#pragma once
#if ENABLE(B3_JIT)
#include "B3OpaqueByproducts.h"
#include "B3Origin.h"
#include "B3PCToOriginMap.h"
#include "B3SparseCollection.h"
#include "B3Type.h"
#include "B3ValueKey.h"
#include "CCallHelpers.h"
#include "PureNaN.h"
#include "RegisterAtOffsetList.h"
#include <wtf/Bag.h>
#include <wtf/FastMalloc.h>
#include <wtf/HashSet.h>
#include <wtf/IndexedContainerIterator.h>
#include <wtf/Noncopyable.h>
#include <wtf/PrintStream.h>
#include <wtf/SharedTask.h>
#include <wtf/TriState.h>
#include <wtf/Vector.h>
namespace JSC { namespace B3 {
class BackwardsCFG;
class BackwardsDominators;
class BasicBlock;
class BlockInsertionSet;
class CFG;
class Dominators;
class NaturalLoops;
class StackSlot;
class Value;
class Variable;
namespace Air { class Code; }
typedef void WasmBoundsCheckGeneratorFunction(CCallHelpers&, GPRReg);
typedef SharedTask<WasmBoundsCheckGeneratorFunction> WasmBoundsCheckGenerator;
class Procedure {
WTF_MAKE_NONCOPYABLE(Procedure);
WTF_MAKE_FAST_ALLOCATED;
public:
JS_EXPORT_PRIVATE Procedure();
JS_EXPORT_PRIVATE ~Procedure();
template<typename Callback>
void setOriginPrinter(Callback&& callback)
{
m_originPrinter = createSharedTask<void(PrintStream&, Origin)>(
std::forward<Callback>(callback));
}
void printOrigin(PrintStream& out, Origin origin) const;
void setFrontendData(const void* value) { m_frontendData = value; }
const void* frontendData() const { return m_frontendData; }
JS_EXPORT_PRIVATE BasicBlock* addBlock(double frequency = 1);
template<typename BlockIterable>
void setBlockOrder(const BlockIterable& iterable)
{
Vector<BasicBlock*> blocks;
for (BasicBlock* block : iterable)
blocks.append(block);
setBlockOrderImpl(blocks);
}
JS_EXPORT_PRIVATE StackSlot* addStackSlot(unsigned byteSize);
JS_EXPORT_PRIVATE Variable* addVariable(Type);
template<typename ValueType, typename... Arguments>
ValueType* add(Arguments...);
Value* clone(Value*);
Value* addIntConstant(Origin, Type, int64_t value);
Value* addIntConstant(Value*, int64_t value);
Value* addConstant(Origin, Type, uint64_t bits);
Value* addBottom(Origin, Type);
Value* addBottom(Value*);
Value* addBoolConstant(Origin, TriState);
void resetValueOwners();
JS_EXPORT_PRIVATE void resetReachability();
void invalidateCFG();
JS_EXPORT_PRIVATE void dump(PrintStream&) const;
unsigned size() const { return m_blocks.size(); }
BasicBlock* at(unsigned index) const { return m_blocks[index].get(); }
BasicBlock* operator[](unsigned index) const { return at(index); }
typedef WTF::IndexedContainerIterator<Procedure> iterator;
iterator begin() const { return iterator(*this, 0); }
iterator end() const { return iterator(*this, size()); }
Vector<BasicBlock*> blocksInPreOrder();
Vector<BasicBlock*> blocksInPostOrder();
SparseCollection<StackSlot>& stackSlots() { return m_stackSlots; }
const SparseCollection<StackSlot>& stackSlots() const { return m_stackSlots; }
void deleteStackSlot(StackSlot*);
SparseCollection<Variable>& variables() { return m_variables; }
const SparseCollection<Variable>& variables() const { return m_variables; }
void deleteVariable(Variable*);
SparseCollection<Value>& values() { return m_values; }
const SparseCollection<Value>& values() const { return m_values; }
void deleteValue(Value*);
void deleteOrphans();
CFG& cfg() const { return *m_cfg; }
Dominators& dominators();
NaturalLoops& naturalLoops();
BackwardsCFG& backwardsCFG();
BackwardsDominators& backwardsDominators();
void addFastConstant(const ValueKey&);
bool isFastConstant(const ValueKey&);
unsigned numEntrypoints() const { return m_numEntrypoints; }
JS_EXPORT_PRIVATE void setNumEntrypoints(unsigned);
JS_EXPORT_PRIVATE CCallHelpers::Label entrypointLabel(unsigned entrypointIndex) const;
void setLastPhaseName(const char* name)
{
m_lastPhaseName = name;
}
const char* lastPhaseName() const { return m_lastPhaseName; }
JS_EXPORT_PRIVATE void* addDataSection(size_t);
bool hasQuirks() const { return m_hasQuirks; }
void setHasQuirks(bool value) { m_hasQuirks = value; }
OpaqueByproducts& byproducts() { return *m_byproducts; }
std::unique_ptr<OpaqueByproducts> releaseByproducts() { return WTFMove(m_byproducts); }
const Air::Code& code() const { return *m_code; }
Air::Code& code() { return *m_code; }
unsigned callArgAreaSizeInBytes() const;
void requestCallArgAreaSizeInBytes(unsigned size);
JS_EXPORT_PRIVATE void pinRegister(Reg);
JS_EXPORT_PRIVATE void setOptLevel(unsigned value);
unsigned optLevel() const { return m_optLevel; }
void setNeedsUsedRegisters(bool value) { m_needsUsedRegisters = value; }
bool needsUsedRegisters() const { return m_needsUsedRegisters; }
JS_EXPORT_PRIVATE unsigned frameSize() const;
JS_EXPORT_PRIVATE RegisterAtOffsetList calleeSaveRegisterAtOffsetList() const;
PCToOriginMap& pcToOriginMap() { return m_pcToOriginMap; }
PCToOriginMap releasePCToOriginMap() { return WTFMove(m_pcToOriginMap); }
JS_EXPORT_PRIVATE void setWasmBoundsCheckGenerator(RefPtr<WasmBoundsCheckGenerator>);
template<typename Functor>
void setWasmBoundsCheckGenerator(const Functor& functor)
{
setWasmBoundsCheckGenerator(RefPtr<WasmBoundsCheckGenerator>(createSharedTask<WasmBoundsCheckGeneratorFunction>(functor)));
}
JS_EXPORT_PRIVATE RegisterSet mutableGPRs();
JS_EXPORT_PRIVATE RegisterSet mutableFPRs();
private:
friend class BlockInsertionSet;
JS_EXPORT_PRIVATE Value* addValueImpl(Value*);
void setBlockOrderImpl(Vector<BasicBlock*>&);
SparseCollection<StackSlot> m_stackSlots;
SparseCollection<Variable> m_variables;
Vector<std::unique_ptr<BasicBlock>> m_blocks;
SparseCollection<Value> m_values;
std::unique_ptr<CFG> m_cfg;
std::unique_ptr<Dominators> m_dominators;
std::unique_ptr<NaturalLoops> m_naturalLoops;
std::unique_ptr<BackwardsCFG> m_backwardsCFG;
std::unique_ptr<BackwardsDominators> m_backwardsDominators;
HashSet<ValueKey> m_fastConstants;
unsigned m_numEntrypoints { 1 };
const char* m_lastPhaseName;
std::unique_ptr<OpaqueByproducts> m_byproducts;
std::unique_ptr<Air::Code> m_code;
RefPtr<SharedTask<void(PrintStream&, Origin)>> m_originPrinter;
const void* m_frontendData;
PCToOriginMap m_pcToOriginMap;
unsigned m_optLevel { defaultOptLevel() };
bool m_needsUsedRegisters { true };
bool m_hasQuirks { false };
};
} }
#endif // ENABLE(B3_JIT)