Index: src/compiler/fast-accessor-assembler.cc |
diff --git a/src/compiler/fast-accessor-assembler.cc b/src/compiler/fast-accessor-assembler.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..2b4e842c49d955d43dc0c3539a8cafc67c197c9b |
--- /dev/null |
+++ b/src/compiler/fast-accessor-assembler.cc |
@@ -0,0 +1,189 @@ |
+// Copyright 2015 the V8 project authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "src/compiler/fast-accessor-assembler.h" |
+ |
+#include "src/base/logging.h" |
+#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/handles-inl.h" |
+#include "src/objects.h" // For FAA::GetInternalField impl. |
+ |
+namespace v8 { |
+namespace internal { |
+namespace compiler { |
+ |
+FastAccessorAssembler::FastAccessorAssembler(Isolate* isolate) |
+ : zone_(), |
+ assembler_(new RawMachineAssembler( |
+ isolate, new (zone()) Graph(zone()), |
+ Linkage::GetJSCallDescriptor(&zone_, false, 1, |
Michael Starzinger
2015/11/27 09:15:52
Not sure if a JavaScript call descriptor is what w
epertoso
2015/11/27 10:04:56
Currently we just tail-call these accessors, and i
vogelheim
2015/11/27 16:24:50
Ack to both comments. As long as we haven't agreed
Michael Starzinger
2015/11/27 16:39:49
Acknowledged. Whatever allows you to make forward
|
+ CallDescriptor::kNoFlags))), |
+ state_(BUILDING) {} |
+ |
+ |
+FastAccessorAssembler::~FastAccessorAssembler() {} |
+ |
+ |
+FastAccessorAssembler::ValueId FastAccessorAssembler::IntegerConstant( |
+ int const_value) { |
+ CHECK_EQ(BUILDING, state_); |
+ return FromRaw(assembler_->NumberConstant(const_value)); |
+} |
+ |
+ |
+FastAccessorAssembler::ValueId FastAccessorAssembler::GetCallTarget() { |
+ return GetParameter(0); |
+} |
+ |
+FastAccessorAssembler::ValueId FastAccessorAssembler::GetParameter( |
+ size_t parameter_no) { |
+ CHECK_EQ(BUILDING, state_); |
+ return FromRaw(assembler_->Parameter(parameter_no)); |
+} |
+ |
+ |
+FastAccessorAssembler::ValueId FastAccessorAssembler::GetInternalField( |
+ ValueId value, int field_no) { |
+ CHECK_EQ(BUILDING, state_); |
+ return FromRaw(assembler_->Load( |
+ kMachPtr, FromId(value), |
+ assembler_->IntPtrConstant(JSObject::kHeaderSize - kHeapObjectTag + |
+ kPointerSize * field_no))); |
+} |
+ |
+ |
+FastAccessorAssembler::ValueId FastAccessorAssembler::LoadValue( |
+ FastAccessorAssembler::ValueId value, int offset) { |
+ CHECK_EQ(BUILDING, state_); |
+ return FromRaw(assembler_->Load(kMachIntPtr, FromId(value), |
+ assembler_->IntPtrConstant(offset))); |
+} |
+ |
+ |
+FastAccessorAssembler::ValueId FastAccessorAssembler::LoadObject( |
+ FastAccessorAssembler::ValueId value, int offset) { |
+ CHECK_EQ(BUILDING, state_); |
+ return FromRaw(assembler_->Load(kMachAnyTagged, FromId(value), |
+ assembler_->IntPtrConstant(offset))); |
+} |
+ |
+ |
+void FastAccessorAssembler::ReturnValue(ValueId value) { |
+ CHECK_EQ(BUILDING, state_); |
+ assembler_->Return(FromId(value)); |
+} |
+ |
+ |
+void FastAccessorAssembler::CheckFlagSetOrReturnNull( |
+ FastAccessorAssembler::ValueId value, int mask) { |
+ CHECK_EQ(BUILDING, state_); |
+ RawMachineAssembler::Label pass, fail; |
+ assembler_->Branch( |
+ assembler_->Word32Equal( |
+ assembler_->Word32And(assembler_->Load(kMachUint32, FromId(value)), |
+ assembler_->Int32Constant(mask)), |
+ assembler_->Int32Constant(0)), |
+ &pass, &fail); |
+ assembler_->Bind(&fail); |
+ assembler_->Return(assembler_->NullConstant()); |
+ assembler_->Bind(&pass); |
+} |
+ |
+ |
+void FastAccessorAssembler::CheckNotNullOrReturnNull(ValueId value) { |
+ CHECK_EQ(BUILDING, state_); |
+ RawMachineAssembler::Label pass, fail; |
+ assembler_->Branch( |
+ assembler_->IntPtrEqual(assembler_->Load(kMachIntPtr, FromId(value)), |
+ assembler_->IntPtrConstant(0)), |
+ &pass, &fail); |
+ assembler_->Bind(&fail); |
+ assembler_->Return(assembler_->NullConstant()); |
+ assembler_->Bind(&pass); |
+} |
+ |
+ |
+FastAccessorAssembler::LabelId FastAccessorAssembler::MakeLabel() { |
+ CHECK_EQ(BUILDING, state_); |
+ RawMachineAssembler::Label* label = new (zone()) RawMachineAssembler::Label; |
+ return FromRaw(label); |
+} |
+ |
+ |
+void FastAccessorAssembler::SetLabel(LabelId label_id) { |
+ CHECK_EQ(BUILDING, state_); |
+ assembler_->Bind(FromId(label_id)); |
+} |
+ |
+ |
+void FastAccessorAssembler::CheckNotNullOrJump(ValueId value_id, |
+ LabelId label_id) { |
+ CHECK_EQ(BUILDING, state_); |
+ RawMachineAssembler::Label pass; |
+ assembler_->Branch( |
+ assembler_->IntPtrEqual(assembler_->Load(kMachIntPtr, FromId(value_id)), |
+ assembler_->IntPtrConstant(0)), |
+ &pass, FromId(label_id)); |
+ assembler_->Bind(&pass); |
+} |
+ |
+ |
+Handle<Code> FastAccessorAssembler::Build() { |
+ CHECK_EQ(BUILDING, state_); |
+ |
+ // Cleanup: We no longer need this. |
+ nodes_.clear(); |
+ labels_.clear(); |
+ |
+ // Export the schedule and call the compiler. |
+ CompilationInfo info("FastAccessorAssembler", assembler_->isolate(), zone()); |
+ Schedule* schedule = assembler_->Export(); |
+ Handle<Code> code = Pipeline::GenerateCodeForTesting( |
+ &info, assembler_->call_descriptor(), assembler_->graph(), schedule); |
+ |
+ // Update state & return. |
+ state_ = !code.is_null() ? BUILT : ERROR; |
+ return code; |
+} |
+ |
+ |
+FastAccessorAssembler::ValueId FastAccessorAssembler::FromRaw(Node* node) { |
+ nodes_.push_back(node); |
+ ValueId value = {nodes_.size() - 1}; |
+ return value; |
+} |
+ |
+ |
+FastAccessorAssembler::LabelId FastAccessorAssembler::FromRaw( |
+ RawMachineAssembler::Label* label) { |
+ labels_.push_back(label); |
+ LabelId label_id = {labels_.size() - 1}; |
+ return label_id; |
+} |
+ |
+ |
+Node* FastAccessorAssembler::FromId( |
+ FastAccessorAssembler::ValueId value) const { |
+ CHECK_LT(value.value_id, nodes_.size()); |
+ CHECK_NOT_NULL(nodes_.at(value.value_id)); |
+ return nodes_.at(value.value_id); |
+} |
+ |
+ |
+RawMachineAssembler::Label* FastAccessorAssembler::FromId( |
+ FastAccessorAssembler::LabelId label) const { |
+ CHECK_LT(label.label_id, labels_.size()); |
+ CHECK_NOT_NULL(labels_.at(label.label_id)); |
+ return labels_.at(label.label_id); |
+} |
+ |
+ |
+} // namespace compiler |
+} // namespace internal |
+} // namespace v8 |