Commit 470dfa9f authored by Junliang Yan's avatar Junliang Yan Committed by Commit Bot

PPC/s390: [tasm] Add platform-independent base class TurboAssemblerBase

Port 699a91f2

Original Commit Message:

    This class can contain members and functions common across all
    platforms.

R=jgruber@chromium.org, joransiu@ca.ibm.com, michael_dawson@ca.ibm.com
BUG=
LOG=N

Change-Id: Id085de265e915d0cc3d7851153df53529545743b
Reviewed-on: https://chromium-review.googlesource.com/1095735Reviewed-by: 's avatarJoran Siu <joransiu@ca.ibm.com>
Commit-Queue: Junliang Yan <jyan@ca.ibm.com>
Cr-Commit-Position: refs/heads/master@{#53650}
parent a229e121
......@@ -194,7 +194,7 @@ void DirectCEntryStub::GenerateCall(MacroAssembler* masm, Register target) {
// This is basically an inlined version of Call(Handle<Code>) that loads the
// code object into lr instead of ip.
DCHECK_NE(ip, target);
__ LookupConstant(ip, GetCode());
__ IndirectLoadConstant(ip, GetCode());
__ addi(r0, ip, Operand(Code::kHeaderSize - kHeapObjectTag));
__ Move(ip, target);
__ Call(r0);
......
......@@ -10,7 +10,6 @@
#include "src/base/bits.h"
#include "src/base/division-by-constant.h"
#include "src/bootstrapper.h"
#include "src/builtins/constants-table-builder.h"
#include "src/callable.h"
#include "src/code-factory.h"
#include "src/code-stubs.h"
......@@ -20,7 +19,6 @@
#include "src/instruction-stream.h"
#include "src/register-configuration.h"
#include "src/runtime/runtime.h"
#include "src/snapshot/serializer-common.h"
#include "src/snapshot/snapshot.h"
#include "src/ppc/macro-assembler-ppc.h"
......@@ -42,19 +40,6 @@ MacroAssembler::MacroAssembler(Isolate* isolate, void* buffer, int size,
}
}
TurboAssembler::TurboAssembler(Isolate* isolate, void* buffer, int buffer_size,
CodeObjectRequired create_code_object)
: Assembler(isolate, buffer, buffer_size), isolate_(isolate) {
if (create_code_object == CodeObjectRequired::kYes) {
code_object_ = Handle<HeapObject>::New(
isolate->heap()->self_reference_marker(), isolate);
}
}
TurboAssembler::TurboAssembler(IsolateData isolate_data, void* buffer,
int buffer_size)
: Assembler(isolate_data, buffer, buffer_size) {}
int TurboAssembler::RequiredStackSizeForCallerSaved(SaveFPRegsMode fp_mode,
Register exclusion1,
Register exclusion2,
......@@ -139,44 +124,13 @@ void TurboAssembler::Jump(Register target) {
}
#ifdef V8_EMBEDDED_BUILTINS
void TurboAssembler::LookupConstant(Register destination,
Handle<HeapObject> object) {
CHECK(isolate()->ShouldLoadConstantsFromRootList());
CHECK(root_array_available_);
// Before falling back to the (fairly slow) lookup from the constants table,
// check if any of the fast paths can be applied.
{
int builtin_index;
Heap::RootListIndex root_index;
if (isolate()->heap()->IsRootHandle(object, &root_index)) {
// Roots are loaded relative to the root register.
LoadRoot(destination, root_index);
return;
} else if (isolate()->builtins()->IsBuiltinHandle(object, &builtin_index)) {
// Similar to roots, builtins may be loaded from the builtins table.
LoadBuiltin(destination, builtin_index);
return;
} else if (object.is_identical_to(code_object_) &&
Builtins::IsBuiltinId(maybe_builtin_index_)) {
// The self-reference loaded through Codevalue() may also be a builtin
// and thus viable for a fast load.
LoadBuiltin(destination, maybe_builtin_index_);
return;
}
}
// Ensure the given object is in the builtins constants table and fetch its
// index.
BuiltinsConstantsTableBuilder* builder =
isolate()->builtins_constants_table_builder();
uint32_t index = builder->AddObject(object);
void TurboAssembler::LoadFromConstantsTable(Register destination,
int constant_index) {
DCHECK(isolate()->heap()->RootCanBeTreatedAsConstant(
Heap::kBuiltinsConstantsTableRootIndex));
const uint32_t offset =
FixedArray::kHeaderSize + index * kPointerSize - kHeapObjectTag;
FixedArray::kHeaderSize + constant_index * kPointerSize - kHeapObjectTag;
CHECK(is_uint19(offset));
DCHECK_NE(destination, r0);
......@@ -184,25 +138,11 @@ void TurboAssembler::LookupConstant(Register destination,
LoadP(destination, MemOperand(destination, offset), r0);
}
void TurboAssembler::LookupExternalReference(Register destination,
ExternalReference reference) {
CHECK(reference.address() !=
ExternalReference::roots_array_start(isolate()).address());
CHECK(isolate()->ShouldLoadConstantsFromRootList());
CHECK(root_array_available_);
// Encode as an index into the external reference table stored on the isolate.
ExternalReferenceEncoder encoder(isolate());
ExternalReferenceEncoder::Value v = encoder.Encode(reference.address());
CHECK(!v.is_from_api());
uint32_t index = v.index();
// Generate code to load from the external reference table.
void TurboAssembler::LoadExternalReference(Register destination,
int reference_index) {
int32_t roots_to_external_reference_offset =
Heap::roots_to_external_reference_table_offset() +
ExternalReferenceTable::OffsetOfEntry(index);
ExternalReferenceTable::OffsetOfEntry(reference_index);
LoadP(destination,
MemOperand(kRootRegister, roots_to_external_reference_offset), r0);
......@@ -251,7 +191,7 @@ void TurboAssembler::Jump(Handle<Code> code, RelocInfo::Mode rmode,
#ifdef V8_EMBEDDED_BUILTINS
if (root_array_available_ && isolate()->ShouldLoadConstantsFromRootList()) {
Register scratch = ip;
LookupConstant(scratch, code);
IndirectLoadConstant(scratch, code);
addi(scratch, scratch, Operand(Code::kHeaderSize - kHeapObjectTag));
Label skip;
if (cond != al) b(NegateCondition(cond), &skip, cr);
......@@ -349,7 +289,7 @@ void TurboAssembler::Call(Handle<Code> code, RelocInfo::Mode rmode,
if (root_array_available_ && isolate()->ShouldLoadConstantsFromRootList()) {
// Use ip directly instead of using UseScratchRegisterScope, as we do not
// preserve scratch registers across calls.
LookupConstant(ip, code);
IndirectLoadConstant(ip, code);
addi(ip, ip, Operand(Code::kHeaderSize - kHeapObjectTag));
Label skip;
if (cond != al) b(NegateCondition(cond), &skip);
......@@ -404,7 +344,7 @@ void TurboAssembler::Push(Smi* smi) {
void TurboAssembler::Move(Register dst, Handle<HeapObject> value) {
#ifdef V8_EMBEDDED_BUILTINS
if (root_array_available_ && isolate()->ShouldLoadConstantsFromRootList()) {
LookupConstant(dst, value);
IndirectLoadConstant(dst, value);
return;
}
#endif // V8_EMBEDDED_BUILTINS
......@@ -416,7 +356,7 @@ void TurboAssembler::Move(Register dst, ExternalReference reference) {
if (root_array_available_ && isolate()->ShouldLoadConstantsFromRootList() &&
reference.address() !=
ExternalReference::roots_array_start(isolate()).address()) {
LookupExternalReference(dst, reference);
IndirectLoadExternalReference(dst, reference);
return;
}
#endif // V8_EMBEDDED_BUILTINS
......
......@@ -10,6 +10,7 @@
#include "src/double.h"
#include "src/globals.h"
#include "src/ppc/assembler-ppc.h"
#include "src/turbo-assembler.h"
namespace v8 {
namespace internal {
......@@ -110,21 +111,14 @@ bool AreAliased(DoubleRegister reg1, DoubleRegister reg2,
#define Div divw
#endif
class TurboAssembler : public Assembler {
class TurboAssembler : public TurboAssemblerBase {
public:
TurboAssembler(Isolate* isolate, void* buffer, int buffer_size,
CodeObjectRequired create_code_object);
TurboAssembler(IsolateData isolate_data, void* buffer, int buffer_size);
void set_has_frame(bool value) { has_frame_ = value; }
bool has_frame() { return has_frame_; }
CodeObjectRequired create_code_object)
: TurboAssemblerBase(isolate, buffer, buffer_size, create_code_object) {}
TurboAssembler(IsolateData isolate_data, void* buffer, int buffer_size)
: TurboAssemblerBase(isolate_data, buffer, buffer_size) {}
Isolate* isolate() const { return isolate_; }
Handle<HeapObject> CodeObject() {
DCHECK(!code_object_.is_null());
return code_object_;
}
// Converts the integer (untagged smi) in |src| to a double, storing
// the result to |dst|
void ConvertIntToDouble(Register src, DoubleRegister dst);
......@@ -221,13 +215,6 @@ class TurboAssembler : public Assembler {
void LoadPC(Register dst);
void ComputeCodeStartAddress(Register dst);
bool root_array_available() const { return root_array_available_; }
void set_root_array_available(bool v) { root_array_available_ = v; }
void set_builtin_index(int builtin_index) {
maybe_builtin_index_ = builtin_index;
}
void StoreDouble(DoubleRegister src, const MemOperand& mem,
Register scratch = no_reg);
void StoreDoubleU(DoubleRegister src, const MemOperand& mem,
......@@ -354,8 +341,11 @@ class TurboAssembler : public Assembler {
Register exclusion3 = no_reg);
// Load an object from the root table.
void LoadRoot(Register destination, Heap::RootListIndex index) override {
LoadRoot(destination, index, al);
}
void LoadRoot(Register destination, Heap::RootListIndex index,
Condition cond = al);
Condition cond);
void SwapP(Register src, Register dst, Register scratch);
void SwapP(Register src, MemOperand dst, Register scratch);
......@@ -444,10 +434,11 @@ class TurboAssembler : public Assembler {
#endif
#ifdef V8_EMBEDDED_BUILTINS
void LookupConstant(Register destination, Handle<HeapObject> object);
void LookupExternalReference(Register destination,
ExternalReference reference);
void LoadBuiltin(Register destination, int builtin_index);
void LoadFromConstantsTable(Register destination,
int constant_index) override;
void LoadExternalReference(Register destination,
int reference_index) override;
void LoadBuiltin(Register destination, int builtin_index) override;
#endif // V8_EMBEDDED_BUILTINS
// Returns the size of a call in instructions. Note, the value returned is
......@@ -462,6 +453,8 @@ class TurboAssembler : public Assembler {
CRegister cr = cr7);
void Jump(Handle<Code> code, RelocInfo::Mode rmode, Condition cond = al,
CRegister cr = cr7);
void Jump(intptr_t target, RelocInfo::Mode rmode, Condition cond = al,
CRegister cr = cr7);
void Call(Register target);
void Call(Address target, RelocInfo::Mode rmode, Condition cond = al);
int CallSize(Handle<Code> code,
......@@ -684,20 +677,9 @@ class TurboAssembler : public Assembler {
void ResetSpeculationPoisonRegister();
protected:
// This handle will be patched with the code object on installation.
Handle<HeapObject> code_object_;
private:
int maybe_builtin_index_ = -1; // May be set while generating builtins.
static const int kSmiShift = kSmiTagSize + kSmiShiftSize;
bool has_frame_ = false;
bool root_array_available_ = true;
Isolate* const isolate_ = nullptr;
void Jump(intptr_t target, RelocInfo::Mode rmode, Condition cond = al,
CRegister cr = cr7);
int CalculateStackPassedWords(int num_reg_arguments,
int num_double_arguments);
void CallCFunctionHelper(Register function, int num_reg_arguments,
......
......@@ -222,7 +222,7 @@ void DirectCEntryStub::GenerateCall(MacroAssembler* masm, Register target) {
// This is basically an inlined version of Call(Handle<Code>) that loads the
// code object into lr instead of ip.
__ Move(ip, target);
__ LookupConstant(r1, GetCode());
__ IndirectLoadConstant(r1, GetCode());
__ AddP(r1, r1, Operand(Code::kHeaderSize - kHeapObjectTag));
__ Call(r1);
return;
......
......@@ -10,7 +10,6 @@
#include "src/base/bits.h"
#include "src/base/division-by-constant.h"
#include "src/bootstrapper.h"
#include "src/builtins/constants-table-builder.h"
#include "src/callable.h"
#include "src/code-factory.h"
#include "src/code-stubs.h"
......@@ -20,7 +19,6 @@
#include "src/instruction-stream.h"
#include "src/register-configuration.h"
#include "src/runtime/runtime.h"
#include "src/snapshot/serializer-common.h"
#include "src/snapshot/snapshot.h"
#include "src/s390/macro-assembler-s390.h"
......@@ -42,19 +40,6 @@ MacroAssembler::MacroAssembler(Isolate* isolate, void* buffer, int size,
}
}
TurboAssembler::TurboAssembler(Isolate* isolate, void* buffer, int buffer_size,
CodeObjectRequired create_code_object)
: Assembler(isolate, buffer, buffer_size), isolate_(isolate) {
if (create_code_object == CodeObjectRequired::kYes) {
code_object_ = Handle<HeapObject>::New(
isolate->heap()->self_reference_marker(), isolate);
}
}
TurboAssembler::TurboAssembler(IsolateData isolate_data, void* buffer,
int buffer_size)
: Assembler(isolate_data, buffer, buffer_size) {}
int TurboAssembler::RequiredStackSizeForCallerSaved(SaveFPRegsMode fp_mode,
Register exclusion1,
Register exclusion2,
......@@ -134,44 +119,13 @@ int TurboAssembler::PopCallerSaved(SaveFPRegsMode fp_mode, Register exclusion1,
}
#ifdef V8_EMBEDDED_BUILTINS
void TurboAssembler::LookupConstant(Register destination,
Handle<HeapObject> object) {
CHECK(isolate()->ShouldLoadConstantsFromRootList());
CHECK(root_array_available_);
// Before falling back to the (fairly slow) lookup from the constants table,
// check if any of the fast paths can be applied.
{
int builtin_index;
Heap::RootListIndex root_index;
if (isolate()->heap()->IsRootHandle(object, &root_index)) {
// Roots are loaded relative to the root register.
LoadRoot(destination, root_index);
return;
} else if (isolate()->builtins()->IsBuiltinHandle(object, &builtin_index)) {
// Similar to roots, builtins may be loaded from the builtins table.
LoadBuiltin(destination, builtin_index);
return;
} else if (object.is_identical_to(code_object_) &&
Builtins::IsBuiltinId(maybe_builtin_index_)) {
// The self-reference loaded through Codevalue() may also be a builtin
// and thus viable for a fast load.
LoadBuiltin(destination, maybe_builtin_index_);
return;
}
}
// Ensure the given object is in the builtins constants table and fetch its
// index.
BuiltinsConstantsTableBuilder* builder =
isolate()->builtins_constants_table_builder();
uint32_t index = builder->AddObject(object);
void TurboAssembler::LoadFromConstantsTable(Register destination,
int constant_index) {
DCHECK(isolate()->heap()->RootCanBeTreatedAsConstant(
Heap::kBuiltinsConstantsTableRootIndex));
const uint32_t offset =
FixedArray::kHeaderSize + index * kPointerSize - kHeapObjectTag;
FixedArray::kHeaderSize + constant_index * kPointerSize - kHeapObjectTag;
CHECK(is_uint19(offset));
DCHECK_NE(destination, r0);
......@@ -179,25 +133,11 @@ void TurboAssembler::LookupConstant(Register destination,
LoadP(destination, MemOperand(destination, offset), r1);
}
void TurboAssembler::LookupExternalReference(Register destination,
ExternalReference reference) {
CHECK(reference.address() !=
ExternalReference::roots_array_start(isolate()).address());
CHECK(isolate()->ShouldLoadConstantsFromRootList());
CHECK(root_array_available_);
// Encode as an index into the external reference table stored on the isolate.
ExternalReferenceEncoder encoder(isolate());
ExternalReferenceEncoder::Value v = encoder.Encode(reference.address());
CHECK(!v.is_from_api());
uint32_t index = v.index();
// Generate code to load from the external reference table.
void TurboAssembler::LoadExternalReference(Register destination,
int reference_index) {
int32_t roots_to_external_reference_offset =
Heap::roots_to_external_reference_table_offset() +
ExternalReferenceTable::OffsetOfEntry(index);
ExternalReferenceTable::OffsetOfEntry(reference_index);
LoadP(destination,
MemOperand(kRootRegister, roots_to_external_reference_offset));
......@@ -246,7 +186,7 @@ void TurboAssembler::Jump(Handle<Code> code, RelocInfo::Mode rmode,
#ifdef V8_EMBEDDED_BUILTINS
if (root_array_available_ && isolate()->ShouldLoadConstantsFromRootList()) {
Register scratch = r1;
LookupConstant(scratch, code);
IndirectLoadConstant(scratch, code);
la(scratch, MemOperand(scratch, Code::kHeaderSize - kHeapObjectTag));
b(cond, scratch);
return;
......@@ -341,7 +281,7 @@ void TurboAssembler::Call(Handle<Code> code, RelocInfo::Mode rmode,
if (root_array_available_ && isolate()->ShouldLoadConstantsFromRootList()) {
// Use ip directly instead of using UseScratchRegisterScope, as we do not
// preserve scratch registers across calls.
LookupConstant(ip, code);
IndirectLoadConstant(ip, code);
la(ip, MemOperand(ip, Code::kHeaderSize - kHeapObjectTag));
Call(ip);
return;
......@@ -397,7 +337,7 @@ void TurboAssembler::Push(Smi* smi) {
void TurboAssembler::Move(Register dst, Handle<HeapObject> value) {
#ifdef V8_EMBEDDED_BUILTINS
if (root_array_available_ && isolate()->ShouldLoadConstantsFromRootList()) {
LookupConstant(dst, value);
IndirectLoadConstant(dst, value);
return;
}
#endif // V8_EMBEDDED_BUILTINS
......@@ -409,7 +349,7 @@ void TurboAssembler::Move(Register dst, ExternalReference reference) {
if (root_array_available_ && isolate()->ShouldLoadConstantsFromRootList() &&
reference.address() !=
ExternalReference::roots_array_start(isolate()).address()) {
LookupExternalReference(dst, reference);
IndirectLoadExternalReference(dst, reference);
return;
}
#endif // V8_EMBEDDED_BUILTINS
......
......@@ -9,6 +9,7 @@
#include "src/bailout-reason.h"
#include "src/globals.h"
#include "src/s390/assembler-s390.h"
#include "src/turbo-assembler.h"
namespace v8 {
namespace internal {
......@@ -167,24 +168,20 @@ bool AreAliased(DoubleRegister reg1, DoubleRegister reg2,
#endif
class TurboAssembler : public Assembler {
class TurboAssembler : public TurboAssemblerBase {
public:
TurboAssembler(Isolate* isolate, void* buffer, int buffer_size,
CodeObjectRequired create_code_object);
TurboAssembler(IsolateData isolate_data, void* buffer, int buffer_size);
Isolate* isolate() const { return isolate_; }
Handle<HeapObject> CodeObject() {
DCHECK(!code_object_.is_null());
return code_object_;
}
CodeObjectRequired create_code_object)
: TurboAssemblerBase(isolate, buffer, buffer_size, create_code_object) {}
TurboAssembler(IsolateData isolate_data, void* buffer, int buffer_size)
: TurboAssemblerBase(isolate_data, buffer, buffer_size) {}
#ifdef V8_EMBEDDED_BUILTINS
void LookupConstant(Register destination, Handle<HeapObject> object);
void LookupExternalReference(Register destination,
ExternalReference reference);
void LoadBuiltin(Register destination, int builtin_index);
void LoadFromConstantsTable(Register destination,
int constant_index) override;
void LoadExternalReference(Register destination,
int reference_index) override;
void LoadBuiltin(Register destination, int builtin_index) override;
#endif // V8_EMBEDDED_BUILTINS
// Returns the size of a call in instructions.
......@@ -278,8 +275,11 @@ class TurboAssembler : public Assembler {
Register exclusion3 = no_reg);
// Load an object from the root table.
void LoadRoot(Register destination, Heap::RootListIndex index) override {
LoadRoot(destination, index, al);
}
void LoadRoot(Register destination, Heap::RootListIndex index,
Condition cond = al);
Condition cond);
//--------------------------------------------------------------------------
// S390 Macro Assemblers for Instructions
//--------------------------------------------------------------------------
......@@ -910,8 +910,6 @@ class TurboAssembler : public Assembler {
// Print a message to stdout and abort execution.
void Abort(AbortReason reason);
void set_has_frame(bool value) { has_frame_ = value; }
bool has_frame() { return has_frame_; }
inline bool AllowThisStubCall(CodeStub* stub);
// ---------------------------------------------------------------------------
......@@ -1039,19 +1037,7 @@ class TurboAssembler : public Assembler {
void ResetSpeculationPoisonRegister();
void ComputeCodeStartAddress(Register dst);
bool root_array_available() const { return root_array_available_; }
void set_root_array_available(bool v) { root_array_available_ = v; }
void set_builtin_index(int builtin_index) {
maybe_builtin_index_ = builtin_index;
}
protected:
// This handle will be patched with the code object on installation.
Handle<HeapObject> code_object_;
private:
int maybe_builtin_index_ = -1; // May be set while generating builtins.
static const int kSmiShift = kSmiTagSize + kSmiShiftSize;
void CallCFunctionHelper(Register function, int num_reg_arguments,
......@@ -1060,10 +1046,6 @@ class TurboAssembler : public Assembler {
void Jump(intptr_t target, RelocInfo::Mode rmode, Condition cond = al);
int CalculateStackPassedWords(int num_reg_arguments,
int num_double_arguments);
bool has_frame_ = false;
bool root_array_available_ = true;
Isolate* const isolate_ = nullptr;
};
// MacroAssembler implements a collection of frequently used macros.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment