llvm.org GIT mirror llvm / 3075954
change the objectsize intrinsic signature: add a 3rd parameter to denote the maximum runtime performance penalty that the user is willing to accept. This commit only adds the parameter. Code taking advantage of it will follow. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@156473 91177308-0d34-0410-b5e6-96231b3b80d8 Nuno Lopes 8 years ago
13 changed file(s) with 90 addition(s) and 45 deletion(s). Raw diff Collapse all Expand all
84408440
84418441
Syntax:
84428442

                  
                
8443 declare i32 @llvm.objectsize.i32(i8* <object>, i1 <type>)
8444 declare i64 @llvm.objectsize.i64(i8* <object>, i1 <type>)
8443 declare i32 @llvm.objectsize.i32(i8* <object>, i1 <min>, i32 <runtime>)
8444 declare i64 @llvm.objectsize.i64(i8* <object>, i1 <min>, i32 <runtime>)
84458445
84468446
84478447
Overview:
84528452 an allocation of a specific class, structure, array, or other object.

84538453
84548454
Arguments:
8455

The llvm.objectsize intrinsic takes two arguments. The first

8455

The llvm.objectsize intrinsic takes three arguments. The first

84568456 argument is a pointer to or into the object. The second argument
8457 is a boolean 0 or 1. This argument determines whether you want the
8458 maximum (0) or minimum (1) bytes remaining. This needs to be a literal 0 or
8459 1, variables are not allowed.

8457 is a boolean and determines whether llvm.objectsize returns 0 (if true)
8458 or -1 (if false) when the object size is unknown.
8459 The third argument, runtime, indicates whether the compiler is allowed
8460 to return a non-constant value. The higher the value, the higher the potential
8461 run-time performance impact.
8462 The second and third arguments only accepts constants.

84608463
84618464
Semantics:
8462

The llvm.objectsize intrinsic is lowered to either a constant

8463 representing the size of the object concerned, or i32/i64 -1 or 0,
8464 depending on the type argument, if the size cannot be determined at
8465 compile time.

8465

The llvm.objectsize intrinsic is lowered to a constant representing

8466 the size of the object concerned. If the size cannot be determined at compile
8467 time, llvm.objectsize either returns i32/i64 -1 or 0
8468 (depending on the min argument) if runtime is 0, or a run-time
8469 value (if runtime > 0 and an expression could be generated).

84668470
84678471
84688472
267267 def int_siglongjmp : Intrinsic<[], [llvm_ptr_ty, llvm_i32_ty]>;
268268
269269 // Internal interface for object size checking
270 def int_objectsize : Intrinsic<[llvm_anyint_ty], [llvm_ptr_ty, llvm_i1_ty],
270 def int_objectsize : Intrinsic<[llvm_anyint_ty],
271 [llvm_ptr_ty, llvm_i1_ty, llvm_i32_ty],
271272 [IntrNoMem]>,
272273 GCCBuiltin<"__builtin_object_size">;
273274
4747 F->setName(Name + ".old");
4848 NewFn = Intrinsic::getDeclaration(F->getParent(), Intrinsic::cttz,
4949 F->arg_begin()->getType());
50 return true;
51 }
52 break;
53 }
54 case 'o': {
55 // FIXME: remove in LLVM 3.3
56 if (Name.startswith("objectsize.") && F->arg_size() == 2) {
57 Type *Tys[] = {F->getReturnType(),
58 F->arg_begin()->getType(),
59 Type::getInt1Ty(F->getContext()),
60 Type::getInt32Ty(F->getContext())};
61 NewFn = Intrinsic::getDeclaration(F->getParent(), Intrinsic::objectsize,
62 Tys);
63 NewFn->takeName(F);
5064 return true;
5165 }
5266 break;
194208 llvm_unreachable("Unknown function for CallInst upgrade.");
195209
196210 case Intrinsic::ctlz:
197 case Intrinsic::cttz:
211 case Intrinsic::cttz: {
198212 assert(CI->getNumArgOperands() == 1 &&
199213 "Mismatch between function args and call args");
200214 StringRef Name = CI->getName();
203217 Builder.getFalse(), Name));
204218 CI->eraseFromParent();
205219 return;
220 }
221 case Intrinsic::objectsize: {
222 StringRef Name = CI->getName();
223 CI->setName(Name + ".old");
224 CI->replaceAllUsesWith(Builder.CreateCall3(NewFn, CI->getArgOperand(0),
225 CI->getArgOperand(1),
226 Builder.getInt32(0), Name));
227 CI->eraseFromParent();
228 return;
229 }
206230 }
207231 }
208232
4242 %3 = load i32* @tabsize, align 4
4343 %4 = srem i32 %cols, %3
4444 %5 = sdiv i32 %cols, %3
45 %6 = tail call i32 @llvm.objectsize.i32(i8* null, i1 false)
45 %6 = tail call i32 @llvm.objectsize.i32(i8* null, i1 false, i32 0)
4646 %7 = tail call i8* @__memset_chk(i8* null, i32 9, i32 %5, i32 %6) nounwind
4747 br label %bb1
4848
5353 ret void
5454 }
5555
56 declare i32 @llvm.objectsize.i32(i8*, i1) nounwind readnone
56 declare i32 @llvm.objectsize.i32(i8*, i1, i32) nounwind readnone
5757 declare i8* @__memset_chk(i8*, i32, i32, i32) nounwind
2222 %3 = load double* %1, align 4
2323 %4 = load double* %0, align 4
2424 call void @Parse_Vector(double* %0) nounwind
25 %5 = call i32 @llvm.objectsize.i32(i8* undef, i1 false)
25 %5 = call i32 @llvm.objectsize.i32(i8* undef, i1 false, i32 0)
2626 %6 = icmp eq i32 %5, -1
2727 br i1 %6, label %bb34, label %bb33
2828
3535 }
3636
3737 declare void @Parse_Vector(double*)
38 declare i32 @llvm.objectsize.i32(i8*, i1)
38 declare i32 @llvm.objectsize.i32(i8*, i1, i32)
3939
4040
4141 ; PR9578
0 ; RUN: opt < %s -verify -S | FileCheck %s
1 ; check automatic upgrade of objectsize. To be removed in LLVM 3.3.
2
3 target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
4
5 define i32 @foo() nounwind {
6 ; CHECK: @foo
7 %1 = alloca i8, align 4
8 %2 = getelementptr inbounds i8* %1, i32 0
9 ; CHECK: llvm.objectsize.i32(i8* %2, i1 false, i32 0)
10 %3 = call i32 @llvm.objectsize.i32(i8* %2, i1 0)
11 ret i32 %3
12 }
13
14 ; CHECK: @llvm.objectsize.i32(i8*, i1, i32)
15 declare i32 @llvm.objectsize.i32(i8*, i1) nounwind readonly
77
88 @aux_temp = external global %struct.dfa, align 8
99
10 declare i64 @llvm.objectsize.i64(i8*, i1) nounwind readnone
10 declare i64 @llvm.objectsize.i64(i8*, i1, i32) nounwind readnone
1111
1212 declare void @__memset_chk() nounwind
1313
2020 br i1 undef, label %land.end.thread.i, label %land.end.i
2121
2222 land.end.thread.i: ; preds = %if.end.i
23 %0 = call i64 @llvm.objectsize.i64(i8* undef, i1 false) nounwind
23 %0 = call i64 @llvm.objectsize.i64(i8* undef, i1 false, i32 0) nounwind
2424 %cmp1710.i = icmp eq i64 %0, -1
2525 br i1 %cmp1710.i, label %cond.false156.i, label %cond.true138.i
2626
2727 land.end.i: ; preds = %if.end.i
28 %1 = call i64 @llvm.objectsize.i64(i8* undef, i1 false) nounwind
28 %1 = call i64 @llvm.objectsize.i64(i8* undef, i1 false, i32 0) nounwind
2929 %cmp17.i = icmp eq i64 %1, -1
3030 br i1 %cmp17.i, label %cond.false156.i, label %cond.true138.i
3131
202202 ;
203203 define fastcc void @func_61() nounwind sspreq {
204204 entry:
205 %t1 = tail call i64 @llvm.objectsize.i64(i8* undef, i1 false)
205 %t1 = tail call i64 @llvm.objectsize.i64(i8* undef, i1 false, i32 0)
206206 %t2 = icmp eq i64 %t1, -1
207207 br i1 %t2, label %bb2, label %bb1
208208
213213 ret void
214214 }
215215
216 declare i64 @llvm.objectsize.i64(i8*, i1) nounwind readnone
216 declare i64 @llvm.objectsize.i64(i8*, i1, i32) nounwind readnone
217217
218218 ; PR10277
219219 ; This test has dead code elimination caused by remat during spilling.
99 define void @bar() nounwind ssp {
1010 entry:
1111 %tmp = load i8** @p ; [#uses=1]
12 %0 = call i64 @llvm.objectsize.i64(i8* %tmp, i1 0) ; [#uses=1]
12 %0 = call i64 @llvm.objectsize.i64(i8* %tmp, i1 0, i32 0) ; [#uses=1]
1313 %cmp = icmp ne i64 %0, -1 ; [#uses=1]
1414 ; X64: movabsq $-1, [[RAX:%r..]]
1515 ; X64: cmpq $-1, [[RAX]]
1818 cond.true: ; preds = %entry
1919 %tmp1 = load i8** @p ; [#uses=1]
2020 %tmp2 = load i8** @p ; [#uses=1]
21 %1 = call i64 @llvm.objectsize.i64(i8* %tmp2, i1 1) ; [#uses=1]
21 %1 = call i64 @llvm.objectsize.i64(i8* %tmp2, i1 1, i32 0) ; [#uses=1]
2222 %call = call i8* @__strcpy_chk(i8* %tmp1, i8* getelementptr inbounds ([3 x i8]* @.str, i32 0, i32 0), i64 %1) ssp ; [#uses=1]
2323 br label %cond.end
2424
3232 ret void
3333 }
3434
35 declare i64 @llvm.objectsize.i64(i8*, i1) nounwind readonly
35 declare i64 @llvm.objectsize.i64(i8*, i1, i32) nounwind readonly
3636
3737 declare i8* @__strcpy_chk(i8*, i8*, i64) ssp
3838
4646 %tmp = load i8** %__dest.addr ; [#uses=1]
4747 %tmp1 = load i8** %__src.addr ; [#uses=1]
4848 %tmp2 = load i8** %__dest.addr ; [#uses=1]
49 %0 = call i64 @llvm.objectsize.i64(i8* %tmp2, i1 1) ; [#uses=1]
49 %0 = call i64 @llvm.objectsize.i64(i8* %tmp2, i1 1, i32 0) ; [#uses=1]
5050 %call = call i8* @__strcpy_chk(i8* %tmp, i8* %tmp1, i64 %0) ssp ; [#uses=1]
5151 store i8* %call, i8** %retval
5252 %1 = load i8** %retval ; [#uses=1]
11 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
22 target triple = "x86_64-apple-darwin10.0.0"
33
4 declare i64 @llvm.objectsize.i64(i8*, i1) nounwind readnone
4 declare i64 @llvm.objectsize.i64(i8*, i1, i32) nounwind readnone
55
66 define void @test5() nounwind optsize noinline ssp {
77 entry:
88 ; CHECK: movq ___stack_chk_guard@GOTPCREL(%rip)
99 %buf = alloca [64 x i8], align 16
10 %0 = call i64 @llvm.objectsize.i64(i8* undef, i1 false)
10 %0 = call i64 @llvm.objectsize.i64(i8* undef, i1 false, i32 0)
1111 br i1 false, label %if.end, label %if.then
1212
1313 if.then: ; preds = %entry
11
22 declare void @llvm.dbg.declare(metadata, metadata) nounwind readnone
33
4 declare i64 @llvm.objectsize.i64(i8*, i1) nounwind readnone
4 declare i64 @llvm.objectsize.i64(i8*, i1, i32) nounwind readnone
55
66 declare i8* @foo(i8*, i32, i64, i64) nounwind
77
2222 %tmp1 = load i32* %__val.addr, align 4, !dbg !21, !tbaa !17
2323 %tmp2 = load i64* %__len.addr, align 8, !dbg !21, !tbaa !19
2424 %tmp3 = load i8** %__dest.addr, align 8, !dbg !21, !tbaa !13
25 %0 = call i64 @llvm.objectsize.i64(i8* %tmp3, i1 false), !dbg !21
25 %0 = call i64 @llvm.objectsize.i64(i8* %tmp3, i1 false, i32 0), !dbg !21
2626 %call = call i8* @foo(i8* %tmp, i32 %tmp1, i64 %tmp2, i64 %0), !dbg !21
2727 ret i8* %call, !dbg !21
2828 }
88 define i32 @foo() nounwind {
99 ; CHECK: @foo
1010 ; CHECK-NEXT: ret i32 60
11 %1 = call i32 @llvm.objectsize.i32(i8* getelementptr inbounds ([60 x i8]* @a, i32 0, i32 0), i1 false)
11 %1 = call i32 @llvm.objectsize.i32(i8* getelementptr inbounds ([60 x i8]* @a, i32 0, i32 0), i1 false, i32 0)
1212 ret i32 %1
1313 }
1414
1616 ; CHECK: @bar
1717 entry:
1818 %retval = alloca i8*
19 %0 = call i32 @llvm.objectsize.i32(i8* getelementptr inbounds ([60 x i8]* @a, i32 0, i32 0), i1 false)
19 %0 = call i32 @llvm.objectsize.i32(i8* getelementptr inbounds ([60 x i8]* @a, i32 0, i32 0), i1 false, i32 0)
2020 %cmp = icmp ne i32 %0, -1
2121 ; CHECK: br i1 true
2222 br i1 %cmp, label %cond.true, label %cond.false
3333 define i32 @f() nounwind {
3434 ; CHECK: @f
3535 ; CHECK-NEXT: ret i32 0
36 %1 = call i32 @llvm.objectsize.i32(i8* getelementptr ([60 x i8]* @a, i32 1, i32 0), i1 false)
36 %1 = call i32 @llvm.objectsize.i32(i8* getelementptr ([60 x i8]* @a, i32 1, i32 0), i1 false, i32 0)
3737 ret i32 %1
3838 }
3939
4242 define i1 @baz() nounwind {
4343 ; CHECK: @baz
4444 ; CHECK-NEXT: ret i1 true
45 %1 = tail call i32 @llvm.objectsize.i32(i8* getelementptr inbounds ([0 x i8]* @window, i32 0, i32 0), i1 false)
45 %1 = tail call i32 @llvm.objectsize.i32(i8* getelementptr inbounds ([0 x i8]* @window, i32 0, i32 0), i1 false, i32 0)
4646 %2 = icmp eq i32 %1, -1
4747 ret i1 %2
4848 }
5151 ; CHECK: @test1
5252 ; CHECK: objectsize.i32
5353 entry:
54 %0 = call i32 @llvm.objectsize.i32(i8* getelementptr inbounds ([0 x i8]* @window, i32 0, i32 10), i1 false) ; [#uses=1]
54 %0 = call i32 @llvm.objectsize.i32(i8* getelementptr inbounds ([0 x i8]* @window, i32 0, i32 10), i1 false, i32 0) ; [#uses=1]
5555 %1 = icmp eq i32 %0, -1 ; [#uses=1]
5656 br i1 %1, label %"47", label %"46"
5757
6767 define i32 @test2() nounwind {
6868 ; CHECK: @test2
6969 ; CHECK-NEXT: ret i32 34
70 %1 = call i32 @llvm.objectsize.i32(i8* getelementptr (i8* bitcast ([9 x i32]* @.str5 to i8*), i32 2), i1 false)
70 %1 = call i32 @llvm.objectsize.i32(i8* getelementptr (i8* bitcast ([9 x i32]* @.str5 to i8*), i32 2), i1 false, i32 0)
7171 ret i32 %1
7272 }
7373
7676
7777 declare i8* @__memcpy_chk(i8*, i8*, i32, i32) nounwind
7878
79 declare i32 @llvm.objectsize.i32(i8*, i1) nounwind readonly
79 declare i32 @llvm.objectsize.i32(i8*, i1, i32) nounwind readonly
8080
8181 declare i8* @__inline_memcpy_chk(i8*, i8*, i32) nounwind inlinehint
8282
8888 bb11:
8989 %0 = getelementptr inbounds float* getelementptr inbounds ([480 x float]* @array, i32 0, i32 128), i32 -127 ; [#uses=1]
9090 %1 = bitcast float* %0 to i8* ; [#uses=1]
91 %2 = call i32 @llvm.objectsize.i32(i8* %1, i1 false) ; [#uses=1]
91 %2 = call i32 @llvm.objectsize.i32(i8* %1, i1 false, i32 0) ; [#uses=1]
9292 %3 = call i8* @__memcpy_chk(i8* undef, i8* undef, i32 512, i32 %2) nounwind ; [#uses=0]
9393 ; CHECK: unreachable
9494 unreachable
110110 entry:
111111 %0 = alloca %struct.data, align 8
112112 %1 = bitcast %struct.data* %0 to i8*
113 %2 = call i32 @llvm.objectsize.i32(i8* %1, i1 false) nounwind
113 %2 = call i32 @llvm.objectsize.i32(i8* %1, i1 false, i32 0) nounwind
114114 ; CHECK-NOT: @llvm.objectsize
115115 ; CHECK: @llvm.memset.p0i8.i32(i8* %1, i8 0, i32 1824, i32 8, i1 false)
116116 %3 = call i8* @__memset_chk(i8* %1, i32 0, i32 1824, i32 %2) nounwind
124124 ; CHECK: @test5
125125 entry:
126126 %0 = tail call noalias i8* @malloc(i32 20) nounwind
127 %1 = tail call i32 @llvm.objectsize.i32(i8* %0, i1 false)
127 %1 = tail call i32 @llvm.objectsize.i32(i8* %0, i1 false, i32 0)
128128 %2 = load i8** @s, align 8
129129 ; CHECK-NOT: @llvm.objectsize
130130 ; CHECK: @llvm.memcpy.p0i8.p0i8.i32(i8* %0, i8* %1, i32 10, i32 1, i1 false)
136136 ; CHECK: @test6
137137 entry:
138138 %0 = tail call noalias i8* @malloc(i32 20) nounwind
139 %1 = tail call i32 @llvm.objectsize.i32(i8* %0, i1 false)
139 %1 = tail call i32 @llvm.objectsize.i32(i8* %0, i1 false, i32 0)
140140 %2 = load i8** @s, align 8
141141 ; CHECK-NOT: @llvm.objectsize
142142 ; CHECK: @__memcpy_chk(i8* %0, i8* %1, i32 30, i32 20)
152152 ; CHECK: @test7
153153 %alloc = call noalias i8* @malloc(i32 48) nounwind
154154 %gep = getelementptr inbounds i8* %alloc, i32 16
155 %objsize = call i32 @llvm.objectsize.i32(i8* %gep, i1 false) nounwind readonly
155 %objsize = call i32 @llvm.objectsize.i32(i8* %gep, i1 false, i32 0) nounwind readonly
156156 ; CHECK-NEXT: ret i32 32
157157 ret i32 %objsize
158158 }
163163 ; CHECK: @test8
164164 %alloc = call noalias i8* @calloc(i32 5, i32 7) nounwind
165165 %gep = getelementptr inbounds i8* %alloc, i32 5
166 %objsize = call i32 @llvm.objectsize.i32(i8* %gep, i1 false) nounwind readonly
166 %objsize = call i32 @llvm.objectsize.i32(i8* %gep, i1 false, i32 0) nounwind readonly
167167 ; CHECK-NEXT: ret i32 30
168168 ret i32 %objsize
169169 }
173173 ; CHECK: @test9
174174 %alloc = call noalias i8* @calloc(i32 100000000, i32 100000000) nounwind
175175 %gep = getelementptr inbounds i8* %alloc, i32 2
176 %objsize = call i32 @llvm.objectsize.i32(i8* %gep, i1 true) nounwind readonly
176 %objsize = call i32 @llvm.objectsize.i32(i8* %gep, i1 true, i32 0) nounwind readonly
177177 ; CHECK-NEXT: ret i32 0
178178 ret i32 %objsize
179179 }
1010
1111 declare i8* @__strcpy_chk(i8*, i8*, i32) nounwind
1212
13 declare i32 @llvm.objectsize.i32(i8*, i1) nounwind readonly
13 declare i32 @llvm.objectsize.i32(i8*, i1, i32) nounwind readonly
1414
1515 ; rdar://6839935
1616
2929 %target = alloca [1024 x i8]
3030 %arg1 = getelementptr [1024 x i8]* %target, i32 0, i32 0
3131 %arg2 = getelementptr [6 x i8]* @hello, i32 0, i32 0
32 %tmp1 = call i32 @llvm.objectsize.i32(i8* %arg1, i1 false)
32 %tmp1 = call i32 @llvm.objectsize.i32(i8* %arg1, i1 false, i32 0)
3333 %rslt1 = call i8* @__strcpy_chk(i8* %arg1, i8* %arg2, i32 %tmp1)
3434 ; CHECK: @__memcpy_chk
3535 ret i32 0