14
14
// ===----------------------------------------------------------------------===//
15
15
16
16
#include " llvm/CGData/StableFunctionMap.h"
17
- #include " llvm/ADT/SmallSet.h"
18
17
#include " llvm/Support/CommandLine.h"
19
18
#include " llvm/Support/Debug.h"
20
19
@@ -36,30 +35,21 @@ static cl::opt<unsigned> GlobalMergingMaxParams(
36
35
cl::desc (
37
36
" The maximum number of parameters allowed when merging functions." ),
38
37
cl::init(std::numeric_limits<unsigned >::max()), cl::Hidden);
39
- static cl::opt<bool > GlobalMergingSkipNoParams (
40
- " global-merging-skip-no-params" ,
41
- cl::desc (" Skip merging functions with no parameters." ), cl::init(true ),
42
- cl::Hidden);
43
- static cl::opt<double > GlobalMergingInstOverhead (
44
- " global-merging-inst-overhead" ,
45
- cl::desc (" The overhead cost associated with each instruction when lowering "
46
- " to machine instruction." ),
47
- cl::init(1.2 ), cl::Hidden);
48
- static cl::opt<double > GlobalMergingParamOverhead (
38
+ static cl::opt<unsigned > GlobalMergingParamOverhead (
49
39
" global-merging-param-overhead" ,
50
40
cl::desc (" The overhead cost associated with each parameter when merging "
51
41
" functions." ),
52
- cl::init(2.0 ), cl::Hidden);
53
- static cl::opt<double >
42
+ cl::init(2 ), cl::Hidden);
43
+ static cl::opt<unsigned >
54
44
GlobalMergingCallOverhead (" global-merging-call-overhead" ,
55
45
cl::desc (" The overhead cost associated with each "
56
46
" function call when merging functions." ),
57
- cl::init(1.0 ), cl::Hidden);
58
- static cl::opt<double > GlobalMergingExtraThreshold (
47
+ cl::init(1 ), cl::Hidden);
48
+ static cl::opt<unsigned > GlobalMergingExtraThreshold (
59
49
" global-merging-extra-threshold" ,
60
50
cl::desc (" An additional cost threshold that must be exceeded for merging "
61
51
" to be considered beneficial." ),
62
- cl::init(0.0 ), cl::Hidden);
52
+ cl::init(0 ), cl::Hidden);
63
53
64
54
unsigned StableFunctionMap::getIdOrCreateForName (StringRef Name) {
65
55
auto It = NameToId.find (Name);
@@ -170,32 +160,21 @@ static bool isProfitable(
170
160
if (InstCount < GlobalMergingMinInstrs)
171
161
return false ;
172
162
173
- double Cost = 0.0 ;
174
- SmallSet<stable_hash, 8 > UniqueHashVals;
175
- for (auto &SF : SFS) {
176
- UniqueHashVals.clear ();
177
- for (auto &[IndexPair, Hash] : *SF->IndexOperandHashMap )
178
- UniqueHashVals.insert (Hash);
179
- unsigned ParamCount = UniqueHashVals.size ();
180
- if (ParamCount > GlobalMergingMaxParams)
181
- return false ;
182
- // Theoretically, if ParamCount is 0, it results in identical code folding
183
- // (ICF), which we can skip merging here since the linker already handles
184
- // ICF. This pass would otherwise introduce unnecessary thunks that are
185
- // merely direct jumps. However, enabling this could be beneficial depending
186
- // on downstream passes, so we provide an option for it.
187
- if (GlobalMergingSkipNoParams && ParamCount == 0 )
188
- return false ;
189
- Cost += ParamCount * GlobalMergingParamOverhead + GlobalMergingCallOverhead;
190
- }
191
- Cost += GlobalMergingExtraThreshold;
163
+ unsigned ParamCount = SFS[0 ]->IndexOperandHashMap ->size ();
164
+ if (ParamCount > GlobalMergingMaxParams)
165
+ return false ;
166
+
167
+ unsigned Benefit = InstCount * (StableFunctionCount - 1 );
168
+ unsigned Cost =
169
+ (GlobalMergingParamOverhead * ParamCount + GlobalMergingCallOverhead) *
170
+ StableFunctionCount +
171
+ GlobalMergingExtraThreshold;
192
172
193
- double Benefit =
194
- InstCount * (StableFunctionCount - 1 ) * GlobalMergingInstOverhead;
195
173
bool Result = Benefit > Cost;
196
174
LLVM_DEBUG (dbgs () << " isProfitable: Hash = " << SFS[0 ]->Hash << " , "
197
175
<< " StableFunctionCount = " << StableFunctionCount
198
176
<< " , InstCount = " << InstCount
177
+ << " , ParamCount = " << ParamCount
199
178
<< " , Benefit = " << Benefit << " , Cost = " << Cost
200
179
<< " , Result = " << (Result ? " true" : " false" ) << " \n " );
201
180
return Result;
0 commit comments