27static constexpr llvm::StringRef
kPrintI64 =
"printI64";
28static constexpr llvm::StringRef
kPrintU64 =
"printU64";
29static constexpr llvm::StringRef
kPrintF16 =
"printF16";
30static constexpr llvm::StringRef
kPrintBF16 =
"printBF16";
31static constexpr llvm::StringRef
kPrintF32 =
"printF32";
32static constexpr llvm::StringRef
kPrintF64 =
"printF64";
35static constexpr llvm::StringRef
kPrintOpen =
"printOpen";
39static constexpr llvm::StringRef
kMalloc =
"malloc";
41static constexpr llvm::StringRef
kFree =
"free";
42static constexpr llvm::StringRef
kGenericAlloc =
"_mlir_memref_to_llvm_alloc";
44 "_mlir_memref_to_llvm_aligned_alloc";
45static constexpr llvm::StringRef
kGenericFree =
"_mlir_memref_to_llvm_free";
52LLVM::LLVMFuncOp lookupFuncOp(StringRef name,
Operation *symbolTableOp,
55 return symbolTables->lookupSymbolIn<LLVM::LLVMFuncOp>(
56 symbolTableOp, StringAttr::get(symbolTableOp->getContext(), name));
59 return llvm::dyn_cast_or_null<LLVM::LLVMFuncOp>(
65FailureOr<LLVM::LLVMFuncOp>
68 bool isVarArg,
bool isReserved,
71 "expected SymbolTable operation");
72 auto func = lookupFuncOp(name, moduleOp, symbolTables);
73 auto funcT = LLVMFunctionType::get(resultType, paramTypes, isVarArg);
76 if (funcT !=
func.getFunctionType()) {
78 func.emitError(
"redefinition of reserved function '")
79 << name <<
"' of different type " <<
func.getFunctionType()
82 func.emitError(
"redefinition of function '")
83 << name <<
"' of different type " << funcT <<
" is prohibited";
91 assert(!moduleOp->
getRegion(0).
empty() &&
"expected non-empty region");
93 auto funcOp = LLVM::LLVMFuncOp::create(
95 LLVM::LLVMFunctionType::get(resultType, paramTypes, isVarArg));
105static FailureOr<LLVM::LLVMFuncOp>
114FailureOr<LLVM::LLVMFuncOp>
119 LLVM::LLVMVoidType::get(moduleOp->
getContext()), symbolTables);
122FailureOr<LLVM::LLVMFuncOp>
127 LLVM::LLVMVoidType::get(moduleOp->
getContext()), symbolTables);
130FailureOr<LLVM::LLVMFuncOp>
136 LLVM::LLVMVoidType::get(moduleOp->
getContext()), symbolTables);
139FailureOr<LLVM::LLVMFuncOp>
145 LLVM::LLVMVoidType::get(moduleOp->
getContext()), symbolTables);
148FailureOr<LLVM::LLVMFuncOp>
153 LLVM::LLVMVoidType::get(moduleOp->
getContext()), symbolTables);
156FailureOr<LLVM::LLVMFuncOp>
161 LLVM::LLVMVoidType::get(moduleOp->
getContext()), symbolTables);
164FailureOr<LLVM::LLVMFuncOp>
169 {IntegerType::get(moduleOp->
getContext(), 32),
170 IntegerType::get(moduleOp->
getContext(), 64)},
171 LLVM::LLVMVoidType::get(moduleOp->
getContext()), symbolTables);
175 return LLVM::LLVMPointerType::get(context);
185 std::optional<StringRef> runtimeFunctionName,
190 LLVM::LLVMVoidType::get(moduleOp->
getContext()), symbolTables);
193FailureOr<LLVM::LLVMFuncOp>
198 LLVM::LLVMVoidType::get(moduleOp->
getContext()), symbolTables);
201FailureOr<LLVM::LLVMFuncOp>
206 LLVM::LLVMVoidType::get(moduleOp->
getContext()), symbolTables);
209FailureOr<LLVM::LLVMFuncOp>
214 LLVM::LLVMVoidType::get(moduleOp->
getContext()), symbolTables);
217FailureOr<LLVM::LLVMFuncOp>
222 LLVM::LLVMVoidType::get(moduleOp->
getContext()), symbolTables);
225FailureOr<LLVM::LLVMFuncOp>
234FailureOr<LLVM::LLVMFuncOp>
243FailureOr<LLVM::LLVMFuncOp>
248 LLVM::LLVMVoidType::get(moduleOp->
getContext()), symbolTables);
251FailureOr<LLVM::LLVMFuncOp>
268FailureOr<LLVM::LLVMFuncOp>
273 LLVM::LLVMVoidType::get(moduleOp->
getContext()), symbolTables);
281 ArrayRef<Type>{indexType, unrankedDescriptorType, unrankedDescriptorType},
282 LLVM::LLVMVoidType::get(moduleOp->
getContext()), symbolTables);
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 kPrintApFloat
static FailureOr< LLVM::LLVMFuncOp > lookupOrCreateReservedFn(OpBuilder &b, Operation *moduleOp, StringRef name, ArrayRef< Type > paramTypes, Type resultType, SymbolTableCollection *symbolTables)
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 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.
A trait used to provide symbol table functionalities to a region operation.
Operation is the basic unit of execution within MLIR.
Region & getRegion(unsigned index)
Returns the region held by this operation at position 'index'.
bool hasTrait()
Returns true if the operation was registered with a particular trait, e.g.
Location getLoc()
The source location the operation was defined or derived from.
MLIRContext * getContext()
Return the context this operation is associated with.
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 > lookupOrCreateApFloatPrintFn(OpBuilder &b, Operation *moduleOp, SymbolTableCollection *symbolTables=nullptr)
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 name name`.
Include the generated interface declarations.