[llvm] r263685 - [Statepoints] Separate out logic for statepoint directives; NFC

Sanjoy Das via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 16 18:56:11 PDT 2016


Author: sanjoy
Date: Wed Mar 16 20:56:10 2016
New Revision: 263685

URL: http://llvm.org/viewvc/llvm-project?rev=263685&view=rev
Log:
[Statepoints] Separate out logic for statepoint directives; NFC

This splits out the logic that maps the `"statepoint-id"` attribute into
the actual statepoint ID, and the `"statepoint-num-patch-bytes"`
attribute into the number of patchable bytes the statpeoint is lowered
into.  The new home of this logic is in IR/Statepoint.cpp, and this
refactoring will support similar functionality when lowering calls with
deopt operand bundles in the future.

Modified:
    llvm/trunk/include/llvm/IR/Statepoint.h
    llvm/trunk/lib/IR/Statepoint.cpp
    llvm/trunk/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp

Modified: llvm/trunk/include/llvm/IR/Statepoint.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/Statepoint.h?rev=263685&r1=263684&r2=263685&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/Statepoint.h (original)
+++ llvm/trunk/include/llvm/IR/Statepoint.h Wed Mar 16 20:56:10 2016
@@ -8,8 +8,9 @@
 //===----------------------------------------------------------------------===//
 //
 // This file contains utility functions and a wrapper class analogous to
-// CallSite for accessing the fields of gc.statepoint, gc.relocate, and
-// gc.result intrinsics
+// CallSite for accessing the fields of gc.statepoint, gc.relocate,
+// gc.result intrinsics; and some general utilities helpful when dealing with
+// gc.statepoint.
 //
 //===----------------------------------------------------------------------===//
 
@@ -17,6 +18,7 @@
 #define LLVM_IR_STATEPOINT_H
 
 #include "llvm/ADT/iterator_range.h"
+#include "llvm/ADT/Optional.h"
 #include "llvm/IR/BasicBlock.h"
 #include "llvm/IR/CallSite.h"
 #include "llvm/IR/Constants.h"
@@ -399,6 +401,23 @@ StatepointBase<FunTy, InstructionTy, Val
   }
   return Result;
 }
+
+/// Call sites that get wrapped by a gc.statepoint (currently only in
+/// RewriteStatepointsForGC and potentially in other passes in the future) can
+/// have attributes that describe properties of gc.statepoint call they will be
+/// eventually be wrapped in.  This struct is used represent such directives.
+struct StatepointDirectives {
+  Optional<uint32_t> NumPatchBytes;
+  Optional<uint64_t> StatepointID;
+};
+
+/// Parse out statepoint directives from the function attributes present in \p
+/// AS.
+StatepointDirectives parseStatepointDirectivesFromAttrs(AttributeSet AS);
+
+/// Return \c true if the the \p Attr is an attribute that is a statepoint
+/// directive.
+bool isStatepointDirectiveAttr(Attribute Attr);
 }
 
 #endif

Modified: llvm/trunk/lib/IR/Statepoint.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Statepoint.cpp?rev=263685&r1=263684&r2=263685&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Statepoint.cpp (original)
+++ llvm/trunk/lib/IR/Statepoint.cpp Wed Mar 16 20:56:10 2016
@@ -53,3 +53,28 @@ bool llvm::isGCResult(ImmutableCallSite
 bool llvm::isGCResult(const Value *V) {
   return isGCResult(ImmutableCallSite(V));
 }
+
+bool llvm::isStatepointDirectiveAttr(Attribute Attr) {
+  return Attr.hasAttribute("statepoint-id") ||
+         Attr.hasAttribute("statepoint-num-patch-bytes");
+}
+
+StatepointDirectives llvm::parseStatepointDirectivesFromAttrs(AttributeSet AS) {
+  StatepointDirectives Result;
+
+  Attribute AttrID =
+      AS.getAttribute(AttributeSet::FunctionIndex, "statepoint-id");
+  uint64_t StatepointID;
+  if (AttrID.isStringAttribute())
+    if (!AttrID.getValueAsString().getAsInteger(10, StatepointID))
+      Result.StatepointID = StatepointID;
+
+  uint32_t NumPatchBytes;
+  Attribute AttrNumPatchBytes = AS.getAttribute(AttributeSet::FunctionIndex,
+                                                "statepoint-num-patch-bytes");
+  if (AttrNumPatchBytes.isStringAttribute())
+    if (!AttrNumPatchBytes.getValueAsString().getAsInteger(10, NumPatchBytes))
+      Result.NumPatchBytes = NumPatchBytes;
+
+  return Result;
+}

Modified: llvm/trunk/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp?rev=263685&r1=263684&r2=263685&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp Wed Mar 16 20:56:10 2016
@@ -1187,8 +1187,7 @@ static AttributeSet legalizeCallAttribut
         // These attributes control the generation of the gc.statepoint call /
         // invoke itself; and once the gc.statepoint is in place, they're of no
         // use.
-        if (Attr.hasAttribute("statepoint-num-patch-bytes") ||
-            Attr.hasAttribute("statepoint-id"))
+        if (isStatepointDirectiveAttr(Attr))
           continue;
 
         Ret = Ret.addAttributes(
@@ -1332,17 +1331,14 @@ makeStatepointExplicitImpl(const CallSit
     TransitionArgs = TransitionBundle->Inputs;
   }
 
+  StatepointDirectives SD =
+      parseStatepointDirectivesFromAttrs(CS.getAttributes());
+  if (SD.NumPatchBytes)
+    NumPatchBytes = *SD.NumPatchBytes;
+  if (SD.StatepointID)
+    StatepointID = *SD.StatepointID;
+
   Value *CallTarget = CS.getCalledValue();
-  AttributeSet OriginalAttrs = CS.getAttributes();
-  Attribute AttrID = OriginalAttrs.getAttribute(AttributeSet::FunctionIndex,
-                                                "statepoint-id");
-  if (AttrID.isStringAttribute())
-    AttrID.getValueAsString().getAsInteger(10, StatepointID);
-
-  Attribute AttrNumPatchBytes = OriginalAttrs.getAttribute(
-    AttributeSet::FunctionIndex, "statepoint-num-patch-bytes");
-  if (AttrNumPatchBytes.isStringAttribute())
-    AttrNumPatchBytes.getValueAsString().getAsInteger(10, NumPatchBytes);
 
   // Create the statepoint given all the arguments
   Instruction *Token = nullptr;




More information about the llvm-commits mailing list