Skip to content

Commit

Permalink
Fix C calling convention in AArch64 for large structs (#595)
Browse files Browse the repository at this point in the history
  • Loading branch information
elliottslaughter authored Aug 5, 2022
1 parent a32cae6 commit dcd2eff
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
12 changes: 11 additions & 1 deletion src/tcompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1213,6 +1213,12 @@ struct CCallingConv {
r->addParamAttr(idx - 1, Attribute::ByVal);
#else
r->addParamAttr(idx - 1, Attribute::getWithByValType(*CU->TT->ctx, ty));
#endif
}
template <typename FnOrCall>
void addNoUndefAttr(FnOrCall *r, int idx) {
#if LLVM_VERSION >= 110
r->addParamAttr(idx - 1, Attribute::NoUndef);
#endif
}
template <typename FnOrCall>
Expand Down Expand Up @@ -1248,7 +1254,11 @@ struct CCallingConv {
Argument *v = &info->paramtypes[i];
if (v->kind == C_AGGREGATE_MEM) {
#ifndef _WIN32
addByValAttr(r, argidx, v->cctype);
if (!aarch64_cconv) {
addByValAttr(r, argidx, v->cctype);
} else {
addNoUndefAttr(r, argidx);
}
#endif
}
addExtAttrIfNeeded(v->type, r, argidx);
Expand Down
1 change: 1 addition & 0 deletions tests/cconv_array.t
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ local function run_test_case(typ, N)
end
return x
end
callee:setinlined(false)

local args = terralib.newlist()
for i = 1, N do
Expand Down
16 changes: 9 additions & 7 deletions tests/cconv_more.t
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,10 @@ local function generate_nonuniform_struct(name, types, N)
return parts:concat(" ")
end

local noinline = "__attribute__ ((noinline)) "

local function generate_void_function(name)
return "void " .. name .. "() {}"
return noinline .. "void " .. name .. "() {}"
end

local function generate_scalar_exprs(argname, typ, exprlist)
Expand All @@ -126,7 +128,7 @@ local function generate_uniform_scalar_function(name, typ, N)
for i = 1, N do
generate_scalar_exprs("x" .. i, typ, exprlist)
end
return lookup_scalar_base(typ) .. " " .. name .. N .. "(" .. arglist:concat(", ") .. ") { return " .. exprlist:concat(" + ") .. "; }"
return noinline .. lookup_scalar_base(typ) .. " " .. name .. N .. "(" .. arglist:concat(", ") .. ") { return " .. exprlist:concat(" + ") .. "; }"
end

local function generate_nonuniform_scalar_function(name, types, N)
Expand All @@ -140,7 +142,7 @@ local function generate_nonuniform_scalar_function(name, types, N)
local typ = get_type_in_rotation(types, i)
generate_scalar_exprs("x" .. i, typ, exprlist)
end
return "double " .. name .. N .. "(" .. arglist:concat(", ") .. ") { return " .. exprlist:concat(" + ") .. "; }"
return noinline .. "double " .. name .. N .. "(" .. arglist:concat(", ") .. ") { return " .. exprlist:concat(" + ") .. "; }"
end

local function generate_aggregate_one_field_stat(field, inc, typ, statlist)
Expand All @@ -158,7 +160,7 @@ local function generate_uniform_aggregate_one_arg_function(name, aggname, typ, N
for i = 1, N do
generate_aggregate_one_field_stat("x.f" .. i, i, typ, statlist)
end
return aggname .. N .. " " .. name .. N .. "(" .. aggname .. N .. " x) { " .. statlist:concat(" ") .. " return x; }"
return noinline .. aggname .. N .. " " .. name .. N .. "(" .. aggname .. N .. " x) { " .. statlist:concat(" ") .. " return x; }"
end

local function generate_nonuniform_aggregate_one_arg_function(name, aggname, types, N)
Expand All @@ -167,7 +169,7 @@ local function generate_nonuniform_aggregate_one_arg_function(name, aggname, typ
local typ = get_type_in_rotation(types, i)
generate_aggregate_one_field_stat("x.f" .. i, i, typ, statlist)
end
return aggname .. N .. " " .. name .. N .. "(" .. aggname .. N .. " x) { " .. statlist:concat(" ") .. " return x; }"
return noinline .. aggname .. N .. " " .. name .. N .. "(" .. aggname .. N .. " x) { " .. statlist:concat(" ") .. " return x; }"
end

local function generate_aggregate_two_field_stat(field1, field2, typ, statlist)
Expand All @@ -185,7 +187,7 @@ local function generate_uniform_aggregate_two_arg_function(name, aggname, typ, N
for i = 1, N do
generate_aggregate_two_field_stat("x.f" .. i, "y.f" .. i, typ, statlist)
end
return aggname .. N .. " " .. name .. N .. "(" .. aggname .. N .. " x, " .. aggname .. N .. " y) { " .. statlist:concat(" ") .. " return x; }"
return noinline .. aggname .. N .. " " .. name .. N .. "(" .. aggname .. N .. " x, " .. aggname .. N .. " y) { " .. statlist:concat(" ") .. " return x; }"
end

local function generate_nonuniform_aggregate_two_arg_function(name, aggname, types, N)
Expand All @@ -194,7 +196,7 @@ local function generate_nonuniform_aggregate_two_arg_function(name, aggname, typ
local typ = get_type_in_rotation(types, i)
generate_aggregate_two_field_stat("x.f" .. i, "y.f" .. i, typ, statlist)
end
return aggname .. N .. " " .. name .. N .. "(" .. aggname .. N .. " x, " .. aggname .. N .. " y) { " .. statlist:concat(" ") .. " return x; }"
return noinline .. aggname .. N .. " " .. name .. N .. "(" .. aggname .. N .. " x, " .. aggname .. N .. " y) { " .. statlist:concat(" ") .. " return x; }"
end

local base_types = {uint8, int16, int32, int64, float, double}
Expand Down

0 comments on commit dcd2eff

Please sign in to comment.