ic-compiler-ppc.cc 4.39 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
// Copyright 2014 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/v8.h"

#if V8_TARGET_ARCH_PPC

#include "src/ic/ic.h"
#include "src/ic/ic-compiler.h"

namespace v8 {
namespace internal {

#define __ ACCESS_MASM(masm)


18 19 20
void PropertyICCompiler::GenerateRuntimeSetProperty(
    MacroAssembler* masm, LanguageMode language_mode) {
  __ mov(r0, Operand(Smi::FromInt(language_mode)));
21
  __ Push(StoreDescriptor::ReceiverRegister(), StoreDescriptor::NameRegister(),
22
          StoreDescriptor::ValueRegister(), r0);
23 24 25 26 27 28 29 30 31 32

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


#undef __
#define __ ACCESS_MASM(masm())


33
Handle<Code> PropertyICCompiler::CompilePolymorphic(MapHandleList* maps,
34 35 36 37 38 39 40 41
                                                    CodeHandleList* handlers,
                                                    Handle<Name> name,
                                                    Code::StubType type,
                                                    IcCheckType check) {
  Label miss;

  if (check == PROPERTY &&
      (kind() == Code::KEYED_LOAD_IC || kind() == Code::KEYED_STORE_IC)) {
42
    // In case we are compiling an IC for dictionary loads or stores, just
43 44
    // check whether the name is unique.
    if (name.is_identical_to(isolate()->factory()->normal_ic_symbol())) {
45 46 47
      // 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);
48 49 50 51 52 53 54 55 56 57 58 59
      Register tmp = scratch1();
      __ JumpIfSmi(this->name(), &miss);
      __ LoadP(tmp, FieldMemOperand(this->name(), HeapObject::kMapOffset));
      __ lbz(tmp, FieldMemOperand(tmp, Map::kInstanceTypeOffset));
      __ JumpIfNotUniqueNameInstanceType(tmp, &miss);
    } else {
      __ Cmpi(this->name(), Operand(name), r0);
      __ bne(&miss);
    }
  }

  Label number_case;
60
  Label* smi_target = IncludesNumberMap(maps) ? &number_case : &miss;
61 62 63 64 65
  __ JumpIfSmi(receiver(), smi_target);

  // Polymorphic keyed stores may use the map register
  Register map_reg = scratch1();
  DCHECK(kind() != Code::KEYED_STORE_IC ||
66
         map_reg.is(StoreTransitionDescriptor::MapRegister()));
67

68
  int receiver_count = maps->length();
69 70 71
  int number_of_handled_maps = 0;
  __ LoadP(map_reg, FieldMemOperand(receiver(), HeapObject::kMapOffset));
  for (int current = 0; current < receiver_count; ++current) {
72
    Handle<Map> map = maps->at(current);
73 74
    if (!map->is_deprecated()) {
      number_of_handled_maps++;
75 76
      Handle<WeakCell> cell = Map::WeakCellForMap(map);
      __ CmpWeakValue(map_reg, cell, scratch2());
77 78
      Label next;
      __ bne(&next);
79
      if (map->instance_type() == HEAP_NUMBER_TYPE) {
80 81 82
        DCHECK(!number_case.is_unused());
        __ bind(&number_case);
      }
83 84
      __ Jump(handlers->at(current), RelocInfo::CODE_TARGET);
      __ bind(&next);
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
    }
  }
  DCHECK(number_of_handled_maps != 0);

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

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


Handle<Code> PropertyICCompiler::CompileKeyedStorePolymorphic(
    MapHandleList* receiver_maps, CodeHandleList* handler_stubs,
    MapHandleList* transitioned_maps) {
  Label miss;
  __ JumpIfSmi(receiver(), &miss);

  int receiver_count = receiver_maps->length();
106 107
  Register map_reg = scratch1();
  __ LoadP(map_reg, FieldMemOperand(receiver(), HeapObject::kMapOffset));
108
  for (int i = 0; i < receiver_count; ++i) {
109 110
    Handle<WeakCell> cell = Map::WeakCellForMap(receiver_maps->at(i));
    __ CmpWeakValue(map_reg, cell, scratch2());
111 112 113 114 115
    if (transitioned_maps->at(i).is_null()) {
      __ Jump(handler_stubs->at(i), RelocInfo::CODE_TARGET, eq);
    } else {
      Label next_map;
      __ bne(&next_map);
116 117
      Handle<WeakCell> cell = Map::WeakCellForMap(transitioned_maps->at(i));
      __ LoadWeakValue(transition_map(), cell, &miss);
118 119 120 121 122 123 124 125 126 127 128 129 130 131
      __ Jump(handler_stubs->at(i), RelocInfo::CODE_TARGET, al);
      __ bind(&next_map);
    }
  }

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

  // Return the generated code.
  return GetCode(kind(), Code::NORMAL, factory()->empty_string(), POLYMORPHIC);
}


#undef __
132 133
}  // namespace internal
}  // namespace v8
134 135

#endif  // V8_TARGET_ARCH_PPC