-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[WIP] Extend data layout to add sentinel pointer value for address space. #83109
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
base: main
Are you sure you want to change the base?
Changes from all commits
dfe826e
d0306c7
0f1412d
8e1aea0
abbff8b
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 |
---|---|---|
|
@@ -216,6 +216,8 @@ void DataLayout::reset(StringRef Desc) { | |
if (Error Err = setPointerAlignmentInBits(0, Align(8), Align(8), 64, 64)) | ||
return report_fatal_error(std::move(Err)); | ||
|
||
setSentinelPointerValue(INT_MAX, 0); | ||
|
||
if (Error Err = parseSpecifier(Desc)) | ||
return report_fatal_error(std::move(Err)); | ||
} | ||
|
@@ -251,6 +253,22 @@ template <typename IntTy> static Error getInt(StringRef R, IntTy &Result) { | |
return Error::success(); | ||
} | ||
|
||
template <typename IntTy> | ||
static Error getIntForAddrSpace(StringRef R, IntTy &Result) { | ||
if (R.starts_with("neg")) { | ||
StringRef AfterNeg = R.slice(3, R.size()); | ||
bool error = AfterNeg.getAsInteger(10, Result); | ||
(void)error; | ||
if (error || Result <= 0) | ||
return reportError("not a number, or does not fit in an unsigned int"); | ||
Result *= -1; | ||
} else if (R.contains("neg")) | ||
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. no else after return 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. updated the return. |
||
return reportError("not a valid value for address space"); | ||
else | ||
return getInt<IntTy>(R, Result); | ||
return Error::success(); | ||
} | ||
|
||
/// Get an unsigned integer representing the number of bits and convert it into | ||
/// bytes. Error out of not a byte width multiple. | ||
template <typename IntTy> | ||
|
@@ -502,6 +520,33 @@ Error DataLayout::parseSpecifier(StringRef Desc) { | |
return Err; | ||
break; | ||
} | ||
case 'z': { | ||
sentinelValueDefined = true; | ||
unsigned AddrSpace = 0; | ||
int64_t Value; | ||
// for unlisted address spaces e.g., z:0 | ||
if (Tok.empty()) { | ||
if (Error Err = getIntForAddrSpace(Rest, Value)) | ||
return Err; | ||
setSentinelPointerValue(INT_MAX, Value); | ||
break; | ||
} else { | ||
if (Error Err = getInt(Tok, AddrSpace)) | ||
return Err; | ||
if (!isUInt<24>(AddrSpace)) | ||
return reportError("Invalid address space, must be a 24-bit integer"); | ||
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. error messages should start with lowercase |
||
} | ||
if (Rest.empty()) | ||
return reportError( | ||
"Missing address space value specification for pointer in " | ||
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. error messages should start with lowercase |
||
"datalayout string"); | ||
if (Error Err = ::split(Rest, ':', Split)) | ||
return Err; | ||
if (Error Err = getIntForAddrSpace(Tok, Value)) | ||
return Err; | ||
setSentinelPointerValue(AddrSpace, Value); | ||
break; | ||
} | ||
case 'G': { // Default address space for global variables. | ||
if (Error Err = getAddrSpace(Tok, DefaultGlobalsAddrSpace)) | ||
return Err; | ||
|
@@ -704,6 +749,7 @@ class StructLayoutMap { | |
} // end anonymous namespace | ||
|
||
void DataLayout::clear() { | ||
|
||
LegalIntWidths.clear(); | ||
IntAlignments.clear(); | ||
FloatAlignments.clear(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
; RUN: not llvm-as %s 2>&1 | FileCheck %s | ||
|
||
; CHECK: error: not a number, or does not fit in an unsigned int | ||
|
||
target datalayout = "z:neg" | ||
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. Those should be unit tests in |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
; RUN: not llvm-as %s 2>&1 | FileCheck %s | ||
|
||
; CHECK: error: not a number, or does not fit in an unsigned int | ||
|
||
target datalayout = "z:neg-1" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
; RUN: not llvm-as %s 2>&1 | FileCheck %s | ||
|
||
; CHECK: error: Trailing separator in datalayout string | ||
|
||
target datalayout = "z:" | ||
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. Missing newline at end of file in most of these |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
; RUN: not llvm-as %s 2>&1 | FileCheck %s | ||
|
||
; CHECK: error: Trailing separator in datalayout string | ||
|
||
target datalayout = "z:-1" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
; RUN: not llvm-as %s 2>&1 | FileCheck %s | ||
|
||
; CHECK: error: not a number, or does not fit in an unsigned int | ||
|
||
target datalayout = "za:0" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4 | ||
; RUN: opt < %s -S -mtriple=amdgcn-- | FileCheck %s | ||
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 don't know what this test is supposed to be showing 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. This is a positive test case to check if the data layout string related sentinel pointer value is parsed correctly. |
||
|
||
; CHECK: target datalayout = "e-p:64:64-p1:64:64-p2:32:32-p3:32:32-p4:64:64-p5:32:32-p6:32:32-p7:160:256:256:32-p8:128:128-p9:192:256:256:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-v2048:2048-n32:64-z:0-z2:neg1-z3:neg1-z5:neg1-S32-A5-G1-ni:7:8:9" | ||
target datalayout = "e-p:64:64-p1:64:64-p2:32:32-p3:32:32-p4:64:64-p5:32:32-p6:32:32-p7:160:256:256:32-p8:128:128-p9:192:256:256:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-v2048:2048-n32:64-z:0-z2:neg1-z3:neg1-z5:neg1-S32-A5-G1-ni:7:8:9" | ||
@lds = addrspace(3) global [8 x i32] [i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8] | ||
|
||
define amdgpu_kernel void @load_init_lds_global(ptr addrspace(1) %out, i1 %p) { | ||
; CHECK-LABEL: define amdgpu_kernel void @load_init_lds_global( | ||
; CHECK-SAME: ptr addrspace(1) [[OUT:%.*]], i1 [[P:%.*]]) { | ||
; CHECK-NEXT: [[GEP:%.*]] = getelementptr [8 x i32], ptr addrspace(3) @lds, i32 0, i32 10 | ||
; CHECK-NEXT: [[LD:%.*]] = load i32, ptr addrspace(3) [[GEP]], align 4 | ||
; CHECK-NEXT: store i32 [[LD]], ptr addrspace(1) [[OUT]], align 4 | ||
; CHECK-NEXT: ret void | ||
; | ||
%gep = getelementptr [8 x i32], ptr addrspace(3) @lds, i32 0, i32 10 | ||
%ld = load i32, ptr addrspace(3) %gep | ||
store i32 %ld, ptr addrspace(1) %out | ||
ret void | ||
} |
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.
What would the "unlisted" AS be?
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.
Unlisted here means, for address spaces which are not specified in the data layout string.