| // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| // for details. All rights reserved. Use of this source code is governed by a |
| // BSD-style license that can be found in the LICENSE file. |
| |
| #include "vm/globals.h" // Needed here to get TARGET_ARCH_ARM. |
| #if defined(TARGET_ARCH_ARM) && !defined(DART_PRECOMPILED_RUNTIME) |
| |
| #include "vm/compiler/backend/il.h" |
| |
| #include "vm/compiler/backend/flow_graph.h" |
| #include "vm/compiler/backend/flow_graph_compiler.h" |
| #include "vm/compiler/backend/locations.h" |
| #include "vm/compiler/backend/locations_helpers.h" |
| #include "vm/compiler/backend/range_analysis.h" |
| #include "vm/compiler/jit/compiler.h" |
| #include "vm/cpu.h" |
| #include "vm/dart_entry.h" |
| #include "vm/instructions.h" |
| #include "vm/object_store.h" |
| #include "vm/parser.h" |
| #include "vm/simulator.h" |
| #include "vm/stack_frame.h" |
| #include "vm/stub_code.h" |
| #include "vm/symbols.h" |
| #include "vm/type_testing_stubs.h" |
| |
| #define __ compiler->assembler()-> |
| #define Z (compiler->zone()) |
| |
| namespace dart { |
| |
| // Generic summary for call instructions that have all arguments pushed |
| // on the stack and return the result in a fixed register R0. |
| LocationSummary* Instruction::MakeCallSummary(Zone* zone) { |
| LocationSummary* result = |
| new (zone) LocationSummary(zone, 0, 0, LocationSummary::kCall); |
| result->set_out(0, Location::RegisterLocation(R0)); |
| return result; |
| } |
| |
| DEFINE_BACKEND(LoadIndexedUnsafe, (Register out, Register index)) { |
| ASSERT(instr->RequiredInputRepresentation(0) == kTagged); // It is a Smi. |
| __ add(out, instr->base_reg(), Operand(index, LSL, 1)); |
| __ ldr(out, Address(out, instr->offset())); |
| |
| ASSERT(kSmiTag == 0); |
| ASSERT(kSmiTagSize == 1); |
| } |
| |
| DEFINE_BACKEND(StoreIndexedUnsafe, |
| (NoLocation, Register index, Register value)) { |
| ASSERT(instr->RequiredInputRepresentation( |
| StoreIndexedUnsafeInstr::kIndexPos) == kTagged); // It is a Smi. |
| __ add(TMP, instr->base_reg(), Operand(index, LSL, 1)); |
| __ str(value, Address(TMP, instr->offset())); |
| |
| ASSERT(kSmiTag == 0); |
| ASSERT(kSmiTagSize == 1); |
| } |
| |
| DEFINE_BACKEND(TailCall, |
| (NoLocation, |
| Fixed<Register, ARGS_DESC_REG>, |
| Temp<Register> temp)) { |
| __ LoadObject(CODE_REG, instr->code()); |
| __ LeaveDartFrame(); // The arguments are still on the stack. |
| __ Branch( |
| FieldAddress(CODE_REG, compiler::target::Code::entry_point_offset())); |
| |
| // Even though the TailCallInstr will be the last instruction in a basic |
| // block, the flow graph compiler will emit native code for other blocks after |
| // the one containing this instruction and needs to be able to use the pool. |
| // (The `LeaveDartFrame` above disables usages of the pool.) |
| __ set_constant_pool_allowed(true); |
| } |
| |
| LocationSummary* PushArgumentInstr::MakeLocationSummary(Zone* zone, |
| bool opt) const { |
| const intptr_t kNumInputs = 1; |
| const intptr_t kNumTemps = 0; |
| LocationSummary* locs = new (zone) |
| LocationSummary(zone, kNumInputs, kNumTemps, LocationSummary::kNoCall); |
| locs->set_in(0, LocationAnyOrConstant(value())); |
| return locs; |
| } |
| |
| void PushArgumentInstr::EmitNativeCode(FlowGraphCompiler* compiler) { |
| // In SSA mode, we need an explicit push. Nothing to do in non-SSA mode |
| // where PushArgument is handled by BindInstr::EmitNativeCode. |
| if (compiler->is_optimizing()) { |
| Location value = locs()->in(0); |
| if (value.IsRegister()) { |
| __ Push(value.reg()); |
| } else if (value.IsConstant()) { |
| __ PushObject(value.constant()); |
| } else { |
| ASSERT(value.IsStackSlot()); |
| const intptr_t value_offset = value.ToStackSlotOffset(); |
| __ LoadFromOffset(kWord, IP, value.base_reg(), value_offset); |
| __ Push(IP); |
| } |
| } |
| } |
| |
| LocationSummary* ReturnInstr::MakeLocationSummary(Zone* zone, bool opt) const { |
| const intptr_t kNumInputs = 1; |
| const intptr_t kNumTemps = 0; |
| LocationSummary* locs = new (zone) |
| LocationSummary(zone, kNumInputs, kNumTemps, LocationSummary::kNoCall); |
| locs->set_in(0, Location::RegisterLocation(R0)); |
| return locs; |
| } |
| |
| // Attempt optimized compilation at return instruction instead of at the entry. |
| // The entry needs to be patchable, no inlined objects are allowed in the area |
| // that will be overwritten by the patch instructions: a branch macro sequence. |
| void ReturnInstr::EmitNativeCode(FlowGraphCompiler* compiler) { |
| const Register result = locs()->in(0).reg(); |
| ASSERT(result == R0); |
| |
| if (compiler->intrinsic_mode()) { |
| // Intrinsics don't have a frame. |
| __ Ret(); |
| return; |
| } |
| |
| #if defined(DEBUG) |
| Label stack_ok; |
| __ Comment("Stack Check"); |
| const intptr_t fp_sp_dist = |
| (compiler::target::frame_layout.first_local_from_fp + 1 - |
| compiler->StackSize()) * |
| compiler::target::kWordSize; |
| ASSERT(fp_sp_dist <= 0); |
| __ sub(R2, SP, Operand(FP)); |
| __ CompareImmediate(R2, fp_sp_dist); |
| __ b(&stack_ok, EQ); |
| __ bkpt(0); |
| __ Bind(&stack_ok); |
| #endif |
| ASSERT(__ constant_pool_allowed()); |
| __ LeaveDartFrameAndReturn(); // Disallows constant pool use. |
| // This ReturnInstr may be emitted out of order by the optimizer. The next |
| // block may be a target expecting a properly set constant pool pointer. |
| __ set_constant_pool_allowed(true); |
| } |
| |
| static Condition NegateCondition(Condition condition) { |
| switch (condition) { |
| case EQ: |
| return NE; |
| case NE: |
| return EQ; |
| case LT: |
| return GE; |
| case LE: |
| return GT; |
| case GT: |
| return LE; |
| case GE: |
| return LT; |
| case CC: |
| return CS; |
| case LS: |
| return HI; |
| case HI: |
| return LS; |
| case CS: |
| return CC; |
| case VC: |
| return VS; |
| case VS: |
| return VC; |
| default: |
| UNREACHABLE(); |
| return EQ; |
| } |
| } |
| |
| // Detect pattern when one value is zero and another is a power of 2. |
| static bool IsPowerOfTwoKind(intptr_t v1, intptr_t v2) { |
| return (Utils::IsPowerOfTwo(v1) && (v2 == 0)) || |
| (Utils::IsPowerOfTwo(v2) && (v1 == 0)); |
| } |
| |
| LocationSummary* IfThenElseInstr::MakeLocationSummary(Zone* zone, |
| bool opt) const { |
| comparison()->InitializeLocationSummary(zone, opt); |
| return comparison()->locs(); |
| } |
| |
| void IfThenElseInstr::EmitNativeCode(FlowGraphCompiler* compiler) { |
| const Register result = locs()->out(0).reg(); |
| |
| Location left = locs()->in(0); |
| Location right = locs()->in(1); |
| ASSERT(!left.IsConstant() || !right.IsConstant()); |
| |
| // Clear out register. |
| __ eor(result, result, Operand(result)); |
| |
| // Emit comparison code. This must not overwrite the result register. |
| // IfThenElseInstr::Supports() should prevent EmitComparisonCode from using |
| // the labels or returning an invalid condition. |
| BranchLabels labels = {NULL, NULL, NULL}; |
| Condition true_condition = comparison()->EmitComparisonCode(compiler, labels); |
| ASSERT(true_condition != kInvalidCondition); |
| |
| const bool is_power_of_two_kind = IsPowerOfTwoKind(if_true_, if_false_); |
| |
| intptr_t true_value = if_true_; |
| intptr_t false_value = if_false_; |
| |
| if (is_power_of_two_kind) { |
| if (true_value == 0) { |
| // We need to have zero in result on true_condition. |
| true_condition = NegateCondition(true_condition); |
| } |
| } else { |
| if (true_value == 0) { |
| // Swap values so that false_value is zero. |
| intptr_t temp = true_value; |
| true_value = false_value; |
| false_value = temp; |
| } else { |
| true_condition = NegateCondition(true_condition); |
| } |
| } |
| |
| __ mov(result, Operand(1), true_condition); |
| |
| if (is_power_of_two_kind) { |
| const intptr_t shift = |
| Utils::ShiftForPowerOfTwo(Utils::Maximum(true_value, false_value)); |
| __ Lsl(result, result, Operand(shift + kSmiTagSize)); |
| } else { |
| __ sub(result, result, Operand(1)); |
| const int32_t val = compiler::target::ToRawSmi(true_value) - |
| compiler::target::ToRawSmi(false_value); |
| __ AndImmediate(result, result, val); |
| if (false_value != 0) { |
| __ AddImmediate(result, compiler::target::ToRawSmi(false_value)); |
| } |
| } |
| } |
| |
| LocationSummary* ClosureCallInstr::MakeLocationSummary(Zone* zone, |
| bool opt) const { |
| const intptr_t kNumInputs = 1; |
| const intptr_t kNumTemps = 0; |
| LocationSummary* summary = new (zone) |
| LocationSummary(zone, kNumInputs, kNumTemps, LocationSummary::kCall); |
| summary->set_in(0, Location::RegisterLocation(R0)); // Function. |
| summary->set_out(0, Location::RegisterLocation(R0)); |
| return summary; |
| } |
| |
| void ClosureCallInstr::EmitNativeCode(FlowGraphCompiler* compiler) { |
| // Load arguments descriptor in R4. |
| const intptr_t argument_count = ArgumentCount(); // Includes type args. |
| const Array& arguments_descriptor = |
| Array::ZoneHandle(Z, GetArgumentsDescriptor()); |
| __ LoadObject(R4, arguments_descriptor); |
| |
| // R4: Arguments descriptor. |
| // R0: Function. |
| ASSERT(locs()->in(0).reg() == R0); |
| __ ldr(CODE_REG, FieldAddress(R0, compiler::target::Function::code_offset())); |
| __ ldr(R2, |
| FieldAddress(R0, compiler::target::Code::function_entry_point_offset( |
| entry_kind()))); |
| |
| // R2: instructions entry point. |
| // R9: Smi 0 (no IC data; the lazy-compile stub expects a GC-safe value). |
| __ LoadImmediate(R9, 0); |
| __ blx(R2); |
| compiler->EmitCallsiteMetadata(token_pos(), deopt_id(), |
| RawPcDescriptors::kOther, locs()); |
| __ Drop(argument_count); |
| } |
| |
| LocationSummary* LoadLocalInstr::MakeLocationSummary(Zone* zone, |
| bool opt) const { |
| return LocationSummary::Make(zone, 0, Location::RequiresRegister(), |
| LocationSummary::kNoCall); |
| } |
| |
| void LoadLocalInstr::EmitNativeCode(FlowGraphCompiler* compiler) { |
| const Register result = locs()->out(0).reg(); |
| __ LoadFromOffset(kWord, result, FP, |
| compiler::target::FrameOffsetInBytesForVariable(&local())); |
| } |
| |
| LocationSummary* StoreLocalInstr::MakeLocationSummary(Zone* zone, |
| bool opt) const { |
| return LocationSummary::Make(zone, 1, Location::SameAsFirstInput(), |
| LocationSummary::kNoCall); |
| } |
| |
| void StoreLocalInstr::EmitNativeCode(FlowGraphCompiler* compiler) { |
| const Register value = locs()->in(0).reg(); |
| const Register result = locs()->out(0).reg(); |
| ASSERT(result == value); // Assert that register assignment is correct. |
| __ StoreToOffset(kWord, value, FP, |
| compiler::target::FrameOffsetInBytesForVariable(&local())); |
| } |
| |
| LocationSummary* ConstantInstr::MakeLocationSummary(Zone* zone, |
| bool opt) const { |
| return LocationSummary::Make(zone, 0, Location::RequiresRegister(), |
| LocationSummary::kNoCall); |
| } |
| |
| void ConstantInstr::EmitNativeCode(FlowGraphCompiler* compiler) { |
| // The register allocator drops constant definitions that have no uses. |
| if (!locs()->out(0).IsInvalid()) { |
| const Register result = locs()->out(0).reg(); |
| __ LoadObject(result, value()); |
| } |
| } |
| |
| void ConstantInstr::EmitMoveToLocation(FlowGraphCompiler* compiler, |
| const Location& destination, |
| Register tmp) { |
| if (destination.IsRegister()) { |
| if (representation() == kUnboxedInt32) { |
| int64_t v; |
| const bool ok = compiler::HasIntegerValue(value_, &v); |
| RELEASE_ASSERT(ok); |
| __ LoadImmediate(destination.reg(), v); |
| } else { |
| ASSERT(representation() == kTagged); |
| __ LoadObject(destination.reg(), value_); |
| } |
| } else if (destination.IsFpuRegister()) { |
| const DRegister dst = EvenDRegisterOf(destination.fpu_reg()); |
| if (Utils::DoublesBitEqual(Double::Cast(value_).value(), 0.0) && |
| TargetCPUFeatures::neon_supported()) { |
| QRegister qdst = destination.fpu_reg(); |
| __ veorq(qdst, qdst, qdst); |
| } else { |
| ASSERT(tmp != kNoRegister); |
| __ LoadDImmediate(dst, Double::Cast(value_).value(), tmp); |
| } |
| } else if (destination.IsDoubleStackSlot()) { |
| if (Utils::DoublesBitEqual(Double::Cast(value_).value(), 0.0) && |
| TargetCPUFeatures::neon_supported()) { |
| __ veorq(QTMP, QTMP, QTMP); |
| } else { |
| ASSERT(tmp != kNoRegister); |
| __ LoadDImmediate(DTMP, Double::Cast(value_).value(), tmp); |
| } |
| const intptr_t dest_offset = destination.ToStackSlotOffset(); |
| __ StoreDToOffset(DTMP, destination.base_reg(), dest_offset); |
| } else { |
| ASSERT(destination.IsStackSlot()); |
| ASSERT(tmp != kNoRegister); |
| const intptr_t dest_offset = destination.ToStackSlotOffset(); |
| if (representation() == kUnboxedInt32) { |
| int64_t v; |
| const bool ok = compiler::HasIntegerValue(value_, &v); |
| RELEASE_ASSERT(ok); |
| __ LoadImmediate(tmp, v); |
| } else { |
| __ LoadObject(tmp, value_); |
| } |
| __ StoreToOffset(kWord, tmp, destination.base_reg(), dest_offset); |
| } |
| } |
| |
| LocationSummary* UnboxedConstantInstr::MakeLocationSummary(Zone* zone, |
| bool opt) const { |
| const intptr_t kNumInputs = 0; |
| const intptr_t kNumTemps = (representation_ == kUnboxedInt32) ? 0 : 1; |
| LocationSummary* locs = new (zone) |
| LocationSummary(zone, kNumInputs, kNumTemps, LocationSummary::kNoCall); |
| if (representation_ == kUnboxedInt32) { |
| locs->set_out(0, Location::RequiresRegister()); |
| } else { |
| ASSERT(representation_ == kUnboxedDouble); |
| locs->set_out(0, Location::RequiresFpuRegister()); |
| } |
| if (kNumTemps > 0) { |
| locs->set_temp(0, Location::RequiresRegister()); |
| } |
| return locs; |
| } |
| |
| void UnboxedConstantInstr::EmitNativeCode(FlowGraphCompiler* compiler) { |
| // The register allocator drops constant definitions that have no uses. |
| if (!locs()->out(0).IsInvalid()) { |
| const Register scratch = |
| locs()->temp_count() == 0 ? kNoRegister : locs()->temp(0).reg(); |
| EmitMoveToLocation(compiler, locs()->out(0), scratch); |
| } |
| } |
| |
| LocationSummary* AssertAssignableInstr::MakeLocationSummary(Zone* zone, |
| bool opt) const { |
| // When using a type testing stub, we want to prevent spilling of the |
| // function/instantiator type argument vectors, since stub preserves them. So |
| // we make this a `kNoCall` summary, even though most other registers can be |
| // modified by the stub. To tell the register allocator about it, we reserve |
| // all the other registers as temporary registers. |
| // TODO(http://dartbug.com/32788): Simplify this. |
| const Register kInstanceReg = R0; |
| const Register kInstantiatorTypeArgumentsReg = R2; |
| const Register kFunctionTypeArgumentsReg = R1; |
| |
| const bool using_stub = |
| FlowGraphCompiler::ShouldUseTypeTestingStubFor(opt, dst_type()); |
| |
| const intptr_t kNonChangeableInputRegs = |
| (1 << kInstanceReg) | (1 << kInstantiatorTypeArgumentsReg) | |
| (1 << kFunctionTypeArgumentsReg); |
| |
| const intptr_t kNumInputs = 3; |
| |
| // We invoke a stub that can potentially clobber any CPU register |
| // but can only clobber FPU registers on the slow path when |
| // entering runtime. Preserve all FPU registers that are |
| // not guarateed to be preserved by the ABI. |
| const intptr_t kCpuRegistersToPreserve = |
| kDartAvailableCpuRegs & ~kNonChangeableInputRegs; |
| const intptr_t kFpuRegistersToPreserve = |
| Utils::SignedNBitMask(kNumberOfFpuRegisters) & |
| ~(Utils::SignedNBitMask(kAbiPreservedFpuRegCount) |
| << kAbiFirstPreservedFpuReg) & |
| ~(1 << FpuTMP); |
| |
| const intptr_t kNumTemps = |
| using_stub ? (Utils::CountOneBits64(kCpuRegistersToPreserve) + |
| Utils::CountOneBits64(kFpuRegistersToPreserve)) |
| : 0; |
| |
| LocationSummary* summary = new (zone) LocationSummary( |
| zone, kNumInputs, kNumTemps, |
| using_stub ? LocationSummary::kCallCalleeSafe : LocationSummary::kCall); |
| summary->set_in(0, Location::RegisterLocation(kInstanceReg)); // Value. |
| summary->set_in(1, |
| Location::RegisterLocation( |
| kInstantiatorTypeArgumentsReg)); // Instant. type args. |
| summary->set_in(2, Location::RegisterLocation( |
| kFunctionTypeArgumentsReg)); // Function type args. |
| |
| // TODO(http://dartbug.com/32787): Use Location::SameAsFirstInput() instead, |
| // once register allocator no longer hits assertion. |
| summary->set_out(0, Location::RegisterLocation(kInstanceReg)); |
| |
| if (using_stub) { |
| // Let's reserve all registers except for the input ones. |
| intptr_t next_temp = 0; |
| for (intptr_t i = 0; i < kNumberOfCpuRegisters; ++i) { |
| const bool should_preserve = ((1 << i) & kCpuRegistersToPreserve) != 0; |
| if (should_preserve) { |
| summary->set_temp(next_temp++, |
| Location::RegisterLocation(static_cast<Register>(i))); |
| } |
| } |
| |
| for (intptr_t i = 0; i < kNumberOfFpuRegisters; i++) { |
| const bool should_preserve = ((1 << i) & kFpuRegistersToPreserve) != 0; |
| if (should_preserve) { |
| summary->set_temp(next_temp++, Location::FpuRegisterLocation( |
| static_cast<FpuRegister>(i))); |
| } |
| } |
| } |
| |
| return summary; |
| } |
| |
| LocationSummary* AssertSubtypeInstr::MakeLocationSummary(Zone* zone, |
| bool opt) const { |
| const intptr_t kNumInputs = 2; |
| const intptr_t kNumTemps = 0; |
| LocationSummary* summary = new (zone) |
| LocationSummary(zone, kNumInputs, kNumTemps, LocationSummary::kCall); |
| summary->set_in(0, Location::RegisterLocation(R2)); // Instant. type args. |
| summary->set_in(1, Location::RegisterLocation(R1)); // Function type args. |
| return summary; |
| } |
| |
| LocationSummary* AssertBooleanInstr::MakeLocationSummary(Zone* zone, |
| bool opt) const { |
| const intptr_t kNumInputs = 1; |
| const intptr_t kNumTemps = 0; |
| LocationSummary* locs = new (zone) |
| LocationSummary(zone, kNumInputs, kNumTemps, LocationSummary::kCall); |
| locs->set_in(0, Location::RegisterLocation(R0)); |
| locs->set_out(0, Location::RegisterLocation(R0)); |
| return locs; |
| } |
| |
| static void EmitAssertBoolean(Register reg, |
| TokenPosition token_pos, |
| intptr_t deopt_id, |
| LocationSummary* locs, |
| FlowGraphCompiler* compiler) { |
| // Check that the type of the value is allowed in conditional context. |
| // Call the runtime if the object is not bool::true or bool::false. |
| ASSERT(locs->always_calls()); |
| Label done; |
| |
| __ CompareObject(reg, Object::null_instance()); |
| __ b(&done, NE); |
| |
| __ Push(reg); // Push the source object. |
| compiler->GenerateRuntimeCall(token_pos, deopt_id, |
| kNonBoolTypeErrorRuntimeEntry, 1, locs); |
| // We should never return here. |
| __ bkpt(0); |
| __ Bind(&done); |
| } |
| |
| void AssertBooleanInstr::EmitNativeCode(FlowGraphCompiler* compiler) { |
| const Register obj = locs()->in(0).reg(); |
| const Register result = locs()->out(0).reg(); |
| |
| EmitAssertBoolean(obj, token_pos(), deopt_id(), locs(), compiler); |
| ASSERT(obj == result); |
| } |
| |
| static Condition TokenKindToSmiCondition(Token::Kind kind) { |
| switch (kind) { |
| case Token::kEQ: |
| return EQ; |
| case Token::kNE: |
| return NE; |
| case Token::kLT: |
| return LT; |
| case Token::kGT: |
| return GT; |
| case Token::kLTE: |
| return LE; |
| case Token::kGTE: |
| return GE; |
| default: |
| UNREACHABLE(); |
| return VS; |
| } |
| } |
| |
| LocationSummary* EqualityCompareInstr::MakeLocationSummary(Zone* zone, |
| bool opt) const { |
| const intptr_t kNumInputs = 2; |
| if (operation_cid() == kMintCid) { |
| const intptr_t kNumTemps = 0; |
| LocationSummary* locs = new (zone) |
| LocationSummary(zone, kNumInputs, kNumTemps, LocationSummary::kNoCall); |
| locs->set_in(0, Location::Pair(Location::RequiresRegister(), |
| Location::RequiresRegister())); |
| locs->set_in(1, Location::Pair(Location::RequiresRegister(), |
| Location::RequiresRegister())); |
| locs->set_out(0, Location::RequiresRegister()); |
| return locs; |
| } |
| if (operation_cid() == kDoubleCid) { |
| const intptr_t kNumTemps = 0; |
| LocationSummary* locs = new (zone) |
| LocationSummary(zone, kNumInputs, kNumTemps, LocationSummary::kNoCall); |
| locs->set_in(0, Location::RequiresFpuRegister()); |
| locs->set_in(1, Location::RequiresFpuRegister()); |
| locs->set_out(0, Location::RequiresRegister()); |
| return locs; |
| } |
| if (operation_cid() == kSmiCid) { |
| const intptr_t kNumTemps = 0; |
| LocationSummary* locs = new (zone) |
| LocationSummary(zone, kNumInputs, kNumTemps, LocationSummary::kNoCall); |
| locs->set_in(0, LocationRegisterOrConstant(left())); |
| // Only one input can be a constant operand. The case of two constant |
| // operands should be handled by constant propagation. |
| locs->set_in(1, locs->in(0).IsConstant() |
| ? Location::RequiresRegister() |
| : LocationRegisterOrConstant(right())); |
| locs->set_out(0, Location::RequiresRegister()); |
| return locs; |
| } |
| UNREACHABLE(); |
| return NULL; |
| } |
| |
| static void LoadValueCid(FlowGraphCompiler* compiler, |
| Register value_cid_reg, |
| Register value_reg, |
| Label* value_is_smi = NULL) { |
| if (value_is_smi == NULL) { |
| __ mov(value_cid_reg, Operand(kSmiCid)); |
| } |
| __ tst(value_reg, Operand(kSmiTagMask)); |
| if (value_is_smi == NULL) { |
| __ LoadClassId(value_cid_reg, value_reg, NE); |
| } else { |
| __ b(value_is_smi, EQ); |
| __ LoadClassId(value_cid_reg, value_reg); |
| } |
| } |
| |
| static Condition FlipCondition(Condition condition) { |
| switch (condition) { |
| case EQ: |
| return EQ; |
| case NE: |
| return NE; |
| case LT: |
| return GT; |
| case LE: |
| return GE; |
| case GT: |
| return LT; |
| case GE: |
| return LE; |
| case CC: |
| return HI; |
| case LS: |
| return CS; |
| case HI: |
| return CC; |
| case CS: |
| return LS; |
| default: |
| UNREACHABLE(); |
| return EQ; |
| } |
| } |
| |
| static void EmitBranchOnCondition(FlowGraphCompiler* compiler, |
| Condition true_condition, |
| BranchLabels labels) { |
| if (labels.fall_through == labels.false_label) { |
| // If the next block is the false successor we will fall through to it. |
| __ b(labels.true_label, true_condition); |
| } else { |
| // If the next block is not the false successor we will branch to it. |
| Condition false_condition = NegateCondition(true_condition); |
| __ b(labels.false_label, false_condition); |
| |
| // Fall through or jump to the true successor. |
| if (labels.fall_through != labels.true_label) { |
| __ b(labels.true_label); |
| } |
| } |
| } |
| |
| static Condition EmitSmiComparisonOp(FlowGraphCompiler* compiler, |
| LocationSummary* locs, |
| Token::Kind kind) { |
| Location left = locs->in(0); |
| Location right = locs->in(1); |
| ASSERT(!left.IsConstant() || !right.IsConstant()); |
| |
| Condition true_condition = TokenKindToSmiCondition(kind); |
| |
| if (left.IsConstant()) { |
| __ CompareObject(right.reg(), left.constant()); |
| true_condition = FlipCondition(true_condition); |
| } else if (right.IsConstant()) { |
| __ CompareObject(left.reg(), right.constant()); |
| } else { |
| __ cmp(left.reg(), Operand(right.reg())); |
| } |
| return true_condition; |
| } |
| |
| static Condition TokenKindToMintCondition(Token::Kind kind) { |
| switch (kind) { |
| case Token::kEQ: |
| return EQ; |
| case Token::kNE: |
| return NE; |
| case Token::kLT: |
| return LT; |
| case Token::kGT: |
| return GT; |
| case Token::kLTE: |
| return LE; |
| case Token::kGTE: |
| return GE; |
| default: |
| UNREACHABLE(); |
| return VS; |
| } |
| } |
| |
| static Condition EmitUnboxedMintEqualityOp(FlowGraphCompiler* compiler, |
| LocationSummary* locs, |
| Token::Kind kind) { |
| ASSERT(Token::IsEqualityOperator(kind)); |
| PairLocation* left_pair = locs->in(0).AsPairLocation(); |
| Register left_lo = left_pair->At(0).reg(); |
| Register left_hi = left_pair->At(1).reg(); |
| PairLocation* right_pair = locs->in(1).AsPairLocation(); |
| Register right_lo = right_pair->At(0).reg(); |
| Register right_hi = right_pair->At(1).reg(); |
| |
| // Compare lower. |
| __ cmp(left_lo, Operand(right_lo)); |
| // Compare upper if lower is equal. |
| __ cmp(left_hi, Operand(right_hi), EQ); |
| return TokenKindToMintCondition(kind); |
| } |
| |
| static Condition EmitUnboxedMintComparisonOp(FlowGraphCompiler* compiler, |
| LocationSummary* locs, |
| Token::Kind kind, |
| BranchLabels labels) { |
| PairLocation* left_pair = locs->in(0).AsPairLocation(); |
| Register left_lo = left_pair->At(0).reg(); |
| Register left_hi = left_pair->At(1).reg(); |
| PairLocation* right_pair = locs->in(1).AsPairLocation(); |
| Register right_lo = right_pair->At(0).reg(); |
| Register right_hi = right_pair->At(1).reg(); |
| |
| // 64-bit comparison. |
| Condition hi_cond, lo_cond; |
| switch (kind) { |
| case Token::kLT: |
| hi_cond = LT; |
| lo_cond = CC; |
| break; |
| case Token::kGT: |
| hi_cond = GT; |
| lo_cond = HI; |
| break; |
| case Token::kLTE: |
| hi_cond = LT; |
| lo_cond = LS; |
| break; |
| case Token::kGTE: |
| hi_cond = GT; |
| lo_cond = CS; |
| break; |
| default: |
| UNREACHABLE(); |
| hi_cond = lo_cond = VS; |
| } |
| // Compare upper halves first. |
| __ cmp(left_hi, Operand(right_hi)); |
| __ b(labels.true_label, hi_cond); |
| __ b(labels.false_label, FlipCondition(hi_cond)); |
| |
| // If higher words are equal, compare lower words. |
| __ cmp(left_lo, Operand(right_lo)); |
| return lo_cond; |
| } |
| |
| static Condition TokenKindToDoubleCondition(Token::Kind kind) { |
| switch (kind) { |
| case Token::kEQ: |
| return EQ; |
| case Token::kNE: |
| return NE; |
| case Token::kLT: |
| return LT; |
| case Token::kGT: |
| return GT; |
| case Token::kLTE: |
| return LE; |
| case Token::kGTE: |
| return GE; |
| default: |
| UNREACHABLE(); |
| return VS; |
| } |
| } |
| |
| static Condition EmitDoubleComparisonOp(FlowGraphCompiler* compiler, |
| LocationSummary* locs, |
| BranchLabels labels, |
| Token::Kind kind) { |
| const QRegister left = locs->in(0).fpu_reg(); |
| const QRegister right = locs->in(1).fpu_reg(); |
| const DRegister dleft = EvenDRegisterOf(left); |
| const DRegister dright = EvenDRegisterOf(right); |
| __ vcmpd(dleft, dright); |
| __ vmstat(); |
| Condition true_condition = TokenKindToDoubleCondition(kind); |
| if (true_condition != NE) { |
| // Special case for NaN comparison. Result is always false unless |
| // relational operator is !=. |
| __ b(labels.false_label, VS); |
| } |
| return true_condition; |
| } |
| |
| Condition EqualityCompareInstr::EmitComparisonCode(FlowGraphCompiler* compiler, |
| BranchLabels labels) { |
| if (operation_cid() == kSmiCid) { |
| return EmitSmiComparisonOp(compiler, locs(), kind()); |
| } else if (operation_cid() == kMintCid) { |
| return EmitUnboxedMintEqualityOp(compiler, locs(), kind()); |
| } else { |
| ASSERT(operation_cid() == kDoubleCid); |
| return EmitDoubleComparisonOp(compiler, locs(), labels, kind()); |
| } |
| } |
| |
| LocationSummary* TestSmiInstr::MakeLocationSummary(Zone* zone, bool opt) const { |
| const intptr_t kNumInputs = 2; |
| const intptr_t kNumTemps = 0; |
| LocationSummary* locs = new (zone) |
| LocationSummary(zone, kNumInputs, kNumTemps, LocationSummary::kNoCall); |
| locs->set_in(0, Location::RequiresRegister()); |
| // Only one input can be a constant operand. The case of two constant |
| // operands should be handled by constant propagation. |
| locs->set_in(1, LocationRegisterOrConstant(right())); |
| return locs; |
| } |
| |
| Condition TestSmiInstr::EmitComparisonCode(FlowGraphCompiler* compiler, |
| BranchLabels labels) { |
| const Register left = locs()->in(0).reg(); |
| Location right = locs()->in(1); |
| if (right.IsConstant()) { |
| ASSERT(compiler::target::IsSmi(right.constant())); |
| const int32_t imm = compiler::target::ToRawSmi(right.constant()); |
| __ TestImmediate(left, imm); |
| } else { |
| __ tst(left, Operand(right.reg())); |
| } |
| Condition true_condition = (kind() == Token::kNE) ? NE : EQ; |
| return true_condition; |
| } |
| |
| LocationSummary* TestCidsInstr::MakeLocationSummary(Zone* zone, |
| bool opt) const { |
| const intptr_t kNumInputs = 1; |
| const intptr_t kNumTemps = 1; |
| LocationSummary* locs = new (zone) |
| LocationSummary(zone, kNumInputs, kNumTemps, LocationSummary::kNoCall); |
| locs->set_in(0, Location::RequiresRegister()); |
| locs->set_temp(0, Location::RequiresRegister()); |
| locs->set_out(0, Location::RequiresRegister()); |
| return locs; |
| } |
| |
| Condition TestCidsInstr::EmitComparisonCode(FlowGraphCompiler* compiler, |
| BranchLabels labels) { |
| ASSERT((kind() == Token::kIS) || (kind() == Token::kISNOT)); |
| const Register val_reg = locs()->in(0).reg(); |
| const Register cid_reg = locs()->temp(0).reg(); |
| |
| Label* deopt = CanDeoptimize() ? compiler->AddDeoptStub( |
| deopt_id(), ICData::kDeoptTestCids, |
| licm_hoisted_ ? ICData::kHoisted : 0) |
| : NULL; |
| |
| const intptr_t true_result = (kind() == Token::kIS) ? 1 : 0; |
| const ZoneGrowableArray<intptr_t>& data = cid_results(); |
| ASSERT(data[0] == kSmiCid); |
| bool result = data[1] == true_result; |
| __ tst(val_reg, Operand(kSmiTagMask)); |
| __ b(result ? labels.true_label : labels.false_label, EQ); |
| __ LoadClassId(cid_reg, val_reg); |
| |
| for (intptr_t i = 2; i < data.length(); i += 2) { |
| const intptr_t test_cid = data[i]; |
| ASSERT(test_cid != kSmiCid); |
| result = data[i + 1] == true_result; |
| __ CompareImmediate(cid_reg, test_cid); |
| __ b(result ? labels.true_label : labels.false_label, EQ); |
| } |
| // No match found, deoptimize or default action. |
| if (deopt == NULL) { |
| // If the cid is not in the list, jump to the opposite label from the cids |
| // that are in the list. These must be all the same (see asserts in the |
| // constructor). |
| Label* target = result ? labels.false_label : labels.true_label; |
| if (target != labels.fall_through) { |
| __ b(target); |
| } |
| } else { |
| __ b(deopt); |
| } |
| // Dummy result as this method already did the jump, there's no need |
| // for the caller to branch on a condition. |
| return kInvalidCondition; |
| } |
| |
| LocationSummary* RelationalOpInstr::MakeLocationSummary(Zone* zone, |
| bool opt) const { |
| const intptr_t kNumInputs = 2; |
| const intptr_t kNumTemps = 0; |
| if (operation_cid() == kMintCid) { |
| const intptr_t kNumTemps = 0; |
| LocationSummary* locs = new (zone) |
| LocationSummary(zone, kNumInputs, kNumTemps, LocationSummary::kNoCall); |
| locs->set_in(0, Location::Pair(Location::RequiresRegister(), |
| Location::RequiresRegister())); |
| locs->set_in(1, Location::Pair(Location::RequiresRegister(), |
| Location::RequiresRegister())); |
| locs->set_out(0, Location::RequiresRegister()); |
| return locs; |
| } |
| if (operation_cid() == kDoubleCid) { |
| LocationSummary* summary = new (zone) |
| LocationSummary(zone, kNumInputs, kNumTemps, LocationSummary::kNoCall); |
| summary->set_in(0, Location::RequiresFpuRegister()); |
| summary->set_in(1, Location::RequiresFpuRegister()); |
| summary->set_out(0, Location::RequiresRegister()); |
| return summary; |
| } |
| ASSERT(operation_cid() == kSmiCid); |
| LocationSummary* summary = new (zone) |
| LocationSummary(zone, kNumInputs, kNumTemps, LocationSummary::kNoCall); |
| summary->set_in(0, LocationRegisterOrConstant(left())); |
| // Only one input can be a constant operand. The case of two constant |
| // operands should be handled by constant propagation. |
| summary->set_in(1, summary->in(0).IsConstant() |
| ? Location::RequiresRegister() |
| : LocationRegisterOrConstant(right())); |
| summary->set_out(0, Location::RequiresRegister()); |
| return summary; |
| } |
| |
| Condition RelationalOpInstr::EmitComparisonCode(FlowGraphCompiler* compiler, |
| BranchLabels labels) { |
| if (operation_cid() == kSmiCid) { |
| return EmitSmiComparisonOp(compiler, locs(), kind()); |
| } else if (operation_cid() == kMintCid) { |
| return EmitUnboxedMintComparisonOp(compiler, locs(), kind(), labels); |
| } else { |
| ASSERT(operation_cid() == kDoubleCid); |
| return EmitDoubleComparisonOp(compiler, locs(), labels, kind()); |
| } |
| } |
| |
| LocationSummary* NativeCallInstr::MakeLocationSummary(Zone* zone, |
| bool opt) const { |
| return MakeCallSummary(zone); |
| } |
| |
| void NativeCallInstr::EmitNativeCode(FlowGraphCompiler* compiler) { |
| SetupNative(); |
| const Register result = locs()->out(0).reg(); |
| |
| // All arguments are already @SP due to preceding PushArgument()s. |
| ASSERT(ArgumentCount() == |
| function().NumParameters() + (function().IsGeneric() ? 1 : 0)); |
| |
| // Push the result place holder initialized to NULL. |
| __ PushObject(Object::null_object()); |
| |
| // Pass a pointer to the first argument in R2. |
| __ add(R2, SP, Operand(ArgumentCount() * compiler::target::kWordSize)); |
| |
| // Compute the effective address. When running under the simulator, |
| // this is a redirection address that forces the simulator to call |
| // into the runtime system. |
| uword entry; |
| const intptr_t argc_tag = NativeArguments::ComputeArgcTag(function()); |
| const Code* stub; |
| if (link_lazily()) { |
| stub = &StubCode::CallBootstrapNative(); |
| entry = NativeEntry::LinkNativeCallEntry(); |
| } else { |
| entry = reinterpret_cast<uword>(native_c_function()); |
| if (is_bootstrap_native()) { |
| stub = &StubCode::CallBootstrapNative(); |
| #if defined(USING_SIMULATOR) |
| entry = Simulator::RedirectExternalReference( |
| entry, Simulator::kBootstrapNativeCall, NativeEntry::kNumArguments); |
| #endif |
| } else if (is_auto_scope()) { |
| // In the case of non bootstrap native methods the CallNativeCFunction |
| // stub generates the redirection address when running under the simulator |
| // and hence we do not change 'entry' here. |
| stub = &StubCode::CallAutoScopeNative(); |
| } else { |
| // In the case of non bootstrap native methods the CallNativeCFunction |
| // stub generates the redirection address when running under the simulator |
| // and hence we do not change 'entry' here. |
| stub = &StubCode::CallNoScopeNative(); |
| } |
| } |
| __ LoadImmediate(R1, argc_tag); |
| ExternalLabel label(entry); |
| __ LoadNativeEntry(R9, &label, |
| link_lazily() |
| ? compiler::ObjectPoolBuilderEntry::kPatchable |
| : compiler::ObjectPoolBuilderEntry::kNotPatchable); |
| if (link_lazily()) { |
| compiler->GeneratePatchableCall(token_pos(), *stub, |
| RawPcDescriptors::kOther, locs()); |
| } else { |
| compiler->GenerateCall(token_pos(), *stub, RawPcDescriptors::kOther, |
| locs()); |
| } |
| __ Pop(result); |
| |
| __ Drop(ArgumentCount()); // Drop the arguments. |
| } |
| |
| void FfiCallInstr::EmitNativeCode(FlowGraphCompiler* compiler) { |
| const Register saved_fp = locs()->temp(0).reg(); |
| const Register branch = locs()->in(TargetAddressIndex()).reg(); |
| |
| // Save frame pointer because we're going to update it when we enter the exit |
| // frame. |
| __ mov(saved_fp, Operand(FPREG)); |
| |
| // Make a space to put the return address. |
| __ PushImmediate(0); |
| |
| // We need to create a dummy "exit frame". It will have a null code object. |
| __ LoadObject(CODE_REG, Object::null_object()); |
| __ set_constant_pool_allowed(false); |
| __ EnterDartFrame(0, /*load_pool_pointer=*/false); |
| |
| // Reserve space for arguments and align frame before entering C++ world. |
| __ ReserveAlignedFrameSpace(compiler::ffi::NumStackSlots(arg_locations_) * |
| kWordSize); |
| |
| FrameRebase rebase(/*old_base=*/FPREG, /*new_base=*/saved_fp, |
| /*stack_delta=*/0); |
| for (intptr_t i = 0, n = NativeArgCount(); i < n; ++i) { |
| const Location origin = rebase.Rebase(locs()->in(i)); |
| const Location target = arg_locations_[i]; |
| NoTemporaryAllocator no_temp; |
| compiler->EmitMove(target, origin, &no_temp); |
| } |
| |
| // We need to copy the return address up into the dummy stack frame so the |
| // stack walker will know which safepoint to use. |
| __ mov(TMP, Operand(PC)); |
| __ str(TMP, Address(FPREG, kSavedCallerPcSlotFromFp * kWordSize)); |
| |
| // For historical reasons, the PC on ARM points 8 bytes past the current |
| // instruction. Therefore we emit the metadata here, 8 bytes (2 instructions) |
| // after the original mov. |
| compiler->EmitCallsiteMetadata(TokenPosition::kNoSource, DeoptId::kNone, |
| RawPcDescriptors::Kind::kOther, locs()); |
| |
| // Update information in the thread object and enter a safepoint. |
| __ TransitionGeneratedToNative(branch, FPREG, saved_fp, |
| locs()->temp(1).reg()); |
| |
| __ blx(branch); |
| |
| // Update information in the thread object and leave the safepoint. |
| __ TransitionNativeToGenerated(saved_fp, locs()->temp(1).reg()); |
| |
| // Restore the global object pool after returning from runtime (old space is |
| // moving, so the GOP could have been relocated). |
| if (FLAG_precompiled_mode && FLAG_use_bare_instructions) { |
| __ ldr(PP, Address(THR, Thread::global_object_pool_offset())); |
| } |
| |
| // Leave dummy exit frame. |
| __ LeaveDartFrame(); |
| __ set_constant_pool_allowed(true); |
| |
| // Instead of returning to the "fake" return address, we just pop it. |
| __ PopRegister(TMP); |
| } |
| |
| void NativeReturnInstr::EmitNativeCode(FlowGraphCompiler* compiler) { |
| __ LeaveDartFrame(); |
| |
| // The dummy return address is in LR, no need to pop it as on Intel. |
| |
| // These can be anything besides the return registers (R0 and R1) and THR |
| // (R10). |
| const Register vm_tag_reg = R2, old_exit_frame_reg = R3, tmp = R4, tmp1 = R5; |
| |
| __ Pop(old_exit_frame_reg); |
| |
| // Restore top_resource. |
| __ Pop(tmp); |
| __ StoreToOffset(kWord, tmp, THR, |
| compiler::target::Thread::top_resource_offset()); |
| |
| __ Pop(vm_tag_reg); |
| |
| // Reset the exit frame info to |
| // old_exit_frame_reg *before* entering the safepoint. |
| __ TransitionGeneratedToNative(vm_tag_reg, old_exit_frame_reg, tmp, tmp1); |
| |
| __ PopNativeCalleeSavedRegisters(); |
| |
| // Leave the entry frame. |
| __ LeaveFrame(1 << LR | 1 << FP); |
| |
| // Leave the dummy frame holding the pushed arguments. |
| __ LeaveFrame(1 << LR | 1 << FP); |
| |
| __ Ret(); |
| |
| // For following blocks. |
| __ set_constant_pool_allowed(true); |
| } |
| |
| void NativeEntryInstr::SaveArgument(FlowGraphCompiler* compiler, |
| Location loc) const { |
| if (loc.IsPairLocation()) { |
| // Save higher-order component first, so bytes are in little-endian layout |
| // overall. |
| for (intptr_t i : {1, 0}) { |
| SaveArgument(compiler, loc.Component(i)); |
| } |
| return; |
| } |
| |
| if (loc.HasStackIndex()) return; |
| |
| if (loc.IsRegister()) { |
| __ Push(loc.reg()); |
| } else if (loc.IsFpuRegister()) { |
| const DRegister src = EvenDRegisterOf(loc.fpu_reg()); |
| __ SubImmediateSetFlags(SPREG, SPREG, 8, AL); |
| __ StoreDToOffset(src, SPREG, 0); |
| } else { |
| UNREACHABLE(); |
| } |
| } |
| |
| void NativeEntryInstr::EmitNativeCode(FlowGraphCompiler* compiler) { |
| if (FLAG_precompiled_mode) { |
| UNREACHABLE(); |
| } |
| |
| // Constant pool cannot be used until we enter the actual Dart frame. |
| __ set_constant_pool_allowed(false); |
| |
| __ Bind(compiler->GetJumpLabel(this)); |
| |
| // Create a dummy frame holding the pushed arguments. This simplifies |
| // NativeReturnInstr::EmitNativeCode. |
| __ EnterFrame((1 << FP) | (1 << LR), 0); |
| |
| // Save the argument registers, in reverse order. |
| for (intptr_t i = argument_locations_->length(); i-- > 0;) { |
| SaveArgument(compiler, argument_locations_->At(i)); |
| } |
| |
| // Enter the entry frame. |
| __ EnterFrame((1 << FP) | (1 << LR), 0); |
| |
| // Save a space for the code object. |
| __ PushImmediate(0); |
| |
| __ PushNativeCalleeSavedRegisters(); |
| |
| // Load the thread object. |
| // TODO(35765): Fix linking issue on AOT. |
| // TOOD(35934): Exclude native callbacks from snapshots. |
| // |
| // Create another frame to align the frame before continuing in "native" code. |
| { |
| __ EnterFrame(1 << FP, 0); |
| __ ReserveAlignedFrameSpace(0); |
| |
| __ LoadImmediate( |
| R0, reinterpret_cast<int64_t>(DLRT_GetThreadForNativeCallback)); |
| __ blx(R0); |
| __ mov(THR, Operand(R0)); |
| |
| __ LeaveFrame(1 << FP); |
| } |
| |
| // Save the current VMTag on the stack. |
| __ LoadFromOffset(kWord, R0, THR, compiler::target::Thread::vm_tag_offset()); |
| __ Push(R0); |
| |
| // Save top resource. |
| const intptr_t top_resource_offset = |
| compiler::target::Thread::top_resource_offset(); |
| __ LoadFromOffset(kWord, R0, THR, top_resource_offset); |
| __ Push(R0); |
| __ LoadImmediate(R0, 0); |
| __ StoreToOffset(kWord, R0, THR, top_resource_offset); |
| |
| // Save top exit frame info. Don't set it to 0 yet -- |
| // TransitionNativeToGenerated will handle that *after* leaving the safepoint. |
| __ LoadFromOffset(kWord, R0, THR, |
| compiler::target::Thread::top_exit_frame_info_offset()); |
| __ Push(R0); |
| |
| __ EmitEntryFrameVerification(R0); |
| |
| __ TransitionNativeToGenerated(/*scratch0=*/R0, /*scratch1=*/R1); |
| |
| // Now that the safepoint has ended, we can touch Dart objects without |
| // handles. |
| |
| // Otherwise we'll clobber the argument sent from the caller. |
| ASSERT(CallingConventions::ArgumentRegisters[0] != TMP && |
| CallingConventions::ArgumentRegisters[0] != TMP2 && |
| CallingConventions::ArgumentRegisters[0] != R1); |
| __ LoadImmediate(CallingConventions::ArgumentRegisters[0], callback_id_); |
| __ LoadFromOffset(kWord, R1, THR, |
| compiler::target::Thread::verify_callback_entry_offset()); |
| __ blx(R1); |
| |
| // Load the code object. |
| __ LoadFromOffset(kWord, R0, THR, |
| compiler::target::Thread::callback_code_offset()); |
| __ LoadFieldFromOffset(kWord, R0, R0, |
| compiler::target::GrowableObjectArray::data_offset()); |
| __ LoadFieldFromOffset(kWord, CODE_REG, R0, |
| compiler::target::Array::data_offset() + |
| callback_id_ * compiler::target::kWordSize); |
| |
| // Put the code object in the reserved slot. |
| __ StoreToOffset(kWord, CODE_REG, FPREG, |
| kPcMarkerSlotFromFp * compiler::target::kWordSize); |
| if (FLAG_precompiled_mode && FLAG_use_bare_instructions) { |
| __ ldr(PP, |
| Address(THR, compiler::target::Thread::global_object_pool_offset())); |
| } else { |
| __ LoadImmediate(PP, 0); // GC safe value into PP. |
| } |
| |
| // Load a GC-safe value for the arguments descriptor (unused but tagged). |
| __ LoadImmediate(ARGS_DESC_REG, 0); |
| |
| // Load a dummy return address which suggests that we are inside of |
| // InvokeDartCodeStub. This is how the stack walker detects an entry frame. |
| __ LoadFromOffset(kWord, LR, THR, |
| compiler::target::Thread::invoke_dart_code_stub_offset()); |
| __ LoadFieldFromOffset(kWord, LR, LR, |
| compiler::target::Code::entry_point_offset()); |
| |
| FunctionEntryInstr::EmitNativeCode(compiler); |
| } |
| |
| LocationSummary* OneByteStringFromCharCodeInstr::MakeLocationSummary( |
| Zone* zone, |
| bool opt) const { |
| const intptr_t kNumInputs = 1; |
| // TODO(fschneider): Allow immediate operands for the char code. |
| return LocationSummary::Make(zone, kNumInputs, Location::RequiresRegister(), |
| LocationSummary::kNoCall); |
| } |
| |
| void OneByteStringFromCharCodeInstr::EmitNativeCode( |
| FlowGraphCompiler* compiler) { |
| ASSERT(compiler->is_optimizing()); |
| const Register char_code = locs()->in(0).reg(); |
| const Register result = locs()->out(0).reg(); |
| |
| __ ldr( |
| result, |
| Address(THR, |
| compiler::target::Thread::predefined_symbols_address_offset())); |
| __ AddImmediate( |
| result, Symbols::kNullCharCodeSymbolOffset * compiler::target::kWordSize); |
| __ ldr(result, Address(result, char_code, LSL, 1)); // Char code is a smi. |
| } |
| |
| LocationSummary* StringToCharCodeInstr::MakeLocationSummary(Zone* zone, |
| bool opt) const { |
| const intptr_t kNumInputs = 1; |
| return LocationSummary::Make(zone, kNumInputs, Location::RequiresRegister(), |
| LocationSummary::kNoCall); |
| } |
| |
| void StringToCharCodeInstr::EmitNativeCode(FlowGraphCompiler* compiler) { |
| ASSERT(cid_ == kOneByteStringCid); |
| const Register str = locs()->in(0).reg(); |
| const Register result = locs()->out(0).reg(); |
| __ ldr(result, FieldAddress(str, compiler::target::String::length_offset())); |
| __ cmp(result, Operand(compiler::target::ToRawSmi(1))); |
| __ LoadImmediate(result, -1, NE); |
| __ ldrb(result, |
| FieldAddress(str, compiler::target::OneByteString::data_offset()), |
| EQ); |
| __ SmiTag(result); |
| } |
| |
| LocationSummary* StringInterpolateInstr::MakeLocationSummary(Zone* zone, |
| bool opt) const { |
| const intptr_t kNumInputs = 1; |
| const intptr_t kNumTemps = 0; |
| LocationSummary* summary = new (zone) |
| LocationSummary(zone, kNumInputs, kNumTemps, LocationSummary::kCall); |
| summary->set_in(0, Location::RegisterLocation(R0)); |
| summary->set_out(0, Location::RegisterLocation(R0)); |
| return summary; |
| } |
| |
| void StringInterpolateInstr::EmitNativeCode(FlowGraphCompiler* compiler) { |
| const Register array = locs()->in(0).reg(); |
| __ Push(array); |
| const int kTypeArgsLen = 0; |
| const int kNumberOfArguments = 1; |
| const Array& kNoArgumentNames = Object::null_array(); |
| ArgumentsInfo args_info(kTypeArgsLen, kNumberOfArguments, kNoArgumentNames); |
| compiler->GenerateStaticCall(deopt_id(), token_pos(), CallFunction(), |
| args_info, locs(), ICData::Handle(), |
| ICData::kStatic); |
| ASSERT(locs()->out(0).reg() == R0); |
| } |
| |
| LocationSummary* LoadUntaggedInstr::MakeLocationSummary(Zone* zone, |
| bool opt) const { |
| const intptr_t kNumInputs = 1; |
| return LocationSummary::Make(zone, kNumInputs, Location::RequiresRegister(), |
| LocationSummary::kNoCall); |
| } |
| |
| void LoadUntaggedInstr::EmitNativeCode(FlowGraphCompiler* compiler) { |
| const Register obj = locs()->in(0).reg(); |
| const Register result = locs()->out(0).reg(); |
| if (object()->definition()->representation() == kUntagged) { |
| __ LoadFromOffset(kWord, result, obj, offset()); |
| } else { |
| ASSERT(object()->definition()->representation() == kTagged); |
| __ LoadFieldFromOffset(kWord, result, obj, offset()); |
| } |
| } |
| |
| DEFINE_BACKEND(StoreUntagged, (NoLocation, Register obj, Register value)) { |
| __ StoreToOffset(kWord, value, obj, instr->offset_from_tagged()); |
| } |
| |
| LocationSummary* LoadClassIdInstr::MakeLocationSummary(Zone* zone, |
| bool opt) const { |
| const intptr_t kNumInputs = 1; |
| return LocationSummary::Make(zone, kNumInputs, Location::RequiresRegister(), |
| LocationSummary::kNoCall); |
| } |
| |
| void LoadClassIdInstr::EmitNativeCode(FlowGraphCompiler* compiler) { |
| const Register object = locs()->in(0).reg(); |
| const Register result = locs()->out(0).reg(); |
| const AbstractType& value_type = *this->object()->Type()->ToAbstractType(); |
| if (CompileType::Smi().IsAssignableTo(value_type) || |
| value_type.IsTypeParameter()) { |
| __ LoadTaggedClassIdMayBeSmi(result, object); |
| } else { |
| __ LoadClassId(result, object); |
| __ SmiTag(result); |
| } |
| } |
| |
| CompileType LoadIndexedInstr::ComputeType() const { |
| switch (class_id_) { |
| case kArrayCid: |
| case kImmutableArrayCid: |
| return CompileType::Dynamic(); |
| |
| case kTypedDataFloat32ArrayCid: |
| case kTypedDataFloat64ArrayCid: |
| return CompileType::FromCid(kDoubleCid); |
| case kTypedDataFloat32x4ArrayCid: |
| return CompileType::FromCid(kFloat32x4Cid); |
| case kTypedDataInt32x4ArrayCid: |
| return CompileType::FromCid(kInt32x4Cid); |
| case kTypedDataFloat64x2ArrayCid: |
| return CompileType::FromCid(kFloat64x2Cid); |
| |
| case kTypedDataInt8ArrayCid: |
| case kTypedDataUint8ArrayCid: |
| case kTypedDataUint8ClampedArrayCid: |
| case kExternalTypedDataUint8ArrayCid: |
| case kExternalTypedDataUint8ClampedArrayCid: |
| case kTypedDataInt16ArrayCid: |
| case kTypedDataUint16ArrayCid: |
| case kOneByteStringCid: |
| case kTwoByteStringCid: |
| case kExternalOneByteStringCid: |
| case kExternalTwoByteStringCid: |
| return CompileType::FromCid(kSmiCid); |
| |
| case kTypedDataInt32ArrayCid: |
| case kTypedDataUint32ArrayCid: |
| case kTypedDataInt64ArrayCid: |
| case kTypedDataUint64ArrayCid: |
| return CompileType::Int(); |
| |
| default: |
| UNREACHABLE(); |
| return CompileType::Dynamic(); |
| } |
| } |
| |
| Representation LoadIndexedInstr::representation() const { |
| switch (class_id_) { |
| case kArrayCid: |
| case kImmutableArrayCid: |
| return kTagged; |
| case kOneByteStringCid: |
| case kTwoByteStringCid: |
| case kTypedDataInt8ArrayCid: |
| case kTypedDataInt16ArrayCid: |
| case kTypedDataUint8ArrayCid: |
| case kTypedDataUint8ClampedArrayCid: |
| case kTypedDataUint16ArrayCid: |
| case kExternalOneByteStringCid: |
| case kExternalTwoByteStringCid: |
| case kExternalTypedDataUint8ArrayCid: |
| case kExternalTypedDataUint8ClampedArrayCid: |
| return kUnboxedIntPtr; |
| case kTypedDataInt32ArrayCid: |
| return kUnboxedInt32; |
| case kTypedDataUint32ArrayCid: |
| return kUnboxedUint32; |
| case kTypedDataInt64ArrayCid: |
| case kTypedDataUint64ArrayCid: |
| return kUnboxedInt64; |
| case kTypedDataFloat32ArrayCid: |
| case kTypedDataFloat64ArrayCid: |
| return kUnboxedDouble; |
| case kTypedDataInt32x4ArrayCid: |
| return kUnboxedInt32x4; |
| case kTypedDataFloat32x4ArrayCid: |
| return kUnboxedFloat32x4; |
| case kTypedDataFloat64x2ArrayCid: |
| return kUnboxedFloat64x2; |
| default: |
| UNREACHABLE(); |
| return kTagged; |
| } |
| } |
| |
| static bool CanBeImmediateIndex(Value* value, |
| intptr_t cid, |
| bool is_external, |
| bool is_load, |
| bool* needs_base) { |
| if ((cid == kTypedDataInt32x4ArrayCid) || |
| (cid == kTypedDataFloat32x4ArrayCid) || |
| (cid == kTypedDataFloat64x2ArrayCid)) { |
| // We are using vldmd/vstmd which do not support offset. |
| return false; |
| } |
| |
| ConstantInstr* constant = value->definition()->AsConstant(); |
| if ((constant == NULL) || !Assembler::IsSafeSmi(constant->value())) { |
| return false; |
| } |
| const int64_t index = compiler::target::SmiValue(constant->value()); |
| const intptr_t scale = compiler::target::Instance::ElementSizeFor(cid); |
| const intptr_t base_offset = |
| (is_external ? 0 : (Instance::DataOffsetFor(cid) - kHeapObjectTag)); |
| const int64_t offset = index * scale + base_offset; |
| if (!Utils::IsAbsoluteUint(12, offset)) { |
| return false; |
| } |
| if (Address::CanHoldImmediateOffset(is_load, cid, offset)) { |
| *needs_base = false; |
| return true; |
| } |
| |
| if (Address::CanHoldImmediateOffset(is_load, cid, offset - base_offset)) { |
| *needs_base = true; |
| return true; |
| } |
| |
| return false; |
| } |
| |
| LocationSummary* LoadIndexedInstr::MakeLocationSummary(Zone* zone, |
| bool opt) const { |
| const bool directly_addressable = |
| aligned() && representation() != kUnboxedInt64; |
| const intptr_t kNumInputs = 2; |
| intptr_t kNumTemps = 0; |
| |
| if (!directly_addressable) { |
| kNumTemps += 1; |
| if (representation() == kUnboxedDouble) { |
| kNumTemps += 1; |
| } |
| } |
| LocationSummary* locs = new (zone) |
| LocationSummary(zone, kNumInputs, kNumTemps, LocationSummary::kNoCall); |
| locs->set_in(0, Location::RequiresRegister()); |
| bool needs_base = false; |
| if (CanBeImmediateIndex(index(), class_id(), IsExternal(), |
| true, // Load. |
| &needs_base)) { |
| // CanBeImmediateIndex must return false for unsafe smis. |
| locs->set_in(1, Location::Constant(index()->definition()->AsConstant())); |
| } else { |
| locs->set_in(1, Location::RequiresRegister()); |
| } |
| if ((representation() == kUnboxedDouble) || |
| (representation() == kUnboxedFloat32x4) || |
| (representation() == kUnboxedInt32x4) || |
| (representation() == kUnboxedFloat64x2)) { |
| if (class_id() == kTypedDataFloat32ArrayCid) { |
| // Need register < Q7 for float operations. |
| // TODO(fschneider): Add a register policy to specify a subset of |
| // registers. |
| locs->set_out(0, Location::FpuRegisterLocation(Q6)); |
| } else { |
| locs->set_out(0, Location::RequiresFpuRegister()); |
| } |
| } else if (representation() == kUnboxedInt64) { |
| ASSERT(class_id() == kTypedDataInt64ArrayCid || |
| class_id() == kTypedDataUint64ArrayCid); |
| locs->set_out(0, Location::Pair(Location::RequiresRegister(), |
| Location::RequiresRegister())); |
| } else { |
| locs->set_out(0, Location::RequiresRegister()); |
| } |
| if (!directly_addressable) { |
| locs->set_temp(0, Location::RequiresRegister()); |
| if (representation() == kUnboxedDouble) { |
| locs->set_temp(1, Location::RequiresRegister()); |
| } |
| } |
| return locs; |
| } |
| |
| void LoadIndexedInstr::EmitNativeCode(FlowGraphCompiler* compiler) { |
| const bool directly_addressable = |
| aligned() && representation() != kUnboxedInt64; |
| // The array register points to the backing store for external arrays. |
| const Register array = locs()->in(0).reg(); |
| const Location index = locs()->in(1); |
| const Register address = |
| directly_addressable ? kNoRegister : locs()->temp(0).reg(); |
| |
| Address element_address(kNoRegister); |
| if (directly_addressable) { |
| element_address = index.IsRegister() |
| ? __ ElementAddressForRegIndex( |
| true, // Load. |
| IsExternal(), class_id(), index_scale(), array, |
| index.reg()) |
| : __ ElementAddressForIntIndex( |
| true, // Load. |
| IsExternal(), class_id(), index_scale(), array, |
| compiler::target::SmiValue(index.constant()), |
| IP); // Temp register. |
| // Warning: element_address may use register IP as base. |
| } else { |
| if (index.IsRegister()) { |
| __ LoadElementAddressForRegIndex(address, |
| true, // Load. |
| IsExternal(), class_id(), index_scale(), |
| array, index.reg()); |
| } else { |
| __ LoadElementAddressForIntIndex( |
| address, |
| true, // Load. |
| IsExternal(), class_id(), index_scale(), array, |
| compiler::target::SmiValue(index.constant())); |
| } |
| } |
| |
| if ((representation() == kUnboxedDouble) || |
| (representation() == kUnboxedFloat32x4) || |
| (representation() == kUnboxedInt32x4) || |
| (representation() == kUnboxedFloat64x2)) { |
| const QRegister result = locs()->out(0).fpu_reg(); |
| const DRegister dresult0 = EvenDRegisterOf(result); |
| switch (class_id()) { |
| case kTypedDataFloat32ArrayCid: |
| // Load single precision float. |
| // vldrs does not support indexed addressing. |
| if (aligned()) { |
| __ vldrs(EvenSRegisterOf(dresult0), element_address); |
| } else { |
| const Register value = locs()->temp(1).reg(); |
| __ LoadWordUnaligned(value, address, TMP); |
| __ vmovsr(EvenSRegisterOf(dresult0), value); |
| } |
| break; |
| case kTypedDataFloat64ArrayCid: |
| // vldrd does not support indexed addressing. |
| if (aligned()) { |
| __ vldrd(dresult0, element_address); |
| } else { |
| const Register value = locs()->temp(1).reg(); |
| __ LoadWordUnaligned(value, address, TMP); |
| __ vmovdr(dresult0, 0, value); |
| __ AddImmediate(address, address, 4); |
| __ LoadWordUnaligned(value, address, TMP); |
| __ vmovdr(dresult0, 1, value); |
| } |
| break; |
| case kTypedDataFloat64x2ArrayCid: |
| case kTypedDataInt32x4ArrayCid: |
| case kTypedDataFloat32x4ArrayCid: |
| ASSERT(element_address.Equals(Address(IP))); |
| ASSERT(aligned()); |
| __ vldmd(IA, IP, dresult0, 2); |
| break; |
| default: |
| UNREACHABLE(); |
| } |
| return; |
| } |
| |
| switch (class_id()) { |
| case kTypedDataInt32ArrayCid: { |
| const Register result = locs()->out(0).reg(); |
| ASSERT(representation() == kUnboxedInt32); |
| if (aligned()) { |
| __ ldr(result, element_address); |
| } else { |
| __ LoadWordUnaligned(result, address, TMP); |
| } |
| break; |
| } |
| case kTypedDataUint32ArrayCid: { |
| const Register result = locs()->out(0).reg(); |
| ASSERT(representation() == kUnboxedUint32); |
| if (aligned()) { |
| __ ldr(result, element_address); |
| } else { |
| __ LoadWordUnaligned(result, address, TMP); |
| } |
| break; |
| } |
| case kTypedDataInt64ArrayCid: |
| case kTypedDataUint64ArrayCid: { |
| ASSERT(representation() == kUnboxedInt64); |
| ASSERT(!directly_addressable); // need to add to register |
| ASSERT(locs()->out(0).IsPairLocation()); |
| PairLocation* result_pair = locs()->out(0).AsPairLocation(); |
| const Register result_lo = result_pair->At(0).reg(); |
| const Register result_hi = result_pair->At(1).reg(); |
| if (aligned()) { |
| __ ldr(result_lo, Address(address)); |
| __ ldr(result_hi, Address(address, compiler::target::kWordSize)); |
| } else { |
| __ LoadWordUnaligned(result_lo, address, TMP); |
| __ AddImmediate(address, address, compiler::target::kWordSize); |
| __ LoadWordUnaligned(result_hi, address, TMP); |
| } |
| break; |
| } |
| case kTypedDataInt8ArrayCid: { |
| const Register result = locs()->out(0).reg(); |
| ASSERT(representation() == kUnboxedIntPtr); |
| ASSERT(index_scale() == 1); |
| ASSERT(aligned()); |
| __ ldrsb(result, element_address); |
| break; |
| } |
| case kTypedDataUint8ArrayCid: |
| case kTypedDataUint8ClampedArrayCid: |
| case kExternalTypedDataUint8ArrayCid: |
| case kExternalTypedDataUint8ClampedArrayCid: |
| case kOneByteStringCid: |
| case kExternalOneByteStringCid: { |
| const Register result = locs()->out(0).reg(); |
| ASSERT(representation() == kUnboxedIntPtr); |
| ASSERT(index_scale() == 1); |
| ASSERT(aligned()); |
| __ ldrb(result, element_address); |
| break; |
| } |
| case kTypedDataInt16ArrayCid: { |
| const Register result = locs()->out(0).reg(); |
| ASSERT(representation() == kUnboxedIntPtr); |
| if (aligned()) { |
| __ ldrsh(result, element_address); |
| } else { |
| __ LoadHalfWordUnaligned(result, address, TMP); |
| } |
| break; |
| } |
| case kTypedDataUint16ArrayCid: |
| case kTwoByteStringCid: |
| case kExternalTwoByteStringCid: { |
| const Register result = locs()->out(0).reg(); |
| ASSERT(representation() == kUnboxedIntPtr); |
| if (aligned()) { |
| __ ldrh(result, element_address); |
| } else { |
| __ LoadHalfWordUnsignedUnaligned(result, address, TMP); |
| } |
| break; |
| } |
| default: { |
| const Register result = locs()->out(0).reg(); |
| ASSERT(representation() == kTagged); |
| ASSERT((class_id() == kArrayCid) || (class_id() == kImmutableArrayCid)); |
| __ ldr(result, element_address); |
| break; |
| } |
| } |
| } |
| |
| Representation StoreIndexedInstr::RequiredInputRepresentation( |
| intptr_t idx) const { |
| // Array can be a Dart object or a pointer to external data. |
| if (idx == 0) return kNoRepresentation; // Flexible input representation. |
| if (idx == 1) return kTagged; // Index is a smi. |
| ASSERT(idx == 2); |
| switch (class_id_) { |
| case kArrayCid: |
| return kTagged; |
| case kOneByteStringCid: |
| case kTypedDataInt8ArrayCid: |
| case kTypedDataInt16ArrayCid: |
| case kTypedDataUint8ArrayCid: |
| case kTypedDataUint8ClampedArrayCid: |
| case kTypedDataUint16ArrayCid: |
| case kExternalTypedDataUint8ArrayCid: |
| case kExternalTypedDataUint8ClampedArrayCid: |
| return kUnboxedIntPtr; |
| case kTypedDataInt32ArrayCid: |
| return kUnboxedInt32; |
| case kTypedDataUint32ArrayCid: |
| return kUnboxedUint32; |
| case kTypedDataInt64ArrayCid: |
| case kTypedDataUint64ArrayCid: |
| return kUnboxedInt64; |
| case kTypedDataFloat32ArrayCid: |
| case kTypedDataFloat64ArrayCid: |
| return kUnboxedDouble; |
| case kTypedDataFloat32x4ArrayCid: |
| return kUnboxedFloat32x4; |
| case kTypedDataInt32x4ArrayCid: |
| return kUnboxedInt32x4; |
| case kTypedDataFloat64x2ArrayCid: |
| return kUnboxedFloat64x2; |
| default: |
| UNREACHABLE(); |
| return kTagged; |
| } |
| } |
| |
| LocationSummary* StoreIndexedInstr::MakeLocationSummary(Zone* zone, |
| bool opt) const { |
| const bool directly_addressable = |
| aligned() && class_id() != kTypedDataInt64ArrayCid && |
| class_id() != kTypedDataUint64ArrayCid && class_id() != kArrayCid; |
| const intptr_t kNumInputs = 3; |
| LocationSummary* locs; |
| |
| bool needs_base = false; |
| intptr_t kNumTemps = 0; |
| if (CanBeImmediateIndex(index(), class_id(), IsExternal(), |
| false, // Store. |
| &needs_base)) { |
| if (!directly_addressable) { |
| kNumTemps += 2; |
| } else if (needs_base) { |
| kNumTemps += 1; |
| } |
| |
| locs = new (zone) |
| LocationSummary(zone, kNumInputs, kNumTemps, LocationSummary::kNoCall); |
| |
| // CanBeImmediateIndex must return false for unsafe smis. |
| locs->set_in(1, Location::Constant(index()->definition()->AsConstant())); |
| } else { |
| if (!directly_addressable) { |
| kNumTemps += 2; |
| } |
| |
| locs = new (zone) |
| LocationSummary(zone, kNumInputs, kNumTemps, LocationSummary::kNoCall); |
| |
| locs->set_in(1, Location::WritableRegister()); |
| } |
| locs->set_in(0, Location::RequiresRegister()); |
| for (intptr_t i = 0; i < kNumTemps; i++) { |
| locs->set_temp(i, Location::RequiresRegister()); |
| } |
| |
| switch (class_id()) { |
| case kArrayCid: |
| locs->set_in(2, ShouldEmitStoreBarrier() |
| ? Location::RegisterLocation(kWriteBarrierValueReg) |
| : LocationRegisterOrConstant(value())); |
| if (ShouldEmitStoreBarrier()) { |
| locs->set_in(0, Location::RegisterLocation(kWriteBarrierObjectReg)); |
| locs->set_temp(0, Location::RegisterLocation(kWriteBarrierSlotReg)); |
| } |
| break; |
| case kExternalTypedDataUint8ArrayCid: |
| case kExternalTypedDataUint8ClampedArrayCid: |
| case kTypedDataInt8ArrayCid: |
| case kTypedDataUint8ArrayCid: |
| case kTypedDataUint8ClampedArrayCid: |
| case kOneByteStringCid: |
| case kTypedDataInt16ArrayCid: |
| case kTypedDataUint16ArrayCid: |
| case kTypedDataInt32ArrayCid: |
| case kTypedDataUint32ArrayCid: |
| locs->set_in(2, Location::RequiresRegister()); |
| break; |
| case kTypedDataInt64ArrayCid: |
| case kTypedDataUint64ArrayCid: |
| locs->set_in(2, Location::Pair(Location::RequiresRegister(), |
| Location::RequiresRegister())); |
| break; |
| case kTypedDataFloat32ArrayCid: |
| // Need low register (< Q7). |
| locs->set_in(2, Location::FpuRegisterLocation(Q6)); |
| break; |
| case kTypedDataFloat64ArrayCid: // TODO(srdjan): Support Float64 constants. |
| case kTypedDataInt32x4ArrayCid: |
| case kTypedDataFloat32x4ArrayCid: |
| case kTypedDataFloat64x2ArrayCid: |
| locs->set_in(2, Location::RequiresFpuRegister()); |
| break; |
| default: |
| UNREACHABLE(); |
| return NULL; |
| } |
| |
| return locs; |
| } |
| |
| void StoreIndexedInstr::EmitNativeCode(FlowGraphCompiler* compiler) { |
| const bool directly_addressable = |
| aligned() && class_id() != kTypedDataInt64ArrayCid && |
| class_id() != kTypedDataUint64ArrayCid && class_id() != kArrayCid; |
| // The array register points to the backing store for external arrays. |
| const Register array = locs()->in(0).reg(); |
| const Location index = locs()->in(1); |
| const Register temp = |
| (locs()->temp_count() > 0) ? locs()->temp(0).reg() : kNoRegister; |
| const Register temp2 = |
| (locs()->temp_count() > 1) ? locs()->temp(1).reg() : kNoRegister; |
| |
| Address element_address(kNoRegister); |
| if (directly_addressable) { |
| element_address = |
| index.IsRegister() |
| ? __ ElementAddressForRegIndex(false, // Store. |
| IsExternal(), class_id(), |
| index_scale(), array, |
| index.reg()) |
| : __ ElementAddressForIntIndex( |
| false, // Store. |
| IsExternal(), class_id(), index_scale(), array, |
| compiler::target::SmiValue(index.constant()), temp); |
| } else { |
| if (index.IsRegister()) { |
| __ LoadElementAddressForRegIndex(temp, |
| false, // Store. |
| IsExternal(), class_id(), index_scale(), |
| array, index.reg()); |
| } else { |
| __ LoadElementAddressForIntIndex( |
| temp, |
| false, // Store. |
| IsExternal(), class_id(), index_scale(), array, |
| compiler::target::SmiValue(index.constant())); |
| } |
| } |
| |
| switch (class_id()) { |
| case kArrayCid: |
| if (ShouldEmitStoreBarrier()) { |
| const Register value = locs()->in(2).reg(); |
| __ StoreIntoArray(array, temp, value, CanValueBeSmi(), |
| /*lr_reserved=*/!compiler->intrinsic_mode()); |
| } else if (locs()->in(2).IsConstant()) { |
| const Object& constant = locs()->in(2).constant(); |
| __ StoreIntoObjectNoBarrier(array, Address(temp), constant); |
| } else { |
| const Register value = locs()->in(2).reg(); |
| __ StoreIntoObjectNoBarrier(array, Address(temp), value); |
| } |
| break; |
| case kTypedDataInt8ArrayCid: |
| case kTypedDataUint8ArrayCid: |
| case kExternalTypedDataUint8ArrayCid: |
| case kOneByteStringCid: { |
| ASSERT(RequiredInputRepresentation(2) == kUnboxedIntPtr); |
| if (locs()->in(2).IsConstant()) { |
| __ LoadImmediate(IP, |
| compiler::target::SmiValue(locs()->in(2).constant())); |
| __ strb(IP, element_address); |
| } else { |
| const Register value = locs()->in(2).reg(); |
| __ strb(value, element_address); |
| } |
| break; |
| } |
| case kTypedDataUint8ClampedArrayCid: |
| case kExternalTypedDataUint8ClampedArrayCid: { |
| ASSERT(RequiredInputRepresentation(2) == kUnboxedIntPtr); |
| if (locs()->in(2).IsConstant()) { |
| intptr_t value = compiler::target::SmiValue(locs()->in(2).constant()); |
| // Clamp to 0x0 or 0xFF respectively. |
| if (value > 0xFF) { |
| value = 0xFF; |
| } else if (value < 0) { |
| value = 0; |
| } |
| __ LoadImmediate(IP, static_cast<int8_t>(value)); |
| __ strb(IP, element_address); |
| } else { |
| const Register value = locs()->in(2).reg(); |
| // Clamp to 0x00 or 0xFF respectively. |
| __ LoadImmediate(IP, 0xFF); |
| __ cmp(value, Operand(IP)); // Compare Smi value and smi 0xFF. |
| __ mov(IP, Operand(0), LE); // IP = value <= 0xFF ? 0 : 0xFF. |
| __ mov(IP, Operand(value), LS); // IP = value in range ? value : IP. |
| __ strb(IP, element_address); |
| } |
| break; |
| } |
| case kTypedDataInt16ArrayCid: |
| case kTypedDataUint16ArrayCid: { |
| ASSERT(RequiredInputRepresentation(2) == kUnboxedIntPtr); |
| const Register value = locs()->in(2).reg(); |
| if (aligned()) { |
| __ strh(value, element_address); |
| } else { |
| __ StoreHalfWordUnaligned(value, temp, temp2); |
| } |
| break; |
| } |
| case kTypedDataInt32ArrayCid: |
| case kTypedDataUint32ArrayCid: { |
| const Register value = locs()->in(2).reg(); |
| if (aligned()) { |
| __ str(value, element_address); |
| } else { |
| __ StoreWordUnaligned(value, temp, temp2); |
| } |
| break; |
| } |
| case kTypedDataInt64ArrayCid: |
| case kTypedDataUint64ArrayCid: { |
| ASSERT(!directly_addressable); // need to add to register |
| ASSERT(locs()->in(2).IsPairLocation()); |
| PairLocation* value_pair = locs()->in(2).AsPairLocation(); |
| Register value_lo = value_pair->At(0).reg(); |
| Register value_hi = value_pair->At(1).reg(); |
| if (aligned()) { |
| __ str(value_lo, Address(temp)); |
| __ str(value_hi, Address(temp, compiler::target::kWordSize)); |
| } else { |
| __ StoreWordUnaligned(value_lo, temp, temp2); |
| __ AddImmediate(temp, temp, compiler::target::kWordSize); |
| __ StoreWordUnaligned(value_hi, temp, temp2); |
| } |
| break; |
| } |
| case kTypedDataFloat32ArrayCid: { |
| const SRegister value_reg = |
| EvenSRegisterOf(EvenDRegisterOf(locs()->in(2).fpu_reg())); |
| if (aligned()) { |
| __ vstrs(value_reg, element_address); |
| } else { |
| const Register address = temp; |
| const Register value = temp2; |
| __ vmovrs(value, value_reg); |
| __ StoreWordUnaligned(value, address, TMP); |
| } |
| break; |
| } |
| case kTypedDataFloat64ArrayCid: { |
| const DRegister value_reg = EvenDRegisterOf(locs()->in(2).fpu_reg()); |
| if (aligned()) { |
| __ vstrd(value_reg, element_address); |
| } else { |
| const Register address = temp; |
| const Register value = temp2; |
| __ vmovrs(value, EvenSRegisterOf(value_reg)); |
| __ StoreWordUnaligned(value, address, TMP); |
| __ AddImmediate(address, address, 4); |
| __ vmovrs(value, OddSRegisterOf(value_reg)); |
| __ StoreWordUnaligned(value, address, TMP); |
| } |
| break; |
| } |
| case kTypedDataFloat64x2ArrayCid: |
| case kTypedDataInt32x4ArrayCid: |
| case kTypedDataFloat32x4ArrayCid: { |
| ASSERT(element_address.Equals(Address(index.reg()))); |
| ASSERT(aligned()); |
| const DRegister value_reg = EvenDRegisterOf(locs()->in(2).fpu_reg()); |
| __ vstmd(IA, index.reg(), value_reg, 2); |
| break; |
| } |
| default: |
| UNREACHABLE(); |
| } |
| } |
| |
| LocationSummary* GuardFieldClassInstr::MakeLocationSummary(Zone* zone, |
| bool opt) const { |
| const intptr_t kNumInputs = 1; |
| |
| const intptr_t value_cid = value()->Type()->ToCid(); |
| const intptr_t field_cid = field().guarded_cid(); |
| |
| const bool emit_full_guard = !opt || (field_cid == kIllegalCid); |
| |
| const bool needs_value_cid_temp_reg = |
| emit_full_guard || ((value_cid == kDynamicCid) && (field_cid != kSmiCid)); |
| |
| const bool needs_field_temp_reg = emit_full_guard; |
| |
| intptr_t num_temps = 0; |
| if (needs_value_cid_temp_reg) { |
| num_temps++; |
| } |
| if (needs_field_temp_reg) { |
| num_temps++; |
| } |
| |
| LocationSummary* summary = new (zone) |
| LocationSummary(zone, kNumInputs, num_temps, LocationSummary::kNoCall); |
| summary->set_in(0, Location::RequiresRegister()); |
| |
| for (intptr_t i = 0; i < num_temps; i++) { |
| summary->set_temp(i, Location::RequiresRegister()); |
| } |
| |
| return summary; |
| } |
| |
| void GuardFieldClassInstr::EmitNativeCode(FlowGraphCompiler* compiler) { |
| ASSERT(sizeof(classid_t) == kInt16Size); |
| |
| const intptr_t value_cid = value()->Type()->ToCid(); |
| const intptr_t field_cid = field().guarded_cid(); |
| const intptr_t nullability = field().is_nullable() ? kNullCid : kIllegalCid; |
| |
| if (field_cid == kDynamicCid) { |
| return; // Nothing to emit. |
| } |
| |
| const bool emit_full_guard = |
| !compiler->is_optimizing() || (field_cid == kIllegalCid); |
| |
| const bool needs_value_cid_temp_reg = |
| emit_full_guard || ((value_cid == kDynamicCid) && (field_cid != kSmiCid)); |
| |
| const bool needs_field_temp_reg = emit_full_guard; |
| |
| const Register value_reg = locs()->in(0).reg(); |
| |
| const Register value_cid_reg = |
| needs_value_cid_temp_reg ? locs()->temp(0).reg() : kNoRegister; |
| |
| const Register field_reg = needs_field_temp_reg |
| ? locs()->temp(locs()->temp_count() - 1).reg() |
| : kNoRegister; |
| |
| Label ok, fail_label; |
| |
| Label* deopt = |
| compiler->is_optimizing() |
| ? compiler->AddDeoptStub(deopt_id(), ICData::kDeoptGuardField) |
| : NULL; |
| |
| Label* fail = (deopt != NULL) ? deopt : &fail_label; |
| |
| if (emit_full_guard) { |
| __ LoadObject(field_reg, Field::ZoneHandle(field().Original())); |
| |
| FieldAddress field_cid_operand( |
| field_reg, compiler::target::Field::guarded_cid_offset()); |
| FieldAddress field_nullability_operand( |
| field_reg, compiler::target::Field::is_nullable_offset()); |
| |
| if (value_cid == kDynamicCid) { |
| LoadValueCid(compiler, value_cid_reg, value_reg); |
| __ ldrh(IP, field_cid_operand); |
| __ cmp(value_cid_reg, Operand(IP)); |
| __ b(&ok, EQ); |
| __ ldrh(IP, field_nullability_operand); |
| __ cmp(value_cid_reg, Operand(IP)); |
| } else if (value_cid == kNullCid) { |
| __ ldrh(value_cid_reg, field_nullability_operand); |
| __ CompareImmediate(value_cid_reg, value_cid); |
| } else { |
| __ ldrh(value_cid_reg, field_cid_operand); |
| __ CompareImmediate(value_cid_reg, value_cid); |
| } |
| __ b(&ok, EQ); |
| |
| // Check if the tracked state of the guarded field can be initialized |
| // inline. If the field needs length check we fall through to runtime |
| // which is responsible for computing offset of the length field |
| // based on the class id. |
| // Length guard will be emitted separately when needed via GuardFieldLength |
| // instruction after GuardFieldClass. |
| if (!field().needs_length_check()) { |
| // Uninitialized field can be handled inline. Check if the |
| // field is still unitialized. |
| __ ldrh(IP, field_cid_operand); |
| __ CompareImmediate(IP, kIllegalCid); |
| __ b(fail, NE); |
| |
| if (value_cid == kDynamicCid) { |
| __ strh(value_cid_reg, field_cid_operand); |
| __ strh(value_cid_reg, field_nullability_operand); |
| } else { |
| __ LoadImmediate(IP, value_cid); |
| __ strh(IP, field_cid_operand); |
| __ strh(IP, field_nullability_operand); |
| } |
| |
| __ b(&ok); |
| } |
| |
| if (deopt == NULL) { |
| ASSERT(!compiler->is_optimizing()); |
| __ Bind(fail); |
| |
| __ ldrh(IP, FieldAddress(field_reg, |
| compiler::target::Field::guarded_cid_offset())); |
| __ CompareImmediate(IP, kDynamicCid); |
| __ b(&ok, EQ); |
| |
| __ Push(field_reg); |
| __ Push(value_reg); |
| __ CallRuntime(kUpdateFieldCidRuntimeEntry, 2); |
| __ Drop(2); // Drop the field and the value. |
| } else { |
| __ b(fail); |
| } |
| } else { |
| ASSERT(compiler->is_optimizing()); |
| ASSERT(deopt != NULL); |
| |
| // Field guard class has been initialized and is known. |
| if (value_cid == kDynamicCid) { |
| // Field's guarded class id is fixed by value's class id is not known. |
| __ tst(value_reg, Operand(kSmiTagMask)); |
| |
| if (field_cid != kSmiCid) { |
| __ b(fail, EQ); |
| __ LoadClassId(value_cid_reg, value_reg); |
| __ CompareImmediate(value_cid_reg, field_cid); |
| } |
| |
| if (field().is_nullable() && (field_cid != kNullCid)) { |
| __ b(&ok, EQ); |
| if (field_cid != kSmiCid) { |
| __ CompareImmediate(value_cid_reg, kNullCid); |
| } else { |
| __ CompareObject(value_reg, Object::null_object()); |
| } |
| } |
| __ b(fail, NE); |
| } else { |
| // Both value's and field's class id is known. |
| ASSERT((value_cid != field_cid) && (value_cid != nullability)); |
| __ b(fail); |
| } |
| } |
| __ Bind(&ok); |
| } |
| |
| LocationSummary* GuardFieldLengthInstr::MakeLocationSummary(Zone* zone, |
| bool opt) const { |
| const intptr_t kNumInputs = 1; |
| if (!opt || (field().guarded_list_length() == Field::kUnknownFixedLength)) { |
| const intptr_t kNumTemps = 3; |
| LocationSummary* summary = new (zone) |
| LocationSummary(zone, kNumInputs, kNumTemps, LocationSummary::kNoCall); |
| summary->set_in(0, Location::RequiresRegister()); |
| // We need temporaries for field object, length offset and expected length. |
| summary->set_temp(0, Location::RequiresRegister()); |
| summary->set_temp(1, Location::RequiresRegister()); |
| summary->set_temp(2, Location::RequiresRegister()); |
| return summary; |
| } else { |
| // TODO(vegorov): can use TMP when length is small enough to fit into |
| // immediate. |
| const intptr_t kNumTemps = 1; |
| LocationSummary* summary = new (zone) |
| LocationSummary(zone, kNumInputs, kNumTemps, LocationSummary::kNoCall); |
| summary->set_in(0, Location::RequiresRegister()); |
| summary->set_temp(0, Location::RequiresRegister()); |
| return summary; |
| } |
| UNREACHABLE(); |
| } |
| |
| void GuardFieldLengthInstr::EmitNativeCode(FlowGraphCompiler* compiler) { |
| if (field().guarded_list_length() == Field::kNoFixedLength) { |
| return; // Nothing to emit. |
| } |
| |
| Label* deopt = |
| compiler->is_optimizing() |
| ? compiler->AddDeoptStub(deopt_id(), ICData::kDeoptGuardField) |
| : NULL; |
| |
| const Register value_reg = locs()->in(0).reg(); |
| |
| if (!compiler->is_optimizing() || |
| (field().guarded_list_length() == Field::kUnknownFixedLength)) { |
| const Register field_reg = locs()->temp(0).reg(); |
| const Register offset_reg = locs()->temp(1).reg(); |
| const Register length_reg = locs()->temp(2).reg(); |
| |
| Label ok; |
| |
| __ LoadObject(field_reg, Field::ZoneHandle(field().Original())); |
| |
| __ ldrsb(offset_reg, |
| FieldAddress(field_reg, |
| compiler::target::Field:: |
| guarded_list_length_in_object_offset_offset())); |
| __ ldr(length_reg, |
| FieldAddress(field_reg, |
| compiler::target::Field::guarded_list_length_offset())); |
| |
| __ tst(offset_reg, Operand(offset_reg)); |
| __ b(&ok, MI); |
| |
| // Load the length from the value. GuardFieldClass already verified that |
| // value's class matches guarded class id of the field. |
| // offset_reg contains offset already corrected by -kHeapObjectTag that is |
| // why we use Address instead of FieldAddress. |
| __ ldr(IP, Address(value_reg, offset_reg)); |
| __ cmp(length_reg, Operand(IP)); |
| |
| if (deopt == NULL) { |
| __ b(&ok, EQ); |
| |
| __ Push(field_reg); |
| __ Push(value_reg); |
| __ CallRuntime(kUpdateFieldCidRuntimeEntry, 2); |
| __ Drop(2); // Drop the field and the value. |
| } else { |
| __ b(deopt, NE); |
| } |
| |
| __ Bind(&ok); |
| } else { |
| ASSERT(compiler->is_optimizing()); |
| ASSERT(field().guarded_list_length() >= 0); |
| ASSERT(field().guarded_list_length_in_object_offset() != |
| Field::kUnknownLengthOffset); |
| |
| const Register length_reg = locs()->temp(0).reg(); |
| |
| __ ldr(length_reg, |
| FieldAddress(value_reg, |
| field().guarded_list_length_in_object_offset())); |
| __ CompareImmediate( |
| length_reg, compiler::target::ToRawSmi(field().guarded_list_length())); |
| __ b(deopt, NE); |
| } |
| } |
| |
| DEFINE_UNIMPLEMENTED_INSTRUCTION(GuardFieldTypeInstr) |
| DEFINE_UNIMPLEMENTED_INSTRUCTION(CheckConditionInstr) |
| |
| class BoxAllocationSlowPath : public TemplateSlowPathCode<Instruction> { |
| public: |
| BoxAllocationSlowPath(Instruction* instruction, |
| const Class& cls, |
| Register result) |
| : TemplateSlowPathCode(instruction), cls_(cls), result_(result) {} |
| |
| virtual void EmitNativeCode(FlowGraphCompiler* compiler) { |
| if (Assembler::EmittingComments()) { |
| __ Comment("%s slow path allocation of %s", instruction()->DebugName(), |
| String::Handle(cls_.ScrubbedName()).ToCString()); |
| } |
| __ Bind(entry_label()); |
| const Code& stub = Code::ZoneHandle( |
| compiler->zone(), StubCode::GetAllocationStubForClass(cls_)); |
| |
| LocationSummary* locs = instruction()->locs(); |
| |
| locs->live_registers()->Remove(Location::RegisterLocation(result_)); |
| |
| compiler->SaveLiveRegisters(locs); |
| compiler->GenerateCall(TokenPosition::kNoSource, // No token position. |
| stub, RawPcDescriptors::kOther, locs); |
| __ MoveRegister(result_, R0); |
| compiler->RestoreLiveRegisters(locs); |
| __ b(exit_label()); |
| } |
| |
| static void Allocate(FlowGraphCompiler* compiler, |
| Instruction* instruction, |
| const Class& cls, |
| Register result, |
| Register temp) { |
| if (compiler->intrinsic_mode()) { |
| __ TryAllocate(cls, compiler->intrinsic_slow_path_label(), result, temp); |
| } else { |
| BoxAllocationSlowPath* slow_path = |
| new BoxAllocationSlowPath(instruction, cls, result); |
| compiler->AddSlowPathCode(slow_path); |
| |
| __ TryAllocate(cls, slow_path->entry_label(), result, temp); |
| __ Bind(slow_path->exit_label()); |
| } |
| } |
| |
| private: |
| const Class& cls_; |
| const Register result_; |
| }; |
| |
| LocationSummary* LoadCodeUnitsInstr::MakeLocationSummary(Zone* zone, |
| bool opt) const { |
| const bool might_box = (representation() == kTagged) && !can_pack_into_smi(); |
| const intptr_t kNumInputs = 2; |
| const intptr_t kNumTemps = might_box ? 1 : 0; |
| LocationSummary* summary = new (zone) LocationSummary( |
| zone, kNumInputs, kNumTemps, |
| might_box ? LocationSummary::kCallOnSlowPath : LocationSummary::kNoCall); |
| summary->set_in(0, Location::RequiresRegister()); |
| summary->set_in(1, Location::RequiresRegister()); |
| |
| if (might_box) { |
| summary->set_temp(0, Location::RequiresRegister()); |
| } |
| |
| if (representation() == kUnboxedInt64) { |
| summary->set_out(0, Location::Pair(Location::RequiresRegister(), |
| Location::RequiresRegister())); |
| } else { |
| ASSERT(representation() == kTagged); |
| summary->set_out(0, Location::RequiresRegister()); |
| } |
| |
| return summary; |
| } |
| |
| void LoadCodeUnitsInstr::EmitNativeCode(FlowGraphCompiler* compiler) { |
| // The string register points to the backing store for external strings. |
| const Register str = locs()->in(0).reg(); |
| const Location index = locs()->in(1); |
| |
| Address element_address = __ ElementAddressForRegIndex( |
| true, IsExternal(), class_id(), index_scale(), str, index.reg()); |
| // Warning: element_address may use register IP as base. |
| |
| if (representation() == kUnboxedInt64) { |
| ASSERT(compiler->is_optimizing()); |
| ASSERT(locs()->out(0).IsPairLocation()); |
| PairLocation* result_pair = locs()->out(0).AsPairLocation(); |
| Register result1 = result_pair->At(0).reg(); |
| Register result2 = result_pair->At(1).reg(); |
| switch (class_id()) { |
| case kOneByteStringCid: |
| case kExternalOneByteStringCid: |
| ASSERT(element_count() == 4); |
| __ ldr(result1, element_address); |
| __ eor(result2, result2, Operand(result2)); |
| break; |
| case kTwoByteStringCid: |
| case kExternalTwoByteStringCid: |
| ASSERT(element_count() == 2); |
| __ ldr(result1, element_address); |
| __ eor(result2, result2, Operand(result2)); |
| break; |
| default: |
| UNREACHABLE(); |
| } |
| } else { |
| ASSERT(representation() == kTagged); |
| Register result = locs()->out(0).reg(); |
| switch (class_id()) { |
| case kOneByteStringCid: |
| case kExternalOneByteStringCid: |
| switch (element_count()) { |
| case 1: |
| __ ldrb(result, element_address); |
| break; |
| case 2: |
| __ ldrh(result, element_address); |
| break; |
| case 4: |
| __ ldr(result, element_address); |
| break; |
| default: |
| UNREACHABLE(); |
| } |
| break; |
| case kTwoByteStringCid: |
| case kExternalTwoByteStringCid: |
| switch (element_count()) { |
| case 1: |
| __ ldrh(result, element_address); |
| break; |
| case 2: |
| __ ldr(result, element_address); |
| break; |
| default: |
| UNREACHABLE(); |
| } |
| break; |
| default: |
| UNREACHABLE(); |
| break; |
| } |
| if (can_pack_into_smi()) { |
| __ SmiTag(result); |
| } else { |
| // If the value cannot fit in a smi then allocate a mint box for it. |
| Register value = locs()->temp(0).reg(); |
| Register temp = locs()->temp(1).reg(); |
| // Value register needs to be manually preserved on allocation slow-path. |
| locs()->live_registers()->Add(locs()->temp(0), kUnboxedInt32); |
| |
| ASSERT(result != value); |
| __ MoveRegister(value, result); |
| __ SmiTag(result); |
| |
| Label done; |
| __ TestImmediate(value, 0xC0000000); |
| __ b(&done, EQ); |
| BoxAllocationSlowPath::Allocate(compiler, this, compiler->mint_class(), |
| result, temp); |
| __ eor(temp, temp, Operand(temp)); |
| __ StoreToOffset(kWord, value, result, |
| compiler::target::Mint::value_offset() - kHeapObjectTag); |
| __ StoreToOffset(kWord, temp, result, |
| compiler::target::Mint::value_offset() - kHeapObjectTag + |
| compiler::target::kWordSize); |
| __ Bind(&done); |
| } |
| } |
| } |
| |
| LocationSummary* StoreInstanceFieldInstr::MakeLocationSummary(Zone* zone, |
| bool opt) const { |
| const intptr_t kNumInputs = 2; |
| const intptr_t kNumTemps = |
| ((IsUnboxedStore() && opt) ? 2 : ((IsPotentialUnboxedStore()) ? 3 : 0)); |
| LocationSummary* summary = new (zone) |
| LocationSummary(zone, kNumInputs, kNumTemps, |
| ((IsUnboxedStore() && opt && is_initialization()) || |
| IsPotentialUnboxedStore()) |
| ? LocationSummary::kCallOnSlowPath |
| : LocationSummary::kNoCall); |
| |
| summary->set_in(0, Location::RequiresRegister()); |
| if (IsUnboxedStore() && opt) { |
| summary->set_in(1, Location::RequiresFpuRegister()); |
| summary->set_temp(0, Location::RequiresRegister()); |
| summary->set_temp(1, Location::RequiresRegister()); |
| } else if (IsPotentialUnboxedStore()) { |
| summary->set_in(1, ShouldEmitStoreBarrier() ? Location::WritableRegister() |
| : Location::RequiresRegister()); |
| summary->set_temp(0, Location::RequiresRegister()); |
| summary->set_temp(1, Location::RequiresRegister()); |
| summary->set_temp(2, opt ? Location::RequiresFpuRegister() |
| : Location::FpuRegisterLocation(Q1)); |
| } else { |
| summary->set_in(1, ShouldEmitStoreBarrier() |
| ? Location::RegisterLocation(kWriteBarrierValueReg) |
| : LocationRegisterOrConstant(value())); |
| } |
| return summary; |
| } |
| |
| static void EnsureMutableBox(FlowGraphCompiler* compiler, |
| StoreInstanceFieldInstr* instruction, |
| Register box_reg, |
| const Class& cls, |
| Register instance_reg, |
| intptr_t offset, |
| Register temp) { |
| Label done; |
| __ ldr(box_reg, FieldAddress(instance_reg, offset)); |
| __ CompareObject(box_reg, Object::null_object()); |
| __ b(&done, NE); |
| |
| BoxAllocationSlowPath::Allocate(compiler, instruction, cls, box_reg, temp); |
| |
| __ MoveRegister(temp, box_reg); |
| __ StoreIntoObjectOffset(instance_reg, offset, temp, |
| Assembler::kValueIsNotSmi); |
| __ Bind(&done); |
| } |
| |
| void StoreInstanceFieldInstr::EmitNativeCode(FlowGraphCompiler* compiler) { |
| ASSERT(sizeof(classid_t) == kInt16Size); |
| |
| Label skip_store; |
| |
| const Register instance_reg = locs()->in(0).reg(); |
| const intptr_t offset_in_bytes = OffsetInBytes(); |
| |
| if (IsUnboxedStore() && compiler->is_optimizing()) { |
| const DRegister value = EvenDRegisterOf(locs()->in(1).fpu_reg()); |
| const Register temp = locs()->temp(0).reg(); |
| const Register temp2 = locs()->temp(1).reg(); |
| const intptr_t cid = slot().field().UnboxedFieldCid(); |
| |
| if (is_initialization()) { |
| const Class* cls = NULL; |
| switch (cid) { |
| case kDoubleCid: |
| cls = &compiler->double_class(); |
| break; |
| case kFloat32x4Cid: |
| cls = &compiler->float32x4_class(); |
| break; |
| case kFloat64x2Cid: |
| cls = &compiler->float64x2_class(); |
|