Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 1 | // Copyright 2010 the V8 project authors. All rights reserved. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +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 | |
| 28 | #ifndef V8_IA32_CODEGEN_IA32_H_ |
| 29 | #define V8_IA32_CODEGEN_IA32_H_ |
| 30 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame^] | 31 | #include "ic-inl.h" |
| 32 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 33 | namespace v8 { |
| 34 | namespace internal { |
| 35 | |
| 36 | // Forward declarations |
Leon Clarke | 4515c47 | 2010-02-03 11:58:03 +0000 | [diff] [blame] | 37 | class CompilationInfo; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 38 | class DeferredCode; |
| 39 | class RegisterAllocator; |
| 40 | class RegisterFile; |
| 41 | |
| 42 | enum InitState { CONST_INIT, NOT_CONST_INIT }; |
| 43 | enum TypeofState { INSIDE_TYPEOF, NOT_INSIDE_TYPEOF }; |
| 44 | |
| 45 | |
| 46 | // ------------------------------------------------------------------------- |
| 47 | // Reference support |
| 48 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +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. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 54 | class Reference BASE_EMBEDDED { |
| 55 | public: |
| 56 | // The values of the types is important, see size(). |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +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); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 61 | ~Reference(); |
| 62 | |
| 63 | Expression* expression() const { return expression_; } |
| 64 | Type type() const { return type_; } |
| 65 | void set_type(Type value) { |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 66 | ASSERT_EQ(ILLEGAL, type_); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 67 | type_ = value; |
| 68 | } |
| 69 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 70 | void set_unloaded() { |
| 71 | ASSERT_NE(ILLEGAL, type_); |
| 72 | ASSERT_NE(UNLOADED, type_); |
| 73 | type_ = UNLOADED; |
| 74 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 75 | // The size the reference takes up on the stack. |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 76 | int size() const { |
| 77 | return (type_ < SLOT) ? 0 : type_; |
| 78 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +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; } |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 83 | bool is_unloaded() const { return type_ == UNLOADED; } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +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 |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +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. |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 93 | void GetValue(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 94 | |
| 95 | // Like GetValue except that the slot is expected to be written to before |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 96 | // being read from again. The value of the reference may be invalidated, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 97 | // causing subsequent attempts to read it to fail. |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 98 | void TakeValue(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 99 | |
| 100 | // Generate code to store the value on top of the expression stack in the |
| 101 | // reference. The reference is expected to be immediately below the value |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 102 | // on the expression stack. The value is stored in the location specified |
| 103 | // by the reference, and is left on top of the stack, after the reference |
| 104 | // is popped from beneath it (unloaded). |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 105 | void SetValue(InitState init_state); |
| 106 | |
| 107 | private: |
| 108 | CodeGenerator* cgen_; |
| 109 | Expression* expression_; |
| 110 | Type type_; |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 111 | // Keep the reference on the stack after get, so it can be used by set later. |
| 112 | bool persist_after_get_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 113 | }; |
| 114 | |
| 115 | |
| 116 | // ------------------------------------------------------------------------- |
| 117 | // Control destinations. |
| 118 | |
| 119 | // A control destination encapsulates a pair of jump targets and a |
| 120 | // flag indicating which one is the preferred fall-through. The |
| 121 | // preferred fall-through must be unbound, the other may be already |
| 122 | // bound (ie, a backward target). |
| 123 | // |
| 124 | // The true and false targets may be jumped to unconditionally or |
| 125 | // control may split conditionally. Unconditional jumping and |
| 126 | // splitting should be emitted in tail position (as the last thing |
| 127 | // when compiling an expression) because they can cause either label |
| 128 | // to be bound or the non-fall through to be jumped to leaving an |
| 129 | // invalid virtual frame. |
| 130 | // |
| 131 | // The labels in the control destination can be extracted and |
| 132 | // manipulated normally without affecting the state of the |
| 133 | // destination. |
| 134 | |
| 135 | class ControlDestination BASE_EMBEDDED { |
| 136 | public: |
| 137 | ControlDestination(JumpTarget* true_target, |
| 138 | JumpTarget* false_target, |
| 139 | bool true_is_fall_through) |
| 140 | : true_target_(true_target), |
| 141 | false_target_(false_target), |
| 142 | true_is_fall_through_(true_is_fall_through), |
| 143 | is_used_(false) { |
| 144 | ASSERT(true_is_fall_through ? !true_target->is_bound() |
| 145 | : !false_target->is_bound()); |
| 146 | } |
| 147 | |
| 148 | // Accessors for the jump targets. Directly jumping or branching to |
| 149 | // or binding the targets will not update the destination's state. |
| 150 | JumpTarget* true_target() const { return true_target_; } |
| 151 | JumpTarget* false_target() const { return false_target_; } |
| 152 | |
| 153 | // True if the the destination has been jumped to unconditionally or |
| 154 | // control has been split to both targets. This predicate does not |
| 155 | // test whether the targets have been extracted and manipulated as |
| 156 | // raw jump targets. |
| 157 | bool is_used() const { return is_used_; } |
| 158 | |
| 159 | // True if the destination is used and the true target (respectively |
| 160 | // false target) was the fall through. If the target is backward, |
| 161 | // "fall through" included jumping unconditionally to it. |
| 162 | bool true_was_fall_through() const { |
| 163 | return is_used_ && true_is_fall_through_; |
| 164 | } |
| 165 | |
| 166 | bool false_was_fall_through() const { |
| 167 | return is_used_ && !true_is_fall_through_; |
| 168 | } |
| 169 | |
| 170 | // Emit a branch to one of the true or false targets, and bind the |
| 171 | // other target. Because this binds the fall-through target, it |
| 172 | // should be emitted in tail position (as the last thing when |
| 173 | // compiling an expression). |
| 174 | void Split(Condition cc) { |
| 175 | ASSERT(!is_used_); |
| 176 | if (true_is_fall_through_) { |
| 177 | false_target_->Branch(NegateCondition(cc)); |
| 178 | true_target_->Bind(); |
| 179 | } else { |
| 180 | true_target_->Branch(cc); |
| 181 | false_target_->Bind(); |
| 182 | } |
| 183 | is_used_ = true; |
| 184 | } |
| 185 | |
| 186 | // Emit an unconditional jump in tail position, to the true target |
| 187 | // (if the argument is true) or the false target. The "jump" will |
| 188 | // actually bind the jump target if it is forward, jump to it if it |
| 189 | // is backward. |
| 190 | void Goto(bool where) { |
| 191 | ASSERT(!is_used_); |
| 192 | JumpTarget* target = where ? true_target_ : false_target_; |
| 193 | if (target->is_bound()) { |
| 194 | target->Jump(); |
| 195 | } else { |
| 196 | target->Bind(); |
| 197 | } |
| 198 | is_used_ = true; |
| 199 | true_is_fall_through_ = where; |
| 200 | } |
| 201 | |
| 202 | // Mark this jump target as used as if Goto had been called, but |
| 203 | // without generating a jump or binding a label (the control effect |
| 204 | // should have already happened). This is used when the left |
| 205 | // subexpression of the short-circuit boolean operators are |
| 206 | // compiled. |
| 207 | void Use(bool where) { |
| 208 | ASSERT(!is_used_); |
| 209 | ASSERT((where ? true_target_ : false_target_)->is_bound()); |
| 210 | is_used_ = true; |
| 211 | true_is_fall_through_ = where; |
| 212 | } |
| 213 | |
| 214 | // Swap the true and false targets but keep the same actual label as |
| 215 | // the fall through. This is used when compiling negated |
| 216 | // expressions, where we want to swap the targets but preserve the |
| 217 | // state. |
| 218 | void Invert() { |
| 219 | JumpTarget* temp_target = true_target_; |
| 220 | true_target_ = false_target_; |
| 221 | false_target_ = temp_target; |
| 222 | |
| 223 | true_is_fall_through_ = !true_is_fall_through_; |
| 224 | } |
| 225 | |
| 226 | private: |
| 227 | // True and false jump targets. |
| 228 | JumpTarget* true_target_; |
| 229 | JumpTarget* false_target_; |
| 230 | |
| 231 | // Before using the destination: true if the true target is the |
| 232 | // preferred fall through, false if the false target is. After |
| 233 | // using the destination: true if the true target was actually used |
| 234 | // as the fall through, false if the false target was. |
| 235 | bool true_is_fall_through_; |
| 236 | |
| 237 | // True if the Split or Goto functions have been called. |
| 238 | bool is_used_; |
| 239 | }; |
| 240 | |
| 241 | |
| 242 | // ------------------------------------------------------------------------- |
| 243 | // Code generation state |
| 244 | |
| 245 | // The state is passed down the AST by the code generator (and back up, in |
| 246 | // the form of the state of the jump target pair). It is threaded through |
| 247 | // the call stack. Constructing a state implicitly pushes it on the owning |
| 248 | // code generator's stack of states, and destroying one implicitly pops it. |
| 249 | // |
| 250 | // The code generator state is only used for expressions, so statements have |
| 251 | // the initial state. |
| 252 | |
| 253 | class CodeGenState BASE_EMBEDDED { |
| 254 | public: |
| 255 | // Create an initial code generator state. Destroying the initial state |
| 256 | // leaves the code generator with a NULL state. |
| 257 | explicit CodeGenState(CodeGenerator* owner); |
| 258 | |
| 259 | // Create a code generator state based on a code generator's current |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 260 | // state. The new state has its own control destination. |
| 261 | CodeGenState(CodeGenerator* owner, ControlDestination* destination); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 262 | |
| 263 | // Destroy a code generator state and restore the owning code generator's |
| 264 | // previous state. |
| 265 | ~CodeGenState(); |
| 266 | |
| 267 | // Accessors for the state. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 268 | ControlDestination* destination() const { return destination_; } |
| 269 | |
| 270 | private: |
| 271 | // The owning code generator. |
| 272 | CodeGenerator* owner_; |
| 273 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 274 | // A control destination in case the expression has a control-flow |
| 275 | // effect. |
| 276 | ControlDestination* destination_; |
| 277 | |
| 278 | // The previous state of the owning code generator, restored when |
| 279 | // this state is destroyed. |
| 280 | CodeGenState* previous_; |
| 281 | }; |
| 282 | |
| 283 | |
| 284 | // ------------------------------------------------------------------------- |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 285 | // Arguments allocation mode. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 286 | |
| 287 | enum ArgumentsAllocationMode { |
| 288 | NO_ARGUMENTS_ALLOCATION, |
| 289 | EAGER_ARGUMENTS_ALLOCATION, |
| 290 | LAZY_ARGUMENTS_ALLOCATION |
| 291 | }; |
| 292 | |
| 293 | |
| 294 | // ------------------------------------------------------------------------- |
| 295 | // CodeGenerator |
| 296 | |
| 297 | class CodeGenerator: public AstVisitor { |
| 298 | public: |
| 299 | // Takes a function literal, generates code for it. This function should only |
| 300 | // be called by compiler.cc. |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 301 | static Handle<Code> MakeCode(CompilationInfo* info); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 302 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 303 | // Printing of AST, etc. as requested by flags. |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 304 | static void MakeCodePrologue(CompilationInfo* info); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 305 | |
| 306 | // Allocate and install the code. |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 307 | static Handle<Code> MakeCodeEpilogue(MacroAssembler* masm, |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 308 | Code::Flags flags, |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 309 | CompilationInfo* info); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 310 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 311 | #ifdef ENABLE_LOGGING_AND_PROFILING |
| 312 | static bool ShouldGenerateLog(Expression* type); |
| 313 | #endif |
| 314 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 315 | static void RecordPositions(MacroAssembler* masm, int pos); |
| 316 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 317 | // Accessors |
| 318 | MacroAssembler* masm() { return masm_; } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 319 | VirtualFrame* frame() const { return frame_; } |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 320 | inline Handle<Script> script(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 321 | |
| 322 | bool has_valid_frame() const { return frame_ != NULL; } |
| 323 | |
| 324 | // Set the virtual frame to be new_frame, with non-frame register |
| 325 | // reference counts given by non_frame_registers. The non-frame |
| 326 | // register reference counts of the old frame are returned in |
| 327 | // non_frame_registers. |
| 328 | void SetFrame(VirtualFrame* new_frame, RegisterFile* non_frame_registers); |
| 329 | |
| 330 | void DeleteFrame(); |
| 331 | |
| 332 | RegisterAllocator* allocator() const { return allocator_; } |
| 333 | |
| 334 | CodeGenState* state() { return state_; } |
| 335 | void set_state(CodeGenState* state) { state_ = state; } |
| 336 | |
| 337 | void AddDeferred(DeferredCode* code) { deferred_.Add(code); } |
| 338 | |
| 339 | bool in_spilled_code() const { return in_spilled_code_; } |
| 340 | void set_in_spilled_code(bool flag) { in_spilled_code_ = flag; } |
| 341 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame^] | 342 | // If the name is an inline runtime function call return the number of |
| 343 | // expected arguments. Otherwise return -1. |
| 344 | static int InlineRuntimeCallArgumentsCount(Handle<String> name); |
| 345 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 346 | private: |
| 347 | // Construction/Destruction |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 348 | explicit CodeGenerator(MacroAssembler* masm); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 349 | |
| 350 | // Accessors |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 351 | inline bool is_eval(); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame^] | 352 | inline Scope* scope(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 353 | |
| 354 | // Generating deferred code. |
| 355 | void ProcessDeferred(); |
| 356 | |
| 357 | // State |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 358 | ControlDestination* destination() const { return state_->destination(); } |
| 359 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame^] | 360 | // Control of side-effect-free int32 expression compilation. |
| 361 | bool in_safe_int32_mode() { return in_safe_int32_mode_; } |
| 362 | void set_in_safe_int32_mode(bool value) { in_safe_int32_mode_ = value; } |
| 363 | bool safe_int32_mode_enabled() { |
| 364 | return FLAG_safe_int32_compiler && safe_int32_mode_enabled_; |
| 365 | } |
| 366 | void set_safe_int32_mode_enabled(bool value) { |
| 367 | safe_int32_mode_enabled_ = value; |
| 368 | } |
| 369 | void set_unsafe_bailout(BreakTarget* unsafe_bailout) { |
| 370 | unsafe_bailout_ = unsafe_bailout; |
| 371 | } |
| 372 | |
| 373 | // Take the Result that is an untagged int32, and convert it to a tagged |
| 374 | // Smi or HeapNumber. Remove the untagged_int32 flag from the result. |
| 375 | void ConvertInt32ResultToNumber(Result* value); |
| 376 | void ConvertInt32ResultToSmi(Result* value); |
| 377 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 378 | // Track loop nesting level. |
| 379 | int loop_nesting() const { return loop_nesting_; } |
| 380 | void IncrementLoopNesting() { loop_nesting_++; } |
| 381 | void DecrementLoopNesting() { loop_nesting_--; } |
| 382 | |
| 383 | // Node visitors. |
| 384 | void VisitStatements(ZoneList<Statement*>* statements); |
| 385 | |
| 386 | #define DEF_VISIT(type) \ |
| 387 | void Visit##type(type* node); |
| 388 | AST_NODE_LIST(DEF_VISIT) |
| 389 | #undef DEF_VISIT |
| 390 | |
| 391 | // Visit a statement and then spill the virtual frame if control flow can |
| 392 | // reach the end of the statement (ie, it does not exit via break, |
| 393 | // continue, return, or throw). This function is used temporarily while |
| 394 | // the code generator is being transformed. |
| 395 | void VisitAndSpill(Statement* statement); |
| 396 | |
| 397 | // Visit a list of statements and then spill the virtual frame if control |
| 398 | // flow can reach the end of the list. |
| 399 | void VisitStatementsAndSpill(ZoneList<Statement*>* statements); |
| 400 | |
| 401 | // Main code generation function |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 402 | void Generate(CompilationInfo* info); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 403 | |
| 404 | // Generate the return sequence code. Should be called no more than |
| 405 | // once per compiled function, immediately after binding the return |
| 406 | // target (which can not be done more than once). |
| 407 | void GenerateReturnSequence(Result* return_value); |
| 408 | |
| 409 | // Returns the arguments allocation mode. |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 410 | ArgumentsAllocationMode ArgumentsMode(); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 411 | |
| 412 | // Store the arguments object and allocate it if necessary. |
| 413 | Result StoreArgumentsObject(bool initial); |
| 414 | |
| 415 | // The following are used by class Reference. |
| 416 | void LoadReference(Reference* ref); |
| 417 | void UnloadReference(Reference* ref); |
| 418 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 419 | static Operand ContextOperand(Register context, int index) { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 420 | return Operand(context, Context::SlotOffset(index)); |
| 421 | } |
| 422 | |
| 423 | Operand SlotOperand(Slot* slot, Register tmp); |
| 424 | |
| 425 | Operand ContextSlotOperandCheckExtensions(Slot* slot, |
| 426 | Result tmp, |
| 427 | JumpTarget* slow); |
| 428 | |
| 429 | // Expressions |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 430 | static Operand GlobalObject() { |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 431 | return ContextOperand(esi, Context::GLOBAL_INDEX); |
| 432 | } |
| 433 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame^] | 434 | void LoadCondition(Expression* expr, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 435 | ControlDestination* destination, |
| 436 | bool force_control); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 437 | void Load(Expression* expr); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 438 | void LoadGlobal(); |
| 439 | void LoadGlobalReceiver(); |
| 440 | |
| 441 | // Generate code to push the value of an expression on top of the frame |
| 442 | // and then spill the frame fully to memory. This function is used |
| 443 | // temporarily while the code generator is being transformed. |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 444 | void LoadAndSpill(Expression* expression); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 445 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame^] | 446 | // Evaluate an expression and place its value on top of the frame, |
| 447 | // using, or not using, the side-effect-free expression compiler. |
| 448 | void LoadInSafeInt32Mode(Expression* expr, BreakTarget* unsafe_bailout); |
| 449 | void LoadWithSafeInt32ModeDisabled(Expression* expr); |
| 450 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 451 | // Read a value from a slot and leave it on top of the expression stack. |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 452 | Result LoadFromSlot(Slot* slot, TypeofState typeof_state); |
| 453 | Result LoadFromSlotCheckForArguments(Slot* slot, TypeofState typeof_state); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 454 | Result LoadFromGlobalSlotCheckExtensions(Slot* slot, |
| 455 | TypeofState typeof_state, |
| 456 | JumpTarget* slow); |
| 457 | |
| 458 | // Store the value on top of the expression stack into a slot, leaving the |
| 459 | // value in place. |
| 460 | void StoreToSlot(Slot* slot, InitState init_state); |
| 461 | |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 462 | // Support for compiling assignment expressions. |
| 463 | void EmitSlotAssignment(Assignment* node); |
| 464 | void EmitNamedPropertyAssignment(Assignment* node); |
| 465 | void EmitKeyedPropertyAssignment(Assignment* node); |
| 466 | |
| 467 | // Receiver is passed on the frame and consumed. |
| 468 | Result EmitNamedLoad(Handle<String> name, bool is_contextual); |
| 469 | |
| 470 | // If the store is contextual, value is passed on the frame and consumed. |
| 471 | // Otherwise, receiver and value are passed on the frame and consumed. |
| 472 | Result EmitNamedStore(Handle<String> name, bool is_contextual); |
| 473 | |
| 474 | // Receiver and key are passed on the frame and consumed. |
| 475 | Result EmitKeyedLoad(); |
| 476 | |
| 477 | // Receiver, key, and value are passed on the frame and consumed. |
| 478 | Result EmitKeyedStore(StaticType* key_type); |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 479 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 480 | // Special code for typeof expressions: Unfortunately, we must |
| 481 | // be careful when loading the expression in 'typeof' |
| 482 | // expressions. We are not allowed to throw reference errors for |
| 483 | // non-existing properties of the global object, so we must make it |
| 484 | // look like an explicit property access, instead of an access |
| 485 | // through the context chain. |
| 486 | void LoadTypeofExpression(Expression* x); |
| 487 | |
| 488 | // Translate the value on top of the frame into control flow to the |
| 489 | // control destination. |
| 490 | void ToBoolean(ControlDestination* destination); |
| 491 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame^] | 492 | // Generate code that computes a shortcutting logical operation. |
| 493 | void GenerateLogicalBooleanOperation(BinaryOperation* node); |
| 494 | |
| 495 | void GenericBinaryOperation(BinaryOperation* expr, |
| 496 | OverwriteMode overwrite_mode); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 497 | |
| 498 | // If possible, combine two constant smi values using op to produce |
| 499 | // a smi result, and push it on the virtual frame, all at compile time. |
| 500 | // Returns true if it succeeds. Otherwise it has no effect. |
| 501 | bool FoldConstantSmis(Token::Value op, int left, int right); |
| 502 | |
| 503 | // Emit code to perform a binary operation on a constant |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame^] | 504 | // smi and a likely smi. Consumes the Result operand. |
| 505 | Result ConstantSmiBinaryOperation(BinaryOperation* expr, |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 506 | Result* operand, |
| 507 | Handle<Object> constant_operand, |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 508 | bool reversed, |
| 509 | OverwriteMode overwrite_mode); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 510 | |
| 511 | // Emit code to perform a binary operation on two likely smis. |
| 512 | // The code to handle smi arguments is produced inline. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame^] | 513 | // Consumes the Results left and right. |
| 514 | Result LikelySmiBinaryOperation(BinaryOperation* expr, |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 515 | Result* left, |
| 516 | Result* right, |
| 517 | OverwriteMode overwrite_mode); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 518 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame^] | 519 | |
| 520 | // Emit code to perform a binary operation on two untagged int32 values. |
| 521 | // The values are on top of the frame, and the result is pushed on the frame. |
| 522 | void Int32BinaryOperation(BinaryOperation* node); |
| 523 | |
| 524 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 525 | void Comparison(AstNode* node, |
| 526 | Condition cc, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 527 | bool strict, |
| 528 | ControlDestination* destination); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame^] | 529 | void GenerateInlineNumberComparison(Result* left_side, |
| 530 | Result* right_side, |
| 531 | Condition cc, |
| 532 | ControlDestination* dest); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 533 | |
| 534 | // To prevent long attacker-controlled byte sequences, integer constants |
| 535 | // from the JavaScript source are loaded in two parts if they are larger |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame^] | 536 | // than 17 bits. |
| 537 | static const int kMaxSmiInlinedBits = 17; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 538 | bool IsUnsafeSmi(Handle<Object> value); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 539 | // Load an integer constant x into a register target or into the stack using |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 540 | // at most 16 bits of user-controlled data per assembly operation. |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 541 | void MoveUnsafeSmi(Register target, Handle<Object> value); |
| 542 | void StoreUnsafeSmiToLocal(int offset, Handle<Object> value); |
| 543 | void PushUnsafeSmi(Handle<Object> value); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 544 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 545 | void CallWithArguments(ZoneList<Expression*>* arguments, |
| 546 | CallFunctionFlags flags, |
| 547 | int position); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 548 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 549 | // An optimized implementation of expressions of the form |
| 550 | // x.apply(y, arguments). We call x the applicand and y the receiver. |
| 551 | // The optimization avoids allocating an arguments object if possible. |
| 552 | void CallApplyLazy(Expression* applicand, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 553 | Expression* receiver, |
| 554 | VariableProxy* arguments, |
| 555 | int position); |
| 556 | |
| 557 | void CheckStack(); |
| 558 | |
| 559 | struct InlineRuntimeLUT { |
| 560 | void (CodeGenerator::*method)(ZoneList<Expression*>*); |
| 561 | const char* name; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame^] | 562 | int nargs; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 563 | }; |
| 564 | |
| 565 | static InlineRuntimeLUT* FindInlineRuntimeLUT(Handle<String> name); |
| 566 | bool CheckForInlineRuntimeCall(CallRuntime* node); |
| 567 | static bool PatchInlineRuntimeEntry(Handle<String> name, |
| 568 | const InlineRuntimeLUT& new_entry, |
| 569 | InlineRuntimeLUT* old_entry); |
| 570 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 571 | void ProcessDeclarations(ZoneList<Declaration*>* declarations); |
| 572 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 573 | static Handle<Code> ComputeCallInitialize(int argc, InLoopFlag in_loop); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 574 | |
| 575 | // Declare global variables and functions in the given array of |
| 576 | // name/value pairs. |
| 577 | void DeclareGlobals(Handle<FixedArray> pairs); |
| 578 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame^] | 579 | // Instantiate the function based on the shared function info. |
| 580 | Result InstantiateFunction(Handle<SharedFunctionInfo> function_info); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 581 | |
| 582 | // Support for type checks. |
| 583 | void GenerateIsSmi(ZoneList<Expression*>* args); |
| 584 | void GenerateIsNonNegativeSmi(ZoneList<Expression*>* args); |
| 585 | void GenerateIsArray(ZoneList<Expression*>* args); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 586 | void GenerateIsRegExp(ZoneList<Expression*>* args); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 587 | void GenerateIsObject(ZoneList<Expression*>* args); |
| 588 | void GenerateIsFunction(ZoneList<Expression*>* args); |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 589 | void GenerateIsUndetectableObject(ZoneList<Expression*>* args); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 590 | |
| 591 | // Support for construct call checks. |
| 592 | void GenerateIsConstructCall(ZoneList<Expression*>* args); |
| 593 | |
| 594 | // Support for arguments.length and arguments[?]. |
| 595 | void GenerateArgumentsLength(ZoneList<Expression*>* args); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame^] | 596 | void GenerateArguments(ZoneList<Expression*>* args); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 597 | |
| 598 | // Support for accessing the class and value fields of an object. |
| 599 | void GenerateClassOf(ZoneList<Expression*>* args); |
| 600 | void GenerateValueOf(ZoneList<Expression*>* args); |
| 601 | void GenerateSetValueOf(ZoneList<Expression*>* args); |
| 602 | |
| 603 | // Fast support for charCodeAt(n). |
| 604 | void GenerateFastCharCodeAt(ZoneList<Expression*>* args); |
| 605 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame^] | 606 | // Fast support for string.charAt(n) and string[n]. |
| 607 | void GenerateCharFromCode(ZoneList<Expression*>* args); |
| 608 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 609 | // Fast support for object equality testing. |
| 610 | void GenerateObjectEquals(ZoneList<Expression*>* args); |
| 611 | |
| 612 | void GenerateLog(ZoneList<Expression*>* args); |
| 613 | |
| 614 | void GenerateGetFramePointer(ZoneList<Expression*>* args); |
| 615 | |
| 616 | // Fast support for Math.random(). |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame^] | 617 | void GenerateRandomHeapNumber(ZoneList<Expression*>* args); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 618 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 619 | // Fast support for StringAdd. |
| 620 | void GenerateStringAdd(ZoneList<Expression*>* args); |
| 621 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 622 | // Fast support for SubString. |
| 623 | void GenerateSubString(ZoneList<Expression*>* args); |
| 624 | |
| 625 | // Fast support for StringCompare. |
| 626 | void GenerateStringCompare(ZoneList<Expression*>* args); |
| 627 | |
| 628 | // Support for direct calls from JavaScript to native RegExp code. |
| 629 | void GenerateRegExpExec(ZoneList<Expression*>* args); |
| 630 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame^] | 631 | void GenerateRegExpConstructResult(ZoneList<Expression*>* args); |
| 632 | |
| 633 | // Support for fast native caches. |
| 634 | void GenerateGetFromCache(ZoneList<Expression*>* args); |
| 635 | |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 636 | // Fast support for number to string. |
| 637 | void GenerateNumberToString(ZoneList<Expression*>* args); |
| 638 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame^] | 639 | // Fast swapping of elements. Takes three expressions, the object and two |
| 640 | // indices. This should only be used if the indices are known to be |
| 641 | // non-negative and within bounds of the elements array at the call site. |
| 642 | void GenerateSwapElements(ZoneList<Expression*>* args); |
| 643 | |
| 644 | // Fast call for custom callbacks. |
| 645 | void GenerateCallFunction(ZoneList<Expression*>* args); |
| 646 | |
| 647 | // Fast call to math functions. |
| 648 | void GenerateMathPow(ZoneList<Expression*>* args); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 649 | void GenerateMathSin(ZoneList<Expression*>* args); |
| 650 | void GenerateMathCos(ZoneList<Expression*>* args); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame^] | 651 | void GenerateMathSqrt(ZoneList<Expression*>* args); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 652 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 653 | // Simple condition analysis. |
| 654 | enum ConditionAnalysis { |
| 655 | ALWAYS_TRUE, |
| 656 | ALWAYS_FALSE, |
| 657 | DONT_KNOW |
| 658 | }; |
| 659 | ConditionAnalysis AnalyzeCondition(Expression* cond); |
| 660 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 661 | // Methods used to indicate which source code is generated for. Source |
| 662 | // positions are collected by the assembler and emitted with the relocation |
| 663 | // information. |
| 664 | void CodeForFunctionPosition(FunctionLiteral* fun); |
| 665 | void CodeForReturnPosition(FunctionLiteral* fun); |
| 666 | void CodeForStatementPosition(Statement* stmt); |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 667 | void CodeForDoWhileConditionPosition(DoWhileStatement* stmt); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 668 | void CodeForSourcePosition(int pos); |
| 669 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame^] | 670 | void SetTypeForStackSlot(Slot* slot, TypeInfo info); |
| 671 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 672 | #ifdef DEBUG |
| 673 | // True if the registers are valid for entry to a block. There should |
| 674 | // be no frame-external references to (non-reserved) registers. |
| 675 | bool HasValidEntryRegisters(); |
| 676 | #endif |
| 677 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 678 | ZoneList<DeferredCode*> deferred_; |
| 679 | |
| 680 | // Assembler |
| 681 | MacroAssembler* masm_; // to generate code |
| 682 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 683 | CompilationInfo* info_; |
| 684 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 685 | // Code generation state |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 686 | VirtualFrame* frame_; |
| 687 | RegisterAllocator* allocator_; |
| 688 | CodeGenState* state_; |
| 689 | int loop_nesting_; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame^] | 690 | bool in_safe_int32_mode_; |
| 691 | bool safe_int32_mode_enabled_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 692 | |
| 693 | // Jump targets. |
| 694 | // The target of the return from the function. |
| 695 | BreakTarget function_return_; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame^] | 696 | // The target of the bailout from a side-effect-free int32 subexpression. |
| 697 | BreakTarget* unsafe_bailout_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 698 | |
| 699 | // True if the function return is shadowed (ie, jumping to the target |
| 700 | // function_return_ does not jump to the true function return, but rather |
| 701 | // to some unlinking code). |
| 702 | bool function_return_is_shadowed_; |
| 703 | |
| 704 | // True when we are in code that expects the virtual frame to be fully |
| 705 | // spilled. Some virtual frame function are disabled in DEBUG builds when |
| 706 | // called from spilled code, because they do not leave the virtual frame |
| 707 | // in a spilled state. |
| 708 | bool in_spilled_code_; |
| 709 | |
| 710 | static InlineRuntimeLUT kInlineRuntimeLUT[]; |
| 711 | |
| 712 | friend class VirtualFrame; |
| 713 | friend class JumpTarget; |
| 714 | friend class Reference; |
| 715 | friend class Result; |
Leon Clarke | 4515c47 | 2010-02-03 11:58:03 +0000 | [diff] [blame] | 716 | friend class FastCodeGenerator; |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 717 | friend class FullCodeGenerator; |
| 718 | friend class FullCodeGenSyntaxChecker; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 719 | |
| 720 | friend class CodeGeneratorPatcher; // Used in test-log-stack-tracer.cc |
| 721 | |
| 722 | DISALLOW_COPY_AND_ASSIGN(CodeGenerator); |
| 723 | }; |
| 724 | |
| 725 | |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 726 | // Compute a transcendental math function natively, or call the |
| 727 | // TranscendentalCache runtime function. |
| 728 | class TranscendentalCacheStub: public CodeStub { |
| 729 | public: |
| 730 | explicit TranscendentalCacheStub(TranscendentalCache::Type type) |
| 731 | : type_(type) {} |
| 732 | void Generate(MacroAssembler* masm); |
| 733 | private: |
| 734 | TranscendentalCache::Type type_; |
| 735 | Major MajorKey() { return TranscendentalCache; } |
| 736 | int MinorKey() { return type_; } |
| 737 | Runtime::FunctionId RuntimeFunction(); |
| 738 | void GenerateOperation(MacroAssembler* masm); |
| 739 | }; |
| 740 | |
| 741 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 742 | // Flag that indicates how to generate code for the stub GenericBinaryOpStub. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 743 | enum GenericBinaryFlags { |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 744 | NO_GENERIC_BINARY_FLAGS = 0, |
| 745 | NO_SMI_CODE_IN_STUB = 1 << 0 // Omit smi code in stub. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 746 | }; |
| 747 | |
| 748 | |
| 749 | class GenericBinaryOpStub: public CodeStub { |
| 750 | public: |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 751 | GenericBinaryOpStub(Token::Value op, |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 752 | OverwriteMode mode, |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 753 | GenericBinaryFlags flags, |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame^] | 754 | TypeInfo operands_type) |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 755 | : op_(op), |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 756 | mode_(mode), |
| 757 | flags_(flags), |
| 758 | args_in_registers_(false), |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 759 | args_reversed_(false), |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame^] | 760 | static_operands_type_(operands_type), |
| 761 | runtime_operands_type_(BinaryOpIC::DEFAULT), |
| 762 | name_(NULL) { |
| 763 | if (static_operands_type_.IsSmi()) { |
| 764 | mode_ = NO_OVERWRITE; |
| 765 | } |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 766 | use_sse3_ = CpuFeatures::IsSupported(SSE3); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 767 | ASSERT(OpBits::is_valid(Token::NUM_TOKENS)); |
| 768 | } |
| 769 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame^] | 770 | GenericBinaryOpStub(int key, BinaryOpIC::TypeInfo runtime_operands_type) |
| 771 | : op_(OpBits::decode(key)), |
| 772 | mode_(ModeBits::decode(key)), |
| 773 | flags_(FlagBits::decode(key)), |
| 774 | args_in_registers_(ArgsInRegistersBits::decode(key)), |
| 775 | args_reversed_(ArgsReversedBits::decode(key)), |
| 776 | use_sse3_(SSE3Bits::decode(key)), |
| 777 | static_operands_type_(TypeInfo::ExpandedRepresentation( |
| 778 | StaticTypeInfoBits::decode(key))), |
| 779 | runtime_operands_type_(runtime_operands_type), |
| 780 | name_(NULL) { |
| 781 | } |
| 782 | |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 783 | // Generate code to call the stub with the supplied arguments. This will add |
| 784 | // code at the call site to prepare arguments either in registers or on the |
| 785 | // stack together with the actual call. |
| 786 | void GenerateCall(MacroAssembler* masm, Register left, Register right); |
| 787 | void GenerateCall(MacroAssembler* masm, Register left, Smi* right); |
| 788 | void GenerateCall(MacroAssembler* masm, Smi* left, Register right); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 789 | |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 790 | Result GenerateCall(MacroAssembler* masm, |
| 791 | VirtualFrame* frame, |
| 792 | Result* left, |
| 793 | Result* right); |
| 794 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 795 | private: |
| 796 | Token::Value op_; |
| 797 | OverwriteMode mode_; |
| 798 | GenericBinaryFlags flags_; |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 799 | bool args_in_registers_; // Arguments passed in registers not on the stack. |
| 800 | bool args_reversed_; // Left and right argument are swapped. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 801 | bool use_sse3_; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame^] | 802 | |
| 803 | // Number type information of operands, determined by code generator. |
| 804 | TypeInfo static_operands_type_; |
| 805 | |
| 806 | // Operand type information determined at runtime. |
| 807 | BinaryOpIC::TypeInfo runtime_operands_type_; |
| 808 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 809 | char* name_; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 810 | |
| 811 | const char* GetName(); |
| 812 | |
| 813 | #ifdef DEBUG |
| 814 | void Print() { |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 815 | PrintF("GenericBinaryOpStub %d (op %s), " |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame^] | 816 | "(mode %d, flags %d, registers %d, reversed %d, type_info %s)\n", |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 817 | MinorKey(), |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 818 | Token::String(op_), |
| 819 | static_cast<int>(mode_), |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 820 | static_cast<int>(flags_), |
| 821 | static_cast<int>(args_in_registers_), |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 822 | static_cast<int>(args_reversed_), |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame^] | 823 | static_operands_type_.ToString()); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 824 | } |
| 825 | #endif |
| 826 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame^] | 827 | // Minor key encoding in 18 bits RRNNNFRASOOOOOOOMM. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 828 | class ModeBits: public BitField<OverwriteMode, 0, 2> {}; |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 829 | class OpBits: public BitField<Token::Value, 2, 7> {}; |
| 830 | class SSE3Bits: public BitField<bool, 9, 1> {}; |
| 831 | class ArgsInRegistersBits: public BitField<bool, 10, 1> {}; |
| 832 | class ArgsReversedBits: public BitField<bool, 11, 1> {}; |
| 833 | class FlagBits: public BitField<GenericBinaryFlags, 12, 1> {}; |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame^] | 834 | class StaticTypeInfoBits: public BitField<int, 13, 3> {}; |
| 835 | class RuntimeTypeInfoBits: public BitField<BinaryOpIC::TypeInfo, 16, 2> {}; |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 836 | |
| 837 | Major MajorKey() { return GenericBinaryOp; } |
| 838 | int MinorKey() { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame^] | 839 | // Encode the parameters in a unique 18 bit value. |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 840 | return OpBits::encode(op_) |
| 841 | | ModeBits::encode(mode_) |
| 842 | | FlagBits::encode(flags_) |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 843 | | SSE3Bits::encode(use_sse3_) |
| 844 | | ArgsInRegistersBits::encode(args_in_registers_) |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 845 | | ArgsReversedBits::encode(args_reversed_) |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame^] | 846 | | StaticTypeInfoBits::encode( |
| 847 | static_operands_type_.ThreeBitRepresentation()) |
| 848 | | RuntimeTypeInfoBits::encode(runtime_operands_type_); |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 849 | } |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 850 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 851 | void Generate(MacroAssembler* masm); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 852 | void GenerateSmiCode(MacroAssembler* masm, Label* slow); |
| 853 | void GenerateLoadArguments(MacroAssembler* masm); |
| 854 | void GenerateReturn(MacroAssembler* masm); |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 855 | void GenerateHeapResultAllocation(MacroAssembler* masm, Label* alloc_failure); |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame^] | 856 | void GenerateRegisterArgsPush(MacroAssembler* masm); |
| 857 | void GenerateTypeTransition(MacroAssembler* masm); |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 858 | |
| 859 | bool ArgsInRegistersSupported() { |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 860 | return op_ == Token::ADD || op_ == Token::SUB |
| 861 | || op_ == Token::MUL || op_ == Token::DIV; |
Steve Block | 3ce2e20 | 2009-11-05 08:53:23 +0000 | [diff] [blame] | 862 | } |
| 863 | bool IsOperationCommutative() { |
| 864 | return (op_ == Token::ADD) || (op_ == Token::MUL); |
| 865 | } |
| 866 | |
| 867 | void SetArgsInRegisters() { args_in_registers_ = true; } |
| 868 | void SetArgsReversed() { args_reversed_ = true; } |
| 869 | bool HasSmiCodeInStub() { return (flags_ & NO_SMI_CODE_IN_STUB) == 0; } |
Leon Clarke | d91b9f7 | 2010-01-27 17:25:45 +0000 | [diff] [blame] | 870 | bool HasArgsInRegisters() { return args_in_registers_; } |
| 871 | bool HasArgsReversed() { return args_reversed_; } |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame^] | 872 | |
| 873 | bool ShouldGenerateSmiCode() { |
| 874 | return HasSmiCodeInStub() && |
| 875 | runtime_operands_type_ != BinaryOpIC::HEAP_NUMBERS && |
| 876 | runtime_operands_type_ != BinaryOpIC::STRINGS; |
| 877 | } |
| 878 | |
| 879 | bool ShouldGenerateFPCode() { |
| 880 | return runtime_operands_type_ != BinaryOpIC::STRINGS; |
| 881 | } |
| 882 | |
| 883 | virtual int GetCodeKind() { return Code::BINARY_OP_IC; } |
| 884 | |
| 885 | virtual InlineCacheState GetICState() { |
| 886 | return BinaryOpIC::ToState(runtime_operands_type_); |
| 887 | } |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 888 | }; |
| 889 | |
| 890 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame^] | 891 | class StringHelper : public AllStatic { |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 892 | public: |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame^] | 893 | // Generates fast code for getting a char code out of a string |
| 894 | // object at the given index. May bail out for four reasons (in the |
| 895 | // listed order): |
| 896 | // * Receiver is not a string (receiver_not_string label). |
| 897 | // * Index is not a smi (index_not_smi label). |
| 898 | // * Index is out of range (index_out_of_range). |
| 899 | // * Some other reason (slow_case label). In this case it's |
| 900 | // guaranteed that the above conditions are not violated, |
| 901 | // e.g. it's safe to assume the receiver is a string and the |
| 902 | // index is a non-negative smi < length. |
| 903 | // When successful, object, index, and scratch are clobbered. |
| 904 | // Otherwise, scratch and result are clobbered. |
| 905 | static void GenerateFastCharCodeAt(MacroAssembler* masm, |
| 906 | Register object, |
| 907 | Register index, |
| 908 | Register scratch, |
| 909 | Register result, |
| 910 | Label* receiver_not_string, |
| 911 | Label* index_not_smi, |
| 912 | Label* index_out_of_range, |
| 913 | Label* slow_case); |
| 914 | |
| 915 | // Generates code for creating a one-char string from the given char |
| 916 | // code. May do a runtime call, so any register can be clobbered |
| 917 | // and, if the given invoke flag specifies a call, an internal frame |
| 918 | // is required. In tail call mode the result must be eax register. |
| 919 | static void GenerateCharFromCode(MacroAssembler* masm, |
| 920 | Register code, |
| 921 | Register result, |
| 922 | InvokeFlag flag); |
| 923 | |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 924 | // Generate code for copying characters using a simple loop. This should only |
| 925 | // be used in places where the number of characters is small and the |
| 926 | // additional setup and checking in GenerateCopyCharactersREP adds too much |
| 927 | // overhead. Copying of overlapping regions is not supported. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame^] | 928 | static void GenerateCopyCharacters(MacroAssembler* masm, |
| 929 | Register dest, |
| 930 | Register src, |
| 931 | Register count, |
| 932 | Register scratch, |
| 933 | bool ascii); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 934 | |
| 935 | // Generate code for copying characters using the rep movs instruction. |
| 936 | // Copies ecx characters from esi to edi. Copying of overlapping regions is |
| 937 | // not supported. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame^] | 938 | static void GenerateCopyCharactersREP(MacroAssembler* masm, |
| 939 | Register dest, // Must be edi. |
| 940 | Register src, // Must be esi. |
| 941 | Register count, // Must be ecx. |
| 942 | Register scratch, // Neither of above. |
| 943 | bool ascii); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 944 | |
| 945 | // Probe the symbol table for a two character string. If the string is |
| 946 | // not found by probing a jump to the label not_found is performed. This jump |
| 947 | // does not guarantee that the string is not in the symbol table. If the |
| 948 | // string is found the code falls through with the string in register eax. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame^] | 949 | static void GenerateTwoCharacterSymbolTableProbe(MacroAssembler* masm, |
| 950 | Register c1, |
| 951 | Register c2, |
| 952 | Register scratch1, |
| 953 | Register scratch2, |
| 954 | Register scratch3, |
| 955 | Label* not_found); |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 956 | |
| 957 | // Generate string hash. |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame^] | 958 | static void GenerateHashInit(MacroAssembler* masm, |
| 959 | Register hash, |
| 960 | Register character, |
| 961 | Register scratch); |
| 962 | static void GenerateHashAddCharacter(MacroAssembler* masm, |
| 963 | Register hash, |
| 964 | Register character, |
| 965 | Register scratch); |
| 966 | static void GenerateHashGetHash(MacroAssembler* masm, |
| 967 | Register hash, |
| 968 | Register scratch); |
| 969 | |
| 970 | private: |
| 971 | DISALLOW_IMPLICIT_CONSTRUCTORS(StringHelper); |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 972 | }; |
| 973 | |
| 974 | |
Andrei Popescu | 3100271 | 2010-02-23 13:46:05 +0000 | [diff] [blame] | 975 | // Flag that indicates how to generate code for the stub StringAddStub. |
| 976 | enum StringAddFlags { |
| 977 | NO_STRING_ADD_FLAGS = 0, |
| 978 | NO_STRING_CHECK_IN_STUB = 1 << 0 // Omit string check in stub. |
| 979 | }; |
| 980 | |
| 981 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame^] | 982 | class StringAddStub: public CodeStub { |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 983 | public: |
| 984 | explicit StringAddStub(StringAddFlags flags) { |
| 985 | string_check_ = ((flags & NO_STRING_CHECK_IN_STUB) == 0); |
| 986 | } |
| 987 | |
| 988 | private: |
| 989 | Major MajorKey() { return StringAdd; } |
| 990 | int MinorKey() { return string_check_ ? 0 : 1; } |
| 991 | |
| 992 | void Generate(MacroAssembler* masm); |
| 993 | |
Steve Block | d0582a6 | 2009-12-15 09:54:21 +0000 | [diff] [blame] | 994 | // Should the stub check whether arguments are strings? |
| 995 | bool string_check_; |
| 996 | }; |
| 997 | |
| 998 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame^] | 999 | class SubStringStub: public CodeStub { |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1000 | public: |
| 1001 | SubStringStub() {} |
| 1002 | |
| 1003 | private: |
| 1004 | Major MajorKey() { return SubString; } |
| 1005 | int MinorKey() { return 0; } |
| 1006 | |
| 1007 | void Generate(MacroAssembler* masm); |
| 1008 | }; |
| 1009 | |
| 1010 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame^] | 1011 | class StringCompareStub: public CodeStub { |
Leon Clarke | e46be81 | 2010-01-19 14:06:41 +0000 | [diff] [blame] | 1012 | public: |
| 1013 | explicit StringCompareStub() { |
| 1014 | } |
| 1015 | |
| 1016 | // Compare two flat ascii strings and returns result in eax after popping two |
| 1017 | // arguments from the stack. |
| 1018 | static void GenerateCompareFlatAsciiStrings(MacroAssembler* masm, |
| 1019 | Register left, |
| 1020 | Register right, |
| 1021 | Register scratch1, |
| 1022 | Register scratch2, |
| 1023 | Register scratch3); |
| 1024 | |
| 1025 | private: |
| 1026 | Major MajorKey() { return StringCompare; } |
| 1027 | int MinorKey() { return 0; } |
| 1028 | |
| 1029 | void Generate(MacroAssembler* masm); |
| 1030 | }; |
| 1031 | |
| 1032 | |
Andrei Popescu | 402d937 | 2010-02-26 13:31:12 +0000 | [diff] [blame] | 1033 | class NumberToStringStub: public CodeStub { |
| 1034 | public: |
| 1035 | NumberToStringStub() { } |
| 1036 | |
| 1037 | // Generate code to do a lookup in the number string cache. If the number in |
| 1038 | // the register object is found in the cache the generated code falls through |
| 1039 | // with the result in the result register. The object and the result register |
| 1040 | // can be the same. If the number is not found in the cache the code jumps to |
| 1041 | // the label not_found with only the content of register object unchanged. |
| 1042 | static void GenerateLookupNumberStringCache(MacroAssembler* masm, |
| 1043 | Register object, |
| 1044 | Register result, |
| 1045 | Register scratch1, |
| 1046 | Register scratch2, |
| 1047 | bool object_is_smi, |
| 1048 | Label* not_found); |
| 1049 | |
| 1050 | private: |
| 1051 | Major MajorKey() { return NumberToString; } |
| 1052 | int MinorKey() { return 0; } |
| 1053 | |
| 1054 | void Generate(MacroAssembler* masm); |
| 1055 | |
| 1056 | const char* GetName() { return "NumberToStringStub"; } |
| 1057 | |
| 1058 | #ifdef DEBUG |
| 1059 | void Print() { |
| 1060 | PrintF("NumberToStringStub\n"); |
| 1061 | } |
| 1062 | #endif |
| 1063 | }; |
| 1064 | |
| 1065 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame^] | 1066 | class RecordWriteStub : public CodeStub { |
| 1067 | public: |
| 1068 | RecordWriteStub(Register object, Register addr, Register scratch) |
| 1069 | : object_(object), addr_(addr), scratch_(scratch) { } |
| 1070 | |
| 1071 | void Generate(MacroAssembler* masm); |
| 1072 | |
| 1073 | private: |
| 1074 | Register object_; |
| 1075 | Register addr_; |
| 1076 | Register scratch_; |
| 1077 | |
| 1078 | #ifdef DEBUG |
| 1079 | void Print() { |
| 1080 | PrintF("RecordWriteStub (object reg %d), (addr reg %d), (scratch reg %d)\n", |
| 1081 | object_.code(), addr_.code(), scratch_.code()); |
| 1082 | } |
| 1083 | #endif |
| 1084 | |
| 1085 | // Minor key encoding in 12 bits. 4 bits for each of the three |
| 1086 | // registers (object, address and scratch) OOOOAAAASSSS. |
| 1087 | class ScratchBits: public BitField<uint32_t, 0, 4> {}; |
| 1088 | class AddressBits: public BitField<uint32_t, 4, 4> {}; |
| 1089 | class ObjectBits: public BitField<uint32_t, 8, 4> {}; |
| 1090 | |
| 1091 | Major MajorKey() { return RecordWrite; } |
| 1092 | |
| 1093 | int MinorKey() { |
| 1094 | // Encode the registers. |
| 1095 | return ObjectBits::encode(object_.code()) | |
| 1096 | AddressBits::encode(addr_.code()) | |
| 1097 | ScratchBits::encode(scratch_.code()); |
| 1098 | } |
| 1099 | }; |
| 1100 | |
| 1101 | |
Steve Block | a7e24c1 | 2009-10-30 11:49:00 +0000 | [diff] [blame] | 1102 | } } // namespace v8::internal |
| 1103 | |
| 1104 | #endif // V8_IA32_CODEGEN_IA32_H_ |