6 #ifndef JLM_LLVM_IR_OPERATORS_GETELEMENTPTR_HPP
7 #define JLM_LLVM_IR_OPERATORS_GETELEMENTPTR_HPP
34 const std::vector<std::shared_ptr<const rvsdg::BitType>> & indexTypes,
35 std::shared_ptr<const rvsdg::Type> pointeeType)
45 operator==(
const Operation & other)
const noexcept
override;
47 [[nodiscard]] std::string
50 [[nodiscard]] std::unique_ptr<Operation>
51 copy()
const override;
65 static std::optional<std::vector<uint64_t>>
81 const auto firstIndex = node.input(1);
82 JLM_ASSERT(is<rvsdg::BitType>(firstIndex->Type()));
92 [[nodiscard]]
static size_t
95 JLM_ASSERT(is<GetElementPtrOperation>(node.GetOperation()));
96 return node.ninputs() - 1;
111 const auto baseAddress = node.
input(0);
112 JLM_ASSERT(is<PointerType>(baseAddress->Type()));
128 const auto baseAddress = node.
input(0);
129 JLM_ASSERT(is<PointerType>(baseAddress->Type()));
142 static std::unique_ptr<ThreeAddressCode>
145 const std::vector<const Variable *> & offsets,
146 std::shared_ptr<const rvsdg::Type> pointeeType)
149 auto offsetTypes = checkAndExtractIndexTypes<const Variable>(offsets);
151 auto operation = std::make_unique<GetElementPtrOperation>(offsetTypes, std::move(pointeeType));
152 std::vector
operands(1, baseAddress);
170 const std::vector<rvsdg::Output *> &
indices,
171 std::shared_ptr<const rvsdg::Type> pointeeType)
174 const auto indicesTypes = checkAndExtractIndexTypes<rvsdg::Output>(
indices);
176 std::vector
operands(1, &baseAddress);
179 return rvsdg::CreateOpNode<GetElementPtrOperation>(
182 std::move(pointeeType));
197 const std::vector<rvsdg::Output *> &
indices,
198 std::shared_ptr<const rvsdg::Type> pointeeType)
207 if (!is<PointerType>(type))
214 static std::vector<std::shared_ptr<const rvsdg::BitType>>
217 std::vector<std::shared_ptr<const rvsdg::BitType>> offsetTypes;
218 for (
const auto & offset :
indices)
220 if (
auto offsetType = std::dynamic_pointer_cast<const rvsdg::BitType>(offset->Type()))
222 offsetTypes.emplace_back(std::move(offsetType));
232 static std::vector<std::shared_ptr<const rvsdg::Type>>
236 types.insert(types.end(), indexTypes.begin(), indexTypes.end());
std::string debug_string() const override
static std::optional< std::vector< uint64_t > > tryGetConstantIndices(const rvsdg::Node &node) noexcept
GetElementPtrOperation(GetElementPtrOperation &&other) noexcept=default
static size_t numIndices(const rvsdg::Node &node) noexcept
GetElementPtrOperation(const GetElementPtrOperation &other)=default
static rvsdg::Output * create(rvsdg::Output *baseAddress, const std::vector< rvsdg::Output * > &indices, std::shared_ptr< const rvsdg::Type > pointeeType)
std::shared_ptr< const rvsdg::Type > pointeeType_
static rvsdg::Input & getBaseAddressInput(rvsdg::Node &node)
bool operator==(const Operation &other) const noexcept override
static rvsdg::SimpleNode & createNode(rvsdg::Output &baseAddress, const std::vector< rvsdg::Output * > &indices, std::shared_ptr< const rvsdg::Type > pointeeType)
static void checkPointerType(const rvsdg::Type &type)
static rvsdg::Node::InputConstIteratorRange indices(const rvsdg::Node &node) noexcept
~GetElementPtrOperation() noexcept override
static std::vector< std::shared_ptr< const rvsdg::BitType > > checkAndExtractIndexTypes(const std::vector< T * > &indices)
const rvsdg::Type & getPointeeType() const noexcept
static const rvsdg::Input & getBaseAddressInput(const rvsdg::Node &node)
std::unique_ptr< Operation > copy() const override
static std::vector< std::shared_ptr< const rvsdg::Type > > createOperandTypes(const std::vector< std::shared_ptr< const rvsdg::BitType >> &indexTypes)
static std::unique_ptr< ThreeAddressCode > createTAC(const Variable *baseAddress, const std::vector< const Variable * > &offsets, std::shared_ptr< const rvsdg::Type > pointeeType)
static std::shared_ptr< const PointerType > Create()
static std::unique_ptr< llvm::ThreeAddressCode > create(std::unique_ptr< rvsdg::SimpleOperation > operation, const std::vector< const Variable * > &operands)
const jlm::rvsdg::Type & type() const noexcept
virtual const Operation & GetOperation() const noexcept=0
NodeInput * input(size_t index) const noexcept
const std::shared_ptr< const rvsdg::Type > & Type() const noexcept
NodeOutput * output(size_t index) const noexcept
SimpleOperation(std::vector< std::shared_ptr< const jlm::rvsdg::Type >> operands, std::vector< std::shared_ptr< const jlm::rvsdg::Type >> results)
Global memory state passed between functions.
static std::vector< jlm::rvsdg::Output * > operands(const Node *node)