ic-compiler-mips64.cc 4.66 KB
Newer Older
1
// Copyright 2014 the V8 project authors. All rights reserved.
2 3 4 5 6
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#if V8_TARGET_ARCH_MIPS64

7
#include "src/ic/ic.h"
8
#include "src/ic/ic-compiler.h"
9 10 11 12 13 14 15

namespace v8 {
namespace internal {

#define __ ACCESS_MASM(masm())


16
Handle<Code> PropertyICCompiler::CompilePolymorphic(MapHandleList* maps,
17 18 19 20
                                                    CodeHandleList* handlers,
                                                    Handle<Name> name,
                                                    Code::StubType type,
                                                    IcCheckType check) {
21 22 23 24
  Label miss;

  if (check == PROPERTY &&
      (kind() == Code::KEYED_LOAD_IC || kind() == Code::KEYED_STORE_IC)) {
25
    // In case we are compiling an IC for dictionary loads or stores, just
26 27
    // check whether the name is unique.
    if (name.is_identical_to(isolate()->factory()->normal_ic_symbol())) {
28 29 30
      // Keyed loads with dictionaries shouldn't be here, they go generic.
      // The DCHECK is to protect assumptions when --vector-ics is on.
      DCHECK(kind() != Code::KEYED_LOAD_IC);
31 32 33 34 35
      Register tmp = scratch1();
      __ JumpIfSmi(this->name(), &miss);
      __ ld(tmp, FieldMemOperand(this->name(), HeapObject::kMapOffset));
      __ lbu(tmp, FieldMemOperand(tmp, Map::kInstanceTypeOffset));
      __ JumpIfNotUniqueNameInstanceType(tmp, &miss);
36 37 38
    } else {
      __ Branch(&miss, ne, this->name(), Operand(name));
    }
39 40 41
  }

  Label number_case;
42
  Register match = scratch2();
43
  Label* smi_target = IncludesNumberMap(maps) ? &number_case : &miss;
44 45
  __ JumpIfSmi(receiver(), smi_target, match);  // Reg match is 0 if Smi.

46
  // Polymorphic keyed stores may use the map register
47
  Register map_reg = scratch1();
48
  DCHECK(kind() != Code::KEYED_STORE_IC ||
49
         map_reg.is(StoreTransitionDescriptor::MapRegister()));
50

51
  int receiver_count = maps->length();
52 53 54
  int number_of_handled_maps = 0;
  __ ld(map_reg, FieldMemOperand(receiver(), HeapObject::kMapOffset));
  for (int current = 0; current < receiver_count; ++current) {
55
    Handle<Map> map = maps->at(current);
56 57 58 59
    if (!map->is_deprecated()) {
      number_of_handled_maps++;
      // Check map and tail call if there's a match.
      // Separate compare from branch, to provide path for above JumpIfSmi().
60
      Handle<WeakCell> cell = Map::WeakCellForMap(map);
61
      __ GetWeakValue(match, cell);
62
      __ Dsubu(match, match, Operand(map_reg));
63
      if (map->instance_type() == HEAP_NUMBER_TYPE) {
64
        DCHECK(!number_case.is_unused());
65 66
        __ bind(&number_case);
      }
67
      __ Jump(handlers->at(current), RelocInfo::CODE_TARGET, eq, match,
68
              Operand(zero_reg));
69 70
    }
  }
71
  DCHECK(number_of_handled_maps != 0);
72 73 74 75 76 77 78

  __ bind(&miss);
  TailCallBuiltin(masm(), MissBuiltin(kind()));

  // Return the generated code.
  InlineCacheState state =
      number_of_handled_maps > 1 ? POLYMORPHIC : MONOMORPHIC;
79
  return GetCode(kind(), type, name, state);
80 81 82
}


83
Handle<Code> PropertyICCompiler::CompileKeyedStorePolymorphic(
84
    MapHandleList* receiver_maps, CodeHandleList* handler_stubs,
85 86 87 88 89
    MapHandleList* transitioned_maps) {
  Label miss;
  __ JumpIfSmi(receiver(), &miss);

  int receiver_count = receiver_maps->length();
90 91 92
  Register map_reg = scratch1();
  Register match = scratch2();
  __ ld(map_reg, FieldMemOperand(receiver(), HeapObject::kMapOffset));
93
  for (int i = 0; i < receiver_count; ++i) {
94
    Handle<WeakCell> cell = Map::WeakCellForMap(receiver_maps->at(i));
95
    __ GetWeakValue(match, cell);
96
    if (transitioned_maps->at(i).is_null()) {
97
      __ Jump(handler_stubs->at(i), RelocInfo::CODE_TARGET, eq, match,
98
              Operand(map_reg));
99 100
    } else {
      Label next_map;
101
      __ Branch(&next_map, ne, match, Operand(map_reg));
102 103
      Handle<WeakCell> cell = Map::WeakCellForMap(transitioned_maps->at(i));
      __ LoadWeakValue(transition_map(), cell, &miss);
104 105 106 107 108 109 110 111 112
      __ Jump(handler_stubs->at(i), RelocInfo::CODE_TARGET);
      __ bind(&next_map);
    }
  }

  __ bind(&miss);
  TailCallBuiltin(masm(), MissBuiltin(kind()));

  // Return the generated code.
113
  return GetCode(kind(), Code::NORMAL, factory()->empty_string(), POLYMORPHIC);
114 115 116 117 118 119 120
}


#undef __
#define __ ACCESS_MASM(masm)


121 122
void PropertyICCompiler::GenerateRuntimeSetProperty(
    MacroAssembler* masm, LanguageMode language_mode) {
123 124
  __ Push(StoreDescriptor::ReceiverRegister(), StoreDescriptor::NameRegister(),
          StoreDescriptor::ValueRegister());
125

126
  __ li(a0, Operand(Smi::FromInt(language_mode)));
127 128 129 130 131 132 133
  __ Push(a0);

  // Do tail-call to runtime routine.
  __ TailCallRuntime(Runtime::kSetProperty, 4, 1);
}


134
#undef __
135 136
}  // namespace internal
}  // namespace v8
137 138

#endif  // V8_TARGET_ARCH_MIPS64