зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1104658 - Add constant propagation to MMathFunction. r=nbp
This commit is contained in:
Родитель
bc122cda64
Коммит
7162811aaa
|
@ -627,14 +627,20 @@ MConstant::New(TempAllocator &alloc, const Value &v, types::CompilerConstraintLi
|
|||
}
|
||||
|
||||
MConstant *
|
||||
MConstant::NewAsmJS(TempAllocator &alloc, const Value &v, MIRType type)
|
||||
MConstant::NewTypedValue(TempAllocator &alloc, const Value &v, MIRType type, types::CompilerConstraintList *constraints)
|
||||
{
|
||||
MOZ_ASSERT(!IsSimdType(type));
|
||||
MConstant *constant = new(alloc) MConstant(v, nullptr);
|
||||
MConstant *constant = new(alloc) MConstant(v, constraints);
|
||||
constant->setResultType(type);
|
||||
return constant;
|
||||
}
|
||||
|
||||
MConstant *
|
||||
MConstant::NewAsmJS(TempAllocator &alloc, const Value &v, MIRType type)
|
||||
{
|
||||
return NewTypedValue(alloc, v, type);
|
||||
}
|
||||
|
||||
MConstant *
|
||||
MConstant::NewConstraintlessObject(TempAllocator &alloc, JSObject *v)
|
||||
{
|
||||
|
@ -970,6 +976,101 @@ MMathFunction::printOpcode(FILE *fp) const
|
|||
fprintf(fp, " %s", FunctionName(function()));
|
||||
}
|
||||
|
||||
MDefinition *
|
||||
MMathFunction::foldsTo(TempAllocator &alloc)
|
||||
{
|
||||
MDefinition *input = getOperand(0);
|
||||
if (!input->isConstant())
|
||||
return this;
|
||||
|
||||
Value val = input->toConstant()->value();
|
||||
if (!val.isNumber())
|
||||
return this;
|
||||
|
||||
double in = val.toNumber();
|
||||
double out;
|
||||
switch (function_) {
|
||||
case Log:
|
||||
out = js::math_log_uncached(in);
|
||||
break;
|
||||
case Sin:
|
||||
out = js::math_sin_uncached(in);
|
||||
break;
|
||||
case Cos:
|
||||
out = js::math_cos_uncached(in);
|
||||
break;
|
||||
case Exp:
|
||||
out = js::math_exp_uncached(in);
|
||||
break;
|
||||
case Tan:
|
||||
out = js::math_tan_uncached(in);
|
||||
break;
|
||||
case ACos:
|
||||
out = js::math_acos_uncached(in);
|
||||
break;
|
||||
case ASin:
|
||||
out = js::math_asin_uncached(in);
|
||||
break;
|
||||
case ATan:
|
||||
out = js::math_atan_uncached(in);
|
||||
break;
|
||||
case Log10:
|
||||
out = js::math_log10_uncached(in);
|
||||
break;
|
||||
case Log2:
|
||||
out = js::math_log2_uncached(in);
|
||||
break;
|
||||
case Log1P:
|
||||
out = js::math_log1p_uncached(in);
|
||||
break;
|
||||
case ExpM1:
|
||||
out = js::math_expm1_uncached(in);
|
||||
break;
|
||||
case CosH:
|
||||
out = js::math_cosh_uncached(in);
|
||||
break;
|
||||
case SinH:
|
||||
out = js::math_sinh_uncached(in);
|
||||
break;
|
||||
case TanH:
|
||||
out = js::math_tanh_uncached(in);
|
||||
break;
|
||||
case ACosH:
|
||||
out = js::math_acosh_uncached(in);
|
||||
break;
|
||||
case ASinH:
|
||||
out = js::math_asinh_uncached(in);
|
||||
break;
|
||||
case ATanH:
|
||||
out = js::math_atanh_uncached(in);
|
||||
break;
|
||||
case Sign:
|
||||
out = js::math_sign_uncached(in);
|
||||
break;
|
||||
case Trunc:
|
||||
out = js::math_trunc_uncached(in);
|
||||
break;
|
||||
case Cbrt:
|
||||
out = js::math_cbrt_uncached(in);
|
||||
break;
|
||||
case Floor:
|
||||
out = js::math_floor_impl(in);
|
||||
break;
|
||||
case Ceil:
|
||||
out = js::math_ceil_impl(in);
|
||||
break;
|
||||
case Round:
|
||||
out = js::math_round_impl(in);
|
||||
break;
|
||||
default:
|
||||
return this;
|
||||
}
|
||||
|
||||
if (input->type() == MIRType_Float32)
|
||||
return MConstant::NewTypedValue(alloc, DoubleValue(out), MIRType_Float32);
|
||||
return MConstant::New(alloc, DoubleValue(out));
|
||||
}
|
||||
|
||||
MParameter *
|
||||
MParameter::New(TempAllocator &alloc, int32_t index, types::TemporaryTypeSet *types)
|
||||
{
|
||||
|
|
|
@ -1279,6 +1279,8 @@ class MConstant : public MNullaryInstruction
|
|||
INSTRUCTION_HEADER(Constant)
|
||||
static MConstant *New(TempAllocator &alloc, const Value &v,
|
||||
types::CompilerConstraintList *constraints = nullptr);
|
||||
static MConstant *NewTypedValue(TempAllocator &alloc, const Value &v, MIRType type,
|
||||
types::CompilerConstraintList *constraints = nullptr);
|
||||
static MConstant *NewAsmJS(TempAllocator &alloc, const Value &v, MIRType type);
|
||||
static MConstant *NewConstraintlessObject(TempAllocator &alloc, JSObject *v);
|
||||
|
||||
|
@ -5703,6 +5705,8 @@ class MMathFunction
|
|||
return true;
|
||||
}
|
||||
|
||||
MDefinition *foldsTo(TempAllocator &alloc);
|
||||
|
||||
void printOpcode(FILE *fp) const MOZ_OVERRIDE;
|
||||
|
||||
static const char *FunctionName(Function function);
|
||||
|
|
Загрузка…
Ссылка в новой задаче