blob: f014281ade196047188ca0e1e6b565f333fb6b73 [file] [log] [blame]
/*
* Copyright (C) 2015 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef B3ValueRep_h
#define B3ValueRep_h
#if ENABLE(B3_JIT)
#include "Reg.h"
#include <wtf/PrintStream.h>
namespace JSC { namespace B3 {
// We use this class to describe value representations at stackmaps. It's used both to force a
// representation and to get the representation. When the B3 client forces a representation, we say
// that it's an input. When B3 tells the client what representation it picked, we say that it's an
// output.
class ValueRep {
public:
enum Kind {
// As an input representation, this means that B3 can pick any representation. As an
// output representation, this means that we don't know. This will only arise for the
// right operand (i.e. child(1)) of a CheckMul.
Any,
// As an input representation, this means that B3 should pick some register. It could be a
// register that this claims to clobber!
SomeRegister,
// As an input representation, this forces a particular register. As an output
// representation, this tells us what register B3 picked.
Register,
// As an output representation, this tells us what stack slot B3 picked. It's not a valid
// input representation.
Stack,
// As an input representation, this forces the value to end up in the argument area at some
// offset.
// FIXME: The StackmapSpecial class needs to account for the fact that these don't turn into
// Air operands.
// https://bugs.webkit.org/show_bug.cgi?id=150540
StackArgument,
// As an output representation, this tells us that B3 constant-folded the value.
Constant
};
ValueRep()
: m_kind(Any)
{
}
explicit ValueRep(Reg reg)
: m_kind(Register)
{
u.reg = reg;
}
static ValueRep reg(Reg reg)
{
return ValueRep(reg);
}
static ValueRep stack(intptr_t offsetFromFP)
{
ValueRep result;
result.m_kind = Stack;
result.u.offsetFromFP = offsetFromFP;
return result;
}
static ValueRep stackArgument(intptr_t offsetFromSP)
{
ValueRep result;
result.m_kind = StackArgument;
result.u.offsetFromSP = offsetFromSP;
return result;
}
static ValueRep constant(int64_t value)
{
ValueRep result;
result.m_kind = Constant;
result.u.value = value;
return result;
}
static ValueRep constantDouble(double value)
{
return ValueRep::constant(bitwise_cast<int64_t>(value));
}
Kind kind() const { return m_kind; }
explicit operator bool() const { return kind() != Any; }
Reg reg() const
{
ASSERT(kind() == Register);
return u.reg;
}
intptr_t offsetFromFP() const
{
ASSERT(kind() == Stack);
return u.offsetFromFP;
}
intptr_t offsetFromSP() const
{
ASSERT(kind() == StackArgument);
return u.offsetFromSP;
}
int64_t value() const
{
ASSERT(kind() == Constant);
return u.value;
}
double doubleValue() const
{
return bitwise_cast<double>(value());
}
void dump(PrintStream&) const;
private:
Kind m_kind;
union U {
Reg reg;
intptr_t offsetFromFP;
intptr_t offsetFromSP;
int64_t value;
U()
{
memset(this, 0, sizeof(*this));
}
} u;
};
} } // namespace JSC::B3
namespace WTF {
void printInternal(PrintStream&, JSC::B3::ValueRep::Kind);
} // namespace WTF
#endif // ENABLE(B3_JIT)
#endif // B3ValueRep_h