Jlm
Loading...
Searching...
No Matches
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
15namespace 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{
22public:
24
28
29 inline const BitType &
31 {
32 return *std::static_pointer_cast<const BitType>(argument(0));
33 }
34
37
38 virtual std::unique_ptr<BitUnaryOperation>
39 create(size_t nbits) const = 0;
40
51 static std::optional<std::vector<Output *>>
52 foldConstant(const BitUnaryOperation & operation, const std::vector<Output *> & operands);
53};
54
55/* Represents a binary operation (possibly normalized n-ary if associative)
56 * on a bitstring of a specific width, produces another bitstring of the
57 * same width. */
59{
60public:
62
66
67 /* reduction methods */
70 const noexcept override;
71
76 jlm::rvsdg::Output * arg2) const override;
77
78 virtual BitValueRepresentation
80 const = 0;
81
82 virtual std::unique_ptr<BitBinaryOperation>
83 create(size_t nbits) const = 0;
84
85 inline const BitType &
87 {
88 return *std::static_pointer_cast<const BitType>(result(0));
89 }
90
101 static std::optional<std::vector<Output *>>
102 foldConstants(const BitBinaryOperation & operation, const std::vector<Output *> & operands);
103};
104
106{
110};
111
113{
114public:
116
120
123 const noexcept override;
124
129 jlm::rvsdg::Output * arg2) const override;
130
131 virtual compare_result
133 const = 0;
134
135 virtual std::unique_ptr<BitCompareOperation>
136 create(size_t nbits) const = 0;
137
138 inline const BitType &
140 {
141 return *std::static_pointer_cast<const BitType>(argument(0));
142 }
143
154 static std::optional<std::vector<Output *>>
155 foldConstants(const BitCompareOperation & operation, const std::vector<Output *> & operands);
156};
157
158}
159
160#endif
virtual std::unique_ptr< BitBinaryOperation > create(size_t nbits) const =0
~BitBinaryOperation() noexcept override
binop_reduction_path_t can_reduce_operand_pair(const jlm::rvsdg::Output *arg1, const jlm::rvsdg::Output *arg2) const noexcept override
static std::optional< std::vector< Output * > > foldConstants(const BitBinaryOperation &operation, const std::vector< Output * > &operands)
const BitType & type() const noexcept
virtual BitValueRepresentation reduce_constants(const BitValueRepresentation &arg1, const BitValueRepresentation &arg2) const =0
jlm::rvsdg::Output * reduce_operand_pair(binop_reduction_path_t path, jlm::rvsdg::Output *arg1, jlm::rvsdg::Output *arg2) const override
static std::optional< std::vector< Output * > > foldConstants(const BitCompareOperation &operation, const std::vector< Output * > &operands)
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
virtual std::unique_ptr< BitCompareOperation > create(size_t nbits) const =0
binop_reduction_path_t can_reduce_operand_pair(const jlm::rvsdg::Output *arg1, const jlm::rvsdg::Output *arg2) const noexcept override
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
const BitType & type() const noexcept
static std::optional< std::vector< Output * > > foldConstant(const BitUnaryOperation &operation, const std::vector< Output * > &operands)
virtual std::unique_ptr< BitUnaryOperation > create(size_t nbits) const =0
virtual BitValueRepresentation reduce_constant(const BitValueRepresentation &arg) 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
Unary operator.
Definition unary.hpp:24
static std::vector< jlm::rvsdg::Output * > operands(const Node *node)
Definition node.hpp:1049
size_t binop_reduction_path_t
Definition binary.hpp:19
NodeType * TryGetOwnerNode(const rvsdg::Input &input) noexcept
Checks if this is an input to a node of specified type.
Definition node.hpp:872