5 #ifndef V8_TORQUE_INSTRUCTIONS_H_ 6 #define V8_TORQUE_INSTRUCTIONS_H_ 10 #include "src/torque/ast.h" 11 #include "src/torque/source-positions.h" 12 #include "src/torque/types.h" 13 #include "src/torque/utils.h" 21 class ControlFlowGraph;
24 class NamespaceConstant;
25 class RuntimeFunction;
27 #define TORQUE_INSTRUCTION_LIST(V) \ 30 V(DeleteRangeInstruction) \ 31 V(PushUninitializedInstruction) \ 32 V(PushCodePointerInstruction) \ 33 V(CallCsaMacroInstruction) \ 34 V(CallIntrinsicInstruction) \ 35 V(NamespaceConstantInstruction) \ 36 V(CallCsaMacroAndBranchInstruction) \ 37 V(CallBuiltinInstruction) \ 38 V(CallRuntimeInstruction) \ 39 V(CallBuiltinPointerInstruction) \ 40 V(BranchInstruction) \ 41 V(ConstexprBranchInstruction) \ 43 V(GotoExternalInstruction) \ 44 V(ReturnInstruction) \ 45 V(PrintConstantStringInstruction) \ 47 V(UnsafeCastInstruction) 49 #define TORQUE_INSTRUCTION_BOILERPLATE() \ 50 static const InstructionKind kKind; \ 51 std::unique_ptr<InstructionBase> Clone() const override; \ 52 void Assign(const InstructionBase& other) override; \ 53 void TypeInstruction(Stack<const Type*>* stack, ControlFlowGraph* cfg) \ 56 enum class InstructionKind {
57 #define ENUM_ITEM(name) k##name, 58 TORQUE_INSTRUCTION_LIST(ENUM_ITEM)
64 virtual std::unique_ptr<InstructionBase> Clone()
const = 0;
71 virtual bool IsBlockTerminator()
const {
return false; }
72 virtual void AppendSuccessorBlocks(std::vector<Block*>* block_list)
const {}
81 : kind_(T::kKind), instruction_(
new T(std::move(instr))) {}
86 return static_cast<T&
>(*instruction_);
90 const T& Cast()
const {
92 return static_cast<const T&
>(*instruction_);
97 return kind_ == T::kKind;
102 if (Is<T>())
return &Cast<T>();
107 const T* DynamicCast()
const {
108 if (Is<T>())
return &Cast<T>();
113 : kind_(other.kind_), instruction_(other.instruction_->Clone()) {}
115 if (kind_ == other.kind_) {
116 instruction_->Assign(*other.instruction_);
119 instruction_ = other.instruction_->Clone();
124 InstructionKind kind()
const {
return kind_; }
126 return instruction_->TypeInstruction(stack, cfg);
130 const InstructionBase* operator->()
const {
return instruction_.get(); }
133 InstructionKind kind_;
134 std::unique_ptr<InstructionBase> instruction_;
138 TORQUE_INSTRUCTION_BOILERPLATE()
141 : slot(slot), widened_type(widened_type) {}
148 TORQUE_INSTRUCTION_BOILERPLATE()
151 : slot(slot), widened_type(widened_type) {}
160 TORQUE_INSTRUCTION_BOILERPLATE()
167 TORQUE_INSTRUCTION_BOILERPLATE()
174 TORQUE_INSTRUCTION_BOILERPLATE()
176 : external_name(std::move(external_name)),
type(
type) {
177 DCHECK(
type->IsFunctionPointerType());
180 std::string external_name;
185 TORQUE_INSTRUCTION_BOILERPLATE()
187 : constant(constant) {}
193 TORQUE_INSTRUCTION_BOILERPLATE()
195 std::vector<std::string> constexpr_arguments)
196 : intrinsic(intrinsic), constexpr_arguments(constexpr_arguments) {}
199 std::vector<std::string> constexpr_arguments;
203 TORQUE_INSTRUCTION_BOILERPLATE()
205 std::vector<std::string> constexpr_arguments,
208 constexpr_arguments(constexpr_arguments),
209 catch_block(catch_block) {}
210 void AppendSuccessorBlocks(std::vector<Block*>* block_list)
const override {
211 if (catch_block) block_list->push_back(*catch_block);
215 std::vector<std::string> constexpr_arguments;
220 TORQUE_INSTRUCTION_BOILERPLATE()
222 std::vector<std::string> constexpr_arguments,
224 std::vector<Block*> label_blocks,
227 constexpr_arguments(constexpr_arguments),
228 return_continuation(return_continuation),
229 label_blocks(label_blocks),
230 catch_block(catch_block) {}
231 bool IsBlockTerminator()
const override {
return true; }
232 void AppendSuccessorBlocks(std::vector<Block*>* block_list)
const override {
233 if (catch_block) block_list->push_back(*catch_block);
234 if (return_continuation) block_list->push_back(*return_continuation);
235 for (
Block* block : label_blocks) block_list->push_back(block);
239 std::vector<std::string> constexpr_arguments;
241 std::vector<Block*> label_blocks;
246 TORQUE_INSTRUCTION_BOILERPLATE()
247 bool IsBlockTerminator()
const override {
return is_tailcall; }
250 : is_tailcall(is_tailcall),
253 catch_block(catch_block) {}
254 void AppendSuccessorBlocks(std::vector<Block*>* block_list)
const override {
255 if (catch_block) block_list->push_back(*catch_block);
265 TORQUE_INSTRUCTION_BOILERPLATE()
266 bool IsBlockTerminator()
const override {
return is_tailcall; }
269 : is_tailcall(is_tailcall),
type(
type), argc(argc) {}
277 TORQUE_INSTRUCTION_BOILERPLATE()
278 bool IsBlockTerminator()
const override;
282 : is_tailcall(is_tailcall),
283 runtime_function(runtime_function),
285 catch_block(catch_block) {}
286 void AppendSuccessorBlocks(std::vector<Block*>* block_list)
const override {
287 if (catch_block) block_list->push_back(*catch_block);
297 TORQUE_INSTRUCTION_BOILERPLATE()
298 bool IsBlockTerminator()
const override {
return true; }
299 void AppendSuccessorBlocks(std::vector<Block*>* block_list)
const override {
300 block_list->push_back(if_true);
301 block_list->push_back(if_false);
305 : if_true(if_true), if_false(if_false) {}
312 TORQUE_INSTRUCTION_BOILERPLATE()
313 bool IsBlockTerminator()
const override {
return true; }
314 void AppendSuccessorBlocks(std::vector<Block*>* block_list)
const override {
315 block_list->push_back(if_true);
316 block_list->push_back(if_false);
321 : condition(condition), if_true(if_true), if_false(if_false) {}
323 std::string condition;
329 TORQUE_INSTRUCTION_BOILERPLATE()
330 bool IsBlockTerminator()
const override {
return true; }
331 void AppendSuccessorBlocks(std::vector<Block*>* block_list)
const override {
332 block_list->push_back(destination);
341 TORQUE_INSTRUCTION_BOILERPLATE()
342 bool IsBlockTerminator()
const override {
return true; }
345 std::vector<std::string> variable_names)
346 : destination(std::move(destination)),
347 variable_names(std::move(variable_names)) {}
349 std::string destination;
350 std::vector<std::string> variable_names;
354 TORQUE_INSTRUCTION_BOILERPLATE()
355 bool IsBlockTerminator()
const override {
return true; }
359 TORQUE_INSTRUCTION_BOILERPLATE()
362 this->message = std::move(message);
369 TORQUE_INSTRUCTION_BOILERPLATE()
370 enum class Kind { kDebugBreak, kUnreachable, kAssertionFailure };
371 bool IsBlockTerminator()
const override {
return kind != Kind::kDebugBreak; }
372 explicit AbortInstruction(Kind kind, std::string message =
"") : kind(kind) {
374 this->message = std::move(message);
382 TORQUE_INSTRUCTION_BOILERPLATE()
384 : destination_type(destination_type) {}
386 const Type* destination_type;
393 #endif // V8_TORQUE_INSTRUCTIONS_H_