|
| 1 | +//===-- abi-systemz.cpp |
| 2 | +//-----------------------------------------------------===// |
| 3 | +// |
| 4 | +// LDC - the LLVM D compiler |
| 5 | +// |
| 6 | +// This file is distributed under the BSD-style LDC license. See the LICENSE |
| 7 | +// file for details. |
| 8 | +// |
| 9 | +//===----------------------------------------------------------------------===// |
| 10 | +// |
| 11 | +// The ABI implementation used for 64 bit big-endian IBM Z targets. |
| 12 | +// |
| 13 | +// The IBM s390x ELF ABI can be found here: |
| 14 | +// https://github.com/IBM/s390x-abi |
| 15 | +//===----------------------------------------------------------------------===// |
| 16 | + |
| 17 | +#include "gen/abi/abi.h" |
| 18 | +#include "gen/abi/generic.h" |
| 19 | +#include "gen/dvalue.h" |
| 20 | +#include "gen/irstate.h" |
| 21 | +#include "gen/llvmhelpers.h" |
| 22 | +#include "gen/tollvm.h" |
| 23 | + |
| 24 | +struct SystemZTargetABI : TargetABI { |
| 25 | + IndirectByvalRewrite indirectByvalRewrite{}; |
| 26 | + |
| 27 | + explicit SystemZTargetABI() {} |
| 28 | + |
| 29 | + bool returnInArg(TypeFunction *tf, bool) override { |
| 30 | + if (tf->isref()) { |
| 31 | + return false; |
| 32 | + } |
| 33 | + Type *rt = tf->next->toBasetype(); |
| 34 | + return DtoIsInMemoryOnly(rt); |
| 35 | + } |
| 36 | + |
| 37 | + bool passByVal(TypeFunction *, Type *t) override { |
| 38 | + return DtoIsInMemoryOnly(t); |
| 39 | + } |
| 40 | + |
| 41 | + void rewriteFunctionType(IrFuncTy &fty) override { |
| 42 | + if (!fty.ret->byref) { |
| 43 | + rewriteArgument(fty, *fty.ret); |
| 44 | + } |
| 45 | + |
| 46 | + for (auto arg : fty.args) { |
| 47 | + if (!arg->byref) { |
| 48 | + rewriteArgument(fty, *arg); |
| 49 | + } |
| 50 | + } |
| 51 | + } |
| 52 | + |
| 53 | + void rewriteArgument(IrFuncTy &fty, IrFuncTyArg &arg) override { |
| 54 | + if (!isPOD(arg.type)) { |
| 55 | + // non-PODs should be passed in memory |
| 56 | + indirectByvalRewrite.applyTo(arg); |
| 57 | + return; |
| 58 | + } |
| 59 | + Type *ty = arg.type->toBasetype(); |
| 60 | + // integer types less than 64-bits should be extended to 64 bits |
| 61 | + if (ty->isintegral()) { |
| 62 | + arg.attrs.addAttribute(ty->isunsigned() ? LLAttribute::ZExt |
| 63 | + : LLAttribute::SExt); |
| 64 | + } |
| 65 | + } |
| 66 | +}; |
| 67 | + |
| 68 | +// The public getter for abi.cpp |
| 69 | +TargetABI *getSystemZTargetABI() { return new SystemZTargetABI(); } |
0 commit comments