mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-28 15:23:51 +00:00
Bug 1229399: Make {Get,Set}{Loc,Glo} opcodes type-independent; r=luke
--HG-- extra : commitid : A6RJy6SJp0Q extra : rebase_source : 37050854ab5f9ec2db39483b90478f1400efe2ba
This commit is contained in:
parent
1e4108d6ec
commit
17b127c966
@ -3408,10 +3408,10 @@ CheckFinalReturn(FunctionValidator& f, ParseNode* lastNonEmptyStmt)
|
||||
}
|
||||
|
||||
static bool
|
||||
SetLocal(FunctionValidator& f, Expr exprStmt, Expr setLocal, NumLit lit)
|
||||
SetLocal(FunctionValidator& f, Expr exprStmt, NumLit lit)
|
||||
{
|
||||
return f.writeOp(exprStmt) &&
|
||||
f.writeOp(setLocal) &&
|
||||
f.writeOp(Expr::SetLocal) &&
|
||||
f.writeU32(f.numLocals()) &&
|
||||
f.writeLit(lit);
|
||||
}
|
||||
@ -3442,32 +3442,32 @@ CheckVariable(FunctionValidator& f, ParseNode* var)
|
||||
case NumLit::Fixnum:
|
||||
case NumLit::NegativeInt:
|
||||
case NumLit::BigUnsigned:
|
||||
if (lit.toInt32() != 0 && !SetLocal(f, Expr::I32Expr, Expr::I32SetLocal, lit))
|
||||
if (lit.toInt32() != 0 && !SetLocal(f, Expr::I32Expr, lit))
|
||||
return false;
|
||||
break;
|
||||
case NumLit::Double:
|
||||
if ((lit.toDouble() != 0.0 || IsNegativeZero(lit.toDouble())) &&
|
||||
!SetLocal(f, Expr::F64Expr, Expr::F64SetLocal, lit))
|
||||
!SetLocal(f, Expr::F64Expr, lit))
|
||||
return false;
|
||||
break;
|
||||
case NumLit::Float:
|
||||
if ((lit.toFloat() != 0.f || !IsNegativeZero(lit.toFloat())) &&
|
||||
!SetLocal(f, Expr::F32Expr, Expr::F32SetLocal, lit))
|
||||
!SetLocal(f, Expr::F32Expr, lit))
|
||||
return false;
|
||||
break;
|
||||
case NumLit::Int32x4:
|
||||
if (lit.simdValue() != SimdConstant::SplatX4(0) &&
|
||||
!SetLocal(f, Expr::I32X4Expr, Expr::I32X4SetLocal, lit))
|
||||
!SetLocal(f, Expr::I32X4Expr, lit))
|
||||
return false;
|
||||
break;
|
||||
case NumLit::Float32x4:
|
||||
if (lit.simdValue() != SimdConstant::SplatX4(0.f) &&
|
||||
!SetLocal(f, Expr::F32X4Expr, Expr::F32X4SetLocal, lit))
|
||||
!SetLocal(f, Expr::F32X4Expr, lit))
|
||||
return false;
|
||||
break;
|
||||
case NumLit::Bool32x4:
|
||||
if (lit.simdValue() != SimdConstant::SplatX4(0) &&
|
||||
!SetLocal(f, Expr::B32X4Expr, Expr::B32X4SetLocal, lit))
|
||||
!SetLocal(f, Expr::B32X4Expr, lit))
|
||||
return false;
|
||||
break;
|
||||
case NumLit::OutOfRangeInt:
|
||||
@ -3512,15 +3512,9 @@ CheckVarRef(FunctionValidator& f, ParseNode* varRef, Type* type)
|
||||
PropertyName* name = varRef->name();
|
||||
|
||||
if (const FunctionValidator::Local* local = f.lookupLocal(name)) {
|
||||
switch (local->type) {
|
||||
case ValType::I32: if (!f.writeOp(Expr::I32GetLocal)) return false; break;
|
||||
case ValType::I64: MOZ_CRASH("no int64 in asm.js");
|
||||
case ValType::F32: if (!f.writeOp(Expr::F32GetLocal)) return false; break;
|
||||
case ValType::F64: if (!f.writeOp(Expr::F64GetLocal)) return false; break;
|
||||
case ValType::I32x4: if (!f.writeOp(Expr::I32X4GetLocal)) return false; break;
|
||||
case ValType::F32x4: if (!f.writeOp(Expr::F32X4GetLocal)) return false; break;
|
||||
case ValType::B32x4: if (!f.writeOp(Expr::B32X4GetLocal)) return false; break;
|
||||
}
|
||||
if (!f.writeOp(Expr::GetLocal))
|
||||
return false;
|
||||
MOZ_ASSERT(local->type != ValType::I64, "no int64 in asm.js");
|
||||
if (!f.writeU32(local->slot))
|
||||
return false;
|
||||
*type = Type::var(local->type);
|
||||
@ -3535,18 +3529,9 @@ CheckVarRef(FunctionValidator& f, ParseNode* varRef, Type* type)
|
||||
case ModuleValidator::Global::ConstantImport:
|
||||
case ModuleValidator::Global::Variable: {
|
||||
*type = global->varOrConstType();
|
||||
switch (type->which()) {
|
||||
case Type::Int: if (!f.writeOp(Expr::I32GetGlobal)) return false; break;
|
||||
case Type::Double: if (!f.writeOp(Expr::F64GetGlobal)) return false; break;
|
||||
case Type::Float: if (!f.writeOp(Expr::F32GetGlobal)) return false; break;
|
||||
case Type::Int32x4: if (!f.writeOp(Expr::I32X4GetGlobal)) return false; break;
|
||||
case Type::Float32x4: if (!f.writeOp(Expr::F32X4GetGlobal)) return false; break;
|
||||
case Type::Bool32x4: if (!f.writeOp(Expr::B32X4GetGlobal)) return false; break;
|
||||
default: MOZ_CRASH("unexpected global type");
|
||||
}
|
||||
if (!f.writeU32(global->varOrConstGlobalDataOffset()))
|
||||
return false;
|
||||
return f.writeU8(uint8_t(global->isConst()));
|
||||
return f.writeOp(Expr::LoadGlobal) &&
|
||||
f.writeU32(global->varOrConstGlobalDataOffset()) &&
|
||||
f.writeU8(uint8_t(global->isConst()));
|
||||
}
|
||||
case ModuleValidator::Global::Function:
|
||||
case ModuleValidator::Global::FFI:
|
||||
@ -3851,16 +3836,9 @@ CheckAssignName(FunctionValidator& f, ParseNode* lhs, ParseNode* rhs, Type* type
|
||||
rhsType.toChars(), Type::var(lhsVar->type).toChars());
|
||||
}
|
||||
|
||||
switch (lhsVar->type) {
|
||||
case ValType::I32: f.patchOp(opcodeAt, Expr::I32SetLocal); break;
|
||||
case ValType::I64: MOZ_CRASH("no int64 in asm.js");
|
||||
case ValType::F64: f.patchOp(opcodeAt, Expr::F64SetLocal); break;
|
||||
case ValType::F32: f.patchOp(opcodeAt, Expr::F32SetLocal); break;
|
||||
case ValType::I32x4: f.patchOp(opcodeAt, Expr::I32X4SetLocal); break;
|
||||
case ValType::F32x4: f.patchOp(opcodeAt, Expr::F32X4SetLocal); break;
|
||||
case ValType::B32x4: f.patchOp(opcodeAt, Expr::B32X4SetLocal); break;
|
||||
}
|
||||
MOZ_ASSERT(lhsVar->type != ValType::I64, "no int64 in asm.js");
|
||||
|
||||
f.patchOp(opcodeAt, Expr::SetLocal);
|
||||
f.patch32(indexAt, lhsVar->slot);
|
||||
*type = rhsType;
|
||||
return true;
|
||||
@ -3875,16 +3853,7 @@ CheckAssignName(FunctionValidator& f, ParseNode* lhs, ParseNode* rhs, Type* type
|
||||
rhsType.toChars(), global->varOrConstType().toChars());
|
||||
}
|
||||
|
||||
switch (global->varOrConstType().which()) {
|
||||
case Type::Int: f.patchOp(opcodeAt, Expr::I32SetGlobal); break;
|
||||
case Type::Float: f.patchOp(opcodeAt, Expr::F32SetGlobal); break;
|
||||
case Type::Double: f.patchOp(opcodeAt, Expr::F64SetGlobal); break;
|
||||
case Type::Int32x4: f.patchOp(opcodeAt, Expr::I32X4SetGlobal); break;
|
||||
case Type::Float32x4: f.patchOp(opcodeAt, Expr::F32X4SetGlobal); break;
|
||||
case Type::Bool32x4: f.patchOp(opcodeAt, Expr::B32X4SetGlobal); break;
|
||||
default: MOZ_CRASH("unexpected global type");
|
||||
}
|
||||
|
||||
f.patchOp(opcodeAt, Expr::StoreGlobal);
|
||||
f.patch32(indexAt, global->varOrConstGlobalDataOffset());
|
||||
*type = rhsType;
|
||||
return true;
|
||||
|
@ -51,6 +51,9 @@ enum class Expr : uint8_t
|
||||
Break,
|
||||
BreakLabel,
|
||||
|
||||
GetLocal,
|
||||
SetLocal,
|
||||
|
||||
CallInternal,
|
||||
CallIndirect,
|
||||
CallImport,
|
||||
@ -67,6 +70,10 @@ enum class Expr : uint8_t
|
||||
// asm.js specific
|
||||
Id,
|
||||
Noop,
|
||||
|
||||
LoadGlobal,
|
||||
StoreGlobal,
|
||||
|
||||
InterruptCheckHead,
|
||||
InterruptCheckLoop,
|
||||
|
||||
@ -74,11 +81,6 @@ enum class Expr : uint8_t
|
||||
Bad,
|
||||
|
||||
// I32 opcodes
|
||||
I32GetLocal,
|
||||
I32SetLocal,
|
||||
I32GetGlobal,
|
||||
I32SetGlobal,
|
||||
|
||||
I32CallInternal,
|
||||
I32CallIndirect,
|
||||
I32CallImport,
|
||||
@ -178,11 +180,6 @@ enum class Expr : uint8_t
|
||||
|
||||
// F32 opcdoes
|
||||
// Common opcodes
|
||||
F32GetLocal,
|
||||
F32SetLocal,
|
||||
F32GetGlobal,
|
||||
F32SetGlobal,
|
||||
|
||||
F32CallInternal,
|
||||
F32CallIndirect,
|
||||
F32CallImport,
|
||||
@ -225,11 +222,6 @@ enum class Expr : uint8_t
|
||||
|
||||
// F64 opcodes
|
||||
// Common opcodes
|
||||
F64GetLocal,
|
||||
F64SetLocal,
|
||||
F64GetGlobal,
|
||||
F64SetGlobal,
|
||||
|
||||
F64CallInternal,
|
||||
F64CallIndirect,
|
||||
F64CallImport,
|
||||
@ -280,12 +272,6 @@ enum class Expr : uint8_t
|
||||
|
||||
// I32X4 opcodes
|
||||
// Common opcodes
|
||||
I32X4GetLocal,
|
||||
I32X4SetLocal,
|
||||
|
||||
I32X4GetGlobal,
|
||||
I32X4SetGlobal,
|
||||
|
||||
I32X4CallInternal,
|
||||
I32X4CallIndirect,
|
||||
I32X4CallImport,
|
||||
@ -322,12 +308,6 @@ enum class Expr : uint8_t
|
||||
|
||||
// F32X4 opcodes
|
||||
// Common opcodes
|
||||
F32X4GetLocal,
|
||||
F32X4SetLocal,
|
||||
|
||||
F32X4GetGlobal,
|
||||
F32X4SetGlobal,
|
||||
|
||||
F32X4CallInternal,
|
||||
F32X4CallIndirect,
|
||||
F32X4CallImport,
|
||||
@ -361,12 +341,6 @@ enum class Expr : uint8_t
|
||||
|
||||
// B32X4 opcodes
|
||||
// Common opcodes
|
||||
B32X4GetLocal,
|
||||
B32X4SetLocal,
|
||||
|
||||
B32X4GetGlobal,
|
||||
B32X4SetGlobal,
|
||||
|
||||
B32X4CallInternal,
|
||||
B32X4CallIndirect,
|
||||
B32X4CallImport,
|
||||
|
@ -1328,7 +1328,7 @@ EmitLiteral(FunctionCompiler& f, ValType type, MDefinition**def)
|
||||
}
|
||||
|
||||
static bool
|
||||
EmitGetLoc(FunctionCompiler& f, const DebugOnly<MIRType>& type, MDefinition** def)
|
||||
EmitGetLocal(FunctionCompiler& f, const DebugOnly<MIRType>& type, MDefinition** def)
|
||||
{
|
||||
uint32_t slot = f.readU32();
|
||||
*def = f.getLocalDef(slot);
|
||||
@ -1337,7 +1337,7 @@ EmitGetLoc(FunctionCompiler& f, const DebugOnly<MIRType>& type, MDefinition** de
|
||||
}
|
||||
|
||||
static bool
|
||||
EmitGetGlo(FunctionCompiler& f, MIRType type, MDefinition** def)
|
||||
EmitLoadGlobal(FunctionCompiler& f, MIRType type, MDefinition** def)
|
||||
{
|
||||
uint32_t globalDataOffset = f.readU32();
|
||||
bool isConst = bool(f.readU8());
|
||||
@ -1427,7 +1427,7 @@ EmitStoreWithCoercion(FunctionCompiler& f, Scalar::Type rhsType, Scalar::Type vi
|
||||
}
|
||||
|
||||
static bool
|
||||
EmitSetLoc(FunctionCompiler& f, ValType type, MDefinition** def)
|
||||
EmitSetLocal(FunctionCompiler& f, ValType type, MDefinition** def)
|
||||
{
|
||||
uint32_t slot = f.readU32();
|
||||
MDefinition* expr;
|
||||
@ -1439,7 +1439,7 @@ EmitSetLoc(FunctionCompiler& f, ValType type, MDefinition** def)
|
||||
}
|
||||
|
||||
static bool
|
||||
EmitSetGlo(FunctionCompiler& f, ValType type, MDefinition**def)
|
||||
EmitStoreGlobal(FunctionCompiler& f, ValType type, MDefinition**def)
|
||||
{
|
||||
uint32_t globalDataOffset = f.readU32();
|
||||
MDefinition* expr;
|
||||
@ -2600,18 +2600,18 @@ EmitI32Expr(FunctionCompiler& f, MDefinition** def)
|
||||
{
|
||||
Expr op(f.readOpcode());
|
||||
switch (op) {
|
||||
case Expr::GetLocal:
|
||||
return EmitGetLocal(f, DebugOnly<MIRType>(MIRType_Int32), def);
|
||||
case Expr::SetLocal:
|
||||
return EmitSetLocal(f, ValType::I32, def);
|
||||
case Expr::LoadGlobal:
|
||||
return EmitLoadGlobal(f, MIRType_Int32, def);
|
||||
case Expr::StoreGlobal:
|
||||
return EmitStoreGlobal(f, ValType::I32, def);
|
||||
case Expr::I32Id:
|
||||
return EmitI32Expr(f, def);
|
||||
case Expr::I32Literal:
|
||||
return EmitLiteral(f, ValType::I32, def);
|
||||
case Expr::I32GetLocal:
|
||||
return EmitGetLoc(f, DebugOnly<MIRType>(MIRType_Int32), def);
|
||||
case Expr::I32SetLocal:
|
||||
return EmitSetLoc(f, ValType::I32, def);
|
||||
case Expr::I32GetGlobal:
|
||||
return EmitGetGlo(f, MIRType_Int32, def);
|
||||
case Expr::I32SetGlobal:
|
||||
return EmitSetGlo(f, ValType::I32, def);
|
||||
case Expr::I32CallInternal:
|
||||
return EmitInternalCall(f, ExprType::I32, def);
|
||||
case Expr::I32CallIndirect:
|
||||
@ -2734,18 +2734,18 @@ EmitF32Expr(FunctionCompiler& f, MDefinition** def)
|
||||
{
|
||||
Expr op(f.readOpcode());
|
||||
switch (op) {
|
||||
case Expr::GetLocal:
|
||||
return EmitGetLocal(f, DebugOnly<MIRType>(MIRType_Float32), def);
|
||||
case Expr::SetLocal:
|
||||
return EmitSetLocal(f, ValType::F32, def);
|
||||
case Expr::LoadGlobal:
|
||||
return EmitLoadGlobal(f, MIRType_Float32, def);
|
||||
case Expr::StoreGlobal:
|
||||
return EmitStoreGlobal(f, ValType::F32, def);
|
||||
case Expr::F32Id:
|
||||
return EmitF32Expr(f, def);
|
||||
case Expr::F32Literal:
|
||||
return EmitLiteral(f, ValType::F32, def);
|
||||
case Expr::F32GetLocal:
|
||||
return EmitGetLoc(f, DebugOnly<MIRType>(MIRType_Float32), def);
|
||||
case Expr::F32SetLocal:
|
||||
return EmitSetLoc(f, ValType::F32, def);
|
||||
case Expr::F32GetGlobal:
|
||||
return EmitGetGlo(f, MIRType_Float32, def);
|
||||
case Expr::F32SetGlobal:
|
||||
return EmitSetGlo(f, ValType::F32, def);
|
||||
case Expr::F32CallInternal:
|
||||
return EmitInternalCall(f, ExprType::F32, def);
|
||||
case Expr::F32CallIndirect:
|
||||
@ -2802,16 +2802,16 @@ EmitF64Expr(FunctionCompiler& f, MDefinition** def)
|
||||
{
|
||||
Expr op(f.readOpcode());
|
||||
switch (op) {
|
||||
case Expr::GetLocal:
|
||||
return EmitGetLocal(f, DebugOnly<MIRType>(MIRType_Double), def);
|
||||
case Expr::SetLocal:
|
||||
return EmitSetLocal(f, ValType::F64, def);
|
||||
case Expr::LoadGlobal:
|
||||
return EmitLoadGlobal(f, MIRType_Double, def);
|
||||
case Expr::StoreGlobal:
|
||||
return EmitStoreGlobal(f, ValType::F64, def);
|
||||
case Expr::F64Id:
|
||||
return EmitF64Expr(f, def);
|
||||
case Expr::F64GetLocal:
|
||||
return EmitGetLoc(f, DebugOnly<MIRType>(MIRType_Double), def);
|
||||
case Expr::F64SetLocal:
|
||||
return EmitSetLoc(f, ValType::F64, def);
|
||||
case Expr::F64GetGlobal:
|
||||
return EmitGetGlo(f, MIRType_Double, def);
|
||||
case Expr::F64SetGlobal:
|
||||
return EmitSetGlo(f, ValType::F64, def);
|
||||
case Expr::F64Literal:
|
||||
return EmitLiteral(f, ValType::F64, def);
|
||||
case Expr::F64Add:
|
||||
@ -2880,16 +2880,16 @@ EmitI32X4Expr(FunctionCompiler& f, MDefinition** def)
|
||||
{
|
||||
Expr op(f.readOpcode());
|
||||
switch (op) {
|
||||
case Expr::GetLocal:
|
||||
return EmitGetLocal(f, DebugOnly<MIRType>(MIRType_Int32x4), def);
|
||||
case Expr::SetLocal:
|
||||
return EmitSetLocal(f, ValType::I32x4, def);
|
||||
case Expr::LoadGlobal:
|
||||
return EmitLoadGlobal(f, MIRType_Int32x4, def);
|
||||
case Expr::StoreGlobal:
|
||||
return EmitStoreGlobal(f, ValType::I32x4, def);
|
||||
case Expr::I32X4Id:
|
||||
return EmitI32X4Expr(f, def);
|
||||
case Expr::I32X4GetLocal:
|
||||
return EmitGetLoc(f, DebugOnly<MIRType>(MIRType_Int32x4), def);
|
||||
case Expr::I32X4SetLocal:
|
||||
return EmitSetLoc(f, ValType::I32x4, def);
|
||||
case Expr::I32X4GetGlobal:
|
||||
return EmitGetGlo(f, MIRType_Int32x4, def);
|
||||
case Expr::I32X4SetGlobal:
|
||||
return EmitSetGlo(f, ValType::I32x4, def);
|
||||
case Expr::I32X4Comma:
|
||||
return EmitComma(f, ValType::I32x4, def);
|
||||
case Expr::I32X4Conditional:
|
||||
@ -2941,16 +2941,16 @@ EmitF32X4Expr(FunctionCompiler& f, MDefinition** def)
|
||||
{
|
||||
Expr op(f.readOpcode());
|
||||
switch (op) {
|
||||
case Expr::GetLocal:
|
||||
return EmitGetLocal(f, DebugOnly<MIRType>(MIRType_Float32x4), def);
|
||||
case Expr::SetLocal:
|
||||
return EmitSetLocal(f, ValType::F32x4, def);
|
||||
case Expr::LoadGlobal:
|
||||
return EmitLoadGlobal(f, MIRType_Float32x4, def);
|
||||
case Expr::StoreGlobal:
|
||||
return EmitStoreGlobal(f, ValType::F32x4, def);
|
||||
case Expr::F32X4Id:
|
||||
return EmitF32X4Expr(f, def);
|
||||
case Expr::F32X4GetLocal:
|
||||
return EmitGetLoc(f, DebugOnly<MIRType>(MIRType_Float32x4), def);
|
||||
case Expr::F32X4SetLocal:
|
||||
return EmitSetLoc(f, ValType::F32x4, def);
|
||||
case Expr::F32X4GetGlobal:
|
||||
return EmitGetGlo(f, MIRType_Float32x4, def);
|
||||
case Expr::F32X4SetGlobal:
|
||||
return EmitSetGlo(f, ValType::F32x4, def);
|
||||
case Expr::F32X4Comma:
|
||||
return EmitComma(f, ValType::F32x4, def);
|
||||
case Expr::F32X4Conditional:
|
||||
@ -2998,16 +2998,16 @@ EmitB32X4Expr(FunctionCompiler& f, MDefinition** def)
|
||||
{
|
||||
Expr op(f.readOpcode());
|
||||
switch (op) {
|
||||
case Expr::GetLocal:
|
||||
return EmitGetLocal(f, DebugOnly<MIRType>(MIRType_Bool32x4), def);
|
||||
case Expr::SetLocal:
|
||||
return EmitSetLocal(f, ValType::B32x4, def);
|
||||
case Expr::LoadGlobal:
|
||||
return EmitLoadGlobal(f, MIRType_Bool32x4, def);
|
||||
case Expr::StoreGlobal:
|
||||
return EmitStoreGlobal(f, ValType::B32x4, def);
|
||||
case Expr::B32X4Id:
|
||||
return EmitB32X4Expr(f, def);
|
||||
case Expr::B32X4GetLocal:
|
||||
return EmitGetLoc(f, DebugOnly<MIRType>(MIRType_Bool32x4), def);
|
||||
case Expr::B32X4SetLocal:
|
||||
return EmitSetLoc(f, ValType::B32x4, def);
|
||||
case Expr::B32X4GetGlobal:
|
||||
return EmitGetGlo(f, MIRType_Bool32x4, def);
|
||||
case Expr::B32X4SetGlobal:
|
||||
return EmitSetGlo(f, ValType::B32x4, def);
|
||||
case Expr::B32X4Comma:
|
||||
return EmitComma(f, ValType::B32x4, def);
|
||||
case Expr::B32X4Conditional:
|
||||
|
Loading…
Reference in New Issue
Block a user