Skip to content

Commit 82ff676

Browse files
committed
[clang][SPIRV] Set program address space for Intel-flavored SPIR-V
Signed-off-by: Sarnie, Nick <[email protected]>
1 parent 6a5cb5a commit 82ff676

File tree

5 files changed

+22
-4
lines changed

5 files changed

+22
-4
lines changed

clang/lib/Basic/Targets.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,8 @@ std::unique_ptr<TargetInfo> AllocateTarget(const llvm::Triple &Triple,
683683
return std::make_unique<SPIRV64AMDGCNTargetInfo>(Triple, Opts);
684684
return nullptr;
685685
}
686+
if (Triple.getVendor() == llvm::Triple::Intel)
687+
return std::make_unique<SPIRV64IntelTargetInfo>(Triple, Opts);
686688
return std::make_unique<SPIRV64TargetInfo>(Triple, Opts);
687689
}
688690
case llvm::Triple::wasm32:

clang/lib/Basic/Targets/SPIR.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,17 @@ class LLVM_LIBRARY_VISIBILITY SPIRV64AMDGCNTargetInfo final
469469
bool hasInt128Type() const override { return TargetInfo::hasInt128Type(); }
470470
};
471471

472+
class LLVM_LIBRARY_VISIBILITY SPIRV64IntelTargetInfo final
473+
: public SPIRV64TargetInfo {
474+
public:
475+
SPIRV64IntelTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
476+
: SPIRV64TargetInfo(Triple, Opts) {
477+
assert(Triple.getVendor() == llvm::Triple::VendorType::Intel &&
478+
"64-bit Intel SPIR-V target must use Intel vendor");
479+
resetDataLayout("e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-"
480+
"v256:256-v512:512-v1024:1024-n8:16:32:64-G1-P4-A0");
481+
}
482+
};
472483
} // namespace targets
473484
} // namespace clang
474485
#endif // LLVM_CLANG_LIB_BASIC_TARGETS_SPIR_H

clang/test/CodeGenSPIRV/spirv-intel.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
// RUN: %clang_cc1 -triple spirv64-intel %s -emit-llvm -o - | FileCheck -check-prefix=CHECK-WITH %s
2-
// RUN: %clang_cc1 -triple spirv32-intel %s -emit-llvm -o - | FileCheck -check-prefix=CHECK-WITH %s
1+
// RUN: %clang_cc1 -triple spirv64-intel %s -emit-llvm -o - | FileCheck -check-prefix=CHECK-WITH-64 %s
2+
// RUN: %clang_cc1 -triple spirv32-intel %s -emit-llvm -o - | FileCheck -check-prefix=CHECK-WITH-32 %s
33
// RUN: %clang_cc1 -triple spir-intel %s -emit-llvm -o - | FileCheck -check-prefix=CHECK-WITHOUT %s
44
// RUN: %clang_cc1 -triple spir64-intel %s -emit-llvm -o - | FileCheck -check-prefix=CHECK-WITHOUT %s
55

6-
// CHECK-WITH: spir_func void @foo(ptr addrspace(4) noundef %param) #0 {
6+
// CHECK-WITH-64: spir_func void @foo(ptr addrspace(4) noundef %param) addrspace(4) #0 {
7+
// CHECK-WITH-32: spir_func void @foo(ptr addrspace(4) noundef %param) #0 {
8+
79
// CHECK-WITHOUT: spir_func void @foo(ptr noundef %param) #0 {
810
void foo(int *param) {
911
}

clang/test/OpenMP/spirv_variant_match.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ int foo() { return 1; }
3535

3636
// CHECK-DAG: define{{.*}} @{{"_Z[0-9]+foo\$ompvariant\$.*"}}()
3737

38-
// CHECK-DAG: call spir_func noundef i32 @{{"_Z[0-9]+foo\$ompvariant\$.*"}}()
38+
// CHECK-DAG: call spir_func noundef addrspace(4) i32 @{{"_Z[0-9]+foo\$ompvariant\$.*"}}()
3939

4040
int main() {
4141
int res;

llvm/lib/Target/SPIRV/SPIRVTargetMachine.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ static std::string computeDataLayout(const Triple &TT) {
7777
TT.getOS() == Triple::OSType::AMDHSA)
7878
return "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-"
7979
"v512:512-v1024:1024-n32:64-S32-G1-P4-A0";
80+
if (TT.getVendor() == Triple::VendorType::Intel)
81+
return "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-"
82+
"v512:512-v1024:1024-n8:16:32:64-G1-P4-A0";
8083
return "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-"
8184
"v512:512-v1024:1024-n8:16:32:64-G1";
8285
}

0 commit comments

Comments
 (0)