Skip to content

Commit 1c15a83

Browse files
committed
gen/abi: add initial ABI implementations for s390x
1 parent 1fd551e commit 1c15a83

File tree

3 files changed

+73
-0
lines changed

3 files changed

+73
-0
lines changed

gen/abi/abi.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,8 @@ TargetABI *TargetABI::getTarget() {
281281
case llvm::Triple::wasm32:
282282
case llvm::Triple::wasm64:
283283
return getWasmTargetABI();
284+
case llvm::Triple::systemz:
285+
return getSystemZTargetABI();
284286
default:
285287
warning(Loc(),
286288
"unknown target ABI, falling back to generic implementation. C/C++ "

gen/abi/systemz.cpp

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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(); }

gen/abi/targets.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,5 @@ TargetABI *getX86TargetABI();
4040
TargetABI *getLoongArch64TargetABI();
4141

4242
TargetABI *getWasmTargetABI();
43+
44+
TargetABI *getSystemZTargetABI();

0 commit comments

Comments
 (0)