18#include "llvm/ADT/ArrayRef.h"
31 SymbolTable &symbolTable = symbolTables->getSymbolTable(moduleOp);
36 return symbolTable.
lookupSymbolIn(moduleOp, tentativeName) !=
nullptr;
40 return static_cast<std::string
>(uniqueName);
43 static int counter = 0;
44 std::string uniqueName = std::string(symbolName);
45 while (moduleOp.lookupSymbol(uniqueName)) {
46 uniqueName = std::string(symbolName) +
"_" + std::to_string(counter++);
54 std::optional<StringRef> runtimeFunctionName,
62 elementVals.append(
string.begin(),
string.end());
64 elementVals.push_back(
'\n');
65 elementVals.push_back(
'\0');
66 auto dataAttrType = RankedTensorType::get(
71 LLVM::LLVMArrayType::get(IntegerType::get(ctx, 8), elementVals.size());
72 auto globalOp = LLVM::GlobalOp::create(
73 builder, loc, arrayTy,
true, LLVM::Linkage::Private,
76 auto ptrTy = LLVM::LLVMPointerType::get(builder.
getContext());
80 LLVM::AddressOfOp::create(builder, loc, ptrTy, globalOp.getName());
83 LLVM::GEPOp::create(builder, loc, ptrTy, arrayTy, msgAddr,
indices);
84 FailureOr<LLVM::LLVMFuncOp> printer =
88 LLVM::CallOp::create(builder, loc,
TypeRange(),
89 SymbolRefAttr::get(printer.value()), gep);
static std::string ensureSymbolNameIsUnique(ModuleOp moduleOp, StringRef symbolName, SymbolTableCollection *symbolTables=nullptr)
Check if a given symbol name is already in use within the module operation.
MLIRContext * getContext() const
static DenseElementsAttr get(ShapedType type, ArrayRef< Attribute > values)
Constructs a dense elements attribute from an array of element values.
Conversion from types to the LLVM IR dialect.
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.
This class helps build Operations.
InsertPoint saveInsertionPoint() const
Return a saved insertion point.
void setInsertionPointToStart(Block *block)
Sets the insertion point to the start of the specified block.
void restoreInsertionPoint(InsertPoint ip)
Restore the insert point to a previously saved point.
This class represents a collection of SymbolTables.
This class allows for representing and managing the symbol table used by operations with the 'SymbolT...
static SmallString< N > generateSymbolName(StringRef name, UniqueChecker uniqueChecker, unsigned &uniquingCounter)
Generate a unique symbol name.
static Operation * lookupSymbolIn(Operation *op, StringAttr symbol)
Returns the operation registered with the given symbol name with the regions of 'symbolTableOp'.
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
The OpAsmOpInterface, see OpAsmInterface.td for more details.
FailureOr< LLVM::LLVMFuncOp > lookupOrCreatePrintStringFn(OpBuilder &b, Operation *moduleOp, std::optional< StringRef > runtimeFunctionName={}, SymbolTableCollection *symbolTables=nullptr)
Declares a function to print a C-string.
LogicalResult createPrintStrCall(OpBuilder &builder, Location loc, ModuleOp moduleOp, StringRef symbolName, StringRef string, const LLVMTypeConverter &typeConverter, bool addNewline=true, std::optional< StringRef > runtimeFunctionName={}, SymbolTableCollection *symbolTables=nullptr)
Generate IR that prints the given string to stdout.
Include the generated interface declarations.