-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add function / pointer conversion llvm operators. Accept these operators as top-level nodes in the various transformation passes, and handle them in instruction conversion. There are presently no "users" of these operators or anything that puts them into the graph -- so this is preparatory for making function and pointer distinction in a later commit.
- Loading branch information
Showing
7 changed files
with
275 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* | ||
* Copyright 2024 Helge Bahmann <[email protected]> | ||
* See COPYING for terms of redistribution. | ||
*/ | ||
|
||
#include <jlm/llvm/ir/operators/FunctionPointer.hpp> | ||
|
||
namespace jlm::llvm | ||
{ | ||
|
||
FunctionToPointerOperation::~FunctionToPointerOperation() noexcept | ||
{} | ||
|
||
FunctionToPointerOperation::FunctionToPointerOperation( | ||
std::shared_ptr<const llvm::FunctionType> fn, | ||
std::shared_ptr<const llvm::PointerType> ptr) | ||
: SimpleOperation({ fn }, { ptr }), | ||
FunctionType_(std::move(fn)), | ||
PointerType_(std::move(ptr)) | ||
{} | ||
|
||
bool | ||
FunctionToPointerOperation::operator==(const Operation & other) const noexcept | ||
{ | ||
if (auto o = dynamic_cast<const FunctionToPointerOperation *>(&other)) | ||
{ | ||
return *FunctionType() == *o->FunctionType() && *PointerType() == *o->PointerType(); | ||
} | ||
else | ||
{ | ||
return false; | ||
} | ||
} | ||
|
||
[[nodiscard]] std::string | ||
FunctionToPointerOperation::debug_string() const | ||
{ | ||
return "FunPtr(" + FunctionType()->debug_string() + "," + PointerType()->debug_string() + ")"; | ||
} | ||
|
||
[[nodiscard]] std::unique_ptr<rvsdg::Operation> | ||
FunctionToPointerOperation::copy() const | ||
{ | ||
return Create(FunctionType(), PointerType()); | ||
} | ||
|
||
std::unique_ptr<FunctionToPointerOperation> | ||
FunctionToPointerOperation::Create( | ||
std::shared_ptr<const llvm::FunctionType> fn, | ||
std::shared_ptr<const llvm::PointerType> ptr) | ||
{ | ||
return std::make_unique<FunctionToPointerOperation>(std::move(fn), std::move(ptr)); | ||
} | ||
|
||
PointerToFunctionOperation::~PointerToFunctionOperation() noexcept | ||
{} | ||
|
||
PointerToFunctionOperation::PointerToFunctionOperation( | ||
std::shared_ptr<const llvm::PointerType> ptr, | ||
std::shared_ptr<const llvm::FunctionType> fn) | ||
: SimpleOperation({ ptr }, { fn }), | ||
PointerType_(std::move(ptr)), | ||
FunctionType_(std::move(fn)) | ||
{} | ||
|
||
bool | ||
PointerToFunctionOperation::operator==(const Operation & other) const noexcept | ||
{ | ||
if (auto o = dynamic_cast<const PointerToFunctionOperation *>(&other)) | ||
{ | ||
return *PointerType() == *o->PointerType() && *FunctionType() == *o->FunctionType(); | ||
} | ||
else | ||
{ | ||
return false; | ||
} | ||
} | ||
|
||
[[nodiscard]] std::string | ||
PointerToFunctionOperation::debug_string() const | ||
{ | ||
return "PtrFun(" + PointerType()->debug_string() + "," + FunctionType()->debug_string() + ")"; | ||
} | ||
|
||
[[nodiscard]] std::unique_ptr<rvsdg::Operation> | ||
PointerToFunctionOperation::copy() const | ||
{ | ||
return Create(PointerType(), FunctionType()); | ||
} | ||
|
||
std::unique_ptr<PointerToFunctionOperation> | ||
PointerToFunctionOperation::Create( | ||
std::shared_ptr<const llvm::PointerType> ptr, | ||
std::shared_ptr<const llvm::FunctionType> fn) | ||
{ | ||
return std::make_unique<PointerToFunctionOperation>(std::move(ptr), std::move(fn)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/* | ||
* Copyright 2024 Helge Bahmann <[email protected]> | ||
* See COPYING for terms of redistribution. | ||
*/ | ||
|
||
#ifndef JLM_LLVM_IR_OPERATORS_FUNCTIONPOINTER_HPP | ||
#define JLM_LLVM_IR_OPERATORS_FUNCTIONPOINTER_HPP | ||
|
||
#include <jlm/llvm/ir/tac.hpp> | ||
#include <jlm/llvm/ir/types.hpp> | ||
#include <jlm/rvsdg/bitstring/type.hpp> | ||
#include <jlm/rvsdg/simple-node.hpp> | ||
|
||
namespace jlm::llvm | ||
{ | ||
|
||
/** | ||
\brief Get address of compiled function object. | ||
*/ | ||
class FunctionToPointerOperation final : public rvsdg::SimpleOperation | ||
{ | ||
public: | ||
~FunctionToPointerOperation() noexcept override; | ||
|
||
FunctionToPointerOperation( | ||
std::shared_ptr<const llvm::FunctionType> fn, | ||
std::shared_ptr<const PointerType> ptr); | ||
|
||
bool | ||
operator==(const Operation & other) const noexcept override; | ||
|
||
[[nodiscard]] std::string | ||
debug_string() const override; | ||
|
||
[[nodiscard]] std::unique_ptr<Operation> | ||
copy() const override; | ||
|
||
static std::unique_ptr<FunctionToPointerOperation> | ||
Create(std::shared_ptr<const llvm::FunctionType> fn, std::shared_ptr<const PointerType> ptr); | ||
|
||
inline const std::shared_ptr<const jlm::llvm::FunctionType> & | ||
FunctionType() const noexcept | ||
{ | ||
return FunctionType_; | ||
} | ||
|
||
inline const std::shared_ptr<const llvm::PointerType> & | ||
PointerType() const noexcept | ||
{ | ||
return PointerType_; | ||
} | ||
|
||
private: | ||
std::shared_ptr<const llvm::FunctionType> FunctionType_; | ||
std::shared_ptr<const llvm::PointerType> PointerType_; | ||
}; | ||
|
||
/** | ||
\brief Interpret pointer as callable function. | ||
*/ | ||
class PointerToFunctionOperation final : public rvsdg::SimpleOperation | ||
{ | ||
public: | ||
~PointerToFunctionOperation() noexcept override; | ||
|
||
PointerToFunctionOperation( | ||
std::shared_ptr<const llvm::PointerType> ptr, | ||
std::shared_ptr<const llvm::FunctionType> fn); | ||
|
||
bool | ||
operator==(const Operation & other) const noexcept override; | ||
|
||
[[nodiscard]] std::string | ||
debug_string() const override; | ||
|
||
[[nodiscard]] std::unique_ptr<rvsdg::Operation> | ||
copy() const override; | ||
|
||
static std::unique_ptr<PointerToFunctionOperation> | ||
Create( | ||
std::shared_ptr<const llvm::PointerType> ptr, | ||
std::shared_ptr<const llvm::FunctionType> fn); | ||
|
||
inline const std::shared_ptr<const llvm::PointerType> & | ||
PointerType() const noexcept | ||
{ | ||
return PointerType_; | ||
} | ||
|
||
inline const std::shared_ptr<const llvm::FunctionType> & | ||
FunctionType() const noexcept | ||
{ | ||
return FunctionType_; | ||
} | ||
|
||
private: | ||
std::shared_ptr<const llvm::PointerType> PointerType_; | ||
std::shared_ptr<const llvm::FunctionType> FunctionType_; | ||
}; | ||
|
||
} | ||
|
||
#endif // JLM_LLVM_IR_OPERATORS_FUNCTIONPOINTER_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters