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