Skip to content

Commit ee17263

Browse files
committed
[OpenMPOpt] Make the SCC a vector to ensure deterministic results
1 parent e128f71 commit ee17263

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

llvm/lib/Transforms/IPO/OpenMPOpt.cpp

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ static constexpr auto TAG = "[" DEBUG_TYPE "]";
5151
namespace {
5252
struct OpenMPOpt {
5353

54-
OpenMPOpt(SmallPtrSetImpl<Function *> &SCC,
54+
OpenMPOpt(SmallVectorImpl<Function *> &SCC,
5555
SmallPtrSetImpl<Function *> &ModuleSlice,
5656
CallGraphUpdater &CGUpdater)
5757
: M(*(*SCC.begin())->getParent()), SCC(SCC), ModuleSlice(ModuleSlice),
@@ -475,7 +475,7 @@ struct OpenMPOpt {
475475
Module &M;
476476

477477
/// The SCC we are operating on.
478-
SmallPtrSetImpl<Function *> &SCC;
478+
SmallVectorImpl<Function *> &SCC;
479479

480480
/// The slice of the module we are allowed to look at.
481481
SmallPtrSetImpl<Function *> &ModuleSlice;
@@ -503,17 +503,20 @@ PreservedAnalyses OpenMPOptPass::run(LazyCallGraph::SCC &C,
503503
if (DisableOpenMPOptimizations)
504504
return PreservedAnalyses::all();
505505

506-
SmallPtrSet<Function *, 16> SCC;
507-
for (LazyCallGraph::Node &N : C)
508-
SCC.insert(&N.getFunction());
506+
SmallPtrSet<Function *, 16> ModuleSlice;
507+
SmallVector<Function *, 16> SCC;
508+
for (LazyCallGraph::Node &N : C) {
509+
SCC.push_back(&N.getFunction());
510+
ModuleSlice.insert(SCC.back());
511+
}
509512

510513
if (SCC.empty())
511514
return PreservedAnalyses::all();
512515

513516
CallGraphUpdater CGUpdater;
514517
CGUpdater.initialize(CG, C, AM, UR);
515518
// TODO: Compute the module slice we are allowed to look at.
516-
OpenMPOpt OMPOpt(SCC, SCC, CGUpdater);
519+
OpenMPOpt OMPOpt(SCC, ModuleSlice, CGUpdater);
517520
bool Changed = OMPOpt.run();
518521
(void)Changed;
519522
return PreservedAnalyses::all();
@@ -546,11 +549,14 @@ struct OpenMPOptLegacyPass : public CallGraphSCCPass {
546549
if (DisableOpenMPOptimizations || skipSCC(CGSCC))
547550
return false;
548551

549-
SmallPtrSet<Function *, 16> SCC;
552+
SmallPtrSet<Function *, 16> ModuleSlice;
553+
SmallVector<Function *, 16> SCC;
550554
for (CallGraphNode *CGN : CGSCC)
551555
if (Function *Fn = CGN->getFunction())
552-
if (!Fn->isDeclaration())
553-
SCC.insert(Fn);
556+
if (!Fn->isDeclaration()) {
557+
SCC.push_back(Fn);
558+
ModuleSlice.insert(Fn);
559+
}
554560

555561
if (SCC.empty())
556562
return false;
@@ -559,7 +565,7 @@ struct OpenMPOptLegacyPass : public CallGraphSCCPass {
559565
CGUpdater.initialize(CG, CGSCC);
560566

561567
// TODO: Compute the module slice we are allowed to look at.
562-
OpenMPOpt OMPOpt(SCC, SCC, CGUpdater);
568+
OpenMPOpt OMPOpt(SCC, ModuleSlice, CGUpdater);
563569
return OMPOpt.run();
564570
}
565571

0 commit comments

Comments
 (0)