Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion clang/lib/CodeGen/CGOpenMPRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1037,12 +1037,15 @@ CGOpenMPRuntime::CGOpenMPRuntime(CodeGenModule &CGM)
CGM.getLangOpts().OpenMPOffloadMandatory,
/*HasRequiresReverseOffload*/ false, /*HasRequiresUnifiedAddress*/ false,
hasRequiresUnifiedSharedMemory(), /*HasRequiresDynamicAllocators*/ false);
Config.setDefaultTargetAS(
CGM.getContext().getTargetInfo().getTargetAddressSpace(LangAS::Default));

OMPBuilder.setConfig(Config);
OMPBuilder.initialize();
OMPBuilder.loadOffloadInfoMetadata(*CGM.getFileSystem(),
CGM.getLangOpts().OpenMPIsTargetDevice
? CGM.getLangOpts().OMPHostIRFile
: StringRef{});
OMPBuilder.setConfig(Config);

// The user forces the compiler to behave as if omp requires
// unified_shared_memory was given.
Expand Down
2 changes: 1 addition & 1 deletion clang/test/OpenMP/spirv_locstr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// expected-no-diagnostics

// CHECK: @[[#LOC:]] = private unnamed_addr addrspace(1) constant [23 x i8] c";unknown;unknown;0;0;;\00", align 1
// 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
// 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

int main() {
int ret = 0;
Expand Down
10 changes: 8 additions & 2 deletions llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,19 @@ class OpenMPIRBuilderConfig {

/// First separator used between the initial two parts of a name.
std::optional<StringRef> FirstSeparator;
/// Separator used between all of the rest consecutive parts of s name
/// Separator used between all of the rest consecutive parts of s name.
std::optional<StringRef> Separator;

// Grid Value for the GPU target
// Grid Value for the GPU target.
std::optional<omp::GV> GridValue;

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

// Default address space for the target.
unsigned DefaultTargetAS = 0;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't use std::optional here because we create OpenMPIRBuilder directly in a ton of unit tests directly and I didn't want to update them all, and also I think that since we already assume the default AS is zero we can continue doing that in cases where we don't set it from clang.


LLVM_ABI OpenMPIRBuilderConfig();
LLVM_ABI OpenMPIRBuilderConfig(bool IsTargetDevice, bool IsGPU,
bool OpenMPOffloadMandatory,
Expand Down Expand Up @@ -165,6 +168,8 @@ class OpenMPIRBuilderConfig {
return *GridValue;
}

unsigned getDefaultTargetAS() const { return DefaultTargetAS; }

bool hasRequiresFlags() const { return RequiresFlags; }
LLVM_ABI bool hasRequiresReverseOffload() const;
LLVM_ABI bool hasRequiresUnifiedAddress() const;
Expand Down Expand Up @@ -202,6 +207,7 @@ class OpenMPIRBuilderConfig {
void setFirstSeparator(StringRef FS) { FirstSeparator = FS; }
void setSeparator(StringRef S) { Separator = S; }
void setGridValue(omp::GV G) { GridValue = G; }
void setDefaultTargetAS(unsigned AS) { DefaultTargetAS = AS; }

LLVM_ABI void setHasRequiresReverseOffload(bool Value);
LLVM_ABI void setHasRequiresUnifiedAddress(bool Value);
Expand Down
2 changes: 1 addition & 1 deletion llvm/include/llvm/Frontend/OpenMP/OMPKinds.def
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#endif

#define __OMP_TYPE(VarName) OMP_TYPE(VarName, Type::get##VarName##Ty(Ctx))
#define __OMP_PTR_TYPE(VarName) OMP_TYPE(VarName, PointerType::get(Ctx, 0))
#define __OMP_PTR_TYPE(VarName) OMP_TYPE(VarName, PointerType::get(Ctx, DefaultTargetAS))

__OMP_TYPE(Void)
__OMP_TYPE(Int1)
Expand Down
7 changes: 4 additions & 3 deletions llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10056,19 +10056,20 @@ OpenMPIRBuilder::createOffloadMapnames(SmallVectorImpl<llvm::Constant *> &Names,
void OpenMPIRBuilder::initializeTypes(Module &M) {
LLVMContext &Ctx = M.getContext();
StructType *T;
unsigned DefaultTargetAS = Config.getDefaultTargetAS();
#define OMP_TYPE(VarName, InitValue) VarName = InitValue;
#define OMP_ARRAY_TYPE(VarName, ElemTy, ArraySize) \
VarName##Ty = ArrayType::get(ElemTy, ArraySize); \
VarName##PtrTy = PointerType::getUnqual(Ctx);
VarName##PtrTy = PointerType::get(Ctx, DefaultTargetAS);
#define OMP_FUNCTION_TYPE(VarName, IsVarArg, ReturnType, ...) \
VarName = FunctionType::get(ReturnType, {__VA_ARGS__}, IsVarArg); \
VarName##Ptr = PointerType::getUnqual(Ctx);
VarName##Ptr = PointerType::get(Ctx, DefaultTargetAS);
#define OMP_STRUCT_TYPE(VarName, StructName, Packed, ...) \
T = StructType::getTypeByName(Ctx, StructName); \
if (!T) \
T = StructType::create(Ctx, {__VA_ARGS__}, StructName, Packed); \
VarName = T; \
VarName##Ptr = PointerType::getUnqual(Ctx);
VarName##Ptr = PointerType::get(Ctx, DefaultTargetAS);
#include "llvm/Frontend/OpenMP/OMPKinds.def"
}

Expand Down
Loading