17 #include "llvm/ADT/SmallVectorExtras.h"
18 #include "llvm/ADT/StringSet.h"
19 #include "llvm/Support/FormatVariadic.h"
26 LLVM::LLVMFunctionType type) {
28 if (!(ret = moduleOp.template lookupSymbol<LLVM::LLVMFuncOp>(name))) {
31 ret = b.
create<LLVM::LLVMFuncOp>(loc, name, type, LLVM::Linkage::External);
39 unsigned stringNumber = 0;
42 stringConstName.clear();
43 (prefix + Twine(stringNumber++)).toStringRef(stringConstName);
44 }
while (moduleOp.lookupSymbol(stringConstName));
45 return stringConstName;
50 gpu::GPUModuleOp moduleOp,
Type llvmI8,
51 StringRef namePrefix, StringRef str,
52 uint64_t alignment,
unsigned addrSpace) {
54 nullTermStr.push_back(
'\0');
60 for (
auto globalOp : moduleOp.getOps<LLVM::GlobalOp>())
61 if (globalOp.getGlobalType() == globalType && globalOp.getConstant() &&
62 globalOp.getValueAttr() == attr &&
63 globalOp.getAlignment().value_or(0) == alignment &&
64 globalOp.getAddrSpace() == addrSpace)
71 return b.
create<LLVM::GlobalOp>(loc, globalType,
72 true, LLVM::Linkage::Internal,
73 name, attr, alignment, addrSpace);
82 if (encodeWorkgroupAttributionsAsArguments) {
87 gpuFuncOp.getWorkgroupAttributions();
88 size_t numAttributions = workgroupAttributions.size();
91 unsigned index = gpuFuncOp.getNumArguments();
95 Type workgroupPtrType =
96 rewriter.
getType<LLVM::LLVMPointerType>(workgroupAddrSpace);
101 rewriter.
getNamedAttr(LLVM::LLVMDialect::getNoAliasAttrName(),
104 getDialect().getWorkgroupAttributionAttrHelper().getName(),
109 auto attributionType = cast<MemRefType>(attribution.getType());
110 IntegerAttr numElements =
112 Type llvmElementType =
114 if (!llvmElementType)
117 attrs.back().setValue(
118 rewriter.
getAttr<LLVM::WorkgroupAttributionAttr>(numElements, type));
127 gpuFuncOp, [gpuFuncOp, &argIndices, &argTypes, &argAttrs, &argLocs]() {
128 static_cast<FunctionOpInterface
>(gpuFuncOp).insertArguments(
129 argIndices, argTypes, argAttrs, argLocs);
132 workgroupBuffers.reserve(gpuFuncOp.getNumWorkgroupAttributions());
133 for (
auto [idx, attribution] :
135 auto type = dyn_cast<MemRefType>(attribution.getType());
136 assert(type && type.hasStaticShape() &&
"unexpected type in attribution");
138 uint64_t numElements = type.getNumElements();
144 std::string(llvm::formatv(
"__wg_{0}_{1}", gpuFuncOp.getName(), idx));
145 uint64_t alignment = 0;
146 if (
auto alignAttr = dyn_cast_or_null<IntegerAttr>(
147 gpuFuncOp.getWorkgroupAttributionAttr(
148 idx, LLVM::LLVMDialect::getAlignAttrName())))
149 alignment = alignAttr.getInt();
150 auto globalOp = rewriter.
create<LLVM::GlobalOp>(
151 gpuFuncOp.getLoc(), arrayType,
false,
152 LLVM::Linkage::Internal, name,
Attribute(), alignment,
154 workgroupBuffers.push_back(globalOp);
160 gpuFuncOp.front().getNumArguments());
163 gpuFuncOp.getFunctionType(),
false,
167 diag <<
"failed to convert function signature type for: "
168 << gpuFuncOp.getFunctionType();
176 for (
const auto &attr : gpuFuncOp->getAttrs()) {
178 attr.getName() == gpuFuncOp.getFunctionTypeAttrName() ||
180 gpu::GPUFuncOp::getNumWorkgroupAttributionsAttrName() ||
181 attr.getName() == gpuFuncOp.getWorkgroupAttribAttrsAttrName() ||
182 attr.getName() == gpuFuncOp.getPrivateAttribAttrsAttrName() ||
183 attr.getName() == gpuFuncOp.getKnownBlockSizeAttrName() ||
184 attr.getName() == gpuFuncOp.getKnownGridSizeAttrName())
186 if (attr.getName() == gpuFuncOp.getArgAttrsAttrName()) {
187 argAttrs = gpuFuncOp.getArgAttrsAttr();
190 attributes.push_back(attr);
197 auto *gpuDialect = cast<gpu::GPUDialect>(gpuFuncOp->getDialect());
199 attributes.emplace_back(gpuDialect->getKnownBlockSizeAttrHelper().getName(),
202 attributes.emplace_back(gpuDialect->getKnownGridSizeAttrHelper().getName(),
208 if (gpuFuncOp.isKernel()) {
209 if (kernelAttributeName)
210 attributes.emplace_back(kernelAttributeName, rewriter.
getUnitAttr());
212 if (kernelBlockSizeAttributeName && knownBlockSize) {
213 attributes.emplace_back(kernelBlockSizeAttributeName, knownBlockSize);
216 LLVM::CConv callingConvention = gpuFuncOp.isKernel()
217 ? kernelCallingConvention
218 : nonKernelCallingConvention;
219 auto llvmFuncOp = rewriter.
create<LLVM::LLVMFuncOp>(
220 gpuFuncOp.getLoc(), gpuFuncOp.getName(), funcType,
221 LLVM::Linkage::External,
false, callingConvention,
222 nullptr, attributes);
234 unsigned numProperArguments = gpuFuncOp.getNumArguments();
236 if (encodeWorkgroupAttributionsAsArguments) {
239 unsigned numAttributions = gpuFuncOp.getNumWorkgroupAttributions();
240 assert(numProperArguments >= numAttributions &&
241 "Expecting attributions to be encoded as arguments already");
246 gpuFuncOp.getArguments().slice(numProperArguments - numAttributions,
249 gpuFuncOp.getWorkgroupAttributions(), attributionArguments))) {
250 auto [attribution, arg] = vals;
251 auto type = cast<MemRefType>(attribution.getType());
259 signatureConversion.
remapInput(numProperArguments + idx, descr);
264 global.getAddrSpace());
265 Value address = rewriter.
create<LLVM::AddressOfOp>(
266 loc, ptrType, global.getSymNameAttr());
268 rewriter.
create<LLVM::GEPOp>(loc, ptrType, global.getType(),
275 Value attribution = gpuFuncOp.getWorkgroupAttributions()[idx];
276 auto type = cast<MemRefType>(attribution.getType());
279 signatureConversion.
remapInput(numProperArguments + idx, descr);
284 unsigned numWorkgroupAttributions = gpuFuncOp.getNumWorkgroupAttributions();
286 for (
const auto [idx, attribution] :
288 auto type = cast<MemRefType>(attribution.getType());
289 assert(type && type.hasStaticShape() &&
"unexpected type in attribution");
297 Value numElements = rewriter.
create<LLVM::ConstantOp>(
298 gpuFuncOp.getLoc(), int64Ty, type.getNumElements());
299 uint64_t alignment = 0;
301 dyn_cast_or_null<IntegerAttr>(gpuFuncOp.getPrivateAttributionAttr(
302 idx, LLVM::LLVMDialect::getAlignAttrName())))
303 alignment = alignAttr.getInt();
305 gpuFuncOp.getLoc(), ptrType, elementType, numElements, alignment);
309 numProperArguments + numWorkgroupAttributions + idx, descr);
317 &signatureConversion)))
322 for (
const auto [idx, argTy] :
326 argAttrs ? cast<DictionaryAttr>(argAttrs[idx]) :
NamedAttrList();
327 auto copyAttribute = [&](StringRef attrName) {
331 for (
size_t i = 0, e = remapping->size; i < e; ++i)
332 llvmFuncOp.setArgAttr(remapping->inputNo + i, attrName, attr);
334 auto copyPointerAttribute = [&](StringRef attrName) {
339 if (remapping->size > 1 &&
340 attrName == LLVM::LLVMDialect::getNoAliasAttrName()) {
342 "Cannot copy noalias with non-bare pointers.\n");
345 for (
size_t i = 0, e = remapping->size; i < e; ++i) {
346 if (isa<LLVM::LLVMPointerType>(
347 llvmFuncOp.getArgument(remapping->inputNo + i).getType())) {
348 llvmFuncOp.setArgAttr(remapping->inputNo + i, attrName, attr);
356 copyAttribute(LLVM::LLVMDialect::getReturnedAttrName());
357 copyAttribute(LLVM::LLVMDialect::getNoUndefAttrName());
358 copyAttribute(LLVM::LLVMDialect::getInRegAttrName());
359 bool lowersToPointer =
false;
360 for (
size_t i = 0, e = remapping->size; i < e; ++i) {
361 lowersToPointer |= isa<LLVM::LLVMPointerType>(
362 llvmFuncOp.getArgument(remapping->inputNo + i).getType());
365 if (lowersToPointer) {
366 copyPointerAttribute(LLVM::LLVMDialect::getNoAliasAttrName());
367 copyPointerAttribute(LLVM::LLVMDialect::getNoCaptureAttrName());
368 copyPointerAttribute(LLVM::LLVMDialect::getNoFreeAttrName());
369 copyPointerAttribute(LLVM::LLVMDialect::getAlignAttrName());
370 copyPointerAttribute(LLVM::LLVMDialect::getReadonlyAttrName());
371 copyPointerAttribute(LLVM::LLVMDialect::getWriteOnlyAttrName());
372 copyPointerAttribute(LLVM::LLVMDialect::getReadnoneAttrName());
373 copyPointerAttribute(LLVM::LLVMDialect::getNonNullAttrName());
374 copyPointerAttribute(LLVM::LLVMDialect::getDereferenceableAttrName());
375 copyPointerAttribute(
376 LLVM::LLVMDialect::getDereferenceableOrNullAttrName());
377 copyPointerAttribute(
378 LLVM::LLVMDialect::WorkgroupAttributionAttrHelper::getNameStr());
386 gpu::PrintfOp gpuPrintfOp, gpu::PrintfOpAdaptor adaptor,
388 Location loc = gpuPrintfOp->getLoc();
397 auto moduleOp = gpuPrintfOp->getParentOfType<gpu::GPUModuleOp>();
402 LLVM::LLVMFuncOp ocklAppendArgs;
403 if (!adaptor.getArgs().empty()) {
405 moduleOp, loc, rewriter,
"__ockl_printf_append_args",
407 llvmI64, {llvmI64, llvmI32, llvmI64, llvmI64, llvmI64,
408 llvmI64, llvmI64, llvmI64, llvmI64, llvmI32}));
411 moduleOp, loc, rewriter,
"__ockl_printf_append_string_n",
414 {llvmI64, ptrType, llvmI64, llvmI32}));
417 Value zeroI64 = rewriter.
create<LLVM::ConstantOp>(loc, llvmI64, 0);
418 auto printfBeginCall = rewriter.
create<LLVM::CallOp>(loc, ocklBegin, zeroI64);
419 Value printfDesc = printfBeginCall.getResult();
423 rewriter, loc, moduleOp, llvmI8,
"printfFormat_", adaptor.getFormat());
426 Value globalPtr = rewriter.
create<LLVM::AddressOfOp>(
429 global.getSymNameAttr());
431 rewriter.
create<LLVM::GEPOp>(loc, ptrType, global.getGlobalType(),
433 Value stringLen = rewriter.
create<LLVM::ConstantOp>(
434 loc, llvmI64, cast<StringAttr>(global.getValueAttr()).size());
436 Value oneI32 = rewriter.
create<LLVM::ConstantOp>(loc, llvmI32, 1);
437 Value zeroI32 = rewriter.
create<LLVM::ConstantOp>(loc, llvmI32, 0);
439 auto appendFormatCall = rewriter.
create<LLVM::CallOp>(
440 loc, ocklAppendStringN,
441 ValueRange{printfDesc, stringStart, stringLen,
442 adaptor.getArgs().empty() ? oneI32 : zeroI32});
443 printfDesc = appendFormatCall.
getResult();
446 constexpr
size_t argsPerAppend = 7;
447 size_t nArgs = adaptor.getArgs().size();
448 for (
size_t group = 0; group < nArgs; group += argsPerAppend) {
449 size_t bound =
std::min(group + argsPerAppend, nArgs);
450 size_t numArgsThisCall = bound - group;
453 arguments.push_back(printfDesc);
455 rewriter.
create<LLVM::ConstantOp>(loc, llvmI32, numArgsThisCall));
456 for (
size_t i = group; i < bound; ++i) {
457 Value arg = adaptor.getArgs()[i];
458 if (
auto floatType = dyn_cast<FloatType>(arg.
getType())) {
459 if (!floatType.isF64())
460 arg = rewriter.
create<LLVM::FPExtOp>(
462 arg = rewriter.
create<LLVM::BitcastOp>(loc, llvmI64, arg);
465 arg = rewriter.
create<LLVM::ZExtOp>(loc, llvmI64, arg);
467 arguments.push_back(arg);
470 for (
size_t extra = numArgsThisCall; extra < argsPerAppend; ++extra) {
471 arguments.push_back(zeroI64);
474 auto isLast = (bound == nArgs) ? oneI32 : zeroI32;
475 arguments.push_back(isLast);
476 auto call = rewriter.
create<LLVM::CallOp>(loc, ocklAppendArgs, arguments);
484 gpu::PrintfOp gpuPrintfOp, gpu::PrintfOpAdaptor adaptor,
486 Location loc = gpuPrintfOp->getLoc();
495 auto moduleOp = gpuPrintfOp->getParentOfType<gpu::GPUModuleOp>();
500 LLVM::LLVMFuncOp printfDecl =
505 rewriter, loc, moduleOp, llvmI8,
"printfFormat_", adaptor.getFormat(),
509 Value globalPtr = rewriter.
create<LLVM::AddressOfOp>(
512 global.getSymNameAttr());
514 rewriter.
create<LLVM::GEPOp>(loc, ptrType, global.getGlobalType(),
518 auto argsRange = adaptor.getArgs();
520 printfArgs.reserve(argsRange.size() + 1);
521 printfArgs.push_back(stringStart);
522 printfArgs.append(argsRange.begin(), argsRange.end());
524 rewriter.
create<LLVM::CallOp>(loc, printfDecl, printfArgs);
530 gpu::PrintfOp gpuPrintfOp, gpu::PrintfOpAdaptor adaptor,
532 Location loc = gpuPrintfOp->getLoc();
540 auto moduleOp = gpuPrintfOp->getParentOfType<gpu::GPUModuleOp>();
544 LLVM::LLVMFuncOp vprintfDecl =
549 rewriter, loc, moduleOp, llvmI8,
"printfFormat_", adaptor.getFormat());
552 Value globalPtr = rewriter.
create<LLVM::AddressOfOp>(loc, global);
554 rewriter.
create<LLVM::GEPOp>(loc, ptrType, global.getGlobalType(),
559 for (
Value arg : adaptor.getArgs()) {
560 Type type = arg.getType();
561 Value promotedArg = arg;
563 if (isa<FloatType>(type)) {
565 promotedArg = rewriter.
create<LLVM::FPExtOp>(loc, type, arg);
567 types.push_back(type);
568 args.push_back(promotedArg);
571 LLVM::LLVMStructType::getLiteral(gpuPrintfOp.getContext(), types);
575 rewriter.
create<LLVM::AllocaOp>(loc, ptrType, structType, one,
579 loc, ptrType, structType, tempAlloc,
581 rewriter.
create<LLVM::StoreOp>(loc, arg, ptr);
583 std::array<Value, 2> printfArgs = {stringStart, tempAlloc};
585 rewriter.
create<LLVM::CallOp>(loc, vprintfDecl, printfArgs);
598 VectorType vectorType = cast<VectorType>(llvm1DVectorTy);
600 Value result = rewriter.
create<LLVM::PoisonOp>(loc, vectorType);
603 Type elementType = vectorType.getElementType();
605 for (int64_t i = 0; i < vectorType.getNumElements(); ++i) {
606 Value index = rewriter.
create<LLVM::ConstantOp>(loc, indexType, i);
607 auto extractElement = [&](
Value operand) ->
Value {
608 if (!isa<VectorType>(operand.getType()))
610 return rewriter.
create<LLVM::ExtractElementOp>(loc, operand, index);
612 auto scalarOperands = llvm::map_to_vector(operands, extractElement);
614 rewriter.
create(loc, name, scalarOperands, elementType, op->
getAttrs());
615 result = rewriter.
create<LLVM::InsertElementOp>(
616 loc, result, scalarOp->
getResult(0), index);
626 if (llvm::any_of(operandTypes, llvm::IsaPred<VectorType>)) {
627 VectorType vectorType =
630 rewriter, converter));
634 if (llvm::any_of(operandTypes, llvm::IsaPred<LLVM::LLVMArrayType>)) {
636 op, operands, converter,
656 MemRefType memrefType,
unsigned alignmentBit) {
657 uint64_t alignmentByte = alignmentBit / memrefType.getElementTypeBitWidth();
659 FailureOr<unsigned> addressSpace =
661 if (failed(addressSpace)) {
662 op->emitError() <<
"conversion of memref memory space "
663 << memrefType.getMemorySpace()
664 <<
" to integer address space "
665 "failed. Consider adding memory space conversions.";
671 for (
auto globalOp : moduleOp.getBody()->getOps<LLVM::GlobalOp>()) {
672 existingGlobalNames.insert(globalOp.getSymName());
673 if (
auto arrayType = dyn_cast<LLVM::LLVMArrayType>(globalOp.getType())) {
674 if (globalOp.getAddrSpace() == addressSpace.value() &&
675 arrayType.getNumElements() == 0 &&
676 globalOp.getAlignment().value_or(0) == alignmentByte) {
683 unsigned uniquingCounter = 0;
686 [&](StringRef candidate) {
687 return existingGlobalNames.contains(candidate);
696 typeConverter->
convertType(memrefType.getElementType()), 0);
698 return rewriter.
create<LLVM::GlobalOp>(
699 op->getLoc(), zeroSizedArrayType,
false,
700 LLVM::Linkage::Internal, symName,
Attribute(), alignmentByte,
701 addressSpace.value());
705 gpu::DynamicSharedMemoryOp op,
OpAdaptor adaptor,
708 MemRefType memrefType = op.getResultMemref().getType();
712 MemRefLayoutAttrInterface layout = {};
714 MemRefType::get({0}, elementType, layout, memrefType.getMemorySpace());
718 auto moduleOp = op->getParentOfType<gpu::GPUModuleOp>();
725 auto basePtr = rewriter.
create<LLVM::AddressOfOp>(loc, shmemOp);
726 Type baseType = basePtr->getResultTypes().front();
730 Value shmemPtr = rewriter.
create<LLVM::GEPOp>(loc, baseType, elementType,
738 loc, memrefType0sz, shmemPtr, shmemPtr, shape, strides, rewriter);
741 rewriter.
replaceOp(op, {memRefDescriptor});
749 unsigned numArguments = op.getNumOperands();
753 if (useBarePtrCallConv) {
756 for (
auto it : llvm::zip(op->getOperands(), adaptor.getOperands())) {
757 Type oldTy = std::get<0>(it).getType();
758 Value newOperand = std::get<1>(it);
760 cast<BaseMemRefType>(oldTy))) {
763 }
else if (isa<UnrankedMemRefType>(oldTy)) {
768 updatedOperands.push_back(newOperand);
771 updatedOperands = llvm::to_vector<4>(adaptor.getOperands());
778 if (numArguments <= 1) {
780 op,
TypeRange(), updatedOperands, op->getAttrs());
787 op.getOperandTypes(), useBarePtrCallConv);
792 Value packed = rewriter.
create<LLVM::PoisonOp>(loc, packedType);
794 packed = rewriter.
create<LLVM::InsertValueOp>(loc, packed, operand, idx);
804 [mapping](
BaseMemRefType type, gpu::AddressSpaceAttr memorySpaceAttr) {
805 gpu::AddressSpace memorySpace = memorySpaceAttr.getValue();
806 unsigned addressSpace = mapping(memorySpace);
static IntegerAttr wrapNumericMemorySpace(MLIRContext *ctx, unsigned space)
static SmallString< 16 > getUniqueSymbolName(gpu::GPUModuleOp moduleOp, StringRef prefix)
static Value scalarizeVectorOpHelper(Operation *op, ValueRange operands, Type llvm1DVectorTy, ConversionPatternRewriter &rewriter, const LLVMTypeConverter &converter)
Helper for impl::scalarizeVectorOp.
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...
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...
Value allocatedPtr(OpBuilder &builder, Location loc)
Builds IR extracting the allocated pointer from the descriptor.
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.
OpResult getResult(unsigned idx)
Get the 'idx'th result of 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.
result_type_range getResultTypes()
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, ArrayRef< Value > replacements)
Remap an input of the original signature to replacements values.
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.
LogicalResult handleMultidimensionalVectors(Operation *op, ValueRange operands, const LLVMTypeConverter &typeConverter, std::function< Value(Type, ValueRange)> createOperand, ConversionPatternRewriter &rewriter)
constexpr void enumerate(std::tuple< Tys... > &tuple, CallbackT &&callback)
LogicalResult scalarizeVectorOp(Operation *op, ValueRange operands, ConversionPatternRewriter &rewriter, const LLVMTypeConverter &converter)
Unrolls op to array/vector elements.
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
Methods that operate on the SourceOp type.
LogicalResult matchAndRewrite(gpu::GPUFuncOp gpuFuncOp, OpAdaptor adaptor, ConversionPatternRewriter &rewriter) const override
Methods that operate on the SourceOp type.
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
Methods that operate on the SourceOp type.