Skip to content

Commit a202b89

Browse files
committed
Revert "[mono][wasm] Fix the passing/returning of small vtypes. (dotnet#62299)"
This reverts commit 915ee6d. This causes test failures in the System.Collections.Immutable testsuite on wasm.
1 parent fedf64f commit a202b89

File tree

3 files changed

+8
-100
lines changed

3 files changed

+8
-100
lines changed

src/mono/mono/mini/mini-llvm.c

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1568,10 +1568,6 @@ sig_to_llvm_sig_full (EmitContext *ctx, MonoMethodSignature *sig, LLVMCallInfo *
15681568
vretaddr = TRUE;
15691569
ret_type = LLVMVoidType ();
15701570
break;
1571-
case LLVMArgWasmVtypeAsScalar:
1572-
g_assert (cinfo->ret.esize);
1573-
ret_type = LLVMIntType (cinfo->ret.esize * 8);
1574-
break;
15751571
default:
15761572
break;
15771573
}
@@ -1689,10 +1685,6 @@ sig_to_llvm_sig_full (EmitContext *ctx, MonoMethodSignature *sig, LLVMCallInfo *
16891685
case LLVMArgVtypeAsScalar:
16901686
g_assert_not_reached ();
16911687
break;
1692-
case LLVMArgWasmVtypeAsScalar:
1693-
g_assert (ainfo->esize);
1694-
param_types [pindex ++] = LLVMIntType (ainfo->esize * 8);
1695-
break;
16961688
case LLVMArgGsharedvtFixed:
16971689
case LLVMArgGsharedvtFixedVtype:
16981690
param_types [pindex ++] = LLVMPointerType (type_to_llvm_arg_type (ctx, ainfo->type), 0);
@@ -3833,7 +3825,6 @@ emit_entry_bb (EmitContext *ctx, LLVMBuilderRef builder)
38333825
char *name;
38343826

38353827
pindex = ainfo->pindex;
3836-
LLVMValueRef arg = LLVMGetParam (ctx->lmethod, pindex);
38373828

38383829
switch (ainfo->storage) {
38393830
case LLVMArgVtypeInReg:
@@ -3892,16 +3883,6 @@ emit_entry_bb (EmitContext *ctx, LLVMBuilderRef builder)
38923883
case LLVMArgVtypeAsScalar:
38933884
g_assert_not_reached ();
38943885
break;
3895-
case LLVMArgWasmVtypeAsScalar: {
3896-
MonoType *t = mini_get_underlying_type (ainfo->type);
3897-
3898-
/* The argument is received as a scalar */
3899-
ctx->addresses [reg] = build_alloca (ctx, t);
3900-
3901-
LLVMValueRef dest = convert (ctx, ctx->addresses [reg], LLVMPointerType (LLVMIntType (ainfo->esize * 8), 0));
3902-
LLVMBuildStore (ctx->builder, arg, dest);
3903-
break;
3904-
}
39053886
case LLVMArgGsharedvtFixed: {
39063887
/* These are non-gsharedvt arguments passed by ref, the rest of the IR treats them as scalars */
39073888
LLVMValueRef arg = LLVMGetParam (ctx->lmethod, pindex);
@@ -4435,10 +4416,6 @@ process_call (EmitContext *ctx, MonoBasicBlock *bb, LLVMBuilderRef *builder_ref,
44354416
case LLVMArgVtypeAsScalar:
44364417
g_assert_not_reached ();
44374418
break;
4438-
case LLVMArgWasmVtypeAsScalar:
4439-
g_assert (addresses [reg]);
4440-
args [pindex] = LLVMBuildLoad (ctx->builder, convert (ctx, addresses [reg], LLVMPointerType (LLVMIntType (ainfo->esize * 8), 0)), "");
4441-
break;
44424419
case LLVMArgGsharedvtFixed:
44434420
case LLVMArgGsharedvtFixedVtype:
44444421
g_assert (addresses [reg]);
@@ -4588,11 +4565,6 @@ process_call (EmitContext *ctx, MonoBasicBlock *bb, LLVMBuilderRef *builder_ref,
45884565
case LLVMArgGsharedvtFixedVtype:
45894566
values [ins->dreg] = LLVMBuildLoad (builder, convert_full (ctx, addresses [call->inst.dreg], LLVMPointerType (type_to_llvm_type (ctx, sig->ret), 0), FALSE), "");
45904567
break;
4591-
case LLVMArgWasmVtypeAsScalar:
4592-
if (!addresses [call->inst.dreg])
4593-
addresses [call->inst.dreg] = build_alloca (ctx, sig->ret);
4594-
LLVMBuildStore (builder, lcall, convert_full (ctx, addresses [call->inst.dreg], LLVMPointerType (LLVMTypeOf (lcall), 0), FALSE));
4595-
break;
45964568
default:
45974569
if (sig->ret->type != MONO_TYPE_VOID)
45984570
/* If the method returns an unsigned value, need to zext it */
@@ -5719,8 +5691,7 @@ process_bb (EmitContext *ctx, MonoBasicBlock *bb)
57195691
switch (linfo->ret.storage) {
57205692
case LLVMArgNormal:
57215693
case LLVMArgVtypeInReg:
5722-
case LLVMArgVtypeAsScalar:
5723-
case LLVMArgWasmVtypeAsScalar: {
5694+
case LLVMArgVtypeAsScalar: {
57245695
LLVMTypeRef ret_type = LLVMGetReturnType (LLVMGetElementType (LLVMTypeOf (method)));
57255696
LLVMValueRef retval = LLVMGetUndef (ret_type);
57265697
gboolean src_in_reg = FALSE;
@@ -5777,10 +5748,6 @@ process_bb (EmitContext *ctx, MonoBasicBlock *bb)
57775748
retval = LLVMBuildLoad (builder, LLVMBuildBitCast (builder, addresses [ins->sreg1], LLVMPointerType (ret_type, 0), ""), "");
57785749
}
57795750
break;
5780-
case LLVMArgWasmVtypeAsScalar:
5781-
g_assert (addresses [ins->sreg1]);
5782-
retval = LLVMBuildLoad (builder, LLVMBuildBitCast (builder, addresses [ins->sreg1], LLVMPointerType (ret_type, 0), ""), "");
5783-
break;
57845751
}
57855752
LLVMBuildRet (builder, retval);
57865753
break;
@@ -12196,7 +12163,6 @@ mono_llvm_emit_call (MonoCompile *cfg, MonoCallInst *call)
1219612163
case LLVMArgGsharedvtVariable:
1219712164
case LLVMArgGsharedvtFixed:
1219812165
case LLVMArgGsharedvtFixedVtype:
12199-
case LLVMArgWasmVtypeAsScalar:
1220012166
MONO_INST_NEW (cfg, ins, OP_LLVM_OUTARG_VT);
1220112167
ins->dreg = mono_alloc_ireg (cfg);
1220212168
ins->sreg1 = in->dreg;

src/mono/mono/mini/mini-wasm.c

Lines changed: 6 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,11 @@ typedef enum {
2323
ArgValuetypeAddrOnStack,
2424
ArgGsharedVTOnStack,
2525
ArgValuetypeAddrInIReg,
26-
ArgVtypeAsScalar,
2726
ArgInvalid,
2827
} ArgStorage;
2928

3029
typedef struct {
3130
ArgStorage storage : 8;
32-
MonoType *type;
3331
} ArgInfo;
3432

3533
struct CallInfo {
@@ -40,45 +38,6 @@ struct CallInfo {
4038
ArgInfo args [1];
4139
};
4240

43-
/* Return whenever TYPE represents a vtype with only one scalar member */
44-
static gboolean
45-
is_scalar_vtype (MonoType *type)
46-
{
47-
MonoClass *klass;
48-
MonoClassField *field;
49-
gpointer iter;
50-
51-
if (!MONO_TYPE_ISSTRUCT (type))
52-
return FALSE;
53-
klass = mono_class_from_mono_type_internal (type);
54-
mono_class_init_internal (klass);
55-
56-
int size = mono_class_value_size (klass, NULL);
57-
if (size == 0 || size >= 8)
58-
return FALSE;
59-
60-
iter = NULL;
61-
int nfields = 0;
62-
field = NULL;
63-
while ((field = mono_class_get_fields_internal (klass, &iter))) {
64-
if (field->type->attrs & FIELD_ATTRIBUTE_STATIC)
65-
continue;
66-
nfields ++;
67-
if (nfields > 1)
68-
return FALSE;
69-
if (MONO_TYPE_ISSTRUCT (field->type)) {
70-
if (!is_scalar_vtype (field->type))
71-
return FALSE;
72-
} else if (!((MONO_TYPE_IS_PRIMITIVE (field->type) || MONO_TYPE_IS_REFERENCE (field->type)))) {
73-
return FALSE;
74-
}
75-
}
76-
77-
return TRUE;
78-
}
79-
80-
// WASM ABI: https://github.com/WebAssembly/tool-conventions/blob/main/BasicCABI.md
81-
8241
static ArgStorage
8342
get_storage (MonoType *type, gboolean is_return)
8443
{
@@ -116,14 +75,14 @@ get_storage (MonoType *type, gboolean is_return)
11675
/* fall through */
11776
case MONO_TYPE_VALUETYPE:
11877
case MONO_TYPE_TYPEDBYREF: {
119-
if (is_scalar_vtype (type))
120-
return ArgVtypeAsScalar;
12178
return is_return ? ArgValuetypeAddrInIReg : ArgValuetypeAddrOnStack;
79+
break;
12280
}
12381
case MONO_TYPE_VAR:
12482
case MONO_TYPE_MVAR:
12583
g_assert (mini_is_gsharedvt_type (type));
12684
return ArgGsharedVTOnStack;
85+
break;
12786
case MONO_TYPE_VOID:
12887
g_assert (is_return);
12988
break;
@@ -148,8 +107,7 @@ get_call_info (MonoMemPool *mp, MonoMethodSignature *sig)
148107
cinfo->gsharedvt = mini_is_gsharedvt_variable_signature (sig);
149108

150109
/* return value */
151-
cinfo->ret.type = mini_get_underlying_type (sig->ret);
152-
cinfo->ret.storage = get_storage (cinfo->ret.type, TRUE);
110+
cinfo->ret.storage = get_storage (mini_get_underlying_type (sig->ret), TRUE);
153111

154112
if (sig->hasthis)
155113
cinfo->args [0].storage = ArgOnStack;
@@ -158,10 +116,8 @@ get_call_info (MonoMemPool *mp, MonoMethodSignature *sig)
158116
g_assert (sig->call_convention != MONO_CALL_VARARG);
159117

160118
int i;
161-
for (i = 0; i < sig->param_count; ++i) {
162-
cinfo->args [i + sig->hasthis].type = mini_get_underlying_type (sig->params [i]);
163-
cinfo->args [i + sig->hasthis].storage = get_storage (cinfo->args [i + sig->hasthis].type, FALSE);
164-
}
119+
for (i = 0; i < sig->param_count; ++i)
120+
cinfo->args [i + sig->hasthis].storage = get_storage (mini_get_underlying_type (sig->params [i]), FALSE);
165121

166122
return cinfo;
167123
}
@@ -348,10 +304,7 @@ mono_arch_get_llvm_call_info (MonoCompile *cfg, MonoMethodSignature *sig)
348304

349305
linfo = mono_mempool_alloc0 (cfg->mempool, sizeof (LLVMCallInfo) + (sizeof (LLVMArgInfo) * n));
350306

351-
if (cinfo->ret.storage == ArgVtypeAsScalar) {
352-
linfo->ret.storage = LLVMArgWasmVtypeAsScalar;
353-
linfo->ret.esize = mono_class_value_size (mono_class_from_mono_type_internal (cinfo->ret.type), NULL);
354-
} else if (mini_type_is_vtype (sig->ret)) {
307+
if (mini_type_is_vtype (sig->ret)) {
355308
/* Vtype returned using a hidden argument */
356309
linfo->ret.storage = LLVMArgVtypeRetAddr;
357310
// linfo->vret_arg_index = cinfo->vret_arg_index;
@@ -373,11 +326,6 @@ mono_arch_get_llvm_call_info (MonoCompile *cfg, MonoMethodSignature *sig)
373326
case ArgGsharedVTOnStack:
374327
linfo->args [i].storage = LLVMArgGsharedvtVariable;
375328
break;
376-
case ArgVtypeAsScalar:
377-
linfo->args [i].storage = LLVMArgWasmVtypeAsScalar;
378-
linfo->args [i].type = ainfo->type;
379-
linfo->args [i].esize = mono_class_value_size (mono_class_from_mono_type_internal (ainfo->type), NULL);
380-
break;
381329
case ArgValuetypeAddrInIReg:
382330
g_error ("this is only valid for sig->ret");
383331
break;

src/mono/mono/mini/mini.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -667,13 +667,7 @@ typedef enum {
667667
/* Vtype returned as an int */
668668
LLVMArgVtypeAsScalar,
669669
/* Address to local vtype passed as argument (using register or stack). */
670-
LLVMArgVtypeAddr,
671-
/*
672-
* On WASM, a one element vtype is passed/returned as a scalar with the same
673-
* type as the element.
674-
* esize is the size of the value.
675-
*/
676-
LLVMArgWasmVtypeAsScalar
670+
LLVMArgVtypeAddr
677671
} LLVMArgStorage;
678672

679673
typedef struct {

0 commit comments

Comments
 (0)