1 //===- llvm/Analysis/ScalarEvolutionNormalization.h - See below -*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // This file defines utilities for working with "normalized" ScalarEvolution 11 // expressions. 12 // 13 // The following example illustrates post-increment uses and how normalized 14 // expressions help. 15 // 16 // for (i=0; i!=n; ++i) { 17 // ... 18 // } 19 // use(i); 20 // 21 // While the expression for most uses of i inside the loop is {0,+,1}<%L>, the 22 // expression for the use of i outside the loop is {1,+,1}<%L>, since i is 23 // incremented at the end of the loop body. This is inconveient, since it 24 // suggests that we need two different induction variables, one that starts 25 // at 0 and one that starts at 1. We'd prefer to be able to think of these as 26 // the same induction variable, with uses inside the loop using the 27 // "pre-incremented" value, and uses after the loop using the 28 // "post-incremented" value. 29 // 30 // Expressions for post-incremented uses are represented as an expression 31 // paired with a set of loops for which the expression is in "post-increment" 32 // mode (there may be multiple loops). 33 // 34 //===----------------------------------------------------------------------===// 35 36 #ifndef LLVM_ANALYSIS_SCALAREVOLUTION_NORMALIZATION_H 37 #define LLVM_ANALYSIS_SCALAREVOLUTION_NORMALIZATION_H 38 39 #include "llvm/ADT/SmallPtrSet.h" 40 41 namespace llvm { 42 43 class Instruction; 44 class DominatorTree; 45 class Loop; 46 class ScalarEvolution; 47 class SCEV; 48 class Value; 49 50 /// TransformKind - Different types of transformations that 51 /// TransformForPostIncUse can do. 52 enum TransformKind { 53 /// Normalize - Normalize according to the given loops. 54 Normalize, 55 /// NormalizeAutodetect - Detect post-inc opportunities on new expressions, 56 /// update the given loop set, and normalize. 57 NormalizeAutodetect, 58 /// Denormalize - Perform the inverse transform on the expression with the 59 /// given loop set. 60 Denormalize 61 }; 62 63 /// PostIncLoopSet - A set of loops. 64 typedef SmallPtrSet<const Loop *, 2> PostIncLoopSet; 65 66 /// TransformForPostIncUse - Transform the given expression according to the 67 /// given transformation kind. 68 const SCEV *TransformForPostIncUse(TransformKind Kind, 69 const SCEV *S, 70 Instruction *User, 71 Value *OperandValToReplace, 72 PostIncLoopSet &Loops, 73 ScalarEvolution &SE, 74 DominatorTree &DT); 75 76 } 77 78 #endif 79