mini-llvm
0.1.0
Toggle main menu visibility
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
11
#include "
mini-llvm/mir/Immediate.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
LI
:
public
Instruction
{
25
public
:
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
83
private
:
84
int
width_;
85
RegisterOperand
dst_;
86
ImmediateOperand
src_;
87
};
88
89
}
// namespace mini_llvm::mir
Compiler.h
MINI_LLVM_EXPORT
#define MINI_LLVM_EXPORT
Definition
Compiler.h:17
ImmediateOperand.h
Immediate.h
MemoryOperand.h
Memory.h
RegisterClass.h
RegisterOperand.h
Register.h
mini_llvm::mir::ImmediateOperand
Definition
ImmediateOperand.h:12
mini_llvm::mir::InstructionVisitor
Definition
InstructionVisitor.h:70
mini_llvm::mir::InstructionVisitor::visitLI
virtual void visitLI(LI &I)
Definition
InstructionVisitor.h:113
mini_llvm::mir::Instruction::Instruction
Instruction()=default
mini_llvm::mir::LI::srcs
std::unordered_set< const RegisterOperand * > srcs() const override
Definition
LI.h:51
mini_llvm::mir::LI::immOps
std::unordered_set< const ImmediateOperand * > immOps() const override
Definition
LI.h:55
mini_llvm::mir::LI::dst
auto & dst(this Self &&self)
Definition
LI.h:34
mini_llvm::mir::LI::clone
std::unique_ptr< Instruction > clone() const override
Definition
LI.h:71
mini_llvm::mir::LI::src
auto & src(this Self &&self)
Definition
LI.h:39
mini_llvm::mir::LI::accept
void accept(InstructionVisitor &visitor) override
Definition
LI.h:75
mini_llvm::mir::LI::hasSideEffects
bool hasSideEffects() const override
Definition
LI.h:67
mini_llvm::mir::LI::width
int width() const
Definition
LI.h:29
mini_llvm::mir::LI::memOps
std::unordered_set< const MemoryOperand * > memOps() const override
Definition
LI.h:59
mini_llvm::mir::LI::dsts
std::unordered_set< const RegisterOperand * > dsts() const override
Definition
LI.h:47
mini_llvm::mir::LI::regOps
std::unordered_set< const RegisterOperand * > regOps() const override
Definition
LI.h:43
mini_llvm::mir::LI::accept
void accept(InstructionVisitor &visitor) const override
Definition
LI.h:79
mini_llvm::mir::LI::format
std::string format() const override
Definition
LI.h:63
mini_llvm::mir::LI::LI
LI(int width, std::shared_ptr< Register > dst, std::unique_ptr< Immediate > src)
Definition
LI.h:26
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
LI.h
Generated by
1.17.0