Commit df2fc5ef authored by ishell's avatar ishell Committed by Commit bot

[turbofan] Move CodeAssembler::Label and CodeAssembler::Variable to compiler namespace.

This allows us to forward declare Label and Variable classes without including the
code-assembler.h.

BUG=

Review-Url: https://codereview.chromium.org/2551163003
Cr-Commit-Position: refs/heads/master@{#41509}
parent 7a6f294f
......@@ -8,6 +8,7 @@
#include "src/bailout-reason.h"
#include "src/code-factory.h"
#include "src/code-stub-assembler.h"
#include "src/crankshaft/hydrogen.h"
#include "src/crankshaft/lithium.h"
#include "src/field-index.h"
......
......@@ -7,7 +7,6 @@
#include "src/allocation.h"
#include "src/assembler.h"
#include "src/code-stub-assembler.h"
#include "src/codegen.h"
#include "src/globals.h"
#include "src/ic/ic-state.h"
......@@ -19,7 +18,14 @@
namespace v8 {
namespace internal {
// Forward declarations.
class CodeStubAssembler;
class ObjectLiteral;
namespace compiler {
class CodeAssemblerLabel;
class CodeAssemblerState;
class Node;
}
// List of code stubs used on all platforms.
#define CODE_STUB_LIST_ALL_PLATFORMS(V) \
......@@ -925,7 +931,7 @@ class FastCloneShallowArrayStub : public TurboFanCodeStub {
compiler::Node* closure,
compiler::Node* literal_index,
compiler::Node* context,
CodeStubAssembler::Label* call_runtime,
compiler::CodeAssemblerLabel* call_runtime,
AllocationSiteMode allocation_site_mode);
AllocationSiteMode allocation_site_mode() const {
......@@ -952,9 +958,9 @@ class FastCloneShallowObjectStub : public TurboFanCodeStub {
}
static compiler::Node* GenerateFastPath(
CodeStubAssembler* assembler,
compiler::CodeAssembler::Label* call_runtime, compiler::Node* closure,
compiler::Node* literals_index, compiler::Node* properties_count);
CodeStubAssembler* assembler, compiler::CodeAssemblerLabel* call_runtime,
compiler::Node* closure, compiler::Node* literals_index,
compiler::Node* properties_count);
static bool IsSupported(ObjectLiteral* expr);
static int PropertiesCount(int literal_length);
......
......@@ -217,7 +217,7 @@ void CodeAssembler::Comment(const char* format, ...) {
raw_assembler()->Comment(copy);
}
void CodeAssembler::Bind(CodeAssembler::Label* label) { return label->Bind(); }
void CodeAssembler::Bind(Label* label) { return label->Bind(); }
Node* CodeAssembler::LoadFramePointer() {
return raw_assembler()->LoadFramePointer();
......@@ -993,7 +993,7 @@ Node* CodeAssembler::CallCFunction2(MachineType return_type,
function, arg0, arg1);
}
void CodeAssembler::Goto(CodeAssembler::Label* label) {
void CodeAssembler::Goto(Label* label) {
label->MergeVariables();
raw_assembler()->Goto(label->label_);
}
......@@ -1010,8 +1010,8 @@ void CodeAssembler::GotoUnless(Node* condition, Label* false_label) {
Bind(&true_label);
}
void CodeAssembler::Branch(Node* condition, CodeAssembler::Label* true_label,
CodeAssembler::Label* false_label) {
void CodeAssembler::Branch(Node* condition, Label* true_label,
Label* false_label) {
true_label->MergeVariables();
false_label->MergeVariables();
return raw_assembler()->Branch(condition, true_label->label_,
......@@ -1048,41 +1048,41 @@ RawMachineAssembler* CodeAssembler::raw_assembler() const {
// that it can outlive the often block-scoped Variable declarations. This is
// needed to ensure that variable binding and merging through phis can
// properly be verified.
class CodeAssembler::Variable::Impl : public ZoneObject {
class CodeAssemblerVariable::Impl : public ZoneObject {
public:
explicit Impl(MachineRepresentation rep) : value_(nullptr), rep_(rep) {}
Node* value_;
MachineRepresentation rep_;
};
CodeAssembler::Variable::Variable(CodeAssembler* assembler,
MachineRepresentation rep)
: impl_(new (assembler->zone()) Impl(rep)), state_(assembler->state_) {
CodeAssemblerVariable::CodeAssemblerVariable(CodeAssembler* assembler,
MachineRepresentation rep)
: impl_(new (assembler->zone()) Impl(rep)), state_(assembler->state()) {
state_->variables_.insert(impl_);
}
CodeAssembler::Variable::~Variable() { state_->variables_.erase(impl_); }
CodeAssemblerVariable::~CodeAssemblerVariable() {
state_->variables_.erase(impl_);
}
void CodeAssembler::Variable::Bind(Node* value) { impl_->value_ = value; }
void CodeAssemblerVariable::Bind(Node* value) { impl_->value_ = value; }
Node* CodeAssembler::Variable::value() const {
Node* CodeAssemblerVariable::value() const {
DCHECK_NOT_NULL(impl_->value_);
return impl_->value_;
}
MachineRepresentation CodeAssembler::Variable::rep() const {
return impl_->rep_;
}
MachineRepresentation CodeAssemblerVariable::rep() const { return impl_->rep_; }
bool CodeAssembler::Variable::IsBound() const {
return impl_->value_ != nullptr;
}
bool CodeAssemblerVariable::IsBound() const { return impl_->value_ != nullptr; }
CodeAssembler::Label::Label(CodeAssembler* assembler, size_t vars_count,
Variable** vars, CodeAssembler::Label::Type type)
CodeAssemblerLabel::CodeAssemblerLabel(CodeAssembler* assembler,
size_t vars_count,
CodeAssemblerVariable** vars,
CodeAssemblerLabel::Type type)
: bound_(false),
merge_count_(0),
state_(assembler->state_),
state_(assembler->state()),
label_(nullptr) {
void* buffer = assembler->zone()->New(sizeof(RawMachineLabel));
label_ = new (buffer)
......@@ -1093,7 +1093,7 @@ CodeAssembler::Label::Label(CodeAssembler* assembler, size_t vars_count,
}
}
void CodeAssembler::Label::MergeVariables() {
void CodeAssemblerLabel::MergeVariables() {
++merge_count_;
for (auto var : state_->variables_) {
size_t count = 0;
......@@ -1139,7 +1139,7 @@ void CodeAssembler::Label::MergeVariables() {
}
}
void CodeAssembler::Label::Bind() {
void CodeAssemblerLabel::Bind() {
DCHECK(!bound_);
state_->raw_assembler_->Bind(label_);
......@@ -1163,7 +1163,7 @@ void CodeAssembler::Label::Bind() {
}
for (auto var : variable_phis_) {
CodeAssembler::Variable::Impl* var_impl = var.first;
CodeAssemblerVariable::Impl* var_impl = var.first;
auto i = variable_merges_.find(var_impl);
// If the following assert fires, then a variable that has been marked as
// being merged at the label--either by explicitly marking it so in the
......
......@@ -30,11 +30,15 @@ class Zone;
namespace compiler {
class CallDescriptor;
class CodeAssemblerLabel;
class CodeAssemblerVariable;
class CodeAssemblerState;
class Node;
class RawMachineAssembler;
class RawMachineLabel;
typedef ZoneList<CodeAssemblerVariable*> CodeAssemblerVariableList;
#define CODE_ASSEMBLER_COMPARE_BINARY_OP_LIST(V) \
V(Float32Equal) \
V(Float32LessThan) \
......@@ -194,25 +198,10 @@ class V8_EXPORT_PRIVATE CodeAssembler {
bool IsFloat64RoundTiesEvenSupported() const;
bool IsFloat64RoundTruncateSupported() const;
class Label;
class Variable {
public:
explicit Variable(CodeAssembler* assembler, MachineRepresentation rep);
~Variable();
void Bind(Node* value);
Node* value() const;
MachineRepresentation rep() const;
bool IsBound() const;
private:
friend class CodeAssembler;
friend class CodeAssemblerState;
class Impl;
Impl* impl_;
CodeAssemblerState* state_;
};
typedef ZoneList<Variable*> VariableList;
// Shortened aliases for use in CodeAssembler subclasses.
typedef CodeAssemblerLabel Label;
typedef CodeAssemblerVariable Variable;
typedef CodeAssemblerVariableList VariableList;
// ===========================================================================
// Base Assembler
......@@ -463,6 +452,8 @@ class V8_EXPORT_PRIVATE CodeAssembler {
Isolate* isolate() const;
Zone* zone() const;
CodeAssemblerState* state() { return state_; }
protected:
// Enables subclasses to perform operations before and after a call.
virtual void CallPrologue();
......@@ -479,24 +470,46 @@ class V8_EXPORT_PRIVATE CodeAssembler {
DISALLOW_COPY_AND_ASSIGN(CodeAssembler);
};
class CodeAssembler::Label {
class CodeAssemblerVariable {
public:
explicit CodeAssemblerVariable(CodeAssembler* assembler,
MachineRepresentation rep);
~CodeAssemblerVariable();
void Bind(Node* value);
Node* value() const;
MachineRepresentation rep() const;
bool IsBound() const;
private:
friend class CodeAssemblerLabel;
friend class CodeAssemblerState;
class Impl;
Impl* impl_;
CodeAssemblerState* state_;
};
class CodeAssemblerLabel {
public:
enum Type { kDeferred, kNonDeferred };
explicit Label(
explicit CodeAssemblerLabel(
CodeAssembler* assembler,
CodeAssemblerLabel::Type type = CodeAssemblerLabel::kNonDeferred)
: CodeAssemblerLabel(assembler, 0, nullptr, type) {}
CodeAssemblerLabel(
CodeAssembler* assembler,
CodeAssembler::Label::Type type = CodeAssembler::Label::kNonDeferred)
: CodeAssembler::Label(assembler, 0, nullptr, type) {}
Label(CodeAssembler* assembler, const VariableList& merged_variables,
CodeAssembler::Label::Type type = CodeAssembler::Label::kNonDeferred)
: CodeAssembler::Label(assembler, merged_variables.length(),
&(merged_variables[0]), type) {}
Label(CodeAssembler* assembler, size_t count, Variable** vars,
CodeAssembler::Label::Type type = CodeAssembler::Label::kNonDeferred);
Label(CodeAssembler* assembler, CodeAssembler::Variable* merged_variable,
CodeAssembler::Label::Type type = CodeAssembler::Label::kNonDeferred)
: Label(assembler, 1, &merged_variable, type) {}
~Label() {}
const CodeAssemblerVariableList& merged_variables,
CodeAssemblerLabel::Type type = CodeAssemblerLabel::kNonDeferred)
: CodeAssemblerLabel(assembler, merged_variables.length(),
&(merged_variables[0]), type) {}
CodeAssemblerLabel(
CodeAssembler* assembler, size_t count, CodeAssemblerVariable** vars,
CodeAssemblerLabel::Type type = CodeAssemblerLabel::kNonDeferred);
CodeAssemblerLabel(
CodeAssembler* assembler, CodeAssemblerVariable* merged_variable,
CodeAssemblerLabel::Type type = CodeAssemblerLabel::kNonDeferred)
: CodeAssemblerLabel(assembler, 1, &merged_variable, type) {}
~CodeAssemblerLabel() {}
private:
friend class CodeAssembler;
......@@ -510,10 +523,10 @@ class CodeAssembler::Label {
RawMachineLabel* label_;
// Map of variables that need to be merged to their phi nodes (or placeholders
// for those phis).
std::map<Variable::Impl*, Node*> variable_phis_;
std::map<CodeAssemblerVariable::Impl*, Node*> variable_phis_;
// Map of variables to the list of value nodes that have been added from each
// merge path in their order of merging.
std::map<Variable::Impl*, std::vector<Node*>> variable_merges_;
std::map<CodeAssemblerVariable::Impl*, std::vector<Node*>> variable_merges_;
};
class V8_EXPORT_PRIVATE CodeAssemblerState {
......@@ -534,6 +547,8 @@ class V8_EXPORT_PRIVATE CodeAssemblerState {
private:
friend class CodeAssembler;
friend class CodeAssemblerLabel;
friend class CodeAssemblerVariable;
CodeAssemblerState(Isolate* isolate, Zone* zone,
CallDescriptor* call_descriptor, Code::Flags flags,
......@@ -543,7 +558,7 @@ class V8_EXPORT_PRIVATE CodeAssemblerState {
Code::Flags flags_;
const char* name_;
bool code_generated_;
ZoneSet<CodeAssembler::Variable::Impl*> variables_;
ZoneSet<CodeAssemblerVariable::Impl*> variables_;
DISALLOW_COPY_AND_ASSIGN(CodeAssemblerState);
};
......
......@@ -215,8 +215,8 @@ TEST(VariableMerge1) {
Isolate* isolate(CcTest::InitIsolateOnce());
CodeAssemblerTester data(isolate);
CodeAssembler m(data.state());
CodeStubAssembler::Variable var1(&m, MachineRepresentation::kTagged);
CodeStubAssembler::Label l1(&m), l2(&m), merge(&m);
CodeAssemblerVariable var1(&m, MachineRepresentation::kTagged);
CodeAssemblerLabel l1(&m), l2(&m), merge(&m);
Node* temp = m.Int32Constant(0);
var1.Bind(temp);
m.Branch(m.Int32Constant(1), &l1, &l2);
......@@ -234,8 +234,8 @@ TEST(VariableMerge2) {
Isolate* isolate(CcTest::InitIsolateOnce());
CodeAssemblerTester data(isolate);
CodeAssembler m(data.state());
CodeStubAssembler::Variable var1(&m, MachineRepresentation::kTagged);
CodeStubAssembler::Label l1(&m), l2(&m), merge(&m);
CodeAssemblerVariable var1(&m, MachineRepresentation::kTagged);
CodeAssemblerLabel l1(&m), l2(&m), merge(&m);
Node* temp = m.Int32Constant(0);
var1.Bind(temp);
m.Branch(m.Int32Constant(1), &l1, &l2);
......@@ -255,9 +255,9 @@ TEST(VariableMerge3) {
Isolate* isolate(CcTest::InitIsolateOnce());
CodeAssemblerTester data(isolate);
CodeAssembler m(data.state());
CodeStubAssembler::Variable var1(&m, MachineRepresentation::kTagged);
CodeStubAssembler::Variable var2(&m, MachineRepresentation::kTagged);
CodeStubAssembler::Label l1(&m), l2(&m), merge(&m);
CodeAssemblerVariable var1(&m, MachineRepresentation::kTagged);
CodeAssemblerVariable var2(&m, MachineRepresentation::kTagged);
CodeAssemblerLabel l1(&m), l2(&m), merge(&m);
Node* temp = m.Int32Constant(0);
var1.Bind(temp);
var2.Bind(temp);
......@@ -280,8 +280,8 @@ TEST(VariableMergeBindFirst) {
Isolate* isolate(CcTest::InitIsolateOnce());
CodeAssemblerTester data(isolate);
CodeAssembler m(data.state());
CodeStubAssembler::Variable var1(&m, MachineRepresentation::kTagged);
CodeStubAssembler::Label l1(&m), l2(&m), merge(&m, &var1), end(&m);
CodeAssemblerVariable var1(&m, MachineRepresentation::kTagged);
CodeAssemblerLabel l1(&m), l2(&m), merge(&m, &var1), end(&m);
Node* temp = m.Int32Constant(0);
var1.Bind(temp);
m.Branch(m.Int32Constant(1), &l1, &l2);
......@@ -306,9 +306,9 @@ TEST(VariableMergeSwitch) {
Isolate* isolate(CcTest::InitIsolateOnce());
CodeAssemblerTester data(isolate);
CodeAssembler m(data.state());
CodeStubAssembler::Variable var1(&m, MachineRepresentation::kTagged);
CodeStubAssembler::Label l1(&m), l2(&m), default_label(&m);
CodeStubAssembler::Label* labels[] = {&l1, &l2};
CodeAssemblerVariable var1(&m, MachineRepresentation::kTagged);
CodeAssemblerLabel l1(&m), l2(&m), default_label(&m);
CodeAssemblerLabel* labels[] = {&l1, &l2};
int32_t values[] = {1, 2};
Node* temp = m.Int32Constant(0);
var1.Bind(temp);
......@@ -328,7 +328,7 @@ TEST(SplitEdgeBranchMerge) {
Isolate* isolate(CcTest::InitIsolateOnce());
CodeAssemblerTester data(isolate);
CodeAssembler m(data.state());
CodeStubAssembler::Label l1(&m), merge(&m);
CodeAssemblerLabel l1(&m), merge(&m);
m.Branch(m.Int32Constant(1), &l1, &merge);
m.Bind(&l1);
m.Goto(&merge);
......@@ -340,8 +340,8 @@ TEST(SplitEdgeSwitchMerge) {
Isolate* isolate(CcTest::InitIsolateOnce());
CodeAssemblerTester data(isolate);
CodeAssembler m(data.state());
CodeStubAssembler::Label l1(&m), l2(&m), l3(&m), default_label(&m);
CodeStubAssembler::Label* labels[] = {&l1, &l2};
CodeAssemblerLabel l1(&m), l2(&m), l3(&m), default_label(&m);
CodeAssemblerLabel* labels[] = {&l1, &l2};
int32_t values[] = {1, 2};
m.Branch(m.Int32Constant(1), &l3, &l1);
m.Bind(&l3);
......@@ -383,8 +383,8 @@ TEST(TestToConstant) {
TEST(DeferredCodePhiHints) {
typedef compiler::Node Node;
typedef CodeStubAssembler::Label Label;
typedef CodeStubAssembler::Variable Variable;
typedef CodeAssemblerLabel Label;
typedef CodeAssemblerVariable Variable;
Isolate* isolate(CcTest::InitIsolateOnce());
CodeAssemblerTester data(isolate);
CodeAssembler m(data.state());
......@@ -407,8 +407,8 @@ TEST(DeferredCodePhiHints) {
}
TEST(TestOutOfScopeVariable) {
typedef CodeStubAssembler::Label Label;
typedef CodeStubAssembler::Variable Variable;
typedef CodeAssemblerLabel Label;
typedef CodeAssemblerVariable Variable;
Isolate* isolate(CcTest::InitIsolateOnce());
CodeAssemblerTester data(isolate);
CodeAssembler m(data.state());
......
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