diff options
author | Xinliang David Li <davidxl@google.com> | 2016-01-20 01:26:34 +0000 |
---|---|---|
committer | Xinliang David Li <davidxl@google.com> | 2016-01-20 01:26:34 +0000 |
commit | 59411db5202ed5a4e680457109cdbeed217219b6 (patch) | |
tree | 9e2452b5de4c268ec505867ac5850e26025623a6 /llvm | |
parent | 19352b1cbe2763857b13f45c632d01f3d089f0d6 (diff) | |
download | bcm5719-llvm-59411db5202ed5a4e680457109cdbeed217219b6.tar.gz bcm5719-llvm-59411db5202ed5a4e680457109cdbeed217219b6.zip |
[PGO] Add a new interface to be used by Indirect Call Promotion
llvm-svn: 258271
Diffstat (limited to 'llvm')
-rw-r--r-- | llvm/include/llvm/ProfileData/InstrProf.h | 4 | ||||
-rw-r--r-- | llvm/lib/ProfileData/InstrProf.cpp | 7 | ||||
-rw-r--r-- | llvm/unittests/ProfileData/InstrProfTest.cpp | 36 |
3 files changed, 47 insertions, 0 deletions
diff --git a/llvm/include/llvm/ProfileData/InstrProf.h b/llvm/include/llvm/ProfileData/InstrProf.h index ea11885c073..b8405f79fb2 100644 --- a/llvm/include/llvm/ProfileData/InstrProf.h +++ b/llvm/include/llvm/ProfileData/InstrProf.h @@ -274,6 +274,10 @@ public: /// encoded in the format described in \c collectPGOFuncNameStrings. /// This method is a wrapper to \c readPGOFuncNameStrings method. inline std::error_code create(StringRef NameStrings); + /// A wrapper interface to populate the PGO symtab with functions + /// decls from module \c M. This interface is used by transformation + /// passes such as indirect function call promotion. + void create(const Module &M); /// Create InstrProfSymtab from a set of names iteratable from /// \p IterRange. This interface is used by IndexedProfReader. template <typename NameIterRange> void create(const NameIterRange &IterRange); diff --git a/llvm/lib/ProfileData/InstrProf.cpp b/llvm/lib/ProfileData/InstrProf.cpp index f856c25789e..8482b18f1e0 100644 --- a/llvm/lib/ProfileData/InstrProf.cpp +++ b/llvm/lib/ProfileData/InstrProf.cpp @@ -165,6 +165,13 @@ GlobalVariable *createPGOFuncNameVar(Function &F, StringRef FuncName) { return createPGOFuncNameVar(*F.getParent(), F.getLinkage(), FuncName); } +void InstrProfSymtab::create(const Module &M) { + for (const Function &F : M) + addFuncName(getPGOFuncName(F)); + + finalizeSymtab(); +} + int collectPGOFuncNameStrings(const std::vector<std::string> &NameStrs, bool doCompression, std::string &Result) { uint8_t Header[16], *P = Header; diff --git a/llvm/unittests/ProfileData/InstrProfTest.cpp b/llvm/unittests/ProfileData/InstrProfTest.cpp index 51f52f2a077..54a13e44b0a 100644 --- a/llvm/unittests/ProfileData/InstrProfTest.cpp +++ b/llvm/unittests/ProfileData/InstrProfTest.cpp @@ -7,6 +7,9 @@ // //===----------------------------------------------------------------------===// +#include "llvm/IR/Function.h" +#include "llvm/IR/LLVMContext.h" +#include "llvm/IR/Module.h" #include "llvm/ProfileData/InstrProfReader.h" #include "llvm/ProfileData/InstrProfWriter.h" #include "llvm/Support/Compression.h" @@ -658,6 +661,39 @@ TEST_F(InstrProfTest, instr_prof_symtab_test) { ASSERT_EQ(StringRef("bar3"), R); } +TEST_F(InstrProfTest, instr_prof_symtab_module_test) { + LLVMContext Ctx; + std::unique_ptr<Module> M = llvm::make_unique<Module>("MyModule.cpp", Ctx); + FunctionType *FTy = FunctionType::get(Type::getVoidTy(Ctx), + /*isVarArg=*/false); + Function::Create(FTy, Function::ExternalLinkage, "Gfoo", M.get()); + Function::Create(FTy, Function::ExternalLinkage, "Gblah", M.get()); + Function::Create(FTy, Function::ExternalLinkage, "Gbar", M.get()); + Function::Create(FTy, Function::InternalLinkage, "Ifoo", M.get()); + Function::Create(FTy, Function::InternalLinkage, "Iblah", M.get()); + Function::Create(FTy, Function::InternalLinkage, "Ibar", M.get()); + Function::Create(FTy, Function::PrivateLinkage, "Pfoo", M.get()); + Function::Create(FTy, Function::PrivateLinkage, "Pblah", M.get()); + Function::Create(FTy, Function::PrivateLinkage, "Pbar", M.get()); + Function::Create(FTy, Function::WeakODRLinkage, "Wfoo", M.get()); + Function::Create(FTy, Function::WeakODRLinkage, "Wblah", M.get()); + Function::Create(FTy, Function::WeakODRLinkage, "Wbar", M.get()); + + InstrProfSymtab ProfSymtab; + ProfSymtab.create(*(M.get())); + + StringRef Funcs[] = {"Gfoo", "Gblah", "Gbar", "Ifoo", "Iblah", "Ibar", + "Pfoo", "Pblah", "Pbar", "Wfoo", "Wblah", "Wbar"}; + + for (unsigned I = 0; I < sizeof(Funcs) / sizeof(*Funcs); I++) { + Function *F = M->getFunction(Funcs[I]); + ASSERT_TRUE(F != NULL); + StringRef PGOName = getPGOFuncName(*F); + ASSERT_EQ(PGOName, + ProfSymtab.getFuncName(IndexedInstrProf::ComputeHash(PGOName))); + } +} + TEST_F(InstrProfTest, instr_prof_symtab_compression_test) { std::vector<std::string> FuncNames1; std::vector<std::string> FuncNames2; |