mini-llvm 0.1.0
Loading...
Searching...
No Matches
Select.h
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2
3#pragma once
4
5#include <memory>
6#include <string>
7#include <unordered_set>
8#include <utility>
9
12#include "mini-llvm/ir/Type.h"
13#include "mini-llvm/ir/Use.h"
14#include "mini-llvm/ir/Value.h"
16
17namespace mini_llvm::ir {
18
19class MINI_LLVM_EXPORT Select final : public Instruction {
20public:
21 Select(std::shared_ptr<Value> cond, std::shared_ptr<Value> trueValue, std::shared_ptr<Value> falseValue)
22 : cond_(this, std::move(cond)),
23 trueValue_(this, std::move(trueValue)),
24 falseValue_(this, std::move(falseValue)) {}
25
26 template <typename Self>
27 auto &cond(this Self &&self) {
28 return self.cond_;
29 }
30
31 template <typename Self>
32 auto &trueValue(this Self &&self) {
33 return self.trueValue_;
34 }
35
36 template <typename Self>
37 auto &falseValue(this Self &&self) {
38 return self.falseValue_;
39 }
40
41 std::unordered_set<const UseBase *> operands() const override {
42 return {&cond(), &trueValue(), &falseValue()};
43 }
44
45 bool isFoldable() const override;
46 std::shared_ptr<Constant> fold() const override;
47
48 void accept(InstructionVisitor &visitor) override {
49 visitor.visitSelect(*this);
50 }
51
52 void accept(InstructionVisitor &visitor) const override {
53 visitor.visitSelect(*this);
54 }
55
56 bool isWellFormed() const override;
57
58 std::unique_ptr<Type> type() const override {
59 return trueValue()->type();
60 }
61
62 std::string format() const override;
63 std::unique_ptr<Value> clone() const override;
64
65private:
66 Use<Value> cond_;
67 Use<Value> trueValue_, falseValue_;
68};
69
70} // namespace mini_llvm::ir
#define MINI_LLVM_EXPORT
Definition Compiler.h:17
Definition InstructionVisitor.h:58
virtual void visitSelect(Select &I)
Definition InstructionVisitor.h:101
Definition Instruction.h:22
bool isWellFormed() const override
Select(std::shared_ptr< Value > cond, std::shared_ptr< Value > trueValue, std::shared_ptr< Value > falseValue)
Definition Select.h:21
bool isFoldable() const override
std::shared_ptr< Constant > fold() const override
std::unique_ptr< Type > type() const override
Definition Select.h:58
auto & trueValue(this Self &&self)
Definition Select.h:32
auto & cond(this Self &&self)
Definition Select.h:27
std::unique_ptr< Value > clone() const override
auto & falseValue(this Self &&self)
Definition Select.h:37
std::unordered_set< const UseBase * > operands() const override
Definition Select.h:41
std::string format() const override
void accept(InstructionVisitor &visitor) const override
Definition Select.h:52
void accept(InstructionVisitor &visitor) override
Definition Select.h:48
Definition Use.h:44
Definition Argument.h:13