From 5527a9dd42f0a9e09353699252f0d4fcd001923b Mon Sep 17 00:00:00 2001 From: Xinliang David Li Date: Thu, 4 Feb 2016 19:54:17 +0000 Subject: [PATCH] [PGO] code simplification: use existing VP annotation API /NFC llvm-svn: 259819 --- clang/lib/CodeGen/CodeGenPGO.cpp | 30 +++--------------------------- 1 file changed, 3 insertions(+), 27 deletions(-) diff --git a/clang/lib/CodeGen/CodeGenPGO.cpp b/clang/lib/CodeGen/CodeGenPGO.cpp index c59d2d1b27fe..2d46adfce135 100644 --- a/clang/lib/CodeGen/CodeGenPGO.cpp +++ b/clang/lib/CodeGen/CodeGenPGO.cpp @@ -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, - NumValueSites[ValueKind]); - std::unique_ptr VD = - ProfRecord->getValueForSite(ValueKind, NumValueSites[ValueKind]); - uint64_t Sum = 0; - for (uint32_t I = 0; I < NV; ++I) - Sum += VD[I].Count; + llvm::annotateValueSite(CGM.getModule(), *ValueSite, *ProfRecord, + (llvm::InstrProfValueKind)ValueKind, + NumValueSites[ValueKind]); - llvm::LLVMContext &Ctx = CGM.getLLVMContext(); - llvm::MDBuilder MDHelper(Ctx); - SmallVector 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]++; } }