Skip to content

Commit

Permalink
Initial support for SPIR-V calling convention.
Browse files Browse the repository at this point in the history
  • Loading branch information
elliottslaughter committed Nov 21, 2023
1 parent 4d32a10 commit c7665ee
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/tcompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -762,34 +762,36 @@ struct CCallingConv {
lua_State *L;
terra_CompilerState *C;
Types *Ty;
bool pass_struct_as_exploded_values;
bool return_empty_struct_as_void;
bool wasm_cconv;
bool aarch64_cconv;
bool amdgpu_cconv;
bool ppc64_cconv;
int ppc64_float_limit;
int ppc64_int_limit;
bool ppc64_count_used;
bool spirv_cconv;
bool wasm_cconv;

CCallingConv(TerraCompilationUnit *CU_, Types *Ty_)
: CU(CU_),
T(CU_->T),
L(CU_->T->L),
C(CU_->T->C),
Ty(Ty_),
pass_struct_as_exploded_values(false),
return_empty_struct_as_void(false),
wasm_cconv(false),
aarch64_cconv(false),
amdgpu_cconv(false),
ppc64_cconv(false),
ppc64_float_limit(0),
ppc64_int_limit(0),
ppc64_count_used(false) {
ppc64_count_used(false),
spirv_cconv(false),
wasm_cconv(false) {
auto Triple = CU->TT->tm->getTargetTriple();
switch (Triple.getArch()) {
case Triple::ArchType::amdgcn: {
return_empty_struct_as_void = true;
pass_struct_as_exploded_values = true;
amdgpu_cconv = true;
} break;
case Triple::ArchType::aarch64:
case Triple::ArchType::aarch64_be: {
Expand All @@ -806,6 +808,10 @@ struct CCallingConv {
ppc64_int_limit = 8;
ppc64_count_used = true;
} break;
case Triple::ArchType::spirv32:
case Triple::ArchType::spirv64: {
spirv_cconv = true;
} break;
case Triple::ArchType::wasm32:
case Triple::ArchType::wasm64: {
wasm_cconv = true;
Expand Down Expand Up @@ -1088,11 +1094,11 @@ struct CCallingConv {
return Argument(C_PRIMITIVE, t, usei1 ? Type::getInt1Ty(*CU->TT->ctx) : NULL);
}

if (wasm_cconv && !WasmIsSingletonOrEmpty(t->type)) {
if ((wasm_cconv && !WasmIsSingletonOrEmpty(t->type)) || spirv_cconv) {
return Argument(C_AGGREGATE_MEM, t);
}

if (pass_struct_as_exploded_values) {
if (amdgpu_cconv) {
return Argument(C_AGGREGATE_REG, t, t->type);
}

Expand Down

0 comments on commit c7665ee

Please sign in to comment.