MLIR 24.0.0git
BasicPtxBuilderInterface.cpp
Go to the documentation of this file.
1//===- BasicPtxBuilderInterface.td - PTX builder interface -*- tablegen -*-===//
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// Defines the interface to build PTX (Parallel Thread Execution) from NVVM Ops
10// automatically. It is used by NVVM to LLVM pass.
11//
12//===----------------------------------------------------------------------===//
13
18#include "mlir/IR/Diagnostics.h"
19#include "mlir/IR/Location.h"
20#include "mlir/IR/MLIRContext.h"
21
22#include "mlir/Support/LLVM.h"
23#include "llvm/ADT/StringExtras.h"
24#include "llvm/ADT/TypeSwitch.h"
25#include "llvm/Support/DebugLog.h"
26#include "llvm/Support/FormatVariadic.h"
27#include "llvm/Support/LogicalResult.h"
28#include "llvm/Support/Regex.h"
29
30#define DEBUG_TYPE "ptx-builder"
31
32//===----------------------------------------------------------------------===//
33// BasicPtxBuilderInterface
34//===----------------------------------------------------------------------===//
35
36#include "mlir/Dialect/LLVMIR/BasicPtxBuilderInterface.cpp.inc"
37
38using namespace mlir;
39using namespace NVVM;
40
41static constexpr int64_t kSharedMemorySpace = 3;
42
43static FailureOr<char> getRegisterType(Type type, Location loc) {
44 MLIRContext *ctx = type.getContext();
45 auto i16 = IntegerType::get(ctx, 16);
46 auto i32 = IntegerType::get(ctx, 32);
47 auto f32 = Float32Type::get(ctx);
48
49 auto getRegisterTypeForScalar = [&](Type type) -> FailureOr<char> {
50 if (type.isInteger(1))
51 return 'b';
52 if (type.isInteger(16))
53 return 'h';
54 if (type.isInteger(32))
55 return 'r';
56 if (type.isInteger(64))
57 return 'l';
58 if (type.isF32())
59 return 'f';
60 if (type.isF64())
61 return 'd';
62 if (auto ptr = dyn_cast<LLVM::LLVMPointerType>(type)) {
63 // Shared address spaces is addressed with 32-bit pointers.
64 if (ptr.getAddressSpace() == kSharedMemorySpace) {
65 return 'r';
66 }
67 return 'l';
68 }
69 // register type for struct is not supported.
71 loc, "The register type could not be deduced from MLIR type. The ")
72 << type
73 << " is not supported. Supported types are:"
74 "i1, i16, i32, i64, f32, f64,"
75 "pointers.\nPlease use llvm.bitcast if you have different type. "
76 "\nSee the constraints from here: "
77 "https://docs.nvidia.com/cuda/inline-ptx-assembly/"
78 "index.html#constraints";
79 return failure();
80 };
81
82 // Packed registers
83 if (auto v = dyn_cast<VectorType>(type)) {
84 assert(v.getNumDynamicDims() == 0 && "Dynamic vectors are not supported");
85
86 int64_t lanes = v.getNumElements();
87 Type elem = v.getElementType();
88
89 // Case 1. Single vector
90 if (lanes <= 1)
91 return getRegisterTypeForScalar(elem);
92
93 // Case 2. Packed registers
94 Type widened = elem;
95 switch (lanes) {
96
97 case 2:
98 if (elem.isF16() || elem.isBF16()) // vector<2xf16>
99 widened = f32;
100 else if (elem.isFloat(8)) // vector<2xf8>
101 widened = i16;
102 break;
103 case 4:
104 if (elem.isInteger(8)) // vector<i8x4>
105 widened = i32;
106 else if (elem.isFloat(8)) // vector<f8x4>
107 widened = f32;
108 else if (elem.isFloat(4)) // vector<f4x4>
109 widened = i16;
110 break;
111 // Other packing is not supported
112 default:
113 break;
114 }
115 return getRegisterTypeForScalar(widened);
116 }
117
118 return getRegisterTypeForScalar(type);
119}
120
121static FailureOr<char> getRegisterType(Value v, Location loc) {
122 if (v.getDefiningOp<LLVM::ConstantOp>())
123 return 'n';
124 return getRegisterType(v.getType(), loc);
125}
126
127/// Extract every element of a struct value.
129 Location loc, Value structVal) {
130 auto structTy = dyn_cast<LLVM::LLVMStructType>(structVal.getType());
131 assert(structTy && "expected LLVM struct");
132
133 SmallVector<Value> elems;
134 for (unsigned i : llvm::seq<unsigned>(0, structTy.getBody().size()))
135 elems.push_back(LLVM::ExtractValueOp::create(rewriter, loc, structVal, i));
136
137 return elems;
138}
139
141 LDBG() << v << "\t Modifier : " << itype << "\n";
142 registerModifiers.push_back(itype);
143
144 Location loc = interfaceOp->getLoc();
145 auto getModifier = [&]() -> const char * {
146 switch (itype) {
148 return "";
150 return "=";
152 // "Read-Write modifier is not actually supported
153 // Interface will change it to "=" later and add integer mapping
154 return "+";
155 }
156 llvm_unreachable("Unknown PTX register modifier");
157 };
158
159 auto addValue = [&](Value v) {
160 if (itype == PTXRegisterMod::Read) {
161 ptxOperands.push_back(v);
162 return;
163 }
164 if (itype == PTXRegisterMod::ReadWrite)
165 ptxOperands.push_back(v);
166 hasResult = true;
167 };
168
169 llvm::raw_string_ostream ss(registerConstraints);
170 // Handle Structs
171 if (auto stype = dyn_cast<LLVM::LLVMStructType>(v.getType())) {
172 if (itype == PTXRegisterMod::Write) {
173 addValue(v);
174 }
175 for (auto [idx, t] : llvm::enumerate(stype.getBody())) {
176 if (itype != PTXRegisterMod::Write) {
177 Value extractValue =
178 LLVM::ExtractValueOp::create(rewriter, loc, v, idx);
179 addValue(extractValue);
180 }
181 if (itype == PTXRegisterMod::ReadWrite) {
182 ss << idx << ",";
183 } else {
184 FailureOr<char> regType = getRegisterType(t, loc);
185 if (failed(regType))
186 return rewriter.notifyMatchFailure(loc,
187 "failed to get register type");
188 ss << getModifier() << regType.value() << ",";
189 }
190 }
191 return success();
192 }
193 // Handle Scalars
194 addValue(v);
195 FailureOr<char> regType = getRegisterType(v, loc);
196 if (failed(regType))
197 return rewriter.notifyMatchFailure(loc, "failed to get register type");
198 ss << getModifier() << regType.value() << ",";
199 return success();
200}
201
202/// Check if the operation needs to pack and unpack results.
203static bool
204needsPackUnpack(BasicPtxBuilderInterface interfaceOp,
205 bool needsManualRegisterMapping,
206 SmallVectorImpl<PTXRegisterMod> &registerModifiers) {
207 if (needsManualRegisterMapping)
208 return false;
209 const unsigned writeOnlyVals = interfaceOp->getNumResults();
210 const unsigned readWriteVals =
211 llvm::count_if(registerModifiers, [](PTXRegisterMod m) {
212 return m == PTXRegisterMod::ReadWrite;
213 });
214 return (writeOnlyVals + readWriteVals) > 1;
215}
216
217/// Pack the result types of the interface operation.
218/// If the operation has multiple results, it packs them into a struct
219/// type. Otherwise, it returns the original result types.
220static SmallVector<Type>
221packResultTypes(BasicPtxBuilderInterface interfaceOp,
222 bool needsManualRegisterMapping,
223 SmallVectorImpl<PTXRegisterMod> &registerModifiers,
224 SmallVectorImpl<Value> &ptxOperands) {
225 MLIRContext *ctx = interfaceOp->getContext();
226 TypeRange resultRange = interfaceOp->getResultTypes();
227
228 if (!needsPackUnpack(interfaceOp, needsManualRegisterMapping,
229 registerModifiers)) {
230 // Single value path:
231 if (interfaceOp->getResults().size() == 1)
232 return SmallVector<Type>{resultRange.front()};
233
234 // No declared results: if there is an RW, forward its type.
235 for (auto [m, v] : llvm::zip(registerModifiers, ptxOperands))
237 return SmallVector<Type>{v.getType()};
238 }
239
240 SmallVector<Type> packed;
241 for (auto [m, v] : llvm::zip(registerModifiers, ptxOperands))
243 packed.push_back(v.getType());
244 for (Type t : resultRange)
245 packed.push_back(t);
246
247 if (packed.empty())
248 return {};
249
250 auto sTy = LLVM::LLVMStructType::getLiteral(ctx, packed, /*isPacked=*/false);
251 return SmallVector<Type>{sTy};
252}
253
254/// Canonicalize the register constraints:
255/// - Turn every "+X" into "=X"
256/// - Append (at the very end) the 0-based indices of tokens that were "+X"
257/// Examples:
258/// "+f,+f,+r,=r,=r,r,r" -> "=f,=f,=r,=r,=r,r,r,0,1,2"
259/// "+f,+f,+r,=r,=r" -> "=f,=f,=r,=r,=r,0,1,2"
260static std::string canonicalizeRegisterConstraints(llvm::StringRef csv) {
263 SmallVector<unsigned> plusIdx;
264
265 csv.split(toks, ',');
266 out.reserve(toks.size() + 8);
267
268 for (unsigned i = 0, e = toks.size(); i < e; ++i) {
269 StringRef t = toks[i].trim();
270 if (t.consume_front("+")) {
271 plusIdx.push_back(i);
272 out.push_back(("=" + t).str());
273 } else {
274 out.push_back(t.str());
275 }
276 }
277
278 // Append indices of original "+X" tokens.
279 for (unsigned idx : plusIdx)
280 out.push_back(std::to_string(idx));
281
282 // Join back to CSV.
283 std::string result;
284 result.reserve(csv.size() + plusIdx.size() * 2);
285 llvm::raw_string_ostream os(result);
286 for (size_t i = 0; i < out.size(); ++i) {
287 if (i)
288 os << ',';
289 os << out[i];
290 }
291 return os.str();
292}
293
294constexpr llvm::StringLiteral kReadWritePrefix{"rw"};
295constexpr llvm::StringLiteral kWriteOnlyPrefix{"w"};
296constexpr llvm::StringLiteral kReadOnlyPrefix{"r"};
297
298/// Returns a regex that matches {$rwN}, {$wN}, {$rN}
299static llvm::Regex getPredicateMappingRegex() {
300 llvm::Regex rx(llvm::formatv(R"(\{\$({0}|{1}|{2})([0-9]+)\})",
303 .str());
304 return rx;
305}
306
308 StringRef ptxCode, llvm::SmallDenseSet<unsigned int> &seenRW,
309 llvm::SmallDenseSet<unsigned int> &seenW,
310 llvm::SmallDenseSet<unsigned int> &seenR,
311 llvm::SmallVectorImpl<unsigned int> &rwNums,
312 llvm::SmallVectorImpl<unsigned int> &wNums,
313 llvm::SmallVectorImpl<unsigned int> &rNums) {
314
315 llvm::Regex rx = getPredicateMappingRegex();
316 StringRef rest = ptxCode;
317
318 SmallVector<StringRef, 3> m; // 0: full, 1: kind, 2: number
319 while (!rest.empty() && rx.match(rest, &m)) {
320 unsigned num = 0;
321 (void)m[2].getAsInteger(10, num);
322 // Insert it into the vector only the first time we see this number
323 if (m[1].equals_insensitive(kReadWritePrefix)) {
324 if (seenRW.insert(num).second)
325 rwNums.push_back(num);
326 } else if (m[1].equals_insensitive(kWriteOnlyPrefix)) {
327 if (seenW.insert(num).second)
328 wNums.push_back(num);
329 } else {
330 if (seenR.insert(num).second)
331 rNums.push_back(num);
332 }
333
334 const size_t advance = (size_t)(m[0].data() - rest.data()) + m[0].size();
335 rest = rest.drop_front(advance);
336 }
337}
338
339/// Rewrites `{$rwN}`, `{$wN}`, and `{$rN}` placeholders in `ptxCode` into
340/// compact `$K` indices:
341/// - All `rw*` first (sorted by N),
342/// - Then `w*`,
343/// - Then `r*`.
344/// If there a predicate, it comes always in the end.
345/// Each number is assigned once; duplicates are ignored.
346///
347/// Example Input:
348/// "{
349/// reg .pred p;
350/// setp.ge.s32 p, {$r0}, {$r1};"
351/// selp.s32 {$rw0}, {$r0}, {$r1}, p;
352/// selp.s32 {$rw1}, {$r0}, {$r1}, p;
353/// selp.s32 {$w0}, {$r0}, {$r1}, p;
354/// selp.s32 {$w1}, {$r0}, {$r1}, p;
355/// }\n"
356/// Example Output:
357/// "{
358/// reg .pred p;
359/// setp.ge.s32 p, $4, $5;"
360/// selp.s32 $0, $4, $5, p;
361/// selp.s32 $1, $4, $5, p;
362/// selp.s32 $2, $4, $5, p;
363/// selp.s32 $3, $4, $5, p;
364/// }\n"
365static std::string rewriteAsmPlaceholders(llvm::StringRef ptxCode) {
366 llvm::SmallDenseSet<unsigned> seenRW, seenW, seenR;
367 llvm::SmallVector<unsigned> rwNums, wNums, rNums;
368
369 // Step 1. Count Register Placeholder numbers
370 countPlaceholderNumbers(ptxCode, seenRW, seenW, seenR, rwNums, wNums, rNums);
371
372 // Step 2. Sort the Register Placeholder numbers
373 llvm::sort(rwNums);
374 llvm::sort(wNums);
375 llvm::sort(rNums);
376
377 // Step 3. Create mapping from original to new IDs
378 llvm::DenseMap<unsigned, unsigned> rwMap, wMap, rMap;
379 unsigned nextId = 0;
380 for (unsigned n : rwNums)
381 rwMap[n] = nextId++;
382 for (unsigned n : wNums)
383 wMap[n] = nextId++;
384 for (unsigned n : rNums)
385 rMap[n] = nextId++;
386
387 // Step 4. Rewrite the PTX code with new IDs
388 std::string out;
389 out.reserve(ptxCode.size());
390 size_t prev = 0;
391 StringRef rest = ptxCode;
393 llvm::Regex rx = getPredicateMappingRegex();
394 while (!rest.empty() && rx.match(rest, &matches)) {
395 // Compute absolute match bounds in the original buffer.
396 size_t absStart = (size_t)(matches[0].data() - ptxCode.data());
397 size_t absEnd = absStart + matches[0].size();
398
399 // Emit text before the match.
400 out.append(ptxCode.data() + prev, ptxCode.data() + absStart);
401
402 // Emit compact $K
403 unsigned num = 0;
404 (void)matches[2].getAsInteger(10, num);
405 unsigned id = 0;
406 if (matches[1].equals_insensitive(kReadWritePrefix))
407 id = rwMap.lookup(num);
408 else if (matches[1].equals_insensitive(kWriteOnlyPrefix))
409 id = wMap.lookup(num);
410 else
411 id = rMap.lookup(num);
412
413 out.push_back('$');
414 out += std::to_string(id);
415
416 prev = absEnd;
417
418 const size_t advance =
419 (size_t)(matches[0].data() - rest.data()) + matches[0].size();
420 rest = rest.drop_front(advance);
421 }
422
423 // Step 5. Tail.
424 out.append(ptxCode.data() + prev, ptxCode.data() + ptxCode.size());
425 return out;
426}
427
428/// Return the constraint index of the predicate operand. The predicate
429/// constraint ("b") is always the last non-tied token in the canonicalized
430/// constraint string. Tied constraints (digit-only tokens from read-write
431/// canonicalization) are appended at the end, so we walk backwards to skip
432/// them.
433static unsigned getPredicateConstraintIndex(StringRef constraints) {
435 constraints.split(tokens, ',');
436 assert(!tokens.empty() && "expected at least a predicate constraint");
437
438 auto isTiedConstraint = [](StringRef tok) {
439 unsigned idx;
440 return !tok.trim().getAsInteger(10, idx);
441 };
442
443 size_t numTied = 0;
444 for (StringRef tok : llvm::reverse(tokens)) {
445 if (!isTiedConstraint(tok))
446 break;
447 ++numTied;
448 }
449 assert(numTied < tokens.size() && "all constraints are tied");
450 return tokens.size() - numTied - 1;
451}
452
453LLVM::InlineAsmOp PtxBuilder::build() {
454 auto asmDialectAttr = LLVM::AsmDialectAttr::get(interfaceOp->getContext(),
455 LLVM::AsmDialect::AD_ATT);
456
458 interfaceOp, needsManualRegisterMapping, registerModifiers, ptxOperands);
459
460 // Remove the last comma from the constraints string.
461 if (!registerConstraints.empty() &&
462 registerConstraints[registerConstraints.size() - 1] == ',')
463 registerConstraints.pop_back();
464 registerConstraints = canonicalizeRegisterConstraints(registerConstraints);
465
466 std::string ptxInstruction = interfaceOp.getPtx();
467 if (!needsManualRegisterMapping)
468 ptxInstruction = rewriteAsmPlaceholders(ptxInstruction);
469
470 // Add the predicate to the asm string.
471 if (interfaceOp.getPredicate().has_value() &&
472 interfaceOp.getPredicate().value()) {
473 unsigned predIdx = getPredicateConstraintIndex(registerConstraints);
474 std::string predicateStr = "@%";
475 predicateStr += std::to_string(predIdx);
476 ptxInstruction = predicateStr + " " + ptxInstruction;
477 }
478
479 // Clobbers go after all register constraints.
480 if (interfaceOp.hasMemoryClobber()) {
481 if (!registerConstraints.empty())
482 registerConstraints += ",";
483 registerConstraints += "~{memory}";
484 }
485
486 // Operand placeholders are written as %0, %1, ... (and the predicate as
487 // @%N), because TableGen string attributes cannot contain '$', which inline
488 // assembly uses for operand substitution. Convert only a '%' that is
489 // immediately followed by a digit; this leaves literal PTX special-register
490 // names such as %tid.x, %laneid or %dynamic_smem_size intact.
491 std::string mapped;
492 mapped.reserve(ptxInstruction.size());
493 for (size_t i = 0, e = ptxInstruction.size(); i < e; ++i) {
494 if (ptxInstruction[i] == '%' && i + 1 < e &&
495 llvm::isDigit(ptxInstruction[i + 1]))
496 mapped.push_back('$');
497 else
498 mapped.push_back(ptxInstruction[i]);
499 }
500 ptxInstruction = std::move(mapped);
501
502 return LLVM::InlineAsmOp::create(
503 rewriter, interfaceOp->getLoc(),
504 /*result types=*/resultTypes,
505 /*operands=*/ptxOperands,
506 /*asm_string=*/ptxInstruction,
507 /*constraints=*/registerConstraints.data(),
508 /*has_side_effects=*/interfaceOp.hasSideEffect(),
509 /*is_align_stack=*/false, LLVM::TailCallKind::None,
510 /*convergent=*/false,
511 /*asm_dialect=*/asmDialectAttr,
512 /*operand_attrs=*/ArrayAttr());
513}
514
516 LLVM::InlineAsmOp inlineAsmOp = build();
517 LDBG() << "\n Generated PTX \n\t" << inlineAsmOp;
518
519 // Case 0: no result at all → just erase wrapper op.
520 if (!hasResult) {
521 rewriter.eraseOp(interfaceOp);
522 return;
523 }
524
525 if (needsManualRegisterMapping) {
526 rewriter.replaceOp(interfaceOp, inlineAsmOp->getResults());
527 return;
528 }
529
530 // Case 1: Simple path, single scalar inline asm result.
531 if (!needsPackUnpack(interfaceOp, needsManualRegisterMapping,
532 registerModifiers)) {
533 // Sub-case 1a: the wrapper op has a declared result -- replace it
534 // directly with the inline asm result.
535 if (interfaceOp->getNumResults() > 0) {
536 rewriter.replaceOp(interfaceOp, inlineAsmOp->getResults());
537 return;
538 }
539 // Sub-case 1b: RW-only, no declared result. The inline asm produces a
540 // single value that represents the post-asm value of the read-write
541 // operand; forward it to that operand's uses and erase the wrapper.
542 if (inlineAsmOp->getNumResults() > 0) {
543 Value postAsm = inlineAsmOp->getResult(0);
544 for (auto [m, v] : llvm::zip(registerModifiers, ptxOperands)) {
546 continue;
547 v.replaceUsesWithIf(postAsm, [&](OpOperand &use) {
548 Operation *owner = use.getOwner();
549 return owner != interfaceOp && owner != inlineAsmOp;
550 });
551 break;
552 }
553 }
554 rewriter.eraseOp(interfaceOp);
555 return;
556 }
557
558 const bool hasRW = llvm::any_of(registerModifiers, [](PTXRegisterMod m) {
559 return m == PTXRegisterMod::ReadWrite;
560 });
561
562 // All multi-value paths produce a single struct result we need to unpack.
563 assert(LLVM::LLVMStructType::classof(inlineAsmOp.getResultTypes().front()) &&
564 "expected struct return for multi-result inline asm");
565 Value structVal = inlineAsmOp.getResult(0);
566 SmallVector<Value> unpacked =
567 extractStructElements(rewriter, interfaceOp->getLoc(), structVal);
568
569 // Case 2: only declared results (no RW): replace the op with all unpacked.
570 if (!hasRW && interfaceOp->getResults().size() > 0) {
571 rewriter.replaceOp(interfaceOp, unpacked);
572 return;
573 }
574
575 // Case 3: RW-only (no declared results): update RW uses and erase wrapper.
576 if (hasRW && interfaceOp->getResults().size() == 0) {
577 unsigned idx = 0;
578 for (auto [m, v] : llvm::zip(registerModifiers, ptxOperands)) {
580 continue;
581 Value repl = unpacked[idx++];
582 v.replaceUsesWithIf(repl, [&](OpOperand &use) {
583 Operation *owner = use.getOwner();
584 return owner != interfaceOp && owner != inlineAsmOp;
585 });
586 }
587 rewriter.eraseOp(interfaceOp);
588 return;
589 }
590
591 // Case 4: mixed (RW + declared results).
592 {
593 // First rewrite RW operands in place.
594 unsigned idx = 0;
595 for (auto [m, v] : llvm::zip(registerModifiers, ptxOperands)) {
597 continue;
598 Value repl = unpacked[idx++];
599 v.replaceUsesWithIf(repl, [&](OpOperand &use) {
600 Operation *owner = use.getOwner();
601 return owner != interfaceOp && owner != inlineAsmOp;
602 });
603 }
604 // The remaining unpacked values correspond to the declared results.
606 tail.reserve(unpacked.size() - idx);
607 for (unsigned i = idx, e = unpacked.size(); i < e; ++i)
608 tail.push_back(unpacked[i]);
609
610 rewriter.replaceOp(interfaceOp, tail);
611 }
612}
return success()
static std::string canonicalizeRegisterConstraints(llvm::StringRef csv)
Canonicalize the register constraints:
constexpr llvm::StringLiteral kWriteOnlyPrefix
static SmallVector< Value > extractStructElements(PatternRewriter &rewriter, Location loc, Value structVal)
Extract every element of a struct value.
static FailureOr< char > getRegisterType(Type type, Location loc)
static constexpr int64_t kSharedMemorySpace
static unsigned getPredicateConstraintIndex(StringRef constraints)
Return the constraint index of the predicate operand.
static SmallVector< Type > packResultTypes(BasicPtxBuilderInterface interfaceOp, bool needsManualRegisterMapping, SmallVectorImpl< PTXRegisterMod > &registerModifiers, SmallVectorImpl< Value > &ptxOperands)
Pack the result types of the interface operation.
static std::string rewriteAsmPlaceholders(llvm::StringRef ptxCode)
Rewrites {$rwN}, {$wN}, and {$rN} placeholders in ptxCode into compact $K indices:
static bool needsPackUnpack(BasicPtxBuilderInterface interfaceOp, bool needsManualRegisterMapping, SmallVectorImpl< PTXRegisterMod > &registerModifiers)
Check if the operation needs to pack and unpack results.
constexpr llvm::StringLiteral kReadWritePrefix
constexpr llvm::StringLiteral kReadOnlyPrefix
static llvm::Regex getPredicateMappingRegex()
Returns a regex that matches {$rwN}, {$wN}, {$rN}.
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
Definition Location.h:76
MLIRContext is the top-level object for a collection of MLIR operations.
Definition MLIRContext.h:71
LogicalResult insertValue(Value v, PTXRegisterMod itype=PTXRegisterMod::Read)
Add an operand with the read/write input type.
LLVM::InlineAsmOp build()
Builds the inline assembly Op and returns it.
void buildAndReplaceOp()
Shortcut to build the inline assembly Op and replace or erase the original op with.
This class represents an operand of an operation.
Definition Value.h:256
Operation is the basic unit of execution within MLIR.
Definition Operation.h:87
A special type of RewriterBase that coordinates the application of a rewrite pattern on the current I...
This class provides an abstraction over the various different ranges of value types.
Definition TypeRange.h:40
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
Definition Types.h:74
bool isF64() const
Definition Types.cpp:41
bool isFloat() const
Return true if this is an float type (with the specified width).
Definition Types.cpp:47
MLIRContext * getContext() const
Return the MLIRContext in which this type was uniqued.
Definition Types.cpp:35
bool isF32() const
Definition Types.cpp:40
bool isInteger() const
Return true if this is an integer type (with the specified width).
Definition Types.cpp:58
bool isF16() const
Definition Types.cpp:38
bool isBF16() const
Definition Types.cpp:37
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Definition Value.h:96
Type getType() const
Return the type of this value.
Definition Value.h:105
Operation * getDefiningOp() const
If this value is the result of an operation, return the operation that defines it.
Definition Value.cpp:18
Operation * getOwner() const
Return the owner of this operand.
Definition UseDefLists.h:38
PTXRegisterMod
Register read/write modifier to build constraint string for PTX inline https://docs....
@ Write
Write register with '=' modifier.
@ ReadWrite
ReadWrite register with '+' modifier.
@ Read
Read register with no modifier.
void countPlaceholderNumbers(StringRef ptxCode, llvm::SmallDenseSet< unsigned > &seenRW, llvm::SmallDenseSet< unsigned > &seenW, llvm::SmallDenseSet< unsigned > &seenR, llvm::SmallVectorImpl< unsigned > &rwNums, llvm::SmallVectorImpl< unsigned > &wNums, llvm::SmallVectorImpl< unsigned > &rNums)
Count the number of placeholder variables such as {$r}, {$w}, {$rw} in the PTX code.
Include the generated interface declarations.
InFlightDiagnostic emitError(Location loc)
Utility method to emit an error message using this location.