ScalarEvolutionExpander.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===---- llvm/Analysis/ScalarEvolutionExpander.h - SCEV Exprs --*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // This file defines the classes used to generate code from scalar expressions.
  15. //
  16. //===----------------------------------------------------------------------===//
  17. #ifndef LLVM_TRANSFORMS_UTILS_SCALAREVOLUTIONEXPANDER_H
  18. #define LLVM_TRANSFORMS_UTILS_SCALAREVOLUTIONEXPANDER_H
  19. #include "llvm/ADT/DenseMap.h"
  20. #include "llvm/ADT/DenseSet.h"
  21. #include "llvm/ADT/SmallVector.h"
  22. #include "llvm/Analysis/InstSimplifyFolder.h"
  23. #include "llvm/Analysis/ScalarEvolutionExpressions.h"
  24. #include "llvm/Analysis/ScalarEvolutionNormalization.h"
  25. #include "llvm/Analysis/TargetTransformInfo.h"
  26. #include "llvm/IR/IRBuilder.h"
  27. #include "llvm/IR/ValueHandle.h"
  28. #include "llvm/Support/CommandLine.h"
  29. #include "llvm/Support/InstructionCost.h"
  30. namespace llvm {
  31. extern cl::opt<unsigned> SCEVCheapExpansionBudget;
  32. /// struct for holding enough information to help calculate the cost of the
  33. /// given SCEV when expanded into IR.
  34. struct SCEVOperand {
  35. explicit SCEVOperand(unsigned Opc, int Idx, const SCEV *S) :
  36. ParentOpcode(Opc), OperandIdx(Idx), S(S) { }
  37. /// LLVM instruction opcode that uses the operand.
  38. unsigned ParentOpcode;
  39. /// The use index of an expanded instruction.
  40. int OperandIdx;
  41. /// The SCEV operand to be costed.
  42. const SCEV* S;
  43. };
  44. /// This class uses information about analyze scalars to rewrite expressions
  45. /// in canonical form.
  46. ///
  47. /// Clients should create an instance of this class when rewriting is needed,
  48. /// and destroy it when finished to allow the release of the associated
  49. /// memory.
  50. class SCEVExpander : public SCEVVisitor<SCEVExpander, Value *> {
  51. ScalarEvolution &SE;
  52. const DataLayout &DL;
  53. // New instructions receive a name to identify them with the current pass.
  54. const char *IVName;
  55. /// Indicates whether LCSSA phis should be created for inserted values.
  56. bool PreserveLCSSA;
  57. // InsertedExpressions caches Values for reuse, so must track RAUW.
  58. DenseMap<std::pair<const SCEV *, Instruction *>, TrackingVH<Value>>
  59. InsertedExpressions;
  60. // InsertedValues only flags inserted instructions so needs no RAUW.
  61. DenseSet<AssertingVH<Value>> InsertedValues;
  62. DenseSet<AssertingVH<Value>> InsertedPostIncValues;
  63. /// Keep track of the existing IR values re-used during expansion.
  64. /// FIXME: Ideally re-used instructions would not be added to
  65. /// InsertedValues/InsertedPostIncValues.
  66. SmallPtrSet<Value *, 16> ReusedValues;
  67. // The induction variables generated.
  68. SmallVector<WeakVH, 2> InsertedIVs;
  69. /// A memoization of the "relevant" loop for a given SCEV.
  70. DenseMap<const SCEV *, const Loop *> RelevantLoops;
  71. /// Addrecs referring to any of the given loops are expanded in post-inc
  72. /// mode. For example, expanding {1,+,1}<L> in post-inc mode returns the add
  73. /// instruction that adds one to the phi for {0,+,1}<L>, as opposed to a new
  74. /// phi starting at 1. This is only supported in non-canonical mode.
  75. PostIncLoopSet PostIncLoops;
  76. /// When this is non-null, addrecs expanded in the loop it indicates should
  77. /// be inserted with increments at IVIncInsertPos.
  78. const Loop *IVIncInsertLoop;
  79. /// When expanding addrecs in the IVIncInsertLoop loop, insert the IV
  80. /// increment at this position.
  81. Instruction *IVIncInsertPos;
  82. /// Phis that complete an IV chain. Reuse
  83. DenseSet<AssertingVH<PHINode>> ChainedPhis;
  84. /// When true, SCEVExpander tries to expand expressions in "canonical" form.
  85. /// When false, expressions are expanded in a more literal form.
  86. ///
  87. /// In "canonical" form addrecs are expanded as arithmetic based on a
  88. /// canonical induction variable. Note that CanonicalMode doesn't guarantee
  89. /// that all expressions are expanded in "canonical" form. For some
  90. /// expressions literal mode can be preferred.
  91. bool CanonicalMode;
  92. /// When invoked from LSR, the expander is in "strength reduction" mode. The
  93. /// only difference is that phi's are only reused if they are already in
  94. /// "expanded" form.
  95. bool LSRMode;
  96. typedef IRBuilder<InstSimplifyFolder, IRBuilderCallbackInserter> BuilderType;
  97. BuilderType Builder;
  98. // RAII object that stores the current insertion point and restores it when
  99. // the object is destroyed. This includes the debug location. Duplicated
  100. // from InsertPointGuard to add SetInsertPoint() which is used to updated
  101. // InsertPointGuards stack when insert points are moved during SCEV
  102. // expansion.
  103. class SCEVInsertPointGuard {
  104. IRBuilderBase &Builder;
  105. AssertingVH<BasicBlock> Block;
  106. BasicBlock::iterator Point;
  107. DebugLoc DbgLoc;
  108. SCEVExpander *SE;
  109. SCEVInsertPointGuard(const SCEVInsertPointGuard &) = delete;
  110. SCEVInsertPointGuard &operator=(const SCEVInsertPointGuard &) = delete;
  111. public:
  112. SCEVInsertPointGuard(IRBuilderBase &B, SCEVExpander *SE)
  113. : Builder(B), Block(B.GetInsertBlock()), Point(B.GetInsertPoint()),
  114. DbgLoc(B.getCurrentDebugLocation()), SE(SE) {
  115. SE->InsertPointGuards.push_back(this);
  116. }
  117. ~SCEVInsertPointGuard() {
  118. // These guards should always created/destroyed in FIFO order since they
  119. // are used to guard lexically scoped blocks of code in
  120. // ScalarEvolutionExpander.
  121. assert(SE->InsertPointGuards.back() == this);
  122. SE->InsertPointGuards.pop_back();
  123. Builder.restoreIP(IRBuilderBase::InsertPoint(Block, Point));
  124. Builder.SetCurrentDebugLocation(DbgLoc);
  125. }
  126. BasicBlock::iterator GetInsertPoint() const { return Point; }
  127. void SetInsertPoint(BasicBlock::iterator I) { Point = I; }
  128. };
  129. /// Stack of pointers to saved insert points, used to keep insert points
  130. /// consistent when instructions are moved.
  131. SmallVector<SCEVInsertPointGuard *, 8> InsertPointGuards;
  132. #ifdef LLVM_ENABLE_ABI_BREAKING_CHECKS
  133. const char *DebugType;
  134. #endif
  135. friend struct SCEVVisitor<SCEVExpander, Value *>;
  136. public:
  137. /// Construct a SCEVExpander in "canonical" mode.
  138. explicit SCEVExpander(ScalarEvolution &se, const DataLayout &DL,
  139. const char *name, bool PreserveLCSSA = true)
  140. : SE(se), DL(DL), IVName(name), PreserveLCSSA(PreserveLCSSA),
  141. IVIncInsertLoop(nullptr), IVIncInsertPos(nullptr), CanonicalMode(true),
  142. LSRMode(false),
  143. Builder(se.getContext(), InstSimplifyFolder(DL),
  144. IRBuilderCallbackInserter(
  145. [this](Instruction *I) { rememberInstruction(I); })) {
  146. #ifdef LLVM_ENABLE_ABI_BREAKING_CHECKS
  147. DebugType = "";
  148. #endif
  149. }
  150. ~SCEVExpander() {
  151. // Make sure the insert point guard stack is consistent.
  152. assert(InsertPointGuards.empty());
  153. }
  154. #ifdef LLVM_ENABLE_ABI_BREAKING_CHECKS
  155. void setDebugType(const char *s) { DebugType = s; }
  156. #endif
  157. /// Erase the contents of the InsertedExpressions map so that users trying
  158. /// to expand the same expression into multiple BasicBlocks or different
  159. /// places within the same BasicBlock can do so.
  160. void clear() {
  161. InsertedExpressions.clear();
  162. InsertedValues.clear();
  163. InsertedPostIncValues.clear();
  164. ReusedValues.clear();
  165. ChainedPhis.clear();
  166. InsertedIVs.clear();
  167. }
  168. ScalarEvolution *getSE() { return &SE; }
  169. const SmallVectorImpl<WeakVH> &getInsertedIVs() const { return InsertedIVs; }
  170. /// Return a vector containing all instructions inserted during expansion.
  171. SmallVector<Instruction *, 32> getAllInsertedInstructions() const {
  172. SmallVector<Instruction *, 32> Result;
  173. for (const auto &VH : InsertedValues) {
  174. Value *V = VH;
  175. if (ReusedValues.contains(V))
  176. continue;
  177. if (auto *Inst = dyn_cast<Instruction>(V))
  178. Result.push_back(Inst);
  179. }
  180. for (const auto &VH : InsertedPostIncValues) {
  181. Value *V = VH;
  182. if (ReusedValues.contains(V))
  183. continue;
  184. if (auto *Inst = dyn_cast<Instruction>(V))
  185. Result.push_back(Inst);
  186. }
  187. return Result;
  188. }
  189. /// Return true for expressions that can't be evaluated at runtime
  190. /// within given \b Budget.
  191. ///
  192. /// \p At is a parameter which specifies point in code where user is going to
  193. /// expand these expressions. Sometimes this knowledge can lead to
  194. /// a less pessimistic cost estimation.
  195. bool isHighCostExpansion(ArrayRef<const SCEV *> Exprs, Loop *L,
  196. unsigned Budget, const TargetTransformInfo *TTI,
  197. const Instruction *At) {
  198. assert(TTI && "This function requires TTI to be provided.");
  199. assert(At && "This function requires At instruction to be provided.");
  200. if (!TTI) // In assert-less builds, avoid crashing
  201. return true; // by always claiming to be high-cost.
  202. SmallVector<SCEVOperand, 8> Worklist;
  203. SmallPtrSet<const SCEV *, 8> Processed;
  204. InstructionCost Cost = 0;
  205. unsigned ScaledBudget = Budget * TargetTransformInfo::TCC_Basic;
  206. for (auto *Expr : Exprs)
  207. Worklist.emplace_back(-1, -1, Expr);
  208. while (!Worklist.empty()) {
  209. const SCEVOperand WorkItem = Worklist.pop_back_val();
  210. if (isHighCostExpansionHelper(WorkItem, L, *At, Cost, ScaledBudget, *TTI,
  211. Processed, Worklist))
  212. return true;
  213. }
  214. assert(Cost <= ScaledBudget && "Should have returned from inner loop.");
  215. return false;
  216. }
  217. /// Return the induction variable increment's IV operand.
  218. Instruction *getIVIncOperand(Instruction *IncV, Instruction *InsertPos,
  219. bool allowScale);
  220. /// Utility for hoisting \p IncV (with all subexpressions requried for its
  221. /// computation) before \p InsertPos. If \p RecomputePoisonFlags is set, drops
  222. /// all poison-generating flags from instructions being hoisted and tries to
  223. /// re-infer them in the new location. It should be used when we are going to
  224. /// introduce a new use in the new position that didn't exist before, and may
  225. /// trigger new UB in case of poison.
  226. bool hoistIVInc(Instruction *IncV, Instruction *InsertPos,
  227. bool RecomputePoisonFlags = false);
  228. /// replace congruent phis with their most canonical representative. Return
  229. /// the number of phis eliminated.
  230. unsigned replaceCongruentIVs(Loop *L, const DominatorTree *DT,
  231. SmallVectorImpl<WeakTrackingVH> &DeadInsts,
  232. const TargetTransformInfo *TTI = nullptr);
  233. /// Return true if the given expression is safe to expand in the sense that
  234. /// all materialized values are safe to speculate anywhere their operands are
  235. /// defined, and the expander is capable of expanding the expression.
  236. bool isSafeToExpand(const SCEV *S) const;
  237. /// Return true if the given expression is safe to expand in the sense that
  238. /// all materialized values are defined and safe to speculate at the specified
  239. /// location and their operands are defined at this location.
  240. bool isSafeToExpandAt(const SCEV *S, const Instruction *InsertionPoint) const;
  241. /// Insert code to directly compute the specified SCEV expression into the
  242. /// program. The code is inserted into the specified block.
  243. Value *expandCodeFor(const SCEV *SH, Type *Ty, Instruction *I) {
  244. return expandCodeForImpl(SH, Ty, I);
  245. }
  246. /// Insert code to directly compute the specified SCEV expression into the
  247. /// program. The code is inserted into the SCEVExpander's current
  248. /// insertion point. If a type is specified, the result will be expanded to
  249. /// have that type, with a cast if necessary.
  250. Value *expandCodeFor(const SCEV *SH, Type *Ty = nullptr) {
  251. return expandCodeForImpl(SH, Ty);
  252. }
  253. /// Generates a code sequence that evaluates this predicate. The inserted
  254. /// instructions will be at position \p Loc. The result will be of type i1
  255. /// and will have a value of 0 when the predicate is false and 1 otherwise.
  256. Value *expandCodeForPredicate(const SCEVPredicate *Pred, Instruction *Loc);
  257. /// A specialized variant of expandCodeForPredicate, handling the case when
  258. /// we are expanding code for a SCEVComparePredicate.
  259. Value *expandComparePredicate(const SCEVComparePredicate *Pred,
  260. Instruction *Loc);
  261. /// Generates code that evaluates if the \p AR expression will overflow.
  262. Value *generateOverflowCheck(const SCEVAddRecExpr *AR, Instruction *Loc,
  263. bool Signed);
  264. /// A specialized variant of expandCodeForPredicate, handling the case when
  265. /// we are expanding code for a SCEVWrapPredicate.
  266. Value *expandWrapPredicate(const SCEVWrapPredicate *P, Instruction *Loc);
  267. /// A specialized variant of expandCodeForPredicate, handling the case when
  268. /// we are expanding code for a SCEVUnionPredicate.
  269. Value *expandUnionPredicate(const SCEVUnionPredicate *Pred, Instruction *Loc);
  270. /// Set the current IV increment loop and position.
  271. void setIVIncInsertPos(const Loop *L, Instruction *Pos) {
  272. assert(!CanonicalMode &&
  273. "IV increment positions are not supported in CanonicalMode");
  274. IVIncInsertLoop = L;
  275. IVIncInsertPos = Pos;
  276. }
  277. /// Enable post-inc expansion for addrecs referring to the given
  278. /// loops. Post-inc expansion is only supported in non-canonical mode.
  279. void setPostInc(const PostIncLoopSet &L) {
  280. assert(!CanonicalMode &&
  281. "Post-inc expansion is not supported in CanonicalMode");
  282. PostIncLoops = L;
  283. }
  284. /// Disable all post-inc expansion.
  285. void clearPostInc() {
  286. PostIncLoops.clear();
  287. // When we change the post-inc loop set, cached expansions may no
  288. // longer be valid.
  289. InsertedPostIncValues.clear();
  290. }
  291. /// Disable the behavior of expanding expressions in canonical form rather
  292. /// than in a more literal form. Non-canonical mode is useful for late
  293. /// optimization passes.
  294. void disableCanonicalMode() { CanonicalMode = false; }
  295. void enableLSRMode() { LSRMode = true; }
  296. /// Set the current insertion point. This is useful if multiple calls to
  297. /// expandCodeFor() are going to be made with the same insert point and the
  298. /// insert point may be moved during one of the expansions (e.g. if the
  299. /// insert point is not a block terminator).
  300. void setInsertPoint(Instruction *IP) {
  301. assert(IP);
  302. Builder.SetInsertPoint(IP);
  303. }
  304. /// Clear the current insertion point. This is useful if the instruction
  305. /// that had been serving as the insertion point may have been deleted.
  306. void clearInsertPoint() { Builder.ClearInsertionPoint(); }
  307. /// Set location information used by debugging information.
  308. void SetCurrentDebugLocation(DebugLoc L) {
  309. Builder.SetCurrentDebugLocation(std::move(L));
  310. }
  311. /// Get location information used by debugging information.
  312. DebugLoc getCurrentDebugLocation() const {
  313. return Builder.getCurrentDebugLocation();
  314. }
  315. /// Return true if the specified instruction was inserted by the code
  316. /// rewriter. If so, the client should not modify the instruction. Note that
  317. /// this also includes instructions re-used during expansion.
  318. bool isInsertedInstruction(Instruction *I) const {
  319. return InsertedValues.count(I) || InsertedPostIncValues.count(I);
  320. }
  321. void setChainedPhi(PHINode *PN) { ChainedPhis.insert(PN); }
  322. /// Try to find the ValueOffsetPair for S. The function is mainly used to
  323. /// check whether S can be expanded cheaply. If this returns a non-None
  324. /// value, we know we can codegen the `ValueOffsetPair` into a suitable
  325. /// expansion identical with S so that S can be expanded cheaply.
  326. ///
  327. /// L is a hint which tells in which loop to look for the suitable value.
  328. /// On success return value which is equivalent to the expanded S at point
  329. /// At. Return nullptr if value was not found.
  330. ///
  331. /// Note that this function does not perform an exhaustive search. I.e if it
  332. /// didn't find any value it does not mean that there is no such value.
  333. ///
  334. Value *getRelatedExistingExpansion(const SCEV *S, const Instruction *At,
  335. Loop *L);
  336. /// Returns a suitable insert point after \p I, that dominates \p
  337. /// MustDominate. Skips instructions inserted by the expander.
  338. BasicBlock::iterator findInsertPointAfter(Instruction *I,
  339. Instruction *MustDominate) const;
  340. private:
  341. LLVMContext &getContext() const { return SE.getContext(); }
  342. /// Insert code to directly compute the specified SCEV expression into the
  343. /// program. The code is inserted into the SCEVExpander's current
  344. /// insertion point. If a type is specified, the result will be expanded to
  345. /// have that type, with a cast if necessary. If \p Root is true, this
  346. /// indicates that \p SH is the top-level expression to expand passed from
  347. /// an external client call.
  348. Value *expandCodeForImpl(const SCEV *SH, Type *Ty);
  349. /// Insert code to directly compute the specified SCEV expression into the
  350. /// program. The code is inserted into the specified block. If \p
  351. /// Root is true, this indicates that \p SH is the top-level expression to
  352. /// expand passed from an external client call.
  353. Value *expandCodeForImpl(const SCEV *SH, Type *Ty, Instruction *I);
  354. /// Recursive helper function for isHighCostExpansion.
  355. bool isHighCostExpansionHelper(const SCEVOperand &WorkItem, Loop *L,
  356. const Instruction &At, InstructionCost &Cost,
  357. unsigned Budget,
  358. const TargetTransformInfo &TTI,
  359. SmallPtrSetImpl<const SCEV *> &Processed,
  360. SmallVectorImpl<SCEVOperand> &Worklist);
  361. /// Insert the specified binary operator, doing a small amount of work to
  362. /// avoid inserting an obviously redundant operation, and hoisting to an
  363. /// outer loop when the opportunity is there and it is safe.
  364. Value *InsertBinop(Instruction::BinaryOps Opcode, Value *LHS, Value *RHS,
  365. SCEV::NoWrapFlags Flags, bool IsSafeToHoist);
  366. /// We want to cast \p V. What would be the best place for such a cast?
  367. BasicBlock::iterator GetOptimalInsertionPointForCastOf(Value *V) const;
  368. /// Arrange for there to be a cast of V to Ty at IP, reusing an existing
  369. /// cast if a suitable one exists, moving an existing cast if a suitable one
  370. /// exists but isn't in the right place, or creating a new one.
  371. Value *ReuseOrCreateCast(Value *V, Type *Ty, Instruction::CastOps Op,
  372. BasicBlock::iterator IP);
  373. /// Insert a cast of V to the specified type, which must be possible with a
  374. /// noop cast, doing what we can to share the casts.
  375. Value *InsertNoopCastOfTo(Value *V, Type *Ty);
  376. /// Expand a SCEVAddExpr with a pointer type into a GEP instead of using
  377. /// ptrtoint+arithmetic+inttoptr.
  378. Value *expandAddToGEP(const SCEV *const *op_begin, const SCEV *const *op_end,
  379. PointerType *PTy, Type *Ty, Value *V);
  380. Value *expandAddToGEP(const SCEV *Op, PointerType *PTy, Type *Ty, Value *V);
  381. /// Find a previous Value in ExprValueMap for expand.
  382. Value *FindValueInExprValueMap(const SCEV *S, const Instruction *InsertPt);
  383. Value *expand(const SCEV *S);
  384. /// Determine the most "relevant" loop for the given SCEV.
  385. const Loop *getRelevantLoop(const SCEV *);
  386. Value *expandMinMaxExpr(const SCEVNAryExpr *S, Intrinsic::ID IntrinID,
  387. Twine Name, bool IsSequential = false);
  388. Value *visitConstant(const SCEVConstant *S) { return S->getValue(); }
  389. Value *visitPtrToIntExpr(const SCEVPtrToIntExpr *S);
  390. Value *visitTruncateExpr(const SCEVTruncateExpr *S);
  391. Value *visitZeroExtendExpr(const SCEVZeroExtendExpr *S);
  392. Value *visitSignExtendExpr(const SCEVSignExtendExpr *S);
  393. Value *visitAddExpr(const SCEVAddExpr *S);
  394. Value *visitMulExpr(const SCEVMulExpr *S);
  395. Value *visitUDivExpr(const SCEVUDivExpr *S);
  396. Value *visitAddRecExpr(const SCEVAddRecExpr *S);
  397. Value *visitSMaxExpr(const SCEVSMaxExpr *S);
  398. Value *visitUMaxExpr(const SCEVUMaxExpr *S);
  399. Value *visitSMinExpr(const SCEVSMinExpr *S);
  400. Value *visitUMinExpr(const SCEVUMinExpr *S);
  401. Value *visitSequentialUMinExpr(const SCEVSequentialUMinExpr *S);
  402. Value *visitUnknown(const SCEVUnknown *S) { return S->getValue(); }
  403. void rememberInstruction(Value *I);
  404. bool isNormalAddRecExprPHI(PHINode *PN, Instruction *IncV, const Loop *L);
  405. bool isExpandedAddRecExprPHI(PHINode *PN, Instruction *IncV, const Loop *L);
  406. Value *expandAddRecExprLiterally(const SCEVAddRecExpr *);
  407. PHINode *getAddRecExprPHILiterally(const SCEVAddRecExpr *Normalized,
  408. const Loop *L, Type *ExpandTy, Type *IntTy,
  409. Type *&TruncTy, bool &InvertStep);
  410. Value *expandIVInc(PHINode *PN, Value *StepV, const Loop *L, Type *ExpandTy,
  411. Type *IntTy, bool useSubtract);
  412. void fixupInsertPoints(Instruction *I);
  413. /// Create LCSSA PHIs for \p V, if it is required for uses at the Builder's
  414. /// current insertion point.
  415. Value *fixupLCSSAFormFor(Value *V);
  416. };
  417. /// Helper to remove instructions inserted during SCEV expansion, unless they
  418. /// are marked as used.
  419. class SCEVExpanderCleaner {
  420. SCEVExpander &Expander;
  421. /// Indicates whether the result of the expansion is used. If false, the
  422. /// instructions added during expansion are removed.
  423. bool ResultUsed;
  424. public:
  425. SCEVExpanderCleaner(SCEVExpander &Expander)
  426. : Expander(Expander), ResultUsed(false) {}
  427. ~SCEVExpanderCleaner() { cleanup(); }
  428. /// Indicate that the result of the expansion is used.
  429. void markResultUsed() { ResultUsed = true; }
  430. void cleanup();
  431. };
  432. } // namespace llvm
  433. #endif
  434. #ifdef __GNUC__
  435. #pragma GCC diagnostic pop
  436. #endif