mini-llvm 0.1.0
Loading...
Searching...
No Matches
FUnaryOperator.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
20
21namespace mini_llvm::mir {
22
24public:
26 return precision_;
27 }
28
29 template <typename Self>
30 auto &dst(this Self &&self) {
31 return self.dst_;
32 }
33
34 template <typename Self>
35 auto &src(this Self &&self) {
36 return self.src_;
37 }
38
39 std::unordered_set<const RegisterOperand *> regOps() const override {
40 return {&dst(), &src()};
41 }
42
43 std::unordered_set<const RegisterOperand *> dsts() const override {
44 return {&dst()};
45 }
46
47 std::unordered_set<const RegisterOperand *> srcs() const override {
48 return {&src()};
49 }
50
51 std::unordered_set<const ImmediateOperand *> immOps() const override {
52 return {};
53 }
54
55 std::unordered_set<const MemoryOperand *> memOps() const override {
56 return {};
57 }
58
59 std::string format() const override {
60 return std::format("{} {} {}, {}", mnemonic(), specifier(precision()), *dst(), *src());
61 }
62
63protected:
64 FUnaryOperator(Precision precision, std::shared_ptr<Register> dst, std::shared_ptr<Register> src)
65 : precision_(precision),
66 dst_(RegisterClass::kFPR, std::move(dst)),
67 src_(RegisterClass::kFPR, std::move(src)) {}
68
69 virtual const char *mnemonic() const = 0;
70
71private:
72 Precision precision_;
73 RegisterOperand dst_, src_;
74};
75
76} // namespace mini_llvm::mir
#define MINI_LLVM_EXPORT
Definition Compiler.h:17
std::unordered_set< const RegisterOperand * > dsts() const override
Definition FUnaryOperator.h:43
std::unordered_set< const MemoryOperand * > memOps() const override
Definition FUnaryOperator.h:55
virtual const char * mnemonic() const =0
Precision precision() const
Definition FUnaryOperator.h:25
auto & src(this Self &&self)
Definition FUnaryOperator.h:35
auto & dst(this Self &&self)
Definition FUnaryOperator.h:30
std::unordered_set< const RegisterOperand * > regOps() const override
Definition FUnaryOperator.h:39
std::unordered_set< const RegisterOperand * > srcs() const override
Definition FUnaryOperator.h:47
std::unordered_set< const ImmediateOperand * > immOps() const override
Definition FUnaryOperator.h:51
std::string format() const override
Definition FUnaryOperator.h:59
FUnaryOperator(Precision precision, std::shared_ptr< Register > dst, std::shared_ptr< Register > src)
Definition FUnaryOperator.h:64
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
Precision
Definition Precision.h:7