Skip to content

Commit d9500f5

Browse files
committed
[OpenMP] Fix the OpenMPOpt pass incorrectly optimizing if definition was missing
Summary: This code is intended to block transformations if the call isn't present, however the way it's coded it silently lets it pass if the definition doesn't exist at all. This previously was always valid since we included the runtime as one giant blob so everything was always there, but now that we want to move towards separate ones, it's not quite correct.
1 parent 7811c20 commit d9500f5

File tree

3 files changed

+50
-435
lines changed

3 files changed

+50
-435
lines changed

llvm/lib/Passes/PassBuilderPipelines.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -969,7 +969,7 @@ PassBuilder::buildInlinerPipeline(OptimizationLevel Level,
969969
// Try to perform OpenMP specific optimizations. This is a (quick!) no-op if
970970
// there are no OpenMP runtime calls present in the module.
971971
if (Level == OptimizationLevel::O2 || Level == OptimizationLevel::O3)
972-
MainCGPipeline.addPass(OpenMPOptCGSCCPass());
972+
MainCGPipeline.addPass(OpenMPOptCGSCCPass(Phase));
973973

974974
invokeCGSCCOptimizerLateEPCallbacks(MainCGPipeline, Level);
975975

@@ -1137,7 +1137,7 @@ PassBuilder::buildModuleSimplificationPipeline(OptimizationLevel Level,
11371137

11381138
// Try to perform OpenMP specific optimizations on the module. This is a
11391139
// (quick!) no-op if there are no OpenMP runtime calls present in the module.
1140-
MPM.addPass(OpenMPOptPass());
1140+
MPM.addPass(OpenMPOptPass(Phase));
11411141

11421142
if (AttributorRun & AttributorRunOption::MODULE)
11431143
MPM.addPass(AttributorPass());

llvm/lib/Transforms/IPO/OpenMPOpt.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ struct OMPInformationCache : public InformationCache {
569569
for (RuntimeFunction Fn : Fns) {
570570
RuntimeFunctionInfo &RFI = RFIs[Fn];
571571

572-
if (RFI.Declaration && RFI.Declaration->isDeclaration())
572+
if (!RFI.Declaration || RFI.Declaration->isDeclaration())
573573
return false;
574574
}
575575
return true;
@@ -5792,6 +5792,7 @@ PreservedAnalyses OpenMPOptPass::run(Module &M, ModuleAnalysisManager &AM) {
57925792
CallGraphUpdater CGUpdater;
57935793

57945794
bool PostLink = LTOPhase == ThinOrFullLTOPhase::FullLTOPostLink ||
5795+
LTOPhase == ThinOrFullLTOPhase::ThinLTOPostLink ||
57955796
LTOPhase == ThinOrFullLTOPhase::ThinLTOPreLink;
57965797
OMPInformationCache InfoCache(M, AG, Allocator, /*CGSCC*/ nullptr, PostLink);
57975798

@@ -5871,6 +5872,7 @@ PreservedAnalyses OpenMPOptCGSCCPass::run(LazyCallGraph::SCC &C,
58715872
CGUpdater.initialize(CG, C, AM, UR);
58725873

58735874
bool PostLink = LTOPhase == ThinOrFullLTOPhase::FullLTOPostLink ||
5875+
LTOPhase == ThinOrFullLTOPhase::ThinLTOPostLink ||
58745876
LTOPhase == ThinOrFullLTOPhase::ThinLTOPreLink;
58755877
SetVector<Function *> Functions(SCC.begin(), SCC.end());
58765878
OMPInformationCache InfoCache(*(Functions.back()->getParent()), AG, Allocator,

0 commit comments

Comments
 (0)