[PATCH] D42611: [ThinLTO/CFI] Include TYPE_ID summaries into GLOBALVAL_SUMMARY_BLOCK

2018-02-14 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka marked an inline comment as done.
vitalybuka added inline comments.



Comment at: clang/test/CodeGen/thinlto-distributed-cfi-devirt.ll:59
+  ; Check that the call was devirtualized.
+  ; CHECK-IR: %call = tail call i32 @_ZN1A1nEi
+  %1 = tail call { i8*, i1 } @llvm.type.checked.load(i8* %vtable5, i32 8, 
metadata !"_ZTS1A")

pcc wrote:
> Move this to before line 71.
done in r325184


Repository:
  rC Clang

https://reviews.llvm.org/D42611



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D42611: [ThinLTO/CFI] Include TYPE_ID summaries into GLOBALVAL_SUMMARY_BLOCK

2018-02-14 Thread Vitaly Buka via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL325182: [ThinLTO/CFI] Include TYPE_ID summaries into 
GLOBALVAL_SUMMARY_BLOCK (authored by vitalybuka, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D42611?vs=134317&id=134321#toc

Repository:
  rC Clang

https://reviews.llvm.org/D42611

Files:
  cfe/trunk/test/CMakeLists.txt
  cfe/trunk/test/CodeGen/thinlto-distributed-cfi-devirt.ll
  cfe/trunk/test/CodeGen/thinlto-distributed-cfi.ll
  cfe/trunk/test/CodeGen/thinlto-distributed.ll
  llvm/trunk/include/llvm/Bitcode/LLVMBitCodes.h
  llvm/trunk/include/llvm/IR/ModuleSummaryIndex.h
  llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
  llvm/trunk/lib/Bitcode/Writer/BitcodeWriter.cpp
  llvm/trunk/test/ThinLTO/X86/cfi-icall.ll
  llvm/trunk/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp

Index: llvm/trunk/include/llvm/IR/ModuleSummaryIndex.h
===
--- llvm/trunk/include/llvm/IR/ModuleSummaryIndex.h
+++ llvm/trunk/include/llvm/IR/ModuleSummaryIndex.h
@@ -671,7 +671,6 @@
 
   /// Mapping from type identifiers to summary information for that type
   /// identifier.
-  // FIXME: Add bitcode read/write support for this field.
   std::map TypeIdMap;
 
   /// Mapping from original ID to GUID. If original ID can map to multiple
Index: llvm/trunk/include/llvm/Bitcode/LLVMBitCodes.h
===
--- llvm/trunk/include/llvm/Bitcode/LLVMBitCodes.h
+++ llvm/trunk/include/llvm/Bitcode/LLVMBitCodes.h
@@ -263,6 +263,11 @@
   FS_PERMODULE_RELBF = 19,
   // Index-wide flags
   FS_FLAGS = 20,
+  // Maps type identifier to summary information for that type identifier.
+  // TYPE_ID: [typeid, kind, bitwidth, align, size, bitmask, inlinebits,
+  //   n x (typeid, kind, name, numrba,
+  //numrba x (numarg, numarg x arg, kind, info, byte, bit))]
+  FS_TYPE_ID = 21,
 };
 
 enum MetadataCodes {
Index: llvm/trunk/test/ThinLTO/X86/cfi-icall.ll
===
--- llvm/trunk/test/ThinLTO/X86/cfi-icall.ll
+++ llvm/trunk/test/ThinLTO/X86/cfi-icall.ll
@@ -22,8 +22,9 @@
 ; COMBINED:   
 ; COMBINED: 
+; COMBINED: 
 ; COMBINED:   
 
 ; COMBINED:   blob data = 'foobar'
+; COMBINED-NEXT:blob data = 'foobartypeid1'
 ; COMBINED-NEXT: 
Index: llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
===
--- llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
+++ llvm/trunk/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -5071,6 +5071,56 @@
   return Ret;
 }
 
+static void
+parseWholeProgramDevirtResolutionByArg(ArrayRef Record, size_t &Slot,
+   WholeProgramDevirtResolution &Wpd) {
+  uint64_t ArgNum = Record[Slot++];
+  WholeProgramDevirtResolution::ByArg &B =
+  Wpd.ResByArg[{Record.begin() + Slot, Record.begin() + Slot + ArgNum}];
+  Slot += ArgNum;
+
+  B.TheKind =
+  static_cast(Record[Slot++]);
+  B.Info = Record[Slot++];
+  B.Byte = Record[Slot++];
+  B.Bit = Record[Slot++];
+}
+
+static void parseWholeProgramDevirtResolution(ArrayRef Record,
+  StringRef Strtab, size_t &Slot,
+  TypeIdSummary &TypeId) {
+  uint64_t Id = Record[Slot++];
+  WholeProgramDevirtResolution &Wpd = TypeId.WPDRes[Id];
+
+  Wpd.TheKind = static_cast(Record[Slot++]);
+  Wpd.SingleImplName = {Strtab.data() + Record[Slot],
+static_cast(Record[Slot + 1])};
+  Slot += 2;
+
+  uint64_t ResByArgNum = Record[Slot++];
+  for (uint64_t I = 0; I != ResByArgNum; ++I)
+parseWholeProgramDevirtResolutionByArg(Record, Slot, Wpd);
+}
+
+static void parseTypeIdSummaryRecord(ArrayRef Record,
+ StringRef Strtab,
+ ModuleSummaryIndex &TheIndex) {
+  size_t Slot = 0;
+  TypeIdSummary &TypeId = TheIndex.getOrInsertTypeIdSummary(
+  {Strtab.data() + Record[Slot], static_cast(Record[Slot + 1])});
+  Slot += 2;
+
+  TypeId.TTRes.TheKind = static_cast(Record[Slot++]);
+  TypeId.TTRes.SizeM1BitWidth = Record[Slot++];
+  TypeId.TTRes.AlignLog2 = Record[Slot++];
+  TypeId.TTRes.SizeM1 = Record[Slot++];
+  TypeId.TTRes.BitMask = Record[Slot++];
+  TypeId.TTRes.InlineBits = Record[Slot++];
+
+  while (Slot < Record.size())
+parseWholeProgramDevirtResolution(Record, Strtab, Slot, TypeId);
+}
+
 // Eagerly parse the entire summary block. This populates the GlobalValueSummary
 // objects in the index.
 Error ModuleSummaryIndexBitcodeReader::parseEntireSummary(unsigned ID) {
@@ -5388,13 +5438,18 @@
 {Strtab.data() + Record[I], static_cast(Record[I + 1])});
   break;
 }
+
 case bitc::FS_CFI_FUNCTION_DECLS: {
   std::set &CfiFunctionDecls = TheIndex.cfiFunctionDecls();
   for (unsigned I = 0; I != Record.size(); I += 2)
 CfiFuncti

[PATCH] D42611: [ThinLTO/CFI] Include TYPE_ID summaries into GLOBALVAL_SUMMARY_BLOCK

2018-02-14 Thread Vitaly Buka via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC325182: [ThinLTO/CFI] Include TYPE_ID summaries into 
GLOBALVAL_SUMMARY_BLOCK (authored by vitalybuka, committed by ).
Herald added a subscriber: cfe-commits.

Changed prior to commit:
  https://reviews.llvm.org/D42611?vs=134317&id=134320#toc

Repository:
  rC Clang

https://reviews.llvm.org/D42611

Files:
  test/CMakeLists.txt
  test/CodeGen/thinlto-distributed-cfi-devirt.ll
  test/CodeGen/thinlto-distributed-cfi.ll
  test/CodeGen/thinlto-distributed.ll

Index: test/CodeGen/thinlto-distributed.ll
===
--- test/CodeGen/thinlto-distributed.ll
+++ test/CodeGen/thinlto-distributed.ll
@@ -0,0 +1,21 @@
+; REQUIRES: x86-registered-target
+
+; Trivial test for distributes ThinLTO
+
+; RUN: opt -thinlto-bc -o %t.o %s
+
+; RUN: llvm-lto2 run -thinlto-distributed-indexes %t.o \
+; RUN:   -o %t2.index \
+; RUN:   -r=%t.o,main,px
+
+; RUN: %clang_cc1 -triple x86_64-grtev4-linux-gnu \
+; RUN:   -emit-obj -fthinlto-index=%t.o.thinlto.bc \
+; RUN:   -o %t.native.o -x ir %t.o
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-grtev4-linux-gnu"
+
+define i32 @main() {
+entry:
+  ret i32 0
+}
Index: test/CodeGen/thinlto-distributed-cfi-devirt.ll
===
--- test/CodeGen/thinlto-distributed-cfi-devirt.ll
+++ test/CodeGen/thinlto-distributed-cfi-devirt.ll
@@ -0,0 +1,101 @@
+; REQUIRES: x86-registered-target
+
+; Backend test for distribute ThinLTO with CFI.
+; It additionally enables -fwhole-program-vtables to get more information in
+; TYPE_IDs of GLOBALVAL_SUMMARY_BLOCK.
+
+; RUN: opt -thinlto-bc -o %t.o %s
+
+; RUN: llvm-lto2 run -thinlto-distributed-indexes %t.o \
+; RUN:   -o %t2.index \
+; RUN:   -r=%t.o,test,px \
+; RUN:   -r=%t.o,_ZN1A1nEi,p \
+; RUN:   -r=%t.o,_ZN1B1fEi,p \
+; RUN:   -r=%t.o,_ZN1C1fEi,p \
+; RUN:   -r=%t.o,_ZTV1B, \
+; RUN:   -r=%t.o,_ZTV1C, \
+; RUN:   -r=%t.o,_ZN1A1nEi, \
+; RUN:   -r=%t.o,_ZN1B1fEi, \
+; RUN:   -r=%t.o,_ZN1C1fEi, \
+; RUN:   -r=%t.o,_ZTV1B,px \
+; RUN:   -r=%t.o,_ZTV1C,px
+
+; Ensure that typeids are in the index.
+; RUN: llvm-bcanalyzer -dump %t.o.thinlto.bc | FileCheck %s
+; CHECK-LABEL: 
+; CHECK-LABEL: 
+; CHECK-LABEL: ___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits