Skip to content

Commit 6ccd593

Browse files
committed
[clang][OMPIRBuilder] Use default target AS to create types
Signed-off-by: Sarnie, Nick <[email protected]>
1 parent 6578772 commit 6ccd593

File tree

5 files changed

+18
-8
lines changed

5 files changed

+18
-8
lines changed

clang/lib/CodeGen/CGOpenMPRuntime.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1037,12 +1037,15 @@ CGOpenMPRuntime::CGOpenMPRuntime(CodeGenModule &CGM)
10371037
CGM.getLangOpts().OpenMPOffloadMandatory,
10381038
/*HasRequiresReverseOffload*/ false, /*HasRequiresUnifiedAddress*/ false,
10391039
hasRequiresUnifiedSharedMemory(), /*HasRequiresDynamicAllocators*/ false);
1040+
Config.setDefaultTargetAS(
1041+
CGM.getContext().getTargetInfo().getTargetAddressSpace(LangAS::Default));
1042+
1043+
OMPBuilder.setConfig(Config);
10401044
OMPBuilder.initialize();
10411045
OMPBuilder.loadOffloadInfoMetadata(*CGM.getFileSystem(),
10421046
CGM.getLangOpts().OpenMPIsTargetDevice
10431047
? CGM.getLangOpts().OMPHostIRFile
10441048
: StringRef{});
1045-
OMPBuilder.setConfig(Config);
10461049

10471050
// The user forces the compiler to behave as if omp requires
10481051
// unified_shared_memory was given.

clang/test/OpenMP/spirv_locstr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// expected-no-diagnostics
55

66
// CHECK: @[[#LOC:]] = private unnamed_addr addrspace(1) constant [23 x i8] c";unknown;unknown;0;0;;\00", align 1
7-
// CHECK: = private unnamed_addr addrspace(1) constant %struct.ident_t { i32 0, i32 2, i32 0, i32 {{.*}}, ptr addrspacecast (ptr addrspace(1) @[[#LOC]] to ptr) }, align 8
7+
// CHECK: = private unnamed_addr addrspace(1) constant %struct.ident_t { i32 0, i32 2, i32 0, i32 {{.*}}, ptr addrspace(4) addrspacecast (ptr addrspace(1) @[[#LOC]] to ptr addrspace(4)) }, align 8
88

99
int main() {
1010
int ret = 0;

llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,16 +125,19 @@ class OpenMPIRBuilderConfig {
125125

126126
/// First separator used between the initial two parts of a name.
127127
std::optional<StringRef> FirstSeparator;
128-
/// Separator used between all of the rest consecutive parts of s name
128+
/// Separator used between all of the rest consecutive parts of s name.
129129
std::optional<StringRef> Separator;
130130

131-
// Grid Value for the GPU target
131+
// Grid Value for the GPU target.
132132
std::optional<omp::GV> GridValue;
133133

134134
/// When compilation is being done for the OpenMP host (i.e. `IsTargetDevice =
135135
/// false`), this contains the list of offloading triples associated, if any.
136136
SmallVector<Triple> TargetTriples;
137137

138+
// Default address space for the target.
139+
unsigned DefaultTargetAS = 0;
140+
138141
LLVM_ABI OpenMPIRBuilderConfig();
139142
LLVM_ABI OpenMPIRBuilderConfig(bool IsTargetDevice, bool IsGPU,
140143
bool OpenMPOffloadMandatory,
@@ -165,6 +168,8 @@ class OpenMPIRBuilderConfig {
165168
return *GridValue;
166169
}
167170

171+
unsigned getDefaultTargetAS() const { return DefaultTargetAS; }
172+
168173
bool hasRequiresFlags() const { return RequiresFlags; }
169174
LLVM_ABI bool hasRequiresReverseOffload() const;
170175
LLVM_ABI bool hasRequiresUnifiedAddress() const;
@@ -202,6 +207,7 @@ class OpenMPIRBuilderConfig {
202207
void setFirstSeparator(StringRef FS) { FirstSeparator = FS; }
203208
void setSeparator(StringRef S) { Separator = S; }
204209
void setGridValue(omp::GV G) { GridValue = G; }
210+
void setDefaultTargetAS(unsigned AS) { DefaultTargetAS = AS; }
205211

206212
LLVM_ABI void setHasRequiresReverseOffload(bool Value);
207213
LLVM_ABI void setHasRequiresUnifiedAddress(bool Value);

llvm/include/llvm/Frontend/OpenMP/OMPKinds.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#endif
2727

2828
#define __OMP_TYPE(VarName) OMP_TYPE(VarName, Type::get##VarName##Ty(Ctx))
29-
#define __OMP_PTR_TYPE(VarName) OMP_TYPE(VarName, PointerType::get(Ctx, 0))
29+
#define __OMP_PTR_TYPE(VarName) OMP_TYPE(VarName, PointerType::get(Ctx, DefaultTargetAS))
3030

3131
__OMP_TYPE(Void)
3232
__OMP_TYPE(Int1)

llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10056,19 +10056,20 @@ OpenMPIRBuilder::createOffloadMapnames(SmallVectorImpl<llvm::Constant *> &Names,
1005610056
void OpenMPIRBuilder::initializeTypes(Module &M) {
1005710057
LLVMContext &Ctx = M.getContext();
1005810058
StructType *T;
10059+
unsigned DefaultTargetAS = Config.getDefaultTargetAS();
1005910060
#define OMP_TYPE(VarName, InitValue) VarName = InitValue;
1006010061
#define OMP_ARRAY_TYPE(VarName, ElemTy, ArraySize) \
1006110062
VarName##Ty = ArrayType::get(ElemTy, ArraySize); \
10062-
VarName##PtrTy = PointerType::getUnqual(Ctx);
10063+
VarName##PtrTy = PointerType::get(Ctx, DefaultTargetAS);
1006310064
#define OMP_FUNCTION_TYPE(VarName, IsVarArg, ReturnType, ...) \
1006410065
VarName = FunctionType::get(ReturnType, {__VA_ARGS__}, IsVarArg); \
10065-
VarName##Ptr = PointerType::getUnqual(Ctx);
10066+
VarName##Ptr = PointerType::get(Ctx, DefaultTargetAS);
1006610067
#define OMP_STRUCT_TYPE(VarName, StructName, Packed, ...) \
1006710068
T = StructType::getTypeByName(Ctx, StructName); \
1006810069
if (!T) \
1006910070
T = StructType::create(Ctx, {__VA_ARGS__}, StructName, Packed); \
1007010071
VarName = T; \
10071-
VarName##Ptr = PointerType::getUnqual(Ctx);
10072+
VarName##Ptr = PointerType::get(Ctx, DefaultTargetAS);
1007210073
#include "llvm/Frontend/OpenMP/OMPKinds.def"
1007310074
}
1007410075

0 commit comments

Comments
 (0)