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";
51 LLVM::LLVMFuncOp lookupFuncOp(StringRef name,
Operation *symbolTableOp,
54 return symbolTables->lookupSymbolIn<LLVM::LLVMFuncOp>(
58 return llvm::dyn_cast_or_null<LLVM::LLVMFuncOp>(
64 FailureOr<LLVM::LLVMFuncOp>
67 bool isVarArg,
bool isReserved,
70 "expected SymbolTable operation");
71 auto func = lookupFuncOp(name, moduleOp, symbolTables);
75 if (funcT != func.getFunctionType()) {
77 func.emitError(
"redefinition of reserved function '")
78 << name <<
"' of different type " << func.getFunctionType()
81 func.emitError(
"redefinition of function '")
82 << name <<
"' of different type " << funcT <<
" is prohibited";
90 assert(!moduleOp->
getRegion(0).
empty() &&
"expected non-empty region");
92 auto funcOp = LLVM::LLVMFuncOp::create(
93 b, moduleOp->
getLoc(), name,
104 static FailureOr<LLVM::LLVMFuncOp>
113 FailureOr<LLVM::LLVMFuncOp>
121 FailureOr<LLVM::LLVMFuncOp>
129 FailureOr<LLVM::LLVMFuncOp>
138 FailureOr<LLVM::LLVMFuncOp>
147 FailureOr<LLVM::LLVMFuncOp>
155 FailureOr<LLVM::LLVMFuncOp>
174 std::optional<StringRef> runtimeFunctionName,
177 b, moduleOp, runtimeFunctionName.value_or(
kPrintString),
182 FailureOr<LLVM::LLVMFuncOp>
190 FailureOr<LLVM::LLVMFuncOp>
198 FailureOr<LLVM::LLVMFuncOp>
206 FailureOr<LLVM::LLVMFuncOp>
214 FailureOr<LLVM::LLVMFuncOp>
223 FailureOr<LLVM::LLVMFuncOp>
232 FailureOr<LLVM::LLVMFuncOp>
240 FailureOr<LLVM::LLVMFuncOp>
257 FailureOr<LLVM::LLVMFuncOp>
270 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 FailureOr< LLVM::LLVMFuncOp > lookupOrCreateReservedFn(OpBuilder &b, Operation *moduleOp, StringRef name, ArrayRef< Type > paramTypes, Type resultType, SymbolTableCollection *symbolTables)
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 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.
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'.
This class represents a collection of SymbolTables.
virtual SymbolTable & getSymbolTable(Operation *op)
Lookup, or create, a symbol table for an operation.
This class allows for representing and managing the symbol table used by operations with the 'SymbolT...
static Operation * lookupSymbolIn(Operation *op, StringAttr symbol)
Returns the operation registered with the given symbol name with the regions of 'symbolTableOp'.
StringAttr insert(Operation *symbol, Block::iterator insertPt={})
Insert a new symbol into the table, and rename it as necessary to avoid collisions.
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
FailureOr< LLVM::LLVMFuncOp > lookupOrCreateFreeFn(OpBuilder &b, Operation *moduleOp, SymbolTableCollection *symbolTables=nullptr)
FailureOr< LLVM::LLVMFuncOp > lookupOrCreatePrintBF16Fn(OpBuilder &b, Operation *moduleOp, SymbolTableCollection *symbolTables=nullptr)
FailureOr< LLVM::LLVMFuncOp > lookupOrCreatePrintOpenFn(OpBuilder &b, Operation *moduleOp, SymbolTableCollection *symbolTables=nullptr)
FailureOr< LLVM::LLVMFuncOp > lookupOrCreateMemRefCopyFn(OpBuilder &b, Operation *moduleOp, Type indexType, Type unrankedDescriptorType, SymbolTableCollection *symbolTables=nullptr)
FailureOr< LLVM::LLVMFuncOp > lookupOrCreatePrintCommaFn(OpBuilder &b, Operation *moduleOp, SymbolTableCollection *symbolTables=nullptr)
FailureOr< LLVM::LLVMFuncOp > lookupOrCreatePrintI64Fn(OpBuilder &b, Operation *moduleOp, SymbolTableCollection *symbolTables=nullptr)
Helper functions to look up or create the declaration for commonly used external C function calls.
FailureOr< LLVM::LLVMFuncOp > lookupOrCreatePrintNewlineFn(OpBuilder &b, Operation *moduleOp, SymbolTableCollection *symbolTables=nullptr)
FailureOr< LLVM::LLVMFuncOp > lookupOrCreatePrintCloseFn(OpBuilder &b, Operation *moduleOp, SymbolTableCollection *symbolTables=nullptr)
FailureOr< LLVM::LLVMFuncOp > lookupOrCreatePrintU64Fn(OpBuilder &b, Operation *moduleOp, SymbolTableCollection *symbolTables=nullptr)
FailureOr< LLVM::LLVMFuncOp > lookupOrCreateGenericAlignedAllocFn(OpBuilder &b, Operation *moduleOp, Type indexType, SymbolTableCollection *symbolTables=nullptr)
FailureOr< LLVM::LLVMFuncOp > lookupOrCreatePrintF32Fn(OpBuilder &b, Operation *moduleOp, SymbolTableCollection *symbolTables=nullptr)
FailureOr< LLVM::LLVMFuncOp > lookupOrCreateMallocFn(OpBuilder &b, Operation *moduleOp, Type indexType, SymbolTableCollection *symbolTables=nullptr)
FailureOr< LLVM::LLVMFuncOp > lookupOrCreateGenericAllocFn(OpBuilder &b, Operation *moduleOp, Type indexType, SymbolTableCollection *symbolTables=nullptr)
FailureOr< LLVM::LLVMFuncOp > lookupOrCreateAlignedAllocFn(OpBuilder &b, Operation *moduleOp, Type indexType, SymbolTableCollection *symbolTables=nullptr)
FailureOr< LLVM::LLVMFuncOp > lookupOrCreatePrintStringFn(OpBuilder &b, Operation *moduleOp, std::optional< StringRef > runtimeFunctionName={}, SymbolTableCollection *symbolTables=nullptr)
Declares a function to print a C-string.
FailureOr< LLVM::LLVMFuncOp > lookupOrCreatePrintF16Fn(OpBuilder &b, Operation *moduleOp, SymbolTableCollection *symbolTables=nullptr)
FailureOr< LLVM::LLVMFuncOp > lookupOrCreateGenericFreeFn(OpBuilder &b, Operation *moduleOp, SymbolTableCollection *symbolTables=nullptr)
FailureOr< LLVM::LLVMFuncOp > lookupOrCreatePrintF64Fn(OpBuilder &b, Operation *moduleOp, SymbolTableCollection *symbolTables=nullptr)
FailureOr< LLVM::LLVMFuncOp > lookupOrCreateFn(OpBuilder &b, Operation *moduleOp, StringRef name, ArrayRef< Type > paramTypes={}, Type resultType={}, bool isVarArg=false, bool isReserved=false, SymbolTableCollection *symbolTables=nullptr)
Create a FuncOp with signature resultType(paramTypes)and namename`.
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...