Commit 0e16150d authored by rossberg@chromium.org's avatar rossberg@chromium.org

Better typing and type verification

- Extend verifier to check types of JS and Simplified nodes.
- Untyped nodes now contain NULL as types, enforcing hard failure.
- Typer immediately installs itself as a decorator; remove explicit decorator installation.
- Decorator eagerly types all nodes that have typed inputs
  (subsumes typing of constant cache, removing its typing
  side-channel and various spurious dependencies on the typer).
- Cut down typer interface to prevent inconsistently typed graphs.
- Remove verification from start, since it caused too much trouble
  with semi-wellformed nodes.
- Fix a couple of bugs on the way that got uncovered.

To do: verifying machine operators. Also, various conditions in the
verifier are currently commented out, because they don't yet hold.

BUG=
R=jarin@chromium.org,titzer@chromium.org

Review URL: https://codereview.chromium.org/658543002

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@24626 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 46db2f9b
......@@ -23,7 +23,8 @@ GenericNode<B, S>::GenericNode(GenericGraphBase* graph, int input_count)
use_count_(0),
first_use_(NULL),
last_use_(NULL) {
inputs_.static_ = reinterpret_cast<Input*>(this + 1), AssignUniqueID(graph);
inputs_.static_ = reinterpret_cast<Input*>(this + 1);
AssignUniqueID(graph);
}
template <class B, class S>
......
......@@ -167,7 +167,7 @@ Node* StructuredGraphBuilder::NewPhi(int count, Node* input, Node* control) {
Node** buffer = local_zone()->NewArray<Node*>(count + 1);
MemsetPointer(buffer, input, count);
buffer[count] = control;
return graph()->NewNode(phi_op, count + 1, buffer);
return graph()->NewNode(phi_op, count + 1, buffer, true);
}
......@@ -178,7 +178,7 @@ Node* StructuredGraphBuilder::NewEffectPhi(int count, Node* input,
Node** buffer = local_zone()->NewArray<Node*>(count + 1);
MemsetPointer(buffer, input, count);
buffer[count] = control;
return graph()->NewNode(phi_op, count + 1, buffer);
return graph()->NewNode(phi_op, count + 1, buffer, true);
}
......
......@@ -299,7 +299,7 @@ void GraphVisualizer::AnnotateNode(Node* node) {
}
os_ << "}";
if (FLAG_trace_turbo_types && !NodeProperties::IsControl(node)) {
if (FLAG_trace_turbo_types && NodeProperties::IsTyped(node)) {
Bounds bounds = NodeProperties::GetBounds(node);
std::ostringstream upper;
bounds.upper->PrintTo(upper);
......
......@@ -21,14 +21,20 @@ namespace compiler {
Graph::Graph(Zone* zone) : GenericGraph<Node>(zone), decorators_(zone) {}
Node* Graph::NewNode(const Operator* op, int input_count, Node** inputs) {
DCHECK_LE(op->InputCount(), input_count);
Node* result = Node::New(this, input_count, inputs);
result->Initialize(op);
void Graph::Decorate(Node* node) {
for (ZoneVector<GraphDecorator*>::iterator i = decorators_.begin();
i != decorators_.end(); ++i) {
(*i)->Decorate(result);
(*i)->Decorate(node);
}
}
Node* Graph::NewNode(
const Operator* op, int input_count, Node** inputs, bool incomplete) {
DCHECK_LE(op->InputCount(), input_count);
Node* result = Node::New(this, input_count, inputs);
result->Initialize(op);
if (!incomplete) Decorate(result);
return result;
}
......
......@@ -25,7 +25,8 @@ class Graph : public GenericGraph<Node> {
explicit Graph(Zone* zone);
// Base implementation used by all factory methods.
Node* NewNode(const Operator* op, int input_count, Node** inputs);
Node* NewNode(const Operator* op, int input_count, Node** inputs,
bool incomplete = false);
// Factories for nodes with static input counts.
Node* NewNode(const Operator* op) {
......@@ -64,6 +65,8 @@ class Graph : public GenericGraph<Node> {
template <class Visitor>
void VisitNodeInputsFromEnd(Visitor* visitor);
void Decorate(Node* node);
void AddDecorator(GraphDecorator* decorator) {
decorators_.push_back(decorator);
}
......
......@@ -12,14 +12,7 @@ namespace compiler {
Node* JSGraph::ImmovableHeapConstant(Handle<HeapObject> object) {
Unique<HeapObject> unique = Unique<HeapObject>::CreateImmovable(object);
return NewNode(common()->HeapConstant(unique));
}
Node* JSGraph::NewNode(const Operator* op) {
Node* node = graph()->NewNode(op);
typer_->Init(node);
return node;
return graph()->NewNode(common()->HeapConstant(unique));
}
......@@ -95,7 +88,7 @@ Node* JSGraph::NaNConstant() {
Node* JSGraph::HeapConstant(Unique<HeapObject> value) {
// TODO(turbofan): canonicalize heap constants using Unique<T>
return NewNode(common()->HeapConstant(value));
return graph()->NewNode(common()->HeapConstant(value));
}
......@@ -151,7 +144,7 @@ Node* JSGraph::Constant(int32_t value) {
Node* JSGraph::Int32Constant(int32_t value) {
Node** loc = cache_.FindInt32Constant(value);
if (*loc == NULL) {
*loc = NewNode(common()->Int32Constant(value));
*loc = graph()->NewNode(common()->Int32Constant(value));
}
return *loc;
}
......@@ -160,7 +153,7 @@ Node* JSGraph::Int32Constant(int32_t value) {
Node* JSGraph::Int64Constant(int64_t value) {
Node** loc = cache_.FindInt64Constant(value);
if (*loc == NULL) {
*loc = NewNode(common()->Int64Constant(value));
*loc = graph()->NewNode(common()->Int64Constant(value));
}
return *loc;
}
......@@ -169,7 +162,7 @@ Node* JSGraph::Int64Constant(int64_t value) {
Node* JSGraph::NumberConstant(double value) {
Node** loc = cache_.FindNumberConstant(value);
if (*loc == NULL) {
*loc = NewNode(common()->NumberConstant(value));
*loc = graph()->NewNode(common()->NumberConstant(value));
}
return *loc;
}
......@@ -177,14 +170,14 @@ Node* JSGraph::NumberConstant(double value) {
Node* JSGraph::Float32Constant(float value) {
// TODO(turbofan): cache float32 constants.
return NewNode(common()->Float32Constant(value));
return graph()->NewNode(common()->Float32Constant(value));
}
Node* JSGraph::Float64Constant(double value) {
Node** loc = cache_.FindFloat64Constant(value);
if (*loc == NULL) {
*loc = NewNode(common()->Float64Constant(value));
*loc = graph()->NewNode(common()->Float64Constant(value));
}
return *loc;
}
......@@ -193,7 +186,7 @@ Node* JSGraph::Float64Constant(double value) {
Node* JSGraph::ExternalConstant(ExternalReference reference) {
Node** loc = cache_.FindExternalConstant(reference);
if (*loc == NULL) {
*loc = NewNode(common()->ExternalConstant(reference));
*loc = graph()->NewNode(common()->ExternalConstant(reference));
}
return *loc;
}
......
......@@ -24,12 +24,10 @@ class Typer;
class JSGraph : public ZoneObject {
public:
JSGraph(Graph* graph, CommonOperatorBuilder* common,
JSOperatorBuilder* javascript, Typer* typer,
MachineOperatorBuilder* machine)
JSOperatorBuilder* javascript, MachineOperatorBuilder* machine)
: graph_(graph),
common_(common),
javascript_(javascript),
typer_(typer),
machine_(machine),
cache_(zone()) {}
......@@ -109,7 +107,6 @@ class JSGraph : public ZoneObject {
Graph* graph_;
CommonOperatorBuilder* common_;
JSOperatorBuilder* javascript_;
Typer* typer_;
MachineOperatorBuilder* machine_;
SetOncePointer<Node> c_entry_stub_constant_;
......@@ -126,7 +123,6 @@ class JSGraph : public ZoneObject {
Node* ImmovableHeapConstant(Handle<HeapObject> value);
Node* NumberConstant(double value);
Node* NewNode(const Operator* op);
Factory* factory() { return isolate()->factory(); }
};
......
......@@ -410,8 +410,7 @@ void JSInliner::TryInlineCall(Node* call_node) {
}
Graph graph(info.zone());
Typer typer(info.zone());
JSGraph jsgraph(&graph, jsgraph_->common(), jsgraph_->javascript(), &typer,
JSGraph jsgraph(&graph, jsgraph_->common(), jsgraph_->javascript(),
jsgraph_->machine());
AstGraphBuilder graph_builder(&info, &jsgraph);
......
......@@ -602,11 +602,12 @@ static Reduction ReplaceWithReduction(Node* node, Reduction reduction) {
Reduction JSTypedLowering::Reduce(Node* node) {
// Check if the output type is a singleton. In that case we already know the
// result value and can simply replace the node unless there are effects.
if (node->bounds().upper->IsConstant() &&
if (NodeProperties::IsTyped(node) &&
NodeProperties::GetBounds(node).upper->IsConstant() &&
!IrOpcode::IsLeafOpcode(node->opcode()) &&
!OperatorProperties::HasEffectOutput(node->op())) {
return ReplaceEagerly(node, jsgraph()->Constant(
node->bounds().upper->AsConstant()->Value()));
NodeProperties::GetBounds(node).upper->AsConstant()->Value()));
// TODO(neis): Extend this to Range(x,x), NaN, MinusZero, ...?
}
switch (node->opcode()) {
......
......@@ -198,12 +198,30 @@ inline void NodeProperties::ReplaceWithValue(Node* node, Node* value,
// -----------------------------------------------------------------------------
// Type Bounds.
inline Bounds NodeProperties::GetBounds(Node* node) { return node->bounds(); }
inline bool NodeProperties::IsTyped(Node* node) {
Bounds bounds = node->bounds();
DCHECK((bounds.lower == NULL) == (bounds.upper == NULL));
return bounds.upper != NULL;
}
inline Bounds NodeProperties::GetBounds(Node* node) {
DCHECK(IsTyped(node));
return node->bounds();
}
inline void NodeProperties::SetBounds(Node* node, Bounds b) {
DCHECK(b.lower != NULL && b.upper != NULL);
node->set_bounds(b);
}
inline bool NodeProperties::AllValueInputsAreTyped(Node* node) {
int input_count = OperatorProperties::GetValueInputCount(node->op());
for (int i = 0; i < input_count; ++i) {
if (!IsTyped(GetValueInput(node, i))) return false;
}
return true;
}
}
}
......
......@@ -40,8 +40,10 @@ class NodeProperties {
static inline void ReplaceWithValue(Node* node, Node* value,
Node* effect = NULL);
static inline bool IsTyped(Node* node);
static inline Bounds GetBounds(Node* node);
static inline void SetBounds(Node* node, Bounds bounds);
static inline bool AllValueInputsAreTyped(Node* node);
static inline int FirstValueIndex(Node* node);
static inline int FirstContextIndex(Node* node);
......
......@@ -31,14 +31,13 @@ class NodeData {
return static_cast<IrOpcode::Value>(op_->opcode());
}
Bounds bounds() { return bounds_; }
protected:
const Operator* op_;
Bounds bounds_;
explicit NodeData(Zone* zone) : bounds_(Bounds(Type::None(zone))) {}
explicit NodeData(Zone* zone) {}
friend class NodeProperties;
Bounds bounds() { return bounds_; }
void set_bounds(Bounds b) { bounds_ = b; }
};
......
......@@ -105,7 +105,8 @@ void Pipeline::OpenTurboCfgFile(std::ofstream* stream) {
}
void Pipeline::VerifyAndPrintGraph(Graph* graph, const char* phase) {
void Pipeline::VerifyAndPrintGraph(
Graph* graph, const char* phase, bool untyped) {
if (FLAG_trace_turbo) {
char buffer[256];
Vector<char> filename(buffer, sizeof(buffer));
......@@ -143,7 +144,10 @@ void Pipeline::VerifyAndPrintGraph(Graph* graph, const char* phase) {
os << "-- " << phase << " graph printed to file " << filename.start()
<< "\n";
}
if (VerifyGraphs()) Verifier::Run(graph);
if (VerifyGraphs()) {
Verifier::Run(graph,
FLAG_turbo_types && !untyped ? Verifier::TYPED : Verifier::UNTYPED);
}
}
......@@ -231,11 +235,11 @@ Handle<Code> Pipeline::GenerateCode() {
// TODO(turbofan): there is no need to type anything during initial graph
// construction. This is currently only needed for the node cache, which the
// typer could sweep over later.
Typer typer(zone());
Typer typer(&graph, info()->context());
MachineOperatorBuilder machine;
CommonOperatorBuilder common(zone());
JSOperatorBuilder javascript(zone());
JSGraph jsgraph(&graph, &common, &javascript, &typer, &machine);
JSGraph jsgraph(&graph, &common, &javascript, &machine);
Node* context_node;
{
PhaseStats graph_builder_stats(info(), PhaseStats::CREATE_GRAPH,
......@@ -257,7 +261,7 @@ Handle<Code> Pipeline::GenerateCode() {
graph_reducer.ReduceGraph();
}
VerifyAndPrintGraph(&graph, "Initial untyped");
VerifyAndPrintGraph(&graph, "Initial untyped", true);
if (info()->is_context_specializing()) {
SourcePositionTable::Scope pos(&source_positions,
......@@ -265,7 +269,7 @@ Handle<Code> Pipeline::GenerateCode() {
// Specialize the code to the context as aggressively as possible.
JSContextSpecializer spec(info(), &jsgraph, context_node);
spec.SpecializeToContext();
VerifyAndPrintGraph(&graph, "Context specialized");
VerifyAndPrintGraph(&graph, "Context specialized", true);
}
if (info()->is_inlining_enabled()) {
......@@ -273,7 +277,7 @@ Handle<Code> Pipeline::GenerateCode() {
SourcePosition::Unknown());
JSInliner inliner(info(), &jsgraph);
inliner.Inline();
VerifyAndPrintGraph(&graph, "Inlined");
VerifyAndPrintGraph(&graph, "Inlined", true);
}
// Print a replay of the initial graph.
......@@ -288,11 +292,9 @@ Handle<Code> Pipeline::GenerateCode() {
{
// Type the graph.
PhaseStats typer_stats(info(), PhaseStats::CREATE_GRAPH, "typer");
typer.Run(&graph, info()->context());
typer.Run();
VerifyAndPrintGraph(&graph, "Typed");
}
// All new nodes must be typed.
typer.DecorateGraph(&graph);
{
// Lower JSOperators where we can determine types.
PhaseStats lowering_stats(info(), PhaseStats::CREATE_GRAPH,
......@@ -336,7 +338,8 @@ Handle<Code> Pipeline::GenerateCode() {
graph_reducer.AddReducer(&mach_reducer);
graph_reducer.ReduceGraph();
VerifyAndPrintGraph(&graph, "Lowered changes");
// TODO(jarin, rossberg): Remove UNTYPED once machine typing works.
VerifyAndPrintGraph(&graph, "Lowered changes", true);
}
}
......@@ -351,7 +354,8 @@ Handle<Code> Pipeline::GenerateCode() {
graph_reducer.AddReducer(&lowering);
graph_reducer.ReduceGraph();
VerifyAndPrintGraph(&graph, "Lowered generic");
// TODO(jarin, rossberg): Remove UNTYPED once machine typing works.
VerifyAndPrintGraph(&graph, "Lowered generic", true);
}
source_positions.RemoveDecorator();
......@@ -396,7 +400,8 @@ Handle<Code> Pipeline::GenerateCodeForMachineGraph(Linkage* linkage,
Schedule* schedule) {
CHECK(SupportedBackend());
if (schedule == NULL) {
VerifyAndPrintGraph(graph, "Machine");
// TODO(rossberg): Should this really be untyped?
VerifyAndPrintGraph(graph, "Machine", true);
schedule = ComputeSchedule(graph);
}
TraceSchedule(schedule);
......
......@@ -58,7 +58,8 @@ class Pipeline {
const SourcePositionTable* positions,
const InstructionSequence* instructions);
void PrintAllocator(const char* phase, const RegisterAllocator* allocator);
void VerifyAndPrintGraph(Graph* graph, const char* phase);
void VerifyAndPrintGraph(Graph* graph, const char* phase,
bool untyped = false);
Handle<Code> GenerateCode(Linkage* linkage, Graph* graph, Schedule* schedule,
SourcePositionTable* source_positions);
};
......
......@@ -274,7 +274,7 @@ std::ostream& operator<<(std::ostream& os, const Schedule& s) {
++j) {
Node* node = *j;
os << " " << *node;
if (!NodeProperties::IsControl(node)) {
if (NodeProperties::IsTyped(node)) {
Bounds bounds = NodeProperties::GetBounds(node);
os << " : ";
bounds.lower->PrintTo(os);
......
This diff is collapsed.
......@@ -17,23 +17,27 @@ namespace compiler {
class Typer {
public:
explicit Typer(Zone* zone);
explicit Typer(Graph* graph, MaybeHandle<Context> context);
~Typer();
void Init(Node* node);
void Run(Graph* graph, MaybeHandle<Context> context);
void Narrow(Graph* graph, Node* node, MaybeHandle<Context> context);
void Widen(Graph* graph, Node* node, MaybeHandle<Context> context);
void Run();
void Narrow(Node* node);
void DecorateGraph(Graph* graph);
Zone* zone() { return zone_; }
Isolate* isolate() { return zone_->isolate(); }
Graph* graph() { return graph_; }
MaybeHandle<Context> context() { return context_; }
Zone* zone() { return graph_->zone(); }
Isolate* isolate() { return zone()->isolate(); }
private:
class Visitor;
class RunVisitor;
class NarrowVisitor;
class WidenVisitor;
class Decorator;
Graph* graph_;
MaybeHandle<Context> context_;
Decorator* decorator_;
Zone* zone_;
Type* negative_signed32;
......
This diff is collapsed.
......@@ -18,7 +18,9 @@ class Schedule;
// each node, etc.
class Verifier {
public:
static void Run(Graph* graph);
enum Typing { TYPED, UNTYPED };
static void Run(Graph* graph, Typing typing = TYPED);
private:
class Visitor;
......
......@@ -54,6 +54,13 @@ bool TypeImpl<Config>::NowContains(i::Object* value) {
// -----------------------------------------------------------------------------
// ZoneTypeConfig
// static
template<class T>
T* ZoneTypeConfig::null_handle() {
return NULL;
}
// static
template<class T>
T* ZoneTypeConfig::handle(T* type) {
......@@ -197,6 +204,13 @@ void ZoneTypeConfig::struct_set_value(
// -----------------------------------------------------------------------------
// HeapTypeConfig
// static
template<class T>
i::Handle<T> HeapTypeConfig::null_handle() {
return i::Handle<T>();
}
// static
template<class T>
i::Handle<T> HeapTypeConfig::handle(T* type) {
......
......@@ -247,6 +247,7 @@ TypeImpl<Config>::BitsetType::Lub(i::Map* map) {
case SHARED_FUNCTION_INFO_TYPE:
case ACCESSOR_PAIR_TYPE:
case FIXED_ARRAY_TYPE:
case BYTE_ARRAY_TYPE:
case FOREIGN_TYPE:
case CODE_TYPE:
return kInternal & kTaggedPtr;
......@@ -436,6 +437,7 @@ bool TypeImpl<Config>::SlowIs(TypeImpl* that) {
Contains(that->AsRange(), *this->AsConstant()->Value()));
}
if (this->IsRange()) return false;
return this->SimplyEquals(that);
}
......
......@@ -219,8 +219,9 @@ namespace internal {
V(Detectable, kDetectableReceiver | kNumber | kName) \
V(Object, kDetectableObject | kUndetectable) \
V(Receiver, kObject | kProxy) \
V(NonNumber, kBoolean | kName | kNull | kReceiver | \
kUndefined | kInternal) \
V(Unique, kBoolean | kUniqueName | kNull | kUndefined | \
kReceiver) \
V(NonNumber, kUnique | kString | kInternal) \
V(Any, 0xfffffffeu)
/*
......@@ -265,6 +266,7 @@ namespace internal {
// typedef Struct;
// typedef Region;
// template<class> struct Handle { typedef type; } // No template typedefs...
// template<class T> static Handle<T>::type null_handle();
// template<class T> static Handle<T>::type handle(T* t); // !is_bitset(t)
// template<class T> static Handle<T>::type cast(Handle<Type>::type);
// static bool is_bitset(Type*);
......@@ -375,6 +377,12 @@ class TypeImpl : public Config::Base {
static TypeHandle Union(TypeHandle type1, TypeHandle type2, Region* reg);
static TypeHandle Intersect(TypeHandle type1, TypeHandle type2, Region* reg);
static TypeImpl* Union(TypeImpl* type1, TypeImpl* type2) {
return BitsetType::New(type1->AsBitset() | type2->AsBitset());
}
static TypeImpl* Intersect(TypeImpl* type1, TypeImpl* type2) {
return BitsetType::New(type1->AsBitset() & type2->AsBitset());
}
static TypeHandle Of(double value, Region* region) {
return Config::from_bitset(BitsetType::Lub(value), region);
......@@ -912,6 +920,7 @@ struct ZoneTypeConfig {
typedef i::Zone Region;
template<class T> struct Handle { typedef T* type; };
template<class T> static inline T* null_handle();
template<class T> static inline T* handle(T* type);
template<class T> static inline T* cast(Type* type);
......@@ -954,6 +963,7 @@ struct HeapTypeConfig {
typedef i::Isolate Region;
template<class T> struct Handle { typedef i::Handle<T> type; };
template<class T> static inline i::Handle<T> null_handle();
template<class T> static inline i::Handle<T> handle(T* type);
template<class T> static inline i::Handle<T> cast(i::Handle<Type> type);
......@@ -1002,7 +1012,9 @@ struct BoundsImpl {
TypeHandle lower;
TypeHandle upper;
BoundsImpl() {}
BoundsImpl() : // Make sure accessing uninitialized bounds crashes big-time.
lower(Config::template null_handle<Type>()),
upper(Config::template null_handle<Type>()) {}
explicit BoundsImpl(TypeHandle t) : lower(t), upper(t) {}
BoundsImpl(TypeHandle l, TypeHandle u) : lower(l), upper(u) {
DCHECK(lower->Is(upper));
......
......@@ -10,7 +10,7 @@
#include "src/compiler/js-graph.h"
#include "src/compiler/node-properties-inl.h"
#include "src/compiler/pipeline.h"
#include "src/compiler/typer.h"
#include "src/compiler/simplified-lowering.h"
#include "src/compiler/verifier.h"
#include "src/execution.h"
#include "src/globals.h"
......@@ -31,13 +31,10 @@ class ChangesLoweringTester : public GraphBuilderTester<ReturnType> {
public:
explicit ChangesLoweringTester(MachineType p0 = kMachNone)
: GraphBuilderTester<ReturnType>(p0),
typer(this->zone()),
javascript(this->zone()),
jsgraph(this->graph(), this->common(), &javascript, &typer,
this->machine()),
jsgraph(this->graph(), this->common(), &javascript, this->machine()),
function(Handle<JSFunction>::null()) {}
Typer typer;
JSOperatorBuilder javascript;
JSGraph jsgraph;
Handle<JSFunction> function;
......@@ -133,7 +130,7 @@ class ChangesLoweringTester : public GraphBuilderTester<ReturnType> {
GraphReducer reducer(this->graph());
reducer.AddReducer(&lowering);
reducer.ReduceNode(change);
Verifier::Run(this->graph());
Verifier::Run(this->graph(), Verifier::UNTYPED);
}
Factory* factory() { return this->isolate()->factory(); }
......
......@@ -20,7 +20,7 @@ class JSCacheTesterHelper {
: main_graph_(zone),
main_common_(zone),
main_javascript_(zone),
main_typer_(zone),
main_typer_(&main_graph_, MaybeHandle<Context>()),
main_machine_() {}
Graph main_graph_;
CommonOperatorBuilder main_common_;
......@@ -36,8 +36,12 @@ class JSConstantCacheTester : public HandleAndZoneScope,
public:
JSConstantCacheTester()
: JSCacheTesterHelper(main_zone()),
JSGraph(&main_graph_, &main_common_, &main_javascript_, &main_typer_,
&main_machine_) {}
JSGraph(&main_graph_, &main_common_, &main_javascript_,
&main_machine_) {
main_graph_.SetStart(main_graph_.NewNode(common()->Start(0)));
main_graph_.SetEnd(main_graph_.NewNode(common()->End()));
main_typer_.Run();
}
Type* upper(Node* node) { return NodeProperties::GetBounds(node).upper; }
......
......@@ -7,7 +7,6 @@
#include "src/compiler/node-matchers.h"
#include "src/compiler/node-properties-inl.h"
#include "src/compiler/source-position.h"
#include "src/compiler/typer.h"
#include "test/cctest/cctest.h"
#include "test/cctest/compiler/function-tester.h"
#include "test/cctest/compiler/graph-builder-tester.h"
......@@ -24,8 +23,7 @@ class ContextSpecializationTester : public HandleAndZoneScope,
javascript_(main_zone()),
machine_(),
simplified_(main_zone()),
typer_(main_zone()),
jsgraph_(graph(), common(), &javascript_, &typer_, &machine_),
jsgraph_(graph(), common(), &javascript_, &machine_),
info_(main_isolate(), main_zone()) {}
Factory* factory() { return main_isolate()->factory(); }
......@@ -40,7 +38,6 @@ class ContextSpecializationTester : public HandleAndZoneScope,
JSOperatorBuilder javascript_;
MachineOperatorBuilder machine_;
SimplifiedOperatorBuilder simplified_;
Typer typer_;
JSGraph jsgraph_;
CompilationInfo info_;
};
......
......@@ -24,11 +24,11 @@ class JSTypedLoweringTester : public HandleAndZoneScope {
simplified(main_zone()),
common(main_zone()),
graph(main_zone()),
typer(main_zone()),
typer(&graph, MaybeHandle<Context>()),
context_node(NULL) {
typer.DecorateGraph(&graph);
Node* s = graph.NewNode(common.Start(num_parameters));
graph.SetStart(s);
graph.SetStart(graph.NewNode(common.Start(num_parameters)));
graph.SetEnd(graph.NewNode(common.End()));
typer.Run();
}
Isolate* isolate;
......@@ -74,7 +74,7 @@ class JSTypedLoweringTester : public HandleAndZoneScope {
}
Node* reduce(Node* node) {
JSGraph jsgraph(&graph, &common, &javascript, &typer, &machine);
JSGraph jsgraph(&graph, &common, &javascript, &machine);
JSTypedLowering reducer(&jsgraph);
Reduction reduction = reducer.Reduce(node);
if (reduction.Changed()) return reduction.replacement();
......
......@@ -57,8 +57,8 @@ class ReducerTester : public HandleAndZoneScope {
common(main_zone()),
graph(main_zone()),
javascript(main_zone()),
typer(main_zone()),
jsgraph(&graph, &common, &javascript, &typer, &machine),
typer(&graph, MaybeHandle<Context>()),
jsgraph(&graph, &common, &javascript, &machine),
maxuint32(Constant<int32_t>(kMaxUInt32)) {
Node* s = graph.NewNode(common.Start(num_parameters));
graph.SetStart(s);
......
......@@ -11,7 +11,6 @@
#include "src/compiler/node-matchers.h"
#include "src/compiler/representation-change.h"
#include "src/compiler/typer.h"
using namespace v8::internal;
using namespace v8::internal::compiler;
......@@ -25,16 +24,13 @@ class RepresentationChangerTester : public HandleAndZoneScope,
public:
explicit RepresentationChangerTester(int num_parameters = 0)
: GraphAndBuilders(main_zone()),
typer_(main_zone()),
javascript_(main_zone()),
jsgraph_(main_graph_, &main_common_, &javascript_, &typer_,
&main_machine_),
jsgraph_(main_graph_, &main_common_, &javascript_, &main_machine_),
changer_(&jsgraph_, &main_simplified_, main_isolate()) {
Node* s = graph()->NewNode(common()->Start(num_parameters));
graph()->SetStart(s);
}
Typer typer_;
JSOperatorBuilder javascript_;
JSGraph jsgraph_;
RepresentationChanger changer_;
......
......@@ -37,10 +37,9 @@ class SimplifiedLoweringTester : public GraphBuilderTester<ReturnType> {
MachineType p3 = kMachNone,
MachineType p4 = kMachNone)
: GraphBuilderTester<ReturnType>(p0, p1, p2, p3, p4),
typer(this->zone()),
typer(this->graph(), MaybeHandle<Context>()),
javascript(this->zone()),
jsgraph(this->graph(), this->common(), &javascript, &typer,
this->machine()),
jsgraph(this->graph(), this->common(), &javascript, this->machine()),
lowering(&jsgraph) {}
Typer typer;
......@@ -50,12 +49,13 @@ class SimplifiedLoweringTester : public GraphBuilderTester<ReturnType> {
void LowerAllNodes() {
this->End();
typer.Run();
lowering.LowerAllNodes();
}
void LowerAllNodesAndLowerChanges() {
this->End();
typer.Run(jsgraph.graph(), MaybeHandle<Context>());
typer.Run();
lowering.LowerAllNodes();
Zone* zone = this->zone();
......@@ -674,9 +674,9 @@ class TestingGraph : public HandleAndZoneScope, public GraphAndBuilders {
explicit TestingGraph(Type* p0_type, Type* p1_type = Type::None(),
Type* p2_type = Type::None())
: GraphAndBuilders(main_zone()),
typer(main_zone()),
typer(graph(), MaybeHandle<Context>()),
javascript(main_zone()),
jsgraph(graph(), common(), &javascript, &typer, machine()) {
jsgraph(graph(), common(), &javascript, machine()) {
start = graph()->NewNode(common()->Start(2));
graph()->SetStart(start);
ret =
......@@ -686,6 +686,7 @@ class TestingGraph : public HandleAndZoneScope, public GraphAndBuilders {
p0 = graph()->NewNode(common()->Parameter(0), start);
p1 = graph()->NewNode(common()->Parameter(1), start);
p2 = graph()->NewNode(common()->Parameter(2), start);
typer.Run();
NodeProperties::SetBounds(p0, Bounds(p0_type));
NodeProperties::SetBounds(p1, Bounds(p1_type));
NodeProperties::SetBounds(p2, Bounds(p2_type));
......@@ -706,8 +707,7 @@ class TestingGraph : public HandleAndZoneScope, public GraphAndBuilders {
}
void Lower() {
SimplifiedLowering lowering(&jsgraph);
lowering.LowerAllNodes();
SimplifiedLowering(&jsgraph).LowerAllNodes();
}
// Inserts the node as the return value of the graph.
......@@ -1540,10 +1540,11 @@ TEST(UpdatePhi) {
TestingGraph t(Type::Any(), Type::Signed32());
static const MachineType kMachineTypes[] = {kMachInt32, kMachUint32,
kMachFloat64};
Type* kTypes[] = {Type::Signed32(), Type::Unsigned32(), Type::Number()};
for (size_t i = 0; i < arraysize(kMachineTypes); i++) {
FieldAccess access = {kTaggedBase, FixedArrayBase::kHeaderSize,
Handle<Name>::null(), Type::Any(), kMachineTypes[i]};
Handle<Name>::null(), kTypes[i], kMachineTypes[i]};
Node* load0 =
t.graph()->NewNode(t.simplified()->LoadField(access), t.p0, t.start);
......
......@@ -26,7 +26,7 @@ class TyperTester : public HandleAndZoneScope, public GraphAndBuilders {
public:
TyperTester()
: GraphAndBuilders(main_zone()),
typer_(main_zone()),
typer_(graph(), MaybeHandle<Context>()),
javascript_(main_zone()) {
Node* s = graph()->NewNode(common()->Start(3));
graph()->SetStart(s);
......@@ -79,7 +79,6 @@ class TyperTester : public HandleAndZoneScope, public GraphAndBuilders {
NodeProperties::SetBounds(p1, Bounds(rhs));
Node* n = graph()->NewNode(
op, p0, p1, context_node_, graph()->start(), graph()->start());
typer_.Init(n);
return NodeProperties::GetBounds(n).upper;
}
......
......@@ -6,7 +6,6 @@
#include "src/compiler/js-graph.h"
#include "src/compiler/node-properties-inl.h"
#include "src/compiler/simplified-operator.h"
#include "src/compiler/typer.h"
#include "test/unittests/compiler/compiler-test-utils.h"
#include "test/unittests/compiler/graph-unittest.h"
#include "testing/gmock-support.h"
......@@ -65,10 +64,9 @@ class ChangeLoweringTest : public GraphTest {
}
Reduction Reduce(Node* node) {
Typer typer(zone());
MachineOperatorBuilder machine(WordRepresentation());
JSOperatorBuilder javascript(zone());
JSGraph jsgraph(graph(), common(), &javascript, &typer, &machine);
JSGraph jsgraph(graph(), common(), &javascript, &machine);
CompilationInfo info(isolate(), zone());
Linkage linkage(&info);
ChangeLowering reducer(&jsgraph, &linkage);
......
......@@ -8,6 +8,7 @@
#include "src/compiler/common-operator.h"
#include "src/compiler/graph.h"
#include "src/compiler/machine-operator.h"
#include "src/compiler/typer.h"
#include "test/unittests/test-utils.h"
#include "testing/gmock/include/gmock/gmock.h"
......@@ -64,6 +65,20 @@ class GraphTest : public TestWithContext, public TestWithZone {
};
class TypedGraphTest : public GraphTest {
public:
explicit TypedGraphTest(int parameters = 1)
: GraphTest(parameters),
typer_(graph(), MaybeHandle<Context>()) {}
protected:
Typer* typer() { return &typer_; }
private:
Typer typer_;
};
Matcher<Node*> IsBranch(const Matcher<Node*>& value_matcher,
const Matcher<Node*>& control_matcher);
Matcher<Node*> IsMerge(const Matcher<Node*>& control0_matcher,
......
......@@ -16,15 +16,14 @@ namespace v8 {
namespace internal {
namespace compiler {
class JSBuiltinReducerTest : public GraphTest {
class JSBuiltinReducerTest : public TypedGraphTest {
public:
JSBuiltinReducerTest() : javascript_(zone()) {}
protected:
Reduction Reduce(Node* node) {
Typer typer(zone());
MachineOperatorBuilder machine;
JSGraph jsgraph(graph(), common(), javascript(), &typer, &machine);
JSGraph jsgraph(graph(), common(), javascript(), &machine);
JSBuiltinReducer reducer(&jsgraph);
return reducer.Reduce(node);
}
......
......@@ -31,16 +31,15 @@ const StrictMode kStrictModes[] = {SLOPPY, STRICT};
} // namespace
class JSTypedLoweringTest : public GraphTest {
class JSTypedLoweringTest : public TypedGraphTest {
public:
JSTypedLoweringTest() : GraphTest(3), javascript_(zone()) {}
JSTypedLoweringTest() : TypedGraphTest(3), javascript_(zone()) {}
virtual ~JSTypedLoweringTest() {}
protected:
Reduction Reduce(Node* node) {
Typer typer(zone());
MachineOperatorBuilder machine;
JSGraph jsgraph(graph(), common(), javascript(), &typer, &machine);
JSGraph jsgraph(graph(), common(), javascript(), &machine);
JSTypedLowering reducer(&jsgraph);
return reducer.Reduce(node);
}
......
......@@ -18,16 +18,15 @@ namespace v8 {
namespace internal {
namespace compiler {
class MachineOperatorReducerTest : public GraphTest {
class MachineOperatorReducerTest : public TypedGraphTest {
public:
explicit MachineOperatorReducerTest(int num_parameters = 2)
: GraphTest(num_parameters) {}
: TypedGraphTest(num_parameters) {}
protected:
Reduction Reduce(Node* node) {
Typer typer(zone());
JSOperatorBuilder javascript(zone());
JSGraph jsgraph(graph(), common(), &javascript, &typer, &machine_);
JSGraph jsgraph(graph(), common(), &javascript, &machine_);
MachineOperatorReducer reducer(&jsgraph);
return reducer.Reduce(node);
}
......
......@@ -5,7 +5,6 @@
#include "src/compiler/js-graph.h"
#include "src/compiler/simplified-operator.h"
#include "src/compiler/simplified-operator-reducer.h"
#include "src/compiler/typer.h"
#include "src/conversions.h"
#include "test/unittests/compiler/graph-unittest.h"
......@@ -21,10 +20,9 @@ class SimplifiedOperatorReducerTest : public GraphTest {
protected:
Reduction Reduce(Node* node) {
Typer typer(zone());
MachineOperatorBuilder machine;
JSOperatorBuilder javascript(zone());
JSGraph jsgraph(graph(), common(), &javascript, &typer, &machine);
JSGraph jsgraph(graph(), common(), &javascript, &machine);
SimplifiedOperatorReducer reducer(&jsgraph);
return reducer.Reduce(node);
}
......
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