blob: b3b00a9923733d31ac84e5d882da903e9bedc7fb [file] [log] [blame]
fpizlo@apple.com0309686b2013-12-02 19:49:43 +00001/*
mark.lam@apple.com97d3f452019-01-16 18:44:25 +00002 * Copyright (C) 2013-2019 Apple Inc. All rights reserved.
fpizlo@apple.com0309686b2013-12-02 19:49:43 +00003 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
ryanhaddad@apple.com22104f52016-09-28 17:08:17 +000026#pragma once
fpizlo@apple.com0309686b2013-12-02 19:49:43 +000027
ross.kirsling@sony.com848a1382019-04-09 18:50:00 +000028#include "BytecodeStructs.h"
fpizlo@apple.com0309686b2013-12-02 19:49:43 +000029#include "CodeBlock.h"
tzagallo@apple.com3474dd02018-10-29 13:16:03 +000030#include "Instruction.h"
31#include <wtf/Forward.h>
fpizlo@apple.com0309686b2013-12-02 19:49:43 +000032
33namespace JSC {
34
tzagallo@apple.com59ae72b2019-12-10 19:41:40 +000035void computeUsesForBytecodeIndexImpl(VirtualRegister, const Instruction*, const Function<void(VirtualRegister)>&);
36void computeDefsForBytecodeIndexImpl(unsigned, const Instruction*, const Function<void(VirtualRegister)>&);
tzagallo@apple.com3474dd02018-10-29 13:16:03 +000037
tzagallo@apple.com59ae72b2019-12-10 19:41:40 +000038template<typename Block>
39void computeUsesForBytecodeIndex(Block* codeBlock, const Instruction* instruction, const Function<void(VirtualRegister)>& functor)
fpizlo@apple.com0309686b2013-12-02 19:49:43 +000040{
ysuzuki@apple.com86dae442019-11-22 19:55:27 +000041 OpcodeID opcodeID = instruction->opcodeID();
sbarati@apple.com60a3be72017-08-25 18:26:15 +000042 if (opcodeID != op_enter && (codeBlock->wasCompiledWithDebuggingOpcodes() || codeBlock->usesEval()) && codeBlock->scopeRegister().isValid())
tzagallo@apple.com3474dd02018-10-29 13:16:03 +000043 functor(codeBlock->scopeRegister());
44
tzagallo@apple.com59ae72b2019-12-10 19:41:40 +000045 computeUsesForBytecodeIndexImpl(codeBlock->scopeRegister(), instruction, functor);
fpizlo@apple.com0309686b2013-12-02 19:49:43 +000046}
47
tzagallo@apple.com59ae72b2019-12-10 19:41:40 +000048template<typename Block>
49void computeDefsForBytecodeIndex(Block* codeBlock, const Instruction* instruction, const Function<void(VirtualRegister)>& functor)
fpizlo@apple.com0309686b2013-12-02 19:49:43 +000050{
tzagallo@apple.com59ae72b2019-12-10 19:41:40 +000051 computeDefsForBytecodeIndexImpl(codeBlock->numVars(), instruction, functor);
fpizlo@apple.com0309686b2013-12-02 19:49:43 +000052}
53
tzagallo@apple.com3474dd02018-10-29 13:16:03 +000054#undef CALL_FUNCTOR
55#undef USES_OR_DEFS
56#undef USES
57#undef DEFS
fpizlo@apple.com0309686b2013-12-02 19:49:43 +000058} // namespace JSC