blob: 24b82c0c0e89c12ece107314e43c93b9abbbc113 [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 B3ControlValue_h
#define B3ControlValue_h
#if ENABLE(B3_JIT)
#include "B3FrequentedBlock.h"
#include "B3Value.h"
namespace JSC { namespace B3 {
class BasicBlock;
class JS_EXPORT_PRIVATE ControlValue : public Value {
public:
static bool accepts(Opcode opcode)
{
switch (opcode) {
case Jump:
case Branch:
case Return:
case Oops:
return true;
case Switch:
// This is here because SwitchValue is a subclass of ControlValue, so we want
// switchValue->as<ControlValue>() to return non-null.
return true;
default:
return false;
}
}
typedef Vector<FrequentedBlock, 2> SuccessorList;
JS_EXPORT_PRIVATE ~ControlValue();
unsigned numSuccessors() const { return m_successors.size(); }
const FrequentedBlock& successor(unsigned index) const { return m_successors[index]; }
FrequentedBlock& successor(unsigned index) { return m_successors[index]; }
const SuccessorList& successors() const { return m_successors; }
SuccessorList& successors() { return m_successors; }
bool replaceSuccessor(BasicBlock* from, BasicBlock* to);
const FrequentedBlock& taken() const
{
ASSERT(opcode() == Jump || opcode() == Branch);
return successor(0);
}
FrequentedBlock& taken()
{
ASSERT(opcode() == Jump || opcode() == Branch);
return successor(0);
}
const FrequentedBlock& notTaken() const
{
ASSERT(opcode() == Branch);
return successor(1);
}
FrequentedBlock& notTaken()
{
ASSERT(opcode() == Branch);
return successor(1);
}
void convertToJump(BasicBlock* destination);
protected:
JS_EXPORT_PRIVATE void dumpMeta(CommaPrinter&, PrintStream&) const override;
// Use this for subclasses.
template<typename... Arguments>
ControlValue(unsigned index, Opcode opcode, Type type, Origin origin, Arguments... arguments)
: Value(index, opcode, type, origin, arguments...)
{
ASSERT(accepts(opcode));
}
// Subclasses will populate this.
SuccessorList m_successors;
private:
friend class Procedure;
// Use this for Oops.
ControlValue(unsigned index, Opcode opcode, Origin origin)
: Value(index, CheckedOpcode, opcode, Void, origin)
{
ASSERT(opcode == Oops);
}
// Use this for Return.
ControlValue(unsigned index, Opcode opcode, Origin origin, Value* result)
: Value(index, CheckedOpcode, opcode, Void, origin, result)
{
ASSERT(opcode == Return);
}
// Use this for Jump.
ControlValue(unsigned index, Opcode opcode, Origin origin, const FrequentedBlock& target)
: Value(index, CheckedOpcode, opcode, Void, origin)
{
ASSERT(opcode == Jump);
m_successors.append(target);
}
// Use this for Branch.
ControlValue(
unsigned index, Opcode opcode, Origin origin, Value* predicate,
const FrequentedBlock& yes, const FrequentedBlock& no)
: Value(index, CheckedOpcode, opcode, Void, origin, predicate)
{
ASSERT(opcode == Branch);
m_successors.append(yes);
m_successors.append(no);
}
};
} } // namespace JSC::B3
#endif // ENABLE(B3_JIT)
#endif // B3ControlValue_h