Chromium Code Reviews| 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..f4371d486bab1f7a52ff8f4b6ba1109146241925 |
| --- /dev/null |
| +++ b/src/compiler/fast-accessor-assembler.cc |
| @@ -0,0 +1,123 @@ |
| +// 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" |
| + |
| +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_(BUILDING) {} |
| + |
| + |
| +FastAccessorAssembler::~FastAccessorAssembler() {} |
| + |
| + |
| +FastAccessorAssembler::ValueId FastAccessorAssembler::IntegerConstant( |
| + int const_value) { |
| + CHECK_EQ(BUILDING, state_); |
| + return FromNode(assembler_->NumberConstant(const_value)); |
| +} |
| + |
| + |
| +FastAccessorAssembler::ValueId FastAccessorAssembler::GetParameter( |
| + size_t parameter_no) { |
| + CHECK_EQ(BUILDING, state_); |
| + return FromNode(assembler_->Parameter(parameter_no)); |
| +} |
| + |
| + |
| +FastAccessorAssembler::ValueId FastAccessorAssembler::LoadValue( |
| + FastAccessorAssembler::ValueId value, int offset) { |
| + CHECK_EQ(BUILDING, state_); |
| + return FromNode(assembler_->Load(kMachIntPtr, FromValue(value), |
| + assembler_->IntPtrConstant(offset))); |
| +} |
| + |
| + |
| +void FastAccessorAssembler::ReturnValue(ValueId value) { |
| + assembler_->Return(FromValue(value)); |
| +} |
| + |
| + |
| +void FastAccessorAssembler::CheckNotNullOrReturnNull(ValueId value) { |
| + CHECK_EQ(BUILDING, state_); |
| + RawMachineAssembler::Label pass, fail; |
| + assembler_->Branch( |
| + assembler_->IntPtrEqual(assembler_->Load(kMachIntPtr, FromValue(value)), |
| + assembler_->IntPtrConstant(0)), |
| + &pass, &fail); |
| + assembler_->Bind(&fail); |
| + assembler_->Return(assembler_->NullConstant()); |
| + assembler_->Bind(&pass); |
| +} |
| + |
| + |
| +Handle<Code> FastAccessorAssembler::Build() { |
| + CHECK_EQ(BUILDING, state_); |
| + |
| + // Cleanup: We no longer need this memory. |
| + nodes_.clear(); |
|
epertoso
2015/11/25 10:31:15
These two calls to clear() don't do what you seem
vogelheim
2015/11/26 14:41:43
You're technically correct... :-)
Well.. I'm tryi
|
| + labels_.clear(); |
| + |
| + // Export the schedule and call the compiler. |
| + CompilationInfo info("FastAccessorAssembler", assembler_->isolate(), zone()); |
| + Schedule* schedule = assembler_->Export(); |
| + Handle<Code> code = Pipeline::GenerateCodeForTesting( |
|
epertoso
2015/11/25 10:31:15
nit: add a TODO here, we should probably not use a
vogelheim
2015/11/26 14:41:43
Yes. src/compiler/* owners will have an opinion on
|
| + &info, assembler_->call_descriptor(), assembler_->graph(), schedule); |
| + |
| + { |
| + OFStream os(stdout); |
| + os << "schedule\n" << *schedule; |
| + os << "code\n"; |
| + code->Print(); |
| + } |
| + |
| + // Update state & return. |
| + state_ = !code.is_null() ? BUILT : ERROR; |
| + return code; |
| +} |
| + |
| + |
| +CallDescriptor* FastAccessorAssembler::GetCallDescriptor() const { |
| + CHECK_EQ(BUILT, state_); |
| + return assembler_->call_descriptor(); |
| +} |
| + |
| + |
| +FastAccessorAssembler::ValueId FastAccessorAssembler::FromNode(Node* node) { |
| + if (labels_.size() > nodes_.size()) { |
| + nodes_.resize(labels_.size(), nullptr); |
|
epertoso
2015/11/25 10:31:15
Why?
vogelheim
2015/11/26 14:41:43
So... I'm trying to hide the RawMachineAssembler i
|
| + } |
| + |
| + nodes_.push_back(node); |
| + return nodes_.size() - 1; |
| +} |
| + |
| + |
| +Node* FastAccessorAssembler::FromValue( |
| + FastAccessorAssembler::ValueId value) const { |
| + CHECK_LT(value, nodes_.size()); |
| + CHECK_NOT_NULL(nodes_.at(value)); |
| + return nodes_.at(value); |
| +} |
| + |
| +} // namespace compiler |
| +} // namespace internal |
| +} // namespace v8 |