1894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//===---- llvm/Analysis/ScalarEvolutionExpander.h - SCEV Exprs --*- C++ -*-===// 2894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// 3894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// The LLVM Compiler Infrastructure 4894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// 5894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// This file is distributed under the University of Illinois Open Source 6894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// License. See LICENSE.TXT for details. 7894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// 8894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//===----------------------------------------------------------------------===// 9894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// 10894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// This file defines the classes used to generate code from scalar expressions. 11894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman// 12894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman//===----------------------------------------------------------------------===// 13894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 14894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#ifndef LLVM_ANALYSIS_SCALAREVOLUTION_EXPANDER_H 15894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#define LLVM_ANALYSIS_SCALAREVOLUTION_EXPANDER_H 16894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 17894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#include "llvm/Analysis/ScalarEvolutionExpressions.h" 18894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#include "llvm/Analysis/ScalarEvolutionNormalization.h" 19894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#include "llvm/Support/IRBuilder.h" 20894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#include "llvm/Support/TargetFolder.h" 21894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#include "llvm/Support/ValueHandle.h" 22894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#include <set> 23894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 24894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Baumannamespace llvm { 25894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// SCEVExpander - This class uses information about analyze scalars to 26894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// rewrite expressions in canonical form. 27894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// 28894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// Clients should create an instance of this class when rewriting is needed, 29894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// and destroy it when finished to allow the release of the associated 30894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// memory. 31894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman class SCEVExpander : public SCEVVisitor<SCEVExpander, Value*> { 32894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman ScalarEvolution &SE; 3319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 3419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman // New instructions receive a name to identifies them with the current pass. 3519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman const char* IVName; 3619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 37894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman std::map<std::pair<const SCEV *, Instruction *>, AssertingVH<Value> > 38894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman InsertedExpressions; 39894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman std::set<AssertingVH<Value> > InsertedValues; 40894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman std::set<AssertingVH<Value> > InsertedPostIncValues; 41894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 4219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman /// RelevantLoops - A memoization of the "relevant" loop for a given SCEV. 4319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman DenseMap<const SCEV *, const Loop *> RelevantLoops; 4419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 45894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// PostIncLoops - Addrecs referring to any of the given loops are expanded 46894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// in post-inc mode. For example, expanding {1,+,1}<L> in post-inc mode 47894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// returns the add instruction that adds one to the phi for {0,+,1}<L>, 48894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// as opposed to a new phi starting at 1. This is only supported in 49894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// non-canonical mode. 50894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman PostIncLoopSet PostIncLoops; 51894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 52894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// IVIncInsertPos - When this is non-null, addrecs expanded in the 53894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// loop it indicates should be inserted with increments at 54894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// IVIncInsertPos. 55894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman const Loop *IVIncInsertLoop; 56894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 57894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// IVIncInsertPos - When expanding addrecs in the IVIncInsertLoop loop, 58894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// insert the IV increment at this position. 59894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman Instruction *IVIncInsertPos; 60894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 61894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// CanonicalMode - When true, expressions are expanded in "canonical" 62894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// form. In particular, addrecs are expanded as arithmetic based on 63894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// a canonical induction variable. When false, expression are expanded 64894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// in a more literal form. 65894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman bool CanonicalMode; 66894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 6719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman /// When invoked from LSR, the expander is in "strength reduction" mode. The 6819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman /// only difference is that phi's are only reused if they are already in 6919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman /// "expanded" form. 7019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman bool LSRMode; 7119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 7219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman typedef IRBuilder<true, TargetFolder> BuilderType; 73894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman BuilderType Builder; 74894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 7519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman#ifndef NDEBUG 7619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman const char *DebugType; 7719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman#endif 7819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 79894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman friend struct SCEVVisitor<SCEVExpander, Value*>; 80894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 81894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman public: 82894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// SCEVExpander - Construct a SCEVExpander in "canonical" mode. 8319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman explicit SCEVExpander(ScalarEvolution &se, const char *name) 8419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman : SE(se), IVName(name), IVIncInsertLoop(0), IVIncInsertPos(0), 8519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman CanonicalMode(true), LSRMode(false), 8619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman Builder(se.getContext(), TargetFolder(se.TD)) { 8719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman#ifndef NDEBUG 8819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman DebugType = ""; 8919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman#endif 9019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman } 9119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 9219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman#ifndef NDEBUG 9319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman void setDebugType(const char* s) { DebugType = s; } 9419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman#endif 95894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 96894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// clear - Erase the contents of the InsertedExpressions map so that users 97894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// trying to expand the same expression into multiple BasicBlocks or 98894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// different places within the same BasicBlock can do so. 99894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman void clear() { 100894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman InsertedExpressions.clear(); 101894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman InsertedValues.clear(); 102894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman InsertedPostIncValues.clear(); 103894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 104894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 105894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// getOrInsertCanonicalInductionVariable - This method returns the 106894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// canonical induction variable of the specified type for the specified 107894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// loop (inserting one if there is none). A canonical induction variable 108894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// starts at zero and steps by one on each iteration. 10919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman PHINode *getOrInsertCanonicalInductionVariable(const Loop *L, Type *Ty); 11019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 11119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman /// hoistStep - Utility for hoisting an IV increment. 11219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman static bool hoistStep(Instruction *IncV, Instruction *InsertPos, 11319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman const DominatorTree *DT); 11419bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 11519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman /// replaceCongruentIVs - replace congruent phis with their most canonical 11619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman /// representative. Return the number of phis eliminated. 11719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman unsigned replaceCongruentIVs(Loop *L, const DominatorTree *DT, 11819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman SmallVectorImpl<WeakVH> &DeadInsts); 119894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 120894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// expandCodeFor - Insert code to directly compute the specified SCEV 121894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// expression into the program. The inserted code is inserted into the 122894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// specified block. 12319bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman Value *expandCodeFor(const SCEV *SH, Type *Ty, Instruction *I); 124894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 125894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// setIVIncInsertPos - Set the current IV increment loop and position. 126894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman void setIVIncInsertPos(const Loop *L, Instruction *Pos) { 127894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman assert(!CanonicalMode && 128894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman "IV increment positions are not supported in CanonicalMode"); 129894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman IVIncInsertLoop = L; 130894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman IVIncInsertPos = Pos; 131894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 132894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 133894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// setPostInc - Enable post-inc expansion for addrecs referring to the 134894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// given loops. Post-inc expansion is only supported in non-canonical 135894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// mode. 136894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman void setPostInc(const PostIncLoopSet &L) { 137894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman assert(!CanonicalMode && 138894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman "Post-inc expansion is not supported in CanonicalMode"); 139894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman PostIncLoops = L; 140894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 141894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 142894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// clearPostInc - Disable all post-inc expansion. 143894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman void clearPostInc() { 144894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman PostIncLoops.clear(); 145894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 146894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman // When we change the post-inc loop set, cached expansions may no 147894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman // longer be valid. 148894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman InsertedPostIncValues.clear(); 149894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 150894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 151894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// disableCanonicalMode - Disable the behavior of expanding expressions in 152894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// canonical form rather than in a more literal form. Non-canonical mode 153894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// is useful for late optimization passes. 154894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman void disableCanonicalMode() { CanonicalMode = false; } 155894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 15619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman void enableLSRMode() { LSRMode = true; } 15719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 158894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// clearInsertPoint - Clear the current insertion point. This is useful 159894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// if the instruction that had been serving as the insertion point may 160894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// have been deleted. 161894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman void clearInsertPoint() { 162894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman Builder.ClearInsertionPoint(); 163894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 164894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman private: 165894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman LLVMContext &getContext() const { return SE.getContext(); } 166894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 167894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// InsertBinop - Insert the specified binary operator, doing a small amount 168894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// of work to avoid inserting an obviously redundant operation. 169894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman Value *InsertBinop(Instruction::BinaryOps Opcode, Value *LHS, Value *RHS); 170894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 171894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// ReuseOrCreateCast - Arange for there to be a cast of V to Ty at IP, 172894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// reusing an existing cast if a suitable one exists, moving an existing 173894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// cast if a suitable one exists but isn't in the right place, or 174894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// or creating a new one. 17519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman Value *ReuseOrCreateCast(Value *V, Type *Ty, 176894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman Instruction::CastOps Op, 177894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman BasicBlock::iterator IP); 178894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 179894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// InsertNoopCastOfTo - Insert a cast of V to the specified type, 180894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// which must be possible with a noop cast, doing what we can to 181894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// share the casts. 18219bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman Value *InsertNoopCastOfTo(Value *V, Type *Ty); 183894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 184894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// expandAddToGEP - Expand a SCEVAddExpr with a pointer type into a GEP 185894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// instead of using ptrtoint+arithmetic+inttoptr. 186894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman Value *expandAddToGEP(const SCEV *const *op_begin, 187894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman const SCEV *const *op_end, 18819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman PointerType *PTy, Type *Ty, Value *V); 189894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 190894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman Value *expand(const SCEV *S); 191894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 192894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// expandCodeFor - Insert code to directly compute the specified SCEV 193894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// expression into the program. The inserted code is inserted into the 194894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// SCEVExpander's current insertion point. If a type is specified, the 195894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// result will be expanded to have that type, with a cast if necessary. 19619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman Value *expandCodeFor(const SCEV *SH, Type *Ty = 0); 197894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 198894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// isInsertedInstruction - Return true if the specified instruction was 199894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// inserted by the code rewriter. If so, the client should not modify the 200894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman /// instruction. 201894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman bool isInsertedInstruction(Instruction *I) const { 202894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman return InsertedValues.count(I) || InsertedPostIncValues.count(I); 203894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 204894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 20519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman /// getRelevantLoop - Determine the most "relevant" loop for the given SCEV. 20619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman const Loop *getRelevantLoop(const SCEV *); 20719bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 208894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman Value *visitConstant(const SCEVConstant *S) { 209894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman return S->getValue(); 210894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 211894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 212894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman Value *visitTruncateExpr(const SCEVTruncateExpr *S); 213894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 214894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman Value *visitZeroExtendExpr(const SCEVZeroExtendExpr *S); 215894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 216894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman Value *visitSignExtendExpr(const SCEVSignExtendExpr *S); 217894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 218894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman Value *visitAddExpr(const SCEVAddExpr *S); 219894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 220894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman Value *visitMulExpr(const SCEVMulExpr *S); 221894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 222894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman Value *visitUDivExpr(const SCEVUDivExpr *S); 223894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 224894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman Value *visitAddRecExpr(const SCEVAddRecExpr *S); 225894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 226894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman Value *visitSMaxExpr(const SCEVSMaxExpr *S); 227894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 228894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman Value *visitUMaxExpr(const SCEVUMaxExpr *S); 229894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 230894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman Value *visitUnknown(const SCEVUnknown *S) { 231894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman return S->getValue(); 232894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman } 233894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 234894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman void rememberInstruction(Value *I); 235894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 236894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman void restoreInsertPoint(BasicBlock *BB, BasicBlock::iterator I); 237894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 23819bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman bool isNormalAddRecExprPHI(PHINode *PN, Instruction *IncV, const Loop *L); 23919bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 24019bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman bool isExpandedAddRecExprPHI(PHINode *PN, Instruction *IncV, const Loop *L); 24119bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman 242894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman Value *expandAddRecExprLiterally(const SCEVAddRecExpr *); 243894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman PHINode *getAddRecExprPHILiterally(const SCEVAddRecExpr *Normalized, 244894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman const Loop *L, 24519bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman Type *ExpandTy, 24619bac1e08be200c31efd26f0f5fd144c9b3eefd3John Bauman Type *IntTy); 247894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman }; 248894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman} 249894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman 250894018228b0e0bdbd7aa7e8f47d4a9458789ca82John Bauman#endif 251