13#include "llvm/ADT/Hashing.h"
14#include "llvm/ADT/SmallString.h"
20 while (
auto fusedLoc = dyn_cast<FusedLoc>(loc))
21 loc = fusedLoc.getLocations().back();
25std::optional<FileLineColLoc>
29 if (
auto fileLoc = dyn_cast<FileLineColLoc>(unfusedLoc))
32 if (
auto callSiteLoc = dyn_cast<CallSiteLoc>(unfusedLoc)) {
35 if (
auto callerFileLoc =
40 if (errorOnInvalidLocation)
42 "cannot get file:line information: invalid Location information");
50 return parentFuncOp.getName();
52 return parentFuncOp.getSymName();
63 for (
Value value : values) {
74 StringRef name, StringRef value,
76 if (
auto global = module.lookupSymbol<LLVM::GlobalOp>(name))
84 nullTermStr.push_back(
'\0');
85 auto arrayTy = LLVM::LLVMArrayType::get(builder.
getI8Type(),
86 nullTermStr.size_in_bytes());
87 return LLVM::GlobalOp::create(builder, loc, arrayTy,
true,
88 LLVM::Linkage::Internal, name,
94 StringRef name, StringRef value,
98 LLVM::GlobalOp global =
101 Value globalPtr = LLVM::AddressOfOp::create(builder, loc, global);
103 LLVM::ConstantOp::create(builder, loc, i64Ty, builder.
getIndexAttr(0));
104 return LLVM::GEPOp::create(builder, loc, ptrTy, global.getType(), globalPtr,
113 Type ptrTy = LLVM::LLVMPointerType::get(ctx);
114 Type structTy = LLVM::LLVMStructType::getLiteral(
115 ctx, {i32Ty, i32Ty, i32Ty, i32Ty, ptrTy});
118 std::string sourceGlobalName;
119 if (
auto fileLineColLoc =
121 std::string filename = fileLineColLoc->getFilename().str();
122 std::string line = std::to_string(fileLineColLoc->getLine());
123 std::string column = std::to_string(fileLineColLoc->getColumn());
124 std::string functionDisplayName =
125 functionName.empty() ? std::string()
128 source += filename +
";";
129 source += functionDisplayName +
";";
130 source += line +
";";
131 source += column +
";";
133 sourceGlobalName =
"loc_";
134 sourceGlobalName += line +
"_";
135 sourceGlobalName += column +
"_";
137 std::to_string(
static_cast<uint64_t
>(llvm::hash_value(source)));
139 source =
";unknown;unknown;0;0;;";
140 sourceGlobalName =
"loc__";
143 std::string identGlobalName =
"ident_";
144 identGlobalName += sourceGlobalName;
145 auto identGlobal =
module.lookupSymbol<LLVM::GlobalOp>(identGlobalName);
148 loc, builder, sourceGlobalName, source, module);
152 identGlobal = LLVM::GlobalOp::create(
153 builder, loc, structTy,
true, LLVM::Linkage::Internal,
158 Value ident = LLVM::ZeroOp::create(builder, loc, structTy);
159 Value sourceBase = LLVM::AddressOfOp::create(builder, loc, sourceGlobal);
161 LLVM::ConstantOp::create(builder, loc, i64Ty, builder.
getIndexAttr(0));
163 LLVM::GEPOp::create(builder, loc, ptrTy, sourceGlobal.getType(),
165 ident = LLVM::InsertValueOp::create(builder, loc, structTy, ident,
167 LLVM::ReturnOp::create(builder, loc, ident);
170 return LLVM::AddressOfOp::create(builder, loc, identGlobal);
static LLVM::GlobalOp getOrCreateGlobalStringOp(Location loc, OpBuilder &builder, StringRef name, StringRef value, ModuleOp module)
Creates or reuses a module-internal null-terminated string global and returns the GlobalOp.
Attributes are known-constant values of operations.
Block represents an ordered list of Operations.
IntegerAttr getIndexAttr(int64_t value)
StringAttr getStringAttr(const Twine &bytes)
MLIRContext * getContext() const
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.
RAII guard to reset the insertion point of the builder when destroyed.
This class helps build Operations.
Block * createBlock(Region *parent, Region::iterator insertPt={}, TypeRange argTypes={}, ArrayRef< Location > locs={})
Add new block with 'argTypes' arguments and set the insertion point to the end of it.
void setInsertionPointToStart(Block *block)
Sets the insertion point to the start of the specified block.
void setInsertionPointAfter(Operation *op)
Sets the insertion point to the node after the specified operation, which will cause subsequent inser...
Operation is the basic unit of execution within MLIR.
OpTy getParentOfType()
Return the closest surrounding parent operation that is of type 'OpTy'.
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
This class provides an abstraction over the different types of ranges over Values.
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
Operation * getDefiningOp() const
If this value is the result of an operation, return the operation that defines it.
Optional overrides for OpenACC to LLVM runtime lowering.
std::string getFunctionDisplayName(StringRef mangledOrSymbol) const
std::optional< FileLineColLoc > getFileLineColLoc(Location loc, bool errorOnInvalidLocation)
Returns file:line:column location information when available.
Value getOrCreateGlobalString(Location loc, OpBuilder &builder, StringRef name, StringRef value, ModuleOp module)
Creates or reuses a module-internal null-terminated string global.
Value createIdent(Location loc, StringRef functionName, OpBuilder &builder, ModuleOp module, const ACCRuntimeCallConfig &config)
Returns a pointer to a constant global holding an ident_t for OpenACC runtime calls.
StringRef getParentFunctionName(Operation *op)
Returns the enclosing function symbol name for op.
Location unfuseLoc(Location loc)
Unfuses fused locations, returning the last sub-location.
Include the generated interface declarations.