sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 1 | // Copyright 2010 the V8 project authors. All rights reserved. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 28 | #ifndef V8_ARM_CODEGEN_ARM_H_ |
| 29 | #define V8_ARM_CODEGEN_ARM_H_ |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 30 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame^] | 31 | #include "ic-inl.h" |
| 32 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 33 | namespace v8 { |
| 34 | namespace internal { |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 35 | |
| 36 | // Forward declarations |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 37 | class CompilationInfo; |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 38 | class DeferredCode; |
ager@chromium.org | bb29dc9 | 2009-03-24 13:25:23 +0000 | [diff] [blame] | 39 | class RegisterAllocator; |
| 40 | class RegisterFile; |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 41 | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 42 | enum InitState { CONST_INIT, NOT_CONST_INIT }; |
| 43 | enum TypeofState { INSIDE_TYPEOF, NOT_INSIDE_TYPEOF }; |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 44 | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 45 | |
| 46 | // ------------------------------------------------------------------------- |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 47 | // Reference support |
| 48 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 49 | // A reference is a C++ stack-allocated object that puts a |
| 50 | // reference on the virtual frame. The reference may be consumed |
| 51 | // by GetValue, TakeValue, SetValue, and Codegen::UnloadReference. |
| 52 | // When the lifetime (scope) of a valid reference ends, it must have |
| 53 | // been consumed, and be in state UNLOADED. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 54 | class Reference BASE_EMBEDDED { |
| 55 | public: |
| 56 | // The values of the types is important, see size(). |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 57 | enum Type { UNLOADED = -2, ILLEGAL = -1, SLOT = 0, NAMED = 1, KEYED = 2 }; |
| 58 | Reference(CodeGenerator* cgen, |
| 59 | Expression* expression, |
| 60 | bool persist_after_get = false); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 61 | ~Reference(); |
| 62 | |
| 63 | Expression* expression() const { return expression_; } |
| 64 | Type type() const { return type_; } |
| 65 | void set_type(Type value) { |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 66 | ASSERT_EQ(ILLEGAL, type_); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 67 | type_ = value; |
| 68 | } |
| 69 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 70 | void set_unloaded() { |
| 71 | ASSERT_NE(ILLEGAL, type_); |
| 72 | ASSERT_NE(UNLOADED, type_); |
| 73 | type_ = UNLOADED; |
| 74 | } |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 75 | // The size the reference takes up on the stack. |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 76 | int size() const { |
| 77 | return (type_ < SLOT) ? 0 : type_; |
| 78 | } |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 79 | |
| 80 | bool is_illegal() const { return type_ == ILLEGAL; } |
| 81 | bool is_slot() const { return type_ == SLOT; } |
| 82 | bool is_property() const { return type_ == NAMED || type_ == KEYED; } |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 83 | bool is_unloaded() const { return type_ == UNLOADED; } |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 84 | |
| 85 | // Return the name. Only valid for named property references. |
| 86 | Handle<String> GetName(); |
| 87 | |
| 88 | // Generate code to push the value of the reference on top of the |
| 89 | // expression stack. The reference is expected to be already on top of |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 90 | // the expression stack, and it is consumed by the call unless the |
| 91 | // reference is for a compound assignment. |
| 92 | // If the reference is not consumed, it is left in place under its value. |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 93 | void GetValue(); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 94 | |
| 95 | // Generate code to store the value on top of the expression stack in the |
| 96 | // reference. The reference is expected to be immediately below the value |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 97 | // on the expression stack. The value is stored in the location specified |
| 98 | // by the reference, and is left on top of the stack, after the reference |
| 99 | // is popped from beneath it (unloaded). |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 100 | void SetValue(InitState init_state); |
| 101 | |
| 102 | private: |
| 103 | CodeGenerator* cgen_; |
| 104 | Expression* expression_; |
| 105 | Type type_; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 106 | // Keep the reference on the stack after get, so it can be used by set later. |
| 107 | bool persist_after_get_; |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 108 | }; |
| 109 | |
| 110 | |
| 111 | // ------------------------------------------------------------------------- |
| 112 | // Code generation state |
| 113 | |
| 114 | // The state is passed down the AST by the code generator (and back up, in |
| 115 | // the form of the state of the label pair). It is threaded through the |
| 116 | // call stack. Constructing a state implicitly pushes it on the owning code |
| 117 | // generator's stack of states, and destroying one implicitly pops it. |
| 118 | |
| 119 | class CodeGenState BASE_EMBEDDED { |
| 120 | public: |
| 121 | // Create an initial code generator state. Destroying the initial state |
| 122 | // leaves the code generator with a NULL state. |
| 123 | explicit CodeGenState(CodeGenerator* owner); |
| 124 | |
| 125 | // Create a code generator state based on a code generator's current |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 126 | // state. The new state has its own pair of branch labels. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 127 | CodeGenState(CodeGenerator* owner, |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 128 | JumpTarget* true_target, |
| 129 | JumpTarget* false_target); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 130 | |
| 131 | // Destroy a code generator state and restore the owning code generator's |
| 132 | // previous state. |
| 133 | ~CodeGenState(); |
| 134 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 135 | JumpTarget* true_target() const { return true_target_; } |
| 136 | JumpTarget* false_target() const { return false_target_; } |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 137 | |
| 138 | private: |
| 139 | CodeGenerator* owner_; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 140 | JumpTarget* true_target_; |
| 141 | JumpTarget* false_target_; |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 142 | CodeGenState* previous_; |
| 143 | }; |
| 144 | |
| 145 | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 146 | // ------------------------------------------------------------------------- |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 147 | // CodeGenerator |
| 148 | |
ager@chromium.org | a74f0da | 2008-12-03 16:05:52 +0000 | [diff] [blame] | 149 | class CodeGenerator: public AstVisitor { |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 150 | public: |
| 151 | // Takes a function literal, generates code for it. This function should only |
| 152 | // be called by compiler.cc. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 153 | static Handle<Code> MakeCode(CompilationInfo* info); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 154 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 155 | // Printing of AST, etc. as requested by flags. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 156 | static void MakeCodePrologue(CompilationInfo* info); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 157 | |
| 158 | // Allocate and install the code. |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 159 | static Handle<Code> MakeCodeEpilogue(MacroAssembler* masm, |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 160 | Code::Flags flags, |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 161 | CompilationInfo* info); |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 162 | |
christian.plesner.hansen@gmail.com | aca4968 | 2009-01-07 14:29:04 +0000 | [diff] [blame] | 163 | #ifdef ENABLE_LOGGING_AND_PROFILING |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 164 | static bool ShouldGenerateLog(Expression* type); |
christian.plesner.hansen@gmail.com | aca4968 | 2009-01-07 14:29:04 +0000 | [diff] [blame] | 165 | #endif |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 166 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 167 | static void SetFunctionInfo(Handle<JSFunction> fun, |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 168 | FunctionLiteral* lit, |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 169 | bool is_toplevel, |
sgjesse@chromium.org | 911335c | 2009-08-19 12:59:44 +0000 | [diff] [blame] | 170 | Handle<Script> script); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 171 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 172 | static void RecordPositions(MacroAssembler* masm, int pos); |
| 173 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 174 | // Accessors |
| 175 | MacroAssembler* masm() { return masm_; } |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 176 | VirtualFrame* frame() const { return frame_; } |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 177 | inline Handle<Script> script(); |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 178 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 179 | bool has_valid_frame() const { return frame_ != NULL; } |
| 180 | |
| 181 | // Set the virtual frame to be new_frame, with non-frame register |
| 182 | // reference counts given by non_frame_registers. The non-frame |
| 183 | // register reference counts of the old frame are returned in |
| 184 | // non_frame_registers. |
| 185 | void SetFrame(VirtualFrame* new_frame, RegisterFile* non_frame_registers); |
| 186 | |
| 187 | void DeleteFrame(); |
| 188 | |
| 189 | RegisterAllocator* allocator() const { return allocator_; } |
| 190 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 191 | CodeGenState* state() { return state_; } |
| 192 | void set_state(CodeGenState* state) { state_ = state; } |
| 193 | |
| 194 | void AddDeferred(DeferredCode* code) { deferred_.Add(code); } |
| 195 | |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 196 | static const int kUnknownIntValue = -1; |
| 197 | |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 198 | // If the name is an inline runtime function call return the number of |
| 199 | // expected arguments. Otherwise return -1. |
| 200 | static int InlineRuntimeCallArgumentsCount(Handle<String> name); |
| 201 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 202 | private: |
| 203 | // Construction/Destruction |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 204 | explicit CodeGenerator(MacroAssembler* masm); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 205 | |
| 206 | // Accessors |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 207 | inline bool is_eval(); |
sgjesse@chromium.org | 833cdd7 | 2010-02-26 10:06:16 +0000 | [diff] [blame] | 208 | inline Scope* scope(); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 209 | |
sgjesse@chromium.org | 755c5b1 | 2009-05-29 11:04:38 +0000 | [diff] [blame] | 210 | // Generating deferred code. |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 211 | void ProcessDeferred(); |
| 212 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 213 | // State |
| 214 | bool has_cc() const { return cc_reg_ != al; } |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 215 | JumpTarget* true_target() const { return state_->true_target(); } |
| 216 | JumpTarget* false_target() const { return state_->false_target(); } |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 217 | |
kasperl@chromium.org | 71affb5 | 2009-05-26 05:44:31 +0000 | [diff] [blame] | 218 | // We don't track loop nesting level on ARM yet. |
| 219 | int loop_nesting() const { return 0; } |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 220 | |
| 221 | // Node visitors. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 222 | void VisitStatements(ZoneList<Statement*>* statements); |
| 223 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 224 | #define DEF_VISIT(type) \ |
| 225 | void Visit##type(type* node); |
sgjesse@chromium.org | 0b6db59 | 2009-07-30 14:48:31 +0000 | [diff] [blame] | 226 | AST_NODE_LIST(DEF_VISIT) |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 227 | #undef DEF_VISIT |
| 228 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 229 | // Visit a statement and then spill the virtual frame if control flow can |
| 230 | // reach the end of the statement (ie, it does not exit via break, |
| 231 | // continue, return, or throw). This function is used temporarily while |
| 232 | // the code generator is being transformed. |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 233 | inline void VisitAndSpill(Statement* statement); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 234 | |
| 235 | // Visit a list of statements and then spill the virtual frame if control |
| 236 | // flow can reach the end of the list. |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 237 | inline void VisitStatementsAndSpill(ZoneList<Statement*>* statements); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 238 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 239 | // Main code generation function |
fschneider@chromium.org | b95b98b | 2010-02-23 10:34:29 +0000 | [diff] [blame] | 240 | void Generate(CompilationInfo* info); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 241 | |
| 242 | // The following are used by class Reference. |
| 243 | void LoadReference(Reference* ref); |
| 244 | void UnloadReference(Reference* ref); |
| 245 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 246 | static MemOperand ContextOperand(Register context, int index) { |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 247 | return MemOperand(context, Context::SlotOffset(index)); |
| 248 | } |
| 249 | |
| 250 | MemOperand SlotOperand(Slot* slot, Register tmp); |
| 251 | |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 252 | MemOperand ContextSlotOperandCheckExtensions(Slot* slot, |
| 253 | Register tmp, |
| 254 | Register tmp2, |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 255 | JumpTarget* slow); |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 256 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 257 | // Expressions |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 258 | static MemOperand GlobalObject() { |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 259 | return ContextOperand(cp, Context::GLOBAL_INDEX); |
| 260 | } |
| 261 | |
| 262 | void LoadCondition(Expression* x, |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 263 | JumpTarget* true_target, |
| 264 | JumpTarget* false_target, |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 265 | bool force_cc); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 266 | void Load(Expression* expr); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 267 | void LoadGlobal(); |
kasperl@chromium.org | 5a8ca6c | 2008-10-23 13:57:19 +0000 | [diff] [blame] | 268 | void LoadGlobalReceiver(Register scratch); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 269 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 270 | // Generate code to push the value of an expression on top of the frame |
| 271 | // and then spill the frame fully to memory. This function is used |
| 272 | // temporarily while the code generator is being transformed. |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 273 | inline void LoadAndSpill(Expression* expression); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 274 | |
| 275 | // Call LoadCondition and then spill the virtual frame unless control flow |
| 276 | // cannot reach the end of the expression (ie, by emitting only |
| 277 | // unconditional jumps to the control targets). |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 278 | inline void LoadConditionAndSpill(Expression* expression, |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 279 | JumpTarget* true_target, |
| 280 | JumpTarget* false_target, |
| 281 | bool force_control); |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 282 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 283 | // Read a value from a slot and leave it on top of the expression stack. |
| 284 | void LoadFromSlot(Slot* slot, TypeofState typeof_state); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 285 | // Store the value on top of the stack to a slot. |
| 286 | void StoreToSlot(Slot* slot, InitState init_state); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 287 | // Load a keyed property, leaving it in r0. The receiver and key are |
| 288 | // passed on the stack, and remain there. |
| 289 | void EmitKeyedLoad(bool is_global); |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 290 | |
ager@chromium.org | 381abbb | 2009-02-25 13:23:22 +0000 | [diff] [blame] | 291 | void LoadFromGlobalSlotCheckExtensions(Slot* slot, |
| 292 | TypeofState typeof_state, |
| 293 | Register tmp, |
| 294 | Register tmp2, |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 295 | JumpTarget* slow); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 296 | |
| 297 | // Special code for typeof expressions: Unfortunately, we must |
| 298 | // be careful when loading the expression in 'typeof' |
| 299 | // expressions. We are not allowed to throw reference errors for |
| 300 | // non-existing properties of the global object, so we must make it |
| 301 | // look like an explicit property access, instead of an access |
| 302 | // through the context chain. |
| 303 | void LoadTypeofExpression(Expression* x); |
| 304 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 305 | void ToBoolean(JumpTarget* true_target, JumpTarget* false_target); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 306 | |
ager@chromium.org | b26c50a | 2010-03-26 09:27:16 +0000 | [diff] [blame] | 307 | // Generate code that computes a shortcutting logical operation. |
| 308 | void GenerateLogicalBooleanOperation(BinaryOperation* node); |
| 309 | |
kasperl@chromium.org | 86f77b7 | 2009-07-06 08:21:57 +0000 | [diff] [blame] | 310 | void GenericBinaryOperation(Token::Value op, |
| 311 | OverwriteMode overwrite_mode, |
| 312 | int known_rhs = kUnknownIntValue); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame^] | 313 | void VirtualFrameBinaryOperation(Token::Value op, |
| 314 | OverwriteMode overwrite_mode, |
| 315 | int known_rhs = kUnknownIntValue); |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 316 | void Comparison(Condition cc, |
| 317 | Expression* left, |
| 318 | Expression* right, |
| 319 | bool strict = false); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 320 | |
ager@chromium.org | 65dad4b | 2009-04-23 08:48:43 +0000 | [diff] [blame] | 321 | void SmiOperation(Token::Value op, |
| 322 | Handle<Object> value, |
| 323 | bool reversed, |
| 324 | OverwriteMode mode); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 325 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame^] | 326 | void VirtualFrameSmiOperation(Token::Value op, |
| 327 | Handle<Object> value, |
| 328 | bool reversed, |
| 329 | OverwriteMode mode); |
| 330 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 331 | void CallWithArguments(ZoneList<Expression*>* arguments, |
| 332 | CallFunctionFlags flags, |
| 333 | int position); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 334 | |
| 335 | // Control flow |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 336 | void Branch(bool if_true, JumpTarget* target); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 337 | void CheckStack(); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 338 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 339 | struct InlineRuntimeLUT { |
| 340 | void (CodeGenerator::*method)(ZoneList<Expression*>*); |
| 341 | const char* name; |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 342 | int nargs; |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 343 | }; |
| 344 | |
| 345 | static InlineRuntimeLUT* FindInlineRuntimeLUT(Handle<String> name); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 346 | bool CheckForInlineRuntimeCall(CallRuntime* node); |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 347 | static bool PatchInlineRuntimeEntry(Handle<String> name, |
| 348 | const InlineRuntimeLUT& new_entry, |
| 349 | InlineRuntimeLUT* old_entry); |
| 350 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 351 | static Handle<Code> ComputeLazyCompile(int argc); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 352 | void ProcessDeclarations(ZoneList<Declaration*>* declarations); |
| 353 | |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 354 | static Handle<Code> ComputeCallInitialize(int argc, InLoopFlag in_loop); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 355 | |
| 356 | // Declare global variables and functions in the given array of |
| 357 | // name/value pairs. |
| 358 | void DeclareGlobals(Handle<FixedArray> pairs); |
| 359 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 360 | // Instantiate the function based on the shared function info. |
| 361 | void InstantiateFunction(Handle<SharedFunctionInfo> function_info); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 362 | |
| 363 | // Support for type checks. |
| 364 | void GenerateIsSmi(ZoneList<Expression*>* args); |
| 365 | void GenerateIsNonNegativeSmi(ZoneList<Expression*>* args); |
| 366 | void GenerateIsArray(ZoneList<Expression*>* args); |
fschneider@chromium.org | b95b98b | 2010-02-23 10:34:29 +0000 | [diff] [blame] | 367 | void GenerateIsRegExp(ZoneList<Expression*>* args); |
ager@chromium.org | 6141cbe | 2009-11-20 12:14:52 +0000 | [diff] [blame] | 368 | void GenerateIsObject(ZoneList<Expression*>* args); |
| 369 | void GenerateIsFunction(ZoneList<Expression*>* args); |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 370 | void GenerateIsUndetectableObject(ZoneList<Expression*>* args); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 371 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 372 | // Support for construct call checks. |
| 373 | void GenerateIsConstructCall(ZoneList<Expression*>* args); |
| 374 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 375 | // Support for arguments.length and arguments[?]. |
| 376 | void GenerateArgumentsLength(ZoneList<Expression*>* args); |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 377 | void GenerateArguments(ZoneList<Expression*>* args); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 378 | |
kasperl@chromium.org | 2abc450 | 2009-07-02 07:00:29 +0000 | [diff] [blame] | 379 | // Support for accessing the class and value fields of an object. |
| 380 | void GenerateClassOf(ZoneList<Expression*>* args); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 381 | void GenerateValueOf(ZoneList<Expression*>* args); |
| 382 | void GenerateSetValueOf(ZoneList<Expression*>* args); |
| 383 | |
| 384 | // Fast support for charCodeAt(n). |
| 385 | void GenerateFastCharCodeAt(ZoneList<Expression*>* args); |
| 386 | |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 387 | // Fast support for string.charAt(n) and string[n]. |
| 388 | void GenerateCharFromCode(ZoneList<Expression*>* args); |
| 389 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 390 | // Fast support for object equality testing. |
| 391 | void GenerateObjectEquals(ZoneList<Expression*>* args); |
| 392 | |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 393 | void GenerateLog(ZoneList<Expression*>* args); |
| 394 | |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 395 | // Fast support for Math.random(). |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame^] | 396 | void GenerateRandomHeapNumber(ZoneList<Expression*>* args); |
ager@chromium.org | eadaf22 | 2009-06-16 09:43:10 +0000 | [diff] [blame] | 397 | |
sgjesse@chromium.org | ac6aa17 | 2009-12-04 12:29:05 +0000 | [diff] [blame] | 398 | // Fast support for StringAdd. |
| 399 | void GenerateStringAdd(ZoneList<Expression*>* args); |
| 400 | |
fschneider@chromium.org | 0c20e67 | 2010-01-14 15:28:53 +0000 | [diff] [blame] | 401 | // Fast support for SubString. |
| 402 | void GenerateSubString(ZoneList<Expression*>* args); |
| 403 | |
| 404 | // Fast support for StringCompare. |
| 405 | void GenerateStringCompare(ZoneList<Expression*>* args); |
| 406 | |
| 407 | // Support for direct calls from JavaScript to native RegExp code. |
| 408 | void GenerateRegExpExec(ZoneList<Expression*>* args); |
| 409 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 410 | // Fast support for number to string. |
| 411 | void GenerateNumberToString(ZoneList<Expression*>* args); |
| 412 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame^] | 413 | // Fast call for custom callbacks. |
| 414 | void GenerateCallFunction(ZoneList<Expression*>* args); |
| 415 | |
vegorov@chromium.org | f837290 | 2010-03-15 10:26:20 +0000 | [diff] [blame] | 416 | // Fast call to math functions. |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 417 | void GenerateMathPow(ZoneList<Expression*>* args); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 418 | void GenerateMathSin(ZoneList<Expression*>* args); |
| 419 | void GenerateMathCos(ZoneList<Expression*>* args); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 420 | void GenerateMathSqrt(ZoneList<Expression*>* args); |
| 421 | |
christian.plesner.hansen@gmail.com | 9d58c2b | 2009-10-16 11:48:38 +0000 | [diff] [blame] | 422 | // Simple condition analysis. |
| 423 | enum ConditionAnalysis { |
| 424 | ALWAYS_TRUE, |
| 425 | ALWAYS_FALSE, |
| 426 | DONT_KNOW |
| 427 | }; |
| 428 | ConditionAnalysis AnalyzeCondition(Expression* cond); |
| 429 | |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 430 | // Methods used to indicate which source code is generated for. Source |
| 431 | // positions are collected by the assembler and emitted with the relocation |
| 432 | // information. |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 433 | void CodeForFunctionPosition(FunctionLiteral* fun); |
kasperl@chromium.org | 8ccb0be | 2009-04-07 07:21:39 +0000 | [diff] [blame] | 434 | void CodeForReturnPosition(FunctionLiteral* fun); |
sgjesse@chromium.org | c514574 | 2009-10-07 09:00:33 +0000 | [diff] [blame] | 435 | void CodeForStatementPosition(Statement* node); |
ager@chromium.org | c4c9272 | 2009-11-18 14:12:51 +0000 | [diff] [blame] | 436 | void CodeForDoWhileConditionPosition(DoWhileStatement* stmt); |
christian.plesner.hansen@gmail.com | 37abdec | 2009-01-06 14:43:28 +0000 | [diff] [blame] | 437 | void CodeForSourcePosition(int pos); |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 438 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 439 | #ifdef DEBUG |
| 440 | // True if the registers are valid for entry to a block. |
| 441 | bool HasValidEntryRegisters(); |
| 442 | #endif |
| 443 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 444 | List<DeferredCode*> deferred_; |
| 445 | |
| 446 | // Assembler |
| 447 | MacroAssembler* masm_; // to generate code |
| 448 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 449 | CompilationInfo* info_; |
| 450 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 451 | // Code generation state |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 452 | VirtualFrame* frame_; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 453 | RegisterAllocator* allocator_; |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 454 | Condition cc_reg_; |
| 455 | CodeGenState* state_; |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 456 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 457 | // Jump targets |
| 458 | BreakTarget function_return_; |
| 459 | |
| 460 | // True if the function return is shadowed (ie, jumping to the target |
| 461 | // function_return_ does not jump to the true function return, but rather |
| 462 | // to some unlinking code). |
| 463 | bool function_return_is_shadowed_; |
| 464 | |
ager@chromium.org | 9085a01 | 2009-05-11 19:22:57 +0000 | [diff] [blame] | 465 | static InlineRuntimeLUT kInlineRuntimeLUT[]; |
| 466 | |
ager@chromium.org | 3bf7b91 | 2008-11-17 09:09:45 +0000 | [diff] [blame] | 467 | friend class VirtualFrame; |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 468 | friend class JumpTarget; |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 469 | friend class Reference; |
ager@chromium.org | 3811b43 | 2009-10-28 14:53:37 +0000 | [diff] [blame] | 470 | friend class FastCodeGenerator; |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 471 | friend class FullCodeGenerator; |
| 472 | friend class FullCodeGenSyntaxChecker; |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 473 | |
| 474 | DISALLOW_COPY_AND_ASSIGN(CodeGenerator); |
| 475 | }; |
| 476 | |
kasperl@chromium.org | 7be3c99 | 2009-03-12 07:19:55 +0000 | [diff] [blame] | 477 | |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 478 | class GenericBinaryOpStub : public CodeStub { |
| 479 | public: |
| 480 | GenericBinaryOpStub(Token::Value op, |
| 481 | OverwriteMode mode, |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame^] | 482 | Register lhs, |
| 483 | Register rhs, |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 484 | int constant_rhs = CodeGenerator::kUnknownIntValue) |
| 485 | : op_(op), |
| 486 | mode_(mode), |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame^] | 487 | lhs_(lhs), |
| 488 | rhs_(rhs), |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 489 | constant_rhs_(constant_rhs), |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 490 | specialized_on_rhs_(RhsIsOneWeWantToOptimizeFor(op, constant_rhs)), |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame^] | 491 | runtime_operands_type_(BinaryOpIC::DEFAULT), |
| 492 | name_(NULL) { } |
| 493 | |
| 494 | GenericBinaryOpStub(int key, BinaryOpIC::TypeInfo type_info) |
| 495 | : op_(OpBits::decode(key)), |
| 496 | mode_(ModeBits::decode(key)), |
| 497 | lhs_(LhsRegister(RegisterBits::decode(key))), |
| 498 | rhs_(RhsRegister(RegisterBits::decode(key))), |
| 499 | constant_rhs_(KnownBitsForMinorKey(KnownIntBits::decode(key))), |
| 500 | specialized_on_rhs_(RhsIsOneWeWantToOptimizeFor(op_, constant_rhs_)), |
| 501 | runtime_operands_type_(type_info), |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 502 | name_(NULL) { } |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 503 | |
| 504 | private: |
| 505 | Token::Value op_; |
| 506 | OverwriteMode mode_; |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame^] | 507 | Register lhs_; |
| 508 | Register rhs_; |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 509 | int constant_rhs_; |
| 510 | bool specialized_on_rhs_; |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame^] | 511 | BinaryOpIC::TypeInfo runtime_operands_type_; |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 512 | char* name_; |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 513 | |
| 514 | static const int kMaxKnownRhs = 0x40000000; |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame^] | 515 | static const int kKnownRhsKeyBits = 6; |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 516 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame^] | 517 | // Minor key encoding in 17 bits. |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 518 | class ModeBits: public BitField<OverwriteMode, 0, 2> {}; |
| 519 | class OpBits: public BitField<Token::Value, 2, 6> {}; |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame^] | 520 | class TypeInfoBits: public BitField<int, 8, 2> {}; |
| 521 | class RegisterBits: public BitField<bool, 10, 1> {}; |
| 522 | class KnownIntBits: public BitField<int, 11, kKnownRhsKeyBits> {}; |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 523 | |
| 524 | Major MajorKey() { return GenericBinaryOp; } |
| 525 | int MinorKey() { |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame^] | 526 | ASSERT((lhs_.is(r0) && rhs_.is(r1)) || |
| 527 | (lhs_.is(r1) && rhs_.is(r0))); |
| 528 | // Encode the parameters in a unique 18 bit value. |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 529 | return OpBits::encode(op_) |
| 530 | | ModeBits::encode(mode_) |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame^] | 531 | | KnownIntBits::encode(MinorKeyForKnownInt()) |
| 532 | | TypeInfoBits::encode(runtime_operands_type_) |
| 533 | | RegisterBits::encode(lhs_.is(r0)); |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 534 | } |
| 535 | |
| 536 | void Generate(MacroAssembler* masm); |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame^] | 537 | void HandleNonSmiBitwiseOp(MacroAssembler* masm, Register lhs, Register rhs); |
| 538 | void HandleBinaryOpSlowCases(MacroAssembler* masm, |
| 539 | Label* not_smi, |
| 540 | Register lhs, |
| 541 | Register rhs, |
| 542 | const Builtins::JavaScript& builtin); |
| 543 | void GenerateTypeTransition(MacroAssembler* masm); |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 544 | |
| 545 | static bool RhsIsOneWeWantToOptimizeFor(Token::Value op, int constant_rhs) { |
| 546 | if (constant_rhs == CodeGenerator::kUnknownIntValue) return false; |
| 547 | if (op == Token::DIV) return constant_rhs >= 2 && constant_rhs <= 3; |
| 548 | if (op == Token::MOD) { |
| 549 | if (constant_rhs <= 1) return false; |
| 550 | if (constant_rhs <= 10) return true; |
| 551 | if (constant_rhs <= kMaxKnownRhs && IsPowerOf2(constant_rhs)) return true; |
| 552 | return false; |
| 553 | } |
| 554 | return false; |
| 555 | } |
| 556 | |
| 557 | int MinorKeyForKnownInt() { |
| 558 | if (!specialized_on_rhs_) return 0; |
| 559 | if (constant_rhs_ <= 10) return constant_rhs_ + 1; |
| 560 | ASSERT(IsPowerOf2(constant_rhs_)); |
| 561 | int key = 12; |
| 562 | int d = constant_rhs_; |
| 563 | while ((d & 1) == 0) { |
| 564 | key++; |
| 565 | d >>= 1; |
| 566 | } |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame^] | 567 | ASSERT(key >= 0 && key < (1 << kKnownRhsKeyBits)); |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 568 | return key; |
| 569 | } |
| 570 | |
ager@chromium.org | 357bf65 | 2010-04-12 11:30:10 +0000 | [diff] [blame^] | 571 | int KnownBitsForMinorKey(int key) { |
| 572 | if (!key) return 0; |
| 573 | if (key <= 11) return key - 1; |
| 574 | int d = 1; |
| 575 | while (key != 12) { |
| 576 | key--; |
| 577 | d <<= 1; |
| 578 | } |
| 579 | return d; |
| 580 | } |
| 581 | |
| 582 | Register LhsRegister(bool lhs_is_r0) { |
| 583 | return lhs_is_r0 ? r0 : r1; |
| 584 | } |
| 585 | |
| 586 | Register RhsRegister(bool lhs_is_r0) { |
| 587 | return lhs_is_r0 ? r1 : r0; |
| 588 | } |
| 589 | |
| 590 | bool ShouldGenerateSmiCode() { |
| 591 | return ((op_ != Token::DIV && op_ != Token::MOD) || specialized_on_rhs_) && |
| 592 | runtime_operands_type_ != BinaryOpIC::HEAP_NUMBERS && |
| 593 | runtime_operands_type_ != BinaryOpIC::STRINGS; |
| 594 | } |
| 595 | |
| 596 | bool ShouldGenerateFPCode() { |
| 597 | return runtime_operands_type_ != BinaryOpIC::STRINGS; |
| 598 | } |
| 599 | |
| 600 | virtual int GetCodeKind() { return Code::BINARY_OP_IC; } |
| 601 | |
| 602 | virtual InlineCacheState GetICState() { |
| 603 | return BinaryOpIC::ToState(runtime_operands_type_); |
| 604 | } |
| 605 | |
kmillikin@chromium.org | 13bd294 | 2009-12-16 15:36:05 +0000 | [diff] [blame] | 606 | const char* GetName(); |
christian.plesner.hansen@gmail.com | 5a6af92 | 2009-08-12 14:20:51 +0000 | [diff] [blame] | 607 | |
| 608 | #ifdef DEBUG |
| 609 | void Print() { |
| 610 | if (!specialized_on_rhs_) { |
| 611 | PrintF("GenericBinaryOpStub (%s)\n", Token::String(op_)); |
| 612 | } else { |
| 613 | PrintF("GenericBinaryOpStub (%s by %d)\n", |
| 614 | Token::String(op_), |
| 615 | constant_rhs_); |
| 616 | } |
| 617 | } |
| 618 | #endif |
| 619 | }; |
| 620 | |
| 621 | |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 622 | class StringStubBase: public CodeStub { |
| 623 | public: |
| 624 | // Generate code for copying characters using a simple loop. This should only |
| 625 | // be used in places where the number of characters is small and the |
| 626 | // additional setup and checking in GenerateCopyCharactersLong adds too much |
| 627 | // overhead. Copying of overlapping regions is not supported. |
| 628 | // Dest register ends at the position after the last character written. |
| 629 | void GenerateCopyCharacters(MacroAssembler* masm, |
| 630 | Register dest, |
| 631 | Register src, |
| 632 | Register count, |
| 633 | Register scratch, |
| 634 | bool ascii); |
| 635 | |
| 636 | // Generate code for copying a large number of characters. This function |
| 637 | // is allowed to spend extra time setting up conditions to make copying |
| 638 | // faster. Copying of overlapping regions is not supported. |
| 639 | // Dest register ends at the position after the last character written. |
| 640 | void GenerateCopyCharactersLong(MacroAssembler* masm, |
| 641 | Register dest, |
| 642 | Register src, |
| 643 | Register count, |
| 644 | Register scratch1, |
| 645 | Register scratch2, |
| 646 | Register scratch3, |
| 647 | Register scratch4, |
| 648 | Register scratch5, |
| 649 | int flags); |
ager@chromium.org | ce5e87b | 2010-03-10 10:24:18 +0000 | [diff] [blame] | 650 | |
| 651 | |
| 652 | // Probe the symbol table for a two character string. If the string is |
| 653 | // not found by probing a jump to the label not_found is performed. This jump |
| 654 | // does not guarantee that the string is not in the symbol table. If the |
| 655 | // string is found the code falls through with the string in register r0. |
| 656 | // Contents of both c1 and c2 registers are modified. At the exit c1 is |
| 657 | // guaranteed to contain halfword with low and high bytes equal to |
| 658 | // initial contents of c1 and c2 respectively. |
| 659 | void GenerateTwoCharacterSymbolTableProbe(MacroAssembler* masm, |
| 660 | Register c1, |
| 661 | Register c2, |
| 662 | Register scratch1, |
| 663 | Register scratch2, |
| 664 | Register scratch3, |
| 665 | Register scratch4, |
| 666 | Register scratch5, |
| 667 | Label* not_found); |
| 668 | |
| 669 | // Generate string hash. |
| 670 | void GenerateHashInit(MacroAssembler* masm, |
| 671 | Register hash, |
| 672 | Register character); |
| 673 | |
| 674 | void GenerateHashAddCharacter(MacroAssembler* masm, |
| 675 | Register hash, |
| 676 | Register character); |
| 677 | |
| 678 | void GenerateHashGetHash(MacroAssembler* masm, |
| 679 | Register hash); |
ager@chromium.org | 5c83825 | 2010-02-19 08:53:10 +0000 | [diff] [blame] | 680 | }; |
| 681 | |
| 682 | |
| 683 | // Flag that indicates how to generate code for the stub StringAddStub. |
| 684 | enum StringAddFlags { |
| 685 | NO_STRING_ADD_FLAGS = 0, |
| 686 | NO_STRING_CHECK_IN_STUB = 1 << 0 // Omit string check in stub. |
| 687 | }; |
| 688 | |
| 689 | |
| 690 | class StringAddStub: public StringStubBase { |
| 691 | public: |
| 692 | explicit StringAddStub(StringAddFlags flags) { |
| 693 | string_check_ = ((flags & NO_STRING_CHECK_IN_STUB) == 0); |
| 694 | } |
| 695 | |
| 696 | private: |
| 697 | Major MajorKey() { return StringAdd; } |
| 698 | int MinorKey() { return string_check_ ? 0 : 1; } |
| 699 | |
| 700 | void Generate(MacroAssembler* masm); |
| 701 | |
| 702 | // Should the stub check whether arguments are strings? |
| 703 | bool string_check_; |
| 704 | }; |
| 705 | |
| 706 | |
| 707 | class SubStringStub: public StringStubBase { |
| 708 | public: |
| 709 | SubStringStub() {} |
| 710 | |
| 711 | private: |
| 712 | Major MajorKey() { return SubString; } |
| 713 | int MinorKey() { return 0; } |
| 714 | |
| 715 | void Generate(MacroAssembler* masm); |
| 716 | }; |
| 717 | |
| 718 | |
| 719 | |
sgjesse@chromium.org | b302e56 | 2010-02-03 11:26:59 +0000 | [diff] [blame] | 720 | class StringCompareStub: public CodeStub { |
| 721 | public: |
| 722 | StringCompareStub() { } |
| 723 | |
| 724 | // Compare two flat ASCII strings and returns result in r0. |
| 725 | // Does not use the stack. |
| 726 | static void GenerateCompareFlatAsciiStrings(MacroAssembler* masm, |
| 727 | Register left, |
| 728 | Register right, |
| 729 | Register scratch1, |
| 730 | Register scratch2, |
| 731 | Register scratch3, |
| 732 | Register scratch4); |
| 733 | |
| 734 | private: |
| 735 | Major MajorKey() { return StringCompare; } |
| 736 | int MinorKey() { return 0; } |
| 737 | |
| 738 | void Generate(MacroAssembler* masm); |
| 739 | }; |
| 740 | |
| 741 | |
kmillikin@chromium.org | 5d8f0e6 | 2010-03-24 08:21:20 +0000 | [diff] [blame] | 742 | // This stub can convert a signed int32 to a heap number (double). It does |
| 743 | // not work for int32s that are in Smi range! No GC occurs during this stub |
| 744 | // so you don't have to set up the frame. |
| 745 | class WriteInt32ToHeapNumberStub : public CodeStub { |
| 746 | public: |
| 747 | WriteInt32ToHeapNumberStub(Register the_int, |
| 748 | Register the_heap_number, |
| 749 | Register scratch) |
| 750 | : the_int_(the_int), |
| 751 | the_heap_number_(the_heap_number), |
| 752 | scratch_(scratch) { } |
| 753 | |
| 754 | private: |
| 755 | Register the_int_; |
| 756 | Register the_heap_number_; |
| 757 | Register scratch_; |
| 758 | |
| 759 | // Minor key encoding in 16 bits. |
| 760 | class IntRegisterBits: public BitField<int, 0, 4> {}; |
| 761 | class HeapNumberRegisterBits: public BitField<int, 4, 4> {}; |
| 762 | class ScratchRegisterBits: public BitField<int, 8, 4> {}; |
| 763 | |
| 764 | Major MajorKey() { return WriteInt32ToHeapNumber; } |
| 765 | int MinorKey() { |
| 766 | // Encode the parameters in a unique 16 bit value. |
| 767 | return IntRegisterBits::encode(the_int_.code()) |
| 768 | | HeapNumberRegisterBits::encode(the_heap_number_.code()) |
| 769 | | ScratchRegisterBits::encode(scratch_.code()); |
| 770 | } |
| 771 | |
| 772 | void Generate(MacroAssembler* masm); |
| 773 | |
| 774 | const char* GetName() { return "WriteInt32ToHeapNumberStub"; } |
| 775 | |
| 776 | #ifdef DEBUG |
| 777 | void Print() { PrintF("WriteInt32ToHeapNumberStub\n"); } |
| 778 | #endif |
| 779 | }; |
| 780 | |
| 781 | |
fschneider@chromium.org | 086aac6 | 2010-03-17 13:18:24 +0000 | [diff] [blame] | 782 | class NumberToStringStub: public CodeStub { |
| 783 | public: |
| 784 | NumberToStringStub() { } |
| 785 | |
| 786 | // Generate code to do a lookup in the number string cache. If the number in |
| 787 | // the register object is found in the cache the generated code falls through |
| 788 | // with the result in the result register. The object and the result register |
| 789 | // can be the same. If the number is not found in the cache the code jumps to |
| 790 | // the label not_found with only the content of register object unchanged. |
| 791 | static void GenerateLookupNumberStringCache(MacroAssembler* masm, |
| 792 | Register object, |
| 793 | Register result, |
| 794 | Register scratch1, |
| 795 | Register scratch2, |
| 796 | bool object_is_smi, |
| 797 | Label* not_found); |
| 798 | |
| 799 | private: |
| 800 | Major MajorKey() { return NumberToString; } |
| 801 | int MinorKey() { return 0; } |
| 802 | |
| 803 | void Generate(MacroAssembler* masm); |
| 804 | |
| 805 | const char* GetName() { return "NumberToStringStub"; } |
| 806 | |
| 807 | #ifdef DEBUG |
| 808 | void Print() { |
| 809 | PrintF("NumberToStringStub\n"); |
| 810 | } |
| 811 | #endif |
| 812 | }; |
| 813 | |
| 814 | |
ager@chromium.org | 7c537e2 | 2008-10-16 08:43:32 +0000 | [diff] [blame] | 815 | } } // namespace v8::internal |
| 816 | |
ager@chromium.org | 5ec4892 | 2009-05-05 07:25:34 +0000 | [diff] [blame] | 817 | #endif // V8_ARM_CODEGEN_ARM_H_ |