llvm.org GIT mirror llvm / c7c7ff0
Merging r259546: ------------------------------------------------------------------------ r259546 | Matthew.Arsenault | 2016-02-02 11:18:53 -0800 (Tue, 02 Feb 2016) | 5 lines AMDGPU: Whitelist handled intrinsics We shouldn't crash on unhandled intrinsics. Also simplify failure handling in loop. ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_38@271592 91177308-0d34-0410-b5e6-96231b3b80d8 Tom Stellard 3 years ago
2 changed file(s) with 62 addition(s) and 10 deletion(s). Raw diff Collapse all Expand all
255255 return true;
256256 }
257257
258 static bool isCallPromotable(CallInst *CI) {
259 // TODO: We might be able to handle some cases where the callee is a
260 // constantexpr bitcast of a function.
261 if (!CI->getCalledFunction())
262 return false;
263
264 IntrinsicInst *II = dyn_cast(CI);
265 if (!II)
266 return false;
267
268 switch (II->getIntrinsicID()) {
269 case Intrinsic::memcpy:
270 case Intrinsic::memset:
271 case Intrinsic::lifetime_start:
272 case Intrinsic::lifetime_end:
273 case Intrinsic::invariant_start:
274 case Intrinsic::invariant_end:
275 case Intrinsic::invariant_group_barrier:
276 return true;
277 default:
278 return false;
279 }
280 }
281
258282 static bool collectUsesWithPtrTypes(Value *Val, std::vector &WorkList) {
259 bool Success = true;
260283 for (User *User : Val->users()) {
261 if(std::find(WorkList.begin(), WorkList.end(), User) != WorkList.end())
262 continue;
284 if (std::find(WorkList.begin(), WorkList.end(), User) != WorkList.end())
285 continue;
286
263287 if (CallInst *CI = dyn_cast(User)) {
264 // TODO: We might be able to handle some cases where the callee is a
265 // constantexpr bitcast of a function.
266 if (!CI->getCalledFunction())
288 if (!isCallPromotable(CI))
267289 return false;
268290
269291 WorkList.push_back(User);
285307 continue;
286308
287309 WorkList.push_back(User);
288
289 Success &= collectUsesWithPtrTypes(User, WorkList);
290 }
291 return Success;
310 if (!collectUsesWithPtrTypes(User, WorkList))
311 return false;
312 }
313
314 return true;
292315 }
293316
294317 void AMDGPUPromoteAlloca::visitAlloca(AllocaInst &I) {
391414
392415 IntrinsicInst *Intr = dyn_cast(Call);
393416 if (!Intr) {
417 // FIXME: What is this for? It doesn't make sense to promote arbitrary
418 // function calls. If the call is to a defined function that can also be
419 // promoted, we should be able to do this once that function is also
420 // rewritten.
421
394422 std::vector ArgTypes;
395423 for (unsigned ArgIdx = 0, ArgEnd = Call->getNumArgOperands();
396424 ArgIdx != ArgEnd; ++ArgIdx) {
0 ; RUN: opt -S -mtriple=amdgcn-unknown-amdhsa < %s | FileCheck %s
1
2 ; This is just an arbitrary intrinisic that shouldn't ever need to be
3 ; handled to ensure it doesn't crash.
4
5 declare void @eh.sjlj.functioncontext(i8*) #2
6
7 ; CHECK-LABEL: @try_promote_unhandled_intrinsic(
8 ; CHECK: alloca
9 ; CHECK: call void @eh.sjlj.functioncontext(i8* %tmp1)
10 define void @try_promote_unhandled_intrinsic(i32 addrspace(1)* %arg) #2 {
11 bb:
12 %tmp = alloca i32, align 4
13 %tmp1 = bitcast i32* %tmp to i8*
14 %tmp2 = getelementptr inbounds i32, i32 addrspace(1)* %arg, i64 1
15 %tmp3 = load i32, i32 addrspace(1)* %tmp2
16 store i32 %tmp3, i32* %tmp
17 call void @eh.sjlj.functioncontext(i8* %tmp1)
18 ret void
19 }
20
21 attributes #0 = { argmemonly nounwind }
22 attributes #1 = { nounwind readnone }
23 attributes #2 = { nounwind }