Jlm
operation.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2014 Helge Bahmann <hcb@chaoticmind.net>
3  * Copyright 2014 Nico Reißmann <nico.reissmann@gmail.com>
4  * See COPYING for terms of redistribution.
5  */
6 
7 #ifndef JLM_RVSDG_OPERATION_HPP
8 #define JLM_RVSDG_OPERATION_HPP
9 
10 #include <jlm/rvsdg/type.hpp>
11 
12 #include <memory>
13 #include <string>
14 #include <vector>
15 
16 namespace jlm::rvsdg
17 {
18 
19 class Graph;
20 class Node;
21 class Output;
22 class Region;
23 
24 class Operation
25 {
26 public:
27  virtual ~Operation() noexcept;
28 
29  virtual bool
30  operator==(const Operation & other) const noexcept = 0;
31 
32  virtual std::string
33  debug_string() const = 0;
34 
35  [[nodiscard]] virtual std::unique_ptr<Operation>
36  copy() const = 0;
37 
38  inline bool
39  operator!=(const Operation & other) const noexcept
40  {
41  return !(*this == other);
42  }
43 };
44 
45 template<class T>
46 static inline bool
47 is(const Operation & operation) noexcept
48 {
49  static_assert(
50  std::is_base_of<Operation, T>::value,
51  "Template parameter T must be derived from jlm::rvsdg::operation.");
52 
53  return dynamic_cast<const T *>(&operation) != nullptr;
54 }
55 
56 class SimpleOperation : public Operation
57 {
58 public:
59  ~SimpleOperation() noexcept override;
60 
62  std::vector<std::shared_ptr<const jlm::rvsdg::Type>> operands,
63  std::vector<std::shared_ptr<const jlm::rvsdg::Type>> results)
64  : operands_(std::move(operands)),
65  results_(std::move(results))
66  {}
67 
68  size_t
69  narguments() const noexcept;
70 
71  [[nodiscard]] const std::shared_ptr<const rvsdg::Type> &
72  argument(size_t index) const noexcept;
73 
74  size_t
75  nresults() const noexcept;
76 
77  [[nodiscard]] const std::shared_ptr<const rvsdg::Type> &
78  result(size_t index) const noexcept;
79 
80 private:
81  std::vector<std::shared_ptr<const rvsdg::Type>> operands_;
82  std::vector<std::shared_ptr<const rvsdg::Type>> results_;
83 };
84 
86 {
87 public:
88  bool
89  operator==(const Operation & other) const noexcept override;
90 };
91 
92 }
93 
94 #endif
virtual ~Operation() noexcept
virtual bool operator==(const Operation &other) const noexcept=0
virtual std::string debug_string() const =0
virtual std::unique_ptr< Operation > copy() const =0
const std::shared_ptr< const rvsdg::Type > & argument(size_t index) const noexcept
Definition: operation.cpp:23
const std::shared_ptr< const rvsdg::Type > & result(size_t index) const noexcept
Definition: operation.cpp:36
std::vector< std::shared_ptr< const rvsdg::Type > > operands_
Definition: operation.hpp:81
size_t nresults() const noexcept
Definition: operation.cpp:30
std::vector< std::shared_ptr< const rvsdg::Type > > results_
Definition: operation.hpp:82
~SimpleOperation() noexcept override
size_t narguments() const noexcept
Definition: operation.cpp:17
static bool is(const jlm::rvsdg::Input &input) noexcept
Definition: node.hpp:236
static std::vector< jlm::rvsdg::Output * > operands(const Node *node)
Definition: node.hpp:1049