OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 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/compiler/code-stub-assembler.h" |
| 6 |
| 7 #include <ostream> |
| 8 |
| 9 #include "src/code-factory.h" |
| 10 #include "src/compiler/graph.h" |
| 11 #include "src/compiler/instruction-selector.h" |
| 12 #include "src/compiler/linkage.h" |
| 13 #include "src/compiler/machine-type.h" |
| 14 #include "src/compiler/pipeline.h" |
| 15 #include "src/compiler/raw-machine-assembler.h" |
| 16 #include "src/compiler/schedule.h" |
| 17 #include "src/frames.h" |
| 18 #include "src/interface-descriptors.h" |
| 19 #include "src/interpreter/bytecodes.h" |
| 20 #include "src/macro-assembler.h" |
| 21 #include "src/zone.h" |
| 22 |
| 23 namespace v8 { |
| 24 namespace internal { |
| 25 namespace compiler { |
| 26 |
| 27 |
| 28 CodeStubAssembler::CodeStubAssembler(Isolate* isolate, Zone* zone, |
| 29 const CallInterfaceDescriptor& descriptor, |
| 30 Code::Kind kind, const char* name) |
| 31 : raw_assembler_(new RawMachineAssembler( |
| 32 isolate, new (zone) Graph(zone), |
| 33 Linkage::GetStubCallDescriptor(isolate, zone, descriptor, 0, |
| 34 CallDescriptor::kNoFlags))), |
| 35 end_nodes_(zone), |
| 36 kind_(kind), |
| 37 name_(name), |
| 38 code_generated_(false) {} |
| 39 |
| 40 |
| 41 CodeStubAssembler::~CodeStubAssembler() {} |
| 42 |
| 43 |
| 44 Handle<Code> CodeStubAssembler::GenerateCode() { |
| 45 DCHECK(!code_generated_); |
| 46 |
| 47 End(); |
| 48 |
| 49 Schedule* schedule = raw_assembler_->Export(); |
| 50 Handle<Code> code = Pipeline::GenerateCodeForCodeStub( |
| 51 isolate(), raw_assembler_->call_descriptor(), graph(), schedule, kind_, |
| 52 name_); |
| 53 |
| 54 code_generated_ = true; |
| 55 return code; |
| 56 } |
| 57 |
| 58 |
| 59 Node* CodeStubAssembler::Int32Constant(int value) { |
| 60 return raw_assembler_->Int32Constant(value); |
| 61 } |
| 62 |
| 63 |
| 64 Node* CodeStubAssembler::IntPtrConstant(intptr_t value) { |
| 65 return raw_assembler_->IntPtrConstant(value); |
| 66 } |
| 67 |
| 68 |
| 69 Node* CodeStubAssembler::NumberConstant(double value) { |
| 70 return raw_assembler_->NumberConstant(value); |
| 71 } |
| 72 |
| 73 |
| 74 Node* CodeStubAssembler::HeapConstant(Handle<HeapObject> object) { |
| 75 return raw_assembler_->HeapConstant(object); |
| 76 } |
| 77 |
| 78 |
| 79 Node* CodeStubAssembler::BooleanConstant(bool value) { |
| 80 return raw_assembler_->BooleanConstant(value); |
| 81 } |
| 82 |
| 83 |
| 84 Node* CodeStubAssembler::Parameter(int value) { |
| 85 return raw_assembler_->Parameter(value); |
| 86 } |
| 87 |
| 88 |
| 89 void CodeStubAssembler::Return(Node* value) { |
| 90 return raw_assembler_->Return(value); |
| 91 } |
| 92 |
| 93 |
| 94 Node* CodeStubAssembler::SmiShiftBitsConstant() { |
| 95 return Int32Constant(kSmiShiftSize + kSmiTagSize); |
| 96 } |
| 97 |
| 98 |
| 99 Node* CodeStubAssembler::SmiTag(Node* value) { |
| 100 return raw_assembler_->WordShl(value, SmiShiftBitsConstant()); |
| 101 } |
| 102 |
| 103 |
| 104 Node* CodeStubAssembler::SmiUntag(Node* value) { |
| 105 return raw_assembler_->WordSar(value, SmiShiftBitsConstant()); |
| 106 } |
| 107 |
| 108 |
| 109 Node* CodeStubAssembler::IntPtrAdd(Node* a, Node* b) { |
| 110 return raw_assembler_->IntPtrAdd(a, b); |
| 111 } |
| 112 |
| 113 |
| 114 Node* CodeStubAssembler::IntPtrSub(Node* a, Node* b) { |
| 115 return raw_assembler_->IntPtrSub(a, b); |
| 116 } |
| 117 |
| 118 |
| 119 Node* CodeStubAssembler::WordShl(Node* value, int shift) { |
| 120 return raw_assembler_->WordShl(value, Int32Constant(shift)); |
| 121 } |
| 122 |
| 123 |
| 124 Node* CodeStubAssembler::LoadObjectField(Node* object, int offset) { |
| 125 return raw_assembler_->Load(kMachAnyTagged, object, |
| 126 IntPtrConstant(offset - kHeapObjectTag)); |
| 127 } |
| 128 |
| 129 |
| 130 Node* CodeStubAssembler::CallN(CallDescriptor* descriptor, Node* code_target, |
| 131 Node** args) { |
| 132 return raw_assembler_->CallN(descriptor, code_target, args); |
| 133 } |
| 134 |
| 135 |
| 136 Node* CodeStubAssembler::TailCallN(CallDescriptor* descriptor, |
| 137 Node* code_target, Node** args) { |
| 138 return raw_assembler_->TailCallN(descriptor, code_target, args); |
| 139 } |
| 140 |
| 141 |
| 142 Node* CodeStubAssembler::CallRuntime(Runtime::FunctionId function_id, |
| 143 Node* context, Node* arg1) { |
| 144 return raw_assembler_->CallRuntime1(function_id, arg1, context); |
| 145 } |
| 146 |
| 147 |
| 148 Node* CodeStubAssembler::CallRuntime(Runtime::FunctionId function_id, |
| 149 Node* context, Node* arg1, Node* arg2) { |
| 150 return raw_assembler_->CallRuntime2(function_id, arg1, arg2, context); |
| 151 } |
| 152 |
| 153 |
| 154 Node* CodeStubAssembler::TailCallRuntime(Runtime::FunctionId function_id, |
| 155 Node* context, Node* arg1) { |
| 156 return raw_assembler_->TailCallRuntime1(function_id, arg1, context); |
| 157 } |
| 158 |
| 159 |
| 160 Node* CodeStubAssembler::TailCallRuntime(Runtime::FunctionId function_id, |
| 161 Node* context, Node* arg1, |
| 162 Node* arg2) { |
| 163 return raw_assembler_->TailCallRuntime2(function_id, arg1, arg2, context); |
| 164 } |
| 165 |
| 166 |
| 167 void CodeStubAssembler::AddEndInput(Node* input) { |
| 168 DCHECK_NOT_NULL(input); |
| 169 end_nodes_.push_back(input); |
| 170 } |
| 171 |
| 172 |
| 173 void CodeStubAssembler::End() { |
| 174 if (end_nodes_.size() == 0) { |
| 175 end_nodes_.push_back(graph()->start()); |
| 176 } |
| 177 int end_count = static_cast<int>(end_nodes_.size()); |
| 178 Node* end = graph()->NewNode(raw_assembler_->common()->End(end_count), |
| 179 end_count, &end_nodes_[0]); |
| 180 graph()->SetEnd(end); |
| 181 } |
| 182 |
| 183 |
| 184 // RawMachineAssembler delegate helpers: |
| 185 Isolate* CodeStubAssembler::isolate() { return raw_assembler_->isolate(); } |
| 186 |
| 187 |
| 188 Graph* CodeStubAssembler::graph() { return raw_assembler_->graph(); } |
| 189 |
| 190 |
| 191 Zone* CodeStubAssembler::zone() { return raw_assembler_->zone(); } |
| 192 |
| 193 |
| 194 } // namespace compiler |
| 195 } // namespace internal |
| 196 } // namespace v8 |
OLD | NEW |