mini-llvm 0.1.0
Loading...
Searching...
No Matches
BinaryOperatorI.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()};
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()};
56 }
57
58 std::unordered_set<const ImmediateOperand *> immOps() const override {
59 return {&src2()};
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::unique_ptr<Immediate> src2,
74 : width_(width),
75 dst_(RegisterClass::kGPR, std::move(dst)),
76 src1_(RegisterClass::kGPR, std::move(src1)),
77 src2_(std::move(src2)),
78 extMode_(extMode) {}
79
80 virtual const char *mnemonic() const = 0;
81
82private:
83 int width_;
84 RegisterOperand dst_, src1_;
85 ImmediateOperand src2_;
86 ExtensionMode extMode_;
87};
88
89} // namespace mini_llvm::mir
#define MINI_LLVM_EXPORT
Definition Compiler.h:17
std::string format() const override
std::unordered_set< const RegisterOperand * > dsts() const override
Definition BinaryOperatorI.h:50
auto & src2(this Self &&self)
Definition BinaryOperatorI.h:38
BinaryOperatorI(int width, std::shared_ptr< Register > dst, std::shared_ptr< Register > src1, std::unique_ptr< Immediate > src2, ExtensionMode extMode)
Definition BinaryOperatorI.h:69
std::unordered_set< const MemoryOperand * > memOps() const override
Definition BinaryOperatorI.h:62
ExtensionMode extMode() const
Definition BinaryOperatorI.h:42
std::unordered_set< const RegisterOperand * > srcs() const override
Definition BinaryOperatorI.h:54
std::unordered_set< const ImmediateOperand * > immOps() const override
Definition BinaryOperatorI.h:58
std::unordered_set< const RegisterOperand * > regOps() const override
Definition BinaryOperatorI.h:46
int width() const
Definition BinaryOperatorI.h:23
auto & src1(this Self &&self)
Definition BinaryOperatorI.h:33
auto & dst(this Self &&self)
Definition BinaryOperatorI.h:28
virtual const char * mnemonic() const =0
Definition ImmediateOperand.h:12
Definition RegisterOperand.h:13
Definition BasicBlock.h:22
RegisterClass
Definition RegisterClass.h:7
@ kGPR
Definition RegisterClass.h:8
ExtensionMode
Definition ExtensionMode.h:7