llvm.org GIT mirror llvm / 6adafb6
[Transforms] Support making mutable versions of new-format TBAA access tags Differential Revision: https://reviews.llvm.org/D41565 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@322650 91177308-0d34-0410-b5e6-96231b3b80d8 Ivan A. Kosarev 1 year, 8 months ago
4 changed file(s) with 57 addition(s) and 23 deletion(s). Raw diff Collapse all Expand all
189189 uint64_t Offset, uint64_t Size,
190190 bool IsImmutable = false);
191191
192 /// \brief Return mutable version of the given mutable or immutable TBAA
193 /// access tag.
194 MDNode *createMutableTBAAAccessTag(MDNode *Tag);
195
192196 /// \brief Return metadata containing an irreducible loop header weight.
193197 MDNode *createIrrLoopHeaderWeight(uint64_t Weight);
194198 };
231231 return MDNode::get(Context, {BaseType, AccessType, OffsetNode, SizeNode});
232232 }
233233
234 MDNode *MDBuilder::createMutableTBAAAccessTag(MDNode *Tag) {
235 MDNode *BaseType = cast(Tag->getOperand(1));
236 MDNode *AccessType = cast(Tag->getOperand(1));
237 Metadata *OffsetNode = Tag->getOperand(2);
238 uint64_t Offset = mdconst::extract(OffsetNode)->getZExtValue();
239
240 bool NewFormat = isa(AccessType->getOperand(0));
241
242 // See if the tag is already mutable.
243 unsigned ImmutabilityFlagOp = NewFormat ? 4 : 3;
244 if (Tag->getNumOperands() <= ImmutabilityFlagOp)
245 return Tag;
246
247 // If Tag is already mutable then return it.
248 Metadata *ImmutabilityFlagNode = Tag->getOperand(ImmutabilityFlagOp);
249 if (!mdconst::extract(ImmutabilityFlagNode)->getValue())
250 return Tag;
251
252 // Otherwise, create another node.
253 if (!NewFormat)
254 return createTBAAStructTagNode(BaseType, AccessType, Offset);
255
256 Metadata *SizeNode = Tag->getOperand(3);
257 uint64_t Size = mdconst::extract(SizeNode)->getZExtValue();
258 return createTBAAAccessTag(BaseType, AccessType, Offset, Size);
259 }
260
234261 MDNode *MDBuilder::createIrrLoopHeaderWeight(uint64_t Weight) {
235262 SmallVector Vals(2);
236263 Vals[0] = createString("loop_header_weight");
24602460 continue;
24612461 }
24622462
2463 if (const MDNode *MD = I.getMetadata(LLVMContext::MD_tbaa)) {
2464 assert(MD->getNumOperands() < 5 && "unrecognized metadata shape!");
2465 bool IsImmutableTBAA =
2466 MD->getNumOperands() == 4 &&
2467 mdconst::extract(MD->getOperand(3))->getValue() == 1;
2468
2469 if (!IsImmutableTBAA)
2470 continue; // no work to do, MD_tbaa is already marked mutable
2471
2472 MDNode *Base = cast(MD->getOperand(0));
2473 MDNode *Access = cast(MD->getOperand(1));
2474 uint64_t Offset =
2475 mdconst::extract(MD->getOperand(2))->getZExtValue();
2476
2477 MDNode *MutableTBAA =
2478 Builder.createTBAAStructTagNode(Base, Access, Offset);
2463 if (MDNode *Tag = I.getMetadata(LLVMContext::MD_tbaa)) {
2464 MDNode *MutableTBAA = Builder.createMutableTBAAAccessTag(Tag);
24792465 I.setMetadata(LLVMContext::MD_tbaa, MutableTBAA);
24802466 }
24812467
6161
6262 define i8 @test_md(i8 addrspace(1)* %ptr) gc "statepoint-example" {
6363 ; CHECK-LABEL: @test_md(
64 ; CHECK: %tmp = load i8, i8 addrspace(1)* %ptr, !tbaa !0
64 ; CHECK: %tmp = load i8, i8 addrspace(1)* %ptr, !tbaa [[TAG_old:!.*]]
6565 entry:
6666 %tmp = load i8, i8 addrspace(1)* %ptr, !tbaa !0
67 call void @foo() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
68 ret i8 %tmp
69 }
70
71 ; Same as test_md() above, but with new-format TBAA metadata.
72 define i8 @test_md_new(i8 addrspace(1)* %ptr) gc "statepoint-example" {
73 ; CHECK-LABEL: @test_md_new(
74 ; CHECK: %tmp = load i8, i8 addrspace(1)* %ptr, !tbaa [[TAG_new:!.*]]
75 entry:
76 %tmp = load i8, i8 addrspace(1)* %ptr, !tbaa !3
6777 call void @foo() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
6878 ret i8 %tmp
6979 }
91101 define i8 addrspace(1)* @test_callsite_arg_attribute(i8 addrspace(1)* %ptr) gc "statepoint-example" {
92102 ; CHECK-LABEL: @test_callsite_arg_attribute(
93103 ; CHECK: call void @some_function_consumer(i8 addrspace(1)* %ptr)
94 ; CHECK: !0 = !{!1, !1, i64 0}
95 ; CHECK: !1 = !{!"red", !2}
96 ; CHECK: !2 = !{!"blue"}
97104 entry:
98105 call void @some_function_consumer(i8 addrspace(1)* dereferenceable(4) noalias %ptr)
99106 call void @foo() [ "deopt"(i32 0, i32 -1, i32 0, i32 0, i32 0) ]
100107 ret i8 addrspace(1)* %ptr
101108 }
102 !0 = !{!1, !1, i64 0, i64 1}
103 !1 = !{!"red", !2}
104 !2 = !{!"blue"}
109
110 !0 = !{!1, !1, i64 0, i64 1} ; TAG_old
111 !1 = !{!"type_old", !2}
112 !2 = !{!"root"}
113
114 !3 = !{!4, !4, i64 0, i64 1, i64 1} ; TAG_new
115 !4 = !{!2, i64 1, !"type_new"}
116
117 ; CHECK-DAG: [[ROOT:!.*]] = !{!"root"}
118 ; CHECK-DAG: [[TYPE_old:!.*]] = !{!"type_old", [[ROOT]]}
119 ; CHECK-DAG: [[TAG_old]] = !{[[TYPE_old]], [[TYPE_old]], i64 0}
120 ; CHECK-DAG: [[TYPE_new:!.*]] = !{[[ROOT]], i64 1, !"type_new"}
121 ; CHECK-DAG: [[TAG_new]] = !{[[TYPE_new]], [[TYPE_new]], i64 0, i64 1}