Jlm
GetElementPtr.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2018 Nico Reißmann <nico.reissmann@gmail.com>
3  * See COPYING for terms of redistribution.
4  */
5 
7 #include <jlm/llvm/ir/Trace.hpp>
8 
9 namespace jlm::llvm
10 {
11 
13 
14 bool
15 GetElementPtrOperation::operator==(const Operation & other) const noexcept
16 {
17  auto operation = dynamic_cast<const GetElementPtrOperation *>(&other);
18 
19  if (operation == nullptr || getPointeeType() != operation->getPointeeType()
20  || narguments() != operation->narguments())
21  {
22  return false;
23  }
24 
25  for (size_t n = 0; n < narguments(); n++)
26  {
27  if (operation->argument(n) != argument(n))
28  {
29  return false;
30  }
31  }
32 
33  return true;
34 }
35 
36 std::string
38 {
39  return "GetElementPtr";
40 }
41 
42 std::unique_ptr<rvsdg::Operation>
44 {
45  return std::make_unique<GetElementPtrOperation>(*this);
46 }
47 
48 std::optional<std::vector<uint64_t>>
50 {
51  JLM_ASSERT(is<GetElementPtrOperation>(node.GetOperation()));
52 
53  std::vector<size_t> constants;
54  for (auto & input : indices(node))
55  {
56  if (auto constant = tryGetConstantSignedInteger(*input.origin()))
57  {
58  constants.push_back(constant.value());
59  }
60  else
61  {
62  return std::nullopt;
63  }
64  }
65 
66  return constants;
67 }
68 
69 }
std::string debug_string() const override
static std::optional< std::vector< uint64_t > > tryGetConstantIndices(const rvsdg::Node &node) noexcept
~GetElementPtrOperation() noexcept override
std::unique_ptr< Operation > copy() const override
#define JLM_ASSERT(x)
Definition: common.hpp:16
Global memory state passed between functions.
std::optional< int64_t > tryGetConstantSignedInteger(const rvsdg::Output &output)
Definition: Trace.cpp:62