V8 Project
v8::internal::compiler::JSContextSpecializer Class Reference

#include <js-context-specialization.h>

+ Collaboration diagram for v8::internal::compiler::JSContextSpecializer:

Public Member Functions

 JSContextSpecializer (CompilationInfo *info, JSGraph *jsgraph, Node *context)
 
void SpecializeToContext ()
 
Reduction ReduceJSLoadContext (Node *node)
 
Reduction ReduceJSStoreContext (Node *node)
 

Private Attributes

CompilationInfoinfo_
 
JSGraphjsgraph_
 
Node * context_
 

Detailed Description

Definition at line 19 of file js-context-specialization.h.

Constructor & Destructor Documentation

◆ JSContextSpecializer()

v8::internal::compiler::JSContextSpecializer::JSContextSpecializer ( CompilationInfo info,
JSGraph jsgraph,
Node *  context 
)
inline

Member Function Documentation

◆ ReduceJSLoadContext()

Reduction v8::internal::compiler::JSContextSpecializer::ReduceJSLoadContext ( Node *  node)

Definition at line 61 of file js-context-specialization.cc.

61  {
62  DCHECK_EQ(IrOpcode::kJSLoadContext, node->opcode());
63 
64  HeapObjectMatcher<Context> m(NodeProperties::GetValueInput(node, 0));
65  // If the context is not constant, no reduction can occur.
66  if (!m.HasValue()) {
67  return Reducer::NoChange();
68  }
69 
70  ContextAccess access = OpParameter<ContextAccess>(node);
71 
72  // Find the right parent context.
73  Context* context = *m.Value().handle();
74  for (int i = access.depth(); i > 0; --i) {
75  context = context->previous();
76  }
77 
78  // If the access itself is mutable, only fold-in the parent.
79  if (!access.immutable()) {
80  // The access does not have to look up a parent, nothing to fold.
81  if (access.depth() == 0) {
82  return Reducer::NoChange();
83  }
84  const Operator* op = jsgraph_->javascript()->LoadContext(
85  0, access.index(), access.immutable());
86  node->set_op(op);
87  Handle<Object> context_handle = Handle<Object>(context, info_->isolate());
88  node->ReplaceInput(0, jsgraph_->Constant(context_handle));
89  return Reducer::Changed(node);
90  }
91  Handle<Object> value =
92  Handle<Object>(context->get(access.index()), info_->isolate());
93 
94  // Even though the context slot is immutable, the context might have escaped
95  // before the function to which it belongs has initialized the slot.
96  // We must be conservative and check if the value in the slot is currently the
97  // hole or undefined. If it is neither of these, then it must be initialized.
98  if (value->IsUndefined() || value->IsTheHole()) {
99  return Reducer::NoChange();
100  }
101 
102  // Success. The context load can be replaced with the constant.
103  // TODO(titzer): record the specialization for sharing code across multiple
104  // contexts that have the same value in the corresponding context slot.
105  return Reducer::Replace(jsgraph_->Constant(value));
106 }
Isolate * isolate() const
Definition: compiler.h:96
JSOperatorBuilder * javascript()
Definition: js-graph.h:86
Node * Constant(Handle< Object > value)
Definition: js-graph.cc:115
const Operator * LoadContext(uint16_t depth, uint32_t index, bool immutable)
Definition: js-operator.h:152
static Node * GetValueInput(Node *node, int index)
static Reduction Replace(Node *node)
Definition: graph-reducer.h:47
static Reduction Changed(Node *node)
Definition: graph-reducer.h:48
#define DCHECK_EQ(v1, v2)
Definition: logging.h:206

References v8::internal::compiler::Reducer::Changed(), v8::internal::compiler::JSGraph::Constant(), DCHECK_EQ, v8::internal::compiler::ContextAccess::depth(), v8::internal::FixedArray::get(), v8::internal::compiler::NodeProperties::GetValueInput(), v8::internal::compiler::ContextAccess::immutable(), v8::internal::compiler::ContextAccess::index(), info_, v8::internal::CompilationInfo::isolate(), v8::internal::compiler::JSGraph::javascript(), jsgraph_, v8::internal::compiler::JSOperatorBuilder::LoadContext(), v8::internal::compiler::Reducer::NoChange(), v8::internal::Context::previous(), and v8::internal::compiler::Reducer::Replace().

Referenced by v8::internal::compiler::ContextSpecializationVisitor::Post().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ReduceJSStoreContext()

Reduction v8::internal::compiler::JSContextSpecializer::ReduceJSStoreContext ( Node *  node)

Definition at line 109 of file js-context-specialization.cc.

109  {
110  DCHECK_EQ(IrOpcode::kJSStoreContext, node->opcode());
111 
112  HeapObjectMatcher<Context> m(NodeProperties::GetValueInput(node, 0));
113  // If the context is not constant, no reduction can occur.
114  if (!m.HasValue()) {
115  return Reducer::NoChange();
116  }
117 
118  ContextAccess access = OpParameter<ContextAccess>(node);
119 
120  // The access does not have to look up a parent, nothing to fold.
121  if (access.depth() == 0) {
122  return Reducer::NoChange();
123  }
124 
125  // Find the right parent context.
126  Context* context = *m.Value().handle();
127  for (int i = access.depth(); i > 0; --i) {
128  context = context->previous();
129  }
130 
131  const Operator* op = jsgraph_->javascript()->StoreContext(0, access.index());
132  node->set_op(op);
133  Handle<Object> new_context_handle = Handle<Object>(context, info_->isolate());
134  node->ReplaceInput(0, jsgraph_->Constant(new_context_handle));
135 
136  return Reducer::Changed(node);
137 }
const Operator * StoreContext(uint16_t depth, uint32_t index)
Definition: js-operator.h:157

References v8::internal::compiler::Reducer::Changed(), v8::internal::compiler::JSGraph::Constant(), DCHECK_EQ, v8::internal::compiler::ContextAccess::depth(), v8::internal::compiler::NodeProperties::GetValueInput(), v8::internal::compiler::ContextAccess::index(), info_, v8::internal::CompilationInfo::isolate(), v8::internal::compiler::JSGraph::javascript(), jsgraph_, v8::internal::compiler::Reducer::NoChange(), v8::internal::Context::previous(), and v8::internal::compiler::JSOperatorBuilder::StoreContext().

Referenced by v8::internal::compiler::ContextSpecializationVisitor::Post().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SpecializeToContext()

void v8::internal::compiler::JSContextSpecializer::SpecializeToContext ( )

Definition at line 52 of file js-context-specialization.cc.

52  {
55 
56  ContextSpecializationVisitor visitor(this);
58 }
Handle< Context > context() const
Definition: compiler.h:127
void VisitNodeInputsFromEnd(Visitor *visitor)
Definition: graph-inl.h:30
static void ReplaceWithValue(Node *node, Node *value, Node *effect=NULL)

References v8::internal::compiler::JSGraph::Constant(), v8::internal::CompilationInfo::context(), context_, v8::internal::compiler::JSGraph::graph(), info_, jsgraph_, v8::internal::compiler::NodeProperties::ReplaceWithValue(), and v8::internal::compiler::Graph::VisitNodeInputsFromEnd().

Referenced by v8::internal::compiler::Pipeline::GenerateCode().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ context_

Node* v8::internal::compiler::JSContextSpecializer::context_
private

Definition at line 31 of file js-context-specialization.h.

Referenced by SpecializeToContext().

◆ info_

CompilationInfo* v8::internal::compiler::JSContextSpecializer::info_
private

◆ jsgraph_

JSGraph* v8::internal::compiler::JSContextSpecializer::jsgraph_
private

The documentation for this class was generated from the following files: