mini-llvm
0.1.0
Toggle main menu visibility
Loading...
Searching...
No Matches
Store.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
Store
:
public
Instruction
{
24
public
:
25
Store
(
int
width
,
MemoryOperand
dst
, std::shared_ptr<Register>
src
)
26
: width_(
width
), dst_(std::move(
dst
)), src_(
RegisterClass
::
kGPR
, std::move(
src
)) {}
27
28
int
width
()
const
{
29
return
width_;
30
}
31
32
template
<
typename
Self>
33
auto
&
dst
(
this
Self &&self) {
34
return
self.dst_;
35
}
36
37
template
<
typename
Self>
38
auto
&
src
(
this
Self &&self) {
39
return
self.src_;
40
}
41
42
std::unordered_set<const RegisterOperand *>
regOps
()
const override
{
43
return
{&
dst
().baseReg(), &
src
()};
44
}
45
46
std::unordered_set<const RegisterOperand *>
dsts
()
const override
{
47
return
{};
48
}
49
50
std::unordered_set<const RegisterOperand *>
srcs
()
const override
{
51
return
{&
dst
().baseReg(), &
src
()};
52
}
53
54
std::unordered_set<const ImmediateOperand *>
immOps
()
const override
{
55
return
{&
dst
().offset()};
56
}
57
58
std::unordered_set<const MemoryOperand *>
memOps
()
const override
{
59
return
{&
dst
()};
60
}
61
62
bool
hasSideEffects
()
const override
{
63
return
true
;
64
}
65
66
std::string
format
()
const override
{
67
return
std::format(
"STORE i{} {}, {}"
,
width
() * 8,
dst
(), *
src
());
68
}
69
70
std::unique_ptr<Instruction>
clone
()
const override
{
71
return
std::make_unique<Store>(
width
(),
dst
().
clone
(),
share
(*
src
()));
72
}
73
74
void
accept
(
InstructionVisitor
&visitor)
override
{
75
visitor.
visitStore
(*
this
);
76
}
77
78
void
accept
(
InstructionVisitor
&visitor)
const override
{
79
visitor.
visitStore
(*
this
);
80
}
81
82
private
:
83
int
width_;
84
MemoryOperand
dst_;
85
RegisterOperand
src_;
86
};
87
88
}
// 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::InstructionVisitor
Definition
InstructionVisitor.h:70
mini_llvm::mir::InstructionVisitor::visitStore
virtual void visitStore(Store &I)
Definition
InstructionVisitor.h:132
mini_llvm::mir::Instruction::Instruction
Instruction()=default
mini_llvm::mir::MemoryOperand
Definition
MemoryOperand.h:20
mini_llvm::mir::RegisterOperand
Definition
RegisterOperand.h:13
mini_llvm::mir::Store::Store
Store(int width, MemoryOperand dst, std::shared_ptr< Register > src)
Definition
Store.h:25
mini_llvm::mir::Store::width
int width() const
Definition
Store.h:28
mini_llvm::mir::Store::accept
void accept(InstructionVisitor &visitor) override
Definition
Store.h:74
mini_llvm::mir::Store::srcs
std::unordered_set< const RegisterOperand * > srcs() const override
Definition
Store.h:50
mini_llvm::mir::Store::src
auto & src(this Self &&self)
Definition
Store.h:38
mini_llvm::mir::Store::memOps
std::unordered_set< const MemoryOperand * > memOps() const override
Definition
Store.h:58
mini_llvm::mir::Store::clone
std::unique_ptr< Instruction > clone() const override
Definition
Store.h:70
mini_llvm::mir::Store::accept
void accept(InstructionVisitor &visitor) const override
Definition
Store.h:78
mini_llvm::mir::Store::format
std::string format() const override
Definition
Store.h:66
mini_llvm::mir::Store::immOps
std::unordered_set< const ImmediateOperand * > immOps() const override
Definition
Store.h:54
mini_llvm::mir::Store::hasSideEffects
bool hasSideEffects() const override
Definition
Store.h:62
mini_llvm::mir::Store::regOps
std::unordered_set< const RegisterOperand * > regOps() const override
Definition
Store.h:42
mini_llvm::mir::Store::dst
auto & dst(this Self &&self)
Definition
Store.h:33
mini_llvm::mir::Store::dsts
std::unordered_set< const RegisterOperand * > dsts() const override
Definition
Store.h:46
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
Store.h
Generated by
1.17.0