mini-llvm 0.1.0
Loading...
Searching...
No Matches
BitCast.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
13#include "mini-llvm/ir/Type.h"
15#include "mini-llvm/ir/Use.h"
16#include "mini-llvm/ir/Value.h"
18
19namespace mini_llvm::ir {
20
21class MINI_LLVM_EXPORT BitCast final : public Instruction {
22public:
23 BitCast(std::shared_ptr<Value> value, std::unique_ptr<Type> type)
24 : value_(this, std::move(value)), type_(std::move(type)) {}
25
26 template <typename Self>
27 auto &value(this Self &&self) {
28 return self.value_;
29 }
30
31 std::unordered_set<const UseBase *> operands() const override {
32 return {&value()};
33 }
34
35 bool isFoldable() const override;
36
37 std::shared_ptr<Constant> fold() const override;
38
39 void accept(InstructionVisitor &visitor) override {
40 visitor.visitBitCast(*this);
41 }
42
43 void accept(InstructionVisitor &visitor) const override {
44 visitor.visitBitCast(*this);
45 }
46
47 bool isWellFormed() const override;
48
49 std::unique_ptr<Type> type() const override {
50 return type_->clone();
51 }
52
53 std::string format() const override;
54 std::unique_ptr<Value> clone() const override;
55
56private:
57 Use<Value> value_;
58 std::unique_ptr<Type> type_;
59};
60
61} // namespace mini_llvm::ir
#define MINI_LLVM_EXPORT
Definition Compiler.h:17
std::unique_ptr< Type > type() const override
Definition BitCast.h:49
bool isWellFormed() const override
auto & value(this Self &&self)
Definition BitCast.h:27
std::shared_ptr< Constant > fold() const override
std::unordered_set< const UseBase * > operands() const override
Definition BitCast.h:31
BitCast(std::shared_ptr< Value > value, std::unique_ptr< Type > type)
Definition BitCast.h:23
void accept(InstructionVisitor &visitor) const override
Definition BitCast.h:43
std::string format() const override
std::unique_ptr< Value > clone() const override
bool isFoldable() const override
void accept(InstructionVisitor &visitor) override
Definition BitCast.h:39
Definition InstructionVisitor.h:58
virtual void visitBitCast(BitCast &I)
Definition InstructionVisitor.h:74
Definition Instruction.h:22
Definition Use.h:44
Definition Argument.h:13