[llvm] 2c4548e - [rs4gc] Use loops instead of straightline code for attribute stripping [nfc]

Philip Reames via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 2 09:25:24 PDT 2021


Author: Philip Reames
Date: 2021-04-02T09:25:15-07:00
New Revision: 2c4548e18e09686659bddad617b8c42a47714540

URL: https://github.com/llvm/llvm-project/commit/2c4548e18e09686659bddad617b8c42a47714540
DIFF: https://github.com/llvm/llvm-project/commit/2c4548e18e09686659bddad617b8c42a47714540.diff

LOG: [rs4gc] Use loops instead of straightline code for attribute stripping [nfc]

Mostly because I'm about to add more attributes and the straightline copies get much uglier.  What's currently there isn't too bad.

Added: 
    

Modified: 
    llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp b/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
index 644e3c005f99..91c3de569d2f 100644
--- a/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
+++ b/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
@@ -1346,10 +1346,10 @@ static AttributeList legalizeCallAttributes(LLVMContext &Ctx,
 
   // Remove the readonly, readnone, and statepoint function attributes.
   AttrBuilder FnAttrs = AL.getFnAttributes();
-  FnAttrs.removeAttribute(Attribute::ReadNone);
-  FnAttrs.removeAttribute(Attribute::ReadOnly);
-  FnAttrs.removeAttribute(Attribute::NoSync);
-  FnAttrs.removeAttribute(Attribute::NoFree);
+  for (auto Attr : {Attribute::ReadNone, Attribute::ReadOnly,
+                    Attribute::NoSync, Attribute::NoFree})
+    FnAttrs.removeAttribute(Attr);
+
   for (Attribute A : AL.getFnAttributes()) {
     if (isStatepointDirectiveAttr(A))
       FnAttrs.remove(A);
@@ -2587,10 +2587,9 @@ static void RemoveNonValidAttrAtIndex(LLVMContext &Ctx, AttrHolder &AH,
   if (AH.getDereferenceableOrNullBytes(Index))
     R.addAttribute(Attribute::get(Ctx, Attribute::DereferenceableOrNull,
                                   AH.getDereferenceableOrNullBytes(Index)));
-  if (AH.getAttributes().hasAttribute(Index, Attribute::NoAlias))
-    R.addAttribute(Attribute::NoAlias);
-  if (AH.getAttributes().hasAttribute(Index, Attribute::NoFree))
-    R.addAttribute(Attribute::NoFree);
+  for (auto Attr : {Attribute::NoAlias, Attribute::NoFree})
+    if (AH.getAttributes().hasAttribute(Index, Attr))
+      R.addAttribute(Attr);
 
   if (!R.empty())
     AH.setAttributes(AH.getAttributes().removeAttributes(Ctx, Index, R));
@@ -2607,8 +2606,8 @@ static void stripNonValidAttributesFromPrototype(Function &F) {
   if (isa<PointerType>(F.getReturnType()))
     RemoveNonValidAttrAtIndex(Ctx, F, AttributeList::ReturnIndex);
 
-  F.removeFnAttr(Attribute::NoSync);
-  F.removeFnAttr(Attribute::NoFree);
+  for (auto Attr : {Attribute::NoSync, Attribute::NoFree})
+    F.removeFnAttr(Attr);
 }
 
 /// Certain metadata on instructions are invalid after running RS4GC.


        


More information about the llvm-commits mailing list