Skip to content

Commit 137f0bc

Browse files
committed
[𝘀𝗽𝗿] changes introduced through rebase
Created using spr 1.3.8-beta.1 [skip ci]
1 parent af29669 commit 137f0bc

File tree

4 files changed

+127
-2
lines changed

4 files changed

+127
-2
lines changed

llvm/docs/LangRef.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8400,6 +8400,14 @@ functions, and contains richer semantic information about the type of the
84008400
allocation. This information is consumed by the ``alloc-token`` pass to
84018401
instrument such calls with allocation token IDs.
84028402

8403+
The metadata contains a string with the type of an allocation.
8404+
8405+
.. code-block:: none
8406+
8407+
call ptr @malloc(i64 64), !alloc_token !0
8408+
8409+
!0 = !{!"<type-name>"}
8410+
84038411
Module Flags Metadata
84048412
=====================
84058413

llvm/lib/IR/Verifier.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,7 @@ class Verifier : public InstVisitor<Verifier>, VerifierSupport {
535535
void visitDIAssignIDMetadata(Instruction &I, MDNode *MD);
536536
void visitMMRAMetadata(Instruction &I, MDNode *MD);
537537
void visitAnnotationMetadata(MDNode *Annotation);
538+
void visitAllocTokenMetadata(Instruction &I, MDNode *MD);
538539
void visitAliasScopeMetadata(const MDNode *MD);
539540
void visitAliasScopeListMetadata(const MDNode *MD);
540541
void visitAccessGroupMetadata(const MDNode *MD);
@@ -5332,6 +5333,12 @@ void Verifier::visitAccessGroupMetadata(const MDNode *MD) {
53325333
}
53335334
}
53345335

5336+
void Verifier::visitAllocTokenMetadata(Instruction &I, MDNode *MD) {
5337+
Check(isa<CallBase>(I), "!alloc_token should only exist on calls", &I);
5338+
Check(MD->getNumOperands() == 1, "!alloc_token must have 1 operand", MD);
5339+
Check(isa<MDString>(MD->getOperand(0)), "expected string", MD);
5340+
}
5341+
53355342
/// verifyInstruction - Verify that an instruction is well formed.
53365343
///
53375344
void Verifier::visitInstruction(Instruction &I) {
@@ -5559,6 +5566,9 @@ void Verifier::visitInstruction(Instruction &I) {
55595566
if (MDNode *Annotation = I.getMetadata(LLVMContext::MD_annotation))
55605567
visitAnnotationMetadata(Annotation);
55615568

5569+
if (MDNode *MD = I.getMetadata(LLVMContext::MD_alloc_token))
5570+
visitAllocTokenMetadata(I, MD);
5571+
55625572
if (MDNode *N = I.getDebugLoc().getAsMDNode()) {
55635573
CheckDI(isa<DILocation>(N), "invalid !dbg metadata attachment", &I, N);
55645574
visitMDNode(*N, AreDebugLocsAllowed::Yes);

llvm/lib/Transforms/Utils/Local.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3026,8 +3026,11 @@ static void combineMetadata(Instruction *K, const Instruction *J,
30263026
K->setMetadata(Kind, JMD);
30273027
break;
30283028
case LLVMContext::MD_alloc_token:
3029-
// Preserve !alloc_token if both K and J have it.
3030-
K->setMetadata(Kind, JMD);
3029+
// Preserve !alloc_token if both K and J have it, and they are equal.
3030+
if (KMD == JMD)
3031+
K->setMetadata(Kind, JMD);
3032+
else
3033+
K->setMetadata(Kind, nullptr);
30313034
break;
30323035
}
30333036
}
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
2+
; RUN: opt < %s -passes=simplifycfg -S | FileCheck %s
3+
4+
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
5+
6+
declare ptr @_Znwm(i64)
7+
8+
define ptr @test_merge_alloc_token_same(i1 %b) {
9+
; CHECK-LABEL: define ptr @test_merge_alloc_token_same(
10+
; CHECK-SAME: i1 [[B:%.*]]) {
11+
; CHECK-NEXT: [[ENTRY:.*:]]
12+
; CHECK-NEXT: [[CALL:%.*]] = call ptr @_Znwm(i64 4), !alloc_token [[META0:![0-9]+]]
13+
; CHECK-NEXT: ret ptr [[CALL]]
14+
;
15+
entry:
16+
br i1 %b, label %if.then, label %if.else
17+
18+
if.then:
19+
%call = call ptr @_Znwm(i64 4), !alloc_token !0
20+
br label %if.end
21+
22+
if.else:
23+
%call1 = call ptr @_Znwm(i64 4), !alloc_token !0
24+
br label %if.end
25+
26+
if.end:
27+
%x.0 = phi ptr [ %call, %if.then ], [ %call1, %if.else ]
28+
ret ptr %x.0
29+
}
30+
31+
define ptr @test_merge_alloc_token_different(i1 %b) {
32+
; CHECK-LABEL: define ptr @test_merge_alloc_token_different(
33+
; CHECK-SAME: i1 [[B:%.*]]) {
34+
; CHECK-NEXT: [[ENTRY:.*:]]
35+
; CHECK-NEXT: [[CALL:%.*]] = call ptr @_Znwm(i64 4)
36+
; CHECK-NEXT: ret ptr [[CALL]]
37+
;
38+
entry:
39+
br i1 %b, label %if.then, label %if.else
40+
41+
if.then:
42+
%call = call ptr @_Znwm(i64 4), !alloc_token !0
43+
br label %if.end
44+
45+
if.else:
46+
%call1 = call ptr @_Znwm(i64 4), !alloc_token !1
47+
br label %if.end
48+
49+
if.end:
50+
%x.0 = phi ptr [ %call, %if.then ], [ %call1, %if.else ]
51+
ret ptr %x.0
52+
}
53+
54+
define ptr @test_merge_alloc_token_some1(i1 %b) {
55+
; CHECK-LABEL: define ptr @test_merge_alloc_token_some1(
56+
; CHECK-SAME: i1 [[B:%.*]]) {
57+
; CHECK-NEXT: [[ENTRY:.*:]]
58+
; CHECK-NEXT: [[CALL:%.*]] = call ptr @_Znwm(i64 4)
59+
; CHECK-NEXT: ret ptr [[CALL]]
60+
;
61+
entry:
62+
br i1 %b, label %if.then, label %if.else
63+
64+
if.then:
65+
%call = call ptr @_Znwm(i64 4), !alloc_token !0
66+
br label %if.end
67+
68+
if.else:
69+
%call1 = call ptr @_Znwm(i64 4)
70+
br label %if.end
71+
72+
if.end:
73+
%x.0 = phi ptr [ %call, %if.then ], [ %call1, %if.else ]
74+
ret ptr %x.0
75+
}
76+
77+
define ptr @test_merge_alloc_token_some2(i1 %b) {
78+
; CHECK-LABEL: define ptr @test_merge_alloc_token_some2(
79+
; CHECK-SAME: i1 [[B:%.*]]) {
80+
; CHECK-NEXT: [[ENTRY:.*:]]
81+
; CHECK-NEXT: [[CALL:%.*]] = call ptr @_Znwm(i64 4)
82+
; CHECK-NEXT: ret ptr [[CALL]]
83+
;
84+
entry:
85+
br i1 %b, label %if.then, label %if.else
86+
87+
if.then:
88+
%call = call ptr @_Znwm(i64 4)
89+
br label %if.end
90+
91+
if.else:
92+
%call1 = call ptr @_Znwm(i64 4), !alloc_token !0
93+
br label %if.end
94+
95+
if.end:
96+
%x.0 = phi ptr [ %call, %if.then ], [ %call1, %if.else ]
97+
ret ptr %x.0
98+
}
99+
100+
!0 = !{!"int"}
101+
!1 = !{!"char[4]"}
102+
;.
103+
; CHECK: [[META0]] = !{!"int"}
104+
;.

0 commit comments

Comments
 (0)