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