Skip to content

Commit 89c896b

Browse files
committed
Rebase on parent llvm change.
Created using spr 1.3.6-beta.1
2 parents d0a96ac + 7a1c8fb commit 89c896b

File tree

5 files changed

+48
-16
lines changed

5 files changed

+48
-16
lines changed

llvm/include/llvm/IR/Metadata.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,6 +1259,12 @@ class MDNode : public Metadata {
12591259
bool isReplaceable() const { return isTemporary() || isAlwaysReplaceable(); }
12601260
bool isAlwaysReplaceable() const { return getMetadataID() == DIAssignIDKind; }
12611261

1262+
bool hasGeneralizedMDString() const {
1263+
if (getNumOperands() < 2 || !isa<MDString>(getOperand(1)))
1264+
return false;
1265+
return cast<MDString>(getOperand(1))->getString().ends_with(".generalized");
1266+
}
1267+
12621268
unsigned getNumTemporaryUses() const {
12631269
assert(isTemporary() && "Only for temporaries");
12641270
return Context.getReplaceableUses()->getNumUses();

llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1647,23 +1647,16 @@ void AsmPrinter::emitStackUsage(const MachineFunction &MF) {
16471647
static ConstantInt *extractNumericCGTypeId(const Function &F) {
16481648
SmallVector<MDNode *, 2> Types;
16491649
F.getMetadata(LLVMContext::MD_type, Types);
1650-
MDString *MDGeneralizedTypeId = nullptr;
16511650
for (const auto &Type : Types) {
1652-
if (Type->getNumOperands() == 2 && isa<MDString>(Type->getOperand(1))) {
1653-
auto *TMDS = cast<MDString>(Type->getOperand(1));
1654-
if (TMDS->getString().ends_with(".generalized")) {
1655-
MDGeneralizedTypeId = TMDS;
1656-
break;
1657-
}
1651+
if (Type->hasGeneralizedMDString()) {
1652+
MDString *MDGeneralizedTypeId = cast<MDString>(Type->getOperand(1));
1653+
uint64_t TypeIdVal = llvm::MD5Hash(MDGeneralizedTypeId->getString());
1654+
IntegerType *Int64Ty = Type::getInt64Ty(F.getContext());
1655+
return ConstantInt::get(Int64Ty, TypeIdVal);
16581656
}
16591657
}
16601658

1661-
if (!MDGeneralizedTypeId)
1662-
return nullptr;
1663-
1664-
uint64_t TypeIdVal = llvm::MD5Hash(MDGeneralizedTypeId->getString());
1665-
IntegerType *Int64Ty = Type::getInt64Ty(F.getContext());
1666-
return ConstantInt::get(Int64Ty, TypeIdVal);
1659+
return nullptr;
16671660
}
16681661

16691662
/// Emits .callgraph section.

llvm/lib/IR/Verifier.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5060,8 +5060,7 @@ void Verifier::visitCalleeTypeMetadata(Instruction &I, MDNode *MD) {
50605060
&I);
50615061
for (const auto &Op : MD->operands()) {
50625062
auto *TypeMD = cast<MDNode>(Op.get());
5063-
MDString *TypeIdStr = cast<MDString>(TypeMD->getOperand(1));
5064-
Check(TypeIdStr->getString().ends_with(".generalized"),
5063+
Check(TypeMD->hasGeneralizedMDString(),
50655064
"Invalid \"callee_type\" type identifier", &I);
50665065
}
50675066
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
;; Tests that we store the type identifiers in .callgraph section of the object file for tailcalls.
2+
3+
; RUN: llc --call-graph-section -filetype=obj -o - < %s | \
4+
; RUN: llvm-readelf -x .callgraph - | FileCheck %s
5+
6+
define dso_local noundef i32 @_Z13call_indirectPFicEc(ptr noundef readonly captures(none) %func, i8 noundef signext %x) local_unnamed_addr !type !0 {
7+
entry:
8+
%call = tail call noundef i32 %func(i8 noundef signext %x), !callee_type !1
9+
ret i32 %call
10+
}
11+
12+
define dso_local noundef i32 @main(i32 noundef %argc) local_unnamed_addr !type !3 {
13+
entry:
14+
%0 = and i32 %argc, 1
15+
%cmp = icmp eq i32 %0, 0
16+
%_Z3fooc._Z3barc = select i1 %cmp, ptr @_Z3fooc, ptr @_Z3barc
17+
%call.i = tail call noundef i32 %_Z3fooc._Z3barc(i8 noundef signext 97), !callee_type !1
18+
ret i32 %call.i
19+
}
20+
21+
declare !type !2 noundef i32 @_Z3fooc(i8 noundef signext) local_unnamed_addr
22+
23+
declare !type !2 noundef i32 @_Z3barc(i8 noundef signext) local_unnamed_addr
24+
25+
;; Check that the numeric type id (md5 hash) for the below type ids are emitted
26+
;; to the callgraph section.
27+
28+
; CHECK: Hex dump of section '.callgraph':
29+
30+
!0 = !{i64 0, !"_ZTSFiPvcE.generalized"}
31+
!1 = !{!2}
32+
; CHECK-DAG: 5486bc59 814b8e30
33+
!2 = !{i64 0, !"_ZTSFicE.generalized"}
34+
!3 = !{i64 0, !"_ZTSFiiE.generalized"}

llvm/test/CodeGen/X86/call-graph-section.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
;; Tests that we store the type identifiers in .callgraph section of the binary.
1+
;; Tests that we store the type identifiers in .callgraph section of the object file.
22

33
; RUN: llc --call-graph-section -filetype=obj -o - < %s | \
44
; RUN: llvm-readelf -x .callgraph - | FileCheck %s

0 commit comments

Comments
 (0)