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