@@ -57,8 +57,6 @@ class SBFAdjustOptImpl {
57
57
Module *M;
58
58
SmallVector<PassThroughInfo, 16 > PassThroughs;
59
59
60
- void adjustBasicBlock (BasicBlock &BB);
61
- bool serializeICMPCrossBB (BasicBlock &BB);
62
60
void adjustInst (Instruction &I);
63
61
bool serializeICMPInBB (Instruction &I);
64
62
bool avoidSpeculation (Instruction &I);
@@ -70,7 +68,6 @@ class SBFAdjustOptImpl {
70
68
bool SBFAdjustOptImpl::run () {
71
69
for (Function &F : *M)
72
70
for (auto &BB : F) {
73
- adjustBasicBlock (BB);
74
71
for (auto &I : BB)
75
72
adjustInst (I);
76
73
}
@@ -122,86 +119,6 @@ bool SBFAdjustOptImpl::serializeICMPInBB(Instruction &I) {
122
119
return true ;
123
120
}
124
121
125
- // To avoid combining conditionals in the same basic block by
126
- // instrcombine optimization.
127
- bool SBFAdjustOptImpl::serializeICMPCrossBB (BasicBlock &BB) {
128
- // For:
129
- // B1:
130
- // comp1 = icmp <opcode> ...;
131
- // if (comp1) goto B2 else B3;
132
- // B2:
133
- // comp2 = icmp <opcode> ...;
134
- // if (comp2) goto B4 else B5;
135
- // B4:
136
- // ...
137
- // changed to:
138
- // B1:
139
- // comp1 = icmp <opcode> ...;
140
- // comp1 = __builtin_bpf_passthrough(seq_num, comp1);
141
- // if (comp1) goto B2 else B3;
142
- // B2:
143
- // comp2 = icmp <opcode> ...;
144
- // if (comp2) goto B4 else B5;
145
- // B4:
146
- // ...
147
-
148
- // Check basic predecessors, if two of them (say B1, B2) are using
149
- // icmp instructions to generate conditions and one is the predesessor
150
- // of another (e.g., B1 is the predecessor of B2). Add a passthrough
151
- // barrier after icmp inst of block B1.
152
- BasicBlock *B2 = BB.getSinglePredecessor ();
153
- if (!B2)
154
- return false ;
155
-
156
- BasicBlock *B1 = B2->getSinglePredecessor ();
157
- if (!B1)
158
- return false ;
159
-
160
- Instruction *TI = B2->getTerminator ();
161
- auto *BI = dyn_cast<BranchInst>(TI);
162
- if (!BI || !BI->isConditional ())
163
- return false ;
164
- auto *Cond = dyn_cast<ICmpInst>(BI->getCondition ());
165
- if (!Cond || B2->getFirstNonPHI () != Cond)
166
- return false ;
167
- Value *B2Op0 = Cond->getOperand (0 );
168
- auto Cond2Op = Cond->getPredicate ();
169
-
170
- TI = B1->getTerminator ();
171
- BI = dyn_cast<BranchInst>(TI);
172
- if (!BI || !BI->isConditional ())
173
- return false ;
174
- Cond = dyn_cast<ICmpInst>(BI->getCondition ());
175
- if (!Cond)
176
- return false ;
177
- Value *B1Op0 = Cond->getOperand (0 );
178
- auto Cond1Op = Cond->getPredicate ();
179
-
180
- if (B1Op0 != B2Op0)
181
- return false ;
182
-
183
- if (Cond1Op == ICmpInst::ICMP_SGT || Cond1Op == ICmpInst::ICMP_SGE) {
184
- if (Cond2Op != ICmpInst::ICMP_SLT && Cond2Op != ICmpInst::ICMP_SLE)
185
- return false ;
186
- } else if (Cond1Op == ICmpInst::ICMP_SLT || Cond1Op == ICmpInst::ICMP_SLE) {
187
- if (Cond2Op != ICmpInst::ICMP_SGT && Cond2Op != ICmpInst::ICMP_SGE)
188
- return false ;
189
- } else if (Cond1Op == ICmpInst::ICMP_ULT || Cond1Op == ICmpInst::ICMP_ULE) {
190
- if (Cond2Op != ICmpInst::ICMP_UGT && Cond2Op != ICmpInst::ICMP_UGE)
191
- return false ;
192
- } else if (Cond1Op == ICmpInst::ICMP_UGT || Cond1Op == ICmpInst::ICMP_UGE) {
193
- if (Cond2Op != ICmpInst::ICMP_ULT && Cond2Op != ICmpInst::ICMP_ULE)
194
- return false ;
195
- } else {
196
- return false ;
197
- }
198
-
199
- PassThroughInfo Info (Cond, BI, 0 );
200
- PassThroughs.push_back (Info);
201
-
202
- return true ;
203
- }
204
-
205
122
// To avoid speculative hoisting certain computations out of
206
123
// a basic block.
207
124
bool SBFAdjustOptImpl::avoidSpeculation (Instruction &I) {
@@ -297,11 +214,6 @@ bool SBFAdjustOptImpl::avoidSpeculation(Instruction &I) {
297
214
return true ;
298
215
}
299
216
300
- void SBFAdjustOptImpl::adjustBasicBlock (BasicBlock &BB) {
301
- if (!DisableSBFserializeICMP && serializeICMPCrossBB (BB))
302
- return ;
303
- }
304
-
305
217
void SBFAdjustOptImpl::adjustInst (Instruction &I) {
306
218
if (!DisableSBFserializeICMP && serializeICMPInBB (I))
307
219
return ;
0 commit comments