Skip to content

Commit 2131b83

Browse files
necipfazilPrabhuk
authored andcommitted
[𝘀𝗽𝗿] changes introduced through rebase
Created using spr 1.3.6-beta.1 [skip ci]
1 parent 05057b8 commit 2131b83

File tree

7 files changed

+88
-6
lines changed

7 files changed

+88
-6
lines changed

llvm/include/llvm/CodeGen/AsmPrinter.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,10 @@ class AsmPrinter : public MachineFunctionPass {
200200
SmallVector<std::pair<CGTypeId, MCSymbol *>> CallSiteLabels;
201201
};
202202

203+
enum CallGraphSectionFormatVersion : uint64_t {
204+
V_0 = 0,
205+
};
206+
203207
/// Output stream for the stack usage file (i.e., .su file).
204208
std::unique_ptr<raw_fd_ostream> StackUsageStream;
205209

llvm/include/llvm/MC/MCObjectFileInfo.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class MCObjectFileInfo {
6868
/// Language Specific Data Area information is emitted to.
6969
MCSection *LSDASection = nullptr;
7070

71-
/// Section containing metadata on call graph.
71+
/// Section containing call graph metadata.
7272
MCSection *CallGraphSection = nullptr;
7373

7474
/// If exception handling is supported by the target and the target can

llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1673,7 +1673,7 @@ void AsmPrinter::emitCallGraphSection(const MachineFunction &MF,
16731673
OutStreamer->switchSection(FuncCGSection);
16741674

16751675
// Emit format version number.
1676-
OutStreamer->emitInt64(0);
1676+
OutStreamer->emitInt64(CallGraphSectionFormatVersion::V_0);
16771677

16781678
// Emit function's self information, which is composed of:
16791679
// 1) FunctionEntryPc

llvm/lib/Transforms/Utils/ValueMapper.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -985,6 +985,13 @@ void Mapper::remapInstruction(Instruction *I) {
985985
"Referenced value not in value map!");
986986
}
987987

988+
// Drop callee_type metadata from calls that were remapped
989+
// into a direct call from an indirect one.
990+
if (auto *CB = dyn_cast<CallBase>(I)) {
991+
if (CB->getMetadata(LLVMContext::MD_callee_type) && !CB->isIndirectCall())
992+
CB->setMetadata(LLVMContext::MD_callee_type, nullptr);
993+
}
994+
988995
// Remap phi nodes' incoming blocks.
989996
if (PHINode *PN = dyn_cast<PHINode>(I)) {
990997
for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i) {
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Test that the assembler produced callgraph section is correct.
2+
3+
// RUN: llvm-mc -triple=x86_64 -filetype=obj -o - < %s | llvm-readelf -x .callgraph - | FileCheck %s
4+
5+
.text
6+
.globl ball # -- Begin function ball
7+
.p2align 4
8+
.type ball,@function
9+
ball: # @ball
10+
.Lfunc_begin0:
11+
# %bb.0: # %entry
12+
pushq %rbx
13+
subq $32, %rsp
14+
movl $0, 4(%rsp)
15+
movq foo@GOTPCREL(%rip), %rcx
16+
movq %rcx, 24(%rsp)
17+
xorl %eax, %eax
18+
callq *%rcx
19+
.Ltmp0:
20+
movq bar@GOTPCREL(%rip), %rax
21+
movq %rax, 16(%rsp)
22+
movsbl 3(%rsp), %edi
23+
callq *%rax
24+
.Ltmp1:
25+
movq baz@GOTPCREL(%rip), %rax
26+
movq %rax, 8(%rsp)
27+
leaq 3(%rsp), %rbx
28+
movq %rbx, %rdi
29+
callq *%rax
30+
.Ltmp2:
31+
callq foo@PLT
32+
movsbl 3(%rsp), %edi
33+
callq bar@PLT
34+
movq %rbx, %rdi
35+
callq baz@PLT
36+
addq $32, %rsp
37+
popq %rbx
38+
retq
39+
.section .callgraph,"o",@progbits,.text
40+
.quad 0
41+
.quad .Lfunc_begin0
42+
.quad 1
43+
.quad 3
44+
// CHECK: 2444f731 f5eecb3e
45+
.quad 0x3ecbeef531f74424
46+
.quad .Ltmp0
47+
// CHECK: 5486bc59 814b8e30
48+
.quad 0x308e4b8159bc8654
49+
.quad .Ltmp1
50+
// CHECK: 7ade6814 f897fd77
51+
.quad 0x77fd97f81468de7a
52+
.quad .Ltmp2
53+
.text

llvm/test/Transforms/InstCombine/callee-type-metadata.ll renamed to llvm/test/Transforms/Inline/drop-callee-type-metadata.ll

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
;; Test if the callee_type metadata is dropped when an indirect function call through a function ptr is promoted
2-
;; to a direct function call during instcombine.
1+
;; Test if the callee_type metadata is dropped when it is
2+
;; is mapped to a direct function call from an indirect call during inlining.
33

4-
; RUN: opt < %s -passes="cgscc(inline),instcombine" -S | FileCheck %s
4+
; RUN: opt < %s -passes="inline" -S | FileCheck %s
55

66
define i32 @_Z13call_indirectPFicEc(ptr %func, i8 %x) local_unnamed_addr !type !0 {
77
entry:
@@ -16,7 +16,6 @@ entry:
1616
%call = call i32 @_Z13call_indirectPFicEc(ptr nonnull @_Z3fooc, i8 97)
1717
ret i32 %call
1818
}
19-
2019
declare !type !2 i32 @_Z3fooc(i8 signext)
2120

2221
!0 = !{i64 0, !"_ZTSFiPvcE.generalized"}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
;; Test if the callee_type metadata is dropped when it is attached
2+
;; to a direct function call during instcombine.
3+
4+
; RUN: opt < %s -passes="instcombine" -disable-verify -S | FileCheck %s
5+
6+
define i32 @_Z3barv() local_unnamed_addr !type !3 {
7+
entry:
8+
; CHECK: %call = call i32 @_Z3fooc(i8 97)
9+
; CHECK-NOT: %call = call i32 @_Z3fooc(i8 97), !callee_type !1
10+
%call = call i32 @_Z3fooc(i8 97), !callee_type !1
11+
ret i32 %call
12+
}
13+
14+
declare !type !2 i32 @_Z3fooc(i8 signext)
15+
16+
!0 = !{i64 0, !"_ZTSFiPvcE.generalized"}
17+
!1 = !{!2}
18+
!2 = !{i64 0, !"_ZTSFicE.generalized"}
19+
!3 = !{i64 0, !"_ZTSFivE.generalized"}

0 commit comments

Comments
 (0)