@@ -168,13 +168,33 @@ cl::opt<bool> SkipRetExitBlock(
168
168
169
169
using LoadStorePair = std::pair<Instruction *, Instruction *>;
170
170
171
+ static uint64_t getIntModuleFlagOrZero (const Module &M, StringRef Flag) {
172
+ auto *MD = dyn_cast_or_null<ConstantAsMetadata>(M.getModuleFlag (Flag));
173
+ if (!MD)
174
+ return 0 ;
175
+
176
+ // If the flag is a ConstantAsMetadata, it should be an integer representable
177
+ // in 64-bits.
178
+ return cast<ConstantInt>(MD->getValue ())->getZExtValue ();
179
+ }
180
+
181
+ static bool enablesValueProfiling (const Module &M) {
182
+ return isIRPGOFlagSet (&M) ||
183
+ getIntModuleFlagOrZero (M, " EnableValueProfiling" ) != 0 ;
184
+ }
185
+
186
+ // Conservatively returns true if value profiling is enabled.
187
+ static bool profDataReferencedByCode (const Module &M) {
188
+ return enablesValueProfiling (M);
189
+ }
190
+
171
191
class InstrLowerer final {
172
192
public:
173
193
InstrLowerer (Module &M, const InstrProfOptions &Options,
174
194
std::function<const TargetLibraryInfo &(Function &F)> GetTLI,
175
195
bool IsCS)
176
196
: M(M), Options(Options), TT(Triple(M.getTargetTriple())), IsCS(IsCS),
177
- GetTLI (GetTLI) {}
197
+ GetTLI (GetTLI), DataReferencedByCode(profDataReferencedByCode(M)) {}
178
198
179
199
bool lower ();
180
200
@@ -186,6 +206,8 @@ class InstrLowerer final {
186
206
const bool IsCS;
187
207
188
208
std::function<const TargetLibraryInfo &(Function &F)> GetTLI;
209
+
210
+ const bool DataReferencedByCode;
189
211
struct PerFunctionProfileData {
190
212
uint32_t NumValueSites[IPVK_Last + 1 ] = {};
191
213
GlobalVariable *RegionCounters = nullptr ;
@@ -1057,26 +1079,6 @@ static std::string getVarName(InstrProfInstBase *Inc, StringRef Prefix,
1057
1079
return (Prefix + Name + " ." + Twine (FuncHash)).str ();
1058
1080
}
1059
1081
1060
- static uint64_t getIntModuleFlagOrZero (const Module &M, StringRef Flag) {
1061
- auto *MD = dyn_cast_or_null<ConstantAsMetadata>(M.getModuleFlag (Flag));
1062
- if (!MD)
1063
- return 0 ;
1064
-
1065
- // If the flag is a ConstantAsMetadata, it should be an integer representable
1066
- // in 64-bits.
1067
- return cast<ConstantInt>(MD->getValue ())->getZExtValue ();
1068
- }
1069
-
1070
- static bool enablesValueProfiling (const Module &M) {
1071
- return isIRPGOFlagSet (&M) ||
1072
- getIntModuleFlagOrZero (M, " EnableValueProfiling" ) != 0 ;
1073
- }
1074
-
1075
- // Conservatively returns true if data variables may be referenced by code.
1076
- static bool profDataReferencedByCode (const Module &M) {
1077
- return enablesValueProfiling (M);
1078
- }
1079
-
1080
1082
static inline bool shouldRecordFunctionAddr (Function *F) {
1081
1083
// Only record function addresses if IR PGO is enabled or if clang value
1082
1084
// profiling is enabled. Recording function addresses greatly increases object
@@ -1192,7 +1194,6 @@ static bool needsRuntimeRegistrationOfSectionRange(const Triple &TT) {
1192
1194
1193
1195
void InstrLowerer::maybeSetComdat (GlobalVariable *GV, Function *Fn,
1194
1196
StringRef VarName) {
1195
- bool DataReferencedByCode = profDataReferencedByCode (M);
1196
1197
bool NeedComdat = needsComdatForCounter (*Fn, M);
1197
1198
bool UseComdat = (NeedComdat || TT.isOSBinFormatELF ());
1198
1199
@@ -1418,7 +1419,6 @@ void InstrLowerer::createDataVariable(InstrProfCntrInstBase *Inc) {
1418
1419
Visibility = GlobalValue::DefaultVisibility;
1419
1420
}
1420
1421
1421
- bool DataReferencedByCode = profDataReferencedByCode (M);
1422
1422
bool NeedComdat = needsComdatForCounter (*Fn, M);
1423
1423
bool Renamed;
1424
1424
@@ -1719,7 +1719,7 @@ void InstrLowerer::emitUses() {
1719
1719
// and ensure this GC property as well. Otherwise, we have to conservatively
1720
1720
// make all of the sections retained by the linker.
1721
1721
if (TT.isOSBinFormatELF () || TT.isOSBinFormatMachO () ||
1722
- (TT.isOSBinFormatCOFF () && !profDataReferencedByCode (M) ))
1722
+ (TT.isOSBinFormatCOFF () && !DataReferencedByCode ))
1723
1723
appendToCompilerUsed (M, CompilerUsedVars);
1724
1724
else
1725
1725
appendToUsed (M, CompilerUsedVars);
0 commit comments