Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Unified Diff: src/compiler/fast-accessor-assembler.cc

Issue 1474543004: Implement Fast Accessor Builder (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Add tests for load ops. Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..a3b4f70634b17816fde1d111cddccd3f8eefcb6d
--- /dev/null
+++ b/src/compiler/fast-accessor-assembler.cc
@@ -0,0 +1,190 @@
+// 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,
+ CallDescriptor::kNoFlags))),
+ state_(kBuilding) {}
+
+
+FastAccessorAssembler::~FastAccessorAssembler() {}
+
+
+FastAccessorAssembler::ValueId FastAccessorAssembler::IntegerConstant(
+ int const_value) {
+ CHECK_EQ(kBuilding, state_);
+ return FromRaw(assembler_->NumberConstant(const_value));
+}
+
+
+FastAccessorAssembler::ValueId FastAccessorAssembler::GetCallTarget() {
+ CHECK_EQ(kBuilding, state_);
+
+ // For JS call descriptor, we can assume that the call target / 'this' pointer
Michael Starzinger 2015/12/02 19:28:06 We need to use internal nomenclature here, otherwi
vogelheim 2015/12/03 13:10:31 Done.
+ // is parameter 0. If we use other call descriptors, this may or may not hold.
+ // So let's check.
+ CHECK(assembler_->call_descriptor()->IsJSFunctionCall());
+ return FromRaw(assembler_->Parameter(0));
+}
+
+
+FastAccessorAssembler::ValueId FastAccessorAssembler::GetInternalField(
Michael Starzinger 2015/12/02 19:28:06 nit: How would you feel about s/GetInternalField/L
vogelheim 2015/12/03 13:10:31 Done.
+ ValueId value, int field_no) {
+ CHECK_EQ(kBuilding, state_);
+ return FromRaw(assembler_->Load(
+ kMachPtr, FromId(value),
+ assembler_->IntPtrConstant(JSObject::kHeaderSize - kHeapObjectTag +
Michael Starzinger 2015/12/02 19:28:06 This calculation is only correct for JSObject, for
vogelheim 2015/12/03 13:10:31 Changed to check for JSObject, and to return Undef
+ kPointerSize * field_no)));
+}
+
+
+FastAccessorAssembler::ValueId FastAccessorAssembler::LoadValue(
+ FastAccessorAssembler::ValueId value, int offset) {
+ CHECK_EQ(kBuilding, state_);
+ return FromRaw(assembler_->Load(kMachIntPtr, FromId(value),
+ assembler_->IntPtrConstant(offset)));
+}
+
+
+FastAccessorAssembler::ValueId FastAccessorAssembler::LoadObject(
+ FastAccessorAssembler::ValueId value, int offset) {
+ CHECK_EQ(kBuilding, state_);
+ return FromRaw(assembler_->Load(
+ kMachAnyTagged, assembler_->Load(kMachPtr, FromId(value),
+ assembler_->IntPtrConstant(offset))));
+}
+
+
+void FastAccessorAssembler::ReturnValue(ValueId value) {
+ CHECK_EQ(kBuilding, state_);
+ assembler_->Return(FromId(value));
+}
+
+
+void FastAccessorAssembler::CheckFlagSetOrReturnNull(
+ FastAccessorAssembler::ValueId value, int mask) {
+ CHECK_EQ(kBuilding, state_);
+ RawMachineLabel pass, fail;
+ assembler_->Branch(
+ assembler_->Word32Equal(
+ assembler_->Word32And(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) {
Michael Starzinger 2015/12/02 19:28:06 One "null" is more "null" than the other "null" ..
vogelheim 2015/12/03 13:10:31 Done.
+ CHECK_EQ(kBuilding, state_);
+ RawMachineLabel is_null, not_null;
+ assembler_->Branch(
+ assembler_->IntPtrEqual(FromId(value), assembler_->IntPtrConstant(0)),
+ &is_null, &not_null);
+ assembler_->Bind(&is_null);
+ assembler_->Return(assembler_->NullConstant());
+ assembler_->Bind(&not_null);
+}
+
+
+FastAccessorAssembler::LabelId FastAccessorAssembler::MakeLabel() {
+ CHECK_EQ(kBuilding, state_);
+ RawMachineLabel* label = new RawMachineLabel;
Michael Starzinger 2015/12/02 19:28:06 Can we allocate the Labels in our Zone please? Oth
vogelheim 2015/12/03 13:10:31 Done.
+ return FromRaw(label);
+}
+
+
+void FastAccessorAssembler::SetLabel(LabelId label_id) {
+ CHECK_EQ(kBuilding, state_);
+ assembler_->Bind(FromId(label_id));
+}
+
+
+void FastAccessorAssembler::CheckNotNullOrJump(ValueId value_id,
Michael Starzinger 2015/12/02 19:28:06 Likewise s/CheckNotNullOrJump/CheckNotZeroOrJump/
vogelheim 2015/12/03 13:10:31 Done.
+ LabelId label_id) {
+ CHECK_EQ(kBuilding, state_);
+ RawMachineLabel pass;
+ assembler_->Branch(
+ assembler_->IntPtrEqual(FromId(value_id), assembler_->IntPtrConstant(0)),
+ &pass, FromId(label_id));
+ assembler_->Bind(&pass);
+}
+
+
+MaybeHandle<Code> FastAccessorAssembler::Build() {
+ CHECK_EQ(kBuilding, state_);
+
+ // Cleanup: We no longer need this.
+ nodes_.clear();
+ for (auto label : labels_) {
+ delete label;
Michael Starzinger 2015/12/02 19:28:06 See comment above, please allocate in Zone and don
vogelheim 2015/12/03 13:10:31 Done.
+ }
+ labels_.clear();
+
+ // Export the schedule and call the compiler.
+ CompilationInfo info("FastAccessorAssembler", assembler_->isolate(), zone());
+ Schedule* schedule = assembler_->Export();
+ MaybeHandle<Code> code = Pipeline::GenerateCodeForTesting(
Michael Starzinger 2015/12/02 19:28:06 This definitely needs a big fat TODO that we shoul
vogelheim 2015/12/03 13:10:31 Done.
+ &info, assembler_->call_descriptor(), assembler_->graph(), schedule);
+
+ // Update state & return.
+ state_ = !code.is_null() ? kBuilt : kError;
+ 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) {
+ 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);
+}
+
+
+RawMachineLabel* 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

Powered by Google App Engine
This is Rietveld 408576698