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