Index: src/compiler/fast-accessor-assembler.cc |
diff --git a/src/compiler/fast-accessor-assembler.cc b/src/compiler/fast-accessor-assembler.cc |
index 518003b2eedb0d8885b27bd599dd6fb63e74ae71..09727ce2ea1f5b14378c22dcefd3cbc35c05560d 100644 |
--- a/src/compiler/fast-accessor-assembler.cc |
+++ b/src/compiler/fast-accessor-assembler.cc |
@@ -6,12 +6,8 @@ |
#include "src/base/logging.h" |
#include "src/code-stubs.h" // For CallApiFunctionStub. |
-#include "src/compiler/graph.h" |
-#include "src/compiler/linkage.h" |
-#include "src/compiler/pipeline.h" |
-#include "src/compiler/raw-machine-assembler.h" |
-#include "src/compiler/schedule.h" |
-#include "src/compiler/verifier.h" |
+#include "src/compiler/code-stub-assembler.h" |
+#include "src/compiler/linkage.h" // For GetStubCallDescriptor |
#include "src/handles-inl.h" |
#include "src/objects.h" // For FAA::GetInternalField impl. |
@@ -21,15 +17,13 @@ namespace compiler { |
FastAccessorAssembler::FastAccessorAssembler(Isolate* isolate) |
: zone_(), |
- assembler_(new RawMachineAssembler( |
- isolate, new (zone()) Graph(zone()), |
- Linkage::GetJSCallDescriptor(&zone_, false, 1, |
- CallDescriptor::kNoFlags))), |
+ isolate_(isolate), |
+ assembler_(new CodeStubAssembler(isolate, zone(), 1, |
+ Code::ComputeFlags(Code::STUB), |
+ "FastAccessorAssembler")), |
state_(kBuilding) {} |
- |
-FastAccessorAssembler::~FastAccessorAssembler() {} |
- |
+FastAccessorAssembler::~FastAccessorAssembler() { Clear(); } |
FastAccessorAssembler::ValueId FastAccessorAssembler::IntegerConstant( |
int const_value) { |
@@ -37,34 +31,32 @@ FastAccessorAssembler::ValueId FastAccessorAssembler::IntegerConstant( |
return FromRaw(assembler_->NumberConstant(const_value)); |
} |
- |
FastAccessorAssembler::ValueId FastAccessorAssembler::GetReceiver() { |
CHECK_EQ(kBuilding, state_); |
- // For JS call descriptor, the receiver is parameter 0. If we use other |
- // call descriptors, this may or may not hold. So let's check. |
- CHECK(assembler_->call_descriptor()->IsJSFunctionCall()); |
+ // For JS functions, the receiver is parameter 0. |
return FromRaw(assembler_->Parameter(0)); |
} |
- |
FastAccessorAssembler::ValueId FastAccessorAssembler::LoadInternalField( |
ValueId value, int field_no) { |
CHECK_EQ(kBuilding, state_); |
+ |
// Determine the 'value' object's instance type. |
- Node* object_map = |
- assembler_->Load(MachineType::Pointer(), FromId(value), |
- assembler_->IntPtrConstant( |
- Internals::kHeapObjectMapOffset - kHeapObjectTag)); |
+ Node* object_map = assembler_->LoadObjectFieldTyped( |
+ FromId(value), Internals::kHeapObjectMapOffset, MachineType::Pointer()); |
Node* instance_type = assembler_->WordAnd( |
- assembler_->Load( |
- MachineType::Uint16(), object_map, |
- assembler_->IntPtrConstant( |
- Internals::kMapInstanceTypeAndBitFieldOffset - kHeapObjectTag)), |
+ assembler_->LoadObjectFieldTyped( |
+ object_map, Internals::kMapInstanceTypeAndBitFieldOffset, |
+ MachineType::Uint16()), |
assembler_->IntPtrConstant(0xff)); |
// Check whether we have a proper JSObject. |
- RawMachineLabel is_jsobject, is_not_jsobject, merge; |
+ CodeStubAssembler::Variable result(assembler_.get(), |
+ MachineRepresentation::kTagged); |
+ CodeStubAssembler::Label is_jsobject(assembler_.get()); |
+ CodeStubAssembler::Label is_not_jsobject(assembler_.get()); |
+ CodeStubAssembler::Label merge(assembler_.get(), &result); |
assembler_->Branch( |
assembler_->WordEqual( |
instance_type, assembler_->IntPtrConstant(Internals::kJSObjectType)), |
@@ -72,10 +64,10 @@ FastAccessorAssembler::ValueId FastAccessorAssembler::LoadInternalField( |
// JSObject? Then load the internal field field_no. |
assembler_->Bind(&is_jsobject); |
- Node* internal_field = assembler_->Load( |
- MachineType::Pointer(), FromId(value), |
- assembler_->IntPtrConstant(JSObject::kHeaderSize - kHeapObjectTag + |
- kPointerSize * field_no)); |
+ Node* internal_field = assembler_->LoadObjectFieldTyped( |
+ FromId(value), JSObject::kHeaderSize + kPointerSize * field_no, |
+ MachineType::Pointer()); |
+ result.Bind(internal_field); |
assembler_->Goto(&merge); |
// No JSObject? Return undefined. |
@@ -83,43 +75,39 @@ FastAccessorAssembler::ValueId FastAccessorAssembler::LoadInternalField( |
// the method should take a label instead. |
assembler_->Bind(&is_not_jsobject); |
Node* fail_value = assembler_->UndefinedConstant(); |
+ result.Bind(fail_value); |
assembler_->Goto(&merge); |
// Return. |
assembler_->Bind(&merge); |
- Node* phi = assembler_->Phi(MachineRepresentation::kTagged, internal_field, |
- fail_value); |
- return FromRaw(phi); |
+ return FromRaw(result.value()); |
} |
- |
FastAccessorAssembler::ValueId FastAccessorAssembler::LoadValue(ValueId value, |
int offset) { |
CHECK_EQ(kBuilding, state_); |
- return FromRaw(assembler_->Load(MachineType::IntPtr(), FromId(value), |
- assembler_->IntPtrConstant(offset))); |
+ return FromRaw(assembler_->LoadNativeFieldTyped(FromId(value), offset, |
+ MachineType::IntPtr())); |
} |
- |
FastAccessorAssembler::ValueId FastAccessorAssembler::LoadObject(ValueId value, |
int offset) { |
CHECK_EQ(kBuilding, state_); |
- return FromRaw( |
- assembler_->Load(MachineType::AnyTagged(), |
- assembler_->Load(MachineType::Pointer(), FromId(value), |
- assembler_->IntPtrConstant(offset)))); |
+ return FromRaw(assembler_->LoadNativeFieldTyped( |
+ assembler_->LoadNativeFieldTyped(FromId(value), offset, |
+ MachineType::Pointer()), |
+ 0, MachineType::AnyTagged())); |
} |
- |
void FastAccessorAssembler::ReturnValue(ValueId value) { |
CHECK_EQ(kBuilding, state_); |
assembler_->Return(FromId(value)); |
} |
- |
void FastAccessorAssembler::CheckFlagSetOrReturnNull(ValueId value, int mask) { |
CHECK_EQ(kBuilding, state_); |
- RawMachineLabel pass, fail; |
+ CodeStubAssembler::Label pass(assembler_.get()); |
+ CodeStubAssembler::Label fail(assembler_.get()); |
assembler_->Branch( |
assembler_->Word32Equal( |
assembler_->Word32And(FromId(value), assembler_->Int32Constant(mask)), |
@@ -130,39 +118,34 @@ void FastAccessorAssembler::CheckFlagSetOrReturnNull(ValueId value, int mask) { |
assembler_->Bind(&pass); |
} |
- |
void FastAccessorAssembler::CheckNotZeroOrReturnNull(ValueId value) { |
CHECK_EQ(kBuilding, state_); |
- RawMachineLabel is_null, not_null; |
+ CodeStubAssembler::Label is_null(assembler_.get()); |
+ CodeStubAssembler::Label not_null(assembler_.get()); |
assembler_->Branch( |
- assembler_->IntPtrEqual(FromId(value), assembler_->IntPtrConstant(0)), |
+ assembler_->WordEqual(FromId(value), assembler_->IntPtrConstant(0)), |
&is_null, ¬_null); |
assembler_->Bind(&is_null); |
assembler_->Return(assembler_->NullConstant()); |
assembler_->Bind(¬_null); |
} |
- |
FastAccessorAssembler::LabelId FastAccessorAssembler::MakeLabel() { |
CHECK_EQ(kBuilding, state_); |
- RawMachineLabel* label = |
- new (zone()->New(sizeof(RawMachineLabel))) RawMachineLabel; |
- return FromRaw(label); |
+ return FromRaw(new CodeStubAssembler::Label(assembler_.get())); |
} |
- |
void FastAccessorAssembler::SetLabel(LabelId label_id) { |
CHECK_EQ(kBuilding, state_); |
assembler_->Bind(FromId(label_id)); |
} |
- |
void FastAccessorAssembler::CheckNotZeroOrJump(ValueId value_id, |
LabelId label_id) { |
CHECK_EQ(kBuilding, state_); |
- RawMachineLabel pass; |
+ CodeStubAssembler::Label pass(assembler_.get()); |
assembler_->Branch( |
- assembler_->IntPtrEqual(FromId(value_id), assembler_->IntPtrConstant(0)), |
+ assembler_->WordEqual(FromId(value_id), assembler_->IntPtrConstant(0)), |
&pass, FromId(label_id)); |
assembler_->Bind(&pass); |
} |
@@ -172,13 +155,12 @@ FastAccessorAssembler::ValueId FastAccessorAssembler::Call( |
CHECK_EQ(kBuilding, state_); |
// Create API function stub. |
- CallApiFunctionStub stub(assembler_->isolate(), true); |
+ CallApiFunctionStub stub(isolate(), true); |
// Wrap the FunctionCallback in an ExternalReference. |
ApiFunction callback_api_function(FUNCTION_ADDR(callback_function)); |
ExternalReference callback(&callback_api_function, |
- ExternalReference::DIRECT_API_CALL, |
- assembler_->isolate()); |
+ ExternalReference::DIRECT_API_CALL, isolate()); |
// The stub has 5 parameters, and kJSParam (here: 1) parameters to pass |
// through to the callback. |
@@ -201,7 +183,7 @@ FastAccessorAssembler::ValueId FastAccessorAssembler::Call( |
Node* call = assembler_->CallN( |
Linkage::GetStubCallDescriptor( |
- assembler_->isolate(), zone(), stub.GetCallInterfaceDescriptor(), |
+ isolate(), zone(), stub.GetCallInterfaceDescriptor(), |
kStackParam + stub.GetStackParameterCount(), |
CallDescriptor::kNoFlags), |
assembler_->HeapConstant(stub.GetCode()), args); |
@@ -210,52 +192,44 @@ FastAccessorAssembler::ValueId FastAccessorAssembler::Call( |
MaybeHandle<Code> FastAccessorAssembler::Build() { |
CHECK_EQ(kBuilding, state_); |
- |
- // Cleanup: We no longer need this. |
- nodes_.clear(); |
- labels_.clear(); |
- |
- // Export the schedule and call the compiler. |
- Schedule* schedule = assembler_->Export(); |
- Code::Flags flags = Code::ComputeFlags(Code::STUB); |
- MaybeHandle<Code> code = Pipeline::GenerateCodeForCodeStub( |
- assembler_->isolate(), assembler_->call_descriptor(), assembler_->graph(), |
- schedule, flags, "FastAccessorAssembler"); |
- |
- // Update state & return. |
+ Handle<Code> code = assembler_->GenerateCode(); |
state_ = !code.is_null() ? kBuilt : kError; |
+ Clear(); |
return code; |
} |
- |
FastAccessorAssembler::ValueId FastAccessorAssembler::FromRaw(Node* node) { |
nodes_.push_back(node); |
ValueId value = {nodes_.size() - 1}; |
return value; |
} |
- |
FastAccessorAssembler::LabelId FastAccessorAssembler::FromRaw( |
- RawMachineLabel* label) { |
+ CodeStubAssembler::Label* label) { |
labels_.push_back(label); |
LabelId label_id = {labels_.size() - 1}; |
return label_id; |
} |
- |
Node* FastAccessorAssembler::FromId(ValueId value) const { |
CHECK_LT(value.value_id, nodes_.size()); |
CHECK_NOT_NULL(nodes_.at(value.value_id)); |
return nodes_.at(value.value_id); |
} |
- |
-RawMachineLabel* FastAccessorAssembler::FromId(LabelId label) const { |
+CodeStubAssembler::Label* FastAccessorAssembler::FromId(LabelId label) const { |
CHECK_LT(label.label_id, labels_.size()); |
CHECK_NOT_NULL(labels_.at(label.label_id)); |
return labels_.at(label.label_id); |
} |
+void FastAccessorAssembler::Clear() { |
+ for (auto label : labels_) { |
+ delete label; |
+ } |
+ nodes_.clear(); |
+ labels_.clear(); |
+} |
} // namespace compiler |
} // namespace internal |