Skip to content
This repository has been archived by the owner on Jul 1, 2023. It is now read-only.

Commit

Permalink
[BOLTCore] [NFC] Fix braces usages according to LLVM
Browse files Browse the repository at this point in the history
Summary:
Fix according to Coding Standards doc, section Don't Use
Braces on Simple Single-Statement Bodies of if/else/loop Statements.
This set of changes applies to lib Core only.

(cherry picked from FBD33240028)
  • Loading branch information
rafaelauler authored and aaupov committed Dec 30, 2021
1 parent 0c66db3 commit fe3fcf0
Show file tree
Hide file tree
Showing 17 changed files with 167 additions and 311 deletions.
18 changes: 6 additions & 12 deletions bolt/include/bolt/Core/BinaryBasicBlock.h
Expand Up @@ -483,9 +483,8 @@ class BinaryBasicBlock {

/// Add a range of instructions to the end of this basic block.
template <typename Itr> void addInstructions(Itr Begin, Itr End) {
while (Begin != End) {
while (Begin != End)
addInstruction(*Begin++);
}
}

/// Add a range of instructions to the end of this basic block.
Expand Down Expand Up @@ -582,18 +581,16 @@ class BinaryBasicBlock {

/// Add a range of successors.
template <typename Itr> void addSuccessors(Itr Begin, Itr End) {
while (Begin != End) {
while (Begin != End)
addSuccessor(*Begin++);
}
}

/// Add a range of successors with branch info.
template <typename Itr, typename BrItr>
void addSuccessors(Itr Begin, Itr End, BrItr BrBegin, BrItr BrEnd) {
assert(std::distance(Begin, End) == std::distance(BrBegin, BrEnd));
while (Begin != End) {
while (Begin != End)
addSuccessor(*Begin++, *BrBegin++);
}
}

/// Replace Succ with NewSucc. This routine is helpful for preserving
Expand Down Expand Up @@ -701,9 +698,8 @@ class BinaryBasicBlock {
/// Erase instructions in the specified range.
template <typename ItrType>
void eraseInstructions(ItrType Begin, ItrType End) {
while (End > Begin) {
while (End > Begin)
eraseInstruction(findInstruction(*--End));
}
}

/// Erase all instructions.
Expand Down Expand Up @@ -855,9 +851,8 @@ class BinaryBasicBlock {

/// Printer required for printing dominator trees.
void printAsOperand(raw_ostream &OS, bool PrintType = true) {
if (PrintType) {
if (PrintType)
OS << "basic block ";
}
OS << getName();
}

Expand Down Expand Up @@ -920,9 +915,8 @@ class BinaryBasicBlock {
void adjustNumPseudos(const MCInst &Inst, int Sign);

template <typename Itr> void adjustNumPseudos(Itr Begin, Itr End, int Sign) {
while (Begin != End) {
while (Begin != End)
adjustNumPseudos(*Begin++, Sign);
}
}

/// Adds predecessor to the BB. Most likely you don't need to call this.
Expand Down
12 changes: 4 additions & 8 deletions bolt/include/bolt/Core/BinaryContext.h
Expand Up @@ -281,9 +281,8 @@ class BinaryContext {
void setFilename(StringRef Name) { Filename = std::string(Name); }

Optional<StringRef> getFileBuildID() const {
if (FileBuildID) {
if (FileBuildID)
return StringRef(*FileBuildID);
}

return NoneType();
}
Expand Down Expand Up @@ -666,9 +665,8 @@ class BinaryContext {
iterator_range<FilteredBinaryDataConstIterator>
getBinaryDataForSection(const BinarySection &Section) const {
auto Begin = BinaryDataMap.lower_bound(Section.getAddress());
if (Begin != BinaryDataMap.begin()) {
if (Begin != BinaryDataMap.begin())
--Begin;
}
auto End = BinaryDataMap.upper_bound(Section.getEndAddress());
auto pred = [&Section](const binary_data_const_iterator &Itr) -> bool {
return Itr->second->getSection() == Section;
Expand All @@ -681,9 +679,8 @@ class BinaryContext {
iterator_range<FilteredBinaryDataIterator>
getBinaryDataForSection(BinarySection &Section) {
auto Begin = BinaryDataMap.lower_bound(Section.getAddress());
if (Begin != BinaryDataMap.begin()) {
if (Begin != BinaryDataMap.begin())
--Begin;
}
auto End = BinaryDataMap.upper_bound(Section.getEndAddress());
auto pred = [&Section](const binary_data_iterator &Itr) -> bool {
return Itr->second->getSection() == Section;
Expand All @@ -698,9 +695,8 @@ class BinaryContext {
/// Clear the global symbol address -> name(s) map.
void clearBinaryData() {
GlobalSymbols.clear();
for (auto &Entry : BinaryDataMap) {
for (auto &Entry : BinaryDataMap)
delete Entry.second;
}
BinaryDataMap.clear();
}

Expand Down
39 changes: 13 additions & 26 deletions bolt/include/bolt/Core/BinaryFunction.h
Expand Up @@ -708,12 +708,10 @@ class BinaryFunction {
/// Release memory allocated for CFG and instructions.
/// We still keep basic blocks for address translation/mapping purposes.
void releaseCFG() {
for (BinaryBasicBlock *BB : BasicBlocks) {
for (BinaryBasicBlock *BB : BasicBlocks)
BB->releaseCFG();
}
for (BinaryBasicBlock *BB : DeletedBasicBlocks) {
for (BinaryBasicBlock *BB : DeletedBasicBlocks)
BB->releaseCFG();
}

clearList(CallSites);
clearList(ColdCallSites);
Expand Down Expand Up @@ -878,9 +876,8 @@ class BinaryFunction {
const BinaryLoopInfo &getLoopInfo() { return *BLI.get(); }

bool isLoopFree() {
if (!hasLoopInfo()) {
if (!hasLoopInfo())
calculateLoopInfo();
}
return BLI->empty();
}

Expand Down Expand Up @@ -1110,9 +1107,8 @@ class BinaryFunction {
/// Return the number of emitted instructions for this function.
uint32_t getNumNonPseudos() const {
uint32_t N = 0;
for (BinaryBasicBlock *const &BB : layout()) {
for (BinaryBasicBlock *const &BB : layout())
N += BB->getNumNonPseudos();
}
return N;
}

Expand Down Expand Up @@ -1608,9 +1604,8 @@ class BinaryFunction {
/// Make sure basic blocks' indices match the current layout.
void updateLayoutIndices() const {
unsigned Index = 0;
for (BinaryBasicBlock *BB : layout()) {
for (BinaryBasicBlock *BB : layout())
BB->setLayoutIndex(Index++);
}
}

/// Recompute the CFI state for NumNewBlocks following Start after inserting
Expand Down Expand Up @@ -2078,10 +2073,9 @@ class BinaryFunction {
Size += NextMarker - *DataIter;
}

if (!OnBehalfOf) {
if (!OnBehalfOf)
for (BinaryFunction *ExternalFunc : Islands->Dependency)
Size += ExternalFunc->estimateConstantIslandSize(this);
}
return Size;
}

Expand Down Expand Up @@ -2311,17 +2305,13 @@ class BinaryFunction {
size_t estimateHotSize(const bool UseSplitSize = true) const {
size_t Estimate = 0;
if (UseSplitSize && isSplit()) {
for (const BinaryBasicBlock *BB : BasicBlocksLayout) {
if (!BB->isCold()) {
for (const BinaryBasicBlock *BB : BasicBlocksLayout)
if (!BB->isCold())
Estimate += BC.computeCodeSize(BB->begin(), BB->end());
}
}
} else {
for (const BinaryBasicBlock *BB : BasicBlocksLayout) {
if (BB->getKnownExecutionCount() != 0) {
for (const BinaryBasicBlock *BB : BasicBlocksLayout)
if (BB->getKnownExecutionCount() != 0)
Estimate += BC.computeCodeSize(BB->begin(), BB->end());
}
}
}
return Estimate;
}
Expand All @@ -2330,19 +2320,16 @@ class BinaryFunction {
if (!isSplit())
return estimateSize();
size_t Estimate = 0;
for (const BinaryBasicBlock *BB : BasicBlocksLayout) {
if (BB->isCold()) {
for (const BinaryBasicBlock *BB : BasicBlocksLayout)
if (BB->isCold())
Estimate += BC.computeCodeSize(BB->begin(), BB->end());
}
}
return Estimate;
}

size_t estimateSize() const {
size_t Estimate = 0;
for (const BinaryBasicBlock *BB : BasicBlocksLayout) {
for (const BinaryBasicBlock *BB : BasicBlocksLayout)
Estimate += BC.computeCodeSize(BB->begin(), BB->end());
}
return Estimate;
}

Expand Down
9 changes: 3 additions & 6 deletions bolt/include/bolt/Core/DynoStats.h
Expand Up @@ -151,9 +151,8 @@ inline DynoStats getDynoStats(const FuncsType &Funcs) {
DynoStats dynoStats(IsAArch64);
for (auto &BFI : Funcs) {
auto &BF = BFI.second;
if (BF.isSimple()) {
if (BF.isSimple())
dynoStats += getDynoStats(BF);
}
}
return dynoStats;
}
Expand All @@ -164,9 +163,8 @@ inline void callWithDynoStats(FnType &&Func, const FuncsType &Funcs,
StringRef Phase, const bool Flag) {
bool IsAArch64 = Funcs.begin()->second.getBinaryContext().isAArch64();
DynoStats DynoStatsBefore(IsAArch64);
if (Flag) {
if (Flag)
DynoStatsBefore = getDynoStats(Funcs);
}

Func();

Expand All @@ -176,9 +174,8 @@ inline void callWithDynoStats(FnType &&Func, const FuncsType &Funcs,
outs() << "BOLT-INFO: program-wide dynostats after running " << Phase
<< (Changed ? "" : " (no change)") << ":\n\n"
<< DynoStatsBefore << '\n';
if (Changed) {
if (Changed)
DynoStatsAfter.print(outs(), &DynoStatsBefore);
}
outs() << '\n';
}
}
Expand Down
6 changes: 2 additions & 4 deletions bolt/include/bolt/Core/MCPlusBuilder.h
Expand Up @@ -1112,9 +1112,8 @@ class MCPlusBuilder {
} else if (auto *BinExpr = dyn_cast<MCBinaryExpr>(Expr)) {
const auto *SymExpr = dyn_cast<MCSymbolRefExpr>(BinExpr->getLHS());
const auto *ConstExpr = dyn_cast<MCConstantExpr>(BinExpr->getRHS());
if (BinExpr->getOpcode() == MCBinaryExpr::Add && SymExpr && ConstExpr) {
if (BinExpr->getOpcode() == MCBinaryExpr::Add && SymExpr && ConstExpr)
return std::make_pair(&SymExpr->getSymbol(), ConstExpr->getValue());
}
}
return std::make_pair(nullptr, 0);
}
Expand Down Expand Up @@ -1633,9 +1632,8 @@ class MCPlusBuilder {
auto *A = new (Allocator.ValueAllocator)
MCPlus::MCSimpleAnnotation<ValueType>(Val);

if (!std::is_trivial<ValueType>::value) {
if (!std::is_trivial<ValueType>::value)
Allocator.AnnotationPool.insert(A);
}
setAnnotationOpValue(Inst, Index, reinterpret_cast<int64_t>(A),
AllocatorId);
return A->getValue();
Expand Down
18 changes: 7 additions & 11 deletions bolt/lib/Core/BinaryBasicBlock.cpp
Expand Up @@ -157,10 +157,9 @@ BinaryBasicBlock *BinaryBasicBlock::getSuccessor(const MCSymbol *Label) const {
if (!Label && succ_size() == 1)
return *succ_begin();

for (BinaryBasicBlock *BB : successors()) {
for (BinaryBasicBlock *BB : successors())
if (BB->getLabel() == Label)
return BB;
}

return nullptr;
}
Expand All @@ -180,10 +179,9 @@ BinaryBasicBlock *BinaryBasicBlock::getSuccessor(const MCSymbol *Label,
}

BinaryBasicBlock *BinaryBasicBlock::getLandingPad(const MCSymbol *Label) const {
for (BinaryBasicBlock *BB : landing_pads()) {
for (BinaryBasicBlock *BB : landing_pads())
if (BB->getLabel() == Label)
return BB;
}

return nullptr;
}
Expand Down Expand Up @@ -240,11 +238,10 @@ int32_t BinaryBasicBlock::getCFIStateAtInstr(const MCInst *Instr) const {
assert(State >= 0 && "first CFI cannot be RestoreState");
while (Depth && State >= 0) {
const MCCFIInstruction &CFIInstr = FDEProgram[State];
if (CFIInstr.getOperation() == MCCFIInstruction::OpRestoreState) {
if (CFIInstr.getOperation() == MCCFIInstruction::OpRestoreState)
++Depth;
} else if (CFIInstr.getOperation() == MCCFIInstruction::OpRememberState) {
else if (CFIInstr.getOperation() == MCCFIInstruction::OpRememberState)
--Depth;
}
--State;
}
assert(Depth == 0 && "unbalanced RememberState/RestoreState stack");
Expand Down Expand Up @@ -288,9 +285,8 @@ void BinaryBasicBlock::replaceSuccessor(BinaryBasicBlock *Succ,
}

void BinaryBasicBlock::removeAllSuccessors() {
for (BinaryBasicBlock *SuccessorBB : successors()) {
for (BinaryBasicBlock *SuccessorBB : successors())
SuccessorBB->removePredecessor(this);
}
Successors.clear();
BranchInfo.clear();
}
Expand Down Expand Up @@ -488,10 +484,10 @@ uint32_t BinaryBasicBlock::getNumPseudos() const {
#ifndef NDEBUG
BinaryContext &BC = Function->getBinaryContext();
uint32_t N = 0;
for (const MCInst &Instr : Instructions) {
for (const MCInst &Instr : Instructions)
if (BC.MIB->isPseudo(Instr))
++N;
}

if (N != NumPseudos) {
errs() << "BOLT-ERROR: instructions for basic block " << getName()
<< " in function " << *Function << ": calculated pseudos " << N
Expand Down

0 comments on commit fe3fcf0

Please sign in to comment.