[PATCH] D63887: [PoC][ThinLTO] only emit used or referenced CFI records to index

Bob Haarman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 27 10:52:49 PDT 2019


inglorion created this revision.
Herald added subscribers: llvm-commits, arphaman, dexonsmith, hiraditya, mehdi_amini.
Herald added a project: LLVM.

Note: This is a proof of concept and not intended for commit in its
current state. It can build at least parts of Chromium, but breaks
LLVM tests.

We emit CFI_FUNCTION_DEFS and CFI_FUNCTION_DECLS to distributed
ThinLTO indices. This change causes us to only emit entries for
functions that are either defined or used by the module we're writing
the index for, which can make the indices substantially smaller.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D63887

Files:
  llvm/lib/Bitcode/Writer/BitcodeWriter.cpp


Index: llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
===================================================================
--- llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
+++ llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
@@ -3825,7 +3825,8 @@
     Flags |= 0x10;
   Stream.EmitRecord(bitc::FS_FLAGS, ArrayRef<uint64_t>{Flags});
 
-  for (const auto &GVI : valueIds()) {
+  const std::map<GlobalValue::GUID, unsigned> &ValueIds = valueIds();
+  for (const auto &GVI : ValueIds) {
     Stream.EmitRecord(bitc::FS_VALUE_GUID,
                       ArrayRef<uint64_t>{GVI.second, GVI.first});
   }
@@ -4047,20 +4048,28 @@
 
   if (!Index.cfiFunctionDefs().empty()) {
     for (auto &S : Index.cfiFunctionDefs()) {
-      NameVals.push_back(StrtabBuilder.add(S));
-      NameVals.push_back(S.size());
+      if (ValueIds.count(GlobalValue::getGUID(GlobalValue::dropLLVMManglingEscape(S)))) {
+        NameVals.push_back(StrtabBuilder.add(S));
+        NameVals.push_back(S.size());
+      }
+    }
+    if (!NameVals.empty()) {
+      Stream.EmitRecord(bitc::FS_CFI_FUNCTION_DEFS, NameVals);
+      NameVals.clear();
     }
-    Stream.EmitRecord(bitc::FS_CFI_FUNCTION_DEFS, NameVals);
-    NameVals.clear();
   }
 
   if (!Index.cfiFunctionDecls().empty()) {
     for (auto &S : Index.cfiFunctionDecls()) {
-      NameVals.push_back(StrtabBuilder.add(S));
-      NameVals.push_back(S.size());
+      if (ValueIds.count(GlobalValue::getGUID(GlobalValue::dropLLVMManglingEscape(S)))) {
+        NameVals.push_back(StrtabBuilder.add(S));
+        NameVals.push_back(S.size());
+      }
+    }
+    if (!NameVals.empty()) {
+      Stream.EmitRecord(bitc::FS_CFI_FUNCTION_DECLS, NameVals);
+      NameVals.clear();
     }
-    Stream.EmitRecord(bitc::FS_CFI_FUNCTION_DECLS, NameVals);
-    NameVals.clear();
   }
 
   // Walk the GUIDs that were referenced, and write the


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D63887.206888.patch
Type: text/x-patch
Size: 1852 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190627/14e2bd18/attachment.bin>


More information about the llvm-commits mailing list