mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-04-30 15:10:59 +03:00
Refactoring: Introduce TargetABI::reverseExplicitParams()
This commit is contained in:
parent
92913d4c08
commit
29d609d63d
13 changed files with 19 additions and 47 deletions
|
@ -57,12 +57,6 @@ struct AArch64TargetABI : TargetABI {
|
||||||
if (!arg->byref)
|
if (!arg->byref)
|
||||||
rewriteArgument(fty, *arg);
|
rewriteArgument(fty, *arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
// extern(D): reverse parameter order for non variadics, for DMD-compliance
|
|
||||||
if (fty.type->linkage == LINKd && fty.type->varargs != 1 &&
|
|
||||||
fty.args.size() > 1) {
|
|
||||||
fty.reverseParams = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void rewriteArgument(IrFuncTy &fty, IrFuncTyArg &arg) override {
|
void rewriteArgument(IrFuncTy &fty, IrFuncTyArg &arg) override {
|
||||||
|
|
|
@ -84,12 +84,6 @@ struct ArmTargetABI : TargetABI {
|
||||||
if (!arg->byref)
|
if (!arg->byref)
|
||||||
rewriteArgument(fty, *arg);
|
rewriteArgument(fty, *arg);
|
||||||
}
|
}
|
||||||
|
|
||||||
// extern(D): reverse parameter order for non variadics, for DMD-compliance
|
|
||||||
if (fty.type->linkage == LINKd && fty.type->varargs != 1 &&
|
|
||||||
fty.args.size() > 1) {
|
|
||||||
fty.reverseParams = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void rewriteArgument(IrFuncTy &fty, IrFuncTyArg &arg) override {
|
void rewriteArgument(IrFuncTy &fty, IrFuncTyArg &arg) override {
|
||||||
|
|
|
@ -57,12 +57,6 @@ struct MIPS64TargetABI : TargetABI {
|
||||||
rewriteArgument(fty, *arg);
|
rewriteArgument(fty, *arg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// extern(D): reverse parameter order for non variadics, for DMD-compliance
|
|
||||||
if (fty.type->linkage == LINKd && fty.type->varargs != 1 &&
|
|
||||||
fty.args.size() > 1) {
|
|
||||||
fty.reverseParams = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void rewriteArgument(IrFuncTy &fty, IrFuncTyArg &arg) override {
|
void rewriteArgument(IrFuncTy &fty, IrFuncTyArg &arg) override {
|
||||||
|
|
|
@ -28,6 +28,7 @@ struct NVPTXTargetABI : TargetABI {
|
||||||
t = t->toBasetype();
|
t = t->toBasetype();
|
||||||
return ((t->ty == Tsarray || t->ty == Tstruct) && t->size() > 64);
|
return ((t->ty == Tsarray || t->ty == Tstruct) && t->size() > 64);
|
||||||
}
|
}
|
||||||
|
bool reverseExplicitParams(TypeFunction *) override { return false; }
|
||||||
void rewriteFunctionType(IrFuncTy &fty) override {
|
void rewriteFunctionType(IrFuncTy &fty) override {
|
||||||
for (auto arg : fty.args) {
|
for (auto arg : fty.args) {
|
||||||
if (!arg->byref)
|
if (!arg->byref)
|
||||||
|
|
|
@ -70,12 +70,6 @@ struct PPCTargetABI : TargetABI {
|
||||||
rewriteArgument(fty, *arg);
|
rewriteArgument(fty, *arg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// extern(D): reverse parameter order for non variadics, for DMD-compliance
|
|
||||||
if (fty.type->linkage == LINKd && fty.type->varargs != 1 &&
|
|
||||||
fty.args.size() > 1) {
|
|
||||||
fty.reverseParams = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void rewriteArgument(IrFuncTy &fty, IrFuncTyArg &arg) override {
|
void rewriteArgument(IrFuncTy &fty, IrFuncTyArg &arg) override {
|
||||||
|
|
|
@ -59,12 +59,6 @@ struct PPC64LETargetABI : TargetABI {
|
||||||
rewriteArgument(fty, *arg);
|
rewriteArgument(fty, *arg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// extern(D): reverse parameter order for non variadics, for DMD-compliance
|
|
||||||
if (fty.type->linkage == LINKd && fty.type->varargs != 1 &&
|
|
||||||
fty.args.size() > 1) {
|
|
||||||
fty.reverseParams = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void rewriteArgument(IrFuncTy &fty, IrFuncTyArg &arg) override {
|
void rewriteArgument(IrFuncTy &fty, IrFuncTyArg &arg) override {
|
||||||
|
|
|
@ -28,6 +28,7 @@ struct SPIRVTargetABI : TargetABI {
|
||||||
t = t->toBasetype();
|
t = t->toBasetype();
|
||||||
return ((t->ty == Tsarray || t->ty == Tstruct) && t->size() > 64);
|
return ((t->ty == Tsarray || t->ty == Tstruct) && t->size() > 64);
|
||||||
}
|
}
|
||||||
|
bool reverseExplicitParams(TypeFunction *) override { return false; }
|
||||||
void rewriteFunctionType(IrFuncTy &fty) override {
|
void rewriteFunctionType(IrFuncTy &fty) override {
|
||||||
for (auto arg : fty.args) {
|
for (auto arg : fty.args) {
|
||||||
if (!arg->byref)
|
if (!arg->byref)
|
||||||
|
|
|
@ -120,12 +120,6 @@ public:
|
||||||
rewriteArgument(fty, *arg);
|
rewriteArgument(fty, *arg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// extern(D): reverse parameter order for non variadics, for DMD-compliance
|
|
||||||
if (fty.type->linkage == LINKd && fty.type->varargs != 1 &&
|
|
||||||
fty.args.size() > 1) {
|
|
||||||
fty.reverseParams = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void rewriteVarargs(IrFuncTy &fty,
|
void rewriteVarargs(IrFuncTy &fty,
|
||||||
|
|
|
@ -319,12 +319,6 @@ void X86_64TargetABI::rewriteFunctionType(IrFuncTy &fty) {
|
||||||
Logger::println("x86-64 ABI: Transforming argument types");
|
Logger::println("x86-64 ABI: Transforming argument types");
|
||||||
LOG_SCOPE;
|
LOG_SCOPE;
|
||||||
|
|
||||||
// extern(D): reverse parameter order for non variadics, for DMD-compliance
|
|
||||||
if (fty.type->linkage == LINKd && fty.type->varargs != 1 &&
|
|
||||||
fty.args.size() > 1) {
|
|
||||||
fty.reverseParams = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
int begin = 0, end = fty.args.size(), step = 1;
|
int begin = 0, end = fty.args.size(), step = 1;
|
||||||
if (fty.reverseParams) {
|
if (fty.reverseParams) {
|
||||||
begin = end - 1;
|
begin = end - 1;
|
||||||
|
|
|
@ -181,11 +181,6 @@ struct X86TargetABI : TargetABI {
|
||||||
}
|
}
|
||||||
|
|
||||||
// all other arguments are passed on the stack, don't rewrite
|
// all other arguments are passed on the stack, don't rewrite
|
||||||
|
|
||||||
// reverse parameter order
|
|
||||||
if (fty.args.size() > 1) {
|
|
||||||
fty.reverseParams = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
workaroundIssue1356(fty.args);
|
workaroundIssue1356(fty.args);
|
||||||
|
|
10
gen/abi.cpp
10
gen/abi.cpp
|
@ -238,6 +238,14 @@ bool TargetABI::canRewriteAsInt(Type *t, bool include64bit) {
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
bool TargetABI::reverseExplicitParams(TypeFunction *tf) {
|
||||||
|
// Required by druntime for extern(D), except for `, ...`-style variadics.
|
||||||
|
return tf->linkage == LINKd && tf->varargs != 1 &&
|
||||||
|
Parameter::dim(tf->parameters) > 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void TargetABI::rewriteVarargs(IrFuncTy &fty,
|
void TargetABI::rewriteVarargs(IrFuncTy &fty,
|
||||||
std::vector<IrFuncTyArg *> &args) {
|
std::vector<IrFuncTyArg *> &args) {
|
||||||
for (auto arg : args) {
|
for (auto arg : args) {
|
||||||
|
@ -355,6 +363,8 @@ struct IntrinsicABI : TargetABI {
|
||||||
|
|
||||||
bool passByVal(Type *t) override { return false; }
|
bool passByVal(Type *t) override { return false; }
|
||||||
|
|
||||||
|
bool reverseExplicitParams(TypeFunction *) override { return false; }
|
||||||
|
|
||||||
void rewriteArgument(IrFuncTy &fty, IrFuncTyArg &arg) override {
|
void rewriteArgument(IrFuncTy &fty, IrFuncTyArg &arg) override {
|
||||||
Type *ty = arg.type->toBasetype();
|
Type *ty = arg.type->toBasetype();
|
||||||
if (ty->ty != Tstruct) {
|
if (ty->ty != Tstruct) {
|
||||||
|
|
|
@ -143,6 +143,11 @@ struct TargetABI {
|
||||||
/// argument.
|
/// argument.
|
||||||
virtual bool passThisBeforeSret(TypeFunction *tf) { return false; }
|
virtual bool passThisBeforeSret(TypeFunction *tf) { return false; }
|
||||||
|
|
||||||
|
/// Returns true if the explicit parameters order is to be reversed.
|
||||||
|
/// Defaults to true for non-variadic extern(D) functions as required by
|
||||||
|
/// druntime.
|
||||||
|
virtual bool reverseExplicitParams(TypeFunction *tf);
|
||||||
|
|
||||||
/// Called to give ABI the chance to rewrite the types
|
/// Called to give ABI the chance to rewrite the types
|
||||||
virtual void rewriteFunctionType(IrFuncTy &fty) = 0;
|
virtual void rewriteFunctionType(IrFuncTy &fty) = 0;
|
||||||
virtual void rewriteVarargs(IrFuncTy &fty, std::vector<IrFuncTyArg *> &args);
|
virtual void rewriteVarargs(IrFuncTy &fty, std::vector<IrFuncTyArg *> &args);
|
||||||
|
|
|
@ -187,6 +187,8 @@ llvm::FunctionType *DtoFunctionType(Type *type, IrFuncTy &irFty, Type *thistype,
|
||||||
++nextLLArgIdx;
|
++nextLLArgIdx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
newIrFty.reverseParams = abi->reverseExplicitParams(f);
|
||||||
|
|
||||||
// let the ABI rewrite the types as necessary
|
// let the ABI rewrite the types as necessary
|
||||||
abi->rewriteFunctionType(newIrFty);
|
abi->rewriteFunctionType(newIrFty);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue