1717
1818using namespace llvm ;
1919
20- namespace opts {
21-
22- extern cl::OptionCategory BoltOptCategory;
23-
24- extern cl::opt<bool > AlignBlocks;
25- extern cl::opt<bool > PreserveBlocksAlignment;
26- extern cl::opt<unsigned > AlignFunctions;
27-
28- static cl::opt<unsigned > AlignBlocksMinSize (
29- " align-blocks-min-size" ,
30- cl::desc (" minimal size of the basic block that should be aligned" ),
31- cl::init(0 ), cl::ZeroOrMore, cl::Hidden, cl::cat(BoltOptCategory));
32-
33- static cl::opt<unsigned > AlignBlocksThreshold (
34- " align-blocks-threshold" ,
35- cl::desc (
36- " align only blocks with frequency larger than containing function "
37- " execution frequency specified in percent. E.g. 1000 means aligning "
38- " blocks that are 10 times more frequently executed than the "
39- " containing function." ),
40- cl::init(800 ), cl::Hidden, cl::cat(BoltOptCategory));
41-
42- static cl::opt<unsigned > AlignFunctionsMaxBytes (
43- " align-functions-max-bytes" ,
44- cl::desc (" maximum number of bytes to use to align functions" ), cl::init(32 ),
45- cl::cat(BoltOptCategory));
46-
47- static cl::opt<unsigned >
48- BlockAlignment (" block-alignment" ,
49- cl::desc (" boundary to use for alignment of basic blocks" ),
50- cl::init(16 ), cl::ZeroOrMore, cl::cat(BoltOptCategory));
51-
52- static cl::opt<bool >
53- UseCompactAligner (" use-compact-aligner" ,
54- cl::desc (" Use compact approach for aligning functions" ),
55- cl::init(true ), cl::cat(BoltOptCategory));
56-
57- } // end namespace opts
58-
5920namespace llvm {
6021namespace bolt {
6122
6223// Align function to the specified byte-boundary (typically, 64) offsetting
6324// the function by not more than the corresponding value
6425static void alignMaxBytes (BinaryFunction &Function) {
65- Function.setAlignment (opts::AlignFunctions);
66- Function.setMaxAlignmentBytes (opts::AlignFunctionsMaxBytes);
67- Function.setMaxColdAlignmentBytes (opts::AlignFunctionsMaxBytes);
26+ const BinaryContext &BC = Function.getBinaryContext ();
27+ Function.setAlignment (BC .AlignFunctions );
28+ Function.setMaxAlignmentBytes (BC .AlignFunctionsMaxBytes );
29+ Function.setMaxColdAlignmentBytes (BC .AlignFunctionsMaxBytes );
6830}
6931
7032// Align function to the specified byte-boundary (typically, 64) offsetting
@@ -90,16 +52,16 @@ static void alignCompact(BinaryFunction &Function,
9052 else
9153 HotSize += BC .computeCodeSize (BB .begin (), BB .end (), Emitter);
9254
93- Function.setAlignment (opts:: AlignFunctions);
55+ Function.setAlignment (BC . AlignFunctions );
9456 if (HotSize > 0 )
9557 Function.setMaxAlignmentBytes (
96- std::min (size_t (opts:: AlignFunctionsMaxBytes), HotSize));
58+ std::min (size_t (BC . AlignFunctionsMaxBytes ), HotSize));
9759
9860 // using the same option, max-align-bytes, both for cold and hot parts of the
9961 // functions, as aligning cold functions typically does not affect performance
10062 if (ColdSize > 0 )
10163 Function.setMaxColdAlignmentBytes (
102- std::min (size_t (opts:: AlignFunctionsMaxBytes), ColdSize));
64+ std::min (size_t (BC . AlignFunctionsMaxBytes ), ColdSize));
10365}
10466
10567void AlignerPass::alignBlocks (BinaryFunction &Function,
@@ -115,7 +77,7 @@ void AlignerPass::alignBlocks(BinaryFunction &Function,
11577 for (BinaryBasicBlock *BB : Function.getLayout ().blocks ()) {
11678 uint64_t Count = BB ->getKnownExecutionCount ();
11779
118- if (Count <= FuncCount * opts:: AlignBlocksThreshold / 100 ) {
80+ if (Count <= FuncCount * BC . AlignBlocksThreshold / 100 ) {
11981 PrevBB = BB ;
12082 continue ;
12183 }
@@ -132,12 +94,12 @@ void AlignerPass::alignBlocks(BinaryFunction &Function,
13294 const uint64_t BlockSize =
13395 BC .computeCodeSize (BB ->begin (), BB ->end (), Emitter);
13496 const uint64_t BytesToUse =
135- std::min<uint64_t >(opts:: BlockAlignment - 1 , BlockSize);
97+ std::min<uint64_t >(BC . BlockAlignment - 1 , BlockSize);
13698
137- if (opts:: AlignBlocksMinSize && BlockSize < opts:: AlignBlocksMinSize)
99+ if (BC . AlignBlocksMinSize && BlockSize < BC . AlignBlocksMinSize )
138100 continue ;
139101
140- BB ->setAlignment (opts:: BlockAlignment);
102+ BB ->setAlignment (BC . BlockAlignment );
141103 BB ->setAlignmentMaxBytes (BytesToUse);
142104
143105 // Update stats.
@@ -153,14 +115,14 @@ Error AlignerPass::runOnFunctions(BinaryContext &BC) {
153115 if (!BC .HasRelocations )
154116 return Error::success ();
155117
156- AlignHistogram.resize (opts:: BlockAlignment);
118+ AlignHistogram.resize (BC . BlockAlignment );
157119
158120 ParallelUtilities::WorkFuncTy WorkFun = [&](BinaryFunction &BF ) {
159121 // Create a separate MCCodeEmitter to allow lock free execution
160122 BinaryContext::IndependentCodeEmitter Emitter =
161123 BC .createIndependentMCCodeEmitter ();
162124
163- if (opts:: UseCompactAligner)
125+ if (BC . UseCompactAligner )
164126 alignCompact (BF , Emitter.MCE .get ());
165127 else
166128 alignMaxBytes (BF );
@@ -185,7 +147,7 @@ Error AlignerPass::runOnFunctions(BinaryContext &BC) {
185147 BC .getColdCodeSectionName ();
186148 BC .updateMaxCodeAlignment (Align, InMainSection, InColdSection);
187149
188- if (opts:: AlignBlocks && !opts:: PreserveBlocksAlignment)
150+ if (BC . AlignBlocks && !BC . PreserveBlocksAlignment )
189151 alignBlocks (BF , Emitter.MCE .get ());
190152 };
191153
0 commit comments