[llvm-commits] Fwd: [127591] Fix PR1404.

Devang Patel dpatel at apple.com
Wed May 23 08:33:10 PDT 2007


Begin forwarded message:

> Date: May 23, 2007 8:31:01 AM PDT
> To: llvm-group at group.apple.com
> Subject: [127591] Fix PR1404.
>
> Revision: 127591
> Author:   dpatel
> Date:     2007-05-23 08:31:00 -0700 (Wed, 23 May 2007)
>
> Log Message:
> -----------
> Fix PR1404. Patch by Duncan Sands.
> Prune local values from LLVMValues vector.
>
> Modified Paths:
> --------------
>     apple-local/branches/llvm/gcc/llvm-convert.cpp
>
> Modified: apple-local/branches/llvm/gcc/llvm-convert.cpp
> ===================================================================
> --- apple-local/branches/llvm/gcc/llvm-convert.cpp	2007-05-23  
> 09:21:47 UTC (rev 127590)
> +++ apple-local/branches/llvm/gcc/llvm-convert.cpp	2007-05-23  
> 15:31:00 UTC (rev 127591)
> @@ -128,7 +128,8 @@
>      // If there was an error, we may have disabled creating LLVM  
> values.
>      if (Index == 0) return 0;
>    }
> -  assert ((Index - 1) < LLVMValues.size() && "Invalid LLVM Value  
> index");
> +  assert ((Index - 1) < LLVMValues.size() && "Invalid LLVM value  
> index");
> +  assert (LLVMValues[Index - 1] && "Trying to use deleted LLVM  
> value!");
>
>    return LLVMValues[Index - 1];
>  }
> @@ -153,7 +154,8 @@
>
>    // Insert the new value into the value map.  We know that it  
> can't already
>    // exist in the mapping.
> -  LLVMValuesMap[New] = Idx+1;
> +  if (New)
> +    LLVMValuesMap[New] = Idx+1;
>  }
>
>  // Read LLVM Types string table
> @@ -198,7 +200,7 @@
>
>    for (std::vector<Value *>::iterator I = LLVMValues.begin(),
>           E = LLVMValues.end(); I != E; ++I)  {
> -    if (Constant *C = dyn_cast<Constant>(*I))
> +    if (Constant *C = dyn_cast_or_null<Constant>(*I))
>        ValuesForPCH.push_back(C);
>      else
>        // Non constant values, e.g. arguments, are not at global  
> scope.
> @@ -216,6 +218,36 @@
>                       "llvm.pch.values", TheModule);
>  }
>
> +/// eraseLocalLLVMValues - drop all non-global values from the  
> LLVM values map.
> +void eraseLocalLLVMValues() {
> +  // Try to reduce the size of LLVMValues by removing local values  
> from the end.
> +  std::vector<Value *>::reverse_iterator I, E;
> +
> +  for (I = LLVMValues.rbegin(), E = LLVMValues.rend(); I != E; ++I) {
> +    if (Value *V = *I) {
> +      if (isa<Constant>(V))
> +        break;
> +      else
> +        LLVMValuesMap.erase(V);
> +    }
> +  }
> +
> +  LLVMValues.erase(I.base(), LLVMValues.end()); // Drop erased values
> +
> +  // Iterate over LLVMValuesMap since it may be much smaller than  
> LLVMValues.
> +  for (LLVMValuesMapTy::iterator I = LLVMValuesMap.begin(),
> +       E = LLVMValuesMap.end(); I != E; ++I) {
> +    assert(I->first && "Values map contains NULL!");
> +    if (!isa<Constant>(I->first)) {
> +      unsigned Index = I->second - 1;
> +      assert(Index < LLVMValues.size() && LLVMValues[Index] == I- 
> >first &&
> +             "Inconsistent value map!");
> +      LLVMValues[Index] = NULL;
> +      LLVMValuesMap.erase(I);
> +    }
> +  }
> +}
> +
>  /// isGCC_SSA_Temporary - Return true if this is an SSA temporary  
> that we can
>  /// directly compile into an LLVM temporary.  This saves us from  
> creating an
>  /// alloca and creating loads/stores of that alloca (a compile- 
> time win).  We
> @@ -689,7 +721,11 @@
>      if (SI->getNumSuccessors() > 1)
>        SI->setSuccessor(0, SI->getSuccessor(1));
>    }
> -
> +
> +  // Remove any cached LLVM values that are local to this  
> function.  Such values
> +  // may be deleted when the optimizers run, so would be dangerous  
> to keep.
> +  eraseLocalLLVMValues();
> +
>    return Fn;
>  }
>
>
>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20070523/f831b4bb/attachment.html>


More information about the llvm-commits mailing list