mini-llvm 0.1.0
Loading...
Searching...
No Matches
FCmp.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 kOEQ,
22 kONE,
23 kOLT,
24 kOGT,
25 kOLE,
26 kOGE,
27 };
28
29 FCmp(Condition cond, std::shared_ptr<Value> lhs, std::shared_ptr<Value> rhs)
30 : BinaryFloatingRelationalOperator(std::move(lhs), std::move(rhs)), cond_(cond) {}
31
32 Condition cond() const {
33 return cond_;
34 }
35
37 cond_ = cond;
38 }
39
40 std::shared_ptr<Constant> fold() const override;
41
42 void accept(InstructionVisitor &visitor) override {
43 visitor.visitFCmp(*this);
44 }
45
46 void accept(InstructionVisitor &visitor) const override {
47 visitor.visitFCmp(*this);
48 }
49
50 std::string format() const override;
51 std::unique_ptr<Value> clone() const override;
52
53private:
54 Condition cond_;
55};
56
57inline constexpr const char *specifier(FCmp::Condition cond) {
58 using enum FCmp::Condition;
59 switch (cond) {
60 case kOEQ: return "oeq";
61 case kONE: return "one";
62 case kOLT: return "olt";
63 case kOGT: return "ogt";
64 case kOLE: return "ole";
65 case kOGE: return "oge";
66 default: abort();
67 }
68}
69
70} // namespace mini_llvm::ir
#define MINI_LLVM_EXPORT
Definition Compiler.h:17
auto & rhs(this Self &&self)
Definition BinaryFloatingOperator.h:24
auto & lhs(this Self &&self)
Definition BinaryFloatingOperator.h:19
BinaryFloatingRelationalOperator(std::shared_ptr< Value > lhs, std::shared_ptr< Value > rhs)
Definition BinaryFloatingRelationalOperator.h:23
std::shared_ptr< Constant > fold() const override
FCmp(Condition cond, std::shared_ptr< Value > lhs, std::shared_ptr< Value > rhs)
Definition FCmp.h:29
void setCond(Condition cond)
Definition FCmp.h:36
Condition
Definition FCmp.h:20
Condition cond() const
Definition FCmp.h:32
std::unique_ptr< Value > clone() const override
void accept(InstructionVisitor &visitor) override
Definition FCmp.h:42
void accept(InstructionVisitor &visitor) const override
Definition FCmp.h:46
std::string format() const override
Definition InstructionVisitor.h:58
virtual void visitFCmp(FCmp &I)
Definition InstructionVisitor.h:79
Definition Argument.h:13
constexpr const char * specifier(FCmp::Condition cond)
Definition FCmp.h:57