16 #include "llvm/Support/FileSystem.h"
17 #include "llvm/Support/ToolOutputFile.h"
21 #define GEN_PASS_DEF_LOCATIONSNAPSHOT
22 #include "mlir/Transforms/Passes.h.inc"
37 AsmState state(op, flags, &opToLineCol);
41 std::optional<StringAttr> tagIdentifier;
51 auto it = opToLineCol.find(opIt);
52 if (it == opToLineCol.end())
54 const std::pair<unsigned, unsigned> &lineCol = it->second;
65 {opIt->getLoc(), NameLoc::get(*tagIdentifier, newLoc)}));
77 if (filepath.empty()) {
78 if (std::error_code error = llvm::sys::fs::createTemporaryFile(
79 "mlir_snapshot",
"tmp.mlir", filepath)) {
81 <<
"failed to generate temporary file for location snapshot: "
88 std::unique_ptr<llvm::ToolOutputFile> outputFile =
133 struct LocationSnapshotPass
134 :
public impl::LocationSnapshotBase<LocationSnapshotPass> {
135 using impl::LocationSnapshotBase<LocationSnapshotPass>::LocationSnapshotBase;
137 void runOnOperation()
override {
140 return signalPassFailure();
static void generateLocationsFromIR(raw_ostream &os, StringRef fileName, Operation *op, const OpPrintingFlags &flags, StringRef tag)
This function generates new locations from the given IR by snapshotting the IR to the given stream,...
This class provides management for the lifetime of the state used when printing the IR.
This class is a general helper class for creating context-global objects like types,...
StringAttr getStringAttr(const Twine &bytes)
Location getFusedLoc(ArrayRef< Location > locs, Attribute metadata=Attribute())
static FileLineColLoc get(StringAttr filename, unsigned line, unsigned column)
Set of flags used to control the behavior of the various IR print methods (e.g.
OpPrintingFlags & enableDebugInfo(bool enable=true, bool prettyForm=false)
Enable or disable printing of debug information (based on enable).
OpPrintingFlags & printGenericOpForm(bool enable=true)
Always print operations in the generic form.
OpPrintingFlags & useLocalScope(bool enable=true)
Use local scope when printing the operation.
Operation is the basic unit of execution within MLIR.
void setLoc(Location loc)
Set the source location the operation was defined or derived from.
std::enable_if_t< llvm::function_traits< std::decay_t< FnT > >::num_args==1, RetT > walk(FnT &&callback)
Walk the operation by calling the callback for each nested operation (including this one),...
void print(raw_ostream &os, const OpPrintingFlags &flags=std::nullopt)
MLIRContext * getContext()
Return the context this operation is associated with.
InFlightDiagnostic emitError(const Twine &message={})
Emit an error about fatal conditions with this operation, reporting up to any diagnostic handlers tha...
Include the generated interface declarations.
void generateLocationsFromIR(raw_ostream &os, StringRef fileName, Operation *op, OpPrintingFlags flags)
This function generates new locations from the given IR by snapshotting the IR to the given stream,...
std::unique_ptr< llvm::ToolOutputFile > openOutputFile(llvm::StringRef outputFilename, std::string *errorMessage=nullptr)
Open the file specified by its name for writing.