Skip to content

Commit 1ab44d5

Browse files
authored
[DominanceFrontier] make iterating dereferenced DominanceFrontierBase::find deterministic (#69711)
1 parent f61179f commit 1ab44d5

File tree

4 files changed

+35
-33
lines changed

4 files changed

+35
-33
lines changed

llvm/include/llvm/Analysis/DominanceFrontier.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818
#define LLVM_ANALYSIS_DOMINANCEFRONTIER_H
1919

2020
#include "llvm/ADT/GraphTraits.h"
21+
#include "llvm/ADT/SetVector.h"
2122
#include "llvm/Config/llvm-config.h"
2223
#include "llvm/IR/PassManager.h"
2324
#include "llvm/Pass.h"
2425
#include "llvm/Support/GenericDomTree.h"
2526
#include <cassert>
2627
#include <map>
27-
#include <set>
2828
#include <utility>
2929

3030
namespace llvm {
@@ -39,7 +39,9 @@ class raw_ostream;
3939
template <class BlockT, bool IsPostDom>
4040
class DominanceFrontierBase {
4141
public:
42-
using DomSetType = std::set<BlockT *>; // Dom set for a bb
42+
// Dom set for a bb. Use SetVector to make iterating dom frontiers of a bb
43+
// deterministic.
44+
using DomSetType = SetVector<BlockT *>;
4345
using DomSetMapType = std::map<BlockT *, DomSetType>; // Dom set map
4446

4547
protected:

llvm/include/llvm/Analysis/DominanceFrontierImpl.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ template <class BlockT, bool IsPostDom>
4949
void DominanceFrontierBase<BlockT, IsPostDom>::removeBlock(BlockT *BB) {
5050
assert(find(BB) != end() && "Block is not in DominanceFrontier!");
5151
for (iterator I = begin(), E = end(); I != E; ++I)
52-
I->second.erase(BB);
52+
I->second.remove(BB);
5353
Frontiers.erase(BB);
5454
}
5555

@@ -65,7 +65,7 @@ void DominanceFrontierBase<BlockT, IsPostDom>::removeFromFrontier(
6565
iterator I, BlockT *Node) {
6666
assert(I != end() && "BB is not in DominanceFrontier!");
6767
assert(I->second.count(Node) && "Node is not in DominanceFrontier of BB");
68-
I->second.erase(Node);
68+
I->second.remove(Node);
6969
}
7070

7171
template <class BlockT, bool IsPostDom>
@@ -133,7 +133,7 @@ void DominanceFrontierBase<BlockT, IsPostDom>::print(raw_ostream &OS) const {
133133
OS << " <<exit node>>";
134134
OS << " is:\t";
135135

136-
const std::set<BlockT *> &BBs = I->second;
136+
const SetVector<BlockT *> &BBs = I->second;
137137

138138
for (const BlockT *BB : BBs) {
139139
OS << ' ';

llvm/include/llvm/Analysis/RegionInfoImpl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ bool RegionInfoBase<Tr>::isRegion(BlockT *entry, BlockT *exit) const {
587587
for (BlockT *Succ : *entrySuccs) {
588588
if (Succ == exit || Succ == entry)
589589
continue;
590-
if (exitSuccs->find(Succ) == exitSuccs->end())
590+
if (!exitSuccs->contains(Succ))
591591
return false;
592592
if (!isCommonDomFrontier(Succ, entry, exit))
593593
return false;

llvm/test/Analysis/DominanceFrontier/new_pm_test.ll

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,42 +9,42 @@ define void @a_linear_impl_fig_1() nounwind {
99
2:
1010
br label %3
1111
3:
12-
br i1 1, label %12, label %4
12+
br i1 1, label %a12, label %4
1313
4:
1414
br i1 1, label %5, label %1
1515
5:
16-
br i1 1, label %8, label %6
16+
br i1 1, label %a8, label %6
1717
6:
18-
br i1 1, label %7, label %4
19-
7:
18+
br i1 1, label %a7, label %4
19+
a7:
2020
ret void
21-
8:
22-
br i1 1, label %9, label %1
23-
9:
24-
br label %10
25-
10:
26-
br i1 1, label %13, label %11
27-
11:
28-
br i1 1, label %9, label %8
29-
12:
21+
a8:
22+
br i1 1, label %a9, label %1
23+
a9:
24+
br label %a10
25+
a10:
26+
br i1 1, label %a13, label %a11
27+
a11:
28+
br i1 1, label %a9, label %a8
29+
a12:
3030
br i1 1, label %2, label %1
31-
13:
32-
switch i32 0, label %1 [ i32 0, label %9
33-
i32 1, label %8]
31+
a13:
32+
switch i32 0, label %1 [ i32 0, label %a9
33+
i32 1, label %a8]
3434
}
3535

3636
; CHECK: DominanceFrontier for function: a_linear_impl_fig_1
3737
; CHECK-DAG: DomFrontier for BB %0 is:
38-
; CHECK-DAG: DomFrontier for BB %11 is: %{{[8|9]}} %{{[8|9]}}
38+
; CHECK-DAG: DomFrontier for BB %a11 is: %a9 %a8
3939
; CHECK-DAG: DomFrontier for BB %1 is: %1
40-
; CHECK-DAG: DomFrontier for BB %2 is: %{{[1|2]}} %{{[1|2]}}
41-
; CHECK-DAG: DomFrontier for BB %3 is: %{{[1|2]}} %{{[1|2]}}
42-
; CHECK-DAG: DomFrontier for BB %12 is: %{{[1|2]}} %{{[1|2]}}
43-
; CHECK-DAG: DomFrontier for BB %4 is: %{{[1|4]}} %{{[1|4]}}
44-
; CHECK-DAG: DomFrontier for BB %5 is: %{{[1|4]}} %{{[1|4]}}
45-
; CHECK-DAG: DomFrontier for BB %8 is: %{{[1|8]}} %{{[1|8]}}
40+
; CHECK-DAG: DomFrontier for BB %2 is: %1 %2
41+
; CHECK-DAG: DomFrontier for BB %3 is: %1 %2
42+
; CHECK-DAG: DomFrontier for BB %a12 is: %2 %1
43+
; CHECK-DAG: DomFrontier for BB %4 is: %1 %4
44+
; CHECK-DAG: DomFrontier for BB %5 is: %4 %1
45+
; CHECK-DAG: DomFrontier for BB %a8 is: %1 %a8
4646
; CHECK-DAG: DomFrontier for BB %6 is: %4
47-
; CHECK-DAG: DomFrontier for BB %7 is:
48-
; CHECK-DAG: DomFrontier for BB %9 is: %{{[1|8|9]}} %{{[1|8|9]}} %{{[1|8|9]}}
49-
; CHECK-DAG: DomFrontier for BB %10 is: %{{[1|8|9]}} %{{[1|8|9]}} %{{[1|8|9]}}
50-
; CHECK-DAG: DomFrontier for BB %13 is: %{{[1|8|9]}} %{{[1|8|9]}} %{{[1|8|9]}}
47+
; CHECK-DAG: DomFrontier for BB %a7 is:
48+
; CHECK-DAG: DomFrontier for BB %a9 is: %a9 %a8 %1
49+
; CHECK-DAG: DomFrontier for BB %a10 is: %a9 %a8 %1
50+
; CHECK-DAG: DomFrontier for BB %a13 is: %1 %a9 %a8

0 commit comments

Comments
 (0)