Skip to content

Commit 148e099

Browse files
authored
[MLIR][OpenMP] Set default address space for OpenMPIRBuilder (#158689)
Extension of llvm/llvm-project#158152 for MLIR. --------- Signed-off-by: Sarnie, Nick <[email protected]>
1 parent e7101da commit 148e099

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

mlir/lib/Target/LLVMIR/ModuleTranslation.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2246,18 +2246,22 @@ SmallVector<llvm::Value *> ModuleTranslation::lookupValues(ValueRange values) {
22462246
llvm::OpenMPIRBuilder *ModuleTranslation::getOpenMPBuilder() {
22472247
if (!ompBuilder) {
22482248
ompBuilder = std::make_unique<llvm::OpenMPIRBuilder>(*llvmModule);
2249-
ompBuilder->initialize();
22502249

22512250
// Flags represented as top-level OpenMP dialect attributes are set in
22522251
// `OpenMPDialectLLVMIRTranslationInterface::amendOperation()`. Here we set
22532252
// the default configuration.
2254-
ompBuilder->setConfig(llvm::OpenMPIRBuilderConfig(
2253+
llvm::OpenMPIRBuilderConfig config(
22552254
/* IsTargetDevice = */ false, /* IsGPU = */ false,
22562255
/* OpenMPOffloadMandatory = */ false,
22572256
/* HasRequiresReverseOffload = */ false,
22582257
/* HasRequiresUnifiedAddress = */ false,
22592258
/* HasRequiresUnifiedSharedMemory = */ false,
2260-
/* HasRequiresDynamicAllocators = */ false));
2259+
/* HasRequiresDynamicAllocators = */ false);
2260+
unsigned int defaultAS =
2261+
getLLVMModule()->getDataLayout().getProgramAddressSpace();
2262+
config.setDefaultTargetAS(defaultAS);
2263+
ompBuilder->setConfig(std::move(config));
2264+
ompBuilder->initialize();
22612265
}
22622266
return ompBuilder.get();
22632267
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// RUN: mlir-translate -mlir-to-llvmir %s | FileCheck %s
2+
3+
// This tests that we correctly use the default program AS from the data layout.
4+
module attributes {dlti.dl_spec = #dlti.dl_spec<#dlti.dl_entry<"dlti.program_memory_space", 4 : ui32>>, llvm.target_triple = "spirv64-intel", omp.is_target_device = true, omp.is_gpu = true} {
5+
6+
// CHECK: @[[IDENT:.*]] = private unnamed_addr constant %s{{.*}} { i32 0, i32 2, i32 0, i32 22, ptr addrspace(4) addrspacecast (ptr @{{.*}} to ptr addrspace(4)) }, align 8
7+
8+
llvm.func @omp_target_region_() {
9+
%0 = llvm.mlir.constant(20 : i32) : i32
10+
%1 = llvm.mlir.constant(10 : i32) : i32
11+
%2 = llvm.mlir.constant(1 : i64) : i64
12+
%3 = llvm.alloca %2 x i32 {bindc_name = "a", in_type = i32, operandSegmentSizes = array<i32: 0, 0>, uniq_name = "_QFomp_target_regionEa"} : (i64) -> !llvm.ptr<5>
13+
%4 = llvm.addrspacecast %3 : !llvm.ptr<5> to !llvm.ptr
14+
llvm.store %1, %4 : i32, !llvm.ptr
15+
%map = omp.map.info var_ptr(%4 : !llvm.ptr, i32) map_clauses(tofrom) capture(ByRef) -> !llvm.ptr {name = ""}
16+
omp.target map_entries(%map -> %arg : !llvm.ptr) {
17+
omp.terminator
18+
}
19+
llvm.return
20+
}
21+
}

0 commit comments

Comments
 (0)