16 #include "llvm/ADT/SmallVectorExtras.h"
17 #include "llvm/ADT/StringSet.h"
18 #include "llvm/Support/FormatVariadic.h"
28 if (encodeWorkgroupAttributionsAsArguments) {
33 gpuFuncOp.getWorkgroupAttributions();
34 size_t numAttributions = workgroupAttributions.size();
37 unsigned index = gpuFuncOp.getNumArguments();
41 Type workgroupPtrType =
42 rewriter.
getType<LLVM::LLVMPointerType>(workgroupAddrSpace);
47 rewriter.
getNamedAttr(LLVM::LLVMDialect::getNoAliasAttrName(),
50 getDialect().getWorkgroupAttributionAttrHelper().getName(),
55 auto attributionType = cast<MemRefType>(attribution.getType());
56 IntegerAttr numElements =
58 Type llvmElementType =
63 attrs.back().setValue(
64 rewriter.
getAttr<LLVM::WorkgroupAttributionAttr>(numElements, type));
73 gpuFuncOp, [gpuFuncOp, &argIndices, &argTypes, &argAttrs, &argLocs]() {
74 static_cast<FunctionOpInterface
>(gpuFuncOp).insertArguments(
75 argIndices, argTypes, argAttrs, argLocs);
78 workgroupBuffers.reserve(gpuFuncOp.getNumWorkgroupAttributions());
79 for (
auto [idx, attribution] :
81 auto type = dyn_cast<MemRefType>(attribution.getType());
82 assert(type && type.hasStaticShape() &&
"unexpected type in attribution");
84 uint64_t numElements = type.getNumElements();
90 std::string(llvm::formatv(
"__wg_{0}_{1}", gpuFuncOp.getName(), idx));
91 uint64_t alignment = 0;
92 if (
auto alignAttr = dyn_cast_or_null<IntegerAttr>(
93 gpuFuncOp.getWorkgroupAttributionAttr(
94 idx, LLVM::LLVMDialect::getAlignAttrName())))
95 alignment = alignAttr.getInt();
96 auto globalOp = rewriter.
create<LLVM::GlobalOp>(
97 gpuFuncOp.getLoc(), arrayType,
false,
98 LLVM::Linkage::Internal, name,
Attribute(), alignment,
100 workgroupBuffers.push_back(globalOp);
106 gpuFuncOp.front().getNumArguments());
109 gpuFuncOp.getFunctionType(),
false,
113 diag <<
"failed to convert function signature type for: "
114 << gpuFuncOp.getFunctionType();
122 for (
const auto &attr : gpuFuncOp->getAttrs()) {
124 attr.getName() == gpuFuncOp.getFunctionTypeAttrName() ||
126 gpu::GPUFuncOp::getNumWorkgroupAttributionsAttrName() ||
127 attr.getName() == gpuFuncOp.getWorkgroupAttribAttrsAttrName() ||
128 attr.getName() == gpuFuncOp.getPrivateAttribAttrsAttrName() ||
129 attr.getName() == gpuFuncOp.getKnownBlockSizeAttrName() ||
130 attr.getName() == gpuFuncOp.getKnownGridSizeAttrName())
132 if (attr.getName() == gpuFuncOp.getArgAttrsAttrName()) {
133 argAttrs = gpuFuncOp.getArgAttrsAttr();
136 attributes.push_back(attr);
143 auto *gpuDialect = cast<gpu::GPUDialect>(gpuFuncOp->getDialect());
145 attributes.emplace_back(gpuDialect->getKnownBlockSizeAttrHelper().getName(),
148 attributes.emplace_back(gpuDialect->getKnownGridSizeAttrHelper().getName(),
154 if (gpuFuncOp.isKernel()) {
155 if (kernelAttributeName)
156 attributes.emplace_back(kernelAttributeName, rewriter.
getUnitAttr());
158 if (kernelBlockSizeAttributeName && knownBlockSize) {
159 attributes.emplace_back(kernelBlockSizeAttributeName, knownBlockSize);
162 LLVM::CConv callingConvention = gpuFuncOp.isKernel()
163 ? kernelCallingConvention
164 : nonKernelCallingConvention;
165 auto llvmFuncOp = rewriter.
create<LLVM::LLVMFuncOp>(
166 gpuFuncOp.getLoc(), gpuFuncOp.getName(), funcType,
167 LLVM::Linkage::External,
false, callingConvention,
168 nullptr, attributes);
180 unsigned numProperArguments = gpuFuncOp.getNumArguments();
182 if (encodeWorkgroupAttributionsAsArguments) {
185 unsigned numAttributions = gpuFuncOp.getNumWorkgroupAttributions();
186 assert(numProperArguments >= numAttributions &&
187 "Expecting attributions to be encoded as arguments already");
192 gpuFuncOp.getArguments().slice(numProperArguments - numAttributions,
195 gpuFuncOp.getWorkgroupAttributions(), attributionArguments))) {
196 auto [attribution, arg] = vals;
197 auto type = cast<MemRefType>(attribution.getType());
205 signatureConversion.
remapInput(numProperArguments + idx, descr);
210 global.getAddrSpace());
211 Value address = rewriter.
create<LLVM::AddressOfOp>(
212 loc, ptrType, global.getSymNameAttr());
214 rewriter.
create<LLVM::GEPOp>(loc, ptrType, global.getType(),
221 Value attribution = gpuFuncOp.getWorkgroupAttributions()[idx];
222 auto type = cast<MemRefType>(attribution.getType());
225 signatureConversion.
remapInput(numProperArguments + idx, descr);
230 unsigned numWorkgroupAttributions = gpuFuncOp.getNumWorkgroupAttributions();
232 for (
const auto [idx, attribution] :
234 auto type = cast<MemRefType>(attribution.getType());
235 assert(type && type.hasStaticShape() &&
"unexpected type in attribution");
243 Value numElements = rewriter.
create<LLVM::ConstantOp>(
244 gpuFuncOp.getLoc(), int64Ty, type.getNumElements());
245 uint64_t alignment = 0;
247 dyn_cast_or_null<IntegerAttr>(gpuFuncOp.getPrivateAttributionAttr(
248 idx, LLVM::LLVMDialect::getAlignAttrName())))
249 alignment = alignAttr.getInt();
251 gpuFuncOp.getLoc(), ptrType, elementType, numElements, alignment);
255 numProperArguments + numWorkgroupAttributions + idx, descr);
263 &signatureConversion)))
268 for (
const auto [idx, argTy] :
272 argAttrs ? cast<DictionaryAttr>(argAttrs[idx]) :
NamedAttrList();
273 auto copyAttribute = [&](StringRef attrName) {
277 for (
size_t i = 0, e = remapping->size; i < e; ++i)
278 llvmFuncOp.setArgAttr(remapping->inputNo + i, attrName, attr);
280 auto copyPointerAttribute = [&](StringRef attrName) {
285 if (remapping->size > 1 &&
286 attrName == LLVM::LLVMDialect::getNoAliasAttrName()) {
288 "Cannot copy noalias with non-bare pointers.\n");
291 for (
size_t i = 0, e = remapping->size; i < e; ++i) {
292 if (isa<LLVM::LLVMPointerType>(
293 llvmFuncOp.getArgument(remapping->inputNo + i).getType())) {
294 llvmFuncOp.setArgAttr(remapping->inputNo + i, attrName, attr);
302 copyAttribute(LLVM::LLVMDialect::getReturnedAttrName());
303 copyAttribute(LLVM::LLVMDialect::getNoUndefAttrName());
304 copyAttribute(LLVM::LLVMDialect::getInRegAttrName());
305 bool lowersToPointer =
false;
306 for (
size_t i = 0, e = remapping->size; i < e; ++i) {
307 lowersToPointer |= isa<LLVM::LLVMPointerType>(
308 llvmFuncOp.getArgument(remapping->inputNo + i).getType());
311 if (lowersToPointer) {
312 copyPointerAttribute(LLVM::LLVMDialect::getNoAliasAttrName());
313 copyPointerAttribute(LLVM::LLVMDialect::getNoCaptureAttrName());
314 copyPointerAttribute(LLVM::LLVMDialect::getNoFreeAttrName());
315 copyPointerAttribute(LLVM::LLVMDialect::getAlignAttrName());
316 copyPointerAttribute(LLVM::LLVMDialect::getReadonlyAttrName());
317 copyPointerAttribute(LLVM::LLVMDialect::getWriteOnlyAttrName());
318 copyPointerAttribute(LLVM::LLVMDialect::getReadnoneAttrName());
319 copyPointerAttribute(LLVM::LLVMDialect::getNonNullAttrName());
320 copyPointerAttribute(LLVM::LLVMDialect::getDereferenceableAttrName());
321 copyPointerAttribute(
322 LLVM::LLVMDialect::getDereferenceableOrNullAttrName());
323 copyPointerAttribute(
324 LLVM::LLVMDialect::WorkgroupAttributionAttrHelper::getNameStr());
332 const char formatStringPrefix[] =
"printfFormat_";
334 unsigned stringNumber = 0;
337 stringConstName.clear();
338 (formatStringPrefix + Twine(stringNumber++)).toStringRef(stringConstName);
339 }
while (moduleOp.lookupSymbol(stringConstName));
340 return stringConstName;
343 template <
typename T>
347 LLVM::LLVMFunctionType type) {
348 LLVM::LLVMFuncOp ret;
349 if (!(ret = moduleOp.template lookupSymbol<LLVM::LLVMFuncOp>(name))) {
350 ConversionPatternRewriter::InsertionGuard guard(rewriter);
352 ret = rewriter.
create<LLVM::LLVMFuncOp>(loc, name, type,
353 LLVM::Linkage::External);
359 gpu::PrintfOp gpuPrintfOp, gpu::PrintfOpAdaptor adaptor,
361 Location loc = gpuPrintfOp->getLoc();
370 auto moduleOp = gpuPrintfOp->getParentOfType<gpu::GPUModuleOp>();
375 LLVM::LLVMFuncOp ocklAppendArgs;
376 if (!adaptor.getArgs().empty()) {
378 moduleOp, loc, rewriter,
"__ockl_printf_append_args",
380 llvmI64, {llvmI64, llvmI32, llvmI64, llvmI64, llvmI64,
381 llvmI64, llvmI64, llvmI64, llvmI64, llvmI32}));
384 moduleOp, loc, rewriter,
"__ockl_printf_append_string_n",
387 {llvmI64, ptrType, llvmI64, llvmI32}));
390 Value zeroI64 = rewriter.
create<LLVM::ConstantOp>(loc, llvmI64, 0);
391 auto printfBeginCall = rewriter.
create<LLVM::CallOp>(loc, ocklBegin, zeroI64);
392 Value printfDesc = printfBeginCall.getResult();
398 formatString.push_back(
'\0');
399 size_t formatStringSize = formatString.size_in_bytes();
402 LLVM::GlobalOp global;
406 global = rewriter.
create<LLVM::GlobalOp>(
408 true, LLVM::Linkage::Internal, stringConstName,
413 Value globalPtr = rewriter.
create<LLVM::AddressOfOp>(
416 global.getSymNameAttr());
420 rewriter.
create<LLVM::ConstantOp>(loc, llvmI64, formatStringSize);
422 Value oneI32 = rewriter.
create<LLVM::ConstantOp>(loc, llvmI32, 1);
423 Value zeroI32 = rewriter.
create<LLVM::ConstantOp>(loc, llvmI32, 0);
425 auto appendFormatCall = rewriter.
create<LLVM::CallOp>(
426 loc, ocklAppendStringN,
427 ValueRange{printfDesc, stringStart, stringLen,
428 adaptor.getArgs().empty() ? oneI32 : zeroI32});
429 printfDesc = appendFormatCall.
getResult();
432 constexpr
size_t argsPerAppend = 7;
433 size_t nArgs = adaptor.getArgs().size();
434 for (
size_t group = 0; group < nArgs; group += argsPerAppend) {
435 size_t bound =
std::min(group + argsPerAppend, nArgs);
436 size_t numArgsThisCall = bound - group;
439 arguments.push_back(printfDesc);
441 rewriter.
create<LLVM::ConstantOp>(loc, llvmI32, numArgsThisCall));
442 for (
size_t i = group; i < bound; ++i) {
443 Value arg = adaptor.getArgs()[i];
444 if (
auto floatType = dyn_cast<FloatType>(arg.
getType())) {
445 if (!floatType.isF64())
446 arg = rewriter.
create<LLVM::FPExtOp>(
448 arg = rewriter.
create<LLVM::BitcastOp>(loc, llvmI64, arg);
451 arg = rewriter.
create<LLVM::ZExtOp>(loc, llvmI64, arg);
453 arguments.push_back(arg);
456 for (
size_t extra = numArgsThisCall; extra < argsPerAppend; ++extra) {
457 arguments.push_back(zeroI64);
460 auto isLast = (bound == nArgs) ? oneI32 : zeroI32;
461 arguments.push_back(isLast);
462 auto call = rewriter.
create<LLVM::CallOp>(loc, ocklAppendArgs, arguments);
470 gpu::PrintfOp gpuPrintfOp, gpu::PrintfOpAdaptor adaptor,
472 Location loc = gpuPrintfOp->getLoc();
481 auto moduleOp = gpuPrintfOp->getParentOfType<gpu::GPUModuleOp>();
486 LLVM::LLVMFuncOp printfDecl =
493 formatString.push_back(
'\0');
496 LLVM::GlobalOp global;
500 global = rewriter.
create<LLVM::GlobalOp>(
502 true, LLVM::Linkage::Internal, stringConstName,
507 Value globalPtr = rewriter.
create<LLVM::AddressOfOp>(
510 global.getSymNameAttr());
515 auto argsRange = adaptor.getArgs();
517 printfArgs.reserve(argsRange.size() + 1);
518 printfArgs.push_back(stringStart);
519 printfArgs.append(argsRange.begin(), argsRange.end());
521 rewriter.
create<LLVM::CallOp>(loc, printfDecl, printfArgs);
527 gpu::PrintfOp gpuPrintfOp, gpu::PrintfOpAdaptor adaptor,
529 Location loc = gpuPrintfOp->getLoc();
537 auto moduleOp = gpuPrintfOp->getParentOfType<gpu::GPUModuleOp>();
541 LLVM::LLVMFuncOp vprintfDecl =
548 formatString.push_back(
'\0');
551 LLVM::GlobalOp global;
555 global = rewriter.
create<LLVM::GlobalOp>(
557 true, LLVM::Linkage::Internal, stringConstName,
562 Value globalPtr = rewriter.
create<LLVM::AddressOfOp>(loc, global);
568 for (
Value arg : adaptor.getArgs()) {
569 Type type = arg.getType();
570 Value promotedArg = arg;
572 if (isa<FloatType>(type)) {
574 promotedArg = rewriter.
create<LLVM::FPExtOp>(loc, type, arg);
576 types.push_back(type);
577 args.push_back(promotedArg);
584 rewriter.
create<LLVM::AllocaOp>(loc, ptrType, structType, one,
588 loc, ptrType, structType, tempAlloc,
590 rewriter.
create<LLVM::StoreOp>(loc, arg, ptr);
592 std::array<Value, 2> printfArgs = {stringStart, tempAlloc};
594 rewriter.
create<LLVM::CallOp>(loc, vprintfDecl, printfArgs);
604 if (llvm::none_of(operandTypes, llvm::IsaPred<VectorType>)) {
616 Value result = rewriter.
create<LLVM::UndefOp>(loc, vectorType);
619 Type elementType = vectorType.getElementType();
621 for (int64_t i = 0; i < vectorType.getNumElements(); ++i) {
622 Value index = rewriter.
create<LLVM::ConstantOp>(loc, indexType, i);
623 auto extractElement = [&](
Value operand) ->
Value {
624 if (!isa<VectorType>(operand.getType()))
626 return rewriter.
create<LLVM::ExtractElementOp>(loc, operand, index);
628 auto scalarOperands = llvm::map_to_vector(operands, extractElement);
630 rewriter.
create(loc, name, scalarOperands, elementType, op->
getAttrs());
631 result = rewriter.
create<LLVM::InsertElementOp>(
632 loc, result, scalarOp->
getResult(0), index);
647 Operation *moduleOp, gpu::DynamicSharedMemoryOp op,
649 MemRefType memrefType,
unsigned alignmentBit) {
650 uint64_t alignmentByte = alignmentBit / memrefType.getElementTypeBitWidth();
652 FailureOr<unsigned> addressSpace =
654 if (failed(addressSpace)) {
655 op->
emitError() <<
"conversion of memref memory space "
656 << memrefType.getMemorySpace()
657 <<
" to integer address space "
658 "failed. Consider adding memory space conversions.";
666 existingGlobalNames.insert(globalOp.getSymName());
667 if (
auto arrayType = dyn_cast<LLVM::LLVMArrayType>(globalOp.getType())) {
668 if (globalOp.getAddrSpace() == addressSpace.value() &&
669 arrayType.getNumElements() == 0 &&
670 globalOp.getAlignment().value_or(0) == alignmentByte) {
677 unsigned uniquingCounter = 0;
680 [&](StringRef candidate) {
681 return existingGlobalNames.contains(candidate);
690 typeConverter->
convertType(memrefType.getElementType()), 0);
692 return rewriter.
create<LLVM::GlobalOp>(
693 op->
getLoc(), zeroSizedArrayType,
false,
694 LLVM::Linkage::Internal, symName,
Attribute(), alignmentByte,
695 addressSpace.value());
699 gpu::DynamicSharedMemoryOp op, OpAdaptor adaptor,
702 MemRefType memrefType = op.getResultMemref().getType();
706 MemRefLayoutAttrInterface layout = {};
708 MemRefType::get({0}, elementType, layout, memrefType.getMemorySpace());
713 LLVM::GlobalOp shmemOp = {};
721 auto basePtr = rewriter.
create<LLVM::AddressOfOp>(loc, shmemOp);
722 Type baseType = basePtr->getResultTypes().front();
726 Value shmemPtr = rewriter.
create<LLVM::GEPOp>(loc, baseType, elementType,
734 loc, memrefType0sz, shmemPtr, shmemPtr, shape, strides, rewriter);
737 rewriter.
replaceOp(op, {memRefDescriptor});
742 gpu::ReturnOp op, OpAdaptor adaptor,
749 if (useBarePtrCallConv) {
752 for (
auto it : llvm::zip(op->
getOperands(), adaptor.getOperands())) {
753 Type oldTy = std::get<0>(it).getType();
754 Value newOperand = std::get<1>(it);
756 cast<BaseMemRefType>(oldTy))) {
759 }
else if (isa<UnrankedMemRefType>(oldTy)) {
764 updatedOperands.push_back(newOperand);
767 updatedOperands = llvm::to_vector<4>(adaptor.getOperands());
774 if (numArguments <= 1) {
788 Value packed = rewriter.
create<LLVM::UndefOp>(loc, packedType);
790 packed = rewriter.
create<LLVM::InsertValueOp>(loc, packed, operand, idx);
800 [mapping](
BaseMemRefType type, gpu::AddressSpaceAttr memorySpaceAttr) {
801 gpu::AddressSpace memorySpace = memorySpaceAttr.getValue();
802 unsigned addressSpace = mapping(memorySpace);
static LLVM::LLVMFuncOp getOrDefineFunction(T &moduleOp, const Location loc, ConversionPatternRewriter &rewriter, StringRef name, LLVM::LLVMFunctionType type)
LLVM::GlobalOp getDynamicSharedMemorySymbol(ConversionPatternRewriter &rewriter, Operation *moduleOp, gpu::DynamicSharedMemoryOp op, const LLVMTypeConverter *typeConverter, MemRefType memrefType, unsigned alignmentBit)
Generates a symbol with 0-sized array type for dynamic shared memory usage, or uses existing symbol.
static IntegerAttr wrapNumericMemorySpace(MLIRContext *ctx, unsigned space)
static SmallString< 16 > getUniqueFormatGlobalName(gpu::GPUModuleOp moduleOp)
static std::string diag(const llvm::Value &value)
static Value min(ImplicitLocOpBuilder &builder, Value value, Value bound)
Attributes are known-constant values of operations.
This class provides a shared interface for ranked and unranked memref types.
This class represents an argument of a Block.
iterator_range< op_iterator< OpT > > getOps()
Return an iterator range over the operations within this block that are of 'OpT'.
IntegerAttr getIndexAttr(int64_t value)
IntegerAttr getI64IntegerAttr(int64_t value)
IntegerType getIntegerType(unsigned width)
Ty getType(Args &&...args)
Get or construct an instance of the type Ty with provided arguments.
StringAttr getStringAttr(const Twine &bytes)
MLIRContext * getContext() const
DictionaryAttr getDictionaryAttr(ArrayRef< NamedAttribute > value)
NamedAttribute getNamedAttr(StringRef name, Attribute val)
Attr getAttr(Args &&...args)
Get or construct an instance of the attribute Attr with provided arguments.
This class implements a pattern rewriter for use with ConversionPatterns.
void replaceOp(Operation *op, ValueRange newValues) override
PatternRewriter hook for replacing an operation.
FailureOr< Block * > convertRegionTypes(Region *region, const TypeConverter &converter, TypeConverter::SignatureConversion *entryConversion=nullptr)
Apply a signature conversion to each block in the given region.
void eraseOp(Operation *op) override
PatternRewriter hook for erasing a dead operation.
const TypeConverter * typeConverter
An optional type converter for use by this pattern.
MemRefDescriptor createMemRefDescriptor(Location loc, MemRefType memRefType, Value allocatedPtr, Value alignedPtr, ArrayRef< Value > sizes, ArrayRef< Value > strides, ConversionPatternRewriter &rewriter) const
Creates and populates a canonical memref descriptor struct.
void getMemRefDescriptorSizes(Location loc, MemRefType memRefType, ValueRange dynamicSizes, ConversionPatternRewriter &rewriter, SmallVectorImpl< Value > &sizes, SmallVectorImpl< Value > &strides, Value &size, bool sizeInBytes=true) const
Computes sizes, strides and buffer size of memRefType with identity layout.
const LLVMTypeConverter * getTypeConverter() const
LLVM::LLVMDialect & getDialect() const
Returns the LLVM dialect.
LogicalResult copyUnrankedDescriptors(OpBuilder &builder, Location loc, TypeRange origTypes, SmallVectorImpl< Value > &operands, bool toDynamic) const
Copies the memory descriptor for any operands that were unranked descriptors originally to heap-alloc...
This class contains all of the information necessary to report a diagnostic to the DiagnosticEngine.
Conversion from types to the LLVM IR dialect.
Type packFunctionResults(TypeRange types, bool useBarePointerCallConv=false) const
Convert a non-empty list of types to be returned from a function into an LLVM-compatible type.
const LowerToLLVMOptions & getOptions() const
Type convertFunctionSignature(FunctionType funcTy, bool isVariadic, bool useBarePtrCallConv, SignatureConversion &result) const
Convert a function type.
LogicalResult convertType(Type t, SmallVectorImpl< Type > &results) const
Convert the given type.
FailureOr< unsigned > getMemRefAddressSpace(BaseMemRefType type) const
Return the LLVM address space corresponding to the memory space of the memref type type or failure if...
static LLVMStructType getLiteral(MLIRContext *context, ArrayRef< Type > types, bool isPacked=false)
Gets or creates a literal struct with the given body in the provided context.
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
MLIRContext is the top-level object for a collection of MLIR operations.
Helper class to produce LLVM dialect operations extracting or inserting elements of a MemRef descript...
Value allocatedPtr(OpBuilder &builder, Location loc)
Builds IR extracting the allocated pointer from the descriptor.
static MemRefDescriptor fromStaticShape(OpBuilder &builder, Location loc, const LLVMTypeConverter &typeConverter, MemRefType type, Value memory)
Builds IR creating a MemRef descriptor that represents type and populates it with static shape and st...
NamedAttrList is array of NamedAttributes that tracks whether it is sorted and does some basic work t...
Attribute erase(StringAttr name)
Erase the attribute with the given name from the list.
RAII guard to reset the insertion point of the builder when destroyed.
void setInsertionPointToStart(Block *block)
Sets the insertion point to the start of the specified block.
void setInsertionPoint(Block *block, Block::iterator insertPoint)
Set the insertion point to the specified location.
Operation * create(const OperationState &state)
Creates an operation given the fields represented as an OperationState.
A trait used to provide symbol table functionalities to a region operation.
type_range getTypes() const
StringAttr getIdentifier() const
Return the name of this operation as a StringAttr.
Operation is the basic unit of execution within MLIR.
unsigned getNumSuccessors()
OpResult getResult(unsigned idx)
Get the 'idx'th result of this operation.
unsigned getNumRegions()
Returns the number of regions held by this operation.
Location getLoc()
The source location the operation was defined or derived from.
unsigned getNumOperands()
ArrayRef< NamedAttribute > getAttrs()
Return all of the attributes on this operation.
InFlightDiagnostic emitError(const Twine &message={})
Emit an error about fatal conditions with this operation, reporting up to any diagnostic handlers tha...
OpTy getParentOfType()
Return the closest surrounding parent operation that is of type 'OpTy'.
Region & getRegion(unsigned index)
Returns the region held by this operation at position 'index'.
Operation * getParentWithTrait()
Returns the closest surrounding parent operation with trait Trait.
OperationName getName()
The name of an operation is the key identifier for it.
operand_type_range getOperandTypes()
operand_range getOperands()
Returns an iterator on the underlying Value's.
unsigned getNumResults()
Return the number of results held by this operation.
std::enable_if_t<!std::is_convertible< CallbackT, Twine >::value, LogicalResult > notifyMatchFailure(Location loc, CallbackT &&reasonCallback)
Used to notify the listener that the IR failed to be rewritten because of a match failure,...
void modifyOpInPlace(Operation *root, CallableT &&callable)
This method is a utility wrapper around an in-place modification of an operation.
void inlineRegionBefore(Region ®ion, Region &parent, Region::iterator before)
Move the blocks that belong to "region" before the given position in another region "parent".
OpTy replaceOpWithNewOp(Operation *op, Args &&...args)
Replace the results of the given (original) op with a new op that is created without verification (re...
static StringRef getSymbolAttrName()
Return the name of the attribute used for symbol names.
This class provides all of the information necessary to convert a type signature.
std::optional< InputMapping > getInputMapping(unsigned input) const
Get the input mapping for the given argument.
void remapInput(unsigned origInputNo, Value replacement)
Remap an input of the original signature to another replacement value.
LogicalResult convertType(Type t, SmallVectorImpl< Type > &results) const
Convert the given type.
void addTypeAttributeConversion(FnT &&callback)
Register a conversion function for attributes within types.
This class provides an abstraction over the various different ranges of value types.
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
bool isIntOrFloat() const
Return true if this is an integer (of any signedness) or a float type.
unsigned getIntOrFloatBitWidth() const
Return the bit width of an integer or a float type, assert failure on other types.
This class provides an abstraction over the different types of ranges over Values.
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Type getType() const
Return the type of this value.
constexpr void enumerate(std::tuple< Tys... > &tuple, CallbackT &&callback)
LogicalResult scalarizeVectorOp(Operation *op, ValueRange operands, ConversionPatternRewriter &rewriter, const LLVMTypeConverter &converter)
Unrolls op if it's operating on vectors.
Include the generated interface declarations.
InFlightDiagnostic emitWarning(Location loc)
Utility method to emit a warning message using this location.
std::function< unsigned(gpu::AddressSpace)> MemorySpaceMapping
A function that maps a MemorySpace enum to a target-specific integer value.
void populateGpuMemorySpaceAttributeConversions(TypeConverter &typeConverter, const MemorySpaceMapping &mapping)
Populates memory space attribute conversion rules for lowering gpu.address_space to integer values.
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...
LogicalResult matchAndRewrite(gpu::DynamicSharedMemoryOp op, OpAdaptor adaptor, ConversionPatternRewriter &rewriter) const override
LogicalResult matchAndRewrite(gpu::GPUFuncOp gpuFuncOp, OpAdaptor adaptor, ConversionPatternRewriter &rewriter) const override
LogicalResult matchAndRewrite(gpu::PrintfOp gpuPrintfOp, gpu::PrintfOpAdaptor adaptor, ConversionPatternRewriter &rewriter) const override
LogicalResult matchAndRewrite(gpu::PrintfOp gpuPrintfOp, gpu::PrintfOpAdaptor adaptor, ConversionPatternRewriter &rewriter) const override
LogicalResult matchAndRewrite(gpu::PrintfOp gpuPrintfOp, gpu::PrintfOpAdaptor adaptor, ConversionPatternRewriter &rewriter) const override
LogicalResult matchAndRewrite(gpu::ReturnOp op, OpAdaptor adaptor, ConversionPatternRewriter &rewriter) const override