mini-llvm 0.1.0
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
13#include "mini-llvm/ir/Value.h"
15
16namespace mini_llvm::ir {
17
19public:
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
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
57private:
58 Condition cond_;
59};
60
61inline 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
#define MINI_LLVM_EXPORT
Definition Compiler.h:17
auto & lhs(this Self &&self)
Definition BinaryIntegerOperator.h:19
auto & rhs(this Self &&self)
Definition BinaryIntegerOperator.h:24
BinaryIntegerRelationalOperator(std::shared_ptr< Value > lhs, std::shared_ptr< Value > rhs)
Definition BinaryIntegerRelationalOperator.h:23
Condition
Definition ICmp.h:20
void setCond(Condition cond)
Definition ICmp.h:40
std::unique_ptr< Value > clone() const override
std::string format() const override
void accept(InstructionVisitor &visitor) const override
Definition ICmp.h:50
Condition cond() const
Definition ICmp.h:36
std::shared_ptr< Constant > fold() const override
ICmp(Condition cond, std::shared_ptr< Value > lhs, std::shared_ptr< Value > rhs)
Definition ICmp.h:33
void accept(InstructionVisitor &visitor) override
Definition ICmp.h:46
Definition InstructionVisitor.h:58
virtual void visitICmp(ICmp &I)
Definition InstructionVisitor.h:90
Definition Argument.h:13
constexpr const char * specifier(FCmp::Condition cond)
Definition FCmp.h:57