node-properties.cc 21.4 KB
Newer Older
1 2 3 4
// 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.

5
#include "src/compiler/node-properties.h"
6
#include "src/compiler/common-operator.h"
7
#include "src/compiler/graph.h"
8
#include "src/compiler/js-operator.h"
9
#include "src/compiler/linkage.h"
10
#include "src/compiler/node-matchers.h"
11
#include "src/compiler/operator-properties.h"
12
#include "src/compiler/simplified-operator.h"
13
#include "src/compiler/verifier.h"
14
#include "src/handles-inl.h"
15
#include "src/objects-inl.h"
16
#include "src/zone/zone-handle-set.h"
17

18 19 20 21
namespace v8 {
namespace internal {
namespace compiler {

22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
// static
int NodeProperties::PastValueIndex(Node* node) {
  return FirstValueIndex(node) + node->op()->ValueInputCount();
}


// static
int NodeProperties::PastContextIndex(Node* node) {
  return FirstContextIndex(node) +
         OperatorProperties::GetContextInputCount(node->op());
}


// static
int NodeProperties::PastFrameStateIndex(Node* node) {
  return FirstFrameStateIndex(node) +
         OperatorProperties::GetFrameStateInputCount(node->op());
}


// static
int NodeProperties::PastEffectIndex(Node* node) {
  return FirstEffectIndex(node) + node->op()->EffectInputCount();
}


// static
int NodeProperties::PastControlIndex(Node* node) {
  return FirstControlIndex(node) + node->op()->ControlInputCount();
}


// static
Node* NodeProperties::GetValueInput(Node* node, int index) {
  DCHECK(0 <= index && index < node->op()->ValueInputCount());
  return node->InputAt(FirstValueIndex(node) + index);
}


// static
Node* NodeProperties::GetContextInput(Node* node) {
  DCHECK(OperatorProperties::HasContextInput(node->op()));
  return node->InputAt(FirstContextIndex(node));
}


// static
69 70 71
Node* NodeProperties::GetFrameStateInput(Node* node) {
  DCHECK_EQ(1, OperatorProperties::GetFrameStateInputCount(node->op()));
  return node->InputAt(FirstFrameStateIndex(node));
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
}


// static
Node* NodeProperties::GetEffectInput(Node* node, int index) {
  DCHECK(0 <= index && index < node->op()->EffectInputCount());
  return node->InputAt(FirstEffectIndex(node) + index);
}


// static
Node* NodeProperties::GetControlInput(Node* node, int index) {
  DCHECK(0 <= index && index < node->op()->ControlInputCount());
  return node->InputAt(FirstControlIndex(node) + index);
}


// static
bool NodeProperties::IsValueEdge(Edge edge) {
  Node* const node = edge.from();
  return IsInputRange(edge, FirstValueIndex(node),
                      node->op()->ValueInputCount());
}


// static
bool NodeProperties::IsContextEdge(Edge edge) {
  Node* const node = edge.from();
  return IsInputRange(edge, FirstContextIndex(node),
                      OperatorProperties::GetContextInputCount(node->op()));
}


// static
bool NodeProperties::IsFrameStateEdge(Edge edge) {
  Node* const node = edge.from();
  return IsInputRange(edge, FirstFrameStateIndex(node),
                      OperatorProperties::GetFrameStateInputCount(node->op()));
}


// static
bool NodeProperties::IsEffectEdge(Edge edge) {
  Node* const node = edge.from();
  return IsInputRange(edge, FirstEffectIndex(node),
                      node->op()->EffectInputCount());
}


// static
bool NodeProperties::IsControlEdge(Edge edge) {
  Node* const node = edge.from();
  return IsInputRange(edge, FirstControlIndex(node),
                      node->op()->ControlInputCount());
}


svenpanne's avatar
svenpanne committed
129
// static
130
bool NodeProperties::IsExceptionalCall(Node* node, Node** out_exception) {
131
  if (node->op()->HasProperty(Operator::kNoThrow)) return false;
132 133
  for (Edge const edge : node->use_edges()) {
    if (!NodeProperties::IsControlEdge(edge)) continue;
134 135 136 137
    if (edge.from()->opcode() == IrOpcode::kIfException) {
      if (out_exception != nullptr) *out_exception = edge.from();
      return true;
    }
svenpanne's avatar
svenpanne committed
138 139 140 141
  }
  return false;
}

142 143 144 145 146 147 148 149 150 151 152 153
// static
Node* NodeProperties::FindSuccessfulControlProjection(Node* node) {
  DCHECK_GT(node->op()->ControlOutputCount(), 0);
  if (node->op()->HasProperty(Operator::kNoThrow)) return node;
  for (Edge const edge : node->use_edges()) {
    if (!NodeProperties::IsControlEdge(edge)) continue;
    if (edge.from()->opcode() == IrOpcode::kIfSuccess) {
      return edge.from();
    }
  }
  return node;
}
svenpanne's avatar
svenpanne committed
154

155 156 157 158 159 160 161
// static
void NodeProperties::ReplaceValueInput(Node* node, Node* value, int index) {
  DCHECK(index < node->op()->ValueInputCount());
  node->ReplaceInput(FirstValueIndex(node) + index, value);
}


162 163 164 165 166 167 168 169 170 171 172
// static
void NodeProperties::ReplaceValueInputs(Node* node, Node* value) {
  int value_input_count = node->op()->ValueInputCount();
  DCHECK_LE(1, value_input_count);
  node->ReplaceInput(0, value);
  while (--value_input_count > 0) {
    node->RemoveInput(value_input_count);
  }
}


173 174 175 176 177 178 179
// static
void NodeProperties::ReplaceContextInput(Node* node, Node* context) {
  node->ReplaceInput(FirstContextIndex(node), context);
}


// static
180 181 182
void NodeProperties::ReplaceControlInput(Node* node, Node* control, int index) {
  DCHECK(index < node->op()->ControlInputCount());
  node->ReplaceInput(FirstControlIndex(node) + index, control);
183 184 185 186 187 188 189 190 191 192 193
}


// static
void NodeProperties::ReplaceEffectInput(Node* node, Node* effect, int index) {
  DCHECK(index < node->op()->EffectInputCount());
  return node->ReplaceInput(FirstEffectIndex(node) + index, effect);
}


// static
194 195 196
void NodeProperties::ReplaceFrameStateInput(Node* node, Node* frame_state) {
  DCHECK_EQ(1, OperatorProperties::GetFrameStateInputCount(node->op()));
  node->ReplaceInput(FirstFrameStateIndex(node), frame_state);
197 198 199 200 201 202 203 204 205
}


// static
void NodeProperties::RemoveNonValueInputs(Node* node) {
  node->TrimInputCount(node->op()->ValueInputCount());
}


206 207 208 209 210 211 212 213 214
// static
void NodeProperties::RemoveValueInputs(Node* node) {
  int value_input_count = node->op()->ValueInputCount();
  while (--value_input_count >= 0) {
    node->RemoveInput(value_input_count);
  }
}


215 216 217
void NodeProperties::MergeControlToEnd(Graph* graph,
                                       CommonOperatorBuilder* common,
                                       Node* node) {
218 219
  graph->end()->AppendInput(graph->zone(), node);
  graph->end()->set_op(common->End(graph->end()->InputCount()));
220 221 222
}


223
// static
224 225
void NodeProperties::ReplaceUses(Node* node, Node* value, Node* effect,
                                 Node* success, Node* exception) {
226
  // Requires distinguishing between value, effect and control edges.
227
  for (Edge edge : node->use_edges()) {
228
    if (IsControlEdge(edge)) {
229 230 231 232 233 234 235
      if (edge.from()->opcode() == IrOpcode::kIfSuccess) {
        DCHECK_NOT_NULL(success);
        edge.UpdateTo(success);
      } else if (edge.from()->opcode() == IrOpcode::kIfException) {
        DCHECK_NOT_NULL(exception);
        edge.UpdateTo(exception);
      } else {
236 237
        DCHECK_NOT_NULL(success);
        edge.UpdateTo(success);
238
      }
239
    } else if (IsEffectEdge(edge)) {
240 241 242
      DCHECK_NOT_NULL(effect);
      edge.UpdateTo(effect);
    } else {
243
      DCHECK_NOT_NULL(value);
244 245 246 247 248 249
      edge.UpdateTo(value);
    }
  }
}


250 251 252
// static
void NodeProperties::ChangeOp(Node* node, const Operator* new_op) {
  node->set_op(new_op);
253
  Verifier::VerifyNode(node);
254 255 256
}


257 258 259 260
// static
Node* NodeProperties::FindFrameStateBefore(Node* node) {
  Node* effect = NodeProperties::GetEffectInput(node);
  while (effect->opcode() != IrOpcode::kCheckpoint) {
261
    if (effect->opcode() == IrOpcode::kDead) return effect;
262 263 264
    DCHECK_EQ(1, effect->op()->EffectInputCount());
    effect = NodeProperties::GetEffectInput(effect);
  }
265
  Node* frame_state = GetFrameStateInput(effect);
266 267 268
  return frame_state;
}

269
// static
270 271 272 273 274 275 276 277 278 279
Node* NodeProperties::FindProjection(Node* node, size_t projection_index) {
  for (auto use : node->uses()) {
    if (use->opcode() == IrOpcode::kProjection &&
        ProjectionIndexOf(use->op()) == projection_index) {
      return use;
    }
  }
  return nullptr;
}

280

281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297
// static
void NodeProperties::CollectValueProjections(Node* node, Node** projections,
                                             size_t projection_count) {
#ifdef DEBUG
  for (size_t index = 0; index < projection_count; ++index) {
    DCHECK_NULL(projections[index]);
  }
#endif
  for (Edge const edge : node->use_edges()) {
    if (!IsValueEdge(edge)) continue;
    Node* use = edge.from();
    DCHECK_EQ(IrOpcode::kProjection, use->opcode());
    projections[ProjectionIndexOf(use->op())] = use;
  }
}


298 299 300 301
// static
void NodeProperties::CollectControlProjections(Node* node, Node** projections,
                                               size_t projection_count) {
#ifdef DEBUG
302
  DCHECK_LE(static_cast<int>(projection_count), node->UseCount());
303 304 305
  std::memset(projections, 0, sizeof(*projections) * projection_count);
#endif
  size_t if_value_index = 0;
306 307 308
  for (Edge const edge : node->use_edges()) {
    if (!IsControlEdge(edge)) continue;
    Node* use = edge.from();
309 310 311 312 313 314 315 316 317 318
    size_t index;
    switch (use->opcode()) {
      case IrOpcode::kIfTrue:
        DCHECK_EQ(IrOpcode::kBranch, node->opcode());
        index = 0;
        break;
      case IrOpcode::kIfFalse:
        DCHECK_EQ(IrOpcode::kBranch, node->opcode());
        index = 1;
        break;
319
      case IrOpcode::kIfSuccess:
320
        DCHECK(!node->op()->HasProperty(Operator::kNoThrow));
321 322 323
        index = 0;
        break;
      case IrOpcode::kIfException:
324
        DCHECK(!node->op()->HasProperty(Operator::kNoThrow));
325 326
        index = 1;
        break;
327 328 329 330 331 332 333 334
      case IrOpcode::kIfValue:
        DCHECK_EQ(IrOpcode::kSwitch, node->opcode());
        index = if_value_index++;
        break;
      case IrOpcode::kIfDefault:
        DCHECK_EQ(IrOpcode::kSwitch, node->opcode());
        index = projection_count - 1;
        break;
335 336
      default:
        continue;
337 338 339 340 341 342 343 344 345 346 347 348 349
    }
    DCHECK_LT(if_value_index, projection_count);
    DCHECK_LT(index, projection_count);
    DCHECK_NULL(projections[index]);
    projections[index] = use;
  }
#ifdef DEBUG
  for (size_t index = 0; index < projection_count; ++index) {
    DCHECK_NOT_NULL(projections[index]);
  }
#endif
}

350 351 352 353 354 355 356 357 358 359 360 361 362 363
// static
bool NodeProperties::IsSame(Node* a, Node* b) {
  for (;;) {
    if (a->opcode() == IrOpcode::kCheckHeapObject) {
      a = GetValueInput(a, 0);
      continue;
    }
    if (b->opcode() == IrOpcode::kCheckHeapObject) {
      b = GetValueInput(b, 0);
      continue;
    }
    return a == b;
  }
}
364

365
// static
366
NodeProperties::InferReceiverMapsResult NodeProperties::InferReceiverMaps(
367
    JSHeapBroker* broker, Node* receiver, Node* effect,
368
    ZoneHandleSet<Map>* maps_return) {
369 370
  HeapObjectMatcher m(receiver);
  if (m.HasValue()) {
371
    HeapObjectRef receiver = m.Ref(broker).AsHeapObject();
372 373 374 375 376 377 378
    // We don't use ICs for the Array.prototype and the Object.prototype
    // because the runtime has to be able to intercept them properly, so
    // we better make sure that TurboFan doesn't outsmart the system here
    // by storing to elements of either prototype directly.
    //
    // TODO(bmeurer): This can be removed once the Array.prototype and
    // Object.prototype have NO_ELEMENTS elements kind.
379 380 381
    if (!receiver.IsJSObject() ||
        !broker->IsArrayOrObjectPrototype(receiver.AsJSObject())) {
      if (receiver.map().is_stable()) {
382 383
        // The {receiver_map} is only reliable when we install a stability
        // code dependency.
384
        *maps_return = ZoneHandleSet<Map>(receiver.map().object());
385 386
        return kUnreliableReceiverMaps;
      }
387 388
    }
  }
389
  InferReceiverMapsResult result = kReliableReceiverMaps;
390 391
  while (true) {
    switch (effect->opcode()) {
392 393 394
      case IrOpcode::kMapGuard: {
        Node* const object = GetValueInput(effect, 0);
        if (IsSame(receiver, object)) {
395
          *maps_return = MapGuardMapsOf(effect->op()).maps();
396 397 398 399
          return result;
        }
        break;
      }
400 401 402 403
      case IrOpcode::kCheckMaps: {
        Node* const object = GetValueInput(effect, 0);
        if (IsSame(receiver, object)) {
          *maps_return = CheckMapsParametersOf(effect->op()).maps();
404
          return result;
405 406 407 408 409 410 411
        }
        break;
      }
      case IrOpcode::kJSCreate: {
        if (IsSame(receiver, effect)) {
          HeapObjectMatcher mtarget(GetValueInput(effect, 0));
          HeapObjectMatcher mnewtarget(GetValueInput(effect, 1));
412
          if (mtarget.HasValue() && mnewtarget.HasValue() &&
413 414 415 416 417 418
              mnewtarget.Ref(broker).IsJSFunction()) {
            JSFunctionRef original_constructor =
                mnewtarget.Ref(broker).AsJSFunction();
            if (original_constructor.has_initial_map()) {
              original_constructor.Serialize();
              MapRef initial_map = original_constructor.initial_map();
419
              if (initial_map.GetConstructor().equals(mtarget.Ref(broker))) {
420
                *maps_return = ZoneHandleSet<Map>(initial_map.object());
421
                return result;
422 423 424 425
              }
            }
          }
          // We reached the allocation of the {receiver}.
426
          return kNoReceiverMaps;
427 428 429
        }
        break;
      }
430 431 432 433 434 435 436 437 438 439
      case IrOpcode::kJSCreatePromise: {
        if (IsSame(receiver, effect)) {
          *maps_return = ZoneHandleSet<Map>(broker->native_context()
                                                .promise_function()
                                                .initial_map()
                                                .object());
          return result;
        }
        break;
      }
440 441 442 443 444 445 446 447 448 449
      case IrOpcode::kStoreField: {
        // We only care about StoreField of maps.
        Node* const object = GetValueInput(effect, 0);
        FieldAccess const& access = FieldAccessOf(effect->op());
        if (access.base_is_tagged == kTaggedBase &&
            access.offset == HeapObject::kMapOffset) {
          if (IsSame(receiver, object)) {
            Node* const value = GetValueInput(effect, 1);
            HeapObjectMatcher m(value);
            if (m.HasValue()) {
450
              *maps_return = ZoneHandleSet<Map>(m.Ref(broker).AsMap().object());
451
              return result;
452 453 454 455
            }
          }
          // Without alias analysis we cannot tell whether this
          // StoreField[map] affects {receiver} or not.
456
          result = kUnreliableReceiverMaps;
457 458 459 460 461 462 463 464 465 466
        }
        break;
      }
      case IrOpcode::kJSStoreMessage:
      case IrOpcode::kJSStoreModule:
      case IrOpcode::kStoreElement:
      case IrOpcode::kStoreTypedElement: {
        // These never change the map of objects.
        break;
      }
467 468 469 470 471 472 473
      case IrOpcode::kFinishRegion: {
        // FinishRegion renames the output of allocations, so we need
        // to update the {receiver} that we are looking for, if the
        // {receiver} matches the current {effect}.
        if (IsSame(receiver, effect)) receiver = GetValueInput(effect, 0);
        break;
      }
474 475 476
      case IrOpcode::kEffectPhi: {
        Node* control = GetControlInput(effect);
        if (control->opcode() != IrOpcode::kLoop) {
477 478
          DCHECK(control->opcode() == IrOpcode::kDead ||
                 control->opcode() == IrOpcode::kMerge);
479 480 481 482 483 484 485 486 487
          return kNoReceiverMaps;
        }

        // Continue search for receiver map outside the loop. Since operations
        // inside the loop may change the map, the result is unreliable.
        effect = GetEffectInput(effect, 0);
        result = kUnreliableReceiverMaps;
        continue;
      }
488 489
      default: {
        DCHECK_EQ(1, effect->op()->EffectOutputCount());
490
        if (effect->op()->EffectInputCount() != 1) {
491
          // Didn't find any appropriate CheckMaps node.
492 493 494 495 496 497
          return kNoReceiverMaps;
        }
        if (!effect->op()->HasProperty(Operator::kNoWrite)) {
          // Without alias/escape analysis we cannot tell whether this
          // {effect} affects {receiver} or not.
          result = kUnreliableReceiverMaps;
498 499 500 501
        }
        break;
      }
    }
502 503 504 505 506 507

    // Stop walking the effect chain once we hit the definition of
    // the {receiver} along the {effect}s.
    if (IsSame(receiver, effect)) return kNoReceiverMaps;

    // Continue with the next {effect}.
508 509 510 511 512
    DCHECK_EQ(1, effect->op()->EffectInputCount());
    effect = NodeProperties::GetEffectInput(effect);
  }
}

513
// static
514 515
MaybeHandle<Map> NodeProperties::GetMapWitness(JSHeapBroker* broker,
                                               Node* node) {
516 517 518 519
  ZoneHandleSet<Map> maps;
  Node* receiver = NodeProperties::GetValueInput(node, 1);
  Node* effect = NodeProperties::GetEffectInput(node);
  NodeProperties::InferReceiverMapsResult result =
520
      NodeProperties::InferReceiverMaps(broker, receiver, effect, &maps);
521 522 523 524 525 526
  if (result == NodeProperties::kReliableReceiverMaps && maps.size() == 1) {
    return maps[0];
  }
  return MaybeHandle<Map>();
}

527
// static
528 529
bool NodeProperties::HasInstanceTypeWitness(JSHeapBroker* broker,
                                            Node* receiver, Node* effect,
530 531 532
                                            InstanceType instance_type) {
  ZoneHandleSet<Map> receiver_maps;
  NodeProperties::InferReceiverMapsResult result =
533
      NodeProperties::InferReceiverMaps(broker, receiver, effect,
534
                                        &receiver_maps);
535 536 537 538 539
  switch (result) {
    case NodeProperties::kUnreliableReceiverMaps:
    case NodeProperties::kReliableReceiverMaps:
      DCHECK_NE(0, receiver_maps.size());
      for (size_t i = 0; i < receiver_maps.size(); ++i) {
540 541
        MapRef map(broker, receiver_maps[i]);
        if (map.instance_type() != instance_type) return false;
542 543 544 545 546 547 548 549 550
      }
      return true;

    case NodeProperties::kNoReceiverMaps:
      return false;
  }
  UNREACHABLE();
}

551 552 553 554 555 556 557 558 559 560 561 562 563 564
// static
bool NodeProperties::NoObservableSideEffectBetween(Node* effect,
                                                   Node* dominator) {
  while (effect != dominator) {
    if (effect->op()->EffectInputCount() == 1 &&
        effect->op()->properties() & Operator::kNoWrite) {
      effect = NodeProperties::GetEffectInput(effect);
    } else {
      return false;
    }
  }
  return true;
}

565
// static
566
bool NodeProperties::CanBePrimitive(JSHeapBroker* broker, Node* receiver,
567
                                    Node* effect) {
568 569 570 571 572 573 574 575 576 577 578
  switch (receiver->opcode()) {
#define CASE(Opcode) case IrOpcode::k##Opcode:
    JS_CONSTRUCT_OP_LIST(CASE)
    JS_CREATE_OP_LIST(CASE)
#undef CASE
    case IrOpcode::kCheckReceiver:
    case IrOpcode::kConvertReceiver:
    case IrOpcode::kJSGetSuperConstructor:
    case IrOpcode::kJSToObject:
      return false;
    case IrOpcode::kHeapConstant: {
579 580 581
      HeapObjectRef value =
          HeapObjectMatcher(receiver).Ref(broker).AsHeapObject();
      return value.map().IsPrimitiveMap();
582 583 584 585 586 587
    }
    default: {
      // We don't really care about the exact maps here,
      // just the instance types, which don't change
      // across potential side-effecting operations.
      ZoneHandleSet<Map> maps;
588
      if (InferReceiverMaps(broker, receiver, effect, &maps) !=
589
          kNoReceiverMaps) {
590
        // Check if one of the {maps} is not a JSReceiver map.
591
        for (size_t i = 0; i < maps.size(); ++i) {
592 593
          MapRef map(broker, maps[i]);
          if (!map.IsJSReceiverMap()) return true;
594 595 596 597 598 599 600 601 602
        }
        return false;
      }
      return true;
    }
  }
}

// static
603
bool NodeProperties::CanBeNullOrUndefined(JSHeapBroker* broker, Node* receiver,
604
                                          Node* effect) {
605
  if (CanBePrimitive(broker, receiver, effect)) {
606
    switch (receiver->opcode()) {
607
      case IrOpcode::kCheckInternalizedString:
608
      case IrOpcode::kCheckNumber:
609 610 611
      case IrOpcode::kCheckSmi:
      case IrOpcode::kCheckString:
      case IrOpcode::kCheckSymbol:
612 613 614
      case IrOpcode::kJSToLength:
      case IrOpcode::kJSToName:
      case IrOpcode::kJSToNumber:
615
      case IrOpcode::kJSToNumberConvertBigInt:
616 617
      case IrOpcode::kJSToNumeric:
      case IrOpcode::kJSToString:
618
      case IrOpcode::kToBoolean:
619 620
        return false;
      case IrOpcode::kHeapConstant: {
621 622 623 624
        HeapObjectRef value =
            HeapObjectMatcher(receiver).Ref(broker).AsHeapObject();
        OddballType type = value.map().oddball_type();
        return type == OddballType::kNull || type == OddballType::kUndefined;
625 626 627 628 629 630 631 632
      }
      default:
        return true;
    }
  }
  return false;
}

633 634 635 636 637 638 639 640 641 642 643
// static
Node* NodeProperties::GetOuterContext(Node* node, size_t* depth) {
  Node* context = NodeProperties::GetContextInput(node);
  while (*depth > 0 &&
         IrOpcode::IsContextChainExtendingOpcode(context->opcode())) {
    context = NodeProperties::GetContextInput(context);
    (*depth)--;
  }
  return context;
}

644
// static
645
Type NodeProperties::GetTypeOrAny(Node* node) {
646 647 648 649
  return IsTyped(node) ? node->type() : Type::Any();
}


650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666
// static
bool NodeProperties::AllValueInputsAreTyped(Node* node) {
  int input_count = node->op()->ValueInputCount();
  for (int index = 0; index < input_count; ++index) {
    if (!IsTyped(GetValueInput(node, index))) return false;
  }
  return true;
}


// static
bool NodeProperties::IsInputRange(Edge edge, int first, int num) {
  if (num == 0) return false;
  int const index = edge.index();
  return first <= index && index < first + num;
}

667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698
// static
size_t NodeProperties::HashCode(Node* node) {
  size_t h = base::hash_combine(node->op()->HashCode(), node->InputCount());
  for (Node* input : node->inputs()) {
    h = base::hash_combine(h, input->id());
  }
  return h;
}

// static
bool NodeProperties::Equals(Node* a, Node* b) {
  DCHECK_NOT_NULL(a);
  DCHECK_NOT_NULL(b);
  DCHECK_NOT_NULL(a->op());
  DCHECK_NOT_NULL(b->op());
  if (!a->op()->Equals(b->op())) return false;
  if (a->InputCount() != b->InputCount()) return false;
  Node::Inputs aInputs = a->inputs();
  Node::Inputs bInputs = b->inputs();

  auto aIt = aInputs.begin();
  auto bIt = bInputs.begin();
  auto aEnd = aInputs.end();

  for (; aIt != aEnd; ++aIt, ++bIt) {
    DCHECK_NOT_NULL(*aIt);
    DCHECK_NOT_NULL(*bIt);
    if ((*aIt)->id() != (*bIt)->id()) return false;
  }
  return true;
}

699 700 701
}  // namespace compiler
}  // namespace internal
}  // namespace v8