llvm.org GIT mirror llvm / 9a2ae00
Teach the DAGBuilder about lifetime markers which are generated from PHINodes. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@163494 91177308-0d34-0410-b5e6-96231b3b80d8 Nadav Rotem 7 years ago
2 changed file(s) with 59 addition(s) and 20 deletion(s). Raw diff Collapse all Expand all
52175217 }
52185218 case Intrinsic::lifetime_start:
52195219 case Intrinsic::lifetime_end: {
5220 bool IsStart = (Intrinsic == Intrinsic::lifetime_start);
52205221 // Stack coloring is not enabled in O0, discard region information.
5221 if (TM.getOptLevel() == CodeGenOpt::None) {
5222 if (Intrinsic == Intrinsic::lifetime_start)
5223 setValue(&I, DAG.getUNDEF(TLI.getPointerTy()));
5222 if (TM.getOptLevel() == CodeGenOpt::None)
52245223 return 0;
5225 }
5226 SDValue Ops[2];
5227 AllocaInst *LifetimeObject =dyn_cast_or_null(
5228 GetUnderlyingObject(I.getArgOperand(1), TD));
5229 // Could not find an Alloca.
5230 if (!LifetimeObject)
5231 return 0;
5232
5233 int FI = FuncInfo.StaticAllocaMap[LifetimeObject];
5234 Ops[0] = getRoot();
5235 Ops[1] = DAG.getFrameIndex(FI, TLI.getPointerTy(), true);
5236 bool IsStart = (Intrinsic == Intrinsic::lifetime_start);
5237 unsigned Opcode = (IsStart ? ISD::LIFETIME_START : ISD::LIFETIME_END);
5238
5239 Res = DAG.getNode(Opcode, dl, MVT::Other, Ops, 2);
5240 DAG.setRoot(Res);
5241 return 0;
5224
5225 SmallVector Allocas;
5226 GetUnderlyingObjects(I.getArgOperand(1), Allocas, TD);
5227
5228 for (SmallVector::iterator Object = Allocas.begin(),
5229 E = Allocas.end(); Object != E; ++Object) {
5230 AllocaInst *LifetimeObject = dyn_cast_or_null(*Object);
5231
5232 // Could not find an Alloca.
5233 if (!LifetimeObject)
5234 continue;
5235
5236 int FI = FuncInfo.StaticAllocaMap[LifetimeObject];
5237
5238 SDValue Ops[2];
5239 Ops[0] = getRoot();
5240 Ops[1] = DAG.getFrameIndex(FI, TLI.getPointerTy(), true);
5241 unsigned Opcode = (IsStart ? ISD::LIFETIME_START : ISD::LIFETIME_END);
5242
5243 Res = DAG.getNode(Opcode, dl, MVT::Other, Ops, 2);
5244 DAG.setRoot(Res);
5245 }
52425246 }
52435247 case Intrinsic::invariant_start:
52445248 // Discard region information.
261261 ret void
262262 }
263263
264 ;YESCOLOR: subq $272, %rsp
265 ;NOCOLOR: subq $272, %rsp
266 define i32 @func_phi_lifetime(i32 %in, i1 %d) {
267 entry:
268 %a = alloca [17 x i8*], align 8
269 %a2 = alloca [16 x i8*], align 8
270 %b = bitcast [17 x i8*]* %a to i8*
271 %b2 = bitcast [16 x i8*]* %a2 to i8*
272 %t1 = call i32 @foo(i32 %in, i8* %b)
273 %t2 = call i32 @foo(i32 %in, i8* %b)
274 call void @llvm.lifetime.end(i64 -1, i8* %b)
275 br i1 %d, label %bb0, label %bb1
276
277 bb0:
278 %I1 = bitcast [17 x i8*]* %a to i8*
279 br label %bb2
280
281 bb1:
282 %I2 = bitcast [16 x i8*]* %a2 to i8*
283 br label %bb2
284
285 bb2:
286 %split = phi i8* [ %I1, %bb0 ], [ %I2, %bb1 ]
287 call void @llvm.lifetime.start(i64 -1, i8* %split)
288 %t3 = call i32 @foo(i32 %in, i8* %b2)
289 %t4 = call i32 @foo(i32 %in, i8* %b2)
290 %t5 = add i32 %t1, %t2
291 %t6 = add i32 %t3, %t4
292 %t7 = add i32 %t5, %t6
293 call void @llvm.lifetime.end(i64 -1, i8* %split)
294 ret i32 %t7
295 bb3:
296 ret i32 0
297 }
298
264299 declare void @bar([100 x i32]* , [100 x i32]*) nounwind
265300
266301 declare void @llvm.lifetime.start(i64, i8* nocapture) nounwind