mini-llvm 0.1.0
Loading...
Searching...
No Matches
CmpBr.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
23
24namespace mini_llvm::mir {
25
27public:
30 std::shared_ptr<Register> src1,
31 std::shared_ptr<Register> src2,
34 : width_(width),
35 cond_(cond),
36 src1_(RegisterClass::kGPR, std::move(src1)),
37 src2_(RegisterClass::kGPR, std::move(src2)),
38 trueDest_(trueDest),
39 falseDest_(falseDest) {}
40
41 int width() const {
42 return width_;
43 }
44
45 Condition cond() const {
46 return cond_;
47 }
48
50 cond_ = cond;
51 }
52
53 template <typename Self>
54 auto &src1(this Self &&self) {
55 return self.src1_;
56 }
57
58 template <typename Self>
59 auto &src2(this Self &&self) {
60 return self.src2_;
61 }
62
63 template <typename Self>
64 auto &trueDest(this Self &&self) {
65 return self.trueDest_;
66 }
67
68 template <typename Self>
69 auto &falseDest(this Self &&self) {
70 return self.falseDest_;
71 }
72
73 std::unordered_set<const BasicBlockOperand *> blockOps() const override {
74 return {&trueDest(), &falseDest()};
75 }
76
77 std::unordered_set<const RegisterOperand *> regOps() const override {
78 return {&src1(), &src2()};
79 }
80
81 std::unordered_set<const RegisterOperand *> dsts() const override {
82 return {};
83 }
84
85 std::unordered_set<const RegisterOperand *> srcs() const override {
86 return {&src1(), &src2()};
87 }
88
89 std::unordered_set<const ImmediateOperand *> immOps() const override {
90 return {};
91 }
92
93 std::unordered_set<const MemoryOperand *> memOps() const override {
94 return {};
95 }
96
97 std::string format() const override {
98 return std::format(
99 "CMPBR i{} {} {}, {}, {:o}, {:o}",
100 width() * 8, specifier(cond()), *src1(), *src2(), *trueDest(), *falseDest());
101 }
102
103 std::unique_ptr<Instruction> clone() const override {
104 return std::make_unique<CmpBr>(
105 width(), cond(), share(*src1()), share(*src2()), &*trueDest(), &*falseDest());
106 }
107
108 void accept(InstructionVisitor &visitor) override {
109 visitor.visitCmpBr(*this);
110 }
111
112 void accept(InstructionVisitor &visitor) const override {
113 visitor.visitCmpBr(*this);
114 }
115
116private:
117 int width_;
118 Condition cond_;
119 RegisterOperand src1_, src2_;
120 BasicBlockOperand trueDest_, falseDest_;
121};
122
123} // namespace mini_llvm::mir
#define MINI_LLVM_EXPORT
Definition Compiler.h:17
Definition BasicBlockOperand.h:9
Definition BasicBlock.h:24
std::unordered_set< const MemoryOperand * > memOps() const override
Definition CmpBr.h:93
CmpBr(int width, Condition cond, std::shared_ptr< Register > src1, std::shared_ptr< Register > src2, BasicBlock *trueDest, BasicBlock *falseDest)
Definition CmpBr.h:28
std::unordered_set< const ImmediateOperand * > immOps() const override
Definition CmpBr.h:89
std::unordered_set< const RegisterOperand * > regOps() const override
Definition CmpBr.h:77
void setCond(Condition cond)
Definition CmpBr.h:49
auto & falseDest(this Self &&self)
Definition CmpBr.h:69
std::unordered_set< const BasicBlockOperand * > blockOps() const override
Definition CmpBr.h:73
std::unordered_set< const RegisterOperand * > dsts() const override
Definition CmpBr.h:81
std::string format() const override
Definition CmpBr.h:97
void accept(InstructionVisitor &visitor) const override
Definition CmpBr.h:112
std::unordered_set< const RegisterOperand * > srcs() const override
Definition CmpBr.h:85
auto & src2(this Self &&self)
Definition CmpBr.h:59
auto & src1(this Self &&self)
Definition CmpBr.h:54
std::unique_ptr< Instruction > clone() const override
Definition CmpBr.h:103
Condition cond() const
Definition CmpBr.h:45
auto & trueDest(this Self &&self)
Definition CmpBr.h:64
void accept(InstructionVisitor &visitor) override
Definition CmpBr.h:108
int width() const
Definition CmpBr.h:41
Definition InstructionVisitor.h:70
virtual void visitCmpBr(CmpBr &I)
Definition InstructionVisitor.h:87
Definition RegisterOperand.h:13
Definition Terminator.h:13
Definition BasicBlock.h:22
constexpr const char * specifier(Condition cond)
Definition Condition.h:15
RegisterClass
Definition RegisterClass.h:7
@ kGPR
Definition RegisterClass.h:8
Condition
Definition Condition.h:9
std::shared_ptr< T > share(T &value)
Definition Memory.h:25