[turbofan] Make sure Operator is really immutable.

Make Operator const-correct in preparation for allocating sharing
Operators across different isolates (using LazyInstance).

TEST=cctest,compiler-unittests,mjsunit
R=svenpanne@chromium.org

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

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@23677 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
bmeurer@chromium.org 2014-09-04 09:37:25 +00:00
parent dd34bc2cab
commit c8ffed8879
12 changed files with 111 additions and 114 deletions

View File

@ -191,37 +191,37 @@ class CommonOperatorBuilder {
template <typename T>
struct CommonOperatorTraits {
static inline bool Equals(T a, T b);
static inline bool HasValue(Operator* op);
static inline T ValueOf(Operator* op);
static inline bool HasValue(const Operator* op);
static inline T ValueOf(const Operator* op);
};
template <>
struct CommonOperatorTraits<int32_t> {
static inline bool Equals(int32_t a, int32_t b) { return a == b; }
static inline bool HasValue(Operator* op) {
static inline bool HasValue(const Operator* op) {
return op->opcode() == IrOpcode::kInt32Constant ||
op->opcode() == IrOpcode::kNumberConstant;
}
static inline int32_t ValueOf(Operator* op) {
static inline int32_t ValueOf(const Operator* op) {
if (op->opcode() == IrOpcode::kNumberConstant) {
// TODO(titzer): cache the converted int32 value in NumberConstant.
return FastD2I(reinterpret_cast<Operator1<double>*>(op)->parameter());
return FastD2I(OpParameter<double>(op));
}
CHECK_EQ(IrOpcode::kInt32Constant, op->opcode());
return static_cast<Operator1<int32_t>*>(op)->parameter();
return OpParameter<int32_t>(op);
}
};
template <>
struct CommonOperatorTraits<uint32_t> {
static inline bool Equals(uint32_t a, uint32_t b) { return a == b; }
static inline bool HasValue(Operator* op) {
static inline bool HasValue(const Operator* op) {
return CommonOperatorTraits<int32_t>::HasValue(op);
}
static inline uint32_t ValueOf(Operator* op) {
static inline uint32_t ValueOf(const Operator* op) {
if (op->opcode() == IrOpcode::kNumberConstant) {
// TODO(titzer): cache the converted uint32 value in NumberConstant.
return FastD2UI(reinterpret_cast<Operator1<double>*>(op)->parameter());
return FastD2UI(OpParameter<double>(op));
}
return static_cast<uint32_t>(CommonOperatorTraits<int32_t>::ValueOf(op));
}
@ -230,27 +230,27 @@ struct CommonOperatorTraits<uint32_t> {
template <>
struct CommonOperatorTraits<int64_t> {
static inline bool Equals(int64_t a, int64_t b) { return a == b; }
static inline bool HasValue(Operator* op) {
static inline bool HasValue(const Operator* op) {
return op->opcode() == IrOpcode::kInt32Constant ||
op->opcode() == IrOpcode::kInt64Constant ||
op->opcode() == IrOpcode::kNumberConstant;
}
static inline int64_t ValueOf(Operator* op) {
static inline int64_t ValueOf(const Operator* op) {
if (op->opcode() == IrOpcode::kInt32Constant) {
return static_cast<int64_t>(CommonOperatorTraits<int32_t>::ValueOf(op));
}
CHECK_EQ(IrOpcode::kInt64Constant, op->opcode());
return static_cast<Operator1<int64_t>*>(op)->parameter();
return OpParameter<int64_t>(op);
}
};
template <>
struct CommonOperatorTraits<uint64_t> {
static inline bool Equals(uint64_t a, uint64_t b) { return a == b; }
static inline bool HasValue(Operator* op) {
static inline bool HasValue(const Operator* op) {
return CommonOperatorTraits<int64_t>::HasValue(op);
}
static inline uint64_t ValueOf(Operator* op) {
static inline uint64_t ValueOf(const Operator* op) {
return static_cast<uint64_t>(CommonOperatorTraits<int64_t>::ValueOf(op));
}
};
@ -260,15 +260,15 @@ struct CommonOperatorTraits<double> {
static inline bool Equals(double a, double b) {
return DoubleRepresentation(a).bits == DoubleRepresentation(b).bits;
}
static inline bool HasValue(Operator* op) {
static inline bool HasValue(const Operator* op) {
return op->opcode() == IrOpcode::kFloat64Constant ||
op->opcode() == IrOpcode::kInt32Constant ||
op->opcode() == IrOpcode::kNumberConstant;
}
static inline double ValueOf(Operator* op) {
static inline double ValueOf(const Operator* op) {
if (op->opcode() == IrOpcode::kFloat64Constant ||
op->opcode() == IrOpcode::kNumberConstant) {
return reinterpret_cast<Operator1<double>*>(op)->parameter();
return OpParameter<double>(op);
}
return static_cast<double>(CommonOperatorTraits<int32_t>::ValueOf(op));
}
@ -279,43 +279,44 @@ struct CommonOperatorTraits<ExternalReference> {
static inline bool Equals(ExternalReference a, ExternalReference b) {
return a == b;
}
static inline bool HasValue(Operator* op) {
static inline bool HasValue(const Operator* op) {
return op->opcode() == IrOpcode::kExternalConstant;
}
static inline ExternalReference ValueOf(Operator* op) {
static inline ExternalReference ValueOf(const Operator* op) {
CHECK_EQ(IrOpcode::kExternalConstant, op->opcode());
return static_cast<Operator1<ExternalReference>*>(op)->parameter();
return OpParameter<ExternalReference>(op);
}
};
template <typename T>
struct CommonOperatorTraits<PrintableUnique<T> > {
static inline bool HasValue(Operator* op) {
static inline bool HasValue(const Operator* op) {
return op->opcode() == IrOpcode::kHeapConstant;
}
static inline PrintableUnique<T> ValueOf(Operator* op) {
static inline PrintableUnique<T> ValueOf(const Operator* op) {
CHECK_EQ(IrOpcode::kHeapConstant, op->opcode());
return static_cast<Operator1<PrintableUnique<T> >*>(op)->parameter();
return OpParameter<PrintableUnique<T> >(op);
}
};
template <typename T>
struct CommonOperatorTraits<Handle<T> > {
static inline bool HasValue(Operator* op) {
static inline bool HasValue(const Operator* op) {
return CommonOperatorTraits<PrintableUnique<T> >::HasValue(op);
}
static inline Handle<T> ValueOf(Operator* op) {
static inline Handle<T> ValueOf(const Operator* op) {
return CommonOperatorTraits<PrintableUnique<T> >::ValueOf(op).handle();
}
};
template <typename T>
inline T ValueOf(Operator* op) {
inline T ValueOf(const Operator* op) {
return CommonOperatorTraits<T>::ValueOf(op);
}
}
}
} // namespace v8::internal::compiler
} // namespace compiler
} // namespace internal
} // namespace v8
#endif // V8_COMPILER_COMMON_OPERATOR_H_

View File

@ -40,7 +40,7 @@ void GraphReplayPrinter::PostEdge(Node* from, int index, Node* to) {
}
void GraphReplayPrinter::PrintReplayOpCreator(Operator* op) {
void GraphReplayPrinter::PrintReplayOpCreator(const Operator* op) {
IrOpcode::Value opcode = static_cast<IrOpcode::Value>(op->opcode());
const char* builder =
IrOpcode::IsCommonOpcode(opcode) ? "common_builder" : "js_builder";

View File

@ -5,21 +5,19 @@
#ifndef V8_COMPILER_GRAPH_REPLAY_H_
#define V8_COMPILER_GRAPH_REPLAY_H_
#include "src/v8.h"
#include "src/compiler/node.h"
namespace v8 {
namespace internal {
namespace compiler {
// Forward declarations.
class Graph;
class Operator;
// Helper class to print a full replay of a graph. This replay can be used to
// materialize the same graph within a C++ unit test and hence test subsequent
// optimization passes on a graph without going through the construction steps.
class GraphReplayPrinter : public NullNodeVisitor {
class GraphReplayPrinter FINAL : public NullNodeVisitor {
public:
#ifdef DEBUG
static void PrintReplay(Graph* graph);
@ -33,12 +31,13 @@ class GraphReplayPrinter : public NullNodeVisitor {
private:
GraphReplayPrinter() {}
static void PrintReplayOpCreator(Operator* op);
static void PrintReplayOpCreator(const Operator* op);
DISALLOW_COPY_AND_ASSIGN(GraphReplayPrinter);
};
}
}
} // namespace v8::internal::compiler
} // namespace compiler
} // namespace internal
} // namespace v8
#endif // V8_COMPILER_GRAPH_REPLAY_H_

View File

@ -184,7 +184,7 @@ void Inlinee::InlineAtCall(JSGraph* jsgraph, Node* call) {
Node* use = *iter;
switch (use->opcode()) {
case IrOpcode::kParameter: {
int index = 1 + static_cast<Operator1<int>*>(use->op())->parameter();
int index = 1 + OpParameter<int>(use->op());
if (index < inliner_inputs && index < inlinee_context_index) {
// There is an input from the call, and the index is a value
// projection but not the context, so rewire the input.

View File

@ -17,7 +17,7 @@ struct NodeMatcher {
explicit NodeMatcher(Node* node) : node_(node) {}
Node* node() const { return node_; }
Operator* op() const { return node()->op(); }
const Operator* op() const { return node()->op(); }
IrOpcode::Value opcode() const { return node()->opcode(); }
bool HasProperty(Operator::Property property) const {

View File

@ -23,8 +23,8 @@ namespace compiler {
class NodeData {
public:
Operator* op() const { return op_; }
void set_op(Operator* op) { op_ = op; }
const Operator* op() const { return op_; }
void set_op(const Operator* op) { op_ = op; }
IrOpcode::Value opcode() const {
DCHECK(op_->opcode() <= IrOpcode::kLast);
@ -34,7 +34,7 @@ class NodeData {
Bounds bounds() { return bounds_; }
protected:
Operator* op_;
const Operator* op_;
Bounds bounds_;
explicit NodeData(Zone* zone) : bounds_(Bounds(Type::None(zone))) {}
@ -47,12 +47,12 @@ class NodeData {
// during compilation, e.g. during lowering passes. Other information that
// needs to be associated with Nodes during compilation must be stored
// out-of-line indexed by the Node's id.
class Node : public GenericNode<NodeData, Node> {
class Node FINAL : public GenericNode<NodeData, Node> {
public:
Node(GenericGraphBase* graph, int input_count)
: GenericNode<NodeData, Node>(graph, input_count) {}
void Initialize(Operator* op) { set_op(op); }
void Initialize(const Operator* op) { set_op(op); }
void Kill();
void CollectProjections(ZoneVector<Node*>* projections);
@ -78,20 +78,14 @@ typedef NodeVectorVector::reverse_iterator NodeVectorVectorRIter;
typedef Node::Uses::iterator UseIter;
typedef Node::Inputs::iterator InputIter;
// Helper to extract parameters from Operator1<*> operator.
template <typename T>
static inline T OpParameter(Operator* op) {
return reinterpret_cast<Operator1<T>*>(op)->parameter();
}
// Helper to extract parameters from Operator1<*> nodes.
template <typename T>
static inline T OpParameter(Node* node) {
static inline T OpParameter(const Node* node) {
return OpParameter<T>(node->op());
}
}
}
} // namespace v8::internal::compiler
} // namespace compiler
} // namespace internal
} // namespace v8
#endif // V8_COMPILER_NODE_H_

View File

@ -14,24 +14,24 @@ namespace v8 {
namespace internal {
namespace compiler {
inline bool OperatorProperties::HasValueInput(Operator* op) {
inline bool OperatorProperties::HasValueInput(const Operator* op) {
return OperatorProperties::GetValueInputCount(op) > 0;
}
inline bool OperatorProperties::HasContextInput(Operator* op) {
inline bool OperatorProperties::HasContextInput(const Operator* op) {
IrOpcode::Value opcode = static_cast<IrOpcode::Value>(op->opcode());
return IrOpcode::IsJsOpcode(opcode);
}
inline bool OperatorProperties::HasEffectInput(Operator* op) {
inline bool OperatorProperties::HasEffectInput(const Operator* op) {
return OperatorProperties::GetEffectInputCount(op) > 0;
}
inline bool OperatorProperties::HasControlInput(Operator* op) {
inline bool OperatorProperties::HasControlInput(const Operator* op) {
return OperatorProperties::GetControlInputCount(op) > 0;
}
inline bool OperatorProperties::HasFrameStateInput(Operator* op) {
inline bool OperatorProperties::HasFrameStateInput(const Operator* op) {
if (!FLAG_turbo_deoptimization) {
return false;
}
@ -40,8 +40,7 @@ inline bool OperatorProperties::HasFrameStateInput(Operator* op) {
case IrOpcode::kFrameState:
return true;
case IrOpcode::kJSCallRuntime: {
Runtime::FunctionId function =
reinterpret_cast<Operator1<Runtime::FunctionId>*>(op)->parameter();
Runtime::FunctionId function = OpParameter<Runtime::FunctionId>(op);
return Linkage::NeedsFrameState(function);
}
@ -85,29 +84,29 @@ inline bool OperatorProperties::HasFrameStateInput(Operator* op) {
}
}
inline int OperatorProperties::GetValueInputCount(Operator* op) {
inline int OperatorProperties::GetValueInputCount(const Operator* op) {
return op->InputCount();
}
inline int OperatorProperties::GetContextInputCount(Operator* op) {
inline int OperatorProperties::GetContextInputCount(const Operator* op) {
return OperatorProperties::HasContextInput(op) ? 1 : 0;
}
inline int OperatorProperties::GetFrameStateInputCount(Operator* op) {
inline int OperatorProperties::GetFrameStateInputCount(const Operator* op) {
return OperatorProperties::HasFrameStateInput(op) ? 1 : 0;
}
inline int OperatorProperties::GetEffectInputCount(Operator* op) {
inline int OperatorProperties::GetEffectInputCount(const Operator* op) {
if (op->opcode() == IrOpcode::kEffectPhi ||
op->opcode() == IrOpcode::kFinish) {
return static_cast<Operator1<int>*>(op)->parameter();
return OpParameter<int>(op);
}
if (op->HasProperty(Operator::kNoRead) && op->HasProperty(Operator::kNoWrite))
return 0; // no effects.
return 1;
}
inline int OperatorProperties::GetControlInputCount(Operator* op) {
inline int OperatorProperties::GetControlInputCount(const Operator* op) {
switch (op->opcode()) {
case IrOpcode::kPhi:
case IrOpcode::kEffectPhi:
@ -116,7 +115,7 @@ inline int OperatorProperties::GetControlInputCount(Operator* op) {
#define OPCODE_CASE(x) case IrOpcode::k##x:
CONTROL_OP_LIST(OPCODE_CASE)
#undef OPCODE_CASE
return static_cast<ControlOperator*>(op)->ControlInputCount();
return reinterpret_cast<const ControlOperator*>(op)->ControlInputCount();
default:
// Operators that have write effects must have a control
// dependency. Effect dependencies only ensure the correct order of
@ -128,7 +127,7 @@ inline int OperatorProperties::GetControlInputCount(Operator* op) {
return 0;
}
inline int OperatorProperties::GetTotalInputCount(Operator* op) {
inline int OperatorProperties::GetTotalInputCount(const Operator* op) {
return GetValueInputCount(op) + GetContextInputCount(op) +
GetFrameStateInputCount(op) + GetEffectInputCount(op) +
GetControlInputCount(op);
@ -137,38 +136,38 @@ inline int OperatorProperties::GetTotalInputCount(Operator* op) {
// -----------------------------------------------------------------------------
// Output properties.
inline bool OperatorProperties::HasValueOutput(Operator* op) {
inline bool OperatorProperties::HasValueOutput(const Operator* op) {
return GetValueOutputCount(op) > 0;
}
inline bool OperatorProperties::HasEffectOutput(Operator* op) {
inline bool OperatorProperties::HasEffectOutput(const Operator* op) {
return op->opcode() == IrOpcode::kStart ||
op->opcode() == IrOpcode::kControlEffect ||
op->opcode() == IrOpcode::kValueEffect ||
(op->opcode() != IrOpcode::kFinish && GetEffectInputCount(op) > 0);
}
inline bool OperatorProperties::HasControlOutput(Operator* op) {
inline bool OperatorProperties::HasControlOutput(const Operator* op) {
IrOpcode::Value opcode = static_cast<IrOpcode::Value>(op->opcode());
return (opcode != IrOpcode::kEnd && IrOpcode::IsControlOpcode(opcode));
}
inline int OperatorProperties::GetValueOutputCount(Operator* op) {
inline int OperatorProperties::GetValueOutputCount(const Operator* op) {
return op->OutputCount();
}
inline int OperatorProperties::GetEffectOutputCount(Operator* op) {
inline int OperatorProperties::GetEffectOutputCount(const Operator* op) {
return HasEffectOutput(op) ? 1 : 0;
}
inline int OperatorProperties::GetControlOutputCount(Operator* node) {
inline int OperatorProperties::GetControlOutputCount(const Operator* node) {
return node->opcode() == IrOpcode::kBranch ? 2 : HasControlOutput(node) ? 1
: 0;
}
inline bool OperatorProperties::IsBasicBlockBegin(Operator* op) {
inline bool OperatorProperties::IsBasicBlockBegin(const Operator* op) {
uint8_t opcode = op->opcode();
return opcode == IrOpcode::kStart || opcode == IrOpcode::kEnd ||
opcode == IrOpcode::kDead || opcode == IrOpcode::kLoop ||
@ -176,8 +175,8 @@ inline bool OperatorProperties::IsBasicBlockBegin(Operator* op) {
opcode == IrOpcode::kIfFalse;
}
}
}
} // namespace v8::internal::compiler
} // namespace compiler
} // namespace internal
} // namespace v8
#endif // V8_COMPILER_OPERATOR_PROPERTIES_INL_H_

View File

@ -5,8 +5,6 @@
#ifndef V8_COMPILER_OPERATOR_PROPERTIES_H_
#define V8_COMPILER_OPERATOR_PROPERTIES_H_
#include "src/v8.h"
namespace v8 {
namespace internal {
namespace compiler {
@ -15,31 +13,32 @@ class Operator;
class OperatorProperties {
public:
static inline bool HasValueInput(Operator* node);
static inline bool HasContextInput(Operator* node);
static inline bool HasEffectInput(Operator* node);
static inline bool HasControlInput(Operator* node);
static inline bool HasFrameStateInput(Operator* node);
static inline bool HasValueInput(const Operator* op);
static inline bool HasContextInput(const Operator* op);
static inline bool HasEffectInput(const Operator* op);
static inline bool HasControlInput(const Operator* op);
static inline bool HasFrameStateInput(const Operator* op);
static inline int GetValueInputCount(Operator* op);
static inline int GetContextInputCount(Operator* op);
static inline int GetEffectInputCount(Operator* op);
static inline int GetControlInputCount(Operator* op);
static inline int GetFrameStateInputCount(Operator* op);
static inline int GetTotalInputCount(Operator* op);
static inline int GetValueInputCount(const Operator* op);
static inline int GetContextInputCount(const Operator* op);
static inline int GetEffectInputCount(const Operator* op);
static inline int GetControlInputCount(const Operator* op);
static inline int GetFrameStateInputCount(const Operator* op);
static inline int GetTotalInputCount(const Operator* op);
static inline bool HasValueOutput(Operator* op);
static inline bool HasEffectOutput(Operator* op);
static inline bool HasControlOutput(Operator* op);
static inline bool HasValueOutput(const Operator* op);
static inline bool HasEffectOutput(const Operator* op);
static inline bool HasControlOutput(const Operator* op);
static inline int GetValueOutputCount(Operator* op);
static inline int GetEffectOutputCount(Operator* op);
static inline int GetControlOutputCount(Operator* op);
static inline int GetValueOutputCount(const Operator* op);
static inline int GetEffectOutputCount(const Operator* op);
static inline int GetControlOutputCount(const Operator* op);
static inline bool IsBasicBlockBegin(Operator* op);
static inline bool IsBasicBlockBegin(const Operator* op);
};
}
}
} // namespace v8::internal::compiler
} // namespace compiler
} // namespace internal
} // namespace v8
#endif // V8_COMPILER_OPERATOR_PROPERTIES_H_

View File

@ -269,6 +269,13 @@ class Operator1 : public Operator {
// Type definitions for operators with specific types of parameters.
typedef Operator1<PrintableUnique<Name> > NameOperator;
// Helper to extract parameters from Operator1<*> operator.
template <typename T>
static inline T OpParameter(const Operator* op) {
return reinterpret_cast<const Operator1<T>*>(op)->parameter();
}
} // namespace compiler
} // namespace internal
} // namespace v8

View File

@ -81,17 +81,17 @@ struct StaticParameterTraits<ElementAccess> {
};
inline const FieldAccess FieldAccessOf(Operator* op) {
inline const FieldAccess FieldAccessOf(const Operator* op) {
DCHECK(op->opcode() == IrOpcode::kLoadField ||
op->opcode() == IrOpcode::kStoreField);
return static_cast<Operator1<FieldAccess>*>(op)->parameter();
return OpParameter<FieldAccess>(op);
}
inline const ElementAccess ElementAccessOf(Operator* op) {
inline const ElementAccess ElementAccessOf(const Operator* op) {
DCHECK(op->opcode() == IrOpcode::kLoadElement ||
op->opcode() == IrOpcode::kStoreElement);
return static_cast<Operator1<ElementAccess>*>(op)->parameter();
return OpParameter<ElementAccess>(op);
}

View File

@ -174,7 +174,7 @@ GenericGraphVisit::Control Verifier::Visitor::Pre(Node* node) {
CHECK_EQ(IrOpcode::kStart,
NodeProperties::GetValueInput(node, 0)->opcode());
// Parameter has an input that produces enough values.
int index = static_cast<Operator1<int>*>(node->op())->parameter();
int index = OpParameter<int>(node);
Node* input = NodeProperties::GetValueInput(node, 0);
// Currently, parameter indices start at -1 instead of 0.
CHECK_GT(OperatorProperties::GetValueOutputCount(input->op()), index + 1);
@ -213,7 +213,7 @@ GenericGraphVisit::Control Verifier::Visitor::Pre(Node* node) {
break;
case IrOpcode::kProjection: {
// Projection has an input that produces enough values.
int index = static_cast<Operator1<int>*>(node->op())->parameter();
int index = OpParameter<int>(node);
Node* input = NodeProperties::GetValueInput(node, 0);
CHECK_GT(OperatorProperties::GetValueOutputCount(input->op()), index);
break;

View File

@ -95,8 +95,7 @@ TEST(ReduceJSLoadContext) {
CHECK_EQ(IrOpcode::kHeapConstant, new_context_input->opcode());
ValueMatcher<Handle<Context> > match(new_context_input);
CHECK_EQ(*native, *match.Value());
ContextAccess access = static_cast<Operator1<ContextAccess>*>(
r.replacement()->op())->parameter();
ContextAccess access = OpParameter<ContextAccess>(r.replacement());
CHECK_EQ(Context::GLOBAL_EVAL_FUN_INDEX, access.index());
CHECK_EQ(0, access.depth());
CHECK_EQ(false, access.immutable());
@ -176,8 +175,7 @@ TEST(ReduceJSStoreContext) {
CHECK_EQ(IrOpcode::kHeapConstant, new_context_input->opcode());
ValueMatcher<Handle<Context> > match(new_context_input);
CHECK_EQ(*native, *match.Value());
ContextAccess access = static_cast<Operator1<ContextAccess>*>(
r.replacement()->op())->parameter();
ContextAccess access = OpParameter<ContextAccess>(r.replacement());
CHECK_EQ(Context::GLOBAL_EVAL_FUN_INDEX, access.index());
CHECK_EQ(0, access.depth());
CHECK_EQ(false, access.immutable());