[llvm] r267329 - Add "hasSection" flag in the Summary

Mehdi Amini via llvm-commits llvm-commits at lists.llvm.org
Sat Apr 23 22:31:43 PDT 2016


Author: mehdi_amini
Date: Sun Apr 24 00:31:43 2016
New Revision: 267329

URL: http://llvm.org/viewvc/llvm-project?rev=267329&view=rev
Log:
Add "hasSection" flag in the Summary

Reviewers: tejohnson

Subscribers: llvm-commits

Differential Revision: http://reviews.llvm.org/D19405

From: Mehdi Amini <mehdi.amini at apple.com>

Added:
    llvm/trunk/test/Bitcode/thinlto-summary-section.ll
Modified:
    llvm/trunk/include/llvm/IR/ModuleSummaryIndex.h
    llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
    llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp

Modified: llvm/trunk/include/llvm/IR/ModuleSummaryIndex.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/ModuleSummaryIndex.h?rev=267329&r1=267328&r2=267329&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/ModuleSummaryIndex.h (original)
+++ llvm/trunk/include/llvm/IR/ModuleSummaryIndex.h Sun Apr 24 00:31:43 2016
@@ -103,9 +103,14 @@ public:
     /// types based on global summary-based analysis.
     GlobalValue::LinkageTypes Linkage : 4;
 
+    /// Indicate if the global value is located in a specific section.
+    unsigned HasSection : 1;
+
     /// Convenience Constructors
-    explicit GVFlags(GlobalValue::LinkageTypes Linkage) : Linkage(Linkage) {}
-    GVFlags(const GlobalValue &GV) : Linkage(GV.getLinkage()) {}
+    explicit GVFlags(GlobalValue::LinkageTypes Linkage, bool HasSection)
+        : Linkage(Linkage), HasSection(HasSection) {}
+    GVFlags(const GlobalValue &GV)
+        : Linkage(GV.getLinkage()), HasSection(GV.hasSection()) {}
   };
 
 private:
@@ -164,6 +169,9 @@ public:
   /// Return linkage type recorded for this global value.
   GlobalValue::LinkageTypes linkage() const { return Flags.Linkage; }
 
+  /// Return true if this global value is located in a specific section.
+  bool hasSection() const { return Flags.HasSection; }
+
   /// Record a reference from this global value to the global value identified
   /// by \p RefGUID.
   void addRefEdge(GlobalValue::GUID RefGUID) { RefEdgeList.push_back(RefGUID); }

Modified: llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp?rev=267329&r1=267328&r2=267329&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp (original)
+++ llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp Sun Apr 24 00:31:43 2016
@@ -745,7 +745,9 @@ static GlobalValueSummary::GVFlags getDe
   // like getDecodedLinkage() above. Any future change to the linkage enum and
   // to getDecodedLinkage() will need to be taken into account here as above.
   auto Linkage = GlobalValue::LinkageTypes(RawFlags & 0xF); // 4 bits
-  return GlobalValueSummary::GVFlags(Linkage);
+  RawFlags = RawFlags >> 4;
+  auto HasSection = RawFlags & 0x1; // bool
+  return GlobalValueSummary::GVFlags(Linkage, HasSection);
 }
 
 static GlobalValue::VisibilityTypes getDecodedVisibility(unsigned Val) {

Modified: llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp?rev=267329&r1=267328&r2=267329&view=diff
==============================================================================
--- llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp (original)
+++ llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp Sun Apr 24 00:31:43 2016
@@ -789,8 +789,14 @@ static unsigned getEncodedLinkage(const
 // Decode the flags for GlobalValue in the summary
 static uint64_t getEncodedGVSummaryFlags(GlobalValueSummary::GVFlags Flags) {
   uint64_t RawFlags = 0;
-  // Emit Linkage enum.
-  RawFlags |= Flags.Linkage; // 4 bits
+
+  RawFlags |= Flags.HasSection; // bool
+
+  // Linkage don't need to be remapped at that time for the summary. Any future
+  // change to the getEncodedLinkage() function will need to be taken into
+  // account here as well.
+  RawFlags = (RawFlags << 4) | Flags.Linkage; // 4 bits
+
   return RawFlags;
 }
 

Added: llvm/trunk/test/Bitcode/thinlto-summary-section.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Bitcode/thinlto-summary-section.ll?rev=267329&view=auto
==============================================================================
--- llvm/trunk/test/Bitcode/thinlto-summary-section.ll (added)
+++ llvm/trunk/test/Bitcode/thinlto-summary-section.ll Sun Apr 24 00:31:43 2016
@@ -0,0 +1,11 @@
+; Check the linkage types in both the per-module and combined summaries.
+; RUN: opt -module-summary %s -o %t.o
+; RUN: llvm-bcanalyzer -dump %t.o | FileCheck %s
+; RUN: llvm-lto -thinlto -o %t2 %t.o
+; RUN: llvm-bcanalyzer -dump %t2.thinlto.bc | FileCheck %s --check-prefix=COMBINED
+
+; CHECK: <PERMODULE {{.*}} op1=16
+; COMBINED-DAG: <COMBINED {{.*}} op1=16
+define void @functionWithSection() section "some_section" {
+    ret void
+}




More information about the llvm-commits mailing list