Jlm
FunctionPointer.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2024 Helge Bahmann <hcb@chaoticmind.net>
3  * See COPYING for terms of redistribution.
4  */
5 
6 #ifndef JLM_LLVM_IR_OPERATORS_FUNCTIONPOINTER_HPP
7 #define JLM_LLVM_IR_OPERATORS_FUNCTIONPOINTER_HPP
8 
9 #include <jlm/llvm/ir/tac.hpp>
10 #include <jlm/llvm/ir/types.hpp>
12 #include <jlm/rvsdg/unary.hpp>
13 
14 namespace jlm::llvm
15 {
16 
21 {
22 public:
23  ~FunctionToPointerOperation() noexcept override;
24 
25  FunctionToPointerOperation(std::shared_ptr<const rvsdg::FunctionType> fn);
26 
27  bool
28  operator==(const Operation & other) const noexcept override;
29 
30  [[nodiscard]] std::string
31  debug_string() const override;
32 
33  [[nodiscard]] std::unique_ptr<Operation>
34  copy() const override;
35 
37  can_reduce_operand(const jlm::rvsdg::Output * arg) const noexcept override;
38 
41 
42  static std::unique_ptr<FunctionToPointerOperation>
43  Create(std::shared_ptr<const rvsdg::FunctionType> fn);
44 
45  inline const std::shared_ptr<const jlm::rvsdg::FunctionType> &
46  FunctionType() const noexcept
47  {
48  return FunctionType_;
49  }
50 
51 private:
52  std::shared_ptr<const rvsdg::FunctionType> FunctionType_;
53 };
54 
59 {
60 public:
61  ~PointerToFunctionOperation() noexcept override;
62 
63  PointerToFunctionOperation(std::shared_ptr<const rvsdg::FunctionType> fn);
64 
65  bool
66  operator==(const Operation & other) const noexcept override;
67 
68  [[nodiscard]] std::string
69  debug_string() const override;
70 
71  [[nodiscard]] std::unique_ptr<rvsdg::Operation>
72  copy() const override;
73 
75  can_reduce_operand(const jlm::rvsdg::Output * arg) const noexcept override;
76 
79 
80  static std::unique_ptr<PointerToFunctionOperation>
81  Create(std::shared_ptr<const rvsdg::FunctionType> fn);
82 
83  inline const std::shared_ptr<const rvsdg::FunctionType> &
84  FunctionType() const noexcept
85  {
86  return FunctionType_;
87  }
88 
89 private:
90  std::shared_ptr<const rvsdg::FunctionType> FunctionType_;
91 };
92 
93 }
94 
95 #endif // JLM_LLVM_IR_OPERATORS_FUNCTIONPOINTER_HPP
Get address of compiled function object.
std::unique_ptr< Operation > copy() const override
std::string debug_string() const override
bool operator==(const Operation &other) const noexcept override
std::shared_ptr< const rvsdg::FunctionType > FunctionType_
static std::unique_ptr< FunctionToPointerOperation > Create(std::shared_ptr< const rvsdg::FunctionType > fn)
FunctionToPointerOperation(std::shared_ptr< const rvsdg::FunctionType > fn)
~FunctionToPointerOperation() noexcept override
rvsdg::unop_reduction_path_t can_reduce_operand(const jlm::rvsdg::Output *arg) const noexcept override
jlm::rvsdg::Output * reduce_operand(rvsdg::unop_reduction_path_t path, jlm::rvsdg::Output *arg) const override
const std::shared_ptr< const jlm::rvsdg::FunctionType > & FunctionType() const noexcept
Interpret pointer as callable function.
std::string debug_string() const override
PointerToFunctionOperation(std::shared_ptr< const rvsdg::FunctionType > fn)
std::unique_ptr< rvsdg::Operation > copy() const override
const std::shared_ptr< const rvsdg::FunctionType > & FunctionType() const noexcept
bool operator==(const Operation &other) const noexcept override
jlm::rvsdg::Output * reduce_operand(rvsdg::unop_reduction_path_t path, jlm::rvsdg::Output *arg) const override
rvsdg::unop_reduction_path_t can_reduce_operand(const jlm::rvsdg::Output *arg) const noexcept override
~PointerToFunctionOperation() noexcept override
static std::unique_ptr< PointerToFunctionOperation > Create(std::shared_ptr< const rvsdg::FunctionType > fn)
std::shared_ptr< const rvsdg::FunctionType > FunctionType_
Unary operator.
Definition: unary.hpp:26
Global memory state passed between functions.
size_t unop_reduction_path_t
Definition: unary.hpp:18