25
25
26
26
using namespace dmd ;
27
27
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
+
28
67
struct StructSimpleFlattenRewrite : BaseBitcastABIRewrite {
29
68
LLType *type (Type *ty) override {
30
69
const size_t type_size = size (ty);
@@ -47,6 +86,7 @@ struct StructSimpleFlattenRewrite : BaseBitcastABIRewrite {
47
86
struct SystemZTargetABI : TargetABI {
48
87
IndirectByvalRewrite indirectByvalRewrite{};
49
88
StructSimpleFlattenRewrite structSimpleFlattenRewrite{};
89
+ SimpleHardfloatRewrite simpleHardfloatRewrite{};
50
90
51
91
explicit SystemZTargetABI () {}
52
92
@@ -132,8 +172,12 @@ struct SystemZTargetABI : TargetABI {
132
172
arg.attrs .addAttribute (ty->isunsigned () ? LLAttribute::ZExt
133
173
: LLAttribute::SExt);
134
174
}
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
+ }
137
181
}
138
182
}
139
183
0 commit comments