V8 Project
machine-operator.h
Go to the documentation of this file.
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
3 // found in the LICENSE file.
4 
5 #ifndef V8_COMPILER_MACHINE_OPERATOR_H_
6 #define V8_COMPILER_MACHINE_OPERATOR_H_
7 
9 
10 namespace v8 {
11 namespace internal {
12 namespace compiler {
13 
14 // Forward declarations.
15 struct MachineOperatorBuilderImpl;
16 class Operator;
17 
18 
19 // Supported write barrier modes.
21 
22 OStream& operator<<(OStream& os, const WriteBarrierKind& write_barrier_kind);
23 
24 
26 
27 
28 // A Store needs a MachineType and a WriteBarrierKind
29 // in order to emit the correct write barrier.
30 class StoreRepresentation FINAL {
31  public:
33  WriteBarrierKind write_barrier_kind)
34  : machine_type_(machine_type), write_barrier_kind_(write_barrier_kind) {}
35 
36  MachineType machine_type() const { return machine_type_; }
37  WriteBarrierKind write_barrier_kind() const { return write_barrier_kind_; }
38 
39  private:
42 };
43 
44 inline bool operator==(const StoreRepresentation& rep1,
45  const StoreRepresentation& rep2) {
46  return rep1.machine_type() == rep2.machine_type() &&
47  rep1.write_barrier_kind() == rep2.write_barrier_kind();
48 }
49 
50 inline bool operator!=(const StoreRepresentation& rep1,
51  const StoreRepresentation& rep2) {
52  return !(rep1 == rep2);
53 }
54 
55 OStream& operator<<(OStream& os, const StoreRepresentation& rep);
56 
57 
58 // Interface for building machine-level operators. These operators are
59 // machine-level but machine-independent and thus define a language suitable
60 // for generating code to run on architectures such as ia32, x64, arm, etc.
61 class MachineOperatorBuilder FINAL {
62  public:
64 
65  const Operator* Word32And();
66  const Operator* Word32Or();
67  const Operator* Word32Xor();
68  const Operator* Word32Shl();
69  const Operator* Word32Shr();
70  const Operator* Word32Sar();
71  const Operator* Word32Ror();
73 
74  const Operator* Word64And();
75  const Operator* Word64Or();
76  const Operator* Word64Xor();
77  const Operator* Word64Shl();
78  const Operator* Word64Shr();
79  const Operator* Word64Sar();
80  const Operator* Word64Ror();
82 
83  const Operator* Int32Add();
85  const Operator* Int32Sub();
87  const Operator* Int32Mul();
88  const Operator* Int32Div();
89  const Operator* Int32UDiv();
90  const Operator* Int32Mod();
91  const Operator* Int32UMod();
96 
97  const Operator* Int64Add();
98  const Operator* Int64Sub();
99  const Operator* Int64Mul();
100  const Operator* Int64Div();
101  const Operator* Int64UDiv();
102  const Operator* Int64Mod();
103  const Operator* Int64UMod();
106 
107  // These operators change the representation of numbers while preserving the
108  // value of the number. Narrowing operators assume the input is representable
109  // in the target type and are *not* defined for other inputs.
110  // Use narrowing change operators only when there is a static guarantee that
111  // the input value is representable in the target value.
113  const Operator* ChangeFloat64ToInt32(); // narrowing
114  const Operator* ChangeFloat64ToUint32(); // narrowing
119 
120  // These operators truncate numbers, both changing the representation of
121  // the number and mapping multiple input values onto the same output value.
123  const Operator* TruncateFloat64ToInt32(); // JavaScript semantics.
125 
126  // Floating point operators always operate with IEEE 754 round-to-nearest.
133 
134  // Floating point comparisons complying to IEEE 754.
138 
139  // load [base + index]
141 
142  // store [base + index], value
143  const Operator* Store(StoreRepresentation rep);
144 
145  // Target machine word-size assumed by this builder.
146  bool Is32() const { return word() == kRepWord32; }
147  bool Is64() const { return word() == kRepWord64; }
148  MachineType word() const { return word_; }
149 
150 // Pseudo operators that translate to 32/64-bit operators depending on the
151 // word-size of the target machine assumed by this builder.
152 #define PSEUDO_OP_LIST(V) \
153  V(Word, And) \
154  V(Word, Or) \
155  V(Word, Xor) \
156  V(Word, Shl) \
157  V(Word, Shr) \
158  V(Word, Sar) \
159  V(Word, Ror) \
160  V(Word, Equal) \
161  V(Int, Add) \
162  V(Int, Sub) \
163  V(Int, Mul) \
164  V(Int, Div) \
165  V(Int, UDiv) \
166  V(Int, Mod) \
167  V(Int, UMod) \
168  V(Int, LessThan) \
169  V(Int, LessThanOrEqual)
170 #define PSEUDO_OP(Prefix, Suffix) \
171  const Operator* Prefix##Suffix() { \
172  return Is32() ? Prefix##32##Suffix() : Prefix##64##Suffix(); \
173  }
175 #undef PSEUDO_OP
176 #undef PSEUDO_OP_LIST
177 
178  private:
181 };
182 
183 } // namespace compiler
184 } // namespace internal
185 } // namespace v8
186 
187 #endif // V8_COMPILER_MACHINE_OPERATOR_H_
Source to read snapshot and builtins files from.
Definition: lithium-arm.h:372
const Operator * Int32Div()
const Operator * Store(StoreRepresentation rep)
const Operator * Int32LessThan()
const Operator * Int32UMod()
const Operator * Float64LessThan()
const Operator * Int64Add()
const Operator * Int64UMod()
const Operator * Float64LessThanOrEqual()
const Operator * Int64Mod()
const Operator * ChangeFloat32ToFloat64()
const Operator * Float64Sub()
const Operator * Word64Ror()
const Operator * ChangeInt32ToInt64()
const Operator * TruncateFloat64ToFloat32()
const Operator * Word32Equal()
const Operator * Word32Shr()
const Operator * Int32LessThanOrEqual()
const Operator * Int64Mul()
const Operator * Word32Sar()
WriteBarrierKind write_barrier_kind() const
const Operator * ChangeUint32ToUint64()
const Operator * Word32And()
const Operator * Word64Sar()
const Operator * Word64Xor()
const Operator * Uint32LessThanOrEqual()
const Operator * Int32Add()
const Operator * Uint32LessThan()
const Operator * Word64And()
MachineType machine_type() const
const Operator * Int32UDiv()
const Operator * ChangeUint32ToFloat64()
const Operator * Word64Or()
const Operator * Word32Shl()
const Operator * ChangeInt32ToFloat64()
const Operator * Word64Shr()
const Operator * Int32Sub()
const Operator * Word32Ror()
const Operator * Float64Div()
const Operator * Float64Mul()
const Operator * Float64Sqrt()
const Operator * Float64Equal()
const Operator * Word64Shl()
WriteBarrierKind write_barrier_kind_
const Operator * Int32Mod()
const Operator * Float64Add()
const Operator * Int64UDiv()
const Operator * Word32Or()
const Operator * Int32SubWithOverflow()
const Operator * ChangeFloat64ToInt32()
const Operator * Int32Mul()
const Operator * Int32AddWithOverflow()
const Operator * ChangeFloat64ToUint32()
const Operator * Int64Sub()
const Operator * Load(LoadRepresentation rep)
const Operator * Int64LessThanOrEqual()
StoreRepresentation(MachineType machine_type, WriteBarrierKind write_barrier_kind)
const Operator * Word64Equal()
const Operator * Float64Mod()
const Operator * Word32Xor()
MachineOperatorBuilder(MachineType word=kMachPtr)
const Operator * Int64Div()
const MachineOperatorBuilderImpl & impl_
const Operator * TruncateFloat64ToInt32()
const Operator * TruncateInt64ToInt32()
const Operator * Int64LessThan()
#define PSEUDO_OP(Prefix, Suffix)
#define PSEUDO_OP_LIST(V)
bool operator==(const StoreRepresentation &rep1, const StoreRepresentation &rep2)
std::ostream & operator<<(std::ostream &os, const MachineType &type)
MachineType LoadRepresentation
bool operator!=(const StoreRepresentation &rep1, const StoreRepresentation &rep2)
Debugger support for the V8 JavaScript engine.
Definition: accessors.cc:20