15 #include "llvm/ADT/ArrayRef.h"
21 StringRef symbolName) {
22 static int counter = 0;
23 std::string uniqueName = std::string(symbolName);
24 while (moduleOp.lookupSymbol(uniqueName)) {
25 uniqueName = std::string(symbolName) +
"_" + std::to_string(counter++);
33 std::optional<StringRef> runtimeFunctionName) {
40 elementVals.append(
string.begin(),
string.end());
42 elementVals.push_back(
'\n');
43 elementVals.push_back(
'\0');
45 {
static_cast<int64_t
>(elementVals.size())}, builder.
getI8Type());
50 auto globalOp = builder.
create<LLVM::GlobalOp>(
51 loc, arrayTy,
true, LLVM::Linkage::Private,
58 builder.
create<LLVM::AddressOfOp>(loc, ptrTy, globalOp.getName());
61 builder.
create<LLVM::GEPOp>(loc, ptrTy, arrayTy, msgAddr, indices);
static std::string ensureSymbolNameIsUnique(ModuleOp moduleOp, StringRef symbolName)
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.
Operation is the basic unit of execution within MLIR.
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.
LLVM::LLVMFuncOp lookupOrCreatePrintStringFn(Operation *moduleOp, std::optional< StringRef > runtimeFunctionName={})
Declares a function to print a C-string.
void createPrintStrCall(OpBuilder &builder, Location loc, ModuleOp moduleOp, StringRef symbolName, StringRef string, const LLVMTypeConverter &typeConverter, bool addNewline=true, std::optional< StringRef > runtimeFunctionName={})
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...