[llvm] 267768c - [RS4GC] Add a GCStrategy option to enable RS4GC

Denis Antrushin via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 20 11:38:59 PST 2023


Author: Campbell Suter
Date: 2023-01-20T22:38:17+03:00
New Revision: 267768c9dd2657494a3d1314be8eb48ec3984914

URL: https://github.com/llvm/llvm-project/commit/267768c9dd2657494a3d1314be8eb48ec3984914
DIFF: https://github.com/llvm/llvm-project/commit/267768c9dd2657494a3d1314be8eb48ec3984914.diff

LOG: [RS4GC] Add a GCStrategy option to enable RS4GC

Currently, the RewriteStatepointsForGC pass has a hardcoded list of GC
strategies that it operates on, forcing downstream projects to patch
LLVM to enable it for their own strategies. The diff D141110 changes
that to each GCStrategy having a flag to enable or disable RS4GC.

This patch adds that flag. It currently doesn't do anything, but is
provided so downstream projects can enable it to smooth the transition.

Reviewed By: dantrushin

Differential Revision: https://reviews.llvm.org/D142169

Added: 
    

Modified: 
    llvm/include/llvm/IR/GCStrategy.h
    llvm/lib/IR/BuiltinGCs.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/IR/GCStrategy.h b/llvm/include/llvm/IR/GCStrategy.h
index 05f5d82e71e75..9f3904f4c850c 100644
--- a/llvm/include/llvm/IR/GCStrategy.h
+++ b/llvm/include/llvm/IR/GCStrategy.h
@@ -68,8 +68,13 @@ class GCStrategy {
 
 protected:
   bool UseStatepoints = false; /// Uses gc.statepoints as opposed to gc.roots,
-                               /// if set, none of the other options can be
-                               /// anything but their default values.
+                               /// if set, NeededSafePoints and UsesMetadata
+                               /// should be left at their default values.
+
+  bool UseRS4GC = false; /// If UseStatepoints is set, this determines whether
+                         /// the RewriteStatepointsForGC pass should rewrite
+                         /// this function's calls.
+                         /// This should only be set if UseStatepoints is set.
 
   bool NeededSafePoints = false;    ///< if set, calls are inferred to be safepoints
   bool UsesMetadata = false;     ///< If set, backend must emit metadata tables.
@@ -96,6 +101,15 @@ class GCStrategy {
   virtual std::optional<bool> isGCManagedPointer(const Type *Ty) const {
     return std::nullopt;
   }
+
+  /// Returns true if the RewriteStatepointsForGC pass should run on functions
+  /// using this GC.
+  bool useRS4GC() const {
+    assert(useStatepoints() &&
+           "GC strategy has useRS4GC but not useStatepoints set");
+    return UseRS4GC;
+  }
+
   ///@}
 
   /// If set, appropriate metadata tables must be emitted by the back-end

diff  --git a/llvm/lib/IR/BuiltinGCs.cpp b/llvm/lib/IR/BuiltinGCs.cpp
index 1a7100a0d7a9d..163b0383e22c2 100644
--- a/llvm/lib/IR/BuiltinGCs.cpp
+++ b/llvm/lib/IR/BuiltinGCs.cpp
@@ -66,6 +66,7 @@ class StatepointGC : public GCStrategy {
 public:
   StatepointGC() {
     UseStatepoints = true;
+    UseRS4GC = true;
     // These options are all gc.root specific, we specify them so that the
     // gc.root lowering code doesn't run.
     NeededSafePoints = false;
@@ -98,6 +99,7 @@ class CoreCLRGC : public GCStrategy {
 public:
   CoreCLRGC() {
     UseStatepoints = true;
+    UseRS4GC = true;
     // These options are all gc.root specific, we specify them so that the
     // gc.root lowering code doesn't run.
     NeededSafePoints = false;


        


More information about the llvm-commits mailing list