Skip to content

Commit fe3c23b

Browse files
committed
Revert "[CGData][GMF] Skip No Params (llvm#116548)"
This reverts commit fdf1f69.
1 parent b0ca543 commit fe3c23b

File tree

4 files changed

+22
-86
lines changed

4 files changed

+22
-86
lines changed

llvm/lib/CGData/StableFunctionMap.cpp

+16-37
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
//===----------------------------------------------------------------------===//
1515

1616
#include "llvm/CGData/StableFunctionMap.h"
17-
#include "llvm/ADT/SmallSet.h"
1817
#include "llvm/Support/CommandLine.h"
1918
#include "llvm/Support/Debug.h"
2019

@@ -36,30 +35,21 @@ static cl::opt<unsigned> GlobalMergingMaxParams(
3635
cl::desc(
3736
"The maximum number of parameters allowed when merging functions."),
3837
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(
4939
"global-merging-param-overhead",
5040
cl::desc("The overhead cost associated with each parameter when merging "
5141
"functions."),
52-
cl::init(2.0), cl::Hidden);
53-
static cl::opt<double>
42+
cl::init(2), cl::Hidden);
43+
static cl::opt<unsigned>
5444
GlobalMergingCallOverhead("global-merging-call-overhead",
5545
cl::desc("The overhead cost associated with each "
5646
"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(
5949
"global-merging-extra-threshold",
6050
cl::desc("An additional cost threshold that must be exceeded for merging "
6151
"to be considered beneficial."),
62-
cl::init(0.0), cl::Hidden);
52+
cl::init(0), cl::Hidden);
6353

6454
unsigned StableFunctionMap::getIdOrCreateForName(StringRef Name) {
6555
auto It = NameToId.find(Name);
@@ -170,32 +160,21 @@ static bool isProfitable(
170160
if (InstCount < GlobalMergingMinInstrs)
171161
return false;
172162

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;
192172

193-
double Benefit =
194-
InstCount * (StableFunctionCount - 1) * GlobalMergingInstOverhead;
195173
bool Result = Benefit > Cost;
196174
LLVM_DEBUG(dbgs() << "isProfitable: Hash = " << SFS[0]->Hash << ", "
197175
<< "StableFunctionCount = " << StableFunctionCount
198176
<< ", InstCount = " << InstCount
177+
<< ", ParamCount = " << ParamCount
199178
<< ", Benefit = " << Benefit << ", Cost = " << Cost
200179
<< ", Result = " << (Result ? "true" : "false") << "\n");
201180
return Result;

llvm/lib/CodeGen/GlobalMergeFunctions.cpp

+5-6
Original file line numberDiff line numberDiff line change
@@ -405,13 +405,12 @@ static ParamLocsVecTy computeParamInfo(
405405
}
406406

407407
ParamLocsVecTy ParamLocsVec;
408-
for (auto &[HashSeq, Locs] : HashSeqToLocs)
408+
for (auto &[HashSeq, Locs] : HashSeqToLocs) {
409409
ParamLocsVec.push_back(std::move(Locs));
410-
411-
llvm::sort(ParamLocsVec, [&](const ParamLocs &L, const ParamLocs &R) {
412-
return L[0] < R[0];
413-
});
414-
410+
llvm::sort(ParamLocsVec, [&](const ParamLocs &L, const ParamLocs &R) {
411+
return L[0] < R[0];
412+
});
413+
}
415414
return ParamLocsVec;
416415
}
417416

llvm/test/CodeGen/Generic/cgdata-merge-no-params.ll

-42
This file was deleted.

llvm/test/CodeGen/Generic/cgdata-merge-local.ll renamed to llvm/test/ThinLTO/AArch64/cgdata-merge-local.ll

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
; while parameterizing a difference in their global variables, g1 and g2.
33
; To achieve this, we create two instances of the global merging function, f1.Tgm and f2.Tgm,
44
; which are tail-called from thunks f1 and f2 respectively.
5-
; These identical functions, f1.Tgm and f2.Tgm, will be folded by the linker via Identical Code Folding (ICF).
5+
; These identical functions, f1.Tgm and f2.Tgm, will be folded by the linker via Identical Code Folding (IFC).
66

77
; RUN: opt -S --passes=global-merge-func %s | FileCheck %s
88

0 commit comments

Comments
 (0)