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;
347 StringRef str, uint64_t alignment = 0,
unsigned addrSpace = 0) {
349 formatString.push_back(
'\0');
355 for (
auto globalOp : moduleOp.getOps<LLVM::GlobalOp>())
356 if (globalOp.getGlobalType() == globalType && globalOp.getConstant() &&
357 globalOp.getValueAttr() == attr &&
358 globalOp.getAlignment().value_or(0) == alignment &&
359 globalOp.getAddrSpace() == addrSpace)
366 return b.
create<LLVM::GlobalOp>(loc, globalType,
367 true, LLVM::Linkage::Internal,
368 name, attr, alignment, addrSpace);
371 template <
typename T>
375 LLVM::LLVMFunctionType type) {
376 LLVM::LLVMFuncOp ret;
377 if (!(ret = moduleOp.template lookupSymbol<LLVM::LLVMFuncOp>(name))) {
378 ConversionPatternRewriter::InsertionGuard guard(rewriter);
380 ret = rewriter.
create<LLVM::LLVMFuncOp>(loc, name, type,
381 LLVM::Linkage::External);
387 gpu::PrintfOp gpuPrintfOp, gpu::PrintfOpAdaptor adaptor,
389 Location loc = gpuPrintfOp->getLoc();
398 auto moduleOp = gpuPrintfOp->getParentOfType<gpu::GPUModuleOp>();
403 LLVM::LLVMFuncOp ocklAppendArgs;
404 if (!adaptor.getArgs().empty()) {
406 moduleOp, loc, rewriter,
"__ockl_printf_append_args",
408 llvmI64, {llvmI64, llvmI32, llvmI64, llvmI64, llvmI64,
409 llvmI64, llvmI64, llvmI64, llvmI64, llvmI32}));
412 moduleOp, loc, rewriter,
"__ockl_printf_append_string_n",
415 {llvmI64, ptrType, llvmI64, llvmI32}));
418 Value zeroI64 = rewriter.
create<LLVM::ConstantOp>(loc, llvmI64, 0);
419 auto printfBeginCall = rewriter.
create<LLVM::CallOp>(loc, ocklBegin, zeroI64);
420 Value printfDesc = printfBeginCall.getResult();
424 rewriter, loc, moduleOp, llvmI8, adaptor.getFormat());
427 Value globalPtr = rewriter.
create<LLVM::AddressOfOp>(
430 global.getSymNameAttr());
432 rewriter.
create<LLVM::GEPOp>(loc, ptrType, global.getGlobalType(),
434 Value stringLen = rewriter.
create<LLVM::ConstantOp>(
435 loc, llvmI64, cast<StringAttr>(global.getValueAttr()).size());
437 Value oneI32 = rewriter.
create<LLVM::ConstantOp>(loc, llvmI32, 1);
438 Value zeroI32 = rewriter.
create<LLVM::ConstantOp>(loc, llvmI32, 0);
440 auto appendFormatCall = rewriter.
create<LLVM::CallOp>(
441 loc, ocklAppendStringN,
442 ValueRange{printfDesc, stringStart, stringLen,
443 adaptor.getArgs().empty() ? oneI32 : zeroI32});
444 printfDesc = appendFormatCall.
getResult();
447 constexpr
size_t argsPerAppend = 7;
448 size_t nArgs = adaptor.getArgs().size();
449 for (
size_t group = 0; group < nArgs; group += argsPerAppend) {
450 size_t bound =
std::min(group + argsPerAppend, nArgs);
451 size_t numArgsThisCall = bound - group;
454 arguments.push_back(printfDesc);
456 rewriter.
create<LLVM::ConstantOp>(loc, llvmI32, numArgsThisCall));
457 for (
size_t i = group; i < bound; ++i) {
458 Value arg = adaptor.getArgs()[i];
459 if (
auto floatType = dyn_cast<FloatType>(arg.
getType())) {
460 if (!floatType.isF64())
461 arg = rewriter.
create<LLVM::FPExtOp>(
463 arg = rewriter.
create<LLVM::BitcastOp>(loc, llvmI64, arg);
466 arg = rewriter.
create<LLVM::ZExtOp>(loc, llvmI64, arg);
468 arguments.push_back(arg);
471 for (
size_t extra = numArgsThisCall; extra < argsPerAppend; ++extra) {
472 arguments.push_back(zeroI64);
475 auto isLast = (bound == nArgs) ? oneI32 : zeroI32;
476 arguments.push_back(isLast);
477 auto call = rewriter.
create<LLVM::CallOp>(loc, ocklAppendArgs, arguments);
485 gpu::PrintfOp gpuPrintfOp, gpu::PrintfOpAdaptor adaptor,
487 Location loc = gpuPrintfOp->getLoc();
496 auto moduleOp = gpuPrintfOp->getParentOfType<gpu::GPUModuleOp>();
501 LLVM::LLVMFuncOp printfDecl =
506 rewriter, loc, moduleOp, llvmI8, adaptor.getFormat(), 0,
510 Value globalPtr = rewriter.
create<LLVM::AddressOfOp>(
513 global.getSymNameAttr());
515 rewriter.
create<LLVM::GEPOp>(loc, ptrType, global.getGlobalType(),
519 auto argsRange = adaptor.getArgs();
521 printfArgs.reserve(argsRange.size() + 1);
522 printfArgs.push_back(stringStart);
523 printfArgs.append(argsRange.begin(), argsRange.end());
525 rewriter.
create<LLVM::CallOp>(loc, printfDecl, printfArgs);
531 gpu::PrintfOp gpuPrintfOp, gpu::PrintfOpAdaptor adaptor,
533 Location loc = gpuPrintfOp->getLoc();
541 auto moduleOp = gpuPrintfOp->getParentOfType<gpu::GPUModuleOp>();
545 LLVM::LLVMFuncOp vprintfDecl =
550 rewriter, loc, moduleOp, llvmI8, adaptor.getFormat());
553 Value globalPtr = rewriter.
create<LLVM::AddressOfOp>(loc, global);
555 rewriter.
create<LLVM::GEPOp>(loc, ptrType, global.getGlobalType(),
560 for (
Value arg : adaptor.getArgs()) {
561 Type type = arg.getType();
562 Value promotedArg = arg;
564 if (isa<FloatType>(type)) {
566 promotedArg = rewriter.
create<LLVM::FPExtOp>(loc, type, arg);
568 types.push_back(type);
569 args.push_back(promotedArg);
572 LLVM::LLVMStructType::getLiteral(gpuPrintfOp.getContext(), types);
576 rewriter.
create<LLVM::AllocaOp>(loc, ptrType, structType, one,
580 loc, ptrType, structType, tempAlloc,
582 rewriter.
create<LLVM::StoreOp>(loc, arg, ptr);
584 std::array<Value, 2> printfArgs = {stringStart, tempAlloc};
586 rewriter.
create<LLVM::CallOp>(loc, vprintfDecl, printfArgs);
596 if (llvm::none_of(operandTypes, llvm::IsaPred<VectorType>)) {
608 Value result = rewriter.
create<LLVM::UndefOp>(loc, vectorType);
611 Type elementType = vectorType.getElementType();
613 for (int64_t i = 0; i < vectorType.getNumElements(); ++i) {
614 Value index = rewriter.
create<LLVM::ConstantOp>(loc, indexType, i);
615 auto extractElement = [&](
Value operand) ->
Value {
616 if (!isa<VectorType>(operand.getType()))
618 return rewriter.
create<LLVM::ExtractElementOp>(loc, operand, index);
620 auto scalarOperands = llvm::map_to_vector(operands, extractElement);
622 rewriter.
create(loc, name, scalarOperands, elementType, op->
getAttrs());
623 result = rewriter.
create<LLVM::InsertElementOp>(
624 loc, result, scalarOp->
getResult(0), index);
640 MemRefType memrefType,
unsigned alignmentBit) {
641 uint64_t alignmentByte = alignmentBit / memrefType.getElementTypeBitWidth();
643 FailureOr<unsigned> addressSpace =
645 if (failed(addressSpace)) {
646 op->emitError() <<
"conversion of memref memory space "
647 << memrefType.getMemorySpace()
648 <<
" to integer address space "
649 "failed. Consider adding memory space conversions.";
655 for (
auto globalOp : moduleOp.getBody()->getOps<LLVM::GlobalOp>()) {
656 existingGlobalNames.insert(globalOp.getSymName());
657 if (
auto arrayType = dyn_cast<LLVM::LLVMArrayType>(globalOp.getType())) {
658 if (globalOp.getAddrSpace() == addressSpace.value() &&
659 arrayType.getNumElements() == 0 &&
660 globalOp.getAlignment().value_or(0) == alignmentByte) {
667 unsigned uniquingCounter = 0;
670 [&](StringRef candidate) {
671 return existingGlobalNames.contains(candidate);
680 typeConverter->
convertType(memrefType.getElementType()), 0);
682 return rewriter.
create<LLVM::GlobalOp>(
683 op->getLoc(), zeroSizedArrayType,
false,
684 LLVM::Linkage::Internal, symName,
Attribute(), alignmentByte,
685 addressSpace.value());
689 gpu::DynamicSharedMemoryOp op, OpAdaptor adaptor,
692 MemRefType memrefType = op.getResultMemref().getType();
696 MemRefLayoutAttrInterface layout = {};
698 MemRefType::get({0}, elementType, layout, memrefType.getMemorySpace());
702 auto moduleOp = op->getParentOfType<gpu::GPUModuleOp>();
709 auto basePtr = rewriter.
create<LLVM::AddressOfOp>(loc, shmemOp);
710 Type baseType = basePtr->getResultTypes().front();
714 Value shmemPtr = rewriter.
create<LLVM::GEPOp>(loc, baseType, elementType,
722 loc, memrefType0sz, shmemPtr, shmemPtr, shape, strides, rewriter);
725 rewriter.
replaceOp(op, {memRefDescriptor});
730 gpu::ReturnOp op, OpAdaptor adaptor,
733 unsigned numArguments = op.getNumOperands();
737 if (useBarePtrCallConv) {
740 for (
auto it : llvm::zip(op->getOperands(), adaptor.getOperands())) {
741 Type oldTy = std::get<0>(it).getType();
742 Value newOperand = std::get<1>(it);
744 cast<BaseMemRefType>(oldTy))) {
747 }
else if (isa<UnrankedMemRefType>(oldTy)) {
752 updatedOperands.push_back(newOperand);
755 updatedOperands = llvm::to_vector<4>(adaptor.getOperands());
762 if (numArguments <= 1) {
764 op,
TypeRange(), updatedOperands, op->getAttrs());
771 op.getOperandTypes(), useBarePtrCallConv);
776 Value packed = rewriter.
create<LLVM::UndefOp>(loc, packedType);
778 packed = rewriter.
create<LLVM::InsertValueOp>(loc, packed, operand, idx);
788 [mapping](
BaseMemRefType type, gpu::AddressSpaceAttr memorySpaceAttr) {
789 gpu::AddressSpace memorySpace = memorySpaceAttr.getValue();
790 unsigned addressSpace = mapping(memorySpace);
static LLVM::LLVMFuncOp getOrDefineFunction(T &moduleOp, const Location loc, ConversionPatternRewriter &rewriter, StringRef name, LLVM::LLVMFunctionType type)
static IntegerAttr wrapNumericMemorySpace(MLIRContext *ctx, unsigned space)
static LLVM::GlobalOp getOrCreateFormatStringConstant(OpBuilder &b, Location loc, gpu::GPUModuleOp moduleOp, Type llvmI8, StringRef str, uint64_t alignment=0, unsigned addrSpace=0)
Create an global that contains the given format string.
static SmallString< 16 > getUniqueFormatGlobalName(gpu::GPUModuleOp moduleOp)
LLVM::GlobalOp getDynamicSharedMemorySymbol(ConversionPatternRewriter &rewriter, gpu::GPUModuleOp 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 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.
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
Replace the given operation with the new values.
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...
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.
This class helps build Operations.
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.
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.
ArrayRef< NamedAttribute > getAttrs()
Return all of the attributes on this operation.
OperationName getName()
The name of an operation is the key identifier for it.
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