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 =
111 return ::generateLocationsFromIR(fileName, op, flags, StringRef());
129 return ::generateLocationsFromIR(fileName, op, flags, tag);
133struct LocationSnapshotPass
137 void runOnOperation()
override {
140 return signalPassFailure();
145 OpPrintingFlags getFlags() {
146 OpPrintingFlags flags;
This class provides management for the lifetime of the state used when printing the IR.
DenseMap< Operation *, std::pair< unsigned, unsigned > > LocationMap
This map represents the raw locations of operations within the output stream.
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.
InFlightDiagnostic emitError(const Twine &message={})
Emit an error about fatal conditions with this operation, reporting up to any diagnostic handlers tha...
void print(raw_ostream &os, const OpPrintingFlags &flags={})
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),...
MLIRContext * getContext()
Return the context this operation is associated with.
Include the generated interface declarations.
std::unique_ptr< llvm::ToolOutputFile > openOutputFile(llvm::StringRef outputFilename, std::string *errorMessage=nullptr)
Open the file specified by its name for writing.
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,...