@@ -508,29 +508,20 @@ performActions(raw_ostream &os,
508508
509509// / Parses the memory buffer. If successfully, run a series of passes against
510510// / it and print the result.
511- static LogicalResult
512- processBuffer (raw_ostream &os, std::unique_ptr<MemoryBuffer> ownedBuffer,
513- llvm::MemoryBufferRef sourceBuffer,
514- const MlirOptMainConfig &config, DialectRegistry ®istry,
515- SourceMgrDiagnosticVerifierHandler *verifyHandler,
516- llvm::ThreadPoolInterface *threadPool) {
511+ static LogicalResult processBuffer (raw_ostream &os,
512+ std::unique_ptr<MemoryBuffer> ownedBuffer,
513+ const MlirOptMainConfig &config,
514+ DialectRegistry ®istry,
515+ llvm::ThreadPoolInterface *threadPool) {
517516 // Tell sourceMgr about this buffer, which is what the parser will pick up.
518517 auto sourceMgr = std::make_shared<SourceMgr>();
519- // Add the original buffer to the source manager to use for determining
520- // locations.
521- sourceMgr->AddNewSourceBuffer (
522- llvm::MemoryBuffer::getMemBuffer (sourceBuffer,
523- /* RequiresNullTerminator=*/ false ),
524- SMLoc ());
525518 sourceMgr->AddNewSourceBuffer (std::move (ownedBuffer), SMLoc ());
526519
527520 // Create a context just for the current buffer. Disable threading on creation
528521 // since we'll inject the thread-pool separately.
529522 MLIRContext context (registry, MLIRContext::Threading::DISABLED);
530523 if (threadPool)
531524 context.setThreadPool (*threadPool);
532- if (verifyHandler)
533- verifyHandler->registerInContext (&context);
534525
535526 StringRef irdlFile = config.getIrdlFile ();
536527 if (!irdlFile.empty () && failed (loadIRDLDialects (irdlFile, context)))
@@ -554,12 +545,17 @@ processBuffer(raw_ostream &os, std::unique_ptr<MemoryBuffer> ownedBuffer,
554545 return performActions (os, sourceMgr, &context, config);
555546 }
556547
548+ SourceMgrDiagnosticVerifierHandler sourceMgrHandler (
549+ *sourceMgr, &context, config.verifyDiagnosticsLevel ());
550+
557551 // Do any processing requested by command line flags. We don't care whether
558552 // these actions succeed or fail, we only care what diagnostics they produce
559553 // and whether they match our expectations.
560554 (void )performActions (os, sourceMgr, &context, config);
561555
562- return success ();
556+ // Verify the diagnostic handler to make sure that each of the diagnostics
557+ // matched.
558+ return sourceMgrHandler.verify ();
563559}
564560
565561std::pair<std::string, std::string>
@@ -628,31 +624,14 @@ LogicalResult mlir::MlirOptMain(llvm::raw_ostream &outputStream,
628624 if (threadPoolCtx.isMultithreadingEnabled ())
629625 threadPool = &threadPoolCtx.getThreadPool ();
630626
631- SourceMgr sourceMgr;
632- sourceMgr.AddNewSourceBuffer (
633- llvm::MemoryBuffer::getMemBuffer (buffer->getMemBufferRef (),
634- /* RequiresNullTerminator=*/ false ),
635- SMLoc ());
636- // Note: this creates a verifier handler independent of the the flag set, as
637- // internally if the flag is not set, a new scoped diagnostic handler is
638- // created which would intercept the diagnostics and verify them.
639- SourceMgrDiagnosticVerifierHandler sourceMgrHandler (
640- sourceMgr, &threadPoolCtx, config.verifyDiagnosticsLevel ());
641627 auto chunkFn = [&](std::unique_ptr<MemoryBuffer> chunkBuffer,
642- llvm::MemoryBufferRef sourceBuffer, raw_ostream &os) {
643- return processBuffer (
644- os, std::move (chunkBuffer), sourceBuffer, config, registry,
645- config.shouldVerifyDiagnostics () ? &sourceMgrHandler : nullptr ,
646- threadPool);
628+ raw_ostream &os) {
629+ return processBuffer (os, std::move (chunkBuffer), config, registry,
630+ threadPool);
647631 };
648- LogicalResult status = splitAndProcessBuffer (
649- llvm::MemoryBuffer::getMemBuffer (buffer->getMemBufferRef (),
650- /* RequiresNullTerminator=*/ false ),
651- chunkFn, outputStream, config.inputSplitMarker (),
652- config.outputSplitMarker ());
653- if (config.shouldVerifyDiagnostics () && failed (sourceMgrHandler.verify ()))
654- status = failure ();
655- return status;
632+ return splitAndProcessBuffer (std::move (buffer), chunkFn, outputStream,
633+ config.inputSplitMarker (),
634+ config.outputSplitMarker ());
656635}
657636
658637LogicalResult mlir::MlirOptMain (int argc, char **argv,
0 commit comments