mini-llvm 0.1.0
Loading...
Searching...
No Matches
LI.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:
26 LI(int width, std::shared_ptr<Register> dst, std::unique_ptr<Immediate> src)
27 : width_(width), dst_(RegisterClass::kGPR, std::move(dst)), src_(std::move(src)) {}
28
29 int width() const {
30 return width_;
31 }
32
33 template <typename Self>
34 auto &dst(this Self &&self) {
35 return self.dst_;
36 }
37
38 template <typename Self>
39 auto &src(this Self &&self) {
40 return self.src_;
41 }
42
43 std::unordered_set<const RegisterOperand *> regOps() const override {
44 return {&dst()};
45 }
46
47 std::unordered_set<const RegisterOperand *> dsts() const override {
48 return {&dst()};
49 }
50
51 std::unordered_set<const RegisterOperand *> srcs() const override {
52 return {};
53 }
54
55 std::unordered_set<const ImmediateOperand *> immOps() const override {
56 return {&src()};
57 }
58
59 std::unordered_set<const MemoryOperand *> memOps() const override {
60 return {};
61 }
62
63 std::string format() const override {
64 return std::format("LI i{} {}, {}", width() * 8, *dst(), *src());
65 }
66
67 bool hasSideEffects() const override {
68 return false;
69 }
70
71 std::unique_ptr<Instruction> clone() const override {
72 return std::make_unique<LI>(width(), share(*dst()), src()->clone());
73 }
74
75 void accept(InstructionVisitor &visitor) override {
76 visitor.visitLI(*this);
77 }
78
79 void accept(InstructionVisitor &visitor) const override {
80 visitor.visitLI(*this);
81 }
82
83private:
84 int width_;
85 RegisterOperand dst_;
87};
88
89} // namespace mini_llvm::mir
#define MINI_LLVM_EXPORT
Definition Compiler.h:17
Definition ImmediateOperand.h:12
Definition InstructionVisitor.h:70
virtual void visitLI(LI &I)
Definition InstructionVisitor.h:113
std::unordered_set< const RegisterOperand * > srcs() const override
Definition LI.h:51
std::unordered_set< const ImmediateOperand * > immOps() const override
Definition LI.h:55
auto & dst(this Self &&self)
Definition LI.h:34
std::unique_ptr< Instruction > clone() const override
Definition LI.h:71
auto & src(this Self &&self)
Definition LI.h:39
void accept(InstructionVisitor &visitor) override
Definition LI.h:75
bool hasSideEffects() const override
Definition LI.h:67
int width() const
Definition LI.h:29
std::unordered_set< const MemoryOperand * > memOps() const override
Definition LI.h:59
std::unordered_set< const RegisterOperand * > dsts() const override
Definition LI.h:47
std::unordered_set< const RegisterOperand * > regOps() const override
Definition LI.h:43
void accept(InstructionVisitor &visitor) const override
Definition LI.h:79
std::string format() const override
Definition LI.h:63
LI(int width, std::shared_ptr< Register > dst, std::unique_ptr< Immediate > src)
Definition LI.h:26
Definition RegisterOperand.h:13
Definition BasicBlock.h:22
RegisterClass
Definition RegisterClass.h:7
@ kGPR
Definition RegisterClass.h:8
std::shared_ptr< T > share(T &value)
Definition Memory.h:25