-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[SystemZ][z/OS] __ptr32 support for z/OS in Clang #96063
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -21,6 +21,30 @@ | |||||||||||
namespace clang { | ||||||||||||
namespace targets { | ||||||||||||
|
||||||||||||
static const unsigned ZOSAddressMap[] = { | ||||||||||||
0, // Default | ||||||||||||
0, // opencl_global | ||||||||||||
0, // opencl_local | ||||||||||||
0, // opencl_constant | ||||||||||||
0, // opencl_private | ||||||||||||
0, // opencl_generic | ||||||||||||
0, // opencl_global_device | ||||||||||||
0, // opencl_global_host | ||||||||||||
0, // cuda_device | ||||||||||||
0, // cuda_constant | ||||||||||||
0, // cuda_shared | ||||||||||||
0, // sycl_global | ||||||||||||
0, // sycl_global_device | ||||||||||||
0, // sycl_global_host | ||||||||||||
0, // sycl_local | ||||||||||||
0, // sycl_private | ||||||||||||
0, // ptr32_sptr | ||||||||||||
1, // ptr32_uptr | ||||||||||||
0, // ptr64 | ||||||||||||
0, // hlsl_groupshared | ||||||||||||
0 // wasm_funcref | ||||||||||||
}; | ||||||||||||
|
||||||||||||
class LLVM_LIBRARY_VISIBILITY SystemZTargetInfo : public TargetInfo { | ||||||||||||
|
||||||||||||
static const char *const GCCRegNames[]; | ||||||||||||
|
@@ -30,6 +54,7 @@ class LLVM_LIBRARY_VISIBILITY SystemZTargetInfo : public TargetInfo { | |||||||||||
bool HasVector; | ||||||||||||
bool SoftFloat; | ||||||||||||
bool UnalignedSymbols; | ||||||||||||
enum AddrSpace { ptr32 = 1 }; | ||||||||||||
|
||||||||||||
public: | ||||||||||||
SystemZTargetInfo(const llvm::Triple &Triple, const TargetOptions &) | ||||||||||||
|
@@ -49,14 +74,17 @@ class LLVM_LIBRARY_VISIBILITY SystemZTargetInfo : public TargetInfo { | |||||||||||
MinGlobalAlign = 16; | ||||||||||||
HasUnalignedAccess = true; | ||||||||||||
if (Triple.isOSzOS()) { | ||||||||||||
if (Triple.isArch64Bit()) { | ||||||||||||
AddrSpaceMap = &ZOSAddressMap; | ||||||||||||
} | ||||||||||||
TLSSupported = false; | ||||||||||||
// All vector types are default aligned on an 8-byte boundary, even if the | ||||||||||||
// vector facility is not available. That is different from Linux. | ||||||||||||
MaxVectorAlign = 64; | ||||||||||||
// Compared to Linux/ELF, the data layout differs only in some details: | ||||||||||||
// - name mangling is GOFF. | ||||||||||||
// - 32 bit pointers, either as default or special address space | ||||||||||||
resetDataLayout("E-m:l-i1:8:16-i8:8:16-i64:64-f128:64-v128:64-" | ||||||||||||
resetDataLayout("E-m:l-p1:32:32-i1:8:16-i8:8:16-i64:64-f128:64-v128:64-" | ||||||||||||
"a:8:16-n32:64"); | ||||||||||||
} else { | ||||||||||||
TLSSupported = true; | ||||||||||||
|
@@ -224,6 +252,19 @@ class LLVM_LIBRARY_VISIBILITY SystemZTargetInfo : public TargetInfo { | |||||||||||
std::pair<unsigned, unsigned> hardwareInterferenceSizes() const override { | ||||||||||||
return std::make_pair(256, 256); | ||||||||||||
} | ||||||||||||
|
||||||||||||
uint64_t getPointerWidthV(LangAS AddrSpace) const override { | ||||||||||||
unsigned TargetAddrSpace = getTargetAddressSpace(AddrSpace); | ||||||||||||
return (TargetAddrSpace == ptr32 && getTriple().isOSzOS() && | ||||||||||||
getTriple().isArch64Bit()) | ||||||||||||
Comment on lines
+257
to
+259
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
? 32 | ||||||||||||
: PointerWidth; | ||||||||||||
} | ||||||||||||
|
||||||||||||
uint64_t getPointerAlignV(LangAS AddrSpace) const override { | ||||||||||||
return getPointerWidthV(AddrSpace); | ||||||||||||
} | ||||||||||||
|
||||||||||||
}; | ||||||||||||
} // namespace targets | ||||||||||||
} // namespace clang | ||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3567,6 +3567,14 @@ void CompilerInvocationBase::GenerateLangArgs(const LangOptions &Opts, | |
GenerateArg(Consumer, OPT_ftrigraphs); | ||
} | ||
|
||
if (T.isOSzOS()) { | ||
if (!Opts.ZOSExt) | ||
GenerateArg(Consumer, OPT_fno_zos_extensions); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume the default is -fno-zos-extensions, can you check why we need to explicitly pass this option? |
||
} else { | ||
if (Opts.ZOSExt) | ||
GenerateArg(Consumer, OPT_fzos_extensions); | ||
} | ||
|
||
if (Opts.Blocks && !(Opts.OpenCL && Opts.OpenCLVersion == 200)) | ||
GenerateArg(Consumer, OPT_fblocks); | ||
|
||
|
@@ -3968,6 +3976,9 @@ bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args, | |
Opts.Trigraphs = | ||
Args.hasFlag(OPT_ftrigraphs, OPT_fno_trigraphs, Opts.Trigraphs); | ||
|
||
Opts.ZOSExt = | ||
Args.hasFlag(OPT_fzos_extensions, OPT_fno_zos_extensions, T.isOSzOS()); | ||
|
||
Opts.Blocks = Args.hasArg(OPT_fblocks) || (Opts.OpenCL | ||
&& Opts.OpenCLVersion == 200); | ||
|
||
|
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -7089,6 +7089,7 @@ static bool handleMSPointerTypeQualifierAttr(TypeProcessingState &State, | |||||||||||
|
||||||||||||
// Add address space to type based on its attributes. | ||||||||||||
LangAS ASIdx = LangAS::Default; | ||||||||||||
llvm::Triple Triple = S.Context.getTargetInfo().getTriple(); | ||||||||||||
uint64_t PtrWidth = | ||||||||||||
S.Context.getTargetInfo().getPointerWidth(LangAS::Default); | ||||||||||||
if (PtrWidth == 32) { | ||||||||||||
|
@@ -7097,10 +7098,14 @@ static bool handleMSPointerTypeQualifierAttr(TypeProcessingState &State, | |||||||||||
else if (Attrs[attr::UPtr]) | ||||||||||||
ASIdx = LangAS::ptr32_uptr; | ||||||||||||
} else if (PtrWidth == 64 && Attrs[attr::Ptr32]) { | ||||||||||||
if (Attrs[attr::UPtr]) | ||||||||||||
if (Triple.isOSzOS()) { | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
This is simpler. |
||||||||||||
ASIdx = LangAS::ptr32_uptr; | ||||||||||||
else | ||||||||||||
ASIdx = LangAS::ptr32_sptr; | ||||||||||||
} else { | ||||||||||||
if (Attrs[attr::UPtr]) | ||||||||||||
ASIdx = LangAS::ptr32_uptr; | ||||||||||||
else | ||||||||||||
ASIdx = LangAS::ptr32_sptr; | ||||||||||||
} | ||||||||||||
Comment on lines
+7101
to
+7108
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume this block can be simplifed |
||||||||||||
} | ||||||||||||
|
||||||||||||
QualType Pointee = Type->getPointeeType(); | ||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// RUN: %clang_cc1 -triple s390x-ibm-zos -fzos-extensions -emit-llvm < %s | FileCheck %s --check-prefix=PTR32-ZOS | ||
// RUN: %clang_cc1 -triple s390x-ibm-linux -fzos-extensions -emit-llvm < %s | FileCheck %s --check-prefix=PTR32-LINUX | ||
// RUN: %clang_cc1 -triple s390x-linux-gnu -fzos-extensions -emit-llvm < %s | FileCheck %s --check-prefix=PTR32-LINUX | ||
|
||
void ptr32_declarations() { | ||
// PTR32-ZOS-LABEL: @ptr32_declarations() | ||
// PTR32-LINUX-LABEL: @ptr32_declarations() | ||
|
||
// PTR32-ZOS: %p1 = alloca ptr addrspace(1), align 4 | ||
// PTR32-LINUX-NOT: %p1 = alloca i8 addrspace(1)*, align 4 | ||
// PTR32-LINUX: %p1 = alloca ptr, align 8 | ||
char * __ptr32 p1; | ||
|
||
// PTR32-ZOS: %p2 = alloca ptr, align 8 | ||
// PTR32-LINUX-NOT: %p2 = alloca ptr addrspace(1), align 8 | ||
// PTR32-LINUX: %p2 = alloca ptr, align 8 | ||
char * __ptr32 *p2; | ||
|
||
// PTR32-ZOS: %p3 = alloca ptr addrspace(1), align 4 | ||
// PTR32-LINUX-NOT: %p3 = alloca i8* addrspace(1)*, align 4 | ||
// PTR32-LINUX: %p3 = alloca ptr, align 8 | ||
char ** __ptr32 p3; | ||
|
||
// PTR32-ZOS: %p4 = alloca ptr, align 8 | ||
// PTR32-LINUX-NOT: %p4 = alloca ptr addrspace(1), align 8 | ||
// PTR32-LINUX: %p4 = alloca ptr, align 8 | ||
char ** __ptr32 *p4; | ||
|
||
// PTR32-ZOS: %p5 = alloca ptr, align 8 | ||
// PTR32-LINUX-NOT: %p5 = alloca ptr addrspace(1), align 8 | ||
// PTR32-LINUX: %p5 = alloca ptr, align 8 | ||
char *** __ptr32 *p5; | ||
|
||
// PTR32-ZOS: %p6 = alloca ptr, align 8 | ||
// PTR32-LINUX: %p6 = alloca ptr, align 8 | ||
char **p6; | ||
|
||
// PTR32-ZOS: %p7 = alloca ptr addrspace(1), align 4 | ||
// PTR32-LINUX-NOT: %p7 = alloca i8 addrspace(1)* addrspace(1)*, align 4 | ||
// PTR32-LINUX: %p7 = alloca ptr, align 8 | ||
char * __ptr32 * __ptr32 p7; | ||
|
||
// PTR32-ZOS: %p8 = alloca ptr addrspace(1), align 4 | ||
// PTR32-LINUX-NOT: %p8 = alloca i8* addrspace(1)* addrspace(1)*, align 4 | ||
// PTR32-LINUX: %p8 = alloca ptr, align 8 | ||
char ** __ptr32 * __ptr32 p8; | ||
|
||
// PTR32-ZOS: %p9 = alloca ptr, align 8 | ||
// PTR32-LINUX-NOT: %p9 = alloca i8* addrspace(1)* addrspace(1)**, align 8 | ||
// PTR32-LINUX: %p9 = alloca ptr, align 8 | ||
char ** __ptr32 * __ptr32 *p9; | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// RUN: %clang_cc1 -triple s390x-ibm-zos -fzos-extensions -emit-llvm -O2 < %s | FileCheck %s --check-prefix=X64 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this test need to be some complicated? |
||
#include <stddef.h> | ||
void *__malloc31(size_t); | ||
|
||
int test_1() { | ||
// X64-LABEL: define {{.*}} i32 @test_1() | ||
// X64: ret i32 135 | ||
int *__ptr32 a; | ||
int *b; | ||
int i; | ||
int sum1, sum2, sum3; | ||
|
||
a = (int *__ptr32)__malloc31(sizeof(int) * 10); | ||
|
||
b = a; | ||
sum1 = 0; | ||
for (i = 0; i < 10; ++i) { | ||
a[i] = i; | ||
sum1 += i; | ||
} | ||
|
||
sum2 = 0; | ||
for (i = 0; i < 10; ++i) { | ||
sum2 += a[i]; | ||
} | ||
sum3 = 0; | ||
for (i = 0; i < 10; ++i) { | ||
sum3 += b[i]; | ||
} | ||
|
||
return (sum1 + sum2 + sum3); | ||
} | ||
|
||
int test_2() { | ||
// X64-LABEL: define {{.*}} i32 @test_2() | ||
// X64: ret i32 4 | ||
int *a = (int *)__malloc31(sizeof(int)); | ||
int *__ptr32 b; | ||
|
||
*a = 99; | ||
b = a; | ||
*b = 44; | ||
|
||
// Test should return 4 | ||
return (*b - 40); | ||
} | ||
|
||
int test_3() { | ||
// X64-LABEL: define {{.*}} i32 @test_3() | ||
// X64: ret i32 4 | ||
int *a = (int *)__malloc31(sizeof(int)); | ||
int *__ptr32 b; | ||
|
||
*a = 99; | ||
b = a; | ||
|
||
// Test should return 4 | ||
return (*b - 95); | ||
} | ||
|
||
int test_4() { | ||
// X64-LABEL: define {{.*}} i32 @test_4() | ||
// X64: ret i32 1 | ||
int *a = (int *)__malloc31(sizeof(int)); | ||
float *d = (float *)__malloc31(sizeof(float)); | ||
|
||
int *__ptr32 b; | ||
int *c; | ||
|
||
float *__ptr32 e; | ||
float *f; | ||
|
||
*a = 0; | ||
*d = 0.0; | ||
|
||
b = a; | ||
c = a; | ||
e = d; | ||
f = d; | ||
|
||
// Test should return 1 | ||
return (b == c && e == f); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.