Skip to content

Commit f92ab6a

Browse files
aaupovmaksfb
authored andcommitted
[BOLT][NFC] Fix braces usage in Passes
Summary: Refactor bolt/*/Passes to follow the braces rule for if/else/loop from [LLVM Coding Standards](https://llvm.org/docs/CodingStandards.html). (cherry picked from FBD33344642)
1 parent cd7a630 commit f92ab6a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+340
-598
lines changed

bolt/include/bolt/Passes/DataflowAnalysis.h

+10-18
Original file line numberDiff line numberDiff line change
@@ -393,13 +393,12 @@ class DataflowAnalysis {
393393
BinaryBasicBlock *LBB = Func.getLandingPadBBFor(BB, Inst);
394394
if (LBB) {
395395
auto First = LBB->begin();
396-
if (First != LBB->end()) {
396+
if (First != LBB->end())
397397
derived().doConfluenceWithLP(CurState,
398398
getOrCreateStateAt(&*First), Inst);
399-
} else {
399+
else
400400
derived().doConfluenceWithLP(CurState, getOrCreateStateAt(LBB),
401401
Inst);
402-
}
403402
}
404403
}
405404

@@ -412,31 +411,24 @@ class DataflowAnalysis {
412411
PrevState = &St;
413412
};
414413

415-
if (!Backward) {
416-
for (MCInst &Inst : *BB) {
414+
if (!Backward)
415+
for (MCInst &Inst : *BB)
417416
doNext(Inst, *BB);
418-
}
419-
} else {
420-
for (auto I = BB->rbegin(), E = BB->rend(); I != E; ++I) {
417+
else
418+
for (auto I = BB->rbegin(), E = BB->rend(); I != E; ++I)
421419
doNext(*I, *BB);
422-
}
423-
}
424420

425421
if (Changed) {
426422
if (!Backward) {
427-
for (BinaryBasicBlock *Succ : BB->successors()) {
423+
for (BinaryBasicBlock *Succ : BB->successors())
428424
Worklist.push(Succ);
429-
}
430-
for (BinaryBasicBlock *LandingPad : BB->landing_pads()) {
425+
for (BinaryBasicBlock *LandingPad : BB->landing_pads())
431426
Worklist.push(LandingPad);
432-
}
433427
} else {
434-
for (BinaryBasicBlock *Pred : BB->predecessors()) {
428+
for (BinaryBasicBlock *Pred : BB->predecessors())
435429
Worklist.push(Pred);
436-
}
437-
for (BinaryBasicBlock *Thrower : BB->throwers()) {
430+
for (BinaryBasicBlock *Thrower : BB->throwers())
438431
Worklist.push(Thrower);
439-
}
440432
}
441433
}
442434
} // end while (!Worklist.empty())

bolt/include/bolt/Passes/DominatorAnalysis.h

+2-4
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,8 @@ class DominatorAnalysis
9595

9696
void doForAllDominators(const MCInst &Inst,
9797
std::function<void(const MCInst &)> Task) {
98-
for (auto I = this->expr_begin(Inst), E = this->expr_end(); I != E; ++I) {
98+
for (auto I = this->expr_begin(Inst), E = this->expr_end(); I != E; ++I)
9999
Task(**I);
100-
}
101100
}
102101

103102
void run() {
@@ -137,9 +136,8 @@ class DominatorAnalysis
137136
BitVector computeNext(const MCInst &Point, const BitVector &Cur) {
138137
BitVector Next = Cur;
139138
// Gen
140-
if (!this->BC.MIB->isCFI(Point)) {
139+
if (!this->BC.MIB->isCFI(Point))
141140
Next.set(this->ExprToIdx[&Point]);
142-
}
143141
return Next;
144142
}
145143

bolt/include/bolt/Passes/LivenessAnalysis.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,8 @@ class LivenessAnalysis : public DataflowAnalysis<LivenessAnalysis, BitVector,
143143
}
144144
for (auto I = InstInfo.getImplicitUses(),
145145
E = InstInfo.getImplicitUses() + InstInfo.getNumImplicitUses();
146-
I != E; ++I) {
146+
I != E; ++I)
147147
Used |= BC.MIB->getAliases(*I, false);
148-
}
149148
if (IsCall &&
150149
(!BC.MIB->isTailCall(Point) || !BC.MIB->isConditionalBranch(Point))) {
151150
// Never gen FLAGS from a non-conditional call... this is overly

bolt/include/bolt/Passes/ReachingDefOrUse.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,10 @@ class ReachingDefOrUse
4242
bool isReachedBy(MCPhysReg Reg, ExprIterator Candidates) {
4343
for (auto I = Candidates; I != this->expr_end(); ++I) {
4444
BitVector BV = BitVector(this->BC.MRI->getNumRegs(), false);
45-
if (Def) {
45+
if (Def)
4646
RA.getInstClobberList(**I, BV);
47-
} else {
47+
else
4848
this->BC.MIB->getTouchedRegs(**I, BV);
49-
}
5049
if (BV[Reg])
5150
return true;
5251
}

bolt/include/bolt/Passes/ReachingInsns.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,8 @@ class ReachingInsns
7474
BitVector computeNext(const MCInst &Point, const BitVector &Cur) {
7575
BitVector Next = Cur;
7676
// Gen
77-
if (!this->BC.MIB->isCFI(Point)) {
77+
if (!this->BC.MIB->isCFI(Point))
7878
Next.set(this->ExprToIdx[&Point]);
79-
}
8079
return Next;
8180
}
8281

bolt/include/bolt/Passes/ReorderUtils.h

+2-4
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,8 @@ template <typename Cluster> class AdjacencyMatrix {
3737

3838
template <typename F> void forAllAdjacent(const Cluster *C, F Func) {
3939
for (int I = Bits[C->id()].find_first(); I != -1;
40-
I = Bits[C->id()].find_next(I)) {
40+
I = Bits[C->id()].find_next(I))
4141
Func(Clusters[I]);
42-
}
4342
}
4443

4544
/// Merge adjacency info from cluster B into cluster A. Info for cluster B is
@@ -93,9 +92,8 @@ template <typename Cluster, typename ValueType> class ClusterPairCache {
9392

9493
void invalidate(const Cluster *C) {
9594
Valid.reset(C->id() * Size, (C->id() + 1) * Size);
96-
for (size_t Id = 0; Id < Size; Id++) {
95+
for (size_t Id = 0; Id < Size; Id++)
9796
Valid.reset((Id * Size) + C->id());
98-
}
9997
}
10098

10199
private:

bolt/include/bolt/Passes/ShrinkWrapping.h

+2-4
Original file line numberDiff line numberDiff line change
@@ -509,11 +509,9 @@ class ShrinkWrapping {
509509
CSA(FA, BF, Info, AllocId) {}
510510

511511
~ShrinkWrapping() {
512-
for (BinaryBasicBlock &BB : BF) {
513-
for (MCInst &Inst : BB) {
512+
for (BinaryBasicBlock &BB : BF)
513+
for (MCInst &Inst : BB)
514514
BC.MIB->removeAnnotation(Inst, getAnnotationIndex());
515-
}
516-
}
517515
}
518516

519517
bool perform();

bolt/include/bolt/Passes/StackPointerTracking.h

+3-7
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,7 @@ class StackPointerTrackingBase
9999

100100
if (MIB->isLeave(Point))
101101
return FPVal + 8;
102-
else
103-
return FPVal;
102+
return FPVal;
104103
}
105104

106105
if (this->BC.MII->get(Point.getOpcode())
@@ -157,11 +156,8 @@ class StackPointerTrackingBase
157156
return SUPERPOSITION;
158157
}
159158

160-
if (!HasFramePointer) {
161-
if (MIB->escapesVariable(Point, false)) {
162-
HasFramePointer = true;
163-
}
164-
}
159+
if (!HasFramePointer && MIB->escapesVariable(Point, false))
160+
HasFramePointer = true;
165161
return static_cast<int>(Output);
166162
}
167163

bolt/include/bolt/Passes/StokeInfo.h

+3-6
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ struct StokeFuncInfo {
7070
}
7171

7272
void printCsvHeader(std::ofstream &Outfile) {
73-
if (Outfile.is_open()) {
73+
if (Outfile.is_open())
7474
Outfile << "FuncName,Offset,Size,NumInstrs,NumBlocks,"
7575
<< "IsLoopFree,NumLoops,MaxLoopDepth,"
7676
<< "HotSize,TotalSize,"
@@ -79,7 +79,6 @@ struct StokeFuncInfo {
7979
<< "DefIn,LiveOut,HeapOut,StackOut,"
8080
<< "HasRipAddr,"
8181
<< "Omitted\n";
82-
}
8382
}
8483

8584
void printData(std::ofstream &Outfile) {
@@ -88,13 +87,11 @@ struct StokeFuncInfo {
8887
<< "," << NumBlocks << "," << IsLoopFree << "," << NumLoops << ","
8988
<< MaxLoopDepth << "," << HotSize << "," << TotalSize << ","
9089
<< Score << "," << HasCall << ",\"{ ";
91-
for (std::string S : DefIn) {
90+
for (std::string S : DefIn)
9291
Outfile << "%" << S << " ";
93-
}
9492
Outfile << "}\",\"{ ";
95-
for (std::string S : LiveOut) {
93+
for (std::string S : LiveOut)
9694
Outfile << "%" << S << " ";
97-
}
9895
Outfile << "}\"," << HeapOut << "," << StackOut << "," << HasRipAddr
9996
<< "," << Omitted << "\n";
10097
}

bolt/include/bolt/Passes/ValidateInternalCalls.h

+2-4
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,9 @@ class ValidateInternalCalls : public BinaryFunctionPass {
8484

8585
void clearAnnotations(BinaryFunction &Function) const {
8686
const BinaryContext &BC = Function.getBinaryContext();
87-
for (BinaryBasicBlock &BB : Function) {
88-
for (MCInst &Inst : BB) {
87+
for (BinaryBasicBlock &BB : Function)
88+
for (MCInst &Inst : BB)
8989
BC.MIB->removeAnnotation(Inst, getProcessedICTag());
90-
}
91-
}
9290
}
9391
};
9492

bolt/include/bolt/Passes/VeneerElimination.h

+1-3
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ class VeneerElimination : public BinaryFunctionPass {
1818
public:
1919
/// BinaryPass public interface
2020
explicit VeneerElimination(const cl::opt<bool> &PrintPass)
21-
: BinaryFunctionPass(PrintPass) {
22-
;
23-
}
21+
: BinaryFunctionPass(PrintPass) {}
2422

2523
const char *getName() const override { return "veneer-elimination"; }
2624

bolt/lib/Passes/Aligner.cpp

+5-6
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,11 @@ void alignCompact(BinaryFunction &Function, const MCCodeEmitter *Emitter) {
9595
size_t HotSize = 0;
9696
size_t ColdSize = 0;
9797

98-
for (const BinaryBasicBlock *BB : Function.layout()) {
98+
for (const BinaryBasicBlock *BB : Function.layout())
9999
if (BB->isCold())
100100
ColdSize += BC.computeCodeSize(BB->begin(), BB->end(), Emitter);
101101
else
102102
HotSize += BC.computeCodeSize(BB->begin(), BB->end(), Emitter);
103-
}
104103

105104
Function.setAlignment(opts::AlignFunctions);
106105
if (HotSize > 0)
@@ -135,9 +134,9 @@ void AlignerPass::alignBlocks(BinaryFunction &Function,
135134
}
136135

137136
uint64_t FTCount = 0;
138-
if (PrevBB && PrevBB->getFallthrough() == BB) {
137+
if (PrevBB && PrevBB->getFallthrough() == BB)
139138
FTCount = PrevBB->getBranchInfo(*BB).Count;
140-
}
139+
141140
PrevBB = BB;
142141

143142
if (Count < FTCount * 2)
@@ -189,9 +188,9 @@ void AlignerPass::runOnFunctions(BinaryContext &BC) {
189188

190189
LLVM_DEBUG(
191190
dbgs() << "BOLT-DEBUG: max bytes per basic block alignment distribution:\n";
192-
for (unsigned I = 1; I < AlignHistogram.size(); ++I) {
191+
for (unsigned I = 1; I < AlignHistogram.size(); ++I)
193192
dbgs() << " " << I << " : " << AlignHistogram[I] << '\n';
194-
}
193+
195194
dbgs() << "BOLT-DEBUG: total execution count of aligned blocks: "
196195
<< AlignedBlocksCount << '\n';
197196
);

bolt/lib/Passes/AllocCombiner.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,8 @@ bool isIndifferentToSP(const MCInst &Inst, const BinaryContext &BC) {
4646

4747
for (int I = 0, E = MCPlus::getNumPrimeOperands(Inst); I != E; ++I) {
4848
const MCOperand &Operand = Inst.getOperand(I);
49-
if (Operand.isReg() && Operand.getReg() == BC.MIB->getStackPointer()) {
49+
if (Operand.isReg() && Operand.getReg() == BC.MIB->getStackPointer())
5050
return false;
51-
}
5251
}
5352
return true;
5453
}

bolt/lib/Passes/AsmDump.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ void dumpCFI(const BinaryFunction &BF, const MCInst &Instr, AsmPrinter &MAP) {
4242
// Skip unsupported CFI instructions.
4343
case MCCFIInstruction::OpRememberState:
4444
case MCCFIInstruction::OpRestoreState:
45-
if (opts::Verbosity >= 2) {
45+
if (opts::Verbosity >= 2)
4646
errs()
4747
<< "BOLT-WARNING: AsmDump: skipping unsupported CFI instruction in "
4848
<< BF << ".\n";
49-
}
49+
5050
return;
5151

5252
default:

bolt/lib/Passes/BinaryFunctionCallGraph.cpp

+8-14
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,8 @@ buildCallGraph(BinaryContext &BC, CgFilterFunction Filter, bool CgFromPerfData,
114114
// samples. Results from perfomance testing seem to favor the zero
115115
// count though, so I'm leaving it this way for now.
116116
return Cg.addNode(Function, Size, Function->getKnownExecutionCount());
117-
} else {
118-
return Id;
119117
}
118+
return Id;
120119
};
121120

122121
// Add call graph edges.
@@ -128,9 +127,8 @@ buildCallGraph(BinaryContext &BC, CgFilterFunction Filter, bool CgFromPerfData,
128127
for (auto &It : BC.getBinaryFunctions()) {
129128
BinaryFunction *Function = &It.second;
130129

131-
if (Filter(*Function)) {
130+
if (Filter(*Function))
132131
continue;
133-
}
134132

135133
const CallGraph::NodeId SrcId = lookupNode(Function);
136134
// Offset of the current basic block from the beginning of the function
@@ -146,9 +144,9 @@ buildCallGraph(BinaryContext &BC, CgFilterFunction Filter, bool CgFromPerfData,
146144
if (IgnoreRecursiveCalls)
147145
return false;
148146
}
149-
if (Filter(*DstFunc)) {
147+
if (Filter(*DstFunc))
150148
return false;
151-
}
149+
152150
const CallGraph::NodeId DstId = lookupNode(DstFunc);
153151
const bool IsValidCount = Count != COUNT_NO_PROFILE;
154152
const uint64_t AdjCount = UseEdgeCounts && IsValidCount ? Count : 1;
@@ -180,10 +178,9 @@ buildCallGraph(BinaryContext &BC, CgFilterFunction Filter, bool CgFromPerfData,
180178
if (!DstSym && BC.MIB->hasAnnotation(Inst, "CallProfile")) {
181179
const auto &ICSP = BC.MIB->getAnnotationAs<IndirectCallSiteProfile>(
182180
Inst, "CallProfile");
183-
for (const IndirectCallProfile &CSI : ICSP) {
181+
for (const IndirectCallProfile &CSI : ICSP)
184182
if (CSI.Symbol)
185183
Counts.emplace_back(CSI.Symbol, CSI.Count);
186-
}
187184
} else {
188185
const uint64_t Count = BB->getExecutionCount();
189186
Counts.emplace_back(DstSym, Count);
@@ -214,9 +211,8 @@ buildCallGraph(BinaryContext &BC, CgFilterFunction Filter, bool CgFromPerfData,
214211
if (Offset > Size)
215212
Offset = Size;
216213

217-
if (!recordCall(CSI.Symbol, CSI.Count)) {
214+
if (!recordCall(CSI.Symbol, CSI.Count))
218215
++NotProcessed;
219-
}
220216
}
221217
} else {
222218
for (BinaryBasicBlock *BB : Function->layout()) {
@@ -253,9 +249,8 @@ buildCallGraph(BinaryContext &BC, CgFilterFunction Filter, bool CgFromPerfData,
253249
}
254250
}
255251
// Increase Offset if needed
256-
if (BBIncludedInFunctionSize) {
252+
if (BBIncludedInFunctionSize)
257253
Offset += BC.computeCodeSize(&Inst, &Inst + 1);
258-
}
259254
}
260255
}
261256
}
@@ -266,15 +261,14 @@ buildCallGraph(BinaryContext &BC, CgFilterFunction Filter, bool CgFromPerfData,
266261
#else
267262
bool PrintInfo = false;
268263
#endif
269-
if (PrintInfo || opts::Verbosity > 0) {
264+
if (PrintInfo || opts::Verbosity > 0)
270265
outs() << format("BOLT-INFO: buildCallGraph: %u nodes, %u callsites "
271266
"(%u recursive), density = %.6lf, %u callsites not "
272267
"processed, %u callsites with invalid profile, "
273268
"used perf data for %u stale functions.\n",
274269
Cg.numNodes(), TotalCallsites, RecursiveCallsites,
275270
Cg.density(), NotProcessed, NoProfileCallsites,
276271
NumFallbacks);
277-
}
278272

279273
return Cg;
280274
}

0 commit comments

Comments
 (0)