-
Notifications
You must be signed in to change notification settings - Fork 230
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
Added option to choose program address space in emitted LLVM IR #1392
base: main
Are you sure you want to change the base?
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 |
---|---|---|
|
@@ -355,6 +355,18 @@ std::string SPIRVToLLVM::transVCTypeName(SPIRVTypeBufferSurfaceINTEL *PST) { | |
return VectorComputeUtil::getVCBufferSurfaceName(); | ||
} | ||
|
||
static unsigned transPointerStorageClass(SPIRVTypePointer const *PtrType) { | ||
assert(PtrType && "Must be valid pointer type."); | ||
|
||
if (PtrType->getPointerElementType()->getOpCode() == OpTypeFunction) { | ||
auto *M = PtrType->getModule(); | ||
if (M->hasProgramAddressSpace()) | ||
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. It seems to me, that any function in the module will have the set address space, which seems incorrect to me (just consider such artificial example:
how backend will consider addrspace(3) ? 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. If the function had addrspace before the translation the current translator will preserve AS on a pointer but will lose it on the function itself, which will result in an error during the compilation. To some extend this options saves us. Though fixing the current function pointer implementation first is a nice idea too. There's CodeSectionINTEL storage class but it is never used and it is not clear what LLVM IR addrspace should it correspond. |
||
return M->getProgramAddressSpace(); | ||
} | ||
|
||
return SPIRSPIRVAddrSpaceMap::rmap(PtrType->getPointerStorageClass()); | ||
} | ||
|
||
Type *SPIRVToLLVM::transType(SPIRVType *T, bool IsClassMember) { | ||
auto Loc = TypeMap.find(T); | ||
if (Loc != TypeMap.end()) | ||
|
@@ -385,7 +397,7 @@ Type *SPIRVToLLVM::transType(SPIRVType *T, bool IsClassMember) { | |
return mapType( | ||
T, PointerType::get( | ||
transType(T->getPointerElementType(), IsClassMember), | ||
SPIRSPIRVAddrSpaceMap::rmap(T->getPointerStorageClass()))); | ||
transPointerStorageClass(static_cast<SPIRVTypePointer *>(T)))); | ||
case OpTypeVector: | ||
return mapType(T, | ||
FixedVectorType::get(transType(T->getVectorComponentType()), | ||
|
@@ -3244,15 +3256,23 @@ bool SPIRVToLLVM::translate() { | |
return true; | ||
} | ||
|
||
static std::string transDataLayout(SPIRVModule *M, | ||
std::string const &GeneralLayout) { | ||
return M->hasProgramAddressSpace() | ||
? GeneralLayout + "-P" + | ||
std::to_string(M->getProgramAddressSpace()) | ||
: GeneralLayout; | ||
} | ||
|
||
bool SPIRVToLLVM::transAddressingModel() { | ||
switch (BM->getAddressingModel()) { | ||
case AddressingModelPhysical64: | ||
M->setTargetTriple(SPIR_TARGETTRIPLE64); | ||
M->setDataLayout(SPIR_DATALAYOUT64); | ||
M->setDataLayout(transDataLayout(BM, SPIR_DATALAYOUT64)); | ||
break; | ||
case AddressingModelPhysical32: | ||
M->setTargetTriple(SPIR_TARGETTRIPLE32); | ||
M->setDataLayout(SPIR_DATALAYOUT32); | ||
M->setDataLayout(transDataLayout(BM, SPIR_DATALAYOUT32)); | ||
break; | ||
case AddressingModelLogical: | ||
// Do not set target triple and data layout | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
; RUN: llvm-as %s -o %t.bc | ||
; RUN: llvm-spirv %t.bc -o %t.spv --spirv-ext=+SPV_INTEL_function_pointers | ||
; RUN: llvm-spirv -r %t.spv -o %t.bc --override-program-address-space=3 | ||
; RUN: llvm-dis %t.bc -o %t.ll | ||
; RUN: FileCheck %s --input-file %t.ll | ||
|
||
; ModuleID = 'tmp_back.bc' | ||
; CHECK: target datalayout | ||
; CHECK-SAME: P3 | ||
|
||
target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v16:16:16-v24:32:32-v32:32:32-v48:64:64-v64:64:64-v96:128:128-v128:128:128-v192:256:256-v256:256:256-v512:512:512-v1024:1024:1024" | ||
target triple = "spir-unknown-unknown" | ||
|
||
; CHECK: @test | ||
; CHECK-SAME: addrspace(3) | ||
; CHECK: %p | ||
; CHECK-SAME: addrspace(3) | ||
|
||
define spir_kernel void @test() { | ||
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. Could you also check the case with function pointers? Will they end up in the correct namespace? 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. As I've inspected, pointers' address spaces are translated directly into StorageClass and back. So, this information is already preserved by translator |
||
entry: | ||
%p = alloca void () *, align 8 | ||
store void () * @test, void () ** %p, align 8 | ||
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.