Skip to content

Commit 81cb9d2

Browse files
committed
address comments
1 parent 16a02a4 commit 81cb9d2

File tree

4 files changed

+24
-18
lines changed

4 files changed

+24
-18
lines changed

mlir/include/mlir/Dialect/LLVMIR/BasicPtxBuilderInterface.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ namespace NVVM {
2626
enum class PTXRegisterMod {
2727
/// Read register with no modifier
2828
Read = 0,
29-
/// Read register with '=' modifier
29+
/// Write register with '=' modifier
3030
Write = 2,
31-
/// Read register with '+' modifier.
32-
/// Note that, this is not natively supported by LLVM, but it is possible to
33-
/// set read and write for the same operand.
31+
/// ReadWrite register with '+' modifier.
32+
/// Note that, this is not natively supported by LLVM, the Interface does
33+
/// mapping
3434
ReadWrite = 1,
3535
};
3636

@@ -69,15 +69,17 @@ class PtxBuilder {
6969
std::string registerConstraints;
7070
// Modifiers
7171
SmallVector<PTXRegisterMod> registerModifiers;
72+
// Has return value as write-only or read-write
7273
bool hasResult = false;
73-
bool needsManualMapping = false;
74+
// Indicates if the Op will handle the register mapping manually.
75+
bool needsManualRegisterMapping = false;
7476

7577
public:
7678
/// Single constructor that only initializes members.
7779
PtxBuilder(Operation *op, PatternRewriter &rewriter,
78-
bool needsManualMapping = false)
80+
bool needsManualRegisterMapping = false)
7981
: interfaceOp(op), rewriter(rewriter),
80-
needsManualMapping(needsManualMapping) {}
82+
needsManualRegisterMapping(needsManualRegisterMapping) {}
8183

8284
/// Add an operand with the read/write input type.
8385
void insertValue(Value v, PTXRegisterMod itype = PTXRegisterMod::Read);

mlir/include/mlir/Dialect/LLVMIR/BasicPtxBuilderInterface.td

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def BasicPtxBuilderOpInterface : OpInterface<"BasicPtxBuilderInterface"> {
125125
1) Adds results
126126
2) Adds operands
127127
3) Adds attributes
128-
Returns true if it does the mapping manually
128+
Returns true if the OP is going to do register mapping itself
129129
}],
130130
/*retType=*/"bool",
131131
/*methodName=*/"getAsmValues",
@@ -151,7 +151,7 @@ def BasicPtxBuilderOpInterface : OpInterface<"BasicPtxBuilderInterface"> {
151151
asmValues.push_back({val, mlir::NVVM::PTXRegisterMod::Read});
152152
}
153153
}
154-
return false; // No needs manual mapping
154+
return false; // No manual mapping needed
155155
}]
156156
>
157157
];

mlir/lib/Dialect/LLVMIR/IR/BasicPtxBuilderInterface.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,10 @@ void PtxBuilder::insertValue(Value v, PTXRegisterMod itype) {
129129

130130
/// Check if the operation needs to pack and unpack results.
131131
static bool
132-
needsPackUnpack(BasicPtxBuilderInterface interfaceOp, bool needsManualMapping,
132+
needsPackUnpack(BasicPtxBuilderInterface interfaceOp,
133+
bool needsManualRegisterMapping,
133134
SmallVectorImpl<PTXRegisterMod> &registerModifiers) {
134-
if (needsManualMapping)
135+
if (needsManualRegisterMapping)
135136
return false;
136137
const unsigned writeOnly = interfaceOp->getNumResults();
137138
const unsigned readWrite =
@@ -145,13 +146,15 @@ needsPackUnpack(BasicPtxBuilderInterface interfaceOp, bool needsManualMapping,
145146
/// If the operation has multiple results, it packs them into a struct
146147
/// type. Otherwise, it returns the original result types.
147148
static SmallVector<Type>
148-
packResultTypes(BasicPtxBuilderInterface interfaceOp, bool needsManualMapping,
149+
packResultTypes(BasicPtxBuilderInterface interfaceOp,
150+
bool needsManualRegisterMapping,
149151
SmallVectorImpl<PTXRegisterMod> &registerModifiers,
150152
SmallVectorImpl<Value> &ptxOperands) {
151153
MLIRContext *ctx = interfaceOp->getContext();
152154
TypeRange resultRange = interfaceOp->getResultTypes();
153155

154-
if (!needsPackUnpack(interfaceOp, needsManualMapping, registerModifiers)) {
156+
if (!needsPackUnpack(interfaceOp, needsManualRegisterMapping,
157+
registerModifiers)) {
155158
// Single value path:
156159
if (interfaceOp->getResults().size() == 1)
157160
return SmallVector<Type>{resultRange.front()};
@@ -333,7 +336,7 @@ LLVM::InlineAsmOp PtxBuilder::build() {
333336
LLVM::AsmDialect::AD_ATT);
334337

335338
SmallVector<Type> resultTypes = packResultTypes(
336-
interfaceOp, needsManualMapping, registerModifiers, ptxOperands);
339+
interfaceOp, needsManualRegisterMapping, registerModifiers, ptxOperands);
337340

338341
// Remove the last comma from the constraints string.
339342
if (!registerConstraints.empty() &&
@@ -342,7 +345,7 @@ LLVM::InlineAsmOp PtxBuilder::build() {
342345
registerConstraints = canonicalizeRegisterConstraints(registerConstraints);
343346

344347
std::string ptxInstruction = interfaceOp.getPtx();
345-
if (!needsManualMapping)
348+
if (!needsManualRegisterMapping)
346349
ptxInstruction = rewriteAsmPlaceholders(ptxInstruction);
347350

348351
// Add the predicate to the asm string.
@@ -379,13 +382,14 @@ void PtxBuilder::buildAndReplaceOp() {
379382
return;
380383
}
381384

382-
if (needsManualMapping) {
385+
if (needsManualRegisterMapping) {
383386
rewriter.replaceOp(interfaceOp, inlineAsmOp->getResults());
384387
return;
385388
}
386389

387390
// Case 1: Simple path, return single scalar
388-
if (!needsPackUnpack(interfaceOp, needsManualMapping, registerModifiers)) {
391+
if (!needsPackUnpack(interfaceOp, needsManualRegisterMapping,
392+
registerModifiers)) {
389393
if (inlineAsmOp->getNumResults() > 0) {
390394
rewriter.replaceOp(interfaceOp, inlineAsmOp->getResults());
391395
} else {

mlir/lib/Dialect/LLVMIR/IR/NVVMDialect.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1884,7 +1884,7 @@ bool NVVM::InlinePtxOp::getAsmValues(
18841884
asmValues.push_back({arg, mlir::NVVM::PTXRegisterMod::Read});
18851885
if (getPredicate())
18861886
asmValues.push_back({getPredicate(), mlir::NVVM::PTXRegisterMod::Read});
1887-
return false; // Needs manual mapping
1887+
return false; // No manual mapping needed
18881888
}
18891889

18901890
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)