• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2016 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_EFFECT_CONTROL_LINEARIZER_H_
6 #define V8_COMPILER_EFFECT_CONTROL_LINEARIZER_H_
7 
8 #include "src/compiler/common-operator.h"
9 #include "src/compiler/graph-assembler.h"
10 #include "src/compiler/node.h"
11 #include "src/compiler/simplified-operator.h"
12 #include "src/globals.h"
13 
14 namespace v8 {
15 namespace internal {
16 
17 // Forward declarations.
18 class Callable;
19 class Zone;
20 
21 namespace compiler {
22 
23 class CommonOperatorBuilder;
24 class SimplifiedOperatorBuilder;
25 class MachineOperatorBuilder;
26 class JSGraph;
27 class Graph;
28 class Schedule;
29 class SourcePositionTable;
30 class NodeOriginTable;
31 
32 class V8_EXPORT_PRIVATE EffectControlLinearizer {
33  public:
34   enum MaskArrayIndexEnable { kDoNotMaskArrayIndex, kMaskArrayIndex };
35 
36   EffectControlLinearizer(JSGraph* graph, Schedule* schedule, Zone* temp_zone,
37                           SourcePositionTable* source_positions,
38                           NodeOriginTable* node_origins,
39                           MaskArrayIndexEnable mask_array_index);
40 
41   void Run();
42 
43  private:
44   void ProcessNode(Node* node, Node** frame_state, Node** effect,
45                    Node** control);
46 
47   bool TryWireInStateEffect(Node* node, Node* frame_state, Node** effect,
48                             Node** control);
49   Node* LowerChangeBitToTagged(Node* node);
50   Node* LowerChangeInt31ToTaggedSigned(Node* node);
51   Node* LowerChangeInt32ToTagged(Node* node);
52   Node* LowerChangeUint32ToTagged(Node* node);
53   Node* LowerChangeFloat64ToTagged(Node* node);
54   Node* LowerChangeFloat64ToTaggedPointer(Node* node);
55   Node* LowerChangeTaggedSignedToInt32(Node* node);
56   Node* LowerChangeTaggedToBit(Node* node);
57   Node* LowerChangeTaggedToInt32(Node* node);
58   Node* LowerChangeTaggedToUint32(Node* node);
59   Node* LowerChangeTaggedToTaggedSigned(Node* node);
60   Node* LowerCheckBounds(Node* node, Node* frame_state);
61   Node* LowerPoisonIndex(Node* node);
62   Node* LowerCheckInternalizedString(Node* node, Node* frame_state);
63   void LowerCheckMaps(Node* node, Node* frame_state);
64   Node* LowerCompareMaps(Node* node);
65   Node* LowerCheckNumber(Node* node, Node* frame_state);
66   Node* LowerCheckReceiver(Node* node, Node* frame_state);
67   Node* LowerCheckString(Node* node, Node* frame_state);
68   Node* LowerCheckSymbol(Node* node, Node* frame_state);
69   void LowerCheckIf(Node* node, Node* frame_state);
70   Node* LowerCheckedInt32Add(Node* node, Node* frame_state);
71   Node* LowerCheckedInt32Sub(Node* node, Node* frame_state);
72   Node* LowerCheckedInt32Div(Node* node, Node* frame_state);
73   Node* LowerCheckedInt32Mod(Node* node, Node* frame_state);
74   Node* LowerCheckedUint32Div(Node* node, Node* frame_state);
75   Node* LowerCheckedUint32Mod(Node* node, Node* frame_state);
76   Node* LowerCheckedInt32Mul(Node* node, Node* frame_state);
77   Node* LowerCheckedInt32ToTaggedSigned(Node* node, Node* frame_state);
78   Node* LowerCheckedUint32ToInt32(Node* node, Node* frame_state);
79   Node* LowerCheckedUint32ToTaggedSigned(Node* node, Node* frame_state);
80   Node* LowerCheckedFloat64ToInt32(Node* node, Node* frame_state);
81   Node* LowerCheckedTaggedSignedToInt32(Node* node, Node* frame_state);
82   Node* LowerCheckedTaggedToInt32(Node* node, Node* frame_state);
83   Node* LowerCheckedTaggedToFloat64(Node* node, Node* frame_state);
84   Node* LowerCheckedTaggedToTaggedSigned(Node* node, Node* frame_state);
85   Node* LowerCheckedTaggedToTaggedPointer(Node* node, Node* frame_state);
86   Node* LowerChangeTaggedToFloat64(Node* node);
87   void TruncateTaggedPointerToBit(Node* node, GraphAssemblerLabel<1>* done);
88   Node* LowerTruncateTaggedToBit(Node* node);
89   Node* LowerTruncateTaggedPointerToBit(Node* node);
90   Node* LowerTruncateTaggedToFloat64(Node* node);
91   Node* LowerTruncateTaggedToWord32(Node* node);
92   Node* LowerCheckedTruncateTaggedToWord32(Node* node, Node* frame_state);
93   Node* LowerAllocate(Node* node);
94   Node* LowerNumberToString(Node* node);
95   Node* LowerObjectIsArrayBufferView(Node* node);
96   Node* LowerObjectIsBigInt(Node* node);
97   Node* LowerObjectIsCallable(Node* node);
98   Node* LowerObjectIsConstructor(Node* node);
99   Node* LowerObjectIsDetectableCallable(Node* node);
100   Node* LowerObjectIsMinusZero(Node* node);
101   Node* LowerObjectIsNaN(Node* node);
102   Node* LowerNumberIsNaN(Node* node);
103   Node* LowerObjectIsNonCallable(Node* node);
104   Node* LowerObjectIsNumber(Node* node);
105   Node* LowerObjectIsReceiver(Node* node);
106   Node* LowerObjectIsSmi(Node* node);
107   Node* LowerObjectIsString(Node* node);
108   Node* LowerObjectIsSymbol(Node* node);
109   Node* LowerObjectIsUndetectable(Node* node);
110   Node* LowerNumberIsFloat64Hole(Node* node);
111   Node* LowerNumberIsFinite(Node* node);
112   Node* LowerObjectIsFiniteNumber(Node* node);
113   Node* LowerNumberIsInteger(Node* node);
114   Node* LowerObjectIsInteger(Node* node);
115   Node* LowerNumberIsSafeInteger(Node* node);
116   Node* LowerObjectIsSafeInteger(Node* node);
117   Node* LowerArgumentsFrame(Node* node);
118   Node* LowerArgumentsLength(Node* node);
119   Node* LowerNewDoubleElements(Node* node);
120   Node* LowerNewSmiOrObjectElements(Node* node);
121   Node* LowerNewArgumentsElements(Node* node);
122   Node* LowerNewConsString(Node* node);
123   Node* LowerArrayBufferWasNeutered(Node* node);
124   Node* LowerSameValue(Node* node);
125   Node* LowerDeadValue(Node* node);
126   Node* LowerStringToNumber(Node* node);
127   Node* LowerStringCharCodeAt(Node* node);
128   Node* LowerStringCodePointAt(Node* node, UnicodeEncoding encoding);
129   Node* LowerStringToLowerCaseIntl(Node* node);
130   Node* LowerStringToUpperCaseIntl(Node* node);
131   Node* LowerStringFromSingleCharCode(Node* node);
132   Node* LowerStringFromSingleCodePoint(Node* node);
133   Node* LowerStringIndexOf(Node* node);
134   Node* LowerStringSubstring(Node* node);
135   Node* LowerStringLength(Node* node);
136   Node* LowerStringEqual(Node* node);
137   Node* LowerStringLessThan(Node* node);
138   Node* LowerStringLessThanOrEqual(Node* node);
139   Node* LowerCheckFloat64Hole(Node* node, Node* frame_state);
140   Node* LowerCheckNotTaggedHole(Node* node, Node* frame_state);
141   Node* LowerConvertTaggedHoleToUndefined(Node* node);
142   void LowerCheckEqualsInternalizedString(Node* node, Node* frame_state);
143   void LowerCheckEqualsSymbol(Node* node, Node* frame_state);
144   Node* LowerTypeOf(Node* node);
145   Node* LowerToBoolean(Node* node);
146   Node* LowerPlainPrimitiveToNumber(Node* node);
147   Node* LowerPlainPrimitiveToWord32(Node* node);
148   Node* LowerPlainPrimitiveToFloat64(Node* node);
149   Node* LowerEnsureWritableFastElements(Node* node);
150   Node* LowerMaybeGrowFastElements(Node* node, Node* frame_state);
151   void LowerTransitionElementsKind(Node* node);
152   Node* LowerLoadFieldByIndex(Node* node);
153   Node* LowerLoadTypedElement(Node* node);
154   Node* LowerLoadDataViewElement(Node* node);
155   void LowerStoreTypedElement(Node* node);
156   void LowerStoreDataViewElement(Node* node);
157   void LowerStoreSignedSmallElement(Node* node);
158   Node* LowerFindOrderedHashMapEntry(Node* node);
159   Node* LowerFindOrderedHashMapEntryForInt32Key(Node* node);
160   void LowerTransitionAndStoreElement(Node* node);
161   void LowerTransitionAndStoreNumberElement(Node* node);
162   void LowerTransitionAndStoreNonNumberElement(Node* node);
163   void LowerRuntimeAbort(Node* node);
164   Node* LowerConvertReceiver(Node* node);
165   Node* LowerDateNow(Node* node);
166 
167   // Lowering of optional operators.
168   Maybe<Node*> LowerFloat64RoundUp(Node* node);
169   Maybe<Node*> LowerFloat64RoundDown(Node* node);
170   Maybe<Node*> LowerFloat64RoundTiesEven(Node* node);
171   Maybe<Node*> LowerFloat64RoundTruncate(Node* node);
172 
173   Node* AllocateHeapNumberWithValue(Node* node);
174   Node* BuildCheckedFloat64ToInt32(CheckForMinusZeroMode mode,
175                                    const VectorSlotPair& feedback, Node* value,
176                                    Node* frame_state);
177   Node* BuildCheckedHeapNumberOrOddballToFloat64(CheckTaggedInputMode mode,
178                                                  const VectorSlotPair& feedback,
179                                                  Node* value,
180                                                  Node* frame_state);
181   Node* BuildReverseBytes(ExternalArrayType type, Node* value);
182   Node* BuildFloat64RoundDown(Node* value);
183   Node* BuildFloat64RoundTruncate(Node* input);
184   Node* BuildUint32Mod(Node* lhs, Node* rhs);
185   Node* ComputeIntegerHash(Node* value);
186   Node* LowerStringComparison(Callable const& callable, Node* node);
187   Node* IsElementsKindGreaterThan(Node* kind, ElementsKind reference_kind);
188 
189   Node* ChangeInt32ToSmi(Node* value);
190   Node* ChangeInt32ToIntPtr(Node* value);
191   Node* ChangeIntPtrToInt32(Node* value);
192   Node* ChangeUint32ToUintPtr(Node* value);
193   Node* ChangeUint32ToSmi(Node* value);
194   Node* ChangeSmiToIntPtr(Node* value);
195   Node* ChangeSmiToInt32(Node* value);
196   Node* ObjectIsSmi(Node* value);
197   Node* LoadFromSeqString(Node* receiver, Node* position, Node* is_one_byte);
198 
199   Node* SmiMaxValueConstant();
200   Node* SmiShiftBitsConstant();
201   void TransitionElementsTo(Node* node, Node* array, ElementsKind from,
202                             ElementsKind to);
203 
204   Factory* factory() const;
205   Isolate* isolate() const;
jsgraph()206   JSGraph* jsgraph() const { return js_graph_; }
207   Graph* graph() const;
schedule()208   Schedule* schedule() const { return schedule_; }
temp_zone()209   Zone* temp_zone() const { return temp_zone_; }
210   CommonOperatorBuilder* common() const;
211   SimplifiedOperatorBuilder* simplified() const;
212   MachineOperatorBuilder* machine() const;
213 
gasm()214   GraphAssembler* gasm() { return &graph_assembler_; }
215 
216   JSGraph* js_graph_;
217   Schedule* schedule_;
218   Zone* temp_zone_;
219   MaskArrayIndexEnable mask_array_index_;
220   RegionObservability region_observability_ = RegionObservability::kObservable;
221   SourcePositionTable* source_positions_;
222   NodeOriginTable* node_origins_;
223   GraphAssembler graph_assembler_;
224   Node* frame_state_zapper_;  // For tracking down compiler::Node::New crashes.
225 };
226 
227 }  // namespace compiler
228 }  // namespace internal
229 }  // namespace v8
230 
231 #endif  // V8_COMPILER_EFFECT_CONTROL_LINEARIZER_H_
232