2 * Copyright (C) 2011 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 #ifndef DFGNonSpeculativeJIT_h
27 #define DFGNonSpeculativeJIT_h
31 #include <dfg/DFGJITCodeGenerator.h>
33 namespace JSC { namespace DFG {
35 class SpeculationCheckIndexIterator;
37 // === EntryLocation ===
39 // This structure describes an entry point into the non-speculative
40 // code path. This is used in linking bail-outs from the speculative path.
41 struct EntryLocation {
42 EntryLocation(MacroAssembler::Label, NonSpeculativeJIT*);
44 // The node this entry point corresponds to, and the label
45 // marking the start of code for the given node.
46 MacroAssembler::Label m_entry;
47 NodeIndex m_nodeIndex;
49 // For every entry point we record a map recording for every
50 // machine register which, if any, values it contains. For
51 // GPR registers we must also record the format of the value.
57 RegisterInfo m_gprInfo[GPRInfo::numberOfRegisters];
58 RegisterInfo m_fprInfo[FPRInfo::numberOfRegisters];
61 // === NonSpeculativeJIT ===
63 // This class is used to generate code for the non-speculative path.
64 // Code generation will take advantage of static information available
65 // in the dataflow to perform safe optimizations - for example, avoiding
66 // boxing numeric values between arithmetic operations, but will not
67 // perform any unsafe optimizations that would render the code unable
68 // to produce the correct results for any possible input.
69 class NonSpeculativeJIT : public JITCodeGenerator {
70 friend struct EntryLocation;
72 NonSpeculativeJIT(JITCompiler& jit)
73 : JITCodeGenerator(jit, false)
77 void compile(SpeculationCheckIndexIterator&);
79 typedef SegmentedVector<EntryLocation, 16> EntryLocationVector;
80 EntryLocationVector& entryLocations() { return m_entryLocations; }
83 void compile(SpeculationCheckIndexIterator&, Node&);
84 void compile(SpeculationCheckIndexIterator&, BasicBlock&);
86 // These methods are used to plant calls out to C++
87 // helper routines to convert between types.
88 void valueToNumber(JSValueOperand&, GPRReg result);
89 void valueToInt32(JSValueOperand&, GPRReg result);
90 void numberToInt32(FPRReg, GPRReg result);
92 // Record an entry location into the non-speculative code path;
93 // for every bail-out on the speculative path we record information
94 // to be able to re-enter into the non-speculative one.
95 void trackEntry(MacroAssembler::Label entry)
97 m_entryLocations.append(EntryLocation(entry, this));
100 // internal helpers for add/sub/mul operations
101 void knownConstantArithOp(NodeType op, NodeIndex regChild, NodeIndex immChild, bool commute);
102 void basicArithOp(NodeType op, Node&);
104 EntryLocationVector m_entryLocations;
107 } } // namespace JSC::DFG