mini-llvm 0.1.0
Loading...
Searching...
No Matches
FBinaryOperator.h
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2
3#pragma once
4
5#include <format>
6#include <memory>
7#include <string>
8#include <unordered_set>
9#include <utility>
10
20
21namespace mini_llvm::mir {
22
24public:
26 return precision_;
27 }
28
29 template <typename Self>
30 auto &dst(this Self &&self) {
31 return self.dst_;
32 }
33
34 template <typename Self>
35 auto &src1(this Self &&self) {
36 return self.src1_;
37 }
38
39 template <typename Self>
40 auto &src2(this Self &&self) {
41 return self.src2_;
42 }
43
44 std::unordered_set<const RegisterOperand *> regOps() const override {
45 return {&dst(), &src1(), &src2()};
46 }
47
48 std::unordered_set<const RegisterOperand *> dsts() const override {
49 return {&dst()};
50 }
51
52 std::unordered_set<const RegisterOperand *> srcs() const override {
53 return {&src1(), &src2()};
54 }
55
56 std::unordered_set<const ImmediateOperand *> immOps() const override {
57 return {};
58 }
59
60 std::unordered_set<const MemoryOperand *> memOps() const override {
61 return {};
62 }
63
64 std::string format() const override {
65 return std::format("{} {} {}, {}, {}", mnemonic(), specifier(precision()), *dst(), *src1(), *src2());
66 }
67
68protected:
70 std::shared_ptr<Register> dst,
71 std::shared_ptr<Register> src1,
72 std::shared_ptr<Register> src2)
73 : precision_(precision),
74 dst_(RegisterClass::kFPR, std::move(dst)),
75 src1_(RegisterClass::kFPR, std::move(src1)),
76 src2_(RegisterClass::kFPR, std::move(src2)) {}
77
78 virtual const char *mnemonic() const = 0;
79
80private:
81 Precision precision_;
82 RegisterOperand dst_, src1_, src2_;
83};
84
85} // namespace mini_llvm::mir
#define MINI_LLVM_EXPORT
Definition Compiler.h:17
auto & dst(this Self &&self)
Definition FBinaryOperator.h:30
auto & src1(this Self &&self)
Definition FBinaryOperator.h:35
std::unordered_set< const MemoryOperand * > memOps() const override
Definition FBinaryOperator.h:60
std::unordered_set< const RegisterOperand * > regOps() const override
Definition FBinaryOperator.h:44
std::unordered_set< const ImmediateOperand * > immOps() const override
Definition FBinaryOperator.h:56
std::string format() const override
Definition FBinaryOperator.h:64
std::unordered_set< const RegisterOperand * > srcs() const override
Definition FBinaryOperator.h:52
auto & src2(this Self &&self)
Definition FBinaryOperator.h:40
Precision precision() const
Definition FBinaryOperator.h:25
virtual const char * mnemonic() const =0
std::unordered_set< const RegisterOperand * > dsts() const override
Definition FBinaryOperator.h:48
FBinaryOperator(Precision precision, std::shared_ptr< Register > dst, std::shared_ptr< Register > src1, std::shared_ptr< Register > src2)
Definition FBinaryOperator.h:69
Definition RegisterOperand.h:13
Definition BasicBlock.h:22
constexpr const char * specifier(Condition cond)
Definition Condition.h:15
RegisterClass
Definition RegisterClass.h:7
@ kFPR
Definition RegisterClass.h:9
Precision
Definition Precision.h:7