OSDN Git Service

Interface to get/set profile summary metadata to module
authorEaswaran Raman <eraman@google.com>
Fri, 18 Mar 2016 21:29:30 +0000 (21:29 +0000)
committerEaswaran Raman <eraman@google.com>
Fri, 18 Mar 2016 21:29:30 +0000 (21:29 +0000)
Differential Revision: http://reviews.llvm.org/D17894

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@263835 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/IR/Module.h
lib/IR/Module.cpp
unittests/ProfileData/InstrProfTest.cpp
unittests/ProfileData/SampleProfTest.cpp

index 3373528..09cf531 100644 (file)
@@ -637,7 +637,7 @@ public:
   void setPICLevel(PICLevel::Level PL);
 /// @}
 
-  /// @name Utility functions for querying and setting PGO counts
+  /// @name Utility functions for querying and setting PGO summary
   /// @{
 
   /// \brief Set maximum function count in PGO mode
@@ -645,6 +645,12 @@ public:
 
   /// \brief Returns maximum function count in PGO mode
   Optional<uint64_t> getMaximumFunctionCount();
+
+  /// \brief Attach profile summary metadata to this module.
+  void setProfileSummary(Metadata *M);
+
+  /// \brief Returns profile summary metadata
+  Metadata *getProfileSummary();
   /// @}
 };
 
index fc3f9d0..a0bda00 100644 (file)
@@ -485,3 +485,11 @@ Optional<uint64_t> Module::getMaximumFunctionCount() {
     return None;
   return cast<ConstantInt>(Val->getValue())->getZExtValue();
 }
+
+void Module::setProfileSummary(Metadata *M) {
+  addModuleFlag(ModFlagBehavior::Error, "ProfileSummary", M);
+}
+
+Metadata *Module::getProfileSummary() {
+  return getModuleFlag("ProfileSummary");
+}
index 34bb1f2..f0710e7 100644 (file)
@@ -180,6 +180,8 @@ TEST_F(InstrProfTest, get_profile_summary) {
   };
   InstrProfSummary &PS = Reader->getSummary();
   VerifySummary(PS);
+
+  // Test that conversion of summary to and from Metadata works.
   Metadata *MD = PS.getMD(getGlobalContext());
   ASSERT_TRUE(MD);
   ProfileSummary *PSFromMD = ProfileSummary::getFromMD(MD);
@@ -188,6 +190,18 @@ TEST_F(InstrProfTest, get_profile_summary) {
   InstrProfSummary *IPS = cast<InstrProfSummary>(PSFromMD);
   VerifySummary(*IPS);
   delete IPS;
+
+  // Test that summary can be attached to and read back from module.
+  Module M("my_module", getGlobalContext());
+  M.setProfileSummary(MD);
+  MD = M.getProfileSummary();
+  ASSERT_TRUE(MD);
+  PSFromMD = ProfileSummary::getFromMD(MD);
+  ASSERT_TRUE(PSFromMD);
+  ASSERT_TRUE(isa<InstrProfSummary>(PSFromMD));
+  IPS = cast<InstrProfSummary>(PSFromMD);
+  VerifySummary(*IPS);
+  delete IPS;
 }
 
 TEST_P(MaybeSparseInstrProfTest, get_icall_data_read_write) {
index 9738e97..b2e05c3 100644 (file)
@@ -126,6 +126,7 @@ struct SampleProfTest : ::testing::Test {
     SampleProfileSummary &Summary = Reader->getSummary();
     VerifySummary(Summary);
 
+    // Test that conversion of summary to and from Metadata works.
     Metadata *MD = Summary.getMD(getGlobalContext());
     ASSERT_TRUE(MD);
     ProfileSummary *PS = ProfileSummary::getFromMD(MD);
@@ -134,6 +135,18 @@ struct SampleProfTest : ::testing::Test {
     SampleProfileSummary *SPS = cast<SampleProfileSummary>(PS);
     VerifySummary(*SPS);
     delete SPS;
+
+    // Test that summary can be attached to and read back from module.
+    Module M("my_module", getGlobalContext());
+    M.setProfileSummary(MD);
+    MD = M.getProfileSummary();
+    ASSERT_TRUE(MD);
+    PS = ProfileSummary::getFromMD(MD);
+    ASSERT_TRUE(PS);
+    ASSERT_TRUE(isa<SampleProfileSummary>(PS));
+    SPS = cast<SampleProfileSummary>(PS);
+    VerifySummary(*SPS);
+    delete SPS;
   }
 };