mini-llvm 0.1.0
Loading...
Searching...
No Matches
CmpSet.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
21
22namespace mini_llvm::mir {
23
25public:
27 int srcWidth,
29 std::shared_ptr<Register> dst,
30 std::shared_ptr<Register> src1,
31 std::shared_ptr<Register> src2)
32 : dstWidth_(dstWidth),
33 srcWidth_(srcWidth),
34 cond_(cond),
35 dst_(RegisterClass::kGPR, std::move(dst)),
36 src1_(RegisterClass::kGPR, std::move(src1)),
37 src2_(RegisterClass::kGPR, std::move(src2)) {}
38
39 int dstWidth() const {
40 return dstWidth_;
41 }
42
43 int srcWidth() const {
44 return srcWidth_;
45 }
46
47 Condition cond() const {
48 return cond_;
49 }
50
52 cond_ = cond;
53 }
54
55 template <typename Self>
56 auto &dst(this Self &&self) {
57 return self.dst_;
58 }
59
60 template <typename Self>
61 auto &src1(this Self &&self) {
62 return self.src1_;
63 }
64
65 template <typename Self>
66 auto &src2(this Self &&self) {
67 return self.src2_;
68 }
69
70 std::unordered_set<const RegisterOperand *> regOps() const override {
71 return {&dst(), &src1(), &src2()};
72 }
73
74 std::unordered_set<const RegisterOperand *> dsts() const override {
75 return {&dst()};
76 }
77
78 std::unordered_set<const RegisterOperand *> srcs() const override {
79 return {&src1(), &src2()};
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 bool hasSideEffects() const override {
91 return false;
92 }
93
94 std::string format() const override {
95 return std::format(
96 "CMPSET i{} i{} {} {}, {}, {}",
97 dstWidth() * 8, srcWidth() * 8, specifier(cond()), *dst(), *src1(), *src2());
98 }
99
100 std::unique_ptr<Instruction> clone() const override {
101 return std::make_unique<CmpSet>(
102 dstWidth(), srcWidth(), cond(), share(*dst()), share(*src1()), share(*src2()));
103 }
104
105 void accept(InstructionVisitor &visitor) override {
106 visitor.visitCmpSet(*this);
107 }
108
109 void accept(InstructionVisitor &visitor) const override {
110 visitor.visitCmpSet(*this);
111 }
112
113private:
114 int dstWidth_, srcWidth_;
115 Condition cond_;
116 RegisterOperand dst_, src1_, src2_;
117};
118
119} // namespace mini_llvm::mir
#define MINI_LLVM_EXPORT
Definition Compiler.h:17
CmpSet(int dstWidth, int srcWidth, Condition cond, std::shared_ptr< Register > dst, std::shared_ptr< Register > src1, std::shared_ptr< Register > src2)
Definition CmpSet.h:26
Condition cond() const
Definition CmpSet.h:47
int dstWidth() const
Definition CmpSet.h:39
std::string format() const override
Definition CmpSet.h:94
std::unordered_set< const RegisterOperand * > dsts() const override
Definition CmpSet.h:74
auto & src1(this Self &&self)
Definition CmpSet.h:61
std::unique_ptr< Instruction > clone() const override
Definition CmpSet.h:100
void setCond(Condition cond)
Definition CmpSet.h:51
auto & src2(this Self &&self)
Definition CmpSet.h:66
std::unordered_set< const RegisterOperand * > srcs() const override
Definition CmpSet.h:78
auto & dst(this Self &&self)
Definition CmpSet.h:56
void accept(InstructionVisitor &visitor) override
Definition CmpSet.h:105
void accept(InstructionVisitor &visitor) const override
Definition CmpSet.h:109
std::unordered_set< const ImmediateOperand * > immOps() const override
Definition CmpSet.h:82
bool hasSideEffects() const override
Definition CmpSet.h:90
int srcWidth() const
Definition CmpSet.h:43
std::unordered_set< const MemoryOperand * > memOps() const override
Definition CmpSet.h:86
std::unordered_set< const RegisterOperand * > regOps() const override
Definition CmpSet.h:70
Definition InstructionVisitor.h:70
virtual void visitCmpSet(CmpSet &I)
Definition InstructionVisitor.h:89
Definition RegisterOperand.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