[PGO] code simplification: use existing VP annotation API /NFC

llvm-svn: 259819
This commit is contained in:
Xinliang David Li 2016-02-04 19:54:17 +00:00
parent 97c2868362
commit 5527a9dd42
1 changed files with 3 additions and 27 deletions

View File

@ -780,35 +780,11 @@ void CodeGenPGO::valueProfile(CGBuilderTy &Builder, uint32_t ValueKind,
// pairs for each function.
if (NumValueSites[ValueKind] >= ProfRecord->getNumValueSites(ValueKind))
return;
uint32_t NV = ProfRecord->getNumValueDataForSite(ValueKind,
llvm::annotateValueSite(CGM.getModule(), *ValueSite, *ProfRecord,
(llvm::InstrProfValueKind)ValueKind,
NumValueSites[ValueKind]);
std::unique_ptr<InstrProfValueData[]> VD =
ProfRecord->getValueForSite(ValueKind, NumValueSites[ValueKind]);
uint64_t Sum = 0;
for (uint32_t I = 0; I < NV; ++I)
Sum += VD[I].Count;
llvm::LLVMContext &Ctx = CGM.getLLVMContext();
llvm::MDBuilder MDHelper(Ctx);
SmallVector<llvm::Metadata*, 3> Vals;
Vals.push_back(MDHelper.createString("VP"));
Vals.push_back(MDHelper.createConstant(
llvm::ConstantInt::get(llvm::Type::getInt32Ty(Ctx), ValueKind)));
Vals.push_back(MDHelper.createConstant(
llvm::ConstantInt::get(llvm::Type::getInt64Ty(Ctx), Sum)));
uint32_t MDCount = 3;
for (uint32_t I = 0; I < NV; ++I) {
Vals.push_back(MDHelper.createConstant(
llvm::ConstantInt::get(llvm::Type::getInt64Ty(Ctx), VD[I].Value)));
Vals.push_back(MDHelper.createConstant(
llvm::ConstantInt::get(llvm::Type::getInt64Ty(Ctx), VD[I].Count)));
if (--MDCount == 0)
break;
}
ValueSite->setMetadata(
llvm::LLVMContext::MD_prof, llvm::MDNode::get(Ctx, Vals));
NumValueSites[ValueKind]++;
}
}