Skip to content

Commit 3d0093e

Browse files
committed
[Flang][AMDGPU] Lower ALLOCATE/DEALLOCATE to runtime calls.
1 parent 544233f commit 3d0093e

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

clang/lib/Driver/ToolChains/Flang.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,10 @@ void Flang::AddAMDGPUTargetArgs(const ArgList &Args,
432432
Args.MakeArgString("--amdhsa-code-object-version=" + Val));
433433
}
434434

435+
// Force the use of runtime and descriptors for heap allocate/deallocate.
436+
CmdArgs.push_back(Args.MakeArgString("-mmlir"));
437+
CmdArgs.push_back(Args.MakeArgString("--use-alloc-runtime"));
438+
435439
const ToolChain &TC = getToolChain();
436440
TC.addClangTargetOptions(Args, CmdArgs, Action::OffloadKind::OFK_OpenMP);
437441
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
! RUN: %flang -target amdgcn-- -S -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK-AMDGPU
2+
! RUN: %flang -target x86_64-- -S -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK-x86_64
3+
4+
subroutine allocate_deallocate()
5+
real, allocatable :: x
6+
7+
allocate(x)
8+
! CHECK-AMDGPU: call i32 @_FortranAAllocatableAllocate
9+
! CHECK-x86_64: call ptr @malloc
10+
11+
deallocate(x)
12+
! CHECK-AMDGPU: call i32 @_FortranAAllocatableDeallocate
13+
! CHECK-x86_64: call void @free
14+
end subroutine
15+
16+
subroutine allocate_deallocate_ptr()
17+
integer, pointer :: x
18+
19+
allocate(x)
20+
! CHECK-AMDGPU: call i32 @_FortranAPointerAllocate
21+
! CHECK-x86_64: call i32 @_FortranAPointerAllocate
22+
23+
deallocate(x)
24+
! CHECK-AMDGPU: call i32 @_FortranAPointerDeallocate
25+
! CHECK-x86_64: call i32 @_FortranAPointerDeallocate
26+
end subroutine

0 commit comments

Comments
 (0)