diff --git a/llvm/lib/IR/PassInstrumentation.cpp b/llvm/lib/IR/PassInstrumentation.cpp --- a/llvm/lib/IR/PassInstrumentation.cpp +++ b/llvm/lib/IR/PassInstrumentation.cpp @@ -19,7 +19,8 @@ void PassInstrumentationCallbacks::addClassToPassName(StringRef ClassName, StringRef PassName) { - ClassToPassName[ClassName] = PassName.str(); + if (ClassToPassName[ClassName].empty()) + ClassToPassName[ClassName] = PassName.str(); } StringRef diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp --- a/llvm/lib/Passes/PassBuilder.cpp +++ b/llvm/lib/Passes/PassBuilder.cpp @@ -456,10 +456,14 @@ PIC->addClassToPassName(decltype(CREATE_PASS)::name(), NAME); #define FUNCTION_PASS(NAME, CREATE_PASS) \ PIC->addClassToPassName(decltype(CREATE_PASS)::name(), NAME); +#define FUNCTION_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \ + PIC->addClassToPassName(CLASS, NAME); #define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \ PIC->addClassToPassName(decltype(CREATE_PASS)::name(), NAME); #define LOOP_PASS(NAME, CREATE_PASS) \ PIC->addClassToPassName(decltype(CREATE_PASS)::name(), NAME); +#define LOOP_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \ + PIC->addClassToPassName(CLASS, NAME); #define LOOP_ANALYSIS(NAME, CREATE_PASS) \ PIC->addClassToPassName(decltype(CREATE_PASS)::name(), NAME); #define CGSCC_PASS(NAME, CREATE_PASS) \ @@ -2407,7 +2411,7 @@ #define FUNCTION_PASS(NAME, CREATE_PASS) \ if (Name == NAME) \ return true; -#define FUNCTION_PASS_WITH_PARAMS(NAME, CREATE_PASS, PARSER, PARAMS) \ +#define FUNCTION_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \ if (checkParametrizedPassName(Name, NAME)) \ return true; #define FUNCTION_ANALYSIS(NAME, CREATE_PASS) \ @@ -2431,7 +2435,7 @@ #define LOOP_PASS(NAME, CREATE_PASS) \ if (Name == NAME) \ return true; -#define LOOP_PASS_WITH_PARAMS(NAME, CREATE_PASS, PARSER, PARAMS) \ +#define LOOP_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \ if (checkParametrizedPassName(Name, NAME)) \ return true; #define LOOP_ANALYSIS(NAME, CREATE_PASS) \ @@ -2621,7 +2625,7 @@ MPM.addPass(createModuleToFunctionPassAdaptor(CREATE_PASS)); \ return Error::success(); \ } -#define FUNCTION_PASS_WITH_PARAMS(NAME, CREATE_PASS, PARSER, PARAMS) \ +#define FUNCTION_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \ if (checkParametrizedPassName(Name, NAME)) { \ auto Params = parsePassParameters(PARSER, Name, NAME); \ if (!Params) \ @@ -2635,7 +2639,7 @@ createFunctionToLoopPassAdaptor(CREATE_PASS, false, false))); \ return Error::success(); \ } -#define LOOP_PASS_WITH_PARAMS(NAME, CREATE_PASS, PARSER, PARAMS) \ +#define LOOP_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \ if (checkParametrizedPassName(Name, NAME)) { \ auto Params = parsePassParameters(PARSER, Name, NAME); \ if (!Params) \ @@ -2728,7 +2732,7 @@ CGPM.addPass(createCGSCCToFunctionPassAdaptor(CREATE_PASS)); \ return Error::success(); \ } -#define FUNCTION_PASS_WITH_PARAMS(NAME, CREATE_PASS, PARSER, PARAMS) \ +#define FUNCTION_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \ if (checkParametrizedPassName(Name, NAME)) { \ auto Params = parsePassParameters(PARSER, Name, NAME); \ if (!Params) \ @@ -2742,7 +2746,7 @@ createFunctionToLoopPassAdaptor(CREATE_PASS, false, false))); \ return Error::success(); \ } -#define LOOP_PASS_WITH_PARAMS(NAME, CREATE_PASS, PARSER, PARAMS) \ +#define LOOP_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \ if (checkParametrizedPassName(Name, NAME)) { \ auto Params = parsePassParameters(PARSER, Name, NAME); \ if (!Params) \ @@ -2813,7 +2817,7 @@ FPM.addPass(CREATE_PASS); \ return Error::success(); \ } -#define FUNCTION_PASS_WITH_PARAMS(NAME, CREATE_PASS, PARSER, PARAMS) \ +#define FUNCTION_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \ if (checkParametrizedPassName(Name, NAME)) { \ auto Params = parsePassParameters(PARSER, Name, NAME); \ if (!Params) \ @@ -2842,7 +2846,7 @@ FPM.addPass(createFunctionToLoopPassAdaptor(CREATE_PASS, false, false)); \ return Error::success(); \ } -#define LOOP_PASS_WITH_PARAMS(NAME, CREATE_PASS, PARSER, PARAMS) \ +#define LOOP_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \ if (checkParametrizedPassName(Name, NAME)) { \ auto Params = parsePassParameters(PARSER, Name, NAME); \ if (!Params) \ @@ -2900,7 +2904,7 @@ LPM.addPass(CREATE_PASS); \ return Error::success(); \ } -#define LOOP_PASS_WITH_PARAMS(NAME, CREATE_PASS, PARSER, PARAMS) \ +#define LOOP_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \ if (checkParametrizedPassName(Name, NAME)) { \ auto Params = parsePassParameters(PARSER, Name, NAME); \ if (!Params) \ @@ -3193,7 +3197,7 @@ #include "PassRegistry.def" OS << "Function passes with params:\n"; -#define FUNCTION_PASS_WITH_PARAMS(NAME, CREATE_PASS, PARSER, PARAMS) \ +#define FUNCTION_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \ printPassName(NAME, PARAMS, OS); #include "PassRegistry.def" @@ -3210,7 +3214,7 @@ #include "PassRegistry.def" OS << "Loop passes with params:\n"; -#define LOOP_PASS_WITH_PARAMS(NAME, CREATE_PASS, PARSER, PARAMS) \ +#define LOOP_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) \ printPassName(NAME, PARAMS, OS); #include "PassRegistry.def" diff --git a/llvm/lib/Passes/PassRegistry.def b/llvm/lib/Passes/PassRegistry.def --- a/llvm/lib/Passes/PassRegistry.def +++ b/llvm/lib/Passes/PassRegistry.def @@ -331,9 +331,10 @@ #undef FUNCTION_PASS #ifndef FUNCTION_PASS_WITH_PARAMS -#define FUNCTION_PASS_WITH_PARAMS(NAME, CREATE_PASS, PARSER, PARAMS) +#define FUNCTION_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) #endif FUNCTION_PASS_WITH_PARAMS("loop-unroll", + "LoopUnrollPass", [](LoopUnrollOptions Opts) { return LoopUnrollPass(Opts); }, @@ -345,12 +346,14 @@ "no-runtime;runtime;" "no-upperbound;upperbound") FUNCTION_PASS_WITH_PARAMS("msan", + "MemorySanitizerPass", [](MemorySanitizerOptions Opts) { return MemorySanitizerPass(Opts); }, parseMSanPassOptions, "recover;kernel;track-origins=N") FUNCTION_PASS_WITH_PARAMS("simplify-cfg", + "SimplifyCFGPass", [](SimplifyCFGOptions Opts) { return SimplifyCFGPass(Opts); }, @@ -363,6 +366,7 @@ "bonus-inst-threshold=N" ) FUNCTION_PASS_WITH_PARAMS("loop-vectorize", + "LoopVectorizePass", [](LoopVectorizeOptions Opts) { return LoopVectorizePass(Opts); }, @@ -370,12 +374,14 @@ "no-interleave-forced-only;interleave-forced-only;" "no-vectorize-forced-only;vectorize-forced-only") FUNCTION_PASS_WITH_PARAMS("mldst-motion", + "MergedLoadStoreMotionPass", [](MergedLoadStoreMotionOptions Opts) { return MergedLoadStoreMotionPass(Opts); }, parseMergedLoadStoreMotionOptions, "no-split-footer-bb;split-footer-bb") FUNCTION_PASS_WITH_PARAMS("gvn", + "GVN", [](GVNOptions Opts) { return GVN(Opts); }, @@ -385,6 +391,7 @@ "no-split-backedge-load-pre;split-backedge-load-pre;" "no-memdep;memdep") FUNCTION_PASS_WITH_PARAMS("print", + "StackLifetimePrinterPass", [](StackLifetime::LivenessType Type) { return StackLifetimePrinterPass(dbgs(), Type); }, @@ -436,9 +443,10 @@ #undef LOOP_PASS #ifndef LOOP_PASS_WITH_PARAMS -#define LOOP_PASS_WITH_PARAMS(NAME, CREATE_PASS, PARSER, PARAMS) +#define LOOP_PASS_WITH_PARAMS(NAME, CLASS, CREATE_PASS, PARSER, PARAMS) #endif LOOP_PASS_WITH_PARAMS("unswitch", + "SimpleLoopUnswitchPass", [](bool NonTrivial) { return SimpleLoopUnswitchPass(NonTrivial); }, diff --git a/llvm/test/Other/print-before-after.ll b/llvm/test/Other/print-before-after.ll --- a/llvm/test/Other/print-before-after.ll +++ b/llvm/test/Other/print-before-after.ll @@ -8,6 +8,8 @@ ; RUN: opt < %s -disable-output -passes='no-op-function' -print-after=no-op-function 2>&1 | FileCheck %s --check-prefix=ONCE ; RUN: opt < %s -disable-output -passes='no-op-module,no-op-function' -print-before=no-op-function --print-module-scope 2>&1 | FileCheck %s --check-prefix=TWICE ; RUN: opt < %s -disable-output -passes='no-op-module,no-op-function' -print-after=no-op-function --print-module-scope 2>&1 | FileCheck %s --check-prefix=TWICE +; RUN: opt < %s -disable-output -passes='loop-vectorize' -print-before=loop-vectorize -print-after=loop-vectorize 2>&1 | FileCheck %s --check-prefix=CHECK-LV --allow-empty +; RUN: opt < %s -disable-output -passes='simple-loop-unswitch,unswitch' -print-before=unswitch -print-after=simple-loop-unswitch 2>&1 | FileCheck %s --check-prefix=CHECK-UNSWITCH --allow-empty ; NONE-NOT: @foo ; NONE-NOT: @bar @@ -24,10 +26,28 @@ ; TWICE-NOT: @foo ; TWICE-NOT: @bar +; Verify that we can handle function passes with params. +; CHECK-LV: *** IR Dump Before LoopVectorizePass on foo *** +; CHECK-LV: *** IR Dump After LoopVectorizePass on foo *** +; CHECK-LV: *** IR Dump Before LoopVectorizePass on bar *** +; CHECK-LV: *** IR Dump After LoopVectorizePass on bar *** + +; Verify that we can handle loop passes with params. +; FIXME: The SimpleLoopUnswitchPass is extra complicated as we have different +; pass names mapping to the same class name. But we currently only use a 1-1 +; mapping, so we do not get the -print-before=unswitch printout here. +; XXXCHECK-UNSWITCH: *** IR Dump Before SimpleLoopUnswitchPass on Loop at depth 1 containing +; CHECK-UNSWITCH: *** IR Dump After SimpleLoopUnswitchPass on Loop at depth 1 containing +; XXXCHECK-UNSWITCH: *** IR Dump Before SimpleLoopUnswitchPass on Loop at depth 1 containing +; CHECK-UNSWITCH: *** IR Dump After SimpleLoopUnswitchPass on Loop at depth 1 containing + define void @foo() { ret void } define void @bar() { - ret void +entry: + br label %loop +loop: + br label %loop }