Skip to content

Commit be2f67c

Browse files
committed
[BOLT][NFC] Replace anonymous namespace functions with static
Follow LLVM Coding Standards guideline on using anonymous namespaces (https://llvm.org/docs/CodingStandards.html#anonymous-namespaces) and use `static` modifier for function definitions. Reviewed By: #bolt, maksfb Differential Revision: https://reviews.llvm.org/D143124
1 parent 52b34d2 commit be2f67c

10 files changed

+73
-110
lines changed

bolt/lib/Core/BinaryFunction.cpp

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,7 @@ namespace bolt {
166166

167167
constexpr unsigned BinaryFunction::MinAlign;
168168

169-
namespace {
170-
171-
template <typename R> bool emptyRange(const R &Range) {
169+
template <typename R> static bool emptyRange(const R &Range) {
172170
return Range.begin() == Range.end();
173171
}
174172

@@ -177,7 +175,7 @@ template <typename R> bool emptyRange(const R &Range) {
177175
/// to point to this information, which is represented by a
178176
/// DebugLineTableRowRef. The returned pointer is null if no debug line
179177
/// information for this instruction was found.
180-
SMLoc findDebugLineInformationForInstructionAt(
178+
static SMLoc findDebugLineInformationForInstructionAt(
181179
uint64_t Address, DWARFUnit *Unit,
182180
const DWARFDebugLine::LineTable *LineTable) {
183181
// We use the pointer in SMLoc to store an instance of DebugLineTableRowRef,
@@ -206,15 +204,16 @@ SMLoc findDebugLineInformationForInstructionAt(
206204
return SMLoc::getFromPointer(Ptr);
207205
}
208206

209-
std::string buildSectionName(StringRef Prefix, StringRef Name,
210-
const BinaryContext &BC) {
207+
static std::string buildSectionName(StringRef Prefix, StringRef Name,
208+
const BinaryContext &BC) {
211209
if (BC.isELF())
212210
return (Prefix + Name).str();
213211
static NameShortener NS;
214212
return (Prefix + Twine(NS.getID(Name))).str();
215213
}
216214

217-
raw_ostream &operator<<(raw_ostream &OS, const BinaryFunction::State State) {
215+
static raw_ostream &operator<<(raw_ostream &OS,
216+
const BinaryFunction::State State) {
218217
switch (State) {
219218
case BinaryFunction::State::Empty: OS << "empty"; break;
220219
case BinaryFunction::State::Disassembled: OS << "disassembled"; break;
@@ -227,8 +226,6 @@ raw_ostream &operator<<(raw_ostream &OS, const BinaryFunction::State State) {
227226
return OS;
228227
}
229228

230-
} // namespace
231-
232229
std::string BinaryFunction::buildCodeSectionName(StringRef Name,
233230
const BinaryContext &BC) {
234231
return buildSectionName(BC.isELF() ? ".local.text." : ".l.text.", Name, BC);
@@ -669,9 +666,8 @@ void BinaryFunction::printRelocations(raw_ostream &OS, uint64_t Offset,
669666
}
670667
}
671668

672-
namespace {
673-
std::string mutateDWARFExpressionTargetReg(const MCCFIInstruction &Instr,
674-
MCPhysReg NewReg) {
669+
static std::string mutateDWARFExpressionTargetReg(const MCCFIInstruction &Instr,
670+
MCPhysReg NewReg) {
675671
StringRef ExprBytes = Instr.getValues();
676672
assert(ExprBytes.size() > 1 && "DWARF expression CFI is too short");
677673
uint8_t Opcode = ExprBytes[0];
@@ -694,7 +690,6 @@ std::string mutateDWARFExpressionTargetReg(const MCCFIInstruction &Instr,
694690
.concat(ExprBytes.drop_front(1 + Size))
695691
.str();
696692
}
697-
} // namespace
698693

699694
void BinaryFunction::mutateCFIRegisterFor(const MCInst &Instr,
700695
MCPhysReg NewReg) {
@@ -2999,14 +2994,13 @@ void BinaryFunction::duplicateConstantIslands() {
29992994
}
30002995
}
30012996

3002-
namespace {
3003-
30042997
#ifndef MAX_PATH
30052998
#define MAX_PATH 255
30062999
#endif
30073000

3008-
std::string constructFilename(std::string Filename, std::string Annotation,
3009-
std::string Suffix) {
3001+
static std::string constructFilename(std::string Filename,
3002+
std::string Annotation,
3003+
std::string Suffix) {
30103004
std::replace(Filename.begin(), Filename.end(), '/', '-');
30113005
if (!Annotation.empty())
30123006
Annotation.insert(0, "-");
@@ -3023,7 +3017,7 @@ std::string constructFilename(std::string Filename, std::string Annotation,
30233017
return Filename;
30243018
}
30253019

3026-
std::string formatEscapes(const std::string &Str) {
3020+
static std::string formatEscapes(const std::string &Str) {
30273021
std::string Result;
30283022
for (unsigned I = 0; I < Str.size(); ++I) {
30293023
char C = Str[I];
@@ -3041,8 +3035,6 @@ std::string formatEscapes(const std::string &Str) {
30413035
return Result;
30423036
}
30433037

3044-
} // namespace
3045-
30463038
void BinaryFunction::dumpGraph(raw_ostream &OS) const {
30473039
OS << "digraph \"" << getPrintName() << "\" {\n"
30483040
<< "node [fontname=courier, shape=box, style=filled, colorscheme=brbg9]\n";

bolt/lib/Core/DebugData.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,6 @@ std::optional<AttrInfo> findAttributeInfo(const DWARFDie DIE,
9090

9191
const DebugLineTableRowRef DebugLineTableRowRef::NULL_ROW{0, 0};
9292

93-
namespace {
94-
9593
LLVM_ATTRIBUTE_UNUSED
9694
static void printLE64(const std::string &S) {
9795
for (uint32_t I = 0, Size = S.size(); I < Size; ++I) {
@@ -106,9 +104,10 @@ static void printLE64(const std::string &S) {
106104
// the form (begin address, range size), otherwise (begin address, end address).
107105
// Terminates the list by writing a pair of two zeroes.
108106
// Returns the number of written bytes.
109-
uint64_t writeAddressRanges(raw_svector_ostream &Stream,
110-
const DebugAddressRangesVector &AddressRanges,
111-
const bool WriteRelativeRanges = false) {
107+
static uint64_t
108+
writeAddressRanges(raw_svector_ostream &Stream,
109+
const DebugAddressRangesVector &AddressRanges,
110+
const bool WriteRelativeRanges = false) {
112111
for (const DebugAddressRange &Range : AddressRanges) {
113112
support::endian::write(Stream, Range.LowPC, support::little);
114113
support::endian::write(
@@ -121,8 +120,6 @@ uint64_t writeAddressRanges(raw_svector_ostream &Stream,
121120
return AddressRanges.size() * 16 + 16;
122121
}
123122

124-
} // namespace
125-
126123
DebugRangesSectionWriter::DebugRangesSectionWriter() {
127124
RangesBuffer = std::make_unique<DebugBufferVector>();
128125
RangesStream = std::make_unique<raw_svector_ostream>(*RangesBuffer);

bolt/lib/Core/Relocation.cpp

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ using namespace bolt;
2222

2323
Triple::ArchType Relocation::Arch;
2424

25-
namespace {
26-
27-
bool isSupportedX86(uint64_t Type) {
25+
static bool isSupportedX86(uint64_t Type) {
2826
switch (Type) {
2927
default:
3028
return false;
@@ -46,7 +44,7 @@ bool isSupportedX86(uint64_t Type) {
4644
}
4745
}
4846

49-
bool isSupportedAArch64(uint64_t Type) {
47+
static bool isSupportedAArch64(uint64_t Type) {
5048
switch (Type) {
5149
default:
5250
return false;
@@ -91,7 +89,7 @@ bool isSupportedAArch64(uint64_t Type) {
9189
}
9290
}
9391

94-
size_t getSizeForTypeX86(uint64_t Type) {
92+
static size_t getSizeForTypeX86(uint64_t Type) {
9593
switch (Type) {
9694
default:
9795
errs() << object::getELFRelocationTypeName(ELF::EM_X86_64, Type) << '\n';
@@ -117,7 +115,7 @@ size_t getSizeForTypeX86(uint64_t Type) {
117115
}
118116
}
119117

120-
size_t getSizeForTypeAArch64(uint64_t Type) {
118+
static size_t getSizeForTypeAArch64(uint64_t Type) {
121119
switch (Type) {
122120
default:
123121
errs() << object::getELFRelocationTypeName(ELF::EM_AARCH64, Type) << '\n';
@@ -165,17 +163,19 @@ size_t getSizeForTypeAArch64(uint64_t Type) {
165163
}
166164
}
167165

168-
bool skipRelocationTypeX86(uint64_t Type) { return Type == ELF::R_X86_64_NONE; }
166+
static bool skipRelocationTypeX86(uint64_t Type) {
167+
return Type == ELF::R_X86_64_NONE;
168+
}
169169

170-
bool skipRelocationTypeAArch64(uint64_t Type) {
170+
static bool skipRelocationTypeAArch64(uint64_t Type) {
171171
return Type == ELF::R_AARCH64_NONE || Type == ELF::R_AARCH64_LD_PREL_LO19;
172172
}
173173

174-
bool skipRelocationProcessX86(uint64_t &Type, uint64_t Contents) {
174+
static bool skipRelocationProcessX86(uint64_t &Type, uint64_t Contents) {
175175
return false;
176176
}
177177

178-
bool skipRelocationProcessAArch64(uint64_t &Type, uint64_t Contents) {
178+
static bool skipRelocationProcessAArch64(uint64_t &Type, uint64_t Contents) {
179179
auto IsMov = [](uint64_t Contents) -> bool {
180180
// The bits 28-23 are 0b100101
181181
return (Contents & 0x1f800000) == 0x12800000;
@@ -262,7 +262,7 @@ bool skipRelocationProcessAArch64(uint64_t &Type, uint64_t Contents) {
262262
return false;
263263
}
264264

265-
uint64_t adjustValueX86(uint64_t Type, uint64_t Value, uint64_t PC) {
265+
static uint64_t adjustValueX86(uint64_t Type, uint64_t Value, uint64_t PC) {
266266
switch (Type) {
267267
default:
268268
llvm_unreachable("not supported relocation");
@@ -275,7 +275,7 @@ uint64_t adjustValueX86(uint64_t Type, uint64_t Value, uint64_t PC) {
275275
return Value;
276276
}
277277

278-
uint64_t adjustValueAArch64(uint64_t Type, uint64_t Value, uint64_t PC) {
278+
static uint64_t adjustValueAArch64(uint64_t Type, uint64_t Value, uint64_t PC) {
279279
switch (Type) {
280280
default:
281281
llvm_unreachable("not supported relocation");
@@ -290,15 +290,16 @@ uint64_t adjustValueAArch64(uint64_t Type, uint64_t Value, uint64_t PC) {
290290
return Value;
291291
}
292292

293-
uint64_t extractValueX86(uint64_t Type, uint64_t Contents, uint64_t PC) {
293+
static uint64_t extractValueX86(uint64_t Type, uint64_t Contents, uint64_t PC) {
294294
if (Type == ELF::R_X86_64_32S)
295295
return SignExtend64<32>(Contents);
296296
if (Relocation::isPCRelative(Type))
297297
return SignExtend64(Contents, 8 * Relocation::getSizeForType(Type));
298298
return Contents;
299299
}
300300

301-
uint64_t extractValueAArch64(uint64_t Type, uint64_t Contents, uint64_t PC) {
301+
static uint64_t extractValueAArch64(uint64_t Type, uint64_t Contents,
302+
uint64_t PC) {
302303
switch (Type) {
303304
default:
304305
errs() << object::getELFRelocationTypeName(ELF::EM_AARCH64, Type) << '\n';
@@ -405,7 +406,7 @@ uint64_t extractValueAArch64(uint64_t Type, uint64_t Contents, uint64_t PC) {
405406
}
406407
}
407408

408-
bool isGOTX86(uint64_t Type) {
409+
static bool isGOTX86(uint64_t Type) {
409410
switch (Type) {
410411
default:
411412
return false;
@@ -425,7 +426,7 @@ bool isGOTX86(uint64_t Type) {
425426
}
426427
}
427428

428-
bool isGOTAArch64(uint64_t Type) {
429+
static bool isGOTAArch64(uint64_t Type) {
429430
switch (Type) {
430431
default:
431432
return false;
@@ -442,7 +443,7 @@ bool isGOTAArch64(uint64_t Type) {
442443
}
443444
}
444445

445-
bool isTLSX86(uint64_t Type) {
446+
static bool isTLSX86(uint64_t Type) {
446447
switch (Type) {
447448
default:
448449
return false;
@@ -453,7 +454,7 @@ bool isTLSX86(uint64_t Type) {
453454
}
454455
}
455456

456-
bool isTLSAArch64(uint64_t Type) {
457+
static bool isTLSAArch64(uint64_t Type) {
457458
switch (Type) {
458459
default:
459460
return false;
@@ -470,7 +471,7 @@ bool isTLSAArch64(uint64_t Type) {
470471
}
471472
}
472473

473-
bool isPCRelativeX86(uint64_t Type) {
474+
static bool isPCRelativeX86(uint64_t Type) {
474475
switch (Type) {
475476
default:
476477
llvm_unreachable("Unknown relocation type");
@@ -495,7 +496,7 @@ bool isPCRelativeX86(uint64_t Type) {
495496
}
496497
}
497498

498-
bool isPCRelativeAArch64(uint64_t Type) {
499+
static bool isPCRelativeAArch64(uint64_t Type) {
499500
switch (Type) {
500501
default:
501502
llvm_unreachable("Unknown relocation type");
@@ -541,8 +542,6 @@ bool isPCRelativeAArch64(uint64_t Type) {
541542
}
542543
}
543544

544-
} // end anonymous namespace
545-
546545
bool Relocation::isSupported(uint64_t Type) {
547546
if (Arch == Triple::aarch64)
548547
return isSupportedAArch64(Type);

bolt/lib/Passes/Aligner.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,9 @@ cl::opt<bool>
6464
namespace llvm {
6565
namespace bolt {
6666

67-
namespace {
68-
6967
// Align function to the specified byte-boundary (typically, 64) offsetting
7068
// the fuction by not more than the corresponding value
71-
void alignMaxBytes(BinaryFunction &Function) {
69+
static void alignMaxBytes(BinaryFunction &Function) {
7270
Function.setAlignment(opts::AlignFunctions);
7371
Function.setMaxAlignmentBytes(opts::AlignFunctionsMaxBytes);
7472
Function.setMaxColdAlignmentBytes(opts::AlignFunctionsMaxBytes);
@@ -78,7 +76,8 @@ void alignMaxBytes(BinaryFunction &Function) {
7876
// the fuction by not more than the minimum over
7977
// -- the size of the function
8078
// -- the specified number of bytes
81-
void alignCompact(BinaryFunction &Function, const MCCodeEmitter *Emitter) {
79+
static void alignCompact(BinaryFunction &Function,
80+
const MCCodeEmitter *Emitter) {
8281
const BinaryContext &BC = Function.getBinaryContext();
8382
size_t HotSize = 0;
8483
size_t ColdSize = 0;
@@ -101,8 +100,6 @@ void alignCompact(BinaryFunction &Function, const MCCodeEmitter *Emitter) {
101100
std::min(size_t(opts::AlignFunctionsMaxBytes), ColdSize));
102101
}
103102

104-
} // end anonymous namespace
105-
106103
void AlignerPass::alignBlocks(BinaryFunction &Function,
107104
const MCCodeEmitter *Emitter) {
108105
if (!Function.hasValidProfile() || !Function.isSimple())

bolt/lib/Passes/AllocCombiner.cpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,14 @@ extern cl::opt<bolt::FrameOptimizationType> FrameOptimization;
2525
namespace llvm {
2626
namespace bolt {
2727

28-
namespace {
29-
30-
bool getStackAdjustmentSize(const BinaryContext &BC, const MCInst &Inst,
31-
int64_t &Adjustment) {
28+
static bool getStackAdjustmentSize(const BinaryContext &BC, const MCInst &Inst,
29+
int64_t &Adjustment) {
3230
return BC.MIB->evaluateStackOffsetExpr(
3331
Inst, Adjustment, std::make_pair(BC.MIB->getStackPointer(), 0LL),
3432
std::make_pair(0, 0LL));
3533
}
3634

37-
bool isIndifferentToSP(const MCInst &Inst, const BinaryContext &BC) {
35+
static bool isIndifferentToSP(const MCInst &Inst, const BinaryContext &BC) {
3836
if (BC.MIB->isCFI(Inst))
3937
return true;
4038

@@ -50,21 +48,19 @@ bool isIndifferentToSP(const MCInst &Inst, const BinaryContext &BC) {
5048
return true;
5149
}
5250

53-
bool shouldProcess(const BinaryFunction &Function) {
51+
static bool shouldProcess(const BinaryFunction &Function) {
5452
return Function.isSimple() && Function.hasCFG() && !Function.isIgnored();
5553
}
5654

57-
void runForAllWeCare(std::map<uint64_t, BinaryFunction> &BFs,
58-
std::function<void(BinaryFunction &)> Task) {
55+
static void runForAllWeCare(std::map<uint64_t, BinaryFunction> &BFs,
56+
std::function<void(BinaryFunction &)> Task) {
5957
for (auto &It : BFs) {
6058
BinaryFunction &Function = It.second;
6159
if (shouldProcess(Function))
6260
Task(Function);
6361
}
6462
}
6563

66-
} // end anonymous namespace
67-
6864
void AllocCombinerPass::combineAdjustments(BinaryFunction &BF) {
6965
BinaryContext &BC = BF.getBinaryContext();
7066
for (BinaryBasicBlock &BB : BF) {

0 commit comments

Comments
 (0)