Files
sdk/runtime/vm/instructions_arm.h
T
Teagan Strickland a17b52c2c1 Revert "[vm, compiler] Unoptimized megamorphic calls."
This reverts commit fde6a5917e.

Reason for revert: This commit looks to be causing new test failures on dart2js. While there are some odd results on some builders that look like infra failures, some builders (for example, dart2js-minified-strong-linux-x64-d8) show the new failing tests clearly.

Original change's description:
> [vm, compiler] Unoptimized megamorphic calls.
> 
> When an instance call in unoptimized code creates more than FLAG_max_polymorphic_checks cases, switch the call to use a MegamorphicCache instead of ICData. The prevents unbounded collection of type feedback, and gives improvements on microbenchmarks in the 3-8% range for unoptimized code.
> 
> It also leads to a loss of target frequency information for the optimizer, leading to different ordering for range checks in polymorphic inlining. This leads to changes on megamorphic microbenchmarks from -31% to +60%, weighted toward the negative end.
> 
> In practice the frequency information seems unimportant, as dart2js has 4.01% geomean improvement.
> 
> This is a step toward direct monomorphic calls in unoptimized code, which will also make use of the patching and type feedback extraction added here.
> 
> Bug: https://github.com/dart-lang/sdk/issues/26780
> Bug: https://github.com/dart-lang/sdk/issues/36409
> Bug: https://github.com/dart-lang/sdk/issues/36731
> Change-Id: I29f53f23b6794c5f5f0db8b8184788cee16fd9c5
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/99270
> Reviewed-by: Alexander Markov <alexmarkov@google.com>

TBR=rmacnak@google.com,alexmarkov@google.com,ajcbik@google.com

Change-Id: Icad46b93cdf8541a00563f49da6b4ac0a4df1ba1
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: https://github.com/dart-lang/sdk/issues/26780, https://github.com/dart-lang/sdk/issues/36409, https://github.com/dart-lang/sdk/issues/36731
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/103440
Reviewed-by: Teagan Strickland <sstrickl@google.com>
Commit-Queue: Teagan Strickland <sstrickl@google.com>
2019-05-22 13:20:49 +00:00

258 lines
7.8 KiB
C++

// 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.
// Classes that describe assembly patterns as used by inline caches.
#ifndef RUNTIME_VM_INSTRUCTIONS_ARM_H_
#define RUNTIME_VM_INSTRUCTIONS_ARM_H_
#ifndef RUNTIME_VM_INSTRUCTIONS_H_
#error Do not include instructions_arm.h directly; use instructions.h instead.
#endif
#include "vm/allocation.h"
#include "vm/compiler/assembler/assembler.h"
#include "vm/constants.h"
#include "vm/native_function.h"
namespace dart {
class ICData;
class Code;
class Object;
class ObjectPool;
class RawCode;
class RawICData;
class RawObject;
class InstructionPattern : public AllStatic {
public:
// Decodes a load sequence ending at 'end' (the last instruction of the
// load sequence is the instruction before the one at end). Returns the
// address of the first instruction in the sequence. Returns the register
// being loaded and the loaded object in the output parameters 'reg' and
// 'obj' respectively.
static uword DecodeLoadObject(uword end,
const ObjectPool& object_pool,
Register* reg,
Object* obj);
// Decodes a load sequence ending at 'end' (the last instruction of the
// load sequence is the instruction before the one at end). Returns the
// address of the first instruction in the sequence. Returns the register
// being loaded and the loaded immediate value in the output parameters
// 'reg' and 'value' respectively.
static uword DecodeLoadWordImmediate(uword end,
Register* reg,
intptr_t* value);
// Encodes a load immediate sequence ending at 'end' (the last instruction of
// the load sequence is the instruction before the one at end).
//
// Supports only a subset of [DecodeLoadWordImmediate], namely:
// movw r, #lower16
// movt r, #upper16
static void EncodeLoadWordImmediate(uword end, Register reg, intptr_t value);
// Decodes a load sequence ending at 'end' (the last instruction of the
// load sequence is the instruction before the one at end). Returns the
// address of the first instruction in the sequence. Returns the register
// being loaded and the index in the pool being read from in the output
// parameters 'reg' and 'index' respectively.
// IMPORANT: When generating code loading values from pool on ARM use
// LoadWordFromPool macro instruction instead of emitting direct load.
// The macro instruction takes care of pool offsets that can't be
// encoded as immediates.
static uword DecodeLoadWordFromPool(uword end,
Register* reg,
intptr_t* index);
};
class CallPattern : public ValueObject {
public:
CallPattern(uword pc, const Code& code);
RawICData* IcData();
RawCode* TargetCode() const;
void SetTargetCode(const Code& code) const;
private:
const ObjectPool& object_pool_;
uword end_;
uword ic_data_load_end_;
intptr_t target_code_pool_index_;
ICData& ic_data_;
DISALLOW_COPY_AND_ASSIGN(CallPattern);
};
class NativeCallPattern : public ValueObject {
public:
NativeCallPattern(uword pc, const Code& code);
RawCode* target() const;
void set_target(const Code& target) const;
NativeFunction native_function() const;
void set_native_function(NativeFunction target) const;
private:
const ObjectPool& object_pool_;
uword end_;
intptr_t native_function_pool_index_;
intptr_t target_code_pool_index_;
DISALLOW_COPY_AND_ASSIGN(NativeCallPattern);
};
// Instance call that can switch between a direct monomorphic call, an IC call,
// and a megamorphic call.
// load guarded cid load ICData load MegamorphicCache
// load monomorphic target <-> load ICLookup stub -> load MMLookup stub
// call target.entry call stub.entry call stub.entry
class SwitchableCallPatternBase : public ValueObject {
public:
explicit SwitchableCallPatternBase(const Code& code);
RawObject* data() const;
void SetData(const Object& data) const;
protected:
const ObjectPool& object_pool_;
intptr_t data_pool_index_;
intptr_t target_pool_index_;
private:
DISALLOW_COPY_AND_ASSIGN(SwitchableCallPatternBase);
};
// See [SwitchableCallBase] for a switchable calls in general.
//
// The target slot is always a [Code] object: Either the code of the
// monomorphic function or a stub code.
class SwitchableCallPattern : public SwitchableCallPatternBase {
public:
SwitchableCallPattern(uword pc, const Code& code);
RawCode* target() const;
void SetTarget(const Code& target) const;
private:
DISALLOW_COPY_AND_ASSIGN(SwitchableCallPattern);
};
// See [SwitchableCallBase] for a switchable calls in general.
//
// The target slot is always a direct entrypoint address: Either the entry point
// of the monomorphic function or a stub entry point.
class BareSwitchableCallPattern : public SwitchableCallPatternBase {
public:
BareSwitchableCallPattern(uword pc, const Code& code);
RawCode* target() const;
void SetTarget(const Code& target) const;
private:
DISALLOW_COPY_AND_ASSIGN(BareSwitchableCallPattern);
};
class ReturnPattern : public ValueObject {
public:
explicit ReturnPattern(uword pc);
// bx_lr = 1.
static const int kLengthInBytes = 1 * Instr::kInstrSize;
int pattern_length_in_bytes() const { return kLengthInBytes; }
bool IsValid() const;
private:
const uword pc_;
};
class PcRelativeCallPattern : public ValueObject {
public:
// 24 bit signed integer which will get multiplied by 4.
static const intptr_t kLowerCallingRange = -(1 << 25);
static const intptr_t kUpperCallingRange = (1 << 25) - 1;
explicit PcRelativeCallPattern(uword pc) : pc_(pc) {}
static const int kLengthInBytes = 1 * Instr::kInstrSize;
int32_t distance() {
#if !defined(DART_PRECOMPILED_RUNTIME)
return Assembler::DecodeBranchOffset(*reinterpret_cast<int32_t*>(pc_));
#else
UNREACHABLE();
return 0;
#endif
}
void set_distance(int32_t distance) {
#if !defined(DART_PRECOMPILED_RUNTIME)
int32_t* word = reinterpret_cast<int32_t*>(pc_);
*word = Assembler::EncodeBranchOffset(distance, *word);
#else
UNREACHABLE();
#endif
}
bool IsValid() const;
private:
uword pc_;
};
// Instruction pattern for a tail call to a signed 32-bit PC-relative offset
//
// The AOT compiler can emit PC-relative calls. If the destination of such a
// call is not in range for the "bl.<cond> <offset>" instruction, the AOT
// compiler will emit a trampoline which is in range. That trampoline will
// then tail-call to the final destination (also via PC-relative offset, but it
// supports a full signed 32-bit offset).
//
// The pattern of the trampoline looks like:
//
// movw TMP, #lower16
// movt TMP, #upper16
// add PC, PC, TMP lsl #0
//
class PcRelativeTrampolineJumpPattern : public ValueObject {
public:
explicit PcRelativeTrampolineJumpPattern(uword pattern_start)
: pattern_start_(pattern_start) {
USE(pattern_start_);
}
static const int kLengthInBytes = 3 * Instr::kInstrSize;
void Initialize();
int32_t distance();
void set_distance(int32_t distance);
bool IsValid() const;
private:
// This offset must be applied to account for the fact that
// a) the actual "branch" is only in the 3rd instruction
// b) when reading the PC it reports current instruction + 8
static const intptr_t kDistanceOffset = -4 * Instr::kInstrSize;
// add PC, PC, TMP lsl #0
static const uint32_t kAddPcEncoding =
(ADD << kOpcodeShift) | (AL << kConditionShift) | (PC << kRnShift) |
(PC << kRdShift) | (TMP << kRmShift);
uword pattern_start_;
};
} // namespace dart
#endif // RUNTIME_VM_INSTRUCTIONS_ARM_H_