PreciseJumpTargets.cpp [plain text]
#include "config.h"
#include "PreciseJumpTargets.h"
#include "JSCJSValueInlines.h"
#include "PreciseJumpTargetsInlines.h"
namespace JSC {
template <size_t vectorSize, typename Block>
static void getJumpTargetsForInstruction(Block* codeBlock, const InstructionStream::Ref& instruction, Vector<InstructionStream::Offset, vectorSize>& out)
{
extractStoredJumpTargetsForInstruction(codeBlock, instruction, [&](int32_t relativeOffset) {
out.append(instruction.offset() + relativeOffset);
});
OpcodeID opcodeID = instruction->opcodeID();
if (opcodeID == op_loop_hint)
out.append(instruction.offset());
else if (opcodeID == op_enter && codeBlock->hasTailCalls() && Options::optimizeRecursiveTailCalls()) {
out.append(instruction.next().offset());
}
}
enum class ComputePreciseJumpTargetsMode {
FollowCodeBlockClaim,
ForceCompute,
};
template<ComputePreciseJumpTargetsMode Mode, typename Block, size_t vectorSize>
void computePreciseJumpTargetsInternal(Block* codeBlock, const InstructionStream& instructions, Vector<InstructionStream::Offset, vectorSize>& out)
{
ASSERT(out.isEmpty());
if (Mode == ComputePreciseJumpTargetsMode::FollowCodeBlockClaim && !codeBlock->numberOfJumpTargets())
return;
for (unsigned i = codeBlock->numberOfExceptionHandlers(); i--;) {
out.append(codeBlock->exceptionHandler(i).target);
out.append(codeBlock->exceptionHandler(i).start);
out.append(codeBlock->exceptionHandler(i).end);
}
for (const auto& instruction : instructions) {
getJumpTargetsForInstruction(codeBlock, instruction, out);
}
std::sort(out.begin(), out.end());
unsigned toIndex = 0;
unsigned fromIndex = 0;
unsigned lastValue = UINT_MAX;
while (fromIndex < out.size()) {
unsigned value = out[fromIndex++];
if (value == lastValue)
continue;
out[toIndex++] = value;
lastValue = value;
}
out.shrinkCapacity(toIndex);
}
void computePreciseJumpTargets(CodeBlock* codeBlock, Vector<InstructionStream::Offset, 32>& out)
{
computePreciseJumpTargetsInternal<ComputePreciseJumpTargetsMode::FollowCodeBlockClaim>(codeBlock, codeBlock->instructions(), out);
}
void computePreciseJumpTargets(CodeBlock* codeBlock, const InstructionStream& instructions, Vector<InstructionStream::Offset, 32>& out)
{
computePreciseJumpTargetsInternal<ComputePreciseJumpTargetsMode::FollowCodeBlockClaim>(codeBlock, instructions, out);
}
void computePreciseJumpTargets(UnlinkedCodeBlockGenerator* codeBlock, const InstructionStream& instructions, Vector<InstructionStream::Offset, 32>& out)
{
computePreciseJumpTargetsInternal<ComputePreciseJumpTargetsMode::FollowCodeBlockClaim>(codeBlock, instructions, out);
}
void recomputePreciseJumpTargets(UnlinkedCodeBlockGenerator* codeBlock, const InstructionStream& instructions, Vector<InstructionStream::Offset>& out)
{
computePreciseJumpTargetsInternal<ComputePreciseJumpTargetsMode::ForceCompute>(codeBlock, instructions, out);
}
void findJumpTargetsForInstruction(CodeBlock* codeBlock, const InstructionStream::Ref& instruction, Vector<InstructionStream::Offset, 1>& out)
{
getJumpTargetsForInstruction(codeBlock, instruction, out);
}
void findJumpTargetsForInstruction(UnlinkedCodeBlockGenerator* codeBlock, const InstructionStream::Ref& instruction, Vector<InstructionStream::Offset, 1>& out)
{
getJumpTargetsForInstruction(codeBlock, instruction, out);
}
}