| OLD | NEW | 
|    1 // Copyright 2013 the V8 project authors. All rights reserved. |    1 // Copyright 2013 the V8 project authors. All rights reserved. | 
|    2 // Use of this source code is governed by a BSD-style license that can be |    2 // Use of this source code is governed by a BSD-style license that can be | 
|    3 // found in the LICENSE file. |    3 // found in the LICENSE file. | 
|    4  |    4  | 
|    5 #ifndef V8_COMPILER_MACHINE_OPERATOR_H_ |    5 #ifndef V8_COMPILER_MACHINE_OPERATOR_H_ | 
|    6 #define V8_COMPILER_MACHINE_OPERATOR_H_ |    6 #define V8_COMPILER_MACHINE_OPERATOR_H_ | 
|    7  |    7  | 
 |    8 #include "src/compiler/machine-type.h" | 
|    8 #include "src/compiler/opcodes.h" |    9 #include "src/compiler/opcodes.h" | 
|    9 #include "src/compiler/operator.h" |   10 #include "src/compiler/operator.h" | 
|   10 #include "src/zone.h" |   11 #include "src/zone.h" | 
|   11  |   12  | 
|   12 namespace v8 { |   13 namespace v8 { | 
|   13 namespace internal { |   14 namespace internal { | 
|   14 namespace compiler { |   15 namespace compiler { | 
|   15  |   16  | 
|   16 // An enumeration of the storage representations at the machine level. |  | 
|   17 // - Words are uninterpreted bits of a given fixed size that can be used |  | 
|   18 //   to store integers and pointers. They are normally allocated to general |  | 
|   19 //   purpose registers by the backend and are not tracked for GC. |  | 
|   20 // - Floats are bits of a given fixed size that are used to store floating |  | 
|   21 //   point numbers. They are normally allocated to the floating point |  | 
|   22 //   registers of the machine and are not tracked for the GC. |  | 
|   23 // - Tagged values are the size of a reference into the heap and can store |  | 
|   24 //   small words or references into the heap using a language and potentially |  | 
|   25 //   machine-dependent tagging scheme. These values are tracked by the code |  | 
|   26 //   generator for precise GC. |  | 
|   27 enum MachineRepresentation { |  | 
|   28   kMachineWord8, |  | 
|   29   kMachineWord16, |  | 
|   30   kMachineWord32, |  | 
|   31   kMachineWord64, |  | 
|   32   kMachineFloat64, |  | 
|   33   kMachineTagged, |  | 
|   34   kMachineLast |  | 
|   35 }; |  | 
|   36  |  | 
|   37  |  | 
|   38 // TODO(turbofan): other write barriers are possible based on type |   17 // TODO(turbofan): other write barriers are possible based on type | 
|   39 enum WriteBarrierKind { kNoWriteBarrier, kFullWriteBarrier }; |   18 enum WriteBarrierKind { kNoWriteBarrier, kFullWriteBarrier }; | 
|   40  |   19  | 
|   41  |   20  | 
|   42 // A Store needs a MachineRepresentation and a WriteBarrierKind |   21 // A Store needs a MachineType and a WriteBarrierKind | 
|   43 // in order to emit the correct write barrier. |   22 // in order to emit the correct write barrier. | 
|   44 struct StoreRepresentation { |   23 struct StoreRepresentation { | 
|   45   MachineRepresentation rep; |   24   MachineType rep; | 
|   46   WriteBarrierKind write_barrier_kind; |   25   WriteBarrierKind write_barrier_kind; | 
|   47 }; |   26 }; | 
|   48  |   27  | 
|   49  |   28  | 
|   50 // Interface for building machine-level operators. These operators are |   29 // Interface for building machine-level operators. These operators are | 
|   51 // machine-level but machine-independent and thus define a language suitable |   30 // machine-level but machine-independent and thus define a language suitable | 
|   52 // for generating code to run on architectures such as ia32, x64, arm, etc. |   31 // for generating code to run on architectures such as ia32, x64, arm, etc. | 
|   53 class MachineOperatorBuilder { |   32 class MachineOperatorBuilder { | 
|   54  public: |   33  public: | 
|   55   explicit MachineOperatorBuilder(Zone* zone, |   34   explicit MachineOperatorBuilder(Zone* zone, MachineType word = pointer_rep()) | 
|   56                                   MachineRepresentation word = pointer_rep()) |  | 
|   57       : zone_(zone), word_(word) { |   35       : zone_(zone), word_(word) { | 
|   58     CHECK(word == kMachineWord32 || word == kMachineWord64); |   36     CHECK(word == kMachineWord32 || word == kMachineWord64); | 
|   59   } |   37   } | 
|   60  |   38  | 
|   61 #define SIMPLE(name, properties, inputs, outputs) \ |   39 #define SIMPLE(name, properties, inputs, outputs) \ | 
|   62   return new (zone_)                              \ |   40   return new (zone_)                              \ | 
|   63       SimpleOperator(IrOpcode::k##name, properties, inputs, outputs, #name); |   41       SimpleOperator(IrOpcode::k##name, properties, inputs, outputs, #name); | 
|   64  |   42  | 
|   65 #define OP1(name, ptype, pname, properties, inputs, outputs)               \ |   43 #define OP1(name, ptype, pname, properties, inputs, outputs)               \ | 
|   66   return new (zone_)                                                       \ |   44   return new (zone_)                                                       \ | 
|   67       Operator1<ptype>(IrOpcode::k##name, properties | Operator::kNoThrow, \ |   45       Operator1<ptype>(IrOpcode::k##name, properties | Operator::kNoThrow, \ | 
|   68                        inputs, outputs, #name, pname) |   46                        inputs, outputs, #name, pname) | 
|   69  |   47  | 
|   70 #define BINOP(name) SIMPLE(name, Operator::kPure, 2, 1) |   48 #define BINOP(name) SIMPLE(name, Operator::kPure, 2, 1) | 
|   71 #define BINOP_O(name) SIMPLE(name, Operator::kPure, 2, 2) |   49 #define BINOP_O(name) SIMPLE(name, Operator::kPure, 2, 2) | 
|   72 #define BINOP_C(name) \ |   50 #define BINOP_C(name) \ | 
|   73   SIMPLE(name, Operator::kCommutative | Operator::kPure, 2, 1) |   51   SIMPLE(name, Operator::kCommutative | Operator::kPure, 2, 1) | 
|   74 #define BINOP_AC(name)                                                         \ |   52 #define BINOP_AC(name)                                                         \ | 
|   75   SIMPLE(name,                                                                 \ |   53   SIMPLE(name,                                                                 \ | 
|   76          Operator::kAssociative | Operator::kCommutative | Operator::kPure, 2, \ |   54          Operator::kAssociative | Operator::kCommutative | Operator::kPure, 2, \ | 
|   77          1) |   55          1) | 
|   78 #define BINOP_ACO(name)                                                        \ |   56 #define BINOP_ACO(name)                                                        \ | 
|   79   SIMPLE(name,                                                                 \ |   57   SIMPLE(name,                                                                 \ | 
|   80          Operator::kAssociative | Operator::kCommutative | Operator::kPure, 2, \ |   58          Operator::kAssociative | Operator::kCommutative | Operator::kPure, 2, \ | 
|   81          2) |   59          2) | 
|   82 #define UNOP(name) SIMPLE(name, Operator::kPure, 1, 1) |   60 #define UNOP(name) SIMPLE(name, Operator::kPure, 1, 1) | 
|   83  |   61  | 
|   84 #define WORD_SIZE(x) return is64() ? Word64##x() : Word32##x() |   62 #define WORD_SIZE(x) return is64() ? Word64##x() : Word32##x() | 
|   85  |   63  | 
|   86   Operator* Load(MachineRepresentation rep) {  // load [base + index] |   64   Operator* Load(MachineType rep) {  // load [base + index] | 
|   87     OP1(Load, MachineRepresentation, rep, Operator::kNoWrite, 2, 1); |   65     OP1(Load, MachineType, rep, Operator::kNoWrite, 2, 1); | 
|   88   } |   66   } | 
|   89   // store [base + index], value |   67   // store [base + index], value | 
|   90   Operator* Store(MachineRepresentation rep, WriteBarrierKind kind) { |   68   Operator* Store(MachineType rep, WriteBarrierKind kind) { | 
|   91     StoreRepresentation store_rep = {rep, kind}; |   69     StoreRepresentation store_rep = {rep, kind}; | 
|   92     OP1(Store, StoreRepresentation, store_rep, Operator::kNoRead, 3, 0); |   70     OP1(Store, StoreRepresentation, store_rep, Operator::kNoRead, 3, 0); | 
|   93   } |   71   } | 
|   94  |   72  | 
|   95   Operator* WordAnd() { WORD_SIZE(And); } |   73   Operator* WordAnd() { WORD_SIZE(And); } | 
|   96   Operator* WordOr() { WORD_SIZE(Or); } |   74   Operator* WordOr() { WORD_SIZE(Or); } | 
|   97   Operator* WordXor() { WORD_SIZE(Xor); } |   75   Operator* WordXor() { WORD_SIZE(Xor); } | 
|   98   Operator* WordShl() { WORD_SIZE(Shl); } |   76   Operator* WordShl() { WORD_SIZE(Shl); } | 
|   99   Operator* WordShr() { WORD_SIZE(Shr); } |   77   Operator* WordShr() { WORD_SIZE(Shr); } | 
|  100   Operator* WordSar() { WORD_SIZE(Sar); } |   78   Operator* WordSar() { WORD_SIZE(Sar); } | 
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  160   Operator* Float64Div() { BINOP(Float64Div); } |  138   Operator* Float64Div() { BINOP(Float64Div); } | 
|  161   Operator* Float64Mod() { BINOP(Float64Mod); } |  139   Operator* Float64Mod() { BINOP(Float64Mod); } | 
|  162  |  140  | 
|  163   // Floating point comparisons complying to IEEE 754. |  141   // Floating point comparisons complying to IEEE 754. | 
|  164   Operator* Float64Equal() { BINOP_C(Float64Equal); } |  142   Operator* Float64Equal() { BINOP_C(Float64Equal); } | 
|  165   Operator* Float64LessThan() { BINOP(Float64LessThan); } |  143   Operator* Float64LessThan() { BINOP(Float64LessThan); } | 
|  166   Operator* Float64LessThanOrEqual() { BINOP(Float64LessThanOrEqual); } |  144   Operator* Float64LessThanOrEqual() { BINOP(Float64LessThanOrEqual); } | 
|  167  |  145  | 
|  168   inline bool is32() const { return word_ == kMachineWord32; } |  146   inline bool is32() const { return word_ == kMachineWord32; } | 
|  169   inline bool is64() const { return word_ == kMachineWord64; } |  147   inline bool is64() const { return word_ == kMachineWord64; } | 
|  170   inline MachineRepresentation word() const { return word_; } |  148   inline MachineType word() const { return word_; } | 
|  171  |  149  | 
|  172   static inline MachineRepresentation pointer_rep() { |  150   static inline MachineType pointer_rep() { | 
|  173     return kPointerSize == 8 ? kMachineWord64 : kMachineWord32; |  151     return kPointerSize == 8 ? kMachineWord64 : kMachineWord32; | 
|  174   } |  152   } | 
|  175  |  153  | 
|  176 #undef WORD_SIZE |  154 #undef WORD_SIZE | 
|  177 #undef UNOP |  155 #undef UNOP | 
|  178 #undef BINOP |  156 #undef BINOP | 
|  179 #undef OP1 |  157 #undef OP1 | 
|  180 #undef SIMPLE |  158 #undef SIMPLE | 
|  181  |  159  | 
|  182  private: |  160  private: | 
|  183   Zone* zone_; |  161   Zone* zone_; | 
|  184   MachineRepresentation word_; |  162   MachineType word_; | 
|  185 }; |  163 }; | 
|  186 } |  164 } | 
|  187 } |  165 } | 
|  188 }  // namespace v8::internal::compiler |  166 }  // namespace v8::internal::compiler | 
|  189  |  167  | 
|  190 #endif  // V8_COMPILER_MACHINE_OPERATOR_H_ |  168 #endif  // V8_COMPILER_MACHINE_OPERATOR_H_ | 
| OLD | NEW |