Jlm
bitoperation-classes.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2014 Helge Bahmann <hcb@chaoticmind.net>
3  * Copyright 2011 2012 2014 Nico Reißmann <nico.reissmann@gmail.com>
4  * See COPYING for terms of redistribution.
5  */
6 
7 #ifndef JLM_RVSDG_BITSTRING_BITOPERATION_CLASSES_HPP
8 #define JLM_RVSDG_BITSTRING_BITOPERATION_CLASSES_HPP
9 
10 #include <jlm/rvsdg/binary.hpp>
13 #include <jlm/rvsdg/unary.hpp>
14 
15 namespace jlm::rvsdg
16 {
17 
18 /* Represents a unary operation on a bitstring of a specific width,
19  * produces another bitstring of the same width. */
21 {
22 public:
23  ~BitUnaryOperation() noexcept override;
24 
25  explicit BitUnaryOperation(const std::shared_ptr<const BitType> & type) noexcept
27  {}
28 
29  inline const BitType &
30  type() const noexcept
31  {
32  return *std::static_pointer_cast<const BitType>(argument(0));
33  }
34 
36  can_reduce_operand(const jlm::rvsdg::Output * arg) const noexcept override;
37 
39  reduce_operand(unop_reduction_path_t path, jlm::rvsdg::Output * arg) const override;
40 
42  reduce_constant(const BitValueRepresentation & arg) const = 0;
43 
44  virtual std::unique_ptr<BitUnaryOperation>
45  create(size_t nbits) const = 0;
46 };
47 
48 /* Represents a binary operation (possibly normalized n-ary if associative)
49  * on a bitstring of a specific width, produces another bitstring of the
50  * same width. */
52 {
53 public:
54  ~BitBinaryOperation() noexcept override;
55 
56  explicit BitBinaryOperation(const std::shared_ptr<const BitType> type, size_t arity = 2) noexcept
57  : BinaryOperation({ arity, type }, type)
58  {}
59 
60  /* reduction methods */
63  const noexcept override;
64 
68  jlm::rvsdg::Output * arg1,
69  jlm::rvsdg::Output * arg2) const override;
70 
71  virtual BitValueRepresentation
73  const = 0;
74 
75  virtual std::unique_ptr<BitBinaryOperation>
76  create(size_t nbits) const = 0;
77 
78  inline const BitType &
79  type() const noexcept
80  {
81  return *std::static_pointer_cast<const BitType>(result(0));
82  }
83 };
84 
85 enum class compare_result
86 {
90 };
91 
93 {
94 public:
95  ~BitCompareOperation() noexcept override;
96 
97  explicit BitCompareOperation(std::shared_ptr<const BitType> type) noexcept
99  {}
100 
103  const noexcept override;
104 
108  jlm::rvsdg::Output * arg1,
109  jlm::rvsdg::Output * arg2) const override;
110 
111  virtual compare_result
113  const = 0;
114 
115  virtual std::unique_ptr<BitCompareOperation>
116  create(size_t nbits) const = 0;
117 
118  inline const BitType &
119  type() const noexcept
120  {
121  return *std::static_pointer_cast<const BitType>(argument(0));
122  }
123 };
124 
125 }
126 
127 #endif
~BitBinaryOperation() noexcept override
binop_reduction_path_t can_reduce_operand_pair(const jlm::rvsdg::Output *arg1, const jlm::rvsdg::Output *arg2) const noexcept override
virtual std::unique_ptr< BitBinaryOperation > create(size_t nbits) const =0
virtual BitValueRepresentation reduce_constants(const BitValueRepresentation &arg1, const BitValueRepresentation &arg2) const =0
const BitType & type() const noexcept
jlm::rvsdg::Output * reduce_operand_pair(binop_reduction_path_t path, jlm::rvsdg::Output *arg1, jlm::rvsdg::Output *arg2) const override
const BitType & type() const noexcept
binop_reduction_path_t can_reduce_operand_pair(const jlm::rvsdg::Output *arg1, const jlm::rvsdg::Output *arg2) const noexcept override
jlm::rvsdg::Output * reduce_operand_pair(binop_reduction_path_t path, jlm::rvsdg::Output *arg1, jlm::rvsdg::Output *arg2) const override
virtual std::unique_ptr< BitCompareOperation > create(size_t nbits) const =0
virtual compare_result reduce_constants(const BitValueRepresentation &arg1, const BitValueRepresentation &arg2) const =0
~BitCompareOperation() noexcept override
static std::shared_ptr< const BitType > Create(std::size_t nbits)
Creates bit type of specified width.
Definition: type.cpp:45
~BitUnaryOperation() noexcept override
virtual std::unique_ptr< BitUnaryOperation > create(size_t nbits) const =0
unop_reduction_path_t can_reduce_operand(const jlm::rvsdg::Output *arg) const noexcept override
jlm::rvsdg::Output * reduce_operand(unop_reduction_path_t path, jlm::rvsdg::Output *arg) const override
virtual BitValueRepresentation reduce_constant(const BitValueRepresentation &arg) const =0
const BitType & type() const noexcept
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
Unary operator.
Definition: unary.hpp:26
size_t unop_reduction_path_t
Definition: unary.hpp:18
size_t binop_reduction_path_t
Definition: binary.hpp:19