15 #include "llvm/ADT/ArrayRef.h"
28 SymbolTable &symbolTable = symbolTables->getSymbolTable(moduleOp);
33 return symbolTable.
lookupSymbolIn(moduleOp, tentativeName) !=
nullptr;
37 return static_cast<std::string
>(uniqueName);
40 static int counter = 0;
41 std::string uniqueName = std::string(symbolName);
42 while (moduleOp.lookupSymbol(uniqueName)) {
43 uniqueName = std::string(symbolName) +
"_" + std::to_string(counter++);
51 std::optional<StringRef> runtimeFunctionName,
59 elementVals.append(
string.begin(),
string.end());
61 elementVals.push_back(
'\n');
62 elementVals.push_back(
'\0');
64 {
static_cast<int64_t
>(elementVals.size())}, builder.
getI8Type());
69 auto globalOp = builder.
create<LLVM::GlobalOp>(
70 loc, arrayTy,
true, LLVM::Linkage::Private,
77 builder.
create<LLVM::AddressOfOp>(loc, ptrTy, globalOp.getName());
80 builder.
create<LLVM::GEPOp>(loc, ptrTy, arrayTy, msgAddr, indices);
81 FailureOr<LLVM::LLVMFuncOp> printer =
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.
Operation * create(const OperationState &state)
Creates an operation given the fields represented as an OperationState.
This class represents a collection of SymbolTables.
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'.
static SmallString< N > generateSymbolName(StringRef name, UniqueChecker uniqueChecker, unsigned &uniquingCounter)
Generate a unique symbol name.
This class provides an abstraction over the various different ranges of value types.
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.
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...