mini-llvm
0.1.0
Toggle main menu visibility
Loading...
Searching...
No Matches
ICmp.h
Go to the documentation of this file.
1
// SPDX-License-Identifier: MIT
2
3
#pragma once
4
5
#include <cstdlib>
6
#include <memory>
7
#include <string>
8
#include <utility>
9
10
#include "
mini-llvm/ir/Constant.h
"
11
#include "
mini-llvm/ir/Instruction/BinaryIntegerRelationalOperator.h
"
12
#include "
mini-llvm/ir/InstructionVisitor.h
"
13
#include "
mini-llvm/ir/Value.h
"
14
#include "
mini-llvm/utils/Compiler.h
"
15
16
namespace
mini_llvm::ir
{
17
18
class
MINI_LLVM_EXPORT
ICmp
final :
public
BinaryIntegerRelationalOperator
{
19
public
:
20
enum class
Condition
{
21
kEQ,
22
kNE,
23
kSLT,
24
kSGT,
25
kSLE,
26
kSGE,
27
kULT,
28
kUGT,
29
kULE,
30
kUGE,
31
};
32
33
ICmp
(
Condition
cond
, std::shared_ptr<Value>
lhs
, std::shared_ptr<Value>
rhs
)
34
:
BinaryIntegerRelationalOperator
(std::move(
lhs
), std::move(
rhs
)), cond_(
cond
) {}
35
36
Condition
cond
()
const
{
37
return
cond_;
38
}
39
40
void
setCond
(
Condition
cond
) {
41
cond_ =
cond
;
42
}
43
44
std::shared_ptr<Constant>
fold
()
const override
;
45
46
void
accept
(
InstructionVisitor
&visitor)
override
{
47
visitor.
visitICmp
(*
this
);
48
}
49
50
void
accept
(
InstructionVisitor
&visitor)
const override
{
51
visitor.
visitICmp
(*
this
);
52
}
53
54
std::string
format
()
const override
;
55
std::unique_ptr<Value>
clone
()
const override
;
56
57
private
:
58
Condition
cond_;
59
};
60
61
inline
constexpr
const
char
*
specifier
(
ICmp::Condition
cond) {
62
using
enum
ICmp::Condition
;
63
switch
(cond) {
64
case
kEQ:
return
"eq"
;
65
case
kNE:
return
"ne"
;
66
case
kSLT:
return
"slt"
;
67
case
kSGT:
return
"sgt"
;
68
case
kSLE:
return
"sle"
;
69
case
kSGE:
return
"sge"
;
70
case
kULT:
return
"ult"
;
71
case
kUGT:
return
"ugt"
;
72
case
kULE:
return
"ule"
;
73
case
kUGE:
return
"uge"
;
74
default
: abort();
75
}
76
}
77
78
}
// namespace mini_llvm::ir
BinaryIntegerRelationalOperator.h
Compiler.h
MINI_LLVM_EXPORT
#define MINI_LLVM_EXPORT
Definition
Compiler.h:17
Value.h
mini_llvm::ir::BinaryIntegerOperator::lhs
auto & lhs(this Self &&self)
Definition
BinaryIntegerOperator.h:19
mini_llvm::ir::BinaryIntegerOperator::rhs
auto & rhs(this Self &&self)
Definition
BinaryIntegerOperator.h:24
mini_llvm::ir::BinaryIntegerRelationalOperator::BinaryIntegerRelationalOperator
BinaryIntegerRelationalOperator(std::shared_ptr< Value > lhs, std::shared_ptr< Value > rhs)
Definition
BinaryIntegerRelationalOperator.h:23
mini_llvm::ir::ICmp::Condition
Condition
Definition
ICmp.h:20
mini_llvm::ir::ICmp::setCond
void setCond(Condition cond)
Definition
ICmp.h:40
mini_llvm::ir::ICmp::clone
std::unique_ptr< Value > clone() const override
mini_llvm::ir::ICmp::format
std::string format() const override
mini_llvm::ir::ICmp::accept
void accept(InstructionVisitor &visitor) const override
Definition
ICmp.h:50
mini_llvm::ir::ICmp::cond
Condition cond() const
Definition
ICmp.h:36
mini_llvm::ir::ICmp::fold
std::shared_ptr< Constant > fold() const override
mini_llvm::ir::ICmp::ICmp
ICmp(Condition cond, std::shared_ptr< Value > lhs, std::shared_ptr< Value > rhs)
Definition
ICmp.h:33
mini_llvm::ir::ICmp::accept
void accept(InstructionVisitor &visitor) override
Definition
ICmp.h:46
mini_llvm::ir::InstructionVisitor
Definition
InstructionVisitor.h:58
mini_llvm::ir::InstructionVisitor::visitICmp
virtual void visitICmp(ICmp &I)
Definition
InstructionVisitor.h:90
Constant.h
InstructionVisitor.h
mini_llvm::ir
Definition
Argument.h:13
mini_llvm::ir::specifier
constexpr const char * specifier(FCmp::Condition cond)
Definition
FCmp.h:57
include
mini-llvm
ir
Instruction
ICmp.h
Generated by
1.17.0