Jlm
Loading...
Searching...
No Matches
alloca.hpp
Go to the documentation of this file.
1/*
2 * Copyright 2017 Nico Reißmann <nico.reissmann@gmail.com>
3 * See COPYING for terms of redistribution.
4 */
5
6#ifndef JLM_LLVM_IR_OPERATORS_ALLOCA_HPP
7#define JLM_LLVM_IR_OPERATORS_ALLOCA_HPP
8
9#include <jlm/llvm/ir/tac.hpp>
10#include <jlm/llvm/ir/types.hpp>
13
14namespace jlm::llvm
15{
16
18{
19public:
20 ~AllocaOperation() noexcept override;
21
23 std::shared_ptr<const rvsdg::Type> allocatedType,
24 std::shared_ptr<const rvsdg::BitType> countType,
25 const size_t alignment)
27 { countType },
31 {}
32
33 AllocaOperation(const AllocaOperation & other) = default;
34
35 AllocaOperation(AllocaOperation && other) noexcept = default;
36
37 bool
38 operator==(const Operation & other) const noexcept override;
39
40 [[nodiscard]] std::string
41 debug_string() const override;
42
43 [[nodiscard]] std::unique_ptr<Operation>
44 copy() const override;
45
46 const rvsdg::BitType &
47 countType() const noexcept
48 {
49 const auto type = argument(0);
50 JLM_ASSERT(is<rvsdg::BitType>(type));
51 return *std::static_pointer_cast<const rvsdg::BitType>(type);
52 }
53
54 [[nodiscard]] const std::shared_ptr<const rvsdg::Type> &
55 allocatedType() const noexcept
56 {
57 return allocatedType_;
58 }
59
60 size_t
61 alignment() const noexcept
62 {
63 return alignment_;
64 }
65
66 static rvsdg::Input &
68 {
69 JLM_ASSERT(is<AllocaOperation>(&node));
70 return *node.input(0);
71 }
72
73 static rvsdg::Output &
75 {
76 JLM_ASSERT(is<AllocaOperation>(&node));
77 return *node.output(0);
78 }
79
80 static rvsdg::Output &
82 {
83 JLM_ASSERT(is<AllocaOperation>(&node));
84 return *node.output(1);
85 }
86
87 static std::unique_ptr<ThreeAddressCode>
89 std::shared_ptr<const rvsdg::Type> allocatedType,
90 const Variable * count,
91 size_t alignment)
92 {
93 auto bitType = checkOperandType(count->Type());
94
95 auto op =
96 std::make_unique<AllocaOperation>(std::move(allocatedType), std::move(bitType), alignment);
97 return ThreeAddressCode::create(std::move(op), { count });
98 }
99
108 static rvsdg::SimpleNode &
110 std::shared_ptr<const rvsdg::Type> allocatedType,
111 rvsdg::Output & count,
112 const size_t alignment)
113 {
114 auto bitType = checkOperandType(count.Type());
115
117 { &count },
118 std::move(allocatedType),
119 std::move(bitType),
120 alignment);
121 }
122
130 static std::vector<rvsdg::Output *>
132 std::shared_ptr<const rvsdg::Type> allocatedType,
133 rvsdg::Output * count,
134 const size_t alignment)
135 {
136 return rvsdg::outputs(&createNode(std::move(allocatedType), *count, alignment));
137 }
138
139private:
140 static std::shared_ptr<const rvsdg::BitType>
141 checkOperandType(const std::shared_ptr<const rvsdg::Type> & countType)
142 {
143 if (auto bitType = std::dynamic_pointer_cast<const rvsdg::BitType>(countType))
144 return bitType;
145
146 throw util::Error("Expected bits type.");
147 }
148
150 std::shared_ptr<const rvsdg::Type> allocatedType_;
151};
152
153}
154
155#endif
AllocaOperation(AllocaOperation &&other) noexcept=default
std::shared_ptr< const rvsdg::Type > allocatedType_
Definition alloca.hpp:150
static rvsdg::SimpleNode & createNode(std::shared_ptr< const rvsdg::Type > allocatedType, rvsdg::Output &count, const size_t alignment)
Definition alloca.hpp:109
static rvsdg::Output & getPointerOutput(rvsdg::Node &node)
Definition alloca.hpp:74
bool operator==(const Operation &other) const noexcept override
Definition alloca.cpp:14
static rvsdg::Output & getMemoryStateOutput(rvsdg::Node &node)
Definition alloca.hpp:81
const std::shared_ptr< const rvsdg::Type > & allocatedType() const noexcept
Definition alloca.hpp:55
const rvsdg::BitType & countType() const noexcept
Definition alloca.hpp:47
std::string debug_string() const override
Definition alloca.cpp:21
~AllocaOperation() noexcept override
static rvsdg::Input & getCountInput(rvsdg::Node &node)
Definition alloca.hpp:67
size_t alignment() const noexcept
Definition alloca.hpp:61
AllocaOperation(const AllocaOperation &other)=default
static std::shared_ptr< const rvsdg::BitType > checkOperandType(const std::shared_ptr< const rvsdg::Type > &countType)
Definition alloca.hpp:141
static std::vector< rvsdg::Output * > create(std::shared_ptr< const rvsdg::Type > allocatedType, rvsdg::Output *count, const size_t alignment)
Definition alloca.hpp:131
std::unique_ptr< Operation > copy() const override
Definition alloca.cpp:27
static std::unique_ptr< ThreeAddressCode > createTac(std::shared_ptr< const rvsdg::Type > allocatedType, const Variable *count, size_t alignment)
Definition alloca.hpp:88
static std::shared_ptr< const MemoryStateType > Create()
Definition types.cpp:379
static std::shared_ptr< const PointerType > Create()
Definition types.cpp:45
static std::unique_ptr< llvm::ThreeAddressCode > create(std::unique_ptr< rvsdg::SimpleOperation > operation, const std::vector< const Variable * > &operands)
Definition tac.hpp:135
const std::shared_ptr< const jlm::rvsdg::Type > Type() const noexcept
Definition variable.hpp:62
NodeInput * input(size_t index) const noexcept
Definition node.hpp:615
NodeOutput * output(size_t index) const noexcept
Definition node.hpp:650
const std::shared_ptr< const rvsdg::Type > & Type() const noexcept
Definition node.hpp:366
const std::shared_ptr< const rvsdg::Type > & argument(size_t index) const noexcept
Definition operation.cpp:23
SimpleOperation(std::vector< std::shared_ptr< const jlm::rvsdg::Type > > operands, std::vector< std::shared_ptr< const jlm::rvsdg::Type > > results)
Definition operation.hpp:61
#define JLM_ASSERT(x)
Definition common.hpp:16
Global memory state passed between functions.
static std::vector< jlm::rvsdg::Output * > outputs(const Node *node)
Definition node.hpp:1058
NodeType * TryGetOwnerNode(const rvsdg::Input &input) noexcept
Checks if this is an input to a node of specified type.
Definition node.hpp:872