[llvm] 0448ddd - [NFCI] cleanup CloneFunctionInto

Luke Drummond via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 23 05:53:38 PDT 2021


Author: Luke Drummond
Date: 2021-03-23T12:53:27Z
New Revision: 0448ddd169ef3f05c6ec88828565f27b2bcd9b00

URL: https://github.com/llvm/llvm-project/commit/0448ddd169ef3f05c6ec88828565f27b2bcd9b00
DIFF: https://github.com/llvm/llvm-project/commit/0448ddd169ef3f05c6ec88828565f27b2bcd9b00.diff

LOG: [NFCI] cleanup CloneFunctionInto

Hoist early return for decl-only clones to before DIFinder
calculation.
Also fix an out of date assert message after invariants changed in
22a52dfddce.

Reviewed by: nikic, dexonsmith
Differential Revisision: https://reviews.llvm.org/D98957

Added: 
    

Modified: 
    llvm/lib/Transforms/Utils/CloneFunction.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Utils/CloneFunction.cpp b/llvm/lib/Transforms/Utils/CloneFunction.cpp
index 0ff28e9b3c29..9d5922a02a24 100644
--- a/llvm/lib/Transforms/Utils/CloneFunction.cpp
+++ b/llvm/lib/Transforms/Utils/CloneFunction.cpp
@@ -125,6 +125,11 @@ void llvm::CloneFunctionInto(Function *NewFunc, const Function *OldFunc,
       AttributeList::get(NewFunc->getContext(), OldAttrs.getFnAttributes(),
                          OldAttrs.getRetAttributes(), NewArgAttrs));
 
+  // Everything else beyond this point deals with function instructions,
+  // so if we are dealing with a function declaration, we're done.
+  if (OldFunc->isDeclaration())
+    return;
+
   // When we remap instructions within the same module, we want to avoid
   // duplicating inlined DISubprograms, so record all subprograms we find as we
   // duplicate instructions and then freeze them in the MD map. We also record
@@ -149,7 +154,7 @@ void llvm::CloneFunctionInto(Function *NewFunc, const Function *OldFunc,
   } else {
     assert((NewFunc->getParent() == nullptr ||
             NewFunc->getParent() != OldFunc->getParent()) &&
-           "Set SameModule to true if the new function is in the same module");
+           "Expected NewFunc to have 
diff erent parents, or no parent");
 
     if (Changes == CloneFunctionChangeType::DifferentModule) {
       assert(NewFunc->getParent() &&
@@ -160,11 +165,6 @@ void llvm::CloneFunctionInto(Function *NewFunc, const Function *OldFunc,
     }
   }
 
-  // Everything else beyond this point deals with function instructions,
-  // so if we are dealing with a function declaration, we're done.
-  if (OldFunc->isDeclaration())
-    return;
-
   // Loop over all of the basic blocks in the function, cloning them as
   // appropriate.  Note that we save BE this way in order to handle cloning of
   // recursive functions into themselves.


        


More information about the llvm-commits mailing list