Skip to content

Commit aaa33b6

Browse files
committed
Fix assert "DeclRefExpr for Decl not entered in LocalDeclMap?"
Currently compiler assert when passing variable "memspace" in omp_init_allocator. omp_allocator_handle_t alloc=omp_init_allocator(memspace,1,traits) The problem is memspace is not mapping to the target region. During the call to emitAllocatorInit, calls to EmitVarDecl for "alloc", then emit initialization of "alloc" that cause to assert. If I understant correct, it is not necessary to emit variable initialization, since "allocator" is private to target region. To fix this call CGF.EmitAutoVarAlloca(allocator) instead CGF.EmitVarDecl(allocator). Differential Revision: https://reviews.llvm.org/D151743
1 parent 79fadde commit aaa33b6

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

clang/lib/CodeGen/CGOpenMPRuntime.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6041,7 +6041,7 @@ void CGOpenMPRuntime::emitUsesAllocatorsInit(CodeGenFunction &CGF,
60416041
CGM.getModule(), OMPRTL___kmpc_init_allocator),
60426042
{ThreadId, MemSpaceHandle, NumTraits, Traits});
60436043
// Store to allocator.
6044-
CGF.EmitVarDecl(*cast<VarDecl>(
6044+
CGF.EmitAutoVarAlloca(*cast<VarDecl>(
60456045
cast<DeclRefExpr>(Allocator->IgnoreParenImpCasts())->getDecl()));
60466046
LValue AllocatorLVal = CGF.EmitLValue(Allocator->IgnoreParenImpCasts());
60476047
AllocatorVal =

clang/test/OpenMP/target_uses_allocators.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,35 @@ void fie(void) {
6464
{}
6565
}
6666

67+
typedef enum omp_memspace_handle_t {
68+
omp_default_mem_space = 0,
69+
omp_large_cap_mem_space = 1,
70+
omp_const_mem_space = 2,
71+
omp_high_bw_mem_space = 3,
72+
omp_low_lat_mem_space = 4,
73+
llvm_omp_target_host_mem_space = 100,
74+
llvm_omp_target_shared_mem_space = 101,
75+
llvm_omp_target_device_mem_space = 102,
76+
KMP_MEMSPACE_MAX_HANDLE = __UINTPTR_MAX__
77+
} omp_memspace_handle_t;
78+
79+
extern omp_allocator_handle_t
80+
omp_init_allocator(omp_memspace_handle_t memspace, int ntraits,
81+
const omp_alloctrait_t traits[]);
82+
83+
void *omp_aligned_alloc(unsigned long alignment, unsigned long size,
84+
omp_allocator_handle_t allocator);
85+
extern void * omp_alloc(int size, omp_allocator_handle_t a);
86+
#define N 1024
87+
88+
void foo() {
89+
int errors = 0;
90+
omp_memspace_handle_t memspace = omp_default_mem_space;
91+
omp_alloctrait_t traits[1] = {{omp_atk_alignment, 64}};
92+
omp_allocator_handle_t alloc = omp_init_allocator(memspace,1,traits);
93+
#pragma omp target map(tofrom: errors) uses_allocators(alloc(traits))
94+
{ }
95+
}
6796
#endif
6897

6998
// CHECK: %[[#R0:]] = call i32 @__kmpc_global_thread_num(ptr @1)
@@ -140,3 +169,15 @@ void fie(void) {
140169
// CHECK: [[ALLOCATOR:%.+]] = load i64, ptr [[MY_ALLOCATOR_ADDR]],
141170
// CHECK: [[CONV:%.+]] = inttoptr i64 [[ALLOCATOR]] to ptr
142171
// CHECK: call void @__kmpc_destroy_allocator(i32 %{{.+}}, ptr [[CONV]])
172+
173+
// CHECK: [[TRAITS_ADDR_REF:%.+]] = alloca ptr,
174+
// CHECK: [[MY_ALLOCATOR_ADDR:%alloc]] = alloca i64,
175+
// CHECK: [[TRAITS_ADDR:%.+]] = load ptr, ptr [[TRAITS_ADDR_REF]],
176+
// CHECK: [[ALLOCATOR:%.+]] = call ptr @__kmpc_init_allocator(i32 %{{.+}}, ptr null, i32 1, ptr [[TRAITS_ADDR]])
177+
// CHECK: [[CONV:%.+]] = ptrtoint ptr [[ALLOCATOR]] to i64
178+
// CHECK: store i64 [[CONV]], ptr [[MY_ALLOCATOR_ADDR]],
179+
180+
// Destroy allocator upon exit from the region.
181+
// CHECK: [[ALLOCATOR:%.+]] = load i64, ptr [[MY_ALLOCATOR_ADDR]],
182+
// CHECK: [[CONV1:%.+]] = inttoptr i64 [[ALLOCATOR]] to ptr
183+
// CHECK: call void @__kmpc_destroy_allocator(i32 %{{.+}}, ptr [[CONV1]])

0 commit comments

Comments
 (0)