mini-llvm
0.1.0
Toggle main menu visibility
Loading...
Searching...
No Matches
Instruction.h
Go to the documentation of this file.
1
// SPDX-License-Identifier: MIT
2
3
#pragma once
4
5
#include <concepts>
6
#include <cstdlib>
7
#include <memory>
8
#include <optional>
9
#include <string>
10
#include <unordered_set>
11
#include <utility>
12
13
#include "
mini-llvm/ir/BasicBlock.h
"
14
#include "
mini-llvm/ir/Constant.h
"
15
#include "
mini-llvm/ir/InstructionVisitor.h
"
16
#include "
mini-llvm/ir/Value.h
"
17
#include "
mini-llvm/utils/Compiler.h
"
18
#include "
mini-llvm/utils/Memory.h
"
19
20
namespace
mini_llvm::ir
{
21
22
class
MINI_LLVM_EXPORT
Instruction
:
public
Value
{
23
public
:
24
BasicBlock
*
parent
()
const
{
25
return
parent_;
26
}
27
28
BasicBlock::iterator
parentIterator
()
const
{
29
return
*parentIterator_;
30
}
31
32
virtual
std::unordered_set<const UseBase *>
operands
()
const
= 0;
33
std::unordered_set<UseBase *>
operands
();
34
35
virtual
bool
isFoldable
()
const
{
36
return
false
;
37
}
38
39
virtual
std::shared_ptr<Constant>
fold
()
const
{
40
abort();
41
}
42
43
virtual
void
accept
(
InstructionVisitor
&visitor) = 0;
44
virtual
void
accept
(
InstructionVisitor
&visitor)
const
= 0;
45
46
bool
isWellFormed
()
const override
;
47
48
std::string
formatAsOperand
()
const override
{
49
return
"%"
+
formatName
();
50
}
51
52
private
:
53
mutable
BasicBlock
*parent_ =
nullptr
;
54
mutable
std::optional<BasicBlock::iterator> parentIterator_ = std::nullopt;
55
56
friend
class
BasicBlock
;
57
};
58
59
MINI_LLVM_EXPORT
Instruction
&
addToParent
(
const
Instruction
&before, std::shared_ptr<Instruction> I);
60
61
template
<
typename
T>
62
requires
std::derived_from<T, Instruction>
63
T &
addToParent
(
const
Instruction
&before, std::shared_ptr<T> I) {
64
return
static_cast<
T &
>
(
addToParent
(before,
cast<Instruction>
(std::move(I))));
65
}
66
67
MINI_LLVM_EXPORT
void
removeFromParent
(
const
Instruction
&I);
68
69
}
// namespace mini_llvm::ir
Compiler.h
MINI_LLVM_EXPORT
#define MINI_LLVM_EXPORT
Definition
Compiler.h:17
Memory.h
Value.h
mini_llvm::ir::BasicBlock
Definition
BasicBlock.h:28
mini_llvm::ir::BasicBlock::iterator
IndirectIterator< InstructionList::iterator, Instruction > iterator
Definition
BasicBlock.h:32
mini_llvm::ir::InstructionVisitor
Definition
InstructionVisitor.h:58
mini_llvm::ir::Instruction
Definition
Instruction.h:22
mini_llvm::ir::Instruction::formatAsOperand
std::string formatAsOperand() const override
Definition
Instruction.h:48
mini_llvm::ir::Instruction::fold
virtual std::shared_ptr< Constant > fold() const
Definition
Instruction.h:39
mini_llvm::ir::Instruction::parentIterator
BasicBlock::iterator parentIterator() const
Definition
Instruction.h:28
mini_llvm::ir::Instruction::isFoldable
virtual bool isFoldable() const
Definition
Instruction.h:35
mini_llvm::ir::Instruction::operands
std::unordered_set< UseBase * > operands()
mini_llvm::ir::Instruction::parent
BasicBlock * parent() const
Definition
Instruction.h:24
mini_llvm::ir::Instruction::accept
virtual void accept(InstructionVisitor &visitor)=0
mini_llvm::ir::Instruction::isWellFormed
bool isWellFormed() const override
mini_llvm::ir::Instruction::accept
virtual void accept(InstructionVisitor &visitor) const =0
mini_llvm::ir::Instruction::operands
virtual std::unordered_set< const UseBase * > operands() const =0
mini_llvm::ir::Instruction::BasicBlock
friend class BasicBlock
Definition
Instruction.h:56
mini_llvm::ir::Value::formatName
std::string formatName() const
mini_llvm::ir::Value::Value
Value()=default
BasicBlock.h
Constant.h
InstructionVisitor.h
mini_llvm::ir
Definition
Argument.h:13
mini_llvm::ir::removeFromParent
MINI_LLVM_EXPORT void removeFromParent(const BasicBlock &B)
mini_llvm::ir::addToParent
MINI_LLVM_EXPORT Instruction & addToParent(const Instruction &before, std::shared_ptr< Instruction > I)
mini_llvm::cast
std::unique_ptr< To > cast(std::unique_ptr< From > from) noexcept
Definition
Memory.h:10
include
mini-llvm
ir
Instruction.h
Generated by
1.17.0