@@ -218,12 +218,18 @@ struct ConsoleReproducerStream : public mlir::ReproducerStream {
218218 raw_ostream &os () override { return llvm::errs (); }
219219};
220220
221- static ReproducerStreamFactory makeConsoleReproducer () {
221+ ReproducerStreamFactory makeConsoleReproducer () {
222222 return [](std::string &error) -> std::unique_ptr<ReproducerStream> {
223223 return std::make_unique<ConsoleReproducerStream>();
224224 };
225225}
226226
227+ OpPrintingFlags getOpPrintingFlags () {
228+ auto printingFlags = OpPrintingFlags ();
229+ printingFlags.enableDebugInfo ();
230+ return printingFlags;
231+ }
232+
227233} // anonymous namespace
228234
229235/* ****************************************************************************/
@@ -511,8 +517,7 @@ void init_triton_ir(py::module &&m) {
511517 [](OpState &self) -> std::string {
512518 std::string str;
513519 llvm::raw_string_ostream os (str);
514- auto printingFlags = OpPrintingFlags ();
515- printingFlags.enableDebugInfo ();
520+ auto printingFlags = getOpPrintingFlags ();
516521 self->print (os, printingFlags);
517522 return str;
518523 })
@@ -583,8 +588,7 @@ void init_triton_ir(py::module &&m) {
583588 [](ModuleOp &self) -> std::string {
584589 std::string str;
585590 llvm::raw_string_ostream os (str);
586- auto printingFlags = OpPrintingFlags ();
587- printingFlags.enableDebugInfo ();
591+ auto printingFlags = getOpPrintingFlags ();
588592 self.print (os, printingFlags);
589593 return str;
590594 })
@@ -658,9 +662,9 @@ void init_triton_ir(py::module &&m) {
658662 })
659663 .def (" create_location_snapshot" ,
660664 [](ModuleOp &self, const std::string &fileName) -> void {
661- generateLocationsFromIR ( /* raw_ostream= */ llvm::nulls (),
662- /* fileName= */ fileName,
663- /* op= */ self, /* flags= */ {} );
665+ auto printingFlags = getOpPrintingFlags ();
666+ if ( failed ( generateLocationsFromIR ( fileName, self, printingFlags)))
667+ throw std::runtime_error ( " Failed to create location snapshot " );
664668 })
665669 .def (" walk" ,
666670 [](ModuleOp &self, const std::function<void (Operation *)> &fn) {
@@ -1780,9 +1784,8 @@ void init_triton_ir(py::module &&m) {
17801784 }
17811785 if (haveDump) {
17821786 context->disableMultithreading ();
1783- auto printingFlags = OpPrintingFlags ();
1787+ auto printingFlags = getOpPrintingFlags ();
17841788 printingFlags.elideLargeElementsAttrs (16 );
1785- printingFlags.enableDebugInfo ();
17861789 auto printAlways = [funcToDump](Pass *, Operation *op) -> bool {
17871790 if (funcToDump.empty ())
17881791 return true ;
0 commit comments