V8 Project
raw-machine-assembler.cc
Go to the documentation of this file.
1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "src/code-factory.h"
9 
10 namespace v8 {
11 namespace internal {
12 namespace compiler {
13 
15  MachineSignature* machine_sig,
16  MachineType word)
17  : GraphBuilder(graph),
18  schedule_(new (zone()) Schedule(zone())),
19  machine_(word),
20  common_(zone()),
21  machine_sig_(machine_sig),
22  call_descriptor_(
23  Linkage::GetSimplifiedCDescriptor(graph->zone(), machine_sig)),
24  parameters_(NULL),
25  exit_label_(schedule()->end()),
26  current_block_(schedule()->start()) {
27  int param_count = static_cast<int>(parameter_count());
28  Node* s = graph->NewNode(common_.Start(param_count));
29  graph->SetStart(s);
30  if (parameter_count() == 0) return;
31  parameters_ = zone()->NewArray<Node*>(param_count);
32  for (size_t i = 0; i < parameter_count(); ++i) {
33  parameters_[i] =
34  NewNode(common()->Parameter(static_cast<int>(i)), graph->start());
35  }
36 }
37 
38 
40  // Compute the correct codegen order.
41  DCHECK(schedule_->rpo_order()->empty());
43  // Invalidate MachineAssembler.
45  schedule_ = NULL;
46  return schedule;
47 }
48 
49 
50 Node* RawMachineAssembler::Parameter(size_t index) {
51  DCHECK(index < parameter_count());
52  return parameters_[index];
53 }
54 
55 
57  exit_label_.used_ = true;
58  return &exit_label_;
59 }
60 
61 
63  DCHECK(current_block_ != schedule()->end());
64  schedule()->AddGoto(CurrentBlock(), Use(label));
66 }
67 
68 
69 void RawMachineAssembler::Branch(Node* condition, Label* true_val,
70  Label* false_val) {
71  DCHECK(current_block_ != schedule()->end());
72  Node* branch = NewNode(common()->Branch(), condition);
73  schedule()->AddBranch(CurrentBlock(), branch, Use(true_val), Use(false_val));
75 }
76 
77 
78 void RawMachineAssembler::Return(Node* value) {
79  schedule()->AddReturn(CurrentBlock(), value);
81 }
82 
83 
84 Node* RawMachineAssembler::CallFunctionStub0(Node* function, Node* receiver,
85  Node* context, Node* frame_state,
87  Callable callable = CodeFactory::CallFunction(isolate(), 0, flags);
88  CallDescriptor* desc = Linkage::GetStubCallDescriptor(
89  callable.descriptor(), 1, CallDescriptor::kNeedsFrameState, zone());
90  Node* stub_code = HeapConstant(callable.code());
91  Node* call = graph()->NewNode(common()->Call(desc), stub_code, function,
92  receiver, context, frame_state);
93  schedule()->AddNode(CurrentBlock(), call);
94  return call;
95 }
96 
97 
98 Node* RawMachineAssembler::CallJS0(Node* function, Node* receiver,
99  Node* context, Node* frame_state) {
100  CallDescriptor* descriptor = Linkage::GetJSCallDescriptor(1, zone());
101  Node* call = graph()->NewNode(common()->Call(descriptor), function, receiver,
102  context, frame_state);
103  schedule()->AddNode(CurrentBlock(), call);
104  return call;
105 }
106 
107 
109  Node* arg0, Node* context,
110  Node* frame_state) {
111  CallDescriptor* descriptor = Linkage::GetRuntimeCallDescriptor(
112  function, 1, Operator::kNoProperties, zone());
113 
114  Node* centry = HeapConstant(CEntryStub(isolate(), 1).GetCode());
115  Node* ref = NewNode(
116  common()->ExternalConstant(ExternalReference(function, isolate())));
117  Node* arity = Int32Constant(1);
118 
119  Node* call = graph()->NewNode(common()->Call(descriptor), centry, arg0, ref,
120  arity, context, frame_state);
121  schedule()->AddNode(CurrentBlock(), call);
122  return call;
123 }
124 
125 
128  DCHECK(!label->bound_);
129  label->bound_ = true;
130  current_block_ = EnsureBlock(label);
131 }
132 
133 
134 BasicBlock* RawMachineAssembler::Use(Label* label) {
135  label->used_ = true;
136  return EnsureBlock(label);
137 }
138 
139 
141  if (label->block_ == NULL) label->block_ = schedule()->NewBasicBlock();
142  return label->block_;
143 }
144 
145 
148  return current_block_;
149 }
150 
151 
152 Node* RawMachineAssembler::MakeNode(const Operator* op, int input_count,
153  Node** inputs) {
156  Node* node = graph()->NewNode(op, input_count, inputs);
157  BasicBlock* block = op->opcode() == IrOpcode::kParameter ? schedule()->start()
158  : CurrentBlock();
159  schedule()->AddNode(block, node);
160  return node;
161 }
162 
163 } // namespace compiler
164 } // namespace internal
165 } // namespace v8
T * NewArray(int length)
Definition: zone.h:46
Node * NewNode(const Operator *op)
Definition: graph-builder.h:27
Node * NewNode(const Operator *op, int input_count, Node **inputs)
Definition: graph.cc:24
CallDescriptor * GetStubCallDescriptor(CallInterfaceDescriptor descriptor, int stack_parameter_count=0, CallDescriptor::Flags flags=CallDescriptor::kNoFlags)
Definition: linkage.cc:103
CallDescriptor * GetJSCallDescriptor(int parameter_count)
Definition: linkage.cc:90
CallDescriptor * GetRuntimeCallDescriptor(Runtime::FunctionId function, int parameter_count, Operator::Properties properties)
Definition: linkage.cc:95
Node * CallJS0(Node *function, Node *receiver, Node *context, Node *frame_state)
Node * HeapConstant(Handle< Object > object)
RawMachineAssembler(Graph *graph, MachineSignature *machine_sig, MachineType word=kMachPtr)
void Branch(Node *condition, Label *true_val, Label *false_val)
virtual Node * MakeNode(const Operator *op, int input_count, Node **inputs) FINAL
Node * CallRuntime1(Runtime::FunctionId function, Node *arg0, Node *context, Node *frame_state)
Node * CallFunctionStub0(Node *function, Node *receiver, Node *context, Node *frame_state, CallFunctionFlags flags)
void AddGoto(BasicBlock *block, BasicBlock *succ)
Definition: schedule.h:231
void AddReturn(BasicBlock *block, Node *input)
Definition: schedule.h:253
void AddBranch(BasicBlock *block, Node *branch, BasicBlock *tblock, BasicBlock *fblock)
Definition: schedule.h:238
void AddNode(BasicBlock *block, Node *node)
Definition: schedule.h:220
BasicBlockVector * rpo_order()
Definition: schedule.h:279
static BasicBlockVector * ComputeSpecialRPO(Schedule *schedule)
Definition: scheduler.cc:933
enable harmony numeric enable harmony object literal extensions Optimize object Array DOM strings and string trace pretenuring decisions of HAllocate instructions Enables optimizations which favor memory size over execution speed maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining trace the tracking of allocation sites deoptimize every n garbage collections perform array bounds checks elimination analyze liveness of environment slots and zap dead values flushes the cache of optimized code for closures on every GC allow uint32 values on optimize frames if they are used only in safe operations track concurrent recompilation artificial compilation delay in ms do not emit check maps for constant values that have a leaf deoptimize the optimized code if the layout of the maps changes enable context specialization in TurboFan execution budget before interrupt is triggered max percentage of megamorphic generic ICs to allow optimization enable use of SAHF instruction if enable use of VFP3 instructions if available enable use of NEON instructions if enable use of SDIV and UDIV instructions if enable use of MLS instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of d16 d31 registers on ARM this requires VFP3 force all emitted branches to be in long enable alignment of csp to bytes on platforms which prefer the register to always be NULL
#define DCHECK(condition)
Definition: logging.h:205
Debugger support for the V8 JavaScript engine.
Definition: accessors.cc:20