-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR adds a new GCStrategy, that treats any pointer with address space other than 0 as a pointer to managed memory. We extent class GCStrategy in llvm/IR/GCStrategy.h, and register the new GCStrategy.
- Loading branch information
Showing
11 changed files
with
126 additions
and
0 deletions.
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,37 @@ | ||
//===- Extend GCStrategy of llvm/CodeGen/GCStrategy.h ---------------------===// | ||
// | ||
// We extend the base GCStrategy as follows: | ||
// - use gc.safepoints instead of (default) gc.roots. | ||
// - specify that the RewriteStatepointsForGC pass should rewrite the calls of | ||
// this function. | ||
// - pointers with address space != 0 are pointing to GC-managed memory. | ||
//===----------------------------------------------------------------------===// | ||
|
||
// NOLINTBEGIN | ||
|
||
#ifndef LLVM_BACKEND_GC_STRATEGY_H | ||
#define LLVM_BACKEND_GC_STRATEGY_H | ||
|
||
#include "llvm/IR/GCStrategy.h" | ||
#include "llvm/IR/Type.h" | ||
|
||
namespace kllvm { | ||
|
||
/// The GCStrategy for the LLVM Backend | ||
class LLVMBackendGCStrategy : public llvm::GCStrategy { | ||
public: | ||
LLVMBackendGCStrategy(); | ||
|
||
// Override | ||
#if LLVM_VERSION_MAJOR == 15 | ||
llvm::Optional<bool> isGCManagedPointer(llvm::Type const *Ty) const override; | ||
#else | ||
std::optional<bool> isGCManagedPointer(llvm::Type const *Ty) const override; | ||
#endif | ||
}; | ||
|
||
} // namespace kllvm | ||
|
||
#endif // LLVM_BACKEND_GC_STRATEGY_H | ||
|
||
// NOLINTEND |
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
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,52 @@ | ||
//===- Extend GCStrategy of llvm/CodeGen/GCStrategy.h ---------------------===// | ||
// | ||
// We extend the base GCStrategy as follows: | ||
// - use gc.safepoints instead of (default) gc.roots. | ||
// - specify that the RewriteStatepointsForGC pass should rewrite the calls of | ||
// this function. | ||
// - pointers with address space != 0 are pointing to GC-managed memory. | ||
//===----------------------------------------------------------------------===// | ||
|
||
// NOLINTBEGIN | ||
|
||
#include "kllvm/codegen/GCStrategy.h" | ||
|
||
#include "llvm/CodeGen/GCMetadata.h" | ||
#include "llvm/IR/DerivedTypes.h" | ||
#include "llvm/Support/Compiler.h" | ||
|
||
using namespace llvm; | ||
using namespace kllvm; | ||
|
||
LLVMBackendGCStrategy::LLVMBackendGCStrategy() { | ||
UseStatepoints = true; // Use gc.statepoints | ||
#if LLVM_VERSION_MAJOR != 15 | ||
UseRS4GC = true; // Rewrite the calls of a function that has this GCStrategy | ||
#endif | ||
} | ||
|
||
// Override | ||
#if LLVM_VERSION_MAJOR == 15 | ||
llvm::Optional<bool> | ||
LLVMBackendGCStrategy::isGCManagedPointer(Type const *Ty) const { | ||
#else | ||
std::optional<bool> | ||
LLVMBackendGCStrategy::isGCManagedPointer(Type const *Ty) const { | ||
#endif | ||
// Return false for any non-pointer type | ||
if (!Ty->isPointerTy()) { | ||
return false; | ||
} | ||
// Any pointer with address space != 0 is to managed memory. | ||
PointerType const *PTy = dyn_cast<PointerType>(Ty); | ||
if (PTy->getAddressSpace()) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
// Add LLVMBackendGCStrategy to the global GCRegistry | ||
static GCRegistry::Add<LLVMBackendGCStrategy> | ||
X("gcs-llvm-backend", "GC Strategy for the LLVM Backend"); | ||
|
||
// NOLINTEND |
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