Author: vitalybuka Date: Wed Feb 14 14:41:15 2018 New Revision: 325182 URL: http://llvm.org/viewvc/llvm-project?rev=325182&view=rev Log: [ThinLTO/CFI] Include TYPE_ID summaries into GLOBALVAL_SUMMARY_BLOCK
Summary: TypeID summaries are used by CFI and need to be serialized by ThinLTO indexing for later use by LTO Backend. Reviewers: tejohnson, pcc Subscribers: mehdi_amini, inglorion, eraman, hiraditya, llvm-commits Differential Revision: https://reviews.llvm.org/D42611 Added: cfe/trunk/test/CodeGen/thinlto-distributed-cfi-devirt.ll cfe/trunk/test/CodeGen/thinlto-distributed-cfi.ll cfe/trunk/test/CodeGen/thinlto-distributed.ll Modified: cfe/trunk/test/CMakeLists.txt Modified: cfe/trunk/test/CMakeLists.txt URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CMakeLists.txt?rev=325182&r1=325181&r2=325182&view=diff ============================================================================== --- cfe/trunk/test/CMakeLists.txt (original) +++ cfe/trunk/test/CMakeLists.txt Wed Feb 14 14:41:15 2018 @@ -96,6 +96,7 @@ if( NOT CLANG_BUILT_STANDALONE ) llvm-bcanalyzer llvm-cat llvm-dis + llvm-lto2 llvm-modextract llvm-nm llvm-objdump Added: cfe/trunk/test/CodeGen/thinlto-distributed-cfi-devirt.ll URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/thinlto-distributed-cfi-devirt.ll?rev=325182&view=auto ============================================================================== --- cfe/trunk/test/CodeGen/thinlto-distributed-cfi-devirt.ll (added) +++ cfe/trunk/test/CodeGen/thinlto-distributed-cfi-devirt.ll Wed Feb 14 14:41:15 2018 @@ -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: <GLOBALVAL_SUMMARY_BLOCK +; CHECK: <TYPE_ID op0=0 op1=6 op2=4 op3=7 op4=0 op5=0 op6=0 op7=0 op8=0 op9=0 op10=6 op11=0 op12=0 op13=8 op14=1 op15=6 op16=9 op17=0/> +; CHECK-LABEL: </GLOBALVAL_SUMMARY_BLOCK +; CHECK-LABEL: <STRTAB_BLOCK +; CHECK: blob data = '_ZTS1A_ZN1A1nEi' +; CHECK-LABEL: </STRTAB_BLOCK + +; RUN: %clang_cc1 -triple x86_64-grtev4-linux-gnu \ +; RUN: -emit-obj -fthinlto-index=%t.o.thinlto.bc \ +; RUN: -emit-llvm -o - -x ir %t.o | FileCheck %s --check-prefixes=CHECK-IR + +; Check that backend does not fail generating native code. +; 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" + +%struct.A = type { i32 (...)** } +%struct.B = type { %struct.A } +%struct.C = type { %struct.A } + +@_ZTV1B = constant { [4 x i8*] } { [4 x i8*] [i8* null, i8* undef, i8* bitcast (i32 (%struct.B*, i32)* @_ZN1B1fEi to i8*), i8* bitcast (i32 (%struct.A*, i32)* @_ZN1A1nEi to i8*)] }, !type !0, !type !1 +@_ZTV1C = constant { [4 x i8*] } { [4 x i8*] [i8* null, i8* undef, i8* bitcast (i32 (%struct.C*, i32)* @_ZN1C1fEi to i8*), i8* bitcast (i32 (%struct.A*, i32)* @_ZN1A1nEi to i8*)] }, !type !0, !type !2 + +; CHECK-IR-LABEL: define i32 @test +define i32 @test(%struct.A* %obj, i32 %a) { +entry: + %0 = bitcast %struct.A* %obj to i8** + %vtable5 = load i8*, i8** %0 + + ; 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") + %2 = extractvalue { i8*, i1 } %1, 1 + br i1 %2, label %cont, label %trap + +trap: + tail call void @llvm.trap() + unreachable + +cont: + %3 = extractvalue { i8*, i1 } %1, 0 + %4 = bitcast i8* %3 to i32 (%struct.A*, i32)* + %call = tail call i32 %4(%struct.A* nonnull %obj, i32 %a) + %vtable16 = load i8*, i8** %0 + %5 = tail call { i8*, i1 } @llvm.type.checked.load(i8* %vtable16, i32 0, metadata !"_ZTS1A") + %6 = extractvalue { i8*, i1 } %5, 1 + br i1 %6, label %cont2, label %trap + +cont2: + %7 = extractvalue { i8*, i1 } %5, 0 + %8 = bitcast i8* %7 to i32 (%struct.A*, i32)* + + ; Check that traps are conditional. Invalid TYPE_ID can cause + ; unconditional traps. + ; CHECK-IR: br i1 {{.*}}, label %trap + + ; We still have to call it as virtual. + ; CHECK-IR: %call3 = tail call i32 %8 + %call3 = tail call i32 %8(%struct.A* nonnull %obj, i32 %call) + ret i32 %call3 +} +; CHECK-IR-LABEL: ret i32 +; CHECK-IR-LABEL: } + +declare { i8*, i1 } @llvm.type.checked.load(i8*, i32, metadata) +declare void @llvm.trap() + +declare i32 @_ZN1B1fEi(%struct.B* %this, i32 %a) +declare i32 @_ZN1A1nEi(%struct.A* %this, i32 %a) +declare i32 @_ZN1C1fEi(%struct.C* %this, i32 %a) + +!0 = !{i64 16, !"_ZTS1A"} +!1 = !{i64 16, !"_ZTS1B"} +!2 = !{i64 16, !"_ZTS1C"} Added: cfe/trunk/test/CodeGen/thinlto-distributed-cfi.ll URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/thinlto-distributed-cfi.ll?rev=325182&view=auto ============================================================================== --- cfe/trunk/test/CodeGen/thinlto-distributed-cfi.ll (added) +++ cfe/trunk/test/CodeGen/thinlto-distributed-cfi.ll Wed Feb 14 14:41:15 2018 @@ -0,0 +1,67 @@ +; REQUIRES: x86-registered-target + +; Backend test for distribute ThinLTO with CFI. + +; 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,_ZTV1B, \ +; RUN: -r=%t.o,_ZN1B1fEi, \ +; RUN: -r=%t.o,_ZTV1B,px + +; Check that typeids are in the index. +; RUN: llvm-bcanalyzer -dump %t.o.thinlto.bc | FileCheck %s +; CHECK-LABEL: <GLOBALVAL_SUMMARY_BLOCK +; CHECK: <TYPE_ID op0=0 op1=6 op2=3 op3=0 op4=0 op5=0 op6=0 op7=0/> +; CHECK-LABEL: </GLOBALVAL_SUMMARY_BLOCK +; CHECK-LABEL: <STRTAB_BLOCK +; CHECK: blob data = '_ZTS1A' +; CHECK-LABEL: </STRTAB_BLOCK + +; RUN: %clang_cc1 -triple x86_64-grtev4-linux-gnu \ +; RUN: -emit-obj -fthinlto-index=%t.o.thinlto.bc \ +; RUN: -emit-llvm -o - -x ir %t.o | FileCheck %s --check-prefixes=CHECK-IR + +; Ensure that backend does not fail generating native code. +; 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" + +%struct.B = type { %struct.A } +%struct.A = type { i32 (...)** } + +@_ZTV1B = constant { [3 x i8*] } { [3 x i8*] [i8* undef, i8* undef, i8* undef] }, !type !0 + +; CHECK-IR-LABEL: define void @test +define void @test(i8* %b) { +entry: + ; Ensure that traps are conditional. Invalid TYPE_ID can cause + ; unconditional traps. + ; CHECK-IR: br i1 {{.*}}, label %trap + %0 = bitcast i8* %b to i8** + %vtable2 = load i8*, i8** %0 + %1 = tail call i1 @llvm.type.test(i8* %vtable2, metadata !"_ZTS1A") + br i1 %1, label %cont, label %trap + +trap: + tail call void @llvm.trap() + unreachable + +cont: + ; CHECK-IR-LABEL: ret void + ret void +} +; CHECK-IR-LABEL: } + +declare i1 @llvm.type.test(i8*, metadata) +declare void @llvm.trap() + +declare i32 @_ZN1B1fEi(%struct.B* %this, i32 %a) + +!0 = !{i64 16, !"_ZTS1A"} +!1 = !{i64 16, !"_ZTS1B"} Added: cfe/trunk/test/CodeGen/thinlto-distributed.ll URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/thinlto-distributed.ll?rev=325182&view=auto ============================================================================== --- cfe/trunk/test/CodeGen/thinlto-distributed.ll (added) +++ cfe/trunk/test/CodeGen/thinlto-distributed.ll Wed Feb 14 14:41:15 2018 @@ -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 +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits