mini-llvm
0.1.0
Toggle main menu visibility
Loading...
Searching...
No Matches
Cmp.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
11
#include "
mini-llvm/mir/ImmediateOperand.h
"
12
#include "
mini-llvm/mir/Instruction.h
"
13
#include "
mini-llvm/mir/InstructionVisitor.h
"
14
#include "
mini-llvm/mir/MemoryOperand.h
"
15
#include "
mini-llvm/mir/Register.h
"
16
#include "
mini-llvm/mir/RegisterClass.h
"
17
#include "
mini-llvm/mir/RegisterOperand.h
"
18
#include "
mini-llvm/utils/Compiler.h
"
19
#include "
mini-llvm/utils/Memory.h
"
20
21
namespace
mini_llvm::mir
{
22
23
class
MINI_LLVM_EXPORT
Cmp
:
public
Instruction
{
24
public
:
25
Cmp
(
int
width
, std::shared_ptr<Register>
src1
, std::shared_ptr<Register>
src2
)
26
: width_(
width
),
27
src1_(
RegisterClass
::
kGPR
, std::move(
src1
)),
28
src2_(
RegisterClass
::
kGPR
, std::move(
src2
)) {}
29
30
int
width
()
const
{
31
return
width_;
32
}
33
34
template
<
typename
Self>
35
auto
&
src1
(
this
Self &&self) {
36
return
self.src1_;
37
}
38
39
template
<
typename
Self>
40
auto
&
src2
(
this
Self &&self) {
41
return
self.src2_;
42
}
43
44
std::unordered_set<const RegisterOperand *>
regOps
()
const override
{
45
return
{&
src1
(), &
src2
()};
46
}
47
48
std::unordered_set<const RegisterOperand *>
dsts
()
const override
{
49
return
{};
50
}
51
52
std::unordered_set<const RegisterOperand *>
srcs
()
const override
{
53
return
{&
src1
(), &
src2
()};
54
}
55
56
std::unordered_set<const ImmediateOperand *>
immOps
()
const override
{
57
return
{};
58
}
59
60
std::unordered_set<const MemoryOperand *>
memOps
()
const override
{
61
return
{};
62
}
63
64
bool
hasSideEffects
()
const override
{
65
return
false
;
66
}
67
68
std::string
format
()
const override
{
69
return
std::format(
"CMP i{} {}, {}"
,
width
() * 8, *
src1
(), *
src2
());
70
}
71
72
std::unique_ptr<Instruction>
clone
()
const override
{
73
return
std::make_unique<Cmp>(
width
(),
share
(*
src1
()),
share
(*
src2
()));
74
}
75
76
void
accept
(
InstructionVisitor
&visitor)
override
{
77
visitor.
visitCmp
(*
this
);
78
}
79
80
void
accept
(
InstructionVisitor
&visitor)
const override
{
81
visitor.
visitCmp
(*
this
);
82
}
83
84
private
:
85
int
width_;
86
RegisterOperand
src1_, src2_;
87
};
88
89
}
// namespace mini_llvm::mir
Compiler.h
MINI_LLVM_EXPORT
#define MINI_LLVM_EXPORT
Definition
Compiler.h:17
ImmediateOperand.h
MemoryOperand.h
Memory.h
RegisterClass.h
RegisterOperand.h
Register.h
mini_llvm::mir::Cmp::clone
std::unique_ptr< Instruction > clone() const override
Definition
Cmp.h:72
mini_llvm::mir::Cmp::src2
auto & src2(this Self &&self)
Definition
Cmp.h:40
mini_llvm::mir::Cmp::src1
auto & src1(this Self &&self)
Definition
Cmp.h:35
mini_llvm::mir::Cmp::dsts
std::unordered_set< const RegisterOperand * > dsts() const override
Definition
Cmp.h:48
mini_llvm::mir::Cmp::memOps
std::unordered_set< const MemoryOperand * > memOps() const override
Definition
Cmp.h:60
mini_llvm::mir::Cmp::srcs
std::unordered_set< const RegisterOperand * > srcs() const override
Definition
Cmp.h:52
mini_llvm::mir::Cmp::width
int width() const
Definition
Cmp.h:30
mini_llvm::mir::Cmp::regOps
std::unordered_set< const RegisterOperand * > regOps() const override
Definition
Cmp.h:44
mini_llvm::mir::Cmp::hasSideEffects
bool hasSideEffects() const override
Definition
Cmp.h:64
mini_llvm::mir::Cmp::accept
void accept(InstructionVisitor &visitor) const override
Definition
Cmp.h:80
mini_llvm::mir::Cmp::immOps
std::unordered_set< const ImmediateOperand * > immOps() const override
Definition
Cmp.h:56
mini_llvm::mir::Cmp::accept
void accept(InstructionVisitor &visitor) override
Definition
Cmp.h:76
mini_llvm::mir::Cmp::format
std::string format() const override
Definition
Cmp.h:68
mini_llvm::mir::Cmp::Cmp
Cmp(int width, std::shared_ptr< Register > src1, std::shared_ptr< Register > src2)
Definition
Cmp.h:25
mini_llvm::mir::InstructionVisitor
Definition
InstructionVisitor.h:70
mini_llvm::mir::InstructionVisitor::visitCmp
virtual void visitCmp(Cmp &I)
Definition
InstructionVisitor.h:88
mini_llvm::mir::Instruction::Instruction
Instruction()=default
mini_llvm::mir::RegisterOperand
Definition
RegisterOperand.h:13
InstructionVisitor.h
Instruction.h
mini_llvm::mir
Definition
BasicBlock.h:22
mini_llvm::mir::RegisterClass
RegisterClass
Definition
RegisterClass.h:7
mini_llvm::mir::RegisterClass::kGPR
@ kGPR
Definition
RegisterClass.h:8
mini_llvm::share
std::shared_ptr< T > share(T &value)
Definition
Memory.h:25
include
mini-llvm
mir
Instruction
Cmp.h
Generated by
1.17.0