@@ -220,6 +220,10 @@ static cl::opt<int>
220
220
static cl::opt<std::string>
221
221
McpuOpt (" mcpu" , cl::init(" " ), cl::desc(" Target CPU" ), cl::cat(toolOptions));
222
222
223
+ static cl::opt<bool > PMEnablePrinting (
224
+ " pm-enable-printing" , cl::init(false ),
225
+ cl::desc(" Enable printing of IR before and after all passes" ));
226
+
223
227
#include " mlir/Dialect/LLVMIR/LLVMDialect.h"
224
228
225
229
class PolygeistCudaDetectorArgList : public llvm ::opt::ArgList {
@@ -409,18 +413,6 @@ int emitBinary(char *Argv0, const char *filename,
409
413
return Res;
410
414
}
411
415
412
- #define dump_module (PASS_MANAGER, EXEC ) \
413
- do { \
414
- llvm::errs () << " at line" << __LINE__ << " \n " ; \
415
- (void )PASS_MANAGER.run (module .get ()); \
416
- module ->dump (); \
417
- EXEC; \
418
- } while (0 )
419
- #undef dump_module
420
- #define dump_module (PASS_MANAGER, EXEC ) \
421
- do { \
422
- } while (0 )
423
-
424
416
#include " Lib/clang-mlir.cc"
425
417
int main (int argc, char **argv) {
426
418
@@ -539,7 +531,29 @@ int main(int argc, char **argv) {
539
531
parseMLIR (argv[0 ], files, cfunction, includeDirs, defines, module , triple, DL,
540
532
gpuTriple, gpuDL);
541
533
534
+ auto convertGepInBounds = [](llvm::Module &llvmModule) {
535
+ for (auto &F : llvmModule) {
536
+ for (auto &BB : F) {
537
+ for (auto &I : BB) {
538
+ if (auto g = dyn_cast<GetElementPtrInst>(&I))
539
+ g->setIsInBounds (true );
540
+ }
541
+ }
542
+ }
543
+ };
544
+ auto addLICM = [](auto &pm) {
545
+ if (ParallelLICM)
546
+ pm.addPass (polygeist::createParallelLICMPass ());
547
+ else
548
+ pm.addPass (mlir::createLoopInvariantCodeMotionPass ());
549
+ };
550
+ auto enablePrinting = [](auto &pm) {
551
+ if (PMEnablePrinting)
552
+ pm.enableIRPrinting ();
553
+ };
554
+
542
555
mlir::PassManager pm (&context);
556
+ enablePrinting (pm);
543
557
544
558
OpPrintingFlags flags;
545
559
if (PrintDebugInfo)
@@ -568,24 +582,6 @@ int main(int argc, char **argv) {
568
582
}
569
583
#endif
570
584
571
- auto convertGepInBounds = [](llvm::Module &llvmModule) {
572
- for (auto &F : llvmModule) {
573
- for (auto &BB : F) {
574
- for (auto &I : BB) {
575
- if (auto g = dyn_cast<GetElementPtrInst>(&I))
576
- g->setIsInBounds (true );
577
- }
578
- }
579
- }
580
- };
581
- bool ParallelLICM_ = ParallelLICM;
582
- auto addLICM = [&ParallelLICM_](auto &pm) {
583
- if (ParallelLICM)
584
- pm.addPass (polygeist::createParallelLICMPass ());
585
- else
586
- pm.addPass (mlir::createLoopInvariantCodeMotionPass ());
587
- };
588
-
589
585
int unrollSize = 32 ;
590
586
bool LinkOMP = FOpenMP;
591
587
pm.enableVerifier (EarlyVerifier);
@@ -634,6 +630,7 @@ int main(int argc, char **argv) {
634
630
#define pm pm2
635
631
{
636
632
mlir::PassManager pm (&context);
633
+ enablePrinting (pm);
637
634
mlir::OpPassManager &optPM = pm.nest <mlir::func::FuncOp>();
638
635
639
636
if (DetectReduction)
@@ -678,6 +675,7 @@ int main(int argc, char **argv) {
678
675
679
676
if (CudaLower) {
680
677
mlir::PassManager pm (&context);
678
+ enablePrinting (pm);
681
679
mlir::OpPassManager &optPM = pm.nest <mlir::func::FuncOp>();
682
680
optPM.addPass (mlir::createLowerAffinePass ());
683
681
optPM.addPass (mlir::createCanonicalizerPass (canonicalizerConfig, {}, {}));
@@ -746,6 +744,7 @@ int main(int argc, char **argv) {
746
744
}
747
745
748
746
mlir::PassManager pm (&context);
747
+ enablePrinting (pm);
749
748
mlir::OpPassManager &optPM = pm.nest <mlir::func::FuncOp>();
750
749
if (CudaLower) {
751
750
optPM.addPass (mlir::createCanonicalizerPass (canonicalizerConfig, {}, {}));
@@ -861,6 +860,7 @@ int main(int argc, char **argv) {
861
860
862
861
if (EmitLLVM || !EmitAssembly || EmitOpenMPIR || EmitLLVMDialect) {
863
862
mlir::PassManager pm2 (&context);
863
+ enablePrinting (pm2);
864
864
if (SCFOpenMP) {
865
865
pm2.addPass (createConvertSCFToOpenMPPass ());
866
866
} else
@@ -880,6 +880,7 @@ int main(int argc, char **argv) {
880
880
if (!EmitOpenMPIR) {
881
881
module ->walk ([&](mlir::omp::ParallelOp) { LinkOMP = true ; });
882
882
mlir::PassManager pm3 (&context);
883
+ enablePrinting (pm3);
883
884
LowerToLLVMOptions options (&context);
884
885
options.dataLayout = DL;
885
886
// invalid for gemm.c init array
0 commit comments