[llvm] r291927 - [SCEV] Limit recursion depth of constant evolving.

Philip Reames via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 13 21:50:04 PST 2017


Can this code be changed to use an iterative algorithm instead of a 
recursive one easily?  If so, doing that would be strongly preferred.

Philip


On 01/13/2017 10:28 AM, Michael Liao via llvm-commits wrote:
> Author: hliao
> Date: Fri Jan 13 12:28:30 2017
> New Revision: 291927
>
> URL: http://llvm.org/viewvc/llvm-project?rev=291927&view=rev
> Log:
> [SCEV] Limit recursion depth of constant evolving.
>
> - For a loop body with VERY complicated exit condition evaluation, constant
>    evolving may run out of stack on platforms such as Windows. Need to limit the
>    recursion depth.
>
> Differential Revision: https://reviews.llvm.org/D28629
>
>
> Modified:
>      llvm/trunk/lib/Analysis/ScalarEvolution.cpp
>
> Modified: llvm/trunk/lib/Analysis/ScalarEvolution.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ScalarEvolution.cpp?rev=291927&r1=291926&r2=291927&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Analysis/ScalarEvolution.cpp (original)
> +++ llvm/trunk/lib/Analysis/ScalarEvolution.cpp Fri Jan 13 12:28:30 2017
> @@ -132,6 +132,10 @@ static cl::opt<unsigned>
>                       cl::desc("Maximum depth of recursive compare complexity"),
>                       cl::init(32));
>   
> +static cl::opt<unsigned> MaxConstantEvolvingDepth(
> +    "scalar-evolution-max-constant-evolving-depth", cl::Hidden,
> +    cl::desc("Maximum depth of recursive constant evolving"), cl::init(32));
> +
>   //===----------------------------------------------------------------------===//
>   //                           SCEV class definitions
>   //===----------------------------------------------------------------------===//
> @@ -6403,7 +6407,10 @@ static bool canConstantEvolve(Instructio
>   /// recursing through each instruction operand until reaching a loop header phi.
>   static PHINode *
>   getConstantEvolvingPHIOperands(Instruction *UseInst, const Loop *L,
> -                               DenseMap<Instruction *, PHINode *> &PHIMap) {
> +                               DenseMap<Instruction *, PHINode *> &PHIMap,
> +                               unsigned Depth) {
> +  if (Depth > MaxConstantEvolvingDepth)
> +    return nullptr;
>   
>     // Otherwise, we can evaluate this instruction if all of its operands are
>     // constant or derived from a PHI node themselves.
> @@ -6423,7 +6430,7 @@ getConstantEvolvingPHIOperands(Instructi
>       if (!P) {
>         // Recurse and memoize the results, whether a phi is found or not.
>         // This recursive call invalidates pointers into PHIMap.
> -      P = getConstantEvolvingPHIOperands(OpInst, L, PHIMap);
> +      P = getConstantEvolvingPHIOperands(OpInst, L, PHIMap, Depth + 1);
>         PHIMap[OpInst] = P;
>       }
>       if (!P)
> @@ -6450,7 +6457,7 @@ static PHINode *getConstantEvolvingPHI(V
>   
>     // Record non-constant instructions contained by the loop.
>     DenseMap<Instruction *, PHINode *> PHIMap;
> -  return getConstantEvolvingPHIOperands(I, L, PHIMap);
> +  return getConstantEvolvingPHIOperands(I, L, PHIMap, 0);
>   }
>   
>   /// EvaluateExpression - Given an expression that passes the
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits



More information about the llvm-commits mailing list