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