| // Copyright 2015 the V8 project authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| #include "src/compiler/effect-control-linearizer.h" |
| |
| #include "include/v8-fast-api-calls.h" |
| #include "src/base/bits.h" |
| #include "src/codegen/code-factory.h" |
| #include "src/codegen/machine-type.h" |
| #include "src/common/ptr-compr-inl.h" |
| #include "src/compiler/access-builder.h" |
| #include "src/compiler/compiler-source-position-table.h" |
| #include "src/compiler/feedback-source.h" |
| #include "src/compiler/graph-assembler.h" |
| #include "src/compiler/js-graph.h" |
| #include "src/compiler/js-heap-broker.h" |
| #include "src/compiler/linkage.h" |
| #include "src/compiler/node-matchers.h" |
| #include "src/compiler/node-origin-table.h" |
| #include "src/compiler/node-properties.h" |
| #include "src/compiler/node.h" |
| #include "src/compiler/schedule.h" |
| #include "src/execution/frames.h" |
| #include "src/heap/factory-inl.h" |
| #include "src/objects/heap-number.h" |
| #include "src/objects/oddball.h" |
| #include "src/objects/ordered-hash-table.h" |
| |
| namespace v8 { |
| namespace internal { |
| namespace compiler { |
| |
| class EffectControlLinearizer { |
| public: |
| EffectControlLinearizer(JSGraph* js_graph, Schedule* schedule, |
| Zone* temp_zone, |
| SourcePositionTable* source_positions, |
| NodeOriginTable* node_origins, |
| MaskArrayIndexEnable mask_array_index, |
| MaintainSchedule maintain_schedule, |
| JSHeapBroker* broker) |
| : js_graph_(js_graph), |
| schedule_(schedule), |
| temp_zone_(temp_zone), |
| mask_array_index_(mask_array_index), |
| maintain_schedule_(maintain_schedule), |
| source_positions_(source_positions), |
| node_origins_(node_origins), |
| broker_(broker), |
| graph_assembler_(js_graph, temp_zone, base::nullopt, |
| should_maintain_schedule() ? schedule : nullptr), |
| frame_state_zapper_(nullptr), |
| fast_api_call_stack_slot_(nullptr) {} |
| |
| void Run(); |
| |
| private: |
| void UpdateEffectControlForNode(Node* node); |
| void ProcessNode(Node* node, Node** frame_state); |
| |
| bool TryWireInStateEffect(Node* node, Node* frame_state); |
| Node* LowerChangeBitToTagged(Node* node); |
| Node* LowerChangeInt31ToTaggedSigned(Node* node); |
| Node* LowerChangeInt32ToTagged(Node* node); |
| Node* LowerChangeInt64ToTagged(Node* node); |
| Node* LowerChangeUint32ToTagged(Node* node); |
| Node* LowerChangeUint64ToTagged(Node* node); |
| Node* LowerChangeFloat64ToTagged(Node* node); |
| Node* LowerChangeFloat64ToTaggedPointer(Node* node); |
| Node* LowerChangeTaggedSignedToInt32(Node* node); |
| Node* LowerChangeTaggedSignedToInt64(Node* node); |
| Node* LowerChangeTaggedToBit(Node* node); |
| Node* LowerChangeTaggedToInt32(Node* node); |
| Node* LowerChangeTaggedToUint32(Node* node); |
| Node* LowerChangeTaggedToInt64(Node* node); |
| Node* LowerChangeTaggedToTaggedSigned(Node* node); |
| Node* LowerPoisonIndex(Node* node); |
| Node* LowerCheckInternalizedString(Node* node, Node* frame_state); |
| void LowerCheckMaps(Node* node, Node* frame_state); |
| void LowerDynamicCheckMaps(Node* node, Node* frame_state); |
| Node* LowerCompareMaps(Node* node); |
| Node* LowerCheckNumber(Node* node, Node* frame_state); |
| Node* LowerCheckClosure(Node* node, Node* frame_state); |
| Node* LowerCheckReceiver(Node* node, Node* frame_state); |
| Node* LowerCheckReceiverOrNullOrUndefined(Node* node, Node* frame_state); |
| Node* LowerCheckString(Node* node, Node* frame_state); |
| Node* LowerCheckBigInt(Node* node, Node* frame_state); |
| Node* LowerCheckSymbol(Node* node, Node* frame_state); |
| void LowerCheckIf(Node* node, Node* frame_state); |
| Node* LowerCheckedInt32Add(Node* node, Node* frame_state); |
| Node* LowerCheckedInt32Sub(Node* node, Node* frame_state); |
| Node* LowerCheckedInt32Div(Node* node, Node* frame_state); |
| Node* LowerCheckedInt32Mod(Node* node, Node* frame_state); |
| Node* LowerCheckedUint32Div(Node* node, Node* frame_state); |
| Node* LowerCheckedUint32Mod(Node* node, Node* frame_state); |
| Node* LowerCheckedInt32Mul(Node* node, Node* frame_state); |
| Node* LowerCheckedInt32ToTaggedSigned(Node* node, Node* frame_state); |
| Node* LowerCheckedInt64ToInt32(Node* node, Node* frame_state); |
| Node* LowerCheckedInt64ToTaggedSigned(Node* node, Node* frame_state); |
| Node* LowerCheckedUint32Bounds(Node* node, Node* frame_state); |
| Node* LowerCheckedUint32ToInt32(Node* node, Node* frame_state); |
| Node* LowerCheckedUint32ToTaggedSigned(Node* node, Node* frame_state); |
| Node* LowerCheckedUint64Bounds(Node* node, Node* frame_state); |
| Node* LowerCheckedUint64ToInt32(Node* node, Node* frame_state); |
| Node* LowerCheckedUint64ToTaggedSigned(Node* node, Node* frame_state); |
| Node* LowerCheckedFloat64ToInt32(Node* node, Node* frame_state); |
| Node* LowerCheckedFloat64ToInt64(Node* node, Node* frame_state); |
| Node* LowerCheckedTaggedSignedToInt32(Node* node, Node* frame_state); |
| Node* LowerCheckedTaggedToArrayIndex(Node* node, Node* frame_state); |
| Node* LowerCheckedTaggedToInt32(Node* node, Node* frame_state); |
| Node* LowerCheckedTaggedToInt64(Node* node, Node* frame_state); |
| Node* LowerCheckedTaggedToFloat64(Node* node, Node* frame_state); |
| Node* LowerCheckedTaggedToTaggedSigned(Node* node, Node* frame_state); |
| Node* LowerCheckedTaggedToTaggedPointer(Node* node, Node* frame_state); |
| Node* LowerBigIntAsUintN(Node* node, Node* frame_state); |
| Node* LowerChangeUint64ToBigInt(Node* node); |
| Node* LowerTruncateBigIntToUint64(Node* node); |
| Node* LowerChangeTaggedToFloat64(Node* node); |
| void TruncateTaggedPointerToBit(Node* node, GraphAssemblerLabel<1>* done); |
| Node* LowerTruncateTaggedToBit(Node* node); |
| Node* LowerTruncateTaggedPointerToBit(Node* node); |
| Node* LowerTruncateTaggedToFloat64(Node* node); |
| Node* LowerTruncateTaggedToWord32(Node* node); |
| Node* LowerCheckedTruncateTaggedToWord32(Node* node, Node* frame_state); |
| Node* LowerAllocate(Node* node); |
| Node* LowerNumberToString(Node* node); |
| Node* LowerObjectIsArrayBufferView(Node* node); |
| Node* LowerObjectIsBigInt(Node* node); |
| Node* LowerObjectIsCallable(Node* node); |
| Node* LowerObjectIsConstructor(Node* node); |
| Node* LowerObjectIsDetectableCallable(Node* node); |
| Node* LowerObjectIsMinusZero(Node* node); |
| Node* LowerNumberIsMinusZero(Node* node); |
| Node* LowerObjectIsNaN(Node* node); |
| Node* LowerNumberIsNaN(Node* node); |
| Node* LowerObjectIsNonCallable(Node* node); |
| Node* LowerObjectIsNumber(Node* node); |
| Node* LowerObjectIsReceiver(Node* node); |
| Node* LowerObjectIsSmi(Node* node); |
| Node* LowerObjectIsString(Node* node); |
| Node* LowerObjectIsSymbol(Node* node); |
| Node* LowerObjectIsUndetectable(Node* node); |
| Node* LowerNumberIsFloat64Hole(Node* node); |
| Node* LowerNumberIsFinite(Node* node); |
| Node* LowerObjectIsFiniteNumber(Node* node); |
| Node* LowerNumberIsInteger(Node* node); |
| Node* LowerObjectIsInteger(Node* node); |
| Node* LowerNumberIsSafeInteger(Node* node); |
| Node* LowerObjectIsSafeInteger(Node* node); |
| Node* LowerArgumentsFrame(Node* node); |
| Node* LowerArgumentsLength(Node* node); |
| Node* LowerRestLength(Node* node); |
| Node* LowerNewDoubleElements(Node* node); |
| Node* LowerNewSmiOrObjectElements(Node* node); |
| Node* LowerNewArgumentsElements(Node* node); |
| Node* LowerNewConsString(Node* node); |
| Node* LowerSameValue(Node* node); |
| Node* LowerSameValueNumbersOnly(Node* node); |
| Node* LowerNumberSameValue(Node* node); |
| Node* LowerDeadValue(Node* node); |
| Node* LowerStringConcat(Node* node); |
| Node* LowerStringToNumber(Node* node); |
| Node* LowerStringCharCodeAt(Node* node); |
| Node* LowerStringCodePointAt(Node* node); |
| Node* LowerStringToLowerCaseIntl(Node* node); |
| Node* LowerStringToUpperCaseIntl(Node* node); |
| Node* LowerStringFromSingleCharCode(Node* node); |
| Node* LowerStringFromSingleCodePoint(Node* node); |
| Node* LowerStringIndexOf(Node* node); |
| Node* LowerStringSubstring(Node* node); |
| Node* LowerStringFromCodePointAt(Node* node); |
| Node* LowerStringLength(Node* node); |
| Node* LowerStringEqual(Node* node); |
| Node* LowerStringLessThan(Node* node); |
| Node* LowerStringLessThanOrEqual(Node* node); |
| Node* LowerBigIntAdd(Node* node, Node* frame_state); |
| Node* LowerBigIntSubtract(Node* node, Node* frame_state); |
| Node* LowerBigIntNegate(Node* node); |
| Node* LowerCheckFloat64Hole(Node* node, Node* frame_state); |
| Node* LowerCheckNotTaggedHole(Node* node, Node* frame_state); |
| Node* LowerConvertTaggedHoleToUndefined(Node* node); |
| void LowerCheckEqualsInternalizedString(Node* node, Node* frame_state); |
| void LowerCheckEqualsSymbol(Node* node, Node* frame_state); |
| Node* LowerTypeOf(Node* node); |
| void LowerTierUpCheck(Node* node); |
| void LowerUpdateInterruptBudget(Node* node); |
| Node* LowerToBoolean(Node* node); |
| Node* LowerPlainPrimitiveToNumber(Node* node); |
| Node* LowerPlainPrimitiveToWord32(Node* node); |
| Node* LowerPlainPrimitiveToFloat64(Node* node); |
| Node* LowerEnsureWritableFastElements(Node* node); |
| Node* LowerMaybeGrowFastElements(Node* node, Node* frame_state); |
| void LowerTransitionElementsKind(Node* node); |
| Node* LowerLoadFieldByIndex(Node* node); |
| Node* LowerLoadMessage(Node* node); |
| Node* LowerFastApiCall(Node* node); |
| Node* LowerLoadTypedElement(Node* node); |
| Node* LowerLoadDataViewElement(Node* node); |
| Node* LowerLoadStackArgument(Node* node); |
| void LowerStoreMessage(Node* node); |
| void LowerStoreTypedElement(Node* node); |
| void LowerStoreDataViewElement(Node* node); |
| void LowerStoreSignedSmallElement(Node* node); |
| Node* LowerFindOrderedHashMapEntry(Node* node); |
| Node* LowerFindOrderedHashMapEntryForInt32Key(Node* node); |
| void LowerTransitionAndStoreElement(Node* node); |
| void LowerTransitionAndStoreNumberElement(Node* node); |
| void LowerTransitionAndStoreNonNumberElement(Node* node); |
| void LowerRuntimeAbort(Node* node); |
| Node* LowerAssertType(Node* node); |
| Node* LowerFoldConstant(Node* node); |
| Node* LowerConvertReceiver(Node* node); |
| Node* LowerDateNow(Node* node); |
| |
| // Lowering of optional operators. |
| Maybe<Node*> LowerFloat64RoundUp(Node* node); |
| Maybe<Node*> LowerFloat64RoundDown(Node* node); |
| Maybe<Node*> LowerFloat64RoundTiesEven(Node* node); |
| Maybe<Node*> LowerFloat64RoundTruncate(Node* node); |
| |
| Node* AllocateHeapNumberWithValue(Node* node); |
| Node* BuildCheckedFloat64ToInt32(CheckForMinusZeroMode mode, |
| const FeedbackSource& feedback, Node* value, |
| Node* frame_state); |
| Node* BuildCheckedFloat64ToInt64(CheckForMinusZeroMode mode, |
| const FeedbackSource& feedback, Node* value, |
| Node* frame_state); |
| Node* BuildCheckedFloat64ToIndex(const FeedbackSource& feedback, Node* value, |
| Node* frame_state); |
| Node* BuildCheckedHeapNumberOrOddballToFloat64(CheckTaggedInputMode mode, |
| const FeedbackSource& feedback, |
| Node* value, |
| Node* frame_state); |
| Node* BuildReverseBytes(ExternalArrayType type, Node* value); |
| Node* BuildFloat64RoundDown(Node* value); |
| Node* BuildFloat64RoundTruncate(Node* input); |
| template <size_t VarCount, size_t VarCount2> |
| void SmiTagOrOverflow(Node* value, GraphAssemblerLabel<VarCount>* if_overflow, |
| GraphAssemblerLabel<VarCount2>* done); |
| Node* SmiTagOrDeopt(Node* value, const CheckParameters& params, |
| Node* frame_state); |
| Node* BuildUint32Mod(Node* lhs, Node* rhs); |
| Node* ComputeUnseededHash(Node* value); |
| Node* LowerStringComparison(Callable const& callable, Node* node); |
| Node* IsElementsKindGreaterThan(Node* kind, ElementsKind reference_kind); |
| |
| Node* BuildTypedArrayDataPointer(Node* base, Node* external); |
| |
| template <typename... Args> |
| Node* CallBuiltin(Builtins::Name builtin, Operator::Properties properties, |
| Args...); |
| |
| Node* ChangeInt32ToSmi(Node* value); |
| // In pointer compression, we smi-corrupt. This means the upper bits of a Smi |
| // are not important. ChangeTaggedInt32ToSmi has a known tagged int32 as input |
| // and takes advantage of the smi corruption by emitting a Bitcast node |
| // instead of a Change node in order to save instructions. |
| // In non pointer compression, it behaves like ChangeInt32ToSmi. |
| Node* ChangeTaggedInt32ToSmi(Node* value); |
| Node* ChangeInt32ToIntPtr(Node* value); |
| Node* ChangeInt64ToSmi(Node* value); |
| Node* ChangeIntPtrToInt32(Node* value); |
| Node* ChangeIntPtrToSmi(Node* value); |
| Node* ChangeUint32ToUintPtr(Node* value); |
| Node* ChangeUint32ToSmi(Node* value); |
| Node* ChangeSmiToIntPtr(Node* value); |
| Node* ChangeSmiToInt32(Node* value); |
| Node* ChangeSmiToInt64(Node* value); |
| Node* ObjectIsSmi(Node* value); |
| Node* LoadFromSeqString(Node* receiver, Node* position, Node* is_one_byte); |
| Node* TruncateWordToInt32(Node* value); |
| Node* MakeWeakForComparison(Node* heap_object); |
| Node* BuildIsWeakReferenceTo(Node* maybe_object, Node* value); |
| Node* BuildIsClearedWeakReference(Node* maybe_object); |
| Node* BuildIsStrongReference(Node* value); |
| Node* BuildStrongReferenceFromWeakReference(Node* value); |
| Node* SmiMaxValueConstant(); |
| Node* SmiShiftBitsConstant(); |
| void TransitionElementsTo(Node* node, Node* array, ElementsKind from, |
| ElementsKind to); |
| |
| // This function tries to migrate |value| if its map |value_map| is |
| // deprecated. It deopts, if either |value_map| isn't deprecated or migration |
| // fails. |
| void MigrateInstanceOrDeopt(Node* value, Node* value_map, Node* frame_state, |
| FeedbackSource const& feedback_source, |
| DeoptimizeReason reason); |
| |
| // Helper functions used in LowerDynamicCheckMaps |
| void BuildCallDynamicMapChecksBuiltin(Node* actual_value, |
| Node* actual_handler, |
| int feedback_slot_index, |
| GraphAssemblerLabel<0>* done, |
| Node* frame_state); |
| bool should_maintain_schedule() const { |
| return maintain_schedule_ == MaintainSchedule::kMaintain; |
| } |
| |
| Factory* factory() const { return isolate()->factory(); } |
| Isolate* isolate() const { return jsgraph()->isolate(); } |
| JSGraph* jsgraph() const { return js_graph_; } |
| Graph* graph() const { return js_graph_->graph(); } |
| Schedule* schedule() const { return schedule_; } |
| Zone* temp_zone() const { return temp_zone_; } |
| CommonOperatorBuilder* common() const { return js_graph_->common(); } |
| SimplifiedOperatorBuilder* simplified() const { |
| return js_graph_->simplified(); |
| } |
| MachineOperatorBuilder* machine() const { return js_graph_->machine(); } |
| JSGraphAssembler* gasm() { return &graph_assembler_; } |
| JSHeapBroker* broker() const { return broker_; } |
| |
| JSGraph* js_graph_; |
| Schedule* schedule_; |
| Zone* temp_zone_; |
| MaskArrayIndexEnable mask_array_index_; |
| MaintainSchedule maintain_schedule_; |
| RegionObservability region_observability_ = RegionObservability::kObservable; |
| SourcePositionTable* source_positions_; |
| NodeOriginTable* node_origins_; |
| JSHeapBroker* broker_; |
| JSGraphAssembler graph_assembler_; |
| Node* frame_state_zapper_; // For tracking down compiler::Node::New crashes. |
| Node* fast_api_call_stack_slot_; // For caching the stack slot allocated for |
| // fast API calls. |
| }; |
| |
| namespace { |
| |
| struct BlockEffectControlData { |
| Node* current_effect = nullptr; // New effect. |
| Node* current_control = nullptr; // New control. |
| Node* current_frame_state = nullptr; // New frame state. |
| }; |
| |
| class BlockEffectControlMap { |
| public: |
| explicit BlockEffectControlMap(Zone* temp_zone) : map_(temp_zone) {} |
| |
| BlockEffectControlData& For(BasicBlock* from, BasicBlock* to) { |
| return map_[std::make_pair(from->id().ToInt(), to->id().ToInt())]; |
| } |
| |
| const BlockEffectControlData& For(BasicBlock* from, BasicBlock* to) const { |
| return map_.at(std::make_pair(from->id().ToInt(), to->id().ToInt())); |
| } |
| |
| private: |
| using Key = std::pair<int32_t, int32_t>; |
| using Map = ZoneMap<Key, BlockEffectControlData>; |
| |
| Map map_; |
| }; |
| |
| // Effect phis that need to be updated after the first pass. |
| struct PendingEffectPhi { |
| Node* effect_phi; |
| BasicBlock* block; |
| |
| PendingEffectPhi(Node* effect_phi, BasicBlock* block) |
| : effect_phi(effect_phi), block(block) {} |
| }; |
| |
| void UpdateEffectPhi(Node* node, BasicBlock* block, |
| BlockEffectControlMap* block_effects) { |
| // Update all inputs to an effect phi with the effects from the given |
| // block->effect map. |
| DCHECK_EQ(IrOpcode::kEffectPhi, node->opcode()); |
| DCHECK_EQ(static_cast<size_t>(node->op()->EffectInputCount()), |
| block->PredecessorCount()); |
| for (int i = 0; i < node->op()->EffectInputCount(); i++) { |
| Node* input = node->InputAt(i); |
| BasicBlock* predecessor = block->PredecessorAt(static_cast<size_t>(i)); |
| const BlockEffectControlData& block_effect = |
| block_effects->For(predecessor, block); |
| Node* effect = block_effect.current_effect; |
| if (input != effect) { |
| node->ReplaceInput(i, effect); |
| } |
| } |
| } |
| |
| void UpdateBlockControl(BasicBlock* block, |
| BlockEffectControlMap* block_effects) { |
| Node* control = block->NodeAt(0); |
| DCHECK(NodeProperties::IsControl(control)); |
| |
| // Do not rewire the end node. |
| if (control->opcode() == IrOpcode::kEnd) return; |
| |
| // Update all inputs to the given control node with the correct control. |
| DCHECK(control->opcode() == IrOpcode::kMerge || |
| static_cast<size_t>(control->op()->ControlInputCount()) == |
| block->PredecessorCount()); |
| if (static_cast<size_t>(control->op()->ControlInputCount()) != |
| block->PredecessorCount()) { |
| return; // We already re-wired the control inputs of this node. |
| } |
| for (int i = 0; i < control->op()->ControlInputCount(); i++) { |
| Node* input = NodeProperties::GetControlInput(control, i); |
| BasicBlock* predecessor = block->PredecessorAt(static_cast<size_t>(i)); |
| const BlockEffectControlData& block_effect = |
| block_effects->For(predecessor, block); |
| if (input != block_effect.current_control) { |
| NodeProperties::ReplaceControlInput(control, block_effect.current_control, |
| i); |
| } |
| } |
| } |
| |
| void RemoveRenameNode(Node* node) { |
| DCHECK(IrOpcode::kFinishRegion == node->opcode() || |
| IrOpcode::kBeginRegion == node->opcode() || |
| IrOpcode::kTypeGuard == node->opcode()); |
| // Update the value/context uses to the value input of the finish node and |
| // the effect uses to the effect input. |
| for (Edge edge : node->use_edges()) { |
| DCHECK(!edge.from()->IsDead()); |
| if (NodeProperties::IsEffectEdge(edge)) { |
| edge.UpdateTo(NodeProperties::GetEffectInput(node)); |
| } else { |
| DCHECK(!NodeProperties::IsControlEdge(edge)); |
| DCHECK(!NodeProperties::IsFrameStateEdge(edge)); |
| edge.UpdateTo(node->InputAt(0)); |
| } |
| } |
| node->Kill(); |
| } |
| |
| void TryCloneBranch(Node* node, BasicBlock* block, Zone* temp_zone, |
| Graph* graph, CommonOperatorBuilder* common, |
| BlockEffectControlMap* block_effects, |
| SourcePositionTable* source_positions, |
| NodeOriginTable* node_origins) { |
| DCHECK_EQ(IrOpcode::kBranch, node->opcode()); |
| |
| // This optimization is a special case of (super)block cloning. It takes an |
| // input graph as shown below and clones the Branch node for every predecessor |
| // to the Merge, essentially removing the Merge completely. This avoids |
| // materializing the bit for the Phi and may offer potential for further |
| // branch folding optimizations (i.e. because one or more inputs to the Phi is |
| // a constant). Note that there may be more Phi nodes hanging off the Merge, |
| // but we can only a certain subset of them currently (actually only Phi and |
| // EffectPhi nodes whose uses have either the IfTrue or IfFalse as control |
| // input). |
| |
| // Control1 ... ControlN |
| // ^ ^ |
| // | | Cond1 ... CondN |
| // +----+ +----+ ^ ^ |
| // | | | | |
| // | | +----+ | |
| // Merge<--+ | +------------+ |
| // ^ \|/ |
| // | Phi |
| // | | |
| // Branch----+ |
| // ^ |
| // | |
| // +-----+-----+ |
| // | | |
| // IfTrue IfFalse |
| // ^ ^ |
| // | | |
| |
| // The resulting graph (modulo the Phi and EffectPhi nodes) looks like this: |
| |
| // Control1 Cond1 ... ControlN CondN |
| // ^ ^ ^ ^ |
| // \ / \ / |
| // Branch ... Branch |
| // ^ ^ |
| // | | |
| // +---+---+ +---+----+ |
| // | | | | |
| // IfTrue IfFalse ... IfTrue IfFalse |
| // ^ ^ ^ ^ |
| // | | | | |
| // +--+ +-------------+ | |
| // | | +--------------+ +--+ |
| // | | | | |
| // Merge Merge |
| // ^ ^ |
| // | | |
| |
| SourcePositionTable::Scope scope(source_positions, |
| source_positions->GetSourcePosition(node)); |
| NodeOriginTable::Scope origin_scope(node_origins, "clone branch", node); |
| Node* branch = node; |
| Node* cond = NodeProperties::GetValueInput(branch, 0); |
| if (!cond->OwnedBy(branch) || cond->opcode() != IrOpcode::kPhi) return; |
| Node* merge = NodeProperties::GetControlInput(branch); |
| if (merge->opcode() != IrOpcode::kMerge || |
| NodeProperties::GetControlInput(cond) != merge) { |
| return; |
| } |
| // Grab the IfTrue/IfFalse projections of the Branch. |
| BranchMatcher matcher(branch); |
| // Check/collect other Phi/EffectPhi nodes hanging off the Merge. |
| NodeVector phis(temp_zone); |
| for (Node* const use : merge->uses()) { |
| if (use == branch || use == cond) continue; |
| // We cannot currently deal with non-Phi/EffectPhi nodes hanging off the |
| // Merge. Ideally, we would just clone the nodes (and everything that |
| // depends on it to some distant join point), but that requires knowledge |
| // about dominance/post-dominance. |
| if (!NodeProperties::IsPhi(use)) return; |
| for (Edge edge : use->use_edges()) { |
| // Right now we can only handle Phi/EffectPhi nodes whose uses are |
| // directly control-dependend on either the IfTrue or the IfFalse |
| // successor, because we know exactly how to update those uses. |
| if (edge.from()->op()->ControlInputCount() != 1) return; |
| Node* control = NodeProperties::GetControlInput(edge.from()); |
| if (NodeProperties::IsPhi(edge.from())) { |
| control = NodeProperties::GetControlInput(control, edge.index()); |
| } |
| if (control != matcher.IfTrue() && control != matcher.IfFalse()) return; |
| } |
| phis.push_back(use); |
| } |
| BranchHint const hint = BranchHintOf(branch->op()); |
| int const input_count = merge->op()->ControlInputCount(); |
| DCHECK_LE(1, input_count); |
| Node** const inputs = graph->zone()->NewArray<Node*>(2 * input_count); |
| Node** const merge_true_inputs = &inputs[0]; |
| Node** const merge_false_inputs = &inputs[input_count]; |
| for (int index = 0; index < input_count; ++index) { |
| Node* cond1 = NodeProperties::GetValueInput(cond, index); |
| Node* control1 = NodeProperties::GetControlInput(merge, index); |
| Node* branch1 = graph->NewNode(common->Branch(hint), cond1, control1); |
| merge_true_inputs[index] = graph->NewNode(common->IfTrue(), branch1); |
| merge_false_inputs[index] = graph->NewNode(common->IfFalse(), branch1); |
| } |
| Node* const merge_true = matcher.IfTrue(); |
| Node* const merge_false = matcher.IfFalse(); |
| merge_true->TrimInputCount(0); |
| merge_false->TrimInputCount(0); |
| for (int i = 0; i < input_count; ++i) { |
| merge_true->AppendInput(graph->zone(), merge_true_inputs[i]); |
| merge_false->AppendInput(graph->zone(), merge_false_inputs[i]); |
| } |
| DCHECK_EQ(2u, block->SuccessorCount()); |
| NodeProperties::ChangeOp(matcher.IfTrue(), common->Merge(input_count)); |
| NodeProperties::ChangeOp(matcher.IfFalse(), common->Merge(input_count)); |
| int const true_index = |
| block->SuccessorAt(0)->NodeAt(0) == matcher.IfTrue() ? 0 : 1; |
| BlockEffectControlData* true_block_data = |
| &block_effects->For(block, block->SuccessorAt(true_index)); |
| BlockEffectControlData* false_block_data = |
| &block_effects->For(block, block->SuccessorAt(true_index ^ 1)); |
| for (Node* const phi : phis) { |
| for (int index = 0; index < input_count; ++index) { |
| inputs[index] = phi->InputAt(index); |
| } |
| inputs[input_count] = merge_true; |
| Node* phi_true = graph->NewNode(phi->op(), input_count + 1, inputs); |
| inputs[input_count] = merge_false; |
| Node* phi_false = graph->NewNode(phi->op(), input_count + 1, inputs); |
| if (phi->UseCount() == 0) { |
| DCHECK_EQ(phi->opcode(), IrOpcode::kEffectPhi); |
| } else { |
| for (Edge edge : phi->use_edges()) { |
| Node* control = NodeProperties::GetControlInput(edge.from()); |
| if (NodeProperties::IsPhi(edge.from())) { |
| control = NodeProperties::GetControlInput(control, edge.index()); |
| } |
| DCHECK(control == matcher.IfTrue() || control == matcher.IfFalse()); |
| edge.UpdateTo((control == matcher.IfTrue()) ? phi_true : phi_false); |
| } |
| } |
| if (phi->opcode() == IrOpcode::kEffectPhi) { |
| true_block_data->current_effect = phi_true; |
| false_block_data->current_effect = phi_false; |
| } |
| phi->Kill(); |
| } |
| // Fix up IfTrue and IfFalse and kill all dead nodes. |
| if (branch == block->control_input()) { |
| true_block_data->current_control = merge_true; |
| false_block_data->current_control = merge_false; |
| } |
| branch->Kill(); |
| cond->Kill(); |
| merge->Kill(); |
| } |
| |
| } // namespace |
| |
| void EffectControlLinearizer::Run() { |
| BlockEffectControlMap block_effects(temp_zone()); |
| ZoneVector<PendingEffectPhi> pending_effect_phis(temp_zone()); |
| ZoneVector<BasicBlock*> pending_block_controls(temp_zone()); |
| NodeVector inputs_buffer(temp_zone()); |
| |
| // TODO(rmcilroy) We should not depend on having rpo_order on schedule, and |
| // instead just do our own RPO walk here. |
| for (BasicBlock* block : *(schedule()->rpo_order())) { |
| if (block != schedule()->start() && block->PredecessorCount() == 0) { |
| // Block has been removed from the schedule by a preceeding unreachable |
| // node, just skip it. |
| continue; |
| } |
| |
| gasm()->Reset(block); |
| |
| BasicBlock::iterator instr = block->begin(); |
| BasicBlock::iterator end_instr = block->end(); |
| |
| // The control node should be the first. |
| Node* control = *instr; |
| gasm()->AddNode(control); |
| |
| DCHECK(NodeProperties::IsControl(control)); |
| bool has_incoming_backedge = IrOpcode::kLoop == control->opcode(); |
| // Update the control inputs. |
| if (has_incoming_backedge) { |
| // If there are back edges, we need to update later because we have not |
| // computed the control yet. |
| pending_block_controls.push_back(block); |
| } else { |
| // If there are no back edges, we can update now. |
| UpdateBlockControl(block, &block_effects); |
| } |
| instr++; |
| |
| // Iterate over the phis and update the effect phis. |
| Node* effect_phi = nullptr; |
| Node* terminate = nullptr; |
| for (; instr != end_instr; instr++) { |
| Node* node = *instr; |
| // Only go through the phis and effect phis. |
| if (node->opcode() == IrOpcode::kEffectPhi) { |
| // There should be at most one effect phi in a block. |
| DCHECK_NULL(effect_phi); |
| // IfException blocks should not have effect phis. |
| DCHECK_NE(IrOpcode::kIfException, control->opcode()); |
| effect_phi = node; |
| } else if (node->opcode() == IrOpcode::kPhi) { |
| // Just skip phis. |
| } else if (node->opcode() == IrOpcode::kTerminate) { |
| DCHECK_NULL(terminate); |
| terminate = node; |
| } else { |
| break; |
| } |
| gasm()->AddNode(node); |
| } |
| |
| if (effect_phi) { |
| // Make sure we update the inputs to the incoming blocks' effects. |
| if (has_incoming_backedge) { |
| // In case of loops, we do not update the effect phi immediately |
| // because the back predecessor has not been handled yet. We just |
| // record the effect phi for later processing. |
| pending_effect_phis.push_back(PendingEffectPhi(effect_phi, block)); |
| } else { |
| UpdateEffectPhi(effect_phi, block, &block_effects); |
| } |
| } |
| |
| Node* effect = effect_phi; |
| if (effect == nullptr) { |
| // There was no effect phi. |
| if (block == schedule()->start()) { |
| // Start block => effect is start. |
| DCHECK_EQ(graph()->start(), control); |
| effect = graph()->start(); |
| } else if (control->opcode() == IrOpcode::kEnd) { |
| // End block is just a dummy, no effect needed. |
| DCHECK_EQ(BasicBlock::kNone, block->control()); |
| DCHECK_EQ(1u, block->size()); |
| effect = nullptr; |
| } else { |
| // If all the predecessors have the same effect, we can use it as our |
| // current effect. |
| for (size_t i = 0; i < block->PredecessorCount(); ++i) { |
| const BlockEffectControlData& data = |
| block_effects.For(block->PredecessorAt(i), block); |
| if (!effect) effect = data.current_effect; |
| if (data.current_effect != effect) { |
| effect = nullptr; |
| break; |
| } |
| } |
| if (effect == nullptr) { |
| DCHECK_NE(IrOpcode::kIfException, control->opcode()); |
| // The input blocks do not have the same effect. We have |
| // to create an effect phi node. |
| inputs_buffer.clear(); |
| inputs_buffer.resize(block->PredecessorCount(), jsgraph()->Dead()); |
| inputs_buffer.push_back(control); |
| effect = graph()->NewNode( |
| common()->EffectPhi(static_cast<int>(block->PredecessorCount())), |
| static_cast<int>(inputs_buffer.size()), &(inputs_buffer.front())); |
| gasm()->AddNode(effect); |
| // For loops, we update the effect phi node later to break cycles. |
| if (control->opcode() == IrOpcode::kLoop) { |
| pending_effect_phis.push_back(PendingEffectPhi(effect, block)); |
| } else { |
| UpdateEffectPhi(effect, block, &block_effects); |
| } |
| } else if (control->opcode() == IrOpcode::kIfException) { |
| // The IfException is connected into the effect chain, so we need |
| // to update the effect here. |
| NodeProperties::ReplaceEffectInput(control, effect); |
| effect = control; |
| } |
| } |
| } |
| |
| // Fixup the Terminate node. |
| if (terminate != nullptr) { |
| NodeProperties::ReplaceEffectInput(terminate, effect); |
| } |
| |
| // The frame state at block entry is determined by the frame states leaving |
| // all predecessors. In case there is no frame state dominating this block, |
| // we can rely on a checkpoint being present before the next deoptimization. |
| Node* frame_state = nullptr; |
| if (block != schedule()->start()) { |
| // If all the predecessors have the same effect, we can use it |
| // as our current effect. |
| frame_state = |
| block_effects.For(block->PredecessorAt(0), block).current_frame_state; |
| for (size_t i = 1; i < block->PredecessorCount(); i++) { |
| if (block_effects.For(block->PredecessorAt(i), block) |
| .current_frame_state != frame_state) { |
| frame_state = nullptr; |
| frame_state_zapper_ = graph()->end(); |
| break; |
| } |
| } |
| } |
| |
| gasm()->InitializeEffectControl(effect, control); |
| |
| // Process the ordinary instructions. |
| for (; instr != end_instr; instr++) { |
| Node* node = *instr; |
| ProcessNode(node, &frame_state); |
| } |
| |
| block = gasm()->FinalizeCurrentBlock(block); |
| |
| switch (block->control()) { |
| case BasicBlock::kGoto: |
| case BasicBlock::kNone: |
| break; |
| case BasicBlock::kCall: |
| case BasicBlock::kTailCall: |
| case BasicBlock::kSwitch: |
| case BasicBlock::kReturn: |
| case BasicBlock::kDeoptimize: |
| case BasicBlock::kThrow: |
| case BasicBlock::kBranch: |
| UpdateEffectControlForNode(block->control_input()); |
| gasm()->UpdateEffectControlWith(block->control_input()); |
| break; |
| } |
| |
| if (!should_maintain_schedule() && |
| block->control() == BasicBlock::kBranch) { |
| TryCloneBranch(block->control_input(), block, temp_zone(), graph(), |
| common(), &block_effects, source_positions_, |
| node_origins_); |
| } |
| |
| // Store the effect, control and frame state for later use. |
| for (BasicBlock* successor : block->successors()) { |
| BlockEffectControlData* data = &block_effects.For(block, successor); |
| if (data->current_effect == nullptr) { |
| data->current_effect = gasm()->effect(); |
| } |
| if (data->current_control == nullptr) { |
| data->current_control = gasm()->control(); |
| } |
| data->current_frame_state = frame_state; |
| } |
| } |
| |
| for (BasicBlock* pending_block_control : pending_block_controls) { |
| UpdateBlockControl(pending_block_control, &block_effects); |
| } |
| // Update the incoming edges of the effect phis that could not be processed |
| // during the first pass (because they could have incoming back edges). |
| for (const PendingEffectPhi& pending_effect_phi : pending_effect_phis) { |
| UpdateEffectPhi(pending_effect_phi.effect_phi, pending_effect_phi.block, |
| &block_effects); |
| } |
| |
| schedule_->rpo_order()->clear(); |
| } |
| |
| void EffectControlLinearizer::UpdateEffectControlForNode(Node* node) { |
| // If the node takes an effect, replace with the current one. |
| if (node->op()->EffectInputCount() > 0) { |
| DCHECK_EQ(1, node->op()->EffectInputCount()); |
| NodeProperties::ReplaceEffectInput(node, gasm()->effect()); |
| } else { |
| // New effect chain is only started with a Start or ValueEffect node. |
| DCHECK(node->op()->EffectOutputCount() == 0 || |
| node->opcode() == IrOpcode::kStart); |
| } |
| |
| // Rewire control inputs. |
| for (int i = 0; i < node->op()->ControlInputCount(); i++) { |
| NodeProperties::ReplaceControlInput(node, gasm()->control(), i); |
| } |
| } |
| |
| void EffectControlLinearizer::ProcessNode(Node* node, Node** frame_state) { |
| SourcePositionTable::Scope scope(source_positions_, |
| source_positions_->GetSourcePosition(node)); |
| NodeOriginTable::Scope origin_scope(node_origins_, "process node", node); |
| |
| // If basic block is unreachable after this point, update the node's effect |
| // and control inputs to mark it as dead, but don't process further. |
| if (gasm()->effect() == jsgraph()->Dead()) { |
| UpdateEffectControlForNode(node); |
| return; |
| } |
| |
| // If the node needs to be wired into the effect/control chain, do this |
| // here. Pass current frame state for lowering to eager deoptimization. |
| if (TryWireInStateEffect(node, *frame_state)) { |
| return; |
| } |
| |
| // If the node has a visible effect, then there must be a checkpoint in the |
| // effect chain before we are allowed to place another eager deoptimization |
| // point. We zap the frame state to ensure this invariant is maintained. |
| if (region_observability_ == RegionObservability::kObservable && |
| !node->op()->HasProperty(Operator::kNoWrite)) { |
| *frame_state = nullptr; |
| frame_state_zapper_ = node; |
| } |
| |
| // Remove the end markers of 'atomic' allocation region because the |
| // region should be wired-in now. |
| if (node->opcode() == IrOpcode::kFinishRegion) { |
| // Reset the current region observability. |
| region_observability_ = RegionObservability::kObservable; |
| // Update the value uses to the value input of the finish node and |
| // the effect uses to the effect input. |
| return RemoveRenameNode(node); |
| } |
| if (node->opcode() == IrOpcode::kBeginRegion) { |
| // Determine the observability for this region and use that for all |
| // nodes inside the region (i.e. ignore the absence of kNoWrite on |
| // StoreField and other operators). |
| DCHECK_NE(RegionObservability::kNotObservable, region_observability_); |
| region_observability_ = RegionObservabilityOf(node->op()); |
| // Update the value uses to the value input of the finish node and |
| // the effect uses to the effect input. |
| return RemoveRenameNode(node); |
| } |
| if (node->opcode() == IrOpcode::kTypeGuard) { |
| return RemoveRenameNode(node); |
| } |
| |
| // Special treatment for checkpoint nodes. |
| if (node->opcode() == IrOpcode::kCheckpoint) { |
| // Unlink the check point; effect uses will be updated to the incoming |
| // effect that is passed. The frame state is preserved for lowering. |
| DCHECK_EQ(RegionObservability::kObservable, region_observability_); |
| *frame_state = NodeProperties::GetFrameStateInput(node); |
| return; |
| } |
| |
| // The IfSuccess nodes should always start a basic block (and basic block |
| // start nodes are not handled in the ProcessNode method). |
| DCHECK_NE(IrOpcode::kIfSuccess, node->opcode()); |
| |
| UpdateEffectControlForNode(node); |
| |
| gasm()->AddNode(node); |
| |
| if (node->opcode() == IrOpcode::kUnreachable) { |
| // Break the effect chain on {Unreachable} and reconnect to the graph end. |
| // Mark the following code for deletion by connecting to the {Dead} node. |
| gasm()->ConnectUnreachableToEnd(); |
| } |
| } |
| |
| bool EffectControlLinearizer::TryWireInStateEffect(Node* node, |
| Node* frame_state) { |
| Node* result = nullptr; |
| switch (node->opcode()) { |
| case IrOpcode::kChangeBitToTagged: |
| result = LowerChangeBitToTagged(node); |
| break; |
| case IrOpcode::kChangeInt31ToTaggedSigned: |
| result = LowerChangeInt31ToTaggedSigned(node); |
| break; |
| case IrOpcode::kChangeInt32ToTagged: |
| result = LowerChangeInt32ToTagged(node); |
| break; |
| case IrOpcode::kChangeInt64ToTagged: |
| result = LowerChangeInt64ToTagged(node); |
| break; |
| case IrOpcode::kChangeUint32ToTagged: |
| result = LowerChangeUint32ToTagged(node); |
| break; |
| case IrOpcode::kChangeUint64ToTagged: |
| result = LowerChangeUint64ToTagged(node); |
| break; |
| case IrOpcode::kChangeFloat64ToTagged: |
| result = LowerChangeFloat64ToTagged(node); |
| break; |
| case IrOpcode::kChangeFloat64ToTaggedPointer: |
| result = LowerChangeFloat64ToTaggedPointer(node); |
| break; |
| case IrOpcode::kChangeTaggedSignedToInt32: |
| result = LowerChangeTaggedSignedToInt32(node); |
| break; |
| case IrOpcode::kChangeTaggedSignedToInt64: |
| result = LowerChangeTaggedSignedToInt64(node); |
| break; |
| case IrOpcode::kChangeTaggedToBit: |
| result = LowerChangeTaggedToBit(node); |
| break; |
| case IrOpcode::kChangeTaggedToInt32: |
| result = LowerChangeTaggedToInt32(node); |
| break; |
| case IrOpcode::kChangeTaggedToUint32: |
| result = LowerChangeTaggedToUint32(node); |
| break; |
| case IrOpcode::kChangeTaggedToInt64: |
| result = LowerChangeTaggedToInt64(node); |
| break; |
| case IrOpcode::kChangeTaggedToFloat64: |
| result = LowerChangeTaggedToFloat64(node); |
| break; |
| case IrOpcode::kChangeTaggedToTaggedSigned: |
| result = LowerChangeTaggedToTaggedSigned(node); |
| break; |
| case IrOpcode::kTruncateTaggedToBit: |
| result = LowerTruncateTaggedToBit(node); |
| break; |
| case IrOpcode::kTruncateTaggedPointerToBit: |
| result = LowerTruncateTaggedPointerToBit(node); |
| break; |
| case IrOpcode::kTruncateTaggedToFloat64: |
| result = LowerTruncateTaggedToFloat64(node); |
| break; |
| case IrOpcode::kPoisonIndex: |
| result = LowerPoisonIndex(node); |
| break; |
| case IrOpcode::kCheckClosure: |
| result = LowerCheckClosure(node, frame_state); |
| break; |
| case IrOpcode::kCheckMaps: |
| LowerCheckMaps(node, frame_state); |
| break; |
| case IrOpcode::kDynamicCheckMaps: |
| LowerDynamicCheckMaps(node, frame_state); |
| break; |
| case IrOpcode::kCompareMaps: |
| result = LowerCompareMaps(node); |
| break; |
| case IrOpcode::kCheckNumber: |
| result = LowerCheckNumber(node, frame_state); |
| break; |
| case IrOpcode::kCheckReceiver: |
| result = LowerCheckReceiver(node, frame_state); |
| break; |
| case IrOpcode::kCheckReceiverOrNullOrUndefined: |
| result = LowerCheckReceiverOrNullOrUndefined(node, frame_state); |
| break; |
| case IrOpcode::kCheckSymbol: |
| result = LowerCheckSymbol(node, frame_state); |
| break; |
| case IrOpcode::kCheckString: |
| result = LowerCheckString(node, frame_state); |
| break; |
| case IrOpcode::kCheckBigInt: |
| result = LowerCheckBigInt(node, frame_state); |
| break; |
| case IrOpcode::kCheckInternalizedString: |
| result = LowerCheckInternalizedString(node, frame_state); |
| break; |
| case IrOpcode::kCheckIf: |
| LowerCheckIf(node, frame_state); |
| break; |
| case IrOpcode::kCheckedInt32Add: |
| result = LowerCheckedInt32Add(node, frame_state); |
| break; |
| case IrOpcode::kCheckedInt32Sub: |
| result = LowerCheckedInt32Sub(node, frame_state); |
| break; |
| case IrOpcode::kCheckedInt32Div: |
| result = LowerCheckedInt32Div(node, frame_state); |
| break; |
| case IrOpcode::kCheckedInt32Mod: |
| result = LowerCheckedInt32Mod(node, frame_state); |
| break; |
| case IrOpcode::kCheckedUint32Div: |
| result = LowerCheckedUint32Div(node, frame_state); |
| break; |
| case IrOpcode::kCheckedUint32Mod: |
| result = LowerCheckedUint32Mod(node, frame_state); |
| break; |
| case IrOpcode::kCheckedInt32Mul: |
| result = LowerCheckedInt32Mul(node, frame_state); |
| break; |
| case IrOpcode::kCheckedInt32ToTaggedSigned: |
| result = LowerCheckedInt32ToTaggedSigned(node, frame_state); |
| break; |
| case IrOpcode::kCheckedInt64ToInt32: |
| result = LowerCheckedInt64ToInt32(node, frame_state); |
| break; |
| case IrOpcode::kCheckedInt64ToTaggedSigned: |
| result = LowerCheckedInt64ToTaggedSigned(node, frame_state); |
| break; |
| case IrOpcode::kCheckedUint32Bounds: |
| result = LowerCheckedUint32Bounds(node, frame_state); |
| break; |
| case IrOpcode::kCheckedUint32ToInt32: |
| result = LowerCheckedUint32ToInt32(node, frame_state); |
| break; |
| case IrOpcode::kCheckedUint32ToTaggedSigned: |
| result = LowerCheckedUint32ToTaggedSigned(node, frame_state); |
| break; |
| case IrOpcode::kCheckedUint64Bounds: |
| result = LowerCheckedUint64Bounds(node, frame_state); |
| break; |
| case IrOpcode::kCheckedUint64ToInt32: |
| result = LowerCheckedUint64ToInt32(node, frame_state); |
| break; |
| case IrOpcode::kCheckedUint64ToTaggedSigned: |
| result = LowerCheckedUint64ToTaggedSigned(node, frame_state); |
| break; |
| case IrOpcode::kCheckedFloat64ToInt32: |
| result = LowerCheckedFloat64ToInt32(node, frame_state); |
| break; |
| case IrOpcode::kCheckedFloat64ToInt64: |
| result = LowerCheckedFloat64ToInt64(node, frame_state); |
| break; |
| case IrOpcode::kCheckedTaggedSignedToInt32: |
| if (frame_state == nullptr) { |
| FATAL("No frame state (zapped by #%d: %s)", frame_state_zapper_->id(), |
| frame_state_zapper_->op()->mnemonic()); |
| } |
| result = LowerCheckedTaggedSignedToInt32(node, frame_state); |
| break; |
| case IrOpcode::kCheckedTaggedToArrayIndex: |
| result = LowerCheckedTaggedToArrayIndex(node, frame_state); |
| break; |
| case IrOpcode::kCheckedTaggedToInt32: |
| result = LowerCheckedTaggedToInt32(node, frame_state); |
| break; |
| case IrOpcode::kCheckedTaggedToInt64: |
| result = LowerCheckedTaggedToInt64(node, frame_state); |
| break; |
| case IrOpcode::kCheckedTaggedToFloat64: |
| result = LowerCheckedTaggedToFloat64(node, frame_state); |
| break; |
| case IrOpcode::kCheckedTaggedToTaggedSigned: |
| result = LowerCheckedTaggedToTaggedSigned(node, frame_state); |
| break; |
| case IrOpcode::kCheckedTaggedToTaggedPointer: |
| result = LowerCheckedTaggedToTaggedPointer(node, frame_state); |
| break; |
| case IrOpcode::kBigIntAsUintN: |
| result = LowerBigIntAsUintN(node, frame_state); |
| break; |
| case IrOpcode::kChangeUint64ToBigInt: |
| result = LowerChangeUint64ToBigInt(node); |
| break; |
| case IrOpcode::kTruncateBigIntToUint64: |
| result = LowerTruncateBigIntToUint64(node); |
| break; |
| case IrOpcode::kTruncateTaggedToWord32: |
| result = LowerTruncateTaggedToWord32(node); |
| break; |
| case IrOpcode::kCheckedTruncateTaggedToWord32: |
| result = LowerCheckedTruncateTaggedToWord32(node, frame_state); |
| break; |
| case IrOpcode::kNumberToString: |
| result = LowerNumberToString(node); |
| break; |
| case IrOpcode::kObjectIsArrayBufferView: |
| result = LowerObjectIsArrayBufferView(node); |
| break; |
| case IrOpcode::kObjectIsBigInt: |
| result = LowerObjectIsBigInt(node); |
| break; |
| case IrOpcode::kObjectIsCallable: |
| result = LowerObjectIsCallable(node); |
| break; |
| case IrOpcode::kObjectIsConstructor: |
| result = LowerObjectIsConstructor(node); |
| break; |
| case IrOpcode::kObjectIsDetectableCallable: |
| result = LowerObjectIsDetectableCallable(node); |
| break; |
| case IrOpcode::kObjectIsMinusZero: |
| result = LowerObjectIsMinusZero(node); |
| break; |
| case IrOpcode::kNumberIsMinusZero: |
| result = LowerNumberIsMinusZero(node); |
| break; |
| case IrOpcode::kObjectIsNaN: |
| result = LowerObjectIsNaN(node); |
| break; |
| case IrOpcode::kNumberIsNaN: |
| result = LowerNumberIsNaN(node); |
| break; |
| case IrOpcode::kObjectIsNonCallable: |
| result = LowerObjectIsNonCallable(node); |
| break; |
| case IrOpcode::kObjectIsNumber: |
| result = LowerObjectIsNumber(node); |
| break; |
| case IrOpcode::kObjectIsReceiver: |
| result = LowerObjectIsReceiver(node); |
| break; |
| case IrOpcode::kObjectIsSmi: |
| result = LowerObjectIsSmi(node); |
| break; |
| case IrOpcode::kObjectIsString: |
| result = LowerObjectIsString(node); |
| break; |
| case IrOpcode::kObjectIsSymbol: |
| result = LowerObjectIsSymbol(node); |
| break; |
| case IrOpcode::kObjectIsUndetectable: |
| result = LowerObjectIsUndetectable(node); |
| break; |
| case IrOpcode::kArgumentsFrame: |
| result = LowerArgumentsFrame(node); |
| break; |
| case IrOpcode::kArgumentsLength: |
| result = LowerArgumentsLength(node); |
| break; |
| case IrOpcode::kRestLength: |
| result = LowerRestLength(node); |
| break; |
| case IrOpcode::kToBoolean: |
| result = LowerToBoolean(node); |
| break; |
| case IrOpcode::kTypeOf: |
| result = LowerTypeOf(node); |
| break; |
| case IrOpcode::kTierUpCheck: |
| LowerTierUpCheck(node); |
| break; |
| case IrOpcode::kUpdateInterruptBudget: |
| LowerUpdateInterruptBudget(node); |
| break; |
| case IrOpcode::kNewDoubleElements: |
| result = LowerNewDoubleElements(node); |
| break; |
| case IrOpcode::kNewSmiOrObjectElements: |
| result = LowerNewSmiOrObjectElements(node); |
| break; |
| case IrOpcode::kNewArgumentsElements: |
| result = LowerNewArgumentsElements(node); |
| break; |
| case IrOpcode::kNewConsString: |
| result = LowerNewConsString(node); |
| break; |
| case IrOpcode::kSameValue: |
| result = LowerSameValue(node); |
| break; |
| case IrOpcode::kSameValueNumbersOnly: |
| result = LowerSameValueNumbersOnly(node); |
| break; |
| case IrOpcode::kNumberSameValue: |
| result = LowerNumberSameValue(node); |
| break; |
| case IrOpcode::kDeadValue: |
| result = LowerDeadValue(node); |
| break; |
| case IrOpcode::kStringConcat: |
| result = LowerStringConcat(node); |
| break; |
| case IrOpcode::kStringFromSingleCharCode: |
| result = LowerStringFromSingleCharCode(node); |
| break; |
| case IrOpcode::kStringFromSingleCodePoint: |
| result = LowerStringFromSingleCodePoint(node); |
| break; |
| case IrOpcode::kStringIndexOf: |
| result = LowerStringIndexOf(node); |
| break; |
| case IrOpcode::kStringFromCodePointAt: |
| result = LowerStringFromCodePointAt(node); |
| break; |
| case IrOpcode::kStringLength: |
| result = LowerStringLength(node); |
| break; |
| case IrOpcode::kStringToNumber: |
| result = LowerStringToNumber(node); |
| break; |
| case IrOpcode::kStringCharCodeAt: |
| result = LowerStringCharCodeAt(node); |
| break; |
| case IrOpcode::kStringCodePointAt: |
| result = LowerStringCodePointAt(node); |
| break; |
| case IrOpcode::kStringToLowerCaseIntl: |
| result = LowerStringToLowerCaseIntl(node); |
| break; |
| case IrOpcode::kStringToUpperCaseIntl: |
| result = LowerStringToUpperCaseIntl(node); |
| break; |
| case IrOpcode::kStringSubstring: |
| result = LowerStringSubstring(node); |
| break; |
| case IrOpcode::kStringEqual: |
| result = LowerStringEqual(node); |
| break; |
| case IrOpcode::kStringLessThan: |
| result = LowerStringLessThan(node); |
| break; |
| case IrOpcode::kStringLessThanOrEqual: |
| result = LowerStringLessThanOrEqual(node); |
| break; |
| case IrOpcode::kBigIntAdd: |
| result = LowerBigIntAdd(node, frame_state); |
| break; |
| case IrOpcode::kBigIntSubtract: |
| result = LowerBigIntSubtract(node, frame_state); |
| break; |
| case IrOpcode::kBigIntNegate: |
| result = LowerBigIntNegate(node); |
| break; |
| case IrOpcode::kNumberIsFloat64Hole: |
| result = LowerNumberIsFloat64Hole(node); |
| break; |
| case IrOpcode::kNumberIsFinite: |
| result = LowerNumberIsFinite(node); |
| break; |
| case IrOpcode::kObjectIsFiniteNumber: |
| result = LowerObjectIsFiniteNumber(node); |
| break; |
| case IrOpcode::kNumberIsInteger: |
| result = LowerNumberIsInteger(node); |
| break; |
| case IrOpcode::kObjectIsInteger: |
| result = LowerObjectIsInteger(node); |
| break; |
| case IrOpcode::kNumberIsSafeInteger: |
| result = LowerNumberIsSafeInteger(node); |
| break; |
| case IrOpcode::kObjectIsSafeInteger: |
| result = LowerObjectIsSafeInteger(node); |
| break; |
| case IrOpcode::kCheckFloat64Hole: |
| result = LowerCheckFloat64Hole(node, frame_state); |
| break; |
| case IrOpcode::kCheckNotTaggedHole: |
| result = LowerCheckNotTaggedHole(node, frame_state); |
| break; |
| case IrOpcode::kConvertTaggedHoleToUndefined: |
| result = LowerConvertTaggedHoleToUndefined(node); |
| break; |
| case IrOpcode::kCheckEqualsInternalizedString: |
| LowerCheckEqualsInternalizedString(node, frame_state); |
| break; |
| case IrOpcode::kAllocate: |
| result = LowerAllocate(node); |
| break; |
| case IrOpcode::kCheckEqualsSymbol: |
| LowerCheckEqualsSymbol(node, frame_state); |
| break; |
| case IrOpcode::kPlainPrimitiveToNumber: |
| result = LowerPlainPrimitiveToNumber(node); |
| break; |
| case IrOpcode::kPlainPrimitiveToWord32: |
| result = LowerPlainPrimitiveToWord32(node); |
| break; |
| case IrOpcode::kPlainPrimitiveToFloat64: |
| result = LowerPlainPrimitiveToFloat64(node); |
| break; |
| case IrOpcode::kEnsureWritableFastElements: |
| result = LowerEnsureWritableFastElements(node); |
| break; |
| case IrOpcode::kMaybeGrowFastElements: |
| result = LowerMaybeGrowFastElements(node, frame_state); |
| break; |
| case IrOpcode::kTransitionElementsKind: |
| LowerTransitionElementsKind(node); |
| break; |
| case IrOpcode::kLoadMessage: |
| result = LowerLoadMessage(node); |
| break; |
| case IrOpcode::kStoreMessage: |
| LowerStoreMessage(node); |
| break; |
| case IrOpcode::kFastApiCall: |
| result = LowerFastApiCall(node); |
| break; |
| case IrOpcode::kLoadFieldByIndex: |
| result = LowerLoadFieldByIndex(node); |
| break; |
| case IrOpcode::kLoadTypedElement: |
| result = LowerLoadTypedElement(node); |
| break; |
| case IrOpcode::kLoadDataViewElement: |
| result = LowerLoadDataViewElement(node); |
| break; |
| case IrOpcode::kLoadStackArgument: |
| result = LowerLoadStackArgument(node); |
| break; |
| case IrOpcode::kStoreTypedElement: |
| LowerStoreTypedElement(node); |
| break; |
| case IrOpcode::kStoreDataViewElement: |
| LowerStoreDataViewElement(node); |
| break; |
| case IrOpcode::kStoreSignedSmallElement: |
| LowerStoreSignedSmallElement(node); |
| break; |
| case IrOpcode::kFindOrderedHashMapEntry: |
| result = LowerFindOrderedHashMapEntry(node); |
| break; |
| case IrOpcode::kFindOrderedHashMapEntryForInt32Key: |
| result = LowerFindOrderedHashMapEntryForInt32Key(node); |
| break; |
| case IrOpcode::kTransitionAndStoreNumberElement: |
| LowerTransitionAndStoreNumberElement(node); |
| break; |
| case IrOpcode::kTransitionAndStoreNonNumberElement: |
| LowerTransitionAndStoreNonNumberElement(node); |
| break; |
| case IrOpcode::kTransitionAndStoreElement: |
| LowerTransitionAndStoreElement(node); |
| break; |
| case IrOpcode::kRuntimeAbort: |
| LowerRuntimeAbort(node); |
| break; |
| case IrOpcode::kAssertType: |
| result = LowerAssertType(node); |
| break; |
| case IrOpcode::kConvertReceiver: |
| result = LowerConvertReceiver(node); |
| break; |
| case IrOpcode::kFloat64RoundUp: |
| if (!LowerFloat64RoundUp(node).To(&result)) { |
| return false; |
| } |
| break; |
| case IrOpcode::kFloat64RoundDown: |
| if (!LowerFloat64RoundDown(node).To(&result)) { |
| return false; |
| } |
| break; |
| case IrOpcode::kFloat64RoundTruncate: |
| if (!LowerFloat64RoundTruncate(node).To(&result)) { |
| return false; |
| } |
| break; |
| case IrOpcode::kFloat64RoundTiesEven: |
| if (!LowerFloat64RoundTiesEven(node).To(&result)) { |
| return false; |
| } |
| break; |
| case IrOpcode::kDateNow: |
| result = LowerDateNow(node); |
| break; |
| case IrOpcode::kFoldConstant: |
| result = LowerFoldConstant(node); |
| break; |
| default: |
| return false; |
| } |
| |
| if ((result ? 1 : 0) != node->op()->ValueOutputCount()) { |
| FATAL( |
| "Effect control linearizer lowering of '%s':" |
| " value output count does not agree.", |
| node->op()->mnemonic()); |
| } |
| |
| NodeProperties::ReplaceUses(node, result, gasm()->effect(), |
| gasm()->control()); |
| return true; |
| } |
| |
| #define __ gasm()-> |
| |
| Node* EffectControlLinearizer::LowerChangeFloat64ToTagged(Node* node) { |
| CheckForMinusZeroMode mode = CheckMinusZeroModeOf(node->op()); |
| Node* value = node->InputAt(0); |
| |
| auto done = __ MakeLabel(MachineRepresentation::kTagged); |
| auto if_heapnumber = __ MakeDeferredLabel(); |
| auto if_int32 = __ MakeLabel(); |
| |
| Node* value32 = __ RoundFloat64ToInt32(value); |
| __ GotoIf(__ Float64Equal(value, __ ChangeInt32ToFloat64(value32)), |
| &if_int32); |
| __ Goto(&if_heapnumber); |
| |
| __ Bind(&if_int32); |
| { |
| if (mode == CheckForMinusZeroMode::kCheckForMinusZero) { |
| Node* zero = __ Int32Constant(0); |
| auto if_zero = __ MakeDeferredLabel(); |
| auto if_smi = __ MakeLabel(); |
| |
| __ GotoIf(__ Word32Equal(value32, zero), &if_zero); |
| __ Goto(&if_smi); |
| |
| __ Bind(&if_zero); |
| { |
| // In case of 0, we need to check the high bits for the IEEE -0 pattern. |
| __ GotoIf(__ Int32LessThan(__ Float64ExtractHighWord32(value), zero), |
| &if_heapnumber); |
| __ Goto(&if_smi); |
| } |
| |
| __ Bind(&if_smi); |
| } |
| |
| if (SmiValuesAre32Bits()) { |
| Node* value_smi = ChangeInt32ToSmi(value32); |
| __ Goto(&done, value_smi); |
| } else { |
| SmiTagOrOverflow(value32, &if_heapnumber, &done); |
| } |
| } |
| |
| __ Bind(&if_heapnumber); |
| { |
| Node* value_number = AllocateHeapNumberWithValue(value); |
| __ Goto(&done, value_number); |
| } |
| |
| __ Bind(&done); |
| return done.PhiAt(0); |
| } |
| |
| Node* EffectControlLinearizer::LowerChangeFloat64ToTaggedPointer(Node* node) { |
| Node* value = node->InputAt(0); |
| return AllocateHeapNumberWithValue(value); |
| } |
| |
| Node* EffectControlLinearizer::LowerChangeBitToTagged(Node* node) { |
| Node* value = node->InputAt(0); |
| |
| auto if_true = __ MakeLabel(); |
| auto done = __ MakeLabel(MachineRepresentation::kTagged); |
| |
| __ GotoIf(value, &if_true); |
| __ Goto(&done, __ FalseConstant()); |
| |
| __ Bind(&if_true); |
| __ Goto(&done, __ TrueConstant()); |
| |
| __ Bind(&done); |
| return done.PhiAt(0); |
| } |
| |
| Node* EffectControlLinearizer::LowerChangeInt31ToTaggedSigned(Node* node) { |
| Node* value = node->InputAt(0); |
| return ChangeInt32ToSmi(value); |
| } |
| |
| Node* EffectControlLinearizer::LowerChangeInt32ToTagged(Node* node) { |
| Node* value = node->InputAt(0); |
| |
| if (SmiValuesAre32Bits()) { |
| return ChangeInt32ToSmi(value); |
| } |
| DCHECK(SmiValuesAre31Bits()); |
| |
| auto if_overflow = __ MakeDeferredLabel(); |
| auto done = __ MakeLabel(MachineRepresentation::kTagged); |
| |
| SmiTagOrOverflow(value, &if_overflow, &done); |
| |
| __ Bind(&if_overflow); |
| Node* number = AllocateHeapNumberWithValue(__ ChangeInt32ToFloat64(value)); |
| __ Goto(&done, number); |
| |
| __ Bind(&done); |
| return done.PhiAt(0); |
| } |
| |
| Node* EffectControlLinearizer::LowerChangeInt64ToTagged(Node* node) { |
| Node* value = node->InputAt(0); |
| |
| auto if_not_in_smi_range = __ MakeDeferredLabel(); |
| auto done = __ MakeLabel(MachineRepresentation::kTagged); |
| |
| Node* value32 = __ TruncateInt64ToInt32(value); |
| __ GotoIfNot(__ Word64Equal(__ ChangeInt32ToInt64(value32), value), |
| &if_not_in_smi_range); |
| |
| if (SmiValuesAre32Bits()) { |
| Node* value_smi = ChangeInt64ToSmi(value); |
| __ Goto(&done, value_smi); |
| } else { |
| SmiTagOrOverflow(value32, &if_not_in_smi_range, &done); |
| } |
| |
| __ Bind(&if_not_in_smi_range); |
| Node* number = AllocateHeapNumberWithValue(__ ChangeInt64ToFloat64(value)); |
| __ Goto(&done, number); |
| |
| __ Bind(&done); |
| return done.PhiAt(0); |
| } |
| |
| Node* EffectControlLinearizer::LowerChangeUint32ToTagged(Node* node) { |
| Node* value = node->InputAt(0); |
| |
| auto if_not_in_smi_range = __ MakeDeferredLabel(); |
| auto done = __ MakeLabel(MachineRepresentation::kTagged); |
| |
| Node* check = __ Uint32LessThanOrEqual(value, SmiMaxValueConstant()); |
| __ GotoIfNot(check, &if_not_in_smi_range); |
| __ Goto(&done, ChangeUint32ToSmi(value)); |
| |
| __ Bind(&if_not_in_smi_range); |
| Node* number = AllocateHeapNumberWithValue(__ ChangeUint32ToFloat64(value)); |
| |
| __ Goto(&done, number); |
| __ Bind(&done); |
| |
| return done.PhiAt(0); |
| } |
| |
| Node* EffectControlLinearizer::LowerChangeUint64ToTagged(Node* node) { |
| Node* value = node->InputAt(0); |
| |
| auto if_not_in_smi_range = __ MakeDeferredLabel(); |
| auto done = __ MakeLabel(MachineRepresentation::kTagged); |
| |
| Node* check = |
| __ Uint64LessThanOrEqual(value, __ Int64Constant(Smi::kMaxValue)); |
| __ GotoIfNot(check, &if_not_in_smi_range); |
| __ Goto(&done, ChangeInt64ToSmi(value)); |
| |
| __ Bind(&if_not_in_smi_range); |
| Node* number = AllocateHeapNumberWithValue(__ ChangeInt64ToFloat64(value)); |
| |
| __ Goto(&done, number); |
| __ Bind(&done); |
| |
| return done.PhiAt(0); |
| } |
| |
| Node* EffectControlLinearizer::LowerChangeTaggedSignedToInt32(Node* node) { |
| Node* value = node->InputAt(0); |
| return ChangeSmiToInt32(value); |
| } |
| |
| Node* EffectControlLinearizer::LowerChangeTaggedSignedToInt64(Node* node) { |
| Node* value = node->InputAt(0); |
| return ChangeSmiToInt64(value); |
| } |
| |
| Node* EffectControlLinearizer::LowerChangeTaggedToBit(Node* node) { |
| Node* value = node->InputAt(0); |
| return __ TaggedEqual(value, __ TrueConstant()); |
| } |
| |
| void EffectControlLinearizer::TruncateTaggedPointerToBit( |
| Node* node, GraphAssemblerLabel<1>* done) { |
| Node* value = node->InputAt(0); |
| |
| auto if_heapnumber = __ MakeDeferredLabel(); |
| auto if_bigint = __ MakeDeferredLabel(); |
| |
| Node* zero = __ Int32Constant(0); |
| Node* fzero = __ Float64Constant(0.0); |
| |
| // Check if {value} is false. |
| __ GotoIf(__ TaggedEqual(value, __ FalseConstant()), done, zero); |
| |
| // Check if {value} is the empty string. |
| __ GotoIf(__ TaggedEqual(value, __ EmptyStringConstant()), done, zero); |
| |
| // Load the map of {value}. |
| Node* value_map = __ LoadField(AccessBuilder::ForMap(), value); |
| |
| // Check if the {value} is undetectable and immediately return false. |
| // This includes undefined and null. |
| Node* value_map_bitfield = |
| __ LoadField(AccessBuilder::ForMapBitField(), value_map); |
| __ GotoIfNot( |
| __ Word32Equal( |
| __ Word32And(value_map_bitfield, |
| __ Int32Constant(Map::Bits1::IsUndetectableBit::kMask)), |
| zero), |
| done, zero); |
| |
| // Check if {value} is a HeapNumber. |
| __ GotoIf(__ TaggedEqual(value_map, __ HeapNumberMapConstant()), |
| &if_heapnumber); |
| |
| // Check if {value} is a BigInt. |
| __ GotoIf(__ TaggedEqual(value_map, __ BigIntMapConstant()), &if_bigint); |
| |
| // All other values that reach here are true. |
| __ Goto(done, __ Int32Constant(1)); |
| |
| __ Bind(&if_heapnumber); |
| { |
| // For HeapNumber {value}, just check that its value is not 0.0, -0.0 or |
| // NaN. |
| Node* value_value = |
| __ LoadField(AccessBuilder::ForHeapNumberValue(), value); |
| __ Goto(done, __ Float64LessThan(fzero, __ Float64Abs(value_value))); |
| } |
| |
| __ Bind(&if_bigint); |
| { |
| Node* bitfield = __ LoadField(AccessBuilder::ForBigIntBitfield(), value); |
| Node* length_is_zero = __ Word32Equal( |
| __ Word32And(bitfield, __ Int32Constant(BigInt::LengthBits::kMask)), |
| __ Int32Constant(0)); |
| __ Goto(done, __ Word32Equal(length_is_zero, zero)); |
| } |
| } |
| |
| Node* EffectControlLinearizer::LowerTruncateTaggedToBit(Node* node) { |
| auto done = __ MakeLabel(MachineRepresentation::kBit); |
| auto if_smi = __ MakeDeferredLabel(); |
| |
| Node* value = node->InputAt(0); |
| __ GotoIf(ObjectIsSmi(value), &if_smi); |
| |
| TruncateTaggedPointerToBit(node, &done); |
| |
| __ Bind(&if_smi); |
| { |
| // If {value} is a Smi, then we only need to check that it's not zero. |
| __ Goto(&done, __ Word32Equal(__ TaggedEqual(value, __ SmiConstant(0)), |
| __ Int32Constant(0))); |
| } |
| |
| __ Bind(&done); |
| return done.PhiAt(0); |
| } |
| |
| Node* EffectControlLinearizer::LowerTruncateTaggedPointerToBit(Node* node) { |
| auto done = __ MakeLabel(MachineRepresentation::kBit); |
| |
| TruncateTaggedPointerToBit(node, &done); |
| |
| __ Bind(&done); |
| return done.PhiAt(0); |
| } |
| |
| Node* EffectControlLinearizer::LowerChangeTaggedToInt32(Node* node) { |
| Node* value = node->InputAt(0); |
| |
| auto if_not_smi = __ MakeDeferredLabel(); |
| auto done = __ MakeLabel(MachineRepresentation::kWord32); |
| |
| Node* check = ObjectIsSmi(value); |
| __ GotoIfNot(check, &if_not_smi); |
| __ Goto(&done, ChangeSmiToInt32(value)); |
| |
| __ Bind(&if_not_smi); |
| STATIC_ASSERT_FIELD_OFFSETS_EQUAL(HeapNumber::kValueOffset, |
| Oddball::kToNumberRawOffset); |
| Node* vfalse = __ LoadField(AccessBuilder::ForHeapNumberValue(), value); |
| vfalse = __ ChangeFloat64ToInt32(vfalse); |
| __ Goto(&done, vfalse); |
| |
| __ Bind(&done); |
| return done.PhiAt(0); |
| } |
| |
| Node* EffectControlLinearizer::LowerChangeTaggedToUint32(Node* node) { |
| Node* value = node->InputAt(0); |
| |
| auto if_not_smi = __ MakeDeferredLabel(); |
| auto done = __ MakeLabel(MachineRepresentation::kWord32); |
| |
| Node* check = ObjectIsSmi(value); |
| __ GotoIfNot(check, &if_not_smi); |
| __ Goto(&done, ChangeSmiToInt32(value)); |
| |
| __ Bind(&if_not_smi); |
| STATIC_ASSERT_FIELD_OFFSETS_EQUAL(HeapNumber::kValueOffset, |
| Oddball::kToNumberRawOffset); |
| Node* vfalse = __ LoadField(AccessBuilder::ForHeapNumberValue(), value); |
| vfalse = __ ChangeFloat64ToUint32(vfalse); |
| __ Goto(&done, vfalse); |
| |
| __ Bind(&done); |
| return done.PhiAt(0); |
| } |
| |
| Node* EffectControlLinearizer::LowerChangeTaggedToInt64(Node* node) { |
| Node* value = node->InputAt(0); |
| |
| auto if_not_smi = __ MakeDeferredLabel(); |
| auto done = __ MakeLabel(MachineRepresentation::kWord64); |
| |
| Node* check = ObjectIsSmi(value); |
| __ GotoIfNot(check, &if_not_smi); |
| __ Goto(&done, ChangeSmiToInt64(value)); |
| |
| __ Bind(&if_not_smi); |
| STATIC_ASSERT_FIELD_OFFSETS_EQUAL(HeapNumber::kValueOffset, |
| Oddball::kToNumberRawOffset); |
| Node* vfalse = __ LoadField(AccessBuilder::ForHeapNumberValue(), value); |
| vfalse = __ ChangeFloat64ToInt64(vfalse); |
| __ Goto(&done, vfalse); |
| |
| __ Bind(&done); |
| return done.PhiAt(0); |
| } |
| |
| Node* EffectControlLinearizer::LowerChangeTaggedToFloat64(Node* node) { |
| return LowerTruncateTaggedToFloat64(node); |
| } |
| |
| Node* EffectControlLinearizer::LowerChangeTaggedToTaggedSigned(Node* node) { |
| Node* value = node->InputAt(0); |
| |
| auto if_not_smi = __ MakeDeferredLabel(); |
| auto done = __ MakeLabel(MachineRepresentation::kWord32); |
| |
| Node* check = ObjectIsSmi(value); |
| __ GotoIfNot(check, &if_not_smi); |
| __ Goto(&done, value); |
| |
| __ Bind(&if_not_smi); |
| STATIC_ASSERT_FIELD_OFFSETS_EQUAL(HeapNumber::kValueOffset, |
| Oddball::kToNumberRawOffset); |
| Node* vfalse = __ LoadField(AccessBuilder::ForHeapNumberValue(), value); |
| vfalse = __ ChangeFloat64ToInt32(vfalse); |
| vfalse = ChangeInt32ToSmi(vfalse); |
| __ Goto(&done, vfalse); |
| |
| __ Bind(&done); |
| return done.PhiAt(0); |
| } |
| |
| Node* EffectControlLinearizer::LowerTruncateTaggedToFloat64(Node* node) { |
| Node* value = node->InputAt(0); |
| |
| auto if_not_smi = __ MakeDeferredLabel(); |
| auto done = __ MakeLabel(MachineRepresentation::kFloat64); |
| |
| Node* check = ObjectIsSmi(value); |
| __ GotoIfNot(check, &if_not_smi); |
| Node* vtrue = ChangeSmiToInt32(value); |
| vtrue = __ ChangeInt32ToFloat64(vtrue); |
| __ Goto(&done, vtrue); |
| |
| __ Bind(&if_not_smi); |
| STATIC_ASSERT_FIELD_OFFSETS_EQUAL(HeapNumber::kValueOffset, |
| Oddball::kToNumberRawOffset); |
| Node* vfalse = __ LoadField(AccessBuilder::ForHeapNumberValue(), value); |
| __ Goto(&done, vfalse); |
| |
| __ Bind(&done); |
| return done.PhiAt(0); |
| } |
| |
| Node* EffectControlLinearizer::LowerPoisonIndex(Node* node) { |
| Node* index = node->InputAt(0); |
| if (mask_array_index_ == MaskArrayIndexEnable::kMaskArrayIndex) { |
| index = __ Word32PoisonOnSpeculation(index); |
| } |
| return index; |
| } |
| |
| Node* EffectControlLinearizer::LowerCheckClosure(Node* node, |
| Node* frame_state) { |
| Handle<FeedbackCell> feedback_cell = FeedbackCellOf(node->op()); |
| Node* value = node->InputAt(0); |
| |
| // Check that {value} is actually a JSFunction. |
| Node* value_map = __ LoadField(AccessBuilder::ForMap(), value); |
| Node* value_instance_type = |
| __ LoadField(AccessBuilder::ForMapInstanceType(), value_map); |
| Node* check_instance_type = |
| __ Word32Equal(value_instance_type, __ Int32Constant(JS_FUNCTION_TYPE)); |
| __ DeoptimizeIfNot(DeoptimizeReason::kWrongCallTarget, FeedbackSource(), |
| check_instance_type, frame_state); |
| |
| // Check that the {value}s feedback vector cell matches the one |
| // we recorded before. |
| Node* value_cell = |
| __ LoadField(AccessBuilder::ForJSFunctionFeedbackCell(), value); |
| Node* check_cell = __ WordEqual(value_cell, __ HeapConstant(feedback_cell)); |
| __ DeoptimizeIfNot(DeoptimizeReason::kWrongFeedbackCell, FeedbackSource(), |
| check_cell, frame_state); |
| return value; |
| } |
| |
| void EffectControlLinearizer::MigrateInstanceOrDeopt( |
| Node* value, Node* value_map, Node* frame_state, |
| FeedbackSource const& feedback_source, DeoptimizeReason reason) { |
| // If map is not deprecated the migration attempt does not make sense. |
| Node* bitfield3 = __ LoadField(AccessBuilder::ForMapBitField3(), value_map); |
| Node* is_not_deprecated = __ Word32Equal( |
| __ Word32And(bitfield3, |
| __ Int32Constant(Map::Bits3::IsDeprecatedBit::kMask)), |
| __ Int32Constant(0)); |
| __ DeoptimizeIf(reason, feedback_source, is_not_deprecated, frame_state, |
| IsSafetyCheck::kCriticalSafetyCheck); |
| Operator::Properties properties = Operator::kNoDeopt | Operator::kNoThrow; |
| Runtime::FunctionId id = Runtime::kTryMigrateInstance; |
| auto call_descriptor = Linkage::GetRuntimeCallDescriptor( |
| graph()->zone(), id, 1, properties, CallDescriptor::kNoFlags); |
| Node* result = __ Call(call_descriptor, __ CEntryStubConstant(1), value, |
| __ ExternalConstant(ExternalReference::Create(id)), |
| __ Int32Constant(1), __ NoContextConstant()); |
| Node* check = ObjectIsSmi(result); |
| __ DeoptimizeIf(DeoptimizeReason::kInstanceMigrationFailed, feedback_source, |
| check, frame_state, IsSafetyCheck::kCriticalSafetyCheck); |
| } |
| |
| void EffectControlLinearizer::LowerCheckMaps(Node* node, Node* frame_state) { |
| CheckMapsParameters const& p = CheckMapsParametersOf(node->op()); |
| Node* value = node->InputAt(0); |
| |
| ZoneHandleSet<Map> const& maps = p.maps(); |
| size_t const map_count = maps.size(); |
| |
| if (p.flags() & CheckMapsFlag::kTryMigrateInstance) { |
| auto done = __ MakeLabel(); |
| auto migrate = __ MakeDeferredLabel(); |
| |
| // Load the current map of the {value}. |
| Node* value_map = __ LoadField(AccessBuilder::ForMap(), value); |
| |
| // Perform the map checks. |
| for (size_t i = 0; i < map_count; ++i) { |
| Node* map = __ HeapConstant(maps[i]); |
| Node* check = __ TaggedEqual(value_map, map); |
| if (i == map_count - 1) { |
| __ BranchWithCriticalSafetyCheck(check, &done, &migrate); |
| } else { |
| auto next_map = __ MakeLabel(); |
| __ BranchWithCriticalSafetyCheck(check, &done, &next_map); |
| __ Bind(&next_map); |
| } |
| } |
| |
| // Perform the (deferred) instance migration. |
| __ Bind(&migrate); |
| MigrateInstanceOrDeopt(value, value_map, frame_state, p.feedback(), |
| DeoptimizeReason::kWrongMap); |
| |
| // Reload the current map of the {value}. |
| value_map = __ LoadField(AccessBuilder::ForMap(), value); |
| |
| // Perform the map checks again. |
| for (size_t i = 0; i < map_count; ++i) { |
| Node* map = __ HeapConstant(maps[i]); |
| Node* check = __ TaggedEqual(value_map, map); |
| if (i == map_count - 1) { |
| __ DeoptimizeIfNot(DeoptimizeReason::kWrongMap, p.feedback(), check, |
| frame_state, IsSafetyCheck::kCriticalSafetyCheck); |
| } else { |
| auto next_map = __ MakeLabel(); |
| __ BranchWithCriticalSafetyCheck(check, &done, &next_map); |
| __ Bind(&next_map); |
| } |
| } |
| |
| __ Goto(&done); |
| __ Bind(&done); |
| } else { |
| auto done = __ MakeLabel(); |
| |
| // Load the current map of the {value}. |
| Node* value_map = __ LoadField(AccessBuilder::ForMap(), value); |
| |
| for (size_t i = 0; i < map_count; ++i) { |
| Node* map = __ HeapConstant(maps[i]); |
| Node* check = __ TaggedEqual(value_map, map); |
| |
| if (i == map_count - 1) { |
| __ DeoptimizeIfNot(DeoptimizeReason::kWrongMap, p.feedback(), check, |
| frame_state, IsSafetyCheck::kCriticalSafetyCheck); |
| } else { |
| auto next_map = __ MakeLabel(); |
| __ BranchWithCriticalSafetyCheck(check, &done, &next_map); |
| __ Bind(&next_map); |
| } |
| } |
| __ Goto(&done); |
| __ Bind(&done); |
| } |
| } |
| |
| void EffectControlLinearizer::BuildCallDynamicMapChecksBuiltin( |
| Node* actual_value, Node* actual_handler, int feedback_slot_index, |
| GraphAssemblerLabel<0>* done, Node* frame_state) { |
| Node* slot_index = __ IntPtrConstant(feedback_slot_index); |
| Operator::Properties properties = Operator::kNoDeopt | Operator::kNoThrow; |
| auto builtin = Builtins::kDynamicMapChecks; |
| Node* result = CallBuiltin(builtin, properties, slot_index, actual_value, |
| actual_handler); |
| __ GotoIf(__ WordEqual(result, __ IntPtrConstant(static_cast<int>( |
| DynamicMapChecksStatus::kSuccess))), |
| done); |
| __ DeoptimizeIf(DeoptimizeKind::kBailout, DeoptimizeReason::kMissingMap, |
| FeedbackSource(), |
| __ WordEqual(result, __ IntPtrConstant(static_cast<int>( |
| DynamicMapChecksStatus::kBailout))), |
| frame_state, IsSafetyCheck::kCriticalSafetyCheck); |
| __ DeoptimizeIf(DeoptimizeReason::kWrongHandler, FeedbackSource(), |
| __ WordEqual(result, __ IntPtrConstant(static_cast<int>( |
| DynamicMapChecksStatus::kDeopt))), |
| frame_state, IsSafetyCheck::kCriticalSafetyCheck); |
| __ Unreachable(done); |
| } |
| |
| void EffectControlLinearizer::LowerDynamicCheckMaps(Node* node, |
| Node* frame_state) { |
| DynamicCheckMapsParameters const& p = |
| DynamicCheckMapsParametersOf(node->op()); |
| Node* actual_value = node->InputAt(0); |
| |
| FeedbackSource const& feedback = p.feedback(); |
| Node* actual_value_map = __ LoadField(AccessBuilder::ForMap(), actual_value); |
| Node* actual_handler = |
| p.handler()->IsSmi() |
| ? __ SmiConstant(Smi::ToInt(*p.handler())) |
| : __ HeapConstant(Handle<HeapObject>::cast(p.handler())); |
| |
| auto done = __ MakeLabel(); |
| auto call_builtin = __ MakeDeferredLabel(); |
| |
| ZoneHandleSet<Map> maps = p.maps(); |
| size_t const map_count = maps.size(); |
| for (size_t i = 0; i < map_count; ++i) { |
| Node* map = __ HeapConstant(maps[i]); |
| Node* check = __ TaggedEqual(actual_value_map, map); |
| if (i == map_count - 1) { |
| __ BranchWithCriticalSafetyCheck(check, &done, &call_builtin); |
| } else { |
| auto next_map = __ MakeLabel(); |
| __ BranchWithCriticalSafetyCheck(check, &done, &next_map); |
| __ Bind(&next_map); |
| } |
| } |
| |
| __ Bind(&call_builtin); |
| { |
| BuildCallDynamicMapChecksBuiltin(actual_value, actual_handler, |
| feedback.index(), &done, frame_state); |
| } |
| |
| __ Bind(&done); |
| } |
| |
| Node* EffectControlLinearizer::LowerCompareMaps(Node* node) { |
| ZoneHandleSet<Map> const& maps = CompareMapsParametersOf(node->op()); |
| size_t const map_count = maps.size(); |
| Node* value = node->InputAt(0); |
| |
| auto done = __ MakeLabel(MachineRepresentation::kBit); |
| |
| // Load the current map of the {value}. |
| Node* value_map = __ LoadField(AccessBuilder::ForMap(), value); |
| |
| for (size_t i = 0; i < map_count; ++i) { |
| Node* map = __ HeapConstant(maps[i]); |
| Node* check = __ TaggedEqual(value_map, map); |
| |
| auto next_map = __ MakeLabel(); |
| auto passed = __ MakeLabel(); |
| __ BranchWithCriticalSafetyCheck(check, &passed, &next_map); |
| |
| __ Bind(&passed); |
| __ Goto(&done, __ Int32Constant(1)); |
| |
| __ Bind(&next_map); |
| } |
| __ Goto(&done, __ Int32Constant(0)); |
| |
| __ Bind(&done); |
| return done.PhiAt(0); |
| } |
| |
| Node* EffectControlLinearizer::LowerCheckNumber(Node* node, Node* frame_state) { |
| Node* value = node->InputAt(0); |
| const CheckParameters& params = CheckParametersOf(node->op()); |
| |
| auto if_not_smi = __ MakeDeferredLabel(); |
| auto done = __ MakeLabel(); |
| |
| Node* check0 = ObjectIsSmi(value); |
| __ GotoIfNot(check0, &if_not_smi); |
| __ Goto(&done); |
| |
| __ Bind(&if_not_smi); |
| Node* value_map = __ LoadField(AccessBuilder::ForMap(), value); |
| Node* check1 = __ TaggedEqual(value_map, __ HeapNumberMapConstant()); |
| __ DeoptimizeIfNot(DeoptimizeReason::kNotAHeapNumber, params.feedback(), |
| check1, frame_state); |
| __ Goto(&done); |
| |
| __ Bind(&done); |
| return value; |
| } |
| |
| Node* EffectControlLinearizer::LowerCheckReceiver(Node* node, |
| Node* frame_state) { |
| Node* value = node->InputAt(0); |
| |
| Node* value_map = __ LoadField(AccessBuilder::ForMap(), value); |
| Node* value_instance_type = |
| __ LoadField(AccessBuilder::ForMapInstanceType(), value_map); |
| |
| STATIC_ASSERT(LAST_TYPE == LAST_JS_RECEIVER_TYPE); |
| Node* check = __ Uint32LessThanOrEqual( |
| __ Uint32Constant(FIRST_JS_RECEIVER_TYPE), value_instance_type); |
| __ DeoptimizeIfNot(DeoptimizeReason::kNotAJavaScriptObject, FeedbackSource(), |
| check, frame_state); |
| return value; |
| } |
| |
| Node* EffectControlLinearizer::LowerCheckReceiverOrNullOrUndefined( |
| Node* node, Node* frame_state) { |
| Node* value = node->InputAt(0); |
| |
| Node* value_map = __ LoadField(AccessBuilder::ForMap(), value); |
| Node* value_instance_type = |
| __ LoadField(AccessBuilder::ForMapInstanceType(), value_map); |
| |
| // Rule out all primitives except oddballs (true, false, undefined, null). |
| STATIC_ASSERT(LAST_PRIMITIVE_HEAP_OBJECT_TYPE == ODDBALL_TYPE); |
| STATIC_ASSERT(LAST_TYPE == LAST_JS_RECEIVER_TYPE); |
| Node* check0 = __ Uint32LessThanOrEqual(__ Uint32Constant(ODDBALL_TYPE), |
| value_instance_type); |
| __ DeoptimizeIfNot(DeoptimizeReason::kNotAJavaScriptObjectOrNullOrUndefined, |
| FeedbackSource(), check0, frame_state); |
| |
| // Rule out booleans. |
| Node* check1 = __ TaggedEqual(value_map, __ BooleanMapConstant()); |
| __ DeoptimizeIf(DeoptimizeReason::kNotAJavaScriptObjectOrNullOrUndefined, |
| FeedbackSource(), check1, frame_state); |
| return value; |
| } |
| |
| Node* EffectControlLinearizer::LowerCheckSymbol(Node* node, Node* frame_state) { |
| Node* value = node->InputAt(0); |
| |
| Node* value_map = __ LoadField(AccessBuilder::ForMap(), value); |
| |
| Node* check = |
| __ TaggedEqual(value_map, __ HeapConstant(factory()->symbol_map())); |
| __ DeoptimizeIfNot(DeoptimizeReason::kNotASymbol, FeedbackSource(), check, |
| frame_state); |
| return value; |
| } |
| |
| Node* EffectControlLinearizer::LowerCheckString(Node* node, Node* frame_state) { |
| Node* value = node->InputAt(0); |
| const CheckParameters& params = CheckParametersOf(node->op()); |
| |
| Node* value_map = __ LoadField(AccessBuilder::ForMap(), value); |
| Node* value_instance_type = |
| __ LoadField(AccessBuilder::ForMapInstanceType(), value_map); |
| |
| Node* check = __ Uint32LessThan(value_instance_type, |
| __ Uint32Constant(FIRST_NONSTRING_TYPE)); |
| __ DeoptimizeIfNot(DeoptimizeReason::kNotAString, params.feedback(), check, |
| frame_state); |
| return value; |
| } |
| |
| Node* EffectControlLinearizer::LowerCheckInternalizedString(Node* node, |
| Node* frame_state) { |
| Node* value = node->InputAt(0); |
| |
| Node* value_map = __ LoadField(AccessBuilder::ForMap(), value); |
| Node* value_instance_type = |
| __ LoadField(AccessBuilder::ForMapInstanceType(), value_map); |
| |
| Node* check = __ Word32Equal( |
| __ Word32And(value_instance_type, |
| __ Int32Constant(kIsNotStringMask | kIsNotInternalizedMask)), |
| __ Int32Constant(kInternalizedTag)); |
| __ DeoptimizeIfNot(DeoptimizeReason::kWrongInstanceType, FeedbackSource(), |
| check, frame_state); |
| |
| return value; |
| } |
| |
| void EffectControlLinearizer::LowerCheckIf(Node* node, Node* frame_state) { |
| Node* value = node->InputAt(0); |
| const CheckIfParameters& p = CheckIfParametersOf(node->op()); |
| __ DeoptimizeIfNot(p.reason(), p.feedback(), value, frame_state); |
| } |
| |
| Node* EffectControlLinearizer::LowerStringConcat(Node* node) { |
| Node* lhs = node->InputAt(1); |
| Node* rhs = node->InputAt(2); |
| |
| Callable const callable = |
| CodeFactory::StringAdd(isolate(), STRING_ADD_CHECK_NONE); |
| auto call_descriptor = Linkage::GetStubCallDescriptor( |
| graph()->zone(), callable.descriptor(), |
| callable.descriptor().GetStackParameterCount(), CallDescriptor::kNoFlags, |
| Operator::kNoDeopt | Operator::kNoWrite | Operator::kNoThrow); |
| |
| Node* value = __ Call(call_descriptor, __ HeapConstant(callable.code()), lhs, |
| rhs, __ NoContextConstant()); |
| |
| return value; |
| } |
| |
| Node* EffectControlLinearizer::LowerCheckedInt32Add(Node* node, |
| Node* frame_state) { |
| Node* lhs = node->InputAt(0); |
| Node* rhs = node->InputAt(1); |
| |
| Node* value = __ Int32AddWithOverflow(lhs, rhs); |
| Node* check = __ Projection(1, value); |
| __ DeoptimizeIf(DeoptimizeReason::kOverflow, FeedbackSource(), check, |
| frame_state); |
| return __ Projection(0, value); |
| } |
| |
| Node* EffectControlLinearizer::LowerCheckedInt32Sub(Node* node, |
| Node* frame_state) { |
| Node* lhs = node->InputAt(0); |
| Node* rhs = node->InputAt(1); |
| |
| Node* value = __ Int32SubWithOverflow(lhs, rhs); |
| Node* check = __ Projection(1, value); |
| __ DeoptimizeIf(DeoptimizeReason::kOverflow, FeedbackSource(), check, |
| frame_state); |
| return __ Projection(0, value); |
| } |
| |
| Node* EffectControlLinearizer::LowerCheckedInt32Div(Node* node, |
| Node* frame_state) { |
| Node* lhs = node->InputAt(0); |
| Node* rhs = node->InputAt(1); |
| Node* zero = __ Int32Constant(0); |
| |
| // Check if the {rhs} is a known power of two. |
| Int32Matcher m(rhs); |
| if (m.IsPowerOf2()) { |
| // Since we know that {rhs} is a power of two, we can perform a fast |
| // check to see if the relevant least significant bits of the {lhs} |
| // are all zero, and if so we know that we can perform a division |
| // safely (and fast by doing an arithmetic - aka sign preserving - |
| // right shift on {lhs}). |
| int32_t divisor = m.ResolvedValue(); |
| Node* mask = __ Int32Constant(divisor - 1); |
| Node* shift = __ Int32Constant(base::bits::WhichPowerOfTwo(divisor)); |
| Node* check = __ Word32Equal(__ Word32And(lhs, mask), zero); |
| __ DeoptimizeIfNot(DeoptimizeReason::kLostPrecision, FeedbackSource(), |
| check, frame_state); |
| return __ Word32Sar(lhs, shift); |
| } else { |
| auto if_rhs_positive = __ MakeLabel(); |
| auto if_rhs_negative = __ MakeDeferredLabel(); |
| auto done = __ MakeLabel(MachineRepresentation::kWord32); |
| |
| // Check if {rhs} is positive (and not zero). |
| Node* check_rhs_positive = __ Int32LessThan(zero, rhs); |
| __ Branch(check_rhs_positive, &if_rhs_positive, &if_rhs_negative); |
| |
| __ Bind(&if_rhs_positive); |
| { |
| // Fast case, no additional checking required. |
| __ Goto(&done, __ Int32Div(lhs, rhs)); |
| } |
| |
| __ Bind(&if_rhs_negative); |
| { |
| auto if_lhs_minint = __ MakeDeferredLabel(); |
| auto if_lhs_notminint = __ MakeLabel(); |
| |
| // Check if {rhs} is zero. |
| Node* check_rhs_zero = __ Word32Equal(rhs, zero); |
| __ DeoptimizeIf(DeoptimizeReason::kDivisionByZero, FeedbackSource(), |
| check_rhs_zero, frame_state); |
| |
| // Check if {lhs} is zero, as that would produce minus zero. |
| Node* check_lhs_zero = __ Word32Equal(lhs, zero); |
| __ DeoptimizeIf(DeoptimizeReason::kMinusZero, FeedbackSource(), |
| check_lhs_zero, frame_state); |
| |
| // Check if {lhs} is kMinInt and {rhs} is -1, in which case we'd have |
| // to return -kMinInt, which is not representable as Word32. |
| Node* check_lhs_minint = __ Word32Equal(lhs, __ Int32Constant(kMinInt)); |
| __ Branch(check_lhs_minint, &if_lhs_minint, &if_lhs_notminint); |
| |
| __ Bind(&if_lhs_minint); |
| { |
| // Check that {rhs} is not -1, otherwise result would be -kMinInt. |
| Node* check_rhs_minusone = __ Word32Equal(rhs, __ Int32Constant(-1)); |
| __ DeoptimizeIf(DeoptimizeReason::kOverflow, FeedbackSource(), |
| check_rhs_minusone, frame_state); |
| |
| // Perform the actual integer division. |
| __ Goto(&done, __ Int32Div(lhs, rhs)); |
| } |
| |
| __ Bind(&if_lhs_notminint); |
| { |
| // Perform the actual integer division. |
| __ Goto(&done, __ Int32Div(lhs, rhs)); |
| } |
| } |
| |
| __ Bind(&done); |
| Node* value = done.PhiAt(0); |
| |
| // Check if the remainder is non-zero. |
| Node* check = __ Word32Equal(lhs, __ Int32Mul(value, rhs)); |
| __ DeoptimizeIfNot(DeoptimizeReason::kLostPrecision, FeedbackSource(), |
| check, frame_state); |
| |
| return value; |
| } |
| } |
| |
| template <size_t VarCount, size_t VarCount2> |
| void EffectControlLinearizer::SmiTagOrOverflow( |
| Node* value, GraphAssemblerLabel<VarCount>* if_overflow, |
| GraphAssemblerLabel<VarCount2>* done) { |
| DCHECK(SmiValuesAre31Bits()); |
| // Check for overflow at the same time that we are smi tagging. |
| // Since smi tagging shifts left by one, it's the same as adding value twice. |
| Node* add = __ Int32AddWithOverflow(value, value); |
| Node* ovf = __ Projection(1, add); |
| __ GotoIf(ovf, if_overflow); |
| Node* value_smi = __ Projection(0, add); |
| value_smi = ChangeTaggedInt32ToSmi(value_smi); |
| __ Goto(done, value_smi); |
| } |
| |
| Node* EffectControlLinearizer::SmiTagOrDeopt(Node* value, |
| const CheckParameters& params, |
| Node* frame_state) { |
| DCHECK(SmiValuesAre31Bits()); |
| // Check for the lost precision at the same time that we are smi tagging. |
| // Since smi tagging shifts left by one, it's the same as adding value twice. |
| Node* add = __ Int32AddWithOverflow(value, value); |
| Node* check = __ Projection(1, add); |
| __ DeoptimizeIf(DeoptimizeReason::kLostPrecision, params.feedback(), check, |
| frame_state); |
| Node* result = __ Projection(0, add); |
| return ChangeTaggedInt32ToSmi(result); |
| } |
| |
| Node* EffectControlLinearizer::BuildUint32Mod(Node* lhs, Node* rhs) { |
| auto if_rhs_power_of_two = __ MakeLabel(); |
| auto done = __ MakeLabel(MachineRepresentation::kWord32); |
| |
| // Compute the mask for the {rhs}. |
| Node* one = __ Int32Constant(1); |
| Node* msk = __ Int32Sub(rhs, one); |
| |
| // Check if the {rhs} is a power of two. |
| __ GotoIf(__ Word32Equal(__ Word32And(rhs, msk), __ Int32Constant(0)), |
| &if_rhs_power_of_two); |
| { |
| // The {rhs} is not a power of two, do a generic Uint32Mod. |
| __ Goto(&done, __ Uint32Mod(lhs, rhs)); |
| } |
| |
| __ Bind(&if_rhs_power_of_two); |
| { |
| // The {rhs} is a power of two, just do a fast bit masking. |
| __ Goto(&done, __ Word32And(lhs, msk)); |
| } |
| |
| __ Bind(&done); |
| return done.PhiAt(0); |
| } |
| |
| Node* EffectControlLinearizer::LowerCheckedInt32Mod(Node* node, |
| Node* frame_state) { |
| // General case for signed integer modulus, with optimization for (unknown) |
| // power of 2 right hand side. |
| // |
| // if rhs <= 0 then |
| // rhs = -rhs |
| // deopt if rhs == 0 |
| // let msk = rhs - 1 in |
| // if lhs < 0 then |
| // let lhs_abs = -lsh in |
| // let res = if rhs & msk == 0 then |
| // lhs_abs & msk |
| // else |
| // lhs_abs % rhs in |
| // if lhs < 0 then |
| // deopt if res == 0 |
| // -res |
| // else |
| // res |
| // else |
| // if rhs & msk == 0 then |
| // lhs & msk |
| // else |
| // lhs % rhs |
| // |
| Node* lhs = node->InputAt(0); |
| Node* rhs = node->InputAt(1); |
| |
| auto if_rhs_not_positive = __ MakeDeferredLabel(); |
| auto if_lhs_negative = __ MakeDeferredLabel(); |
| auto if_rhs_power_of_two = __ MakeLabel(); |
| auto rhs_checked = __ MakeLabel(MachineRepresentation::kWord32); |
| auto done = __ MakeLabel(MachineRepresentation::kWord32); |
| |
| Node* zero = __ Int32Constant(0); |
| |
| // Check if {rhs} is not strictly positive. |
| Node* check0 = __ Int32LessThanOrEqual(rhs, zero); |
| __ GotoIf(check0, &if_rhs_not_positive); |
| __ Goto(&rhs_checked, rhs); |
| |
| __ Bind(&if_rhs_not_positive); |
| { |
| // Negate {rhs}, might still produce a negative result in case of |
| // -2^31, but that is handled safely below. |
| Node* vtrue0 = __ Int32Sub(zero, rhs); |
| |
| // Ensure that {rhs} is not zero, otherwise we'd have to return NaN. |
| __ DeoptimizeIf(DeoptimizeReason::kDivisionByZero, FeedbackSource(), |
| __ Word32Equal(vtrue0, zero), frame_state); |
| __ Goto(&rhs_checked, vtrue0); |
| } |
| |
| __ Bind(&rhs_checked); |
| rhs = rhs_checked.PhiAt(0); |
| |
| __ GotoIf(__ Int32LessThan(lhs, zero), &if_lhs_negative); |
| { |
| // The {lhs} is a non-negative integer. |
| __ Goto(&done, BuildUint32Mod(lhs, rhs)); |
| } |
| |
| __ Bind(&if_lhs_negative); |
| { |
| // The {lhs} is a negative integer. This is very unlikely and |
| // we intentionally don't use the BuildUint32Mod() here, which |
| // would try to figure out whether {rhs} is a power of two, |
| // since this is intended to be a slow-path. |
| Node* res = __ Uint32Mod(__ Int32Sub(zero, lhs), rhs); |
| |
| // Check if we would have to return -0. |
| __ DeoptimizeIf(DeoptimizeReason::kMinusZero, FeedbackSource(), |
| __ Word32Equal(res, zero), frame_state); |
| __ Goto(&done, __ Int32Sub(zero, res)); |
| } |
| |
| __ Bind(&done); |
| return done.PhiAt(0); |
| } |
| |
| Node* EffectControlLinearizer::LowerCheckedUint32Div(Node* node, |
| Node* frame_state) { |
| Node* lhs = node->InputAt(0); |
| Node* rhs = node->InputAt(1); |
| Node* zero = __ Int32Constant(0); |
| |
| // Check if the {rhs} is a known power of two. |
| Uint32Matcher m(rhs); |
| if (m.IsPowerOf2()) { |
| // Since we know that {rhs} is a power of two, we can perform a fast |
| // check to see if the relevant least significant bits of the {lhs} |
| // are all zero, and if so we know that we can perform a division |
| // safely (and fast by doing a logical - aka zero extending - right |
| // shift on {lhs}). |
| uint32_t divisor = m.ResolvedValue(); |
| Node* mask = __ Uint32Constant(divisor - 1); |
| Node* shift = __ Uint32Constant(base::bits::WhichPowerOfTwo(divisor)); |
| Node* check = __ Word32Equal(__ Word32And(lhs, mask), zero); |
| __ DeoptimizeIfNot(DeoptimizeReason::kLostPrecision, FeedbackSource(), |
| check, frame_state); |
| return __ Word32Shr(lhs, shift); |
| } else { |
| // Ensure that {rhs} is not zero, otherwise we'd have to return NaN. |
| Node* check = __ Word32Equal(rhs, zero); |
| __ DeoptimizeIf(DeoptimizeReason::kDivisionByZero, FeedbackSource(), check, |
| frame_state); |
| |
| // Perform the actual unsigned integer division. |
| Node* value = __ Uint32Div(lhs, rhs); |
| |
| // Check if the remainder is non-zero. |
| check = __ Word32Equal(lhs, __ Int32Mul(rhs, value)); |
| __ DeoptimizeIfNot(DeoptimizeReason::kLostPrecision, FeedbackSource(), |
| check, frame_state); |
| return value; |
| } |
| } |
| |
| Node* EffectControlLinearizer::LowerCheckedUint32Mod(Node* node, |
| Node* frame_state) { |
| Node* lhs = node->InputAt(0); |
| Node* rhs = node->InputAt(1); |
| |
| Node* zero = __ Int32Constant(0); |
| |
| // Ensure that {rhs} is not zero, otherwise we'd have to return NaN. |
| Node* check = __ Word32Equal(rhs, zero); |
| __ DeoptimizeIf(DeoptimizeReason::kDivisionByZero, FeedbackSource(), check, |
| frame_state); |
| |
| // Perform the actual unsigned integer modulus. |
| return BuildUint32Mod(lhs, rhs); |
| } |
| |
| Node* EffectControlLinearizer::LowerCheckedInt32Mul(Node* node, |
| Node* frame_state) { |
| CheckForMinusZeroMode mode = CheckMinusZeroModeOf(node->op()); |
| Node* lhs = node->InputAt(0); |
| Node* rhs = node->InputAt(1); |
| |
| Node* projection = __ Int32MulWithOverflow(lhs, rhs); |
| Node* check = __ Projection(1, projection); |
| __ DeoptimizeIf(DeoptimizeReason::kOverflow, FeedbackSource(), check, |
| frame_state); |
| |
| Node* value = __ Projection(0, projection); |
| |
| if (mode == CheckForMinusZeroMode::kCheckForMinusZero) { |
| auto if_zero = __ MakeDeferredLabel(); |
| auto check_done = __ MakeLabel(); |
| Node* zero = __ Int32Constant(0); |
| Node* check_zero = __ Word32Equal(value, zero); |
| __ GotoIf(check_zero, &if_zero); |
| __ Goto(&check_done); |
| |
| __ Bind(&if_zero); |
| // We may need to return negative zero. |
| Node* check_or = __ Int32LessThan(__ Word32Or(lhs, rhs), zero); |
| __ DeoptimizeIf(DeoptimizeReason::kMinusZero, FeedbackSource(), check_or, |
| frame_state); |
| __ Goto(&check_done); |
| |
| __ Bind(&check_done); |
| } |
| |
| return value; |
| } |
| |
| Node* EffectControlLinearizer::LowerCheckedInt32ToTaggedSigned( |
| Node* node, Node* frame_state) { |
| DCHECK(SmiValuesAre31Bits()); |
| Node* value = node->InputAt(0); |
| const CheckParameters& params = CheckParametersOf(node->op()); |
| return SmiTagOrDeopt(value, params, frame_state); |
| } |
| |
| Node* EffectControlLinearizer::LowerCheckedInt64ToInt32(Node* node, |
| Node* frame_state) { |
| Node* value = node->InputAt(0); |
| const CheckParameters& params = CheckParametersOf(node->op()); |
| |
| Node* value32 = __ TruncateInt64ToInt32(value); |
| Node* check = __ Word64Equal(__ ChangeInt32ToInt64(value32), value); |
| __ DeoptimizeIfNot(DeoptimizeReason::kLostPrecision, params.feedback(), check, |
| frame_state); |
| return value32; |
| } |
| |
| Node* EffectControlLinearizer::LowerCheckedInt64ToTaggedSigned( |
| Node* node, Node* frame_state) { |
| Node* value = node->InputAt(0); |
| const CheckParameters& params = CheckParametersOf(node->op()); |
| |
| Node* value32 = __ TruncateInt64ToInt32(value); |
| Node* check = __ Word64Equal(__ ChangeInt32ToInt64(value32), value); |
| __ DeoptimizeIfNot(DeoptimizeReason::kLostPrecision, params.feedback(), check, |
| frame_state); |
| |
| if (SmiValuesAre32Bits()) { |
| return ChangeInt64ToSmi(value); |
| } else { |
| return SmiTagOrDeopt(value32, params, frame_state); |
| } |
| } |
| |
| Node* EffectControlLinearizer::LowerCheckedUint32Bounds(Node* node, |
| Node* frame_state) { |
| Node* index = node->InputAt(0); |
| Node* limit = node->InputAt(1); |
| const CheckBoundsParameters& params = CheckBoundsParametersOf(node->op()); |
| |
| Node* check = __ Uint32LessThan(index, limit); |
| if (!(params.flags() & CheckBoundsFlag::kAbortOnOutOfBounds)) { |
| __ DeoptimizeIfNot(DeoptimizeReason::kOutOfBounds, |
| params.check_parameters().feedback(), check, frame_state, |
| IsSafetyCheck::kCriticalSafetyCheck); |
| } else { |
| auto if_abort = __ MakeDeferredLabel(); |
| auto done = __ MakeLabel(); |
| |
| __ Branch(check, &done, &if_abort); |
| |
| __ Bind(&if_abort); |
| __ Unreachable(&done); |
| |
| __ Bind(&done); |
| } |
| |
| return index; |
| } |
| |
| Node* EffectControlLinearizer::LowerCheckedUint32ToInt32(Node* node, |
| Node* frame_state) { |
| Node* value = node->InputAt(0); |
| const CheckParameters& params = CheckParametersOf(node->op()); |
| Node* unsafe = __ Int32LessThan(value, __ Int32Constant(0)); |
| __ DeoptimizeIf(DeoptimizeReason::kLostPrecision, params.feedback(), unsafe, |
| frame_state); |
| return value; |
| } |
| |
| Node* EffectControlLinearizer::LowerCheckedUint32ToTaggedSigned( |
| Node* node, Node* frame_state) { |
| Node* value = node->InputAt(0); |
| const CheckParameters& params = CheckParametersOf(node->op()); |
| Node* check = __ Uint32LessThanOrEqual(value, SmiMaxValueConstant()); |
| __ DeoptimizeIfNot(DeoptimizeReason::kLostPrecision, params.feedback(), check, |
| frame_state); |
| return ChangeUint32ToSmi(value); |
| } |
| |
| Node* EffectControlLinearizer::LowerCheckedUint64Bounds(Node* node, |
| Node* frame_state) { |
| Node* const index = node->InputAt(0); |
| Node* const limit = node->InputAt(1); |
| const CheckBoundsParameters& params = CheckBoundsParametersOf(node->op()); |
| |
| Node* check = __ Uint64LessThan(index, limit); |
| if (!(params.flags() & CheckBoundsFlag::kAbortOnOutOfBounds)) { |
| __ DeoptimizeIfNot(DeoptimizeReason::kOutOfBounds, |
| params.check_parameters().feedback(), check, frame_state, |
| IsSafetyCheck::kCriticalSafetyCheck); |
| } else { |
| auto if_abort = __ MakeDeferredLabel(); |
| auto done = __ MakeLabel(); |
| |
| __ Branch(check, &done, &if_abort); |
| |
| __ Bind(&if_abort); |
| __ Unreachable(&done); |
| |
| __ Bind(&done); |
| } |
| return index; |
| } |
| |
| Node* EffectControlLinearizer::LowerCheckedUint64ToInt32(Node* node, |
| Node* frame_state) { |
| Node* value = node->InputAt(0); |
| const CheckParameters& params = CheckParametersOf(node->op()); |
| |
| Node* check = __ Uint64LessThanOrEqual(value, __ Int64Constant(kMaxInt)); |
| __ DeoptimizeIfNot(DeoptimizeReason::kLostPrecision, params.feedback(), check, |
| frame_state); |
| return __ TruncateInt64ToInt32(value); |
| } |
| |
| Node* EffectControlLinearizer::LowerCheckedUint64ToTaggedSigned( |
| Node* node, Node* frame_state) { |
| Node* value = node->InputAt(0); |
| const CheckParameters& params = CheckParametersOf(node->op()); |
| |
| Node* check = |
| __ Uint64LessThanOrEqual(value, __ Int64Constant(Smi::kMaxValue)); |
| __ DeoptimizeIfNot(DeoptimizeReason::kLostPrecision, params.feedback(), check, |
| frame_state); |
| return ChangeInt64ToSmi(value); |
| } |
| |
| Node* EffectControlLinearizer::BuildCheckedFloat64ToInt32( |
| CheckForMinusZeroMode mode, const FeedbackSource& feedback, Node* value, |
| Node* frame_state) { |
| Node* value32 = __ RoundFloat64ToInt32(value); |
| Node* check_same = __ Float64Equal(value, __ ChangeInt32ToFloat64(value32)); |
| __ DeoptimizeIfNot(DeoptimizeReason::kLostPrecisionOrNaN, feedback, |
| check_same, frame_state); |
| |
| if (mode == CheckForMinusZeroMode::kCheckForMinusZero) { |
| // Check if {value} is -0. |
| auto if_zero = __ MakeDeferredLabel(); |
| auto check_done = __ MakeLabel(); |
| |
| Node* check_zero = __ Word32Equal(value32, __ Int32Constant(0)); |
| __ GotoIf(check_zero, &if_zero); |
| __ Goto(&check_done); |
| |
| __ Bind(&if_zero); |
| // In case of 0, we need to check the high bits for the IEEE -0 pattern. |
| Node* check_negative = __ Int32LessThan(__ Float64ExtractHighWord32(value), |
| __ Int32Constant(0)); |
| __ DeoptimizeIf(DeoptimizeReason::kMinusZero, feedback, check_negative, |
| frame_state); |
| __ Goto(&check_done); |
| |
| __ Bind(&check_done); |
| } |
| return value32; |
| } |
| |
| Node* EffectControlLinearizer::BuildCheckedFloat64ToIndex( |
| const FeedbackSource& feedback, Node* value, Node* frame_state) { |
| if (machine()->Is64()) { |
| Node* value64 = __ TruncateFloat64ToInt64(value); |
| Node* check_same = __ Float64Equal(value, __ ChangeInt64ToFloat64(value64)); |
| __ DeoptimizeIfNot(DeoptimizeReason::kLostPrecisionOrNaN, feedback, |
| check_same, frame_state); |
| Node* check_max = |
| __ IntLessThan(value64, __ Int64Constant(kMaxSafeInteger)); |
| __ DeoptimizeIfNot(DeoptimizeReason::kNotAnArrayIndex, feedback, check_max, |
| frame_state); |
| Node* check_min = |
| __ IntLessThan(__ Int64Constant(-kMaxSafeInteger), value64); |
| __ DeoptimizeIfNot(DeoptimizeReason::kNotAnArrayIndex, feedback, check_min, |
| frame_state); |
| return value64; |
| } else { |
| Node* value32 = __ RoundFloat64ToInt32(value); |
| Node* check_same = __ Float64Equal(value, __ ChangeInt32ToFloat64(value32)); |
| __ DeoptimizeIfNot(DeoptimizeReason::kLostPrecisionOrNaN, feedback, |
| check_same, frame_state); |
| return value32; |
| } |
| } |
| |
| Node* EffectControlLinearizer::LowerCheckedFloat64ToInt32(Node* node, |
| Node* frame_state) { |
| const CheckMinusZeroParameters& params = |
| CheckMinusZeroParametersOf(node->op()); |
| Node* value = node->InputAt(0); |
| return BuildCheckedFloat64ToInt32(params.mode(), params.feedback(), value, |
| frame_state); |
| } |
| |
| Node* EffectControlLinearizer::BuildCheckedFloat64ToInt64( |
| CheckForMinusZeroMode mode, const FeedbackSource& feedback, Node* value, |
| Node* frame_state) { |
| Node* value64 = __ TruncateFloat64ToInt64(value); |
| Node* check_same = __ Float64Equal(value, __ ChangeInt64ToFloat64(value64)); |
| __ DeoptimizeIfNot(DeoptimizeReason::kLostPrecisionOrNaN, feedback, |
| check_same, frame_state); |
| |
| if (mode == CheckForMinusZeroMode::kCheckForMinusZero) { |
| // Check if {value} is -0. |
| auto if_zero = __ MakeDeferredLabel(); |
| auto check_done = __ MakeLabel(); |
| |
| Node* check_zero = __ Word64Equal(value64, __ Int64Constant(0)); |
| __ GotoIf(check_zero, &if_zero); |
| __ Goto(&check_done); |
| |
| __ Bind(&if_zero); |
| // In case of 0, we need to check the high bits for the IEEE -0 pattern. |
| Node* check_negative = __ Int32LessThan(__ Float64ExtractHighWord32(value), |
| __ Int32Constant(0)); |
| __ DeoptimizeIf(DeoptimizeReason::kMinusZero, feedback, check_negative, |
| frame_state); |
| __ Goto(&check_done); |
| |
| __ Bind(&check_done); |
| } |
| return value64; |
| } |
| |
| Node* EffectControlLinearizer::LowerCheckedFloat64ToInt64(Node* node, |
| Node* frame_state) { |
| const CheckMinusZeroParameters& params = |
| CheckMinusZeroParametersOf(node->op()); |
| Node* value = node->InputAt(0); |
| return BuildCheckedFloat64ToInt64(params.mode(), params.feedback(), value, |
| frame_state); |
| } |
| |
| Node* EffectControlLinearizer::LowerCheckedTaggedSignedToInt32( |
| Node* node, Node* frame_state) { |
| Node* value = node->InputAt(0); |
| const CheckParameters& params = CheckParametersOf(node->op()); |
| Node* check = ObjectIsSmi(value); |
| __ DeoptimizeIfNot(DeoptimizeReason::kNotASmi, params.feedback(), check, |
| frame_state); |
| return ChangeSmiToInt32(value); |
| } |
| |
| Node* EffectControlLinearizer::LowerCheckedTaggedToArrayIndex( |
| Node* node, Node* frame_state) { |
| CheckParameters con
|