MLIR 24.0.0git
NVVMMiscOps.cpp
Go to the documentation of this file.
1//===- NVVMMiscOps.cpp - NVVM dialect miscellaneous ops -------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines the ops of op partition `Misc` of the NVVM dialect.
10//
11//===----------------------------------------------------------------------===//
12
14
15#include "IR/NVVMOps.h"
16#include "mlir/IR/Diagnostics.h"
17#include "mlir/IR/Operation.h"
19#include "mlir/IR/Types.h"
21#include "llvm/IR/IRBuilder.h"
22#include "llvm/IR/IntrinsicsNVPTX.h"
23#include "llvm/Support/Casting.h"
24
25#include <optional>
26#include <utility>
27
28using namespace mlir;
29using namespace mlir::NVVM;
30
31//===----------------------------------------------------------------------===//
32// Verifier methods
33//===----------------------------------------------------------------------===//
34
35LogicalResult PMEventOp::verify() {
36 auto eventId = getEventId();
37 auto maskedEventId = getMaskedEventId();
38 if (!maskedEventId && !eventId) {
39 return emitOpError() << "either `id` or `mask` must be set";
40 }
41
42 if (maskedEventId && eventId) {
43 return emitOpError() << "`id` and `mask` cannot be set at the same time";
44 }
45
46 if (eventId) {
47 if (eventId < 0 || eventId > 15) {
48 return emitOpError() << "`id` must be between 0 and 15";
49 }
50 }
51
52 return llvm::success();
53}
54
55LogicalResult NVVM::SetMaxRegisterOp::verify() {
56 if (getRegCount() % 8)
57 return emitOpError("new register size must be multiple of 8");
58 if (getRegCount() < 24 || getRegCount() > 256)
59 return emitOpError("new register size must be in between 24 to 256");
60 return success();
61}
62
63//===----------------------------------------------------------------------===//
64// getIntrinsicID/getIntrinsicIDAndArgs methods
65//===----------------------------------------------------------------------===//
66
68PMEventOp::getIntrinsicIDAndArgs(Operation &op, LLVM::ModuleTranslation &mt,
69 llvm::IRBuilderBase &builder) {
70 auto thisOp = cast<NVVM::PMEventOp>(op);
71 llvm::Type *i16Ty = llvm::Type::getInt16Ty(mt.getLLVMContext());
72
73 // With event-id, mask is generated as (1 << event-id)
74 llvm::Value *maskVal;
75 if (auto eventAttr = thisOp.getEventIdAttr()) {
76 uint16_t mask = static_cast<uint16_t>(1u << eventAttr.getInt());
77 maskVal = llvm::ConstantInt::get(i16Ty, mask);
78 } else {
79 maskVal =
80 llvm::ConstantInt::get(i16Ty, thisOp.getMaskedEventIdAttr().getValue());
81 }
82
83 return {llvm::Intrinsic::nvvm_pm_event_mask, {maskVal}};
84}
85
86bool NVVM::InlinePtxOp::getAsmValues(
87 RewriterBase &rewriter,
88 llvm::SmallVectorImpl<std::pair<mlir::Value, mlir::NVVM::PTXRegisterMod>>
89 &asmValues) {
90 for (auto arg : getReadWriteArgs())
91 asmValues.push_back({arg, mlir::NVVM::PTXRegisterMod::ReadWrite});
92 for (auto arg : getResults())
93 asmValues.push_back({arg, mlir::NVVM::PTXRegisterMod::Write});
94 for (auto arg : getReadOnlyArgs())
95 asmValues.push_back({arg, mlir::NVVM::PTXRegisterMod::Read});
96 if (getPredicate())
97 asmValues.push_back({getPredicate(), mlir::NVVM::PTXRegisterMod::Read});
98 return false; // No manual mapping needed
99}
100
101#define GET_OP_CLASSES
102#include "mlir/Dialect/LLVMIR/NVVMMiscOps.cpp.inc"
return success()
Implementation class for module translation.
llvm::LLVMContext & getLLVMContext() const
Returns the LLVM context in which the IR is being constructed.
Operation is the basic unit of execution within MLIR.
Definition Operation.h:87
This class coordinates the application of a rewrite on a set of IR, providing a way for clients to tr...
@ Write
Write register with '=' modifier.
@ ReadWrite
ReadWrite register with '+' modifier.
@ Read
Read register with no modifier.
std::pair< llvm::Intrinsic::ID, llvm::SmallVector< llvm::Value * > > IDArgPair
A pair type of LLVM's Intrinsic ID and args (which are llvm values).
Include the generated interface declarations.