if (CGM.getCodeGenOpts().InstrumentForProfiling)
EmitMCountInstrumentation();
- PGO.assignRegionCounters(GD);
if (CGM.getPGOData() && D) {
// Turn on InlineHint attribute for hot functions.
if (CGM.getPGOData()->isHotFunction(CGM.getMangledName(GD)))
StartFunction(GD, ResTy, Fn, FnInfo, Args, BodyRange.getBegin());
// Generate the body of the function.
+ PGO.assignRegionCounters(GD.getDecl(), CGM.getMangledName(GD));
if (isa<CXXDestructorDecl>(FD))
EmitDestructorBody(Args);
else if (isa<CXXConstructorDecl>(FD))
if (!CurFn->doesNotThrow())
TryMarkNoThrow(CurFn);
- PGO.emitWriteoutFunction(CurGD);
+ PGO.emitWriteoutFunction(CGM.getMangledName(CurGD));
PGO.destroyRegionCounters();
}
return false;
}
-void CodeGenPGO::emitWriteoutFunction(GlobalDecl &GD) {
+void CodeGenPGO::emitWriteoutFunction(StringRef Name) {
if (!CGM.getCodeGenOpts().ProfileInstrGenerate)
return;
CGM.getModule().getOrInsertFunction("llvm_pgo_emit", FTy);
llvm::Constant *MangledName =
- CGM.GetAddrOfConstantCString(CGM.getMangledName(GD), "__llvm_pgo_name");
+ CGM.GetAddrOfConstantCString(Name, "__llvm_pgo_name");
MangledName = llvm::ConstantExpr::getBitCast(MangledName, Int8PtrTy);
PGOBuilder.CreateCall3(EmitFunc, MangledName,
PGOBuilder.getInt32(NumRegionCounters),
};
}
-void CodeGenPGO::assignRegionCounters(GlobalDecl &GD) {
+void CodeGenPGO::assignRegionCounters(const Decl *D, StringRef Name) {
bool InstrumentRegions = CGM.getCodeGenOpts().ProfileInstrGenerate;
PGOProfileData *PGOData = CGM.getPGOData();
if (!InstrumentRegions && !PGOData)
return;
- const Decl *D = GD.getDecl();
if (!D)
return;
mapRegionCounters(D);
if (InstrumentRegions)
emitCounterVariables();
if (PGOData) {
- loadRegionCounts(GD, PGOData);
+ loadRegionCounts(Name, PGOData);
computeRegionCounts(D);
}
}
Builder.CreateStore(Count, Addr);
}
-void CodeGenPGO::loadRegionCounts(GlobalDecl &GD, PGOProfileData *PGOData) {
+void CodeGenPGO::loadRegionCounts(StringRef Name, PGOProfileData *PGOData) {
// For now, ignore the counts from the PGO data file only if the number of
// counters does not match. This could be tightened down in the future to
// ignore counts when the input changes in various ways, e.g., by comparing a
// hash value based on some characteristics of the input.
RegionCounts = new std::vector<uint64_t>();
- if (PGOData->getFunctionCounts(CGM.getMangledName(GD), *RegionCounts) ||
+ if (PGOData->getFunctionCounts(Name, *RegionCounts) ||
RegionCounts->size() != NumRegionCounters) {
delete RegionCounts;
RegionCounts = 0;
/// function. Does nothing if instrumentation is not enabled and either
/// generates global variables or associates PGO data with each of the
/// counters depending on whether we are generating or using instrumentation.
- void assignRegionCounters(GlobalDecl &GD);
+ void assignRegionCounters(const Decl *D, StringRef Name);
/// Emit code to write counts for a given function to disk, if necessary.
- void emitWriteoutFunction(GlobalDecl &GD);
+ void emitWriteoutFunction(StringRef Name);
/// Clean up region counter state. Must be called if assignRegionCounters is
/// used.
void destroyRegionCounters();
private:
void mapRegionCounters(const Decl *D);
void computeRegionCounts(const Decl *D);
- void loadRegionCounts(GlobalDecl &GD, PGOProfileData *PGOData);
+ void loadRegionCounts(StringRef Name, PGOProfileData *PGOData);
void emitCounterVariables();
/// Emit code to increment the counter at the given index