16 #include "llvm/ADT/SmallVectorExtras.h"
17 #include "llvm/ADT/StringSet.h"
18 #include "llvm/Support/FormatVariadic.h"
25 LLVM::LLVMFunctionType type) {
27 if (!(ret = moduleOp.template lookupSymbol<LLVM::LLVMFuncOp>(name))) {
30 ret = b.
create<LLVM::LLVMFuncOp>(loc, name, type, LLVM::Linkage::External);
38 unsigned stringNumber = 0;
41 stringConstName.clear();
42 (prefix + Twine(stringNumber++)).toStringRef(stringConstName);
43 }
while (moduleOp.lookupSymbol(stringConstName));
44 return stringConstName;
49 gpu::GPUModuleOp moduleOp,
Type llvmI8,
50 StringRef namePrefix, StringRef str,
51 uint64_t alignment,
unsigned addrSpace) {
53 nullTermStr.push_back(
'\0');
59 for (
auto globalOp : moduleOp.getOps<LLVM::GlobalOp>())
60 if (globalOp.getGlobalType() == globalType && globalOp.getConstant() &&
61 globalOp.getValueAttr() == attr &&
62 globalOp.getAlignment().value_or(0) == alignment &&
63 globalOp.getAddrSpace() == addrSpace)
70 return b.
create<LLVM::GlobalOp>(loc, globalType,
71 true, LLVM::Linkage::Internal,
72 name, attr, alignment, addrSpace);
81 if (encodeWorkgroupAttributionsAsArguments) {
86 gpuFuncOp.getWorkgroupAttributions();
87 size_t numAttributions = workgroupAttributions.size();
90 unsigned index = gpuFuncOp.getNumArguments();
94 Type workgroupPtrType =
95 rewriter.
getType<LLVM::LLVMPointerType>(workgroupAddrSpace);
100 rewriter.
getNamedAttr(LLVM::LLVMDialect::getNoAliasAttrName(),
103 getDialect().getWorkgroupAttributionAttrHelper().getName(),
108 auto attributionType = cast<MemRefType>(attribution.getType());
109 IntegerAttr numElements =
111 Type llvmElementType =
113 if (!llvmElementType)
116 attrs.back().setValue(
117 rewriter.
getAttr<LLVM::WorkgroupAttributionAttr>(numElements, type));
126 gpuFuncOp, [gpuFuncOp, &argIndices, &argTypes, &argAttrs, &argLocs]() {
127 static_cast<FunctionOpInterface
>(gpuFuncOp).insertArguments(
128 argIndices, argTypes, argAttrs, argLocs);
131 workgroupBuffers.reserve(gpuFuncOp.getNumWorkgroupAttributions());
132 for (
auto [idx, attribution] :
134 auto type = dyn_cast<MemRefType>(attribution.getType());
135 assert(type && type.hasStaticShape() &&
"unexpected type in attribution");
137 uint64_t numElements = type.getNumElements();
143 std::string(llvm::formatv(
"__wg_{0}_{1}", gpuFuncOp.getName(), idx));
144 uint64_t alignment = 0;
145 if (
auto alignAttr = dyn_cast_or_null<IntegerAttr>(
146 gpuFuncOp.getWorkgroupAttributionAttr(
147 idx, LLVM::LLVMDialect::getAlignAttrName())))
148 alignment = alignAttr.getInt();
149 auto globalOp = rewriter.
create<LLVM::GlobalOp>(
150 gpuFuncOp.getLoc(), arrayType,
false,
151 LLVM::Linkage::Internal, name,
Attribute(), alignment,
153 workgroupBuffers.push_back(globalOp);
159 gpuFuncOp.front().getNumArguments());
162 gpuFuncOp.getFunctionType(),
false,
166 diag <<
"failed to convert function signature type for: "
167 << gpuFuncOp.getFunctionType();
175 for (
const auto &attr : gpuFuncOp->getAttrs()) {
177 attr.getName() == gpuFuncOp.getFunctionTypeAttrName() ||
179 gpu::GPUFuncOp::getNumWorkgroupAttributionsAttrName() ||
180 attr.getName() == gpuFuncOp.getWorkgroupAttribAttrsAttrName() ||
181 attr.getName() == gpuFuncOp.getPrivateAttribAttrsAttrName() ||
182 attr.getName() == gpuFuncOp.getKnownBlockSizeAttrName() ||
183 attr.getName() == gpuFuncOp.getKnownGridSizeAttrName())
185 if (attr.getName() == gpuFuncOp.getArgAttrsAttrName()) {
186 argAttrs = gpuFuncOp.getArgAttrsAttr();
189 attributes.push_back(attr);
196 auto *gpuDialect = cast<gpu::GPUDialect>(gpuFuncOp->getDialect());
198 attributes.emplace_back(gpuDialect->getKnownBlockSizeAttrHelper().getName(),
201 attributes.emplace_back(gpuDialect->getKnownGridSizeAttrHelper().getName(),
207 if (gpuFuncOp.isKernel()) {
208 if (kernelAttributeName)
209 attributes.emplace_back(kernelAttributeName, rewriter.
getUnitAttr());
211 if (kernelBlockSizeAttributeName && knownBlockSize) {
212 attributes.emplace_back(kernelBlockSizeAttributeName, knownBlockSize);
215 LLVM::CConv callingConvention = gpuFuncOp.isKernel()
216 ? kernelCallingConvention
217 : nonKernelCallingConvention;
218 auto llvmFuncOp = rewriter.
create<LLVM::LLVMFuncOp>(
219 gpuFuncOp.getLoc(), gpuFuncOp.getName(), funcType,
220 LLVM::Linkage::External,
false, callingConvention,
221 nullptr, attributes);
233 unsigned numProperArguments = gpuFuncOp.getNumArguments();
235 if (encodeWorkgroupAttributionsAsArguments) {
238 unsigned numAttributions = gpuFuncOp.getNumWorkgroupAttributions();
239 assert(numProperArguments >= numAttributions &&
240 "Expecting attributions to be encoded as arguments already");
245 gpuFuncOp.getArguments().slice(numProperArguments - numAttributions,
248 gpuFuncOp.getWorkgroupAttributions(), attributionArguments))) {
249 auto [attribution, arg] = vals;
250 auto type = cast<MemRefType>(attribution.getType());
258 signatureConversion.
remapInput(numProperArguments + idx, descr);
263 global.getAddrSpace());
264 Value address = rewriter.
create<LLVM::AddressOfOp>(
265 loc, ptrType, global.getSymNameAttr());
267 rewriter.
create<LLVM::GEPOp>(loc, ptrType, global.getType(),
274 Value attribution = gpuFuncOp.getWorkgroupAttributions()[idx];
275 auto type = cast<MemRefType>(attribution.getType());
278 signatureConversion.
remapInput(numProperArguments + idx, descr);
283 unsigned numWorkgroupAttributions = gpuFuncOp.getNumWorkgroupAttributions();
285 for (
const auto [idx, attribution] :
287 auto type = cast<MemRefType>(attribution.getType());
288 assert(type && type.hasStaticShape() &&
"unexpected type in attribution");
296 Value numElements = rewriter.
create<LLVM::ConstantOp>(
297 gpuFuncOp.getLoc(), int64Ty, type.getNumElements());
298 uint64_t alignment = 0;
300 dyn_cast_or_null<IntegerAttr>(gpuFuncOp.getPrivateAttributionAttr(
301 idx, LLVM::LLVMDialect::getAlignAttrName())))
302 alignment = alignAttr.getInt();
304 gpuFuncOp.getLoc(), ptrType, elementType, numElements, alignment);
308 numProperArguments + numWorkgroupAttributions + idx, descr);
316 &signatureConversion)))
321 for (
const auto [idx, argTy] :
325 argAttrs ? cast<DictionaryAttr>(argAttrs[idx]) :
NamedAttrList();
326 auto copyAttribute = [&](StringRef attrName) {
330 for (
size_t i = 0, e = remapping->size; i < e; ++i)
331 llvmFuncOp.setArgAttr(remapping->inputNo + i, attrName, attr);
333 auto copyPointerAttribute = [&](StringRef attrName) {
338 if (remapping->size > 1 &&
339 attrName == LLVM::LLVMDialect::getNoAliasAttrName()) {
341 "Cannot copy noalias with non-bare pointers.\n");
344 for (
size_t i = 0, e = remapping->size; i < e; ++i) {
345 if (isa<LLVM::LLVMPointerType>(
346 llvmFuncOp.getArgument(remapping->inputNo + i).getType())) {
347 llvmFuncOp.setArgAttr(remapping->inputNo + i, attrName, attr);
355 copyAttribute(LLVM::LLVMDialect::getReturnedAttrName());
356 copyAttribute(LLVM::LLVMDialect::getNoUndefAttrName());
357 copyAttribute(LLVM::LLVMDialect::getInRegAttrName());
358 bool lowersToPointer =
false;
359 for (
size_t i = 0, e = remapping->size; i < e; ++i) {
360 lowersToPointer |= isa<LLVM::LLVMPointerType>(
361 llvmFuncOp.getArgument(remapping->inputNo + i).getType());
364 if (lowersToPointer) {
365 copyPointerAttribute(LLVM::LLVMDialect::getNoAliasAttrName());
366 copyPointerAttribute(LLVM::LLVMDialect::getNoCaptureAttrName());
367 copyPointerAttribute(LLVM::LLVMDialect::getNoFreeAttrName());
368 copyPointerAttribute(LLVM::LLVMDialect::getAlignAttrName());
369 copyPointerAttribute(LLVM::LLVMDialect::getReadonlyAttrName());
370 copyPointerAttribute(LLVM::LLVMDialect::getWriteOnlyAttrName());
371 copyPointerAttribute(LLVM::LLVMDialect::getReadnoneAttrName());
372 copyPointerAttribute(LLVM::LLVMDialect::getNonNullAttrName());
373 copyPointerAttribute(LLVM::LLVMDialect::getDereferenceableAttrName());
374 copyPointerAttribute(
375 LLVM::LLVMDialect::getDereferenceableOrNullAttrName());
376 copyPointerAttribute(
377 LLVM::LLVMDialect::WorkgroupAttributionAttrHelper::getNameStr());
385 gpu::PrintfOp gpuPrintfOp, gpu::PrintfOpAdaptor adaptor,
387 Location loc = gpuPrintfOp->getLoc();
396 auto moduleOp = gpuPrintfOp->getParentOfType<gpu::GPUModuleOp>();
401 LLVM::LLVMFuncOp ocklAppendArgs;
402 if (!adaptor.getArgs().empty()) {
404 moduleOp, loc, rewriter,
"__ockl_printf_append_args",
406 llvmI64, {llvmI64, llvmI32, llvmI64, llvmI64, llvmI64,
407 llvmI64, llvmI64, llvmI64, llvmI64, llvmI32}));
410 moduleOp, loc, rewriter,
"__ockl_printf_append_string_n",
413 {llvmI64, ptrType, llvmI64, llvmI32}));
416 Value zeroI64 = rewriter.
create<LLVM::ConstantOp>(loc, llvmI64, 0);
417 auto printfBeginCall = rewriter.
create<LLVM::CallOp>(loc, ocklBegin, zeroI64);
418 Value printfDesc = printfBeginCall.getResult();
422 rewriter, loc, moduleOp, llvmI8,
"printfFormat_", adaptor.getFormat());
425 Value globalPtr = rewriter.
create<LLVM::AddressOfOp>(
428 global.getSymNameAttr());
430 rewriter.
create<LLVM::GEPOp>(loc, ptrType, global.getGlobalType(),
432 Value stringLen = rewriter.
create<LLVM::ConstantOp>(
433 loc, llvmI64, cast<StringAttr>(global.getValueAttr()).size());
435 Value oneI32 = rewriter.
create<LLVM::ConstantOp>(loc, llvmI32, 1);
436 Value zeroI32 = rewriter.
create<LLVM::ConstantOp>(loc, llvmI32, 0);
438 auto appendFormatCall = rewriter.
create<LLVM::CallOp>(
439 loc, ocklAppendStringN,
440 ValueRange{printfDesc, stringStart, stringLen,
441 adaptor.getArgs().empty() ? oneI32 : zeroI32});
442 printfDesc = appendFormatCall.
getResult();
445 constexpr
size_t argsPerAppend = 7;
446 size_t nArgs = adaptor.getArgs().size();
447 for (
size_t group = 0; group < nArgs; group += argsPerAppend) {
448 size_t bound =
std::min(group + argsPerAppend, nArgs);
449 size_t numArgsThisCall = bound - group;
452 arguments.push_back(printfDesc);
454 rewriter.
create<LLVM::ConstantOp>(loc, llvmI32, numArgsThisCall));
455 for (
size_t i = group; i < bound; ++i) {
456 Value arg = adaptor.getArgs()[i];
457 if (
auto floatType = dyn_cast<FloatType>(arg.
getType())) {
458 if (!floatType.isF64())
459 arg = rewriter.
create<LLVM::FPExtOp>(
461 arg = rewriter.
create<LLVM::BitcastOp>(loc, llvmI64, arg);
464 arg = rewriter.
create<LLVM::ZExtOp>(loc, llvmI64, arg);
466 arguments.push_back(arg);
469 for (
size_t extra = numArgsThisCall; extra < argsPerAppend; ++extra) {
470 arguments.push_back(zeroI64);
473 auto isLast = (bound == nArgs) ? oneI32 : zeroI32;
474 arguments.push_back(isLast);
475 auto call = rewriter.
create<LLVM::CallOp>(loc, ocklAppendArgs, arguments);
483 gpu::PrintfOp gpuPrintfOp, gpu::PrintfOpAdaptor adaptor,
485 Location loc = gpuPrintfOp->getLoc();
494 auto moduleOp = gpuPrintfOp->getParentOfType<gpu::GPUModuleOp>();
499 LLVM::LLVMFuncOp printfDecl =
504 rewriter, loc, moduleOp, llvmI8,
"printfFormat_", adaptor.getFormat(),
508 Value globalPtr = rewriter.
create<LLVM::AddressOfOp>(
511 global.getSymNameAttr());
513 rewriter.
create<LLVM::GEPOp>(loc, ptrType, global.getGlobalType(),
517 auto argsRange = adaptor.getArgs();
519 printfArgs.reserve(argsRange.size() + 1);
520 printfArgs.push_back(stringStart);
521 printfArgs.append(argsRange.begin(), argsRange.end());
523 rewriter.
create<LLVM::CallOp>(loc, printfDecl, printfArgs);
529 gpu::PrintfOp gpuPrintfOp, gpu::PrintfOpAdaptor adaptor,
531 Location loc = gpuPrintfOp->getLoc();
539 auto moduleOp = gpuPrintfOp->getParentOfType<gpu::GPUModuleOp>();
543 LLVM::LLVMFuncOp vprintfDecl =
548 rewriter, loc, moduleOp, llvmI8,
"printfFormat_", adaptor.getFormat());
551 Value globalPtr = rewriter.
create<LLVM::AddressOfOp>(loc, global);
553 rewriter.
create<LLVM::GEPOp>(loc, ptrType, global.getGlobalType(),
558 for (
Value arg : adaptor.getArgs()) {
559 Type type = arg.getType();
560 Value promotedArg = arg;
562 if (isa<FloatType>(type)) {
564 promotedArg = rewriter.
create<LLVM::FPExtOp>(loc, type, arg);
566 types.push_back(type);
567 args.push_back(promotedArg);
570 LLVM::LLVMStructType::getLiteral(gpuPrintfOp.getContext(), types);
574 rewriter.
create<LLVM::AllocaOp>(loc, ptrType, structType, one,
578 loc, ptrType, structType, tempAlloc,
580 rewriter.
create<LLVM::StoreOp>(loc, arg, ptr);
582 std::array<Value, 2> printfArgs = {stringStart, tempAlloc};
584 rewriter.
create<LLVM::CallOp>(loc, vprintfDecl, printfArgs);
594 if (llvm::none_of(operandTypes, llvm::IsaPred<VectorType>)) {
606 Value result = rewriter.
create<LLVM::UndefOp>(loc, vectorType);
609 Type elementType = vectorType.getElementType();
611 for (int64_t i = 0; i < vectorType.getNumElements(); ++i) {
612 Value index = rewriter.
create<LLVM::ConstantOp>(loc, indexType, i);
613 auto extractElement = [&](
Value operand) ->
Value {
614 if (!isa<VectorType>(operand.getType()))
616 return rewriter.
create<LLVM::ExtractElementOp>(loc, operand, index);
618 auto scalarOperands = llvm::map_to_vector(operands, extractElement);
620 rewriter.
create(loc, name, scalarOperands, elementType, op->
getAttrs());
621 result = rewriter.
create<LLVM::InsertElementOp>(
622 loc, result, scalarOp->
getResult(0), index);
638 MemRefType memrefType,
unsigned alignmentBit) {
639 uint64_t alignmentByte = alignmentBit / memrefType.getElementTypeBitWidth();
641 FailureOr<unsigned> addressSpace =
643 if (failed(addressSpace)) {
644 op->emitError() <<
"conversion of memref memory space "
645 << memrefType.getMemorySpace()
646 <<
" to integer address space "
647 "failed. Consider adding memory space conversions.";
653 for (
auto globalOp : moduleOp.getBody()->getOps<LLVM::GlobalOp>()) {
654 existingGlobalNames.insert(globalOp.getSymName());
655 if (
auto arrayType = dyn_cast<LLVM::LLVMArrayType>(globalOp.getType())) {
656 if (globalOp.getAddrSpace() == addressSpace.value() &&
657 arrayType.getNumElements() == 0 &&
658 globalOp.getAlignment().value_or(0) == alignmentByte) {
665 unsigned uniquingCounter = 0;
668 [&](StringRef candidate) {
669 return existingGlobalNames.contains(candidate);
678 typeConverter->
convertType(memrefType.getElementType()), 0);
680 return rewriter.
create<LLVM::GlobalOp>(
681 op->getLoc(), zeroSizedArrayType,
false,
682 LLVM::Linkage::Internal, symName,
Attribute(), alignmentByte,
683 addressSpace.value());
687 gpu::DynamicSharedMemoryOp op, OpAdaptor adaptor,
690 MemRefType memrefType = op.getResultMemref().getType();
694 MemRefLayoutAttrInterface layout = {};
696 MemRefType::get({0}, elementType, layout, memrefType.getMemorySpace());
700 auto moduleOp = op->getParentOfType<gpu::GPUModuleOp>();
707 auto basePtr = rewriter.
create<LLVM::AddressOfOp>(loc, shmemOp);
708 Type baseType = basePtr->getResultTypes().front();
712 Value shmemPtr = rewriter.
create<LLVM::GEPOp>(loc, baseType, elementType,
720 loc, memrefType0sz, shmemPtr, shmemPtr, shape, strides, rewriter);
723 rewriter.
replaceOp(op, {memRefDescriptor});
728 gpu::ReturnOp op, OpAdaptor adaptor,
731 unsigned numArguments = op.getNumOperands();
735 if (useBarePtrCallConv) {
738 for (
auto it : llvm::zip(op->getOperands(), adaptor.getOperands())) {
739 Type oldTy = std::get<0>(it).getType();
740 Value newOperand = std::get<1>(it);
742 cast<BaseMemRefType>(oldTy))) {
745 }
else if (isa<UnrankedMemRefType>(oldTy)) {
750 updatedOperands.push_back(newOperand);
753 updatedOperands = llvm::to_vector<4>(adaptor.getOperands());
760 if (numArguments <= 1) {
762 op,
TypeRange(), updatedOperands, op->getAttrs());
769 op.getOperandTypes(), useBarePtrCallConv);
774 Value packed = rewriter.
create<LLVM::UndefOp>(loc, packedType);
776 packed = rewriter.
create<LLVM::InsertValueOp>(loc, packed, operand, idx);
786 [mapping](
BaseMemRefType type, gpu::AddressSpaceAttr memorySpaceAttr) {
787 gpu::AddressSpace memorySpace = memorySpaceAttr.getValue();
788 unsigned addressSpace = mapping(memorySpace);
static IntegerAttr wrapNumericMemorySpace(MLIRContext *ctx, unsigned space)
static SmallString< 16 > getUniqueSymbolName(gpu::GPUModuleOp moduleOp, StringRef prefix)
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...
LLVM::LLVMFuncOp getOrDefineFunction(gpu::GPUModuleOp moduleOp, Location loc, OpBuilder &b, StringRef name, LLVM::LLVMFunctionType type)
Find or create an external function declaration in the given module.
LLVM::GlobalOp getOrCreateStringConstant(OpBuilder &b, Location loc, gpu::GPUModuleOp moduleOp, Type llvmI8, StringRef namePrefix, StringRef str, uint64_t alignment=0, unsigned addrSpace=0)
Create a global that contains the given string.
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