[llvm] r258271 - [PGO] Add a new interface to be used by Indirect Call Promotion

Xinliang David Li via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 19 17:26:35 PST 2016


Author: davidxl
Date: Tue Jan 19 19:26:34 2016
New Revision: 258271

URL: http://llvm.org/viewvc/llvm-project?rev=258271&view=rev
Log:
[PGO] Add a new interface to be used by Indirect Call Promotion

Modified:
    llvm/trunk/include/llvm/ProfileData/InstrProf.h
    llvm/trunk/lib/ProfileData/InstrProf.cpp
    llvm/trunk/unittests/ProfileData/InstrProfTest.cpp

Modified: llvm/trunk/include/llvm/ProfileData/InstrProf.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ProfileData/InstrProf.h?rev=258271&r1=258270&r2=258271&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ProfileData/InstrProf.h (original)
+++ llvm/trunk/include/llvm/ProfileData/InstrProf.h Tue Jan 19 19:26:34 2016
@@ -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);

Modified: llvm/trunk/lib/ProfileData/InstrProf.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ProfileData/InstrProf.cpp?rev=258271&r1=258270&r2=258271&view=diff
==============================================================================
--- llvm/trunk/lib/ProfileData/InstrProf.cpp (original)
+++ llvm/trunk/lib/ProfileData/InstrProf.cpp Tue Jan 19 19:26:34 2016
@@ -165,6 +165,13 @@ GlobalVariable *createPGOFuncNameVar(Fun
   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;

Modified: llvm/trunk/unittests/ProfileData/InstrProfTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ProfileData/InstrProfTest.cpp?rev=258271&r1=258270&r2=258271&view=diff
==============================================================================
--- llvm/trunk/unittests/ProfileData/InstrProfTest.cpp (original)
+++ llvm/trunk/unittests/ProfileData/InstrProfTest.cpp Tue Jan 19 19:26:34 2016
@@ -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_
   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;




More information about the llvm-commits mailing list