15 #include "llvm/Support/FileSystem.h"
16 #include "llvm/Support/ToolOutputFile.h"
20 #define GEN_PASS_DEF_LOCATIONSNAPSHOT
21 #include "mlir/Transforms/Passes.h.inc"
36 AsmState state(op, flags, &opToLineCol);
40 std::optional<StringAttr> tagIdentifier;
50 auto it = opToLineCol.find(opIt);
51 if (it == opToLineCol.end())
53 const std::pair<unsigned, unsigned> &lineCol = it->second;
64 {opIt->getLoc(), NameLoc::get(*tagIdentifier, newLoc)}));
76 if (filepath.empty()) {
77 if (std::error_code error = llvm::sys::fs::createTemporaryFile(
78 "mlir_snapshot",
"tmp.mlir", filepath)) {
80 <<
"failed to generate temporary file for location snapshot: "
87 std::unique_ptr<llvm::ToolOutputFile> outputFile =
132 struct LocationSnapshotPass
133 :
public impl::LocationSnapshotBase<LocationSnapshotPass> {
134 LocationSnapshotPass() =
default;
135 LocationSnapshotPass(
OpPrintingFlags flags, StringRef fileName, StringRef tag)
137 this->fileName = fileName.str();
138 this->tag = tag.str();
141 void runOnOperation()
override {
144 return signalPassFailure();
155 return std::make_unique<LocationSnapshotPass>(flags, fileName, tag);
158 return std::make_unique<LocationSnapshotPass>();
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.
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< Pass > createLocationSnapshotPass(OpPrintingFlags flags, StringRef fileName="", StringRef tag="")
Create a pass to generate new locations by snapshotting the IR to the given file, and using the print...
std::unique_ptr< llvm::ToolOutputFile > openOutputFile(llvm::StringRef outputFilename, std::string *errorMessage=nullptr)
Open the file specified by its name for writing.