10 #include "PassDetail.h" 14 #include "llvm/Support/FileSystem.h" 15 #include "llvm/Support/ToolOutputFile.h" 29 AsmState state(op, flags, &opToLineCol);
35 tagIdentifier = builder.getStringAttr(tag);
38 StringAttr file = builder.getStringAttr(fileName);
43 auto it = opToLineCol.find(opIt);
44 if (it == opToLineCol.end())
46 const std::pair<unsigned, unsigned> &lineCol = it->second;
47 auto newLoc = FileLineColLoc::get(file, lineCol.first, lineCol.second);
56 opIt->
setLoc(builder.getFusedLoc(
57 {opIt->getLoc(), NameLoc::get(*tagIdentifier, newLoc)}));
69 if (filepath.empty()) {
70 if (std::error_code error = llvm::sys::fs::createTemporaryFile(
71 "mlir_snapshot",
"tmp.mlir", filepath)) {
73 <<
"failed to generate temporary file for location snapshot: " 80 std::unique_ptr<llvm::ToolOutputFile> outputFile =
125 struct LocationSnapshotPass
126 :
public LocationSnapshotBase<LocationSnapshotPass> {
127 LocationSnapshotPass() =
default;
128 LocationSnapshotPass(
OpPrintingFlags flags, StringRef fileName, StringRef tag)
130 this->fileName = fileName.str();
131 this->tag = tag.str();
134 void runOnOperation()
override {
137 return signalPassFailure();
148 return std::make_unique<LocationSnapshotPass>(flags, fileName, tag);
151 return std::make_unique<LocationSnapshotPass>();
Include the generated interface declarations.
Operation is a basic unit of execution within MLIR.
bool failed(LogicalResult result)
Utility function that returns true if the provided LogicalResult corresponds to a failure value...
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...
MLIRContext * getContext()
Return the context this operation is associated with.
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...
LogicalResult success(bool isSuccess=true)
Utility function to generate a LogicalResult.
std::enable_if< llvm::function_traits< std::decay_t< FnT > >::num_args==1, RetT >::type walk(FnT &&callback)
Walk the operation by calling the callback for each nested operation (including this one)...
This class represents an efficient way to signal success or failure.
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...
void print(raw_ostream &os, const OpPrintingFlags &flags=llvm::None)
Set of flags used to control the behavior of the various IR print methods (e.g.
This class is a general helper class for creating context-global objects like types, attributes, and affine expressions.
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...
This class provides management for the lifetime of the state used when printing the IR...