diff --git a/llvm/include/llvm/IR/GCStrategy.h b/llvm/include/llvm/IR/GCStrategy.h --- a/llvm/include/llvm/IR/GCStrategy.h +++ b/llvm/include/llvm/IR/GCStrategy.h @@ -68,8 +68,13 @@ 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 @@ virtual std::optional isGCManagedPointer(const Type *Ty) const { return std::nullopt; } + + /// Returns true if the RewriteStatepointsForGC pass should run on functions + /// using this GC. + bool useRS4GC() const { + return UseRS4GC; + assert(useStatepoints() && + "GC strategy has useRS4GC but not useStatepoints set"); + } + ///@} /// 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 --- a/llvm/lib/IR/BuiltinGCs.cpp +++ b/llvm/lib/IR/BuiltinGCs.cpp @@ -66,6 +66,7 @@ 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 @@ 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;