[llvm-commits] [PATCH] Lazily Link functions

Peter Collingbourne peter at pcc.me.uk
Wed Oct 26 16:47:01 PDT 2011


On Wed, Oct 26, 2011 at 04:26:27PM -0700, Tanya Lattner wrote:
> The attached patch will only link functions marked with specific linkage (Internal, LO_ODR, or LO linkage) if they have uses in the destination module. Instead of automatically linking, these functions are placed onto a worklist to be processed in the final stage of linking. We iterate over the list and if any functions on the list have uses in the destination module, we link them in and repeat the process until no changes in the state (uses) has changed. This means that any functions in the LazilyLink worklist that have a use in the destination module will be linked in and none that don't. 
> 
> Please review.

Hi Tanya,

> 
> Index: lib/Linker/LinkModules.cpp
> ===================================================================
> --- lib/Linker/LinkModules.cpp	(revision 142986)
> +++ lib/Linker/LinkModules.cpp	(working copy)
> @@ -341,6 +341,9 @@
>      // Set of items not to link in from source.
>      SmallPtrSet<const Value*, 16> DoNotLinkFromSource;
>      
> +    // Vector of functions to lazily link in.
> +    std::vector<Function*> LazilyLinkFunctions;
> +    
>    public:
>      std::string ErrorMsg;
>      
> @@ -449,7 +452,7 @@
>    bool SrcIsDeclaration = Src->isDeclaration();
>    bool DestIsDeclaration = Dest->isDeclaration();
>    
> -  if (SrcIsDeclaration) {
> +  if (SrcIsDeclaration && !Src->isMaterializable()) {
>      // If Src is external or if both Src & Dest are external..  Just link the
>      // external globals, we aren't adding anything.
>      if (Src->hasDLLImportLinkage()) {
> @@ -708,6 +711,12 @@
>      // Any uses of DF need to change to NewDF, with cast.
>      DGV->replaceAllUsesWith(ConstantExpr::getBitCast(NewDF, DGV->getType()));
>      DGV->eraseFromParent();
> +  } else {
> +    // Internal, LO_ODR, or LO linkage - stick in set to ignore and lazily link.
> +    if (SF->hasLinkOnceLinkage() || SF->hasInternalLinkage()) {
> +      DoNotLinkFromSource.insert(SF);
> +      LazilyLinkFunctions.push_back(SF);
> +    }

Shouldn't this use the same set of linkages as globaldce; i.e. hasLocalLinkage,
hasLinkOnceLinkage or hasAvailableExternallyLinkage?

Thanks,
-- 
Peter



More information about the llvm-commits mailing list