Skip to content

Commit 4c8495a

Browse files
committed
gen/abi: flatten single float struct to float on s390x
1 parent b6fd4bf commit 4c8495a

File tree

1 file changed

+46
-2
lines changed

1 file changed

+46
-2
lines changed

gen/abi/systemz.cpp

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,45 @@
2525

2626
using namespace dmd;
2727

28+
struct SimpleHardfloatRewrite : ABIRewrite {
29+
Type *getFirstFieldType(Type *ty) {
30+
if (auto ts = ty->toBasetype()->isTypeStruct()) {
31+
assert(ts->sym->fields.size() == 1);
32+
auto *subField = ts->sym->fields[0];
33+
if (subField->type->isfloating()) {
34+
return subField->type;
35+
}
36+
return nullptr;
37+
}
38+
return nullptr;
39+
}
40+
41+
LLValue *put(DValue *dv, bool, bool) override {
42+
const auto flat = getFirstFieldType(dv->type);
43+
LLType *asType = DtoType(flat);
44+
assert(dv->isLVal());
45+
LLValue *flatGEP = DtoGEP1(asType, DtoLVal(dv), 0U);
46+
LLValue *flatValue = DtoLoad(asType, flatGEP, ".HardfloatRewrite_arg");
47+
return flatValue;
48+
}
49+
50+
LLValue *getLVal(Type *dty, LLValue *v) override {
51+
// inverse operation of method "put"
52+
LLValue *insertedValue = DtoInsertValue(llvm::UndefValue::get(DtoType(dty)), v, 0);
53+
return DtoAllocaDump(insertedValue, dty, ".HardfloatRewrite_param_storage");
54+
}
55+
56+
LLType *type(Type *ty) override { return DtoType(getFirstFieldType(ty)); }
57+
58+
bool shouldApplyRewrite(Type *ty) {
59+
if (auto ts = ty->toBasetype()->isTypeStruct()) {
60+
return ts->sym->fields.size() == 1 &&
61+
ts->sym->fields[0]->type->isfloating();
62+
}
63+
return false;
64+
}
65+
};
66+
2867
struct StructSimpleFlattenRewrite : BaseBitcastABIRewrite {
2968
LLType *type(Type *ty) override {
3069
const size_t type_size = size(ty);
@@ -47,6 +86,7 @@ struct StructSimpleFlattenRewrite : BaseBitcastABIRewrite {
4786
struct SystemZTargetABI : TargetABI {
4887
IndirectByvalRewrite indirectByvalRewrite{};
4988
StructSimpleFlattenRewrite structSimpleFlattenRewrite{};
89+
SimpleHardfloatRewrite simpleHardfloatRewrite{};
5090

5191
explicit SystemZTargetABI() {}
5292

@@ -132,8 +172,12 @@ struct SystemZTargetABI : TargetABI {
132172
arg.attrs.addAttribute(ty->isunsigned() ? LLAttribute::ZExt
133173
: LLAttribute::SExt);
134174
}
135-
if (ty->isTypeStruct() && size(ty) <= 8) {
136-
structSimpleFlattenRewrite.applyToIfNotObsolete(arg);
175+
if (ty->isTypeStruct()) {
176+
if (simpleHardfloatRewrite.shouldApplyRewrite(ty)) {
177+
simpleHardfloatRewrite.applyTo(arg);
178+
} else if (size(ty) <= 8) {
179+
structSimpleFlattenRewrite.applyToIfNotObsolete(arg);
180+
}
137181
}
138182
}
139183

0 commit comments

Comments
 (0)