27 static constexpr llvm::StringRef
kPrintI64 =
"printI64";
28 static constexpr llvm::StringRef
kPrintU64 =
"printU64";
29 static constexpr llvm::StringRef
kPrintF16 =
"printF16";
30 static constexpr llvm::StringRef
kPrintBF16 =
"printBF16";
31 static constexpr llvm::StringRef
kPrintF32 =
"printF32";
32 static constexpr llvm::StringRef
kPrintF64 =
"printF64";
34 static constexpr llvm::StringRef
kPrintOpen =
"printOpen";
38 static constexpr llvm::StringRef
kMalloc =
"malloc";
40 static constexpr llvm::StringRef
kFree =
"free";
41 static constexpr llvm::StringRef
kGenericAlloc =
"_mlir_memref_to_llvm_alloc";
43 "_mlir_memref_to_llvm_aligned_alloc";
44 static constexpr llvm::StringRef
kGenericFree =
"_mlir_memref_to_llvm_free";
48 FailureOr<LLVM::LLVMFuncOp>
51 bool isVarArg,
bool isReserved) {
53 "expected SymbolTable operation");
54 auto func = llvm::dyn_cast_or_null<LLVM::LLVMFuncOp>(
59 if (funcT != func.getFunctionType()) {
61 func.emitError(
"redefinition of reserved function '")
62 << name <<
"' of different type " << func.getFunctionType()
65 func.emitError(
"redefinition of function '")
66 << name <<
"' of different type " << funcT <<
" is prohibited";
74 assert(!moduleOp->
getRegion(0).
empty() &&
"expected non-empty region");
76 return b.
create<LLVM::LLVMFuncOp>(
81 static FailureOr<LLVM::LLVMFuncOp>
88 FailureOr<LLVM::LLVMFuncOp>
95 FailureOr<LLVM::LLVMFuncOp>
102 FailureOr<LLVM::LLVMFuncOp>
110 FailureOr<LLVM::LLVMFuncOp>
118 FailureOr<LLVM::LLVMFuncOp>
125 FailureOr<LLVM::LLVMFuncOp>
143 std::optional<StringRef> runtimeFunctionName) {
145 b, moduleOp, runtimeFunctionName.value_or(
kPrintString),
150 FailureOr<LLVM::LLVMFuncOp>
157 FailureOr<LLVM::LLVMFuncOp>
164 FailureOr<LLVM::LLVMFuncOp>
171 FailureOr<LLVM::LLVMFuncOp>
178 FailureOr<LLVM::LLVMFuncOp>
185 FailureOr<LLVM::LLVMFuncOp>
189 {indexType, indexType},
193 FailureOr<LLVM::LLVMFuncOp>
200 FailureOr<LLVM::LLVMFuncOp>
210 {indexType, indexType},
214 FailureOr<LLVM::LLVMFuncOp>
221 FailureOr<LLVM::LLVMFuncOp>
224 Type unrankedDescriptorType) {
227 ArrayRef<Type>{indexType, unrankedDescriptorType, unrankedDescriptorType},
static LLVM::LLVMPointerType getVoidPtr(MLIRContext *context)
static constexpr llvm::StringRef kPrintI64
Helper functions to lookup or create the declaration for commonly used external C function calls.
static constexpr llvm::StringRef kFree
static constexpr llvm::StringRef kPrintU64
static constexpr llvm::StringRef kPrintBF16
static constexpr llvm::StringRef kPrintString
static constexpr llvm::StringRef kGenericAlignedAlloc
static constexpr llvm::StringRef kAlignedAlloc
static constexpr llvm::StringRef kPrintClose
static constexpr llvm::StringRef kMalloc
static constexpr llvm::StringRef kMemRefCopy
static constexpr llvm::StringRef kPrintComma
static constexpr llvm::StringRef kGenericAlloc
static constexpr llvm::StringRef kPrintNewline
static LLVM::LLVMPointerType getCharPtr(MLIRContext *context)
static constexpr llvm::StringRef kPrintOpen
static constexpr llvm::StringRef kGenericFree
static FailureOr< LLVM::LLVMFuncOp > lookupOrCreateReservedFn(OpBuilder &b, Operation *moduleOp, StringRef name, ArrayRef< Type > paramTypes, Type resultType)
static constexpr llvm::StringRef kPrintF16
static constexpr llvm::StringRef kPrintF32
static constexpr llvm::StringRef kPrintF64
MLIRContext is the top-level object for a collection of MLIR operations.
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.
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.
Operation is the basic unit of execution within MLIR.
bool hasTrait()
Returns true if the operation was registered with a particular trait, e.g.
MLIRContext * getContext()
Return the context this operation is associated with.
Location getLoc()
The source location the operation was defined or derived from.
Region & getRegion(unsigned index)
Returns the region held by this operation at position 'index'.
static Operation * lookupSymbolIn(Operation *op, StringAttr symbol)
Returns the operation registered with the given symbol name with the regions of 'symbolTableOp'.
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
FailureOr< LLVM::LLVMFuncOp > lookupOrCreateMemRefCopyFn(OpBuilder &b, Operation *moduleOp, Type indexType, Type unrankedDescriptorType)
FailureOr< LLVM::LLVMFuncOp > lookupOrCreatePrintNewlineFn(OpBuilder &b, Operation *moduleOp)
FailureOr< LLVM::LLVMFuncOp > lookupOrCreatePrintStringFn(OpBuilder &b, Operation *moduleOp, std::optional< StringRef > runtimeFunctionName={})
Declares a function to print a C-string.
FailureOr< LLVM::LLVMFuncOp > lookupOrCreatePrintOpenFn(OpBuilder &b, Operation *moduleOp)
FailureOr< LLVM::LLVMFuncOp > lookupOrCreatePrintCloseFn(OpBuilder &b, Operation *moduleOp)
FailureOr< LLVM::LLVMFuncOp > lookupOrCreatePrintF16Fn(OpBuilder &b, Operation *moduleOp)
FailureOr< LLVM::LLVMFuncOp > lookupOrCreatePrintBF16Fn(OpBuilder &b, Operation *moduleOp)
FailureOr< LLVM::LLVMFuncOp > lookupOrCreatePrintU64Fn(OpBuilder &b, Operation *moduleOp)
FailureOr< LLVM::LLVMFuncOp > lookupOrCreateGenericAllocFn(OpBuilder &b, Operation *moduleOp, Type indexType)
FailureOr< LLVM::LLVMFuncOp > lookupOrCreateGenericFreeFn(OpBuilder &b, Operation *moduleOp)
FailureOr< LLVM::LLVMFuncOp > lookupOrCreatePrintI64Fn(OpBuilder &b, Operation *moduleOp)
Helper functions to look up or create the declaration for commonly used external C function calls.
FailureOr< LLVM::LLVMFuncOp > lookupOrCreateFreeFn(OpBuilder &b, Operation *moduleOp)
FailureOr< LLVM::LLVMFuncOp > lookupOrCreateAlignedAllocFn(OpBuilder &b, Operation *moduleOp, Type indexType)
FailureOr< LLVM::LLVMFuncOp > lookupOrCreatePrintCommaFn(OpBuilder &b, Operation *moduleOp)
FailureOr< LLVM::LLVMFuncOp > lookupOrCreateGenericAlignedAllocFn(OpBuilder &b, Operation *moduleOp, Type indexType)
FailureOr< LLVM::LLVMFuncOp > lookupOrCreateFn(OpBuilder &b, Operation *moduleOp, StringRef name, ArrayRef< Type > paramTypes={}, Type resultType={}, bool isVarArg=false, bool isReserved=false)
Create a FuncOp with signature resultType(paramTypes)and namename`.
FailureOr< LLVM::LLVMFuncOp > lookupOrCreatePrintF32Fn(OpBuilder &b, Operation *moduleOp)
FailureOr< LLVM::LLVMFuncOp > lookupOrCreateMallocFn(OpBuilder &b, Operation *moduleOp, Type indexType)
FailureOr< LLVM::LLVMFuncOp > lookupOrCreatePrintF64Fn(OpBuilder &b, Operation *moduleOp)
Include the generated interface declarations.
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...