blob: 31aff0d9ebc3d293834e20514cd52e28f3752e41 [file] [log] [blame]
Chris Lattner6ec05f52002-05-10 22:44:58 +00001//===-- LICM.cpp - Loop Invariant Code Motion Pass ------------------------===//
John Criswell482202a2003-10-20 19:43:21 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by the LLVM research group and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
Chris Lattner6ec05f52002-05-10 22:44:58 +00009//
Chris Lattnerc0517682003-12-09 17:18:00 +000010// This pass performs loop invariant code motion, attempting to remove as much
11// code from the body of a loop as possible. It does this by either hoisting
12// code into the preheader block, or by sinking code to the exit blocks if it is
13// safe. This pass also promotes must-aliased memory locations in the loop to
Chris Lattner547192d62003-12-19 07:22:45 +000014// live in registers, thus hoisting and sinking "invariant" loads and stores.
Chris Lattnerc0517682003-12-09 17:18:00 +000015//
16// This pass uses alias analysis for two purposes:
Chris Lattner45d67d62003-02-24 03:52:32 +000017//
Chris Lattner289ba2a2004-05-23 21:20:19 +000018// 1. Moving loop invariant loads and calls out of loops. If we can determine
19// that a load or call inside of a loop never aliases anything stored to,
20// we can hoist it or sink it like any other instruction.
Chris Lattner45d67d62003-02-24 03:52:32 +000021// 2. Scalar Promotion of Memory - If there is a store instruction inside of
22// the loop, we try to move the store to happen AFTER the loop instead of
23// inside of the loop. This can only happen if a few conditions are true:
24// A. The pointer stored through is loop invariant
25// B. There are no stores or loads in the loop which _may_ alias the
26// pointer. There are no calls in the loop which mod/ref the pointer.
27// If these conditions are true, we can promote the loads and stores in the
28// loop of the pointer to use a temporary alloca'd variable. We then use
29// the mem2reg functionality to construct the appropriate SSA form for the
30// variable.
Chris Lattner6ec05f52002-05-10 22:44:58 +000031//
Chris Lattner6ec05f52002-05-10 22:44:58 +000032//===----------------------------------------------------------------------===//
33
34#include "llvm/Transforms/Scalar.h"
Chris Lattner289ba2a2004-05-23 21:20:19 +000035#include "llvm/DerivedTypes.h"
36#include "llvm/Instructions.h"
37#include "llvm/Target/TargetData.h"
Chris Lattner6ec05f52002-05-10 22:44:58 +000038#include "llvm/Analysis/LoopInfo.h"
Chris Lattnera51fa882002-08-22 21:39:55 +000039#include "llvm/Analysis/AliasAnalysis.h"
Chris Lattner0592bb72003-03-03 23:32:45 +000040#include "llvm/Analysis/AliasSetTracker.h"
Chris Lattner64437692002-09-29 21:46:09 +000041#include "llvm/Analysis/Dominators.h"
Chris Lattner45d67d62003-02-24 03:52:32 +000042#include "llvm/Support/CFG.h"
Chris Lattnerec2d34c2004-06-19 08:56:43 +000043#include "llvm/Support/StableBasicBlockNumbering.h"
Chris Lattner289ba2a2004-05-23 21:20:19 +000044#include "llvm/Transforms/Utils/PromoteMemToReg.h"
45#include "llvm/Transforms/Utils/Local.h"
Chris Lattner45d67d62003-02-24 03:52:32 +000046#include "Support/CommandLine.h"
Chris Lattner8abcd562003-08-01 22:15:03 +000047#include "Support/Debug.h"
48#include "Support/Statistic.h"
Chris Lattner6ec05f52002-05-10 22:44:58 +000049#include <algorithm>
Chris Lattnerc0517682003-12-09 17:18:00 +000050using namespace llvm;
Brian Gaeke960707c2003-11-11 22:41:34 +000051
Chris Lattner6ec05f52002-05-10 22:44:58 +000052namespace {
Chris Lattner17895702003-10-13 05:04:27 +000053 cl::opt<bool>
54 DisablePromotion("disable-licm-promotion", cl::Hidden,
55 cl::desc("Disable memory promotion in LICM pass"));
Chris Lattner45d67d62003-02-24 03:52:32 +000056
Chris Lattneraaaea512003-12-10 06:41:05 +000057 Statistic<> NumSunk("licm", "Number of instructions sunk out of loop");
Chris Lattnerbf3a0992002-10-01 22:38:41 +000058 Statistic<> NumHoisted("licm", "Number of instructions hoisted out of loop");
Chris Lattneraaaea512003-12-10 06:41:05 +000059 Statistic<> NumMovedLoads("licm", "Number of load insts hoisted or sunk");
Chris Lattner20cda262004-03-15 04:11:30 +000060 Statistic<> NumMovedCalls("licm", "Number of call insts hoisted or sunk");
Chris Lattner17895702003-10-13 05:04:27 +000061 Statistic<> NumPromoted("licm",
62 "Number of memory locations promoted to registers");
Chris Lattner718b2212002-09-26 16:38:03 +000063
Chris Lattner65c11932003-12-09 19:32:44 +000064 struct LICM : public FunctionPass {
Chris Lattner113f4f42002-06-25 16:13:24 +000065 virtual bool runOnFunction(Function &F);
Chris Lattner6ec05f52002-05-10 22:44:58 +000066
Chris Lattnerf64f2d32002-09-26 16:52:07 +000067 /// This transformation requires natural loop information & requires that
68 /// loop preheaders be inserted into the CFG...
69 ///
Chris Lattner6ec05f52002-05-10 22:44:58 +000070 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
Chris Lattner820d9712002-10-21 20:00:28 +000071 AU.setPreservesCFG();
Chris Lattner72272a72003-10-12 21:52:28 +000072 AU.addRequiredID(LoopSimplifyID);
Chris Lattnerf0ed55d2002-08-08 19:01:30 +000073 AU.addRequired<LoopInfo>();
Chris Lattner64437692002-09-29 21:46:09 +000074 AU.addRequired<DominatorTree>();
Chris Lattner0592bb72003-03-03 23:32:45 +000075 AU.addRequired<DominanceFrontier>(); // For scalar promotion (mem2reg)
Chris Lattnera51fa882002-08-22 21:39:55 +000076 AU.addRequired<AliasAnalysis>();
Chris Lattner6ec05f52002-05-10 22:44:58 +000077 }
78
79 private:
Chris Lattnerc0517682003-12-09 17:18:00 +000080 // Various analyses that we use...
Chris Lattner45d67d62003-02-24 03:52:32 +000081 AliasAnalysis *AA; // Current AliasAnalysis information
Chris Lattnerc0517682003-12-09 17:18:00 +000082 LoopInfo *LI; // Current LoopInfo
83 DominatorTree *DT; // Dominator Tree for the current Loop...
Chris Lattnera906bac2003-10-05 21:20:13 +000084 DominanceFrontier *DF; // Current Dominance Frontier
Chris Lattnerec2d34c2004-06-19 08:56:43 +000085 StableBasicBlockNumbering *BBNum; // Stable IDs for basic blocks
Chris Lattnerc0517682003-12-09 17:18:00 +000086
87 // State that is updated as we process loops
Chris Lattner45d67d62003-02-24 03:52:32 +000088 bool Changed; // Set to true when we change anything.
89 BasicBlock *Preheader; // The preheader block of the current loop...
90 Loop *CurLoop; // The current loop we are working on...
Chris Lattner0592bb72003-03-03 23:32:45 +000091 AliasSetTracker *CurAST; // AliasSet information for the current loop...
Chris Lattner6ec05f52002-05-10 22:44:58 +000092
Chris Lattnerf64f2d32002-09-26 16:52:07 +000093 /// visitLoop - Hoist expressions out of the specified loop...
94 ///
Chris Lattner0592bb72003-03-03 23:32:45 +000095 void visitLoop(Loop *L, AliasSetTracker &AST);
Chris Lattner6ec05f52002-05-10 22:44:58 +000096
Chris Lattner547192d62003-12-19 07:22:45 +000097 /// SinkRegion - Walk the specified region of the CFG (defined by all blocks
98 /// dominated by the specified block, and that are in the current loop) in
99 /// reverse depth first order w.r.t the DominatorTree. This allows us to
100 /// visit uses before definitions, allowing us to sink a loop body in one
101 /// pass without iteration.
102 ///
103 void SinkRegion(DominatorTree::Node *N);
104
Chris Lattner64437692002-09-29 21:46:09 +0000105 /// HoistRegion - Walk the specified region of the CFG (defined by all
106 /// blocks dominated by the specified block, and that are in the current
107 /// loop) in depth first order w.r.t the DominatorTree. This allows us to
Misha Brukman8b2bd4e2003-10-10 17:57:28 +0000108 /// visit definitions before uses, allowing us to hoist a loop body in one
Chris Lattner64437692002-09-29 21:46:09 +0000109 /// pass without iteration.
110 ///
111 void HoistRegion(DominatorTree::Node *N);
112
Chris Lattner05e86302002-09-29 22:26:07 +0000113 /// inSubLoop - Little predicate that returns true if the specified basic
114 /// block is in a subloop of the current one, not the current one itself.
Chris Lattnerf64f2d32002-09-26 16:52:07 +0000115 ///
Chris Lattner05e86302002-09-29 22:26:07 +0000116 bool inSubLoop(BasicBlock *BB) {
117 assert(CurLoop->contains(BB) && "Only valid if BB is IN the loop");
Chris Lattner59d2d7f2004-01-08 00:09:44 +0000118 for (Loop::iterator I = CurLoop->begin(), E = CurLoop->end(); I != E; ++I)
119 if ((*I)->contains(BB))
Chris Lattner05e86302002-09-29 22:26:07 +0000120 return true; // A subloop actually contains this block!
121 return false;
Chris Lattner6ec05f52002-05-10 22:44:58 +0000122 }
123
Chris Lattneraaaea512003-12-10 06:41:05 +0000124 /// isExitBlockDominatedByBlockInLoop - This method checks to see if the
125 /// specified exit block of the loop is dominated by the specified block
126 /// that is in the body of the loop. We use these constraints to
127 /// dramatically limit the amount of the dominator tree that needs to be
128 /// searched.
129 bool isExitBlockDominatedByBlockInLoop(BasicBlock *ExitBlock,
130 BasicBlock *BlockInLoop) const {
131 // If the block in the loop is the loop header, it must be dominated!
132 BasicBlock *LoopHeader = CurLoop->getHeader();
133 if (BlockInLoop == LoopHeader)
134 return true;
135
136 DominatorTree::Node *BlockInLoopNode = DT->getNode(BlockInLoop);
137 DominatorTree::Node *IDom = DT->getNode(ExitBlock);
138
139 // Because the exit block is not in the loop, we know we have to get _at
Chris Lattner289ba2a2004-05-23 21:20:19 +0000140 // least_ its immediate dominator.
Chris Lattneraaaea512003-12-10 06:41:05 +0000141 do {
142 // Get next Immediate Dominator.
143 IDom = IDom->getIDom();
144
145 // If we have got to the header of the loop, then the instructions block
146 // did not dominate the exit node, so we can't hoist it.
147 if (IDom->getBlock() == LoopHeader)
148 return false;
149
150 } while (IDom != BlockInLoopNode);
151
152 return true;
153 }
154
155 /// sink - When an instruction is found to only be used outside of the loop,
156 /// this function moves it to the exit blocks and patches up SSA form as
157 /// needed.
158 ///
159 void sink(Instruction &I);
160
Chris Lattnerf64f2d32002-09-26 16:52:07 +0000161 /// hoist - When an instruction is found to only use loop invariant operands
162 /// that is safe to hoist, this instruction is called to do the dirty work.
163 ///
Chris Lattner113f4f42002-06-25 16:13:24 +0000164 void hoist(Instruction &I);
Chris Lattner6ec05f52002-05-10 22:44:58 +0000165
Chris Lattneraaaea512003-12-10 06:41:05 +0000166 /// isSafeToExecuteUnconditionally - Only sink or hoist an instruction if it
167 /// is not a trapping instruction or if it is a trapping instruction and is
168 /// guaranteed to execute.
Tanya Lattner57c03df2003-08-05 18:45:46 +0000169 ///
Chris Lattneraaaea512003-12-10 06:41:05 +0000170 bool isSafeToExecuteUnconditionally(Instruction &I);
Tanya Lattner57c03df2003-08-05 18:45:46 +0000171
Chris Lattnerf64f2d32002-09-26 16:52:07 +0000172 /// pointerInvalidatedByLoop - Return true if the body of this loop may
173 /// store into the memory location pointed to by V.
174 ///
Chris Lattner45d67d62003-02-24 03:52:32 +0000175 bool pointerInvalidatedByLoop(Value *V) {
Chris Lattner0592bb72003-03-03 23:32:45 +0000176 // Check to see if any of the basic blocks in CurLoop invalidate *V.
177 return CurAST->getAliasSetForPointer(V, 0).isMod();
Chris Lattner45d67d62003-02-24 03:52:32 +0000178 }
Chris Lattnera51fa882002-08-22 21:39:55 +0000179
Chris Lattneraaaea512003-12-10 06:41:05 +0000180 bool canSinkOrHoistInst(Instruction &I);
181 bool isLoopInvariantInst(Instruction &I);
182 bool isNotUsedInLoop(Instruction &I);
Chris Lattner6ec05f52002-05-10 22:44:58 +0000183
Chris Lattner45d67d62003-02-24 03:52:32 +0000184 /// PromoteValuesInLoop - Look at the stores in the loop and promote as many
185 /// to scalars as we can.
186 ///
187 void PromoteValuesInLoop();
188
189 /// findPromotableValuesInLoop - Check the current loop for stores to
Misha Brukman9b8d3392003-09-11 15:32:37 +0000190 /// definite pointers, which are not loaded and stored through may aliases.
Chris Lattner45d67d62003-02-24 03:52:32 +0000191 /// If these are found, create an alloca for the value, add it to the
192 /// PromotedValues list, and keep track of the mapping from value to
193 /// alloca...
194 ///
195 void findPromotableValuesInLoop(
196 std::vector<std::pair<AllocaInst*, Value*> > &PromotedValues,
197 std::map<Value*, AllocaInst*> &Val2AlMap);
Chris Lattner6ec05f52002-05-10 22:44:58 +0000198 };
Chris Lattnerb28b6802002-07-23 18:06:35 +0000199
Chris Lattnerc8b70922002-07-26 21:12:46 +0000200 RegisterOpt<LICM> X("licm", "Loop Invariant Code Motion");
Chris Lattner6ec05f52002-05-10 22:44:58 +0000201}
202
Chris Lattnerc0517682003-12-09 17:18:00 +0000203FunctionPass *llvm::createLICMPass() { return new LICM(); }
Chris Lattner6ec05f52002-05-10 22:44:58 +0000204
Chris Lattnerf64f2d32002-09-26 16:52:07 +0000205/// runOnFunction - For LICM, this simply traverses the loop structure of the
206/// function, hoisting expressions out of loops if possible.
207///
Chris Lattnerec2d34c2004-06-19 08:56:43 +0000208bool LICM::runOnFunction(Function &F) {
Chris Lattner45d67d62003-02-24 03:52:32 +0000209 Changed = false;
Chris Lattner6ec05f52002-05-10 22:44:58 +0000210
Chris Lattner45d67d62003-02-24 03:52:32 +0000211 // Get our Loop and Alias Analysis information...
212 LI = &getAnalysis<LoopInfo>();
Chris Lattnera51fa882002-08-22 21:39:55 +0000213 AA = &getAnalysis<AliasAnalysis>();
Chris Lattnera906bac2003-10-05 21:20:13 +0000214 DF = &getAnalysis<DominanceFrontier>();
Tanya Lattnerdc3c9a82003-08-05 20:39:02 +0000215 DT = &getAnalysis<DominatorTree>();
Chris Lattnera51fa882002-08-22 21:39:55 +0000216
Chris Lattnerec2d34c2004-06-19 08:56:43 +0000217 // Get a stable numbering of basic blocks.
218 StableBasicBlockNumbering CurBBNum(&F);
219 BBNum = &CurBBNum;
220
Chris Lattner45d67d62003-02-24 03:52:32 +0000221 // Hoist expressions out of all of the top-level loops.
Chris Lattner59d2d7f2004-01-08 00:09:44 +0000222 for (LoopInfo::iterator I = LI->begin(), E = LI->end(); I != E; ++I) {
Chris Lattner0592bb72003-03-03 23:32:45 +0000223 AliasSetTracker AST(*AA);
Chris Lattner65c11932003-12-09 19:32:44 +0000224 visitLoop(*I, AST);
Chris Lattner45d67d62003-02-24 03:52:32 +0000225 }
Chris Lattner6ec05f52002-05-10 22:44:58 +0000226 return Changed;
227}
228
Chris Lattnerf64f2d32002-09-26 16:52:07 +0000229
230/// visitLoop - Hoist expressions out of the specified loop...
231///
Chris Lattner0592bb72003-03-03 23:32:45 +0000232void LICM::visitLoop(Loop *L, AliasSetTracker &AST) {
Chris Lattner6ec05f52002-05-10 22:44:58 +0000233 // Recurse through all subloops before we process this loop...
Chris Lattner59d2d7f2004-01-08 00:09:44 +0000234 for (Loop::iterator I = L->begin(), E = L->end(); I != E; ++I) {
Chris Lattner0592bb72003-03-03 23:32:45 +0000235 AliasSetTracker SubAST(*AA);
Chris Lattner65c11932003-12-09 19:32:44 +0000236 visitLoop(*I, SubAST);
Chris Lattner45d67d62003-02-24 03:52:32 +0000237
238 // Incorporate information about the subloops into this loop...
Chris Lattner0592bb72003-03-03 23:32:45 +0000239 AST.add(SubAST);
Chris Lattner45d67d62003-02-24 03:52:32 +0000240 }
Chris Lattner6ec05f52002-05-10 22:44:58 +0000241 CurLoop = L;
Chris Lattner0592bb72003-03-03 23:32:45 +0000242 CurAST = &AST;
Chris Lattner6ec05f52002-05-10 22:44:58 +0000243
Chris Lattnerd57f3f52002-09-26 19:40:25 +0000244 // Get the preheader block to move instructions into...
245 Preheader = L->getLoopPreheader();
246 assert(Preheader&&"Preheader insertion pass guarantees we have a preheader!");
247
Chris Lattner45d67d62003-02-24 03:52:32 +0000248 // Loop over the body of this loop, looking for calls, invokes, and stores.
Chris Lattner0592bb72003-03-03 23:32:45 +0000249 // Because subloops have already been incorporated into AST, we skip blocks in
Chris Lattner45d67d62003-02-24 03:52:32 +0000250 // subloops.
251 //
Chris Lattneraaaea512003-12-10 06:41:05 +0000252 for (std::vector<BasicBlock*>::const_iterator I = L->getBlocks().begin(),
253 E = L->getBlocks().end(); I != E; ++I)
Chris Lattner45d67d62003-02-24 03:52:32 +0000254 if (LI->getLoopFor(*I) == L) // Ignore blocks in subloops...
Chris Lattner0592bb72003-03-03 23:32:45 +0000255 AST.add(**I); // Incorporate the specified basic block
Chris Lattner45d67d62003-02-24 03:52:32 +0000256
Chris Lattner6ec05f52002-05-10 22:44:58 +0000257 // We want to visit all of the instructions in this loop... that are not parts
258 // of our subloops (they have already had their invariants hoisted out of
259 // their loop, into this loop, so there is no need to process the BODIES of
260 // the subloops).
261 //
Chris Lattner64437692002-09-29 21:46:09 +0000262 // Traverse the body of the loop in depth first order on the dominator tree so
263 // that we are guaranteed to see definitions before we see uses. This allows
Chris Lattner547192d62003-12-19 07:22:45 +0000264 // us to sink instructions in one pass, without iteration. AFter sinking
265 // instructions, we perform another pass to hoist them out of the loop.
Chris Lattner64437692002-09-29 21:46:09 +0000266 //
Chris Lattner547192d62003-12-19 07:22:45 +0000267 SinkRegion(DT->getNode(L->getHeader()));
Tanya Lattnerdc3c9a82003-08-05 20:39:02 +0000268 HoistRegion(DT->getNode(L->getHeader()));
Chris Lattner6ec05f52002-05-10 22:44:58 +0000269
Chris Lattner45d67d62003-02-24 03:52:32 +0000270 // Now that all loop invariants have been removed from the loop, promote any
271 // memory references to scalars that we can...
272 if (!DisablePromotion)
273 PromoteValuesInLoop();
274
Chris Lattner6ec05f52002-05-10 22:44:58 +0000275 // Clear out loops state information for the next iteration
276 CurLoop = 0;
Chris Lattnerd57f3f52002-09-26 19:40:25 +0000277 Preheader = 0;
Chris Lattner6ec05f52002-05-10 22:44:58 +0000278}
279
Chris Lattner547192d62003-12-19 07:22:45 +0000280/// SinkRegion - Walk the specified region of the CFG (defined by all blocks
281/// dominated by the specified block, and that are in the current loop) in
282/// reverse depth first order w.r.t the DominatorTree. This allows us to visit
283/// uses before definitions, allowing us to sink a loop body in one pass without
284/// iteration.
285///
286void LICM::SinkRegion(DominatorTree::Node *N) {
287 assert(N != 0 && "Null dominator tree node?");
288 BasicBlock *BB = N->getBlock();
289
290 // If this subregion is not in the top level loop at all, exit.
291 if (!CurLoop->contains(BB)) return;
292
293 // We are processing blocks in reverse dfo, so process children first...
294 const std::vector<DominatorTree::Node*> &Children = N->getChildren();
295 for (unsigned i = 0, e = Children.size(); i != e; ++i)
296 SinkRegion(Children[i]);
297
298 // Only need to process the contents of this block if it is not part of a
299 // subloop (which would already have been processed).
300 if (inSubLoop(BB)) return;
301
Chris Lattner91846012003-12-19 08:18:16 +0000302 for (BasicBlock::iterator II = BB->end(); II != BB->begin(); ) {
303 Instruction &I = *--II;
Chris Lattner547192d62003-12-19 07:22:45 +0000304
305 // Check to see if we can sink this instruction to the exit blocks
306 // of the loop. We can do this if the all users of the instruction are
307 // outside of the loop. In this case, it doesn't even matter if the
308 // operands of the instruction are loop invariant.
309 //
Chris Lattner91846012003-12-19 08:18:16 +0000310 if (canSinkOrHoistInst(I) && isNotUsedInLoop(I)) {
311 ++II;
Chris Lattner547192d62003-12-19 07:22:45 +0000312 sink(I);
Chris Lattner91846012003-12-19 08:18:16 +0000313 }
Chris Lattner547192d62003-12-19 07:22:45 +0000314 }
315}
316
317
Chris Lattner64437692002-09-29 21:46:09 +0000318/// HoistRegion - Walk the specified region of the CFG (defined by all blocks
319/// dominated by the specified block, and that are in the current loop) in depth
Misha Brukman8b2bd4e2003-10-10 17:57:28 +0000320/// first order w.r.t the DominatorTree. This allows us to visit definitions
Chris Lattner64437692002-09-29 21:46:09 +0000321/// before uses, allowing us to hoist a loop body in one pass without iteration.
322///
323void LICM::HoistRegion(DominatorTree::Node *N) {
324 assert(N != 0 && "Null dominator tree node?");
Chris Lattner65c11932003-12-09 19:32:44 +0000325 BasicBlock *BB = N->getBlock();
Chris Lattner64437692002-09-29 21:46:09 +0000326
Chris Lattner05e86302002-09-29 22:26:07 +0000327 // If this subregion is not in the top level loop at all, exit.
Chris Lattner65c11932003-12-09 19:32:44 +0000328 if (!CurLoop->contains(BB)) return;
Chris Lattner64437692002-09-29 21:46:09 +0000329
Chris Lattneraaaea512003-12-10 06:41:05 +0000330 // Only need to process the contents of this block if it is not part of a
331 // subloop (which would already have been processed).
Chris Lattner65c11932003-12-09 19:32:44 +0000332 if (!inSubLoop(BB))
Chris Lattneraaaea512003-12-10 06:41:05 +0000333 for (BasicBlock::iterator II = BB->begin(), E = BB->end(); II != E; ) {
334 Instruction &I = *II++;
Chris Lattner547192d62003-12-19 07:22:45 +0000335
336 // Try hoisting the instruction out to the preheader. We can only do this
337 // if all of the operands of the instruction are loop invariant and if it
338 // is safe to hoist the instruction.
339 //
340 if (isLoopInvariantInst(I) && canSinkOrHoistInst(I) &&
341 isSafeToExecuteUnconditionally(I))
Chris Lattneraaaea512003-12-10 06:41:05 +0000342 hoist(I);
343 }
Chris Lattner64437692002-09-29 21:46:09 +0000344
345 const std::vector<DominatorTree::Node*> &Children = N->getChildren();
Chris Lattnerec2d34c2004-06-19 08:56:43 +0000346 std::vector<std::pair<unsigned, DominatorTree::Node*> > ChildrenWithIDs;
347 ChildrenWithIDs.reserve(Children.size());
348 for (unsigned i = 0, e = Children.size(); i != e; ++i) {
349 unsigned ID = BBNum->getNumber(Children[i]->getBlock());
350 ChildrenWithIDs.push_back(std::make_pair(ID, Children[i]));
351 }
352
353 std::sort(ChildrenWithIDs.begin(), ChildrenWithIDs.end());
Chris Lattner64437692002-09-29 21:46:09 +0000354 for (unsigned i = 0, e = Children.size(); i != e; ++i)
Chris Lattnerec2d34c2004-06-19 08:56:43 +0000355 HoistRegion(ChildrenWithIDs[i].second);
Chris Lattner64437692002-09-29 21:46:09 +0000356}
357
Chris Lattneraaaea512003-12-10 06:41:05 +0000358/// canSinkOrHoistInst - Return true if the hoister and sinker can handle this
359/// instruction.
360///
361bool LICM::canSinkOrHoistInst(Instruction &I) {
Chris Lattner65c11932003-12-09 19:32:44 +0000362 // Loads have extra constraints we have to verify before we can hoist them.
363 if (LoadInst *LI = dyn_cast<LoadInst>(&I)) {
364 if (LI->isVolatile())
365 return false; // Don't hoist volatile loads!
366
367 // Don't hoist loads which have may-aliased stores in loop.
Chris Lattneraaaea512003-12-10 06:41:05 +0000368 return !pointerInvalidatedByLoop(LI->getOperand(0));
Chris Lattner20cda262004-03-15 04:11:30 +0000369 } else if (CallInst *CI = dyn_cast<CallInst>(&I)) {
370 // Handle obvious cases efficiently.
371 if (Function *Callee = CI->getCalledFunction()) {
372 if (AA->doesNotAccessMemory(Callee))
373 return true;
374 else if (AA->onlyReadsMemory(Callee)) {
375 // If this call only reads from memory and there are no writes to memory
376 // in the loop, we can hoist or sink the call as appropriate.
377 bool FoundMod = false;
378 for (AliasSetTracker::iterator I = CurAST->begin(), E = CurAST->end();
379 I != E; ++I) {
380 AliasSet &AS = *I;
381 if (!AS.isForwardingAliasSet() && AS.isMod()) {
382 FoundMod = true;
383 break;
384 }
385 }
386 if (!FoundMod) return true;
387 }
388 }
389
390 // FIXME: This should use mod/ref information to see if we can hoist or sink
391 // the call.
392
393 return false;
Chris Lattner65c11932003-12-09 19:32:44 +0000394 }
395
Chris Lattneraaaea512003-12-10 06:41:05 +0000396 return isa<BinaryOperator>(I) || isa<ShiftInst>(I) || isa<CastInst>(I) ||
Chris Lattner20cda262004-03-15 04:11:30 +0000397 isa<SelectInst>(I) ||
Chris Lattneraaaea512003-12-10 06:41:05 +0000398 isa<GetElementPtrInst>(I) || isa<VANextInst>(I) || isa<VAArgInst>(I);
399}
400
401/// isNotUsedInLoop - Return true if the only users of this instruction are
402/// outside of the loop. If this is true, we can sink the instruction to the
403/// exit blocks of the loop.
404///
405bool LICM::isNotUsedInLoop(Instruction &I) {
Chris Lattner34399dd2003-12-11 22:23:32 +0000406 for (Value::use_iterator UI = I.use_begin(), E = I.use_end(); UI != E; ++UI) {
407 Instruction *User = cast<Instruction>(*UI);
408 if (PHINode *PN = dyn_cast<PHINode>(User)) {
409 // PHI node uses occur in predecessor blocks!
410 for (unsigned i = 0, e = PN->getNumIncomingValues(); i != e; ++i)
411 if (PN->getIncomingValue(i) == &I)
412 if (CurLoop->contains(PN->getIncomingBlock(i)))
413 return false;
414 } else if (CurLoop->contains(User->getParent())) {
Chris Lattneraaaea512003-12-10 06:41:05 +0000415 return false;
Chris Lattner34399dd2003-12-11 22:23:32 +0000416 }
417 }
Chris Lattneraaaea512003-12-10 06:41:05 +0000418 return true;
419}
420
421
422/// isLoopInvariantInst - Return true if all operands of this instruction are
423/// loop invariant. We also filter out non-hoistable instructions here just for
424/// efficiency.
425///
426bool LICM::isLoopInvariantInst(Instruction &I) {
427 // The instruction is loop invariant if all of its operands are loop-invariant
428 for (unsigned i = 0, e = I.getNumOperands(); i != e; ++i)
Chris Lattnerfc44a252004-04-18 22:46:08 +0000429 if (!CurLoop->isLoopInvariant(I.getOperand(i)))
Chris Lattneraaaea512003-12-10 06:41:05 +0000430 return false;
431
Chris Lattner65c11932003-12-09 19:32:44 +0000432 // If we got this far, the instruction is loop invariant!
433 return true;
434}
435
Chris Lattneraaaea512003-12-10 06:41:05 +0000436/// sink - When an instruction is found to only be used outside of the loop,
Chris Lattner91846012003-12-19 08:18:16 +0000437/// this function moves it to the exit blocks and patches up SSA form as needed.
438/// This method is guaranteed to remove the original instruction from its
439/// position, and may either delete it or move it to outside of the loop.
Chris Lattneraaaea512003-12-10 06:41:05 +0000440///
441void LICM::sink(Instruction &I) {
442 DEBUG(std::cerr << "LICM sinking instruction: " << I);
443
Chris Lattner35eaa552004-04-18 22:15:13 +0000444 std::vector<BasicBlock*> ExitBlocks;
445 CurLoop->getExitBlocks(ExitBlocks);
Chris Lattner55c21132003-12-10 20:43:29 +0000446
447 if (isa<LoadInst>(I)) ++NumMovedLoads;
Chris Lattner20cda262004-03-15 04:11:30 +0000448 else if (isa<CallInst>(I)) ++NumMovedCalls;
Chris Lattner55c21132003-12-10 20:43:29 +0000449 ++NumSunk;
450 Changed = true;
451
Chris Lattneraaaea512003-12-10 06:41:05 +0000452 // The case where there is only a single exit node of this loop is common
453 // enough that we handle it as a special (more efficient) case. It is more
454 // efficient to handle because there are no PHI nodes that need to be placed.
455 if (ExitBlocks.size() == 1) {
456 if (!isExitBlockDominatedByBlockInLoop(ExitBlocks[0], I.getParent())) {
457 // Instruction is not used, just delete it.
Chris Lattner289ba2a2004-05-23 21:20:19 +0000458 CurAST->deleteValue(&I);
Chris Lattneraaaea512003-12-10 06:41:05 +0000459 I.getParent()->getInstList().erase(&I);
460 } else {
461 // Move the instruction to the start of the exit block, after any PHI
462 // nodes in it.
463 I.getParent()->getInstList().remove(&I);
464
465 BasicBlock::iterator InsertPt = ExitBlocks[0]->begin();
466 while (isa<PHINode>(InsertPt)) ++InsertPt;
467 ExitBlocks[0]->getInstList().insert(InsertPt, &I);
468 }
469 } else if (ExitBlocks.size() == 0) {
470 // The instruction is actually dead if there ARE NO exit blocks.
Chris Lattner289ba2a2004-05-23 21:20:19 +0000471 CurAST->deleteValue(&I);
Chris Lattneraaaea512003-12-10 06:41:05 +0000472 I.getParent()->getInstList().erase(&I);
Chris Lattneraaaea512003-12-10 06:41:05 +0000473 } else {
474 // Otherwise, if we have multiple exits, use the PromoteMem2Reg function to
475 // do all of the hard work of inserting PHI nodes as necessary. We convert
476 // the value into a stack object to get it to do this.
477
478 // Firstly, we create a stack object to hold the value...
479 AllocaInst *AI = new AllocaInst(I.getType(), 0, I.getName(),
480 I.getParent()->getParent()->front().begin());
481
482 // Secondly, insert load instructions for each use of the instruction
483 // outside of the loop.
484 while (!I.use_empty()) {
485 Instruction *U = cast<Instruction>(I.use_back());
486
487 // If the user is a PHI Node, we actually have to insert load instructions
488 // in all predecessor blocks, not in the PHI block itself!
489 if (PHINode *UPN = dyn_cast<PHINode>(U)) {
490 // Only insert into each predecessor once, so that we don't have
491 // different incoming values from the same block!
492 std::map<BasicBlock*, Value*> InsertedBlocks;
493 for (unsigned i = 0, e = UPN->getNumIncomingValues(); i != e; ++i)
494 if (UPN->getIncomingValue(i) == &I) {
495 BasicBlock *Pred = UPN->getIncomingBlock(i);
496 Value *&PredVal = InsertedBlocks[Pred];
497 if (!PredVal) {
498 // Insert a new load instruction right before the terminator in
499 // the predecessor block.
500 PredVal = new LoadInst(AI, "", Pred->getTerminator());
501 }
502
503 UPN->setIncomingValue(i, PredVal);
504 }
505
506 } else {
507 LoadInst *L = new LoadInst(AI, "", U);
508 U->replaceUsesOfWith(&I, L);
509 }
510 }
511
512 // Thirdly, insert a copy of the instruction in each exit block of the loop
513 // that is dominated by the instruction, storing the result into the memory
514 // location. Be careful not to insert the instruction into any particular
515 // basic block more than once.
516 std::set<BasicBlock*> InsertedBlocks;
517 BasicBlock *InstOrigBB = I.getParent();
518
519 for (unsigned i = 0, e = ExitBlocks.size(); i != e; ++i) {
520 BasicBlock *ExitBlock = ExitBlocks[i];
521
522 if (isExitBlockDominatedByBlockInLoop(ExitBlock, InstOrigBB)) {
Chris Lattneraaaea512003-12-10 06:41:05 +0000523 // If we haven't already processed this exit block, do so now.
Chris Lattner63643142003-12-10 16:58:24 +0000524 if (InsertedBlocks.insert(ExitBlock).second) {
Chris Lattneraaaea512003-12-10 06:41:05 +0000525 // Insert the code after the last PHI node...
526 BasicBlock::iterator InsertPt = ExitBlock->begin();
527 while (isa<PHINode>(InsertPt)) ++InsertPt;
528
529 // If this is the first exit block processed, just move the original
530 // instruction, otherwise clone the original instruction and insert
531 // the copy.
532 Instruction *New;
Chris Lattner6281fd32003-12-10 22:35:56 +0000533 if (InsertedBlocks.size() == 1) {
Chris Lattneraaaea512003-12-10 06:41:05 +0000534 I.getParent()->getInstList().remove(&I);
535 ExitBlock->getInstList().insert(InsertPt, &I);
536 New = &I;
537 } else {
538 New = I.clone();
539 New->setName(I.getName()+".le");
540 ExitBlock->getInstList().insert(InsertPt, New);
541 }
542
543 // Now that we have inserted the instruction, store it into the alloca
544 new StoreInst(New, AI, InsertPt);
Chris Lattneraaaea512003-12-10 06:41:05 +0000545 }
546 }
547 }
Chris Lattner91846012003-12-19 08:18:16 +0000548
549 // If the instruction doesn't dominate any exit blocks, it must be dead.
550 if (InsertedBlocks.empty()) {
Chris Lattner289ba2a2004-05-23 21:20:19 +0000551 CurAST->deleteValue(&I);
Chris Lattner91846012003-12-19 08:18:16 +0000552 I.getParent()->getInstList().erase(&I);
553 }
Chris Lattneraaaea512003-12-10 06:41:05 +0000554
555 // Finally, promote the fine value to SSA form.
556 std::vector<AllocaInst*> Allocas;
557 Allocas.push_back(AI);
558 PromoteMemToReg(Allocas, *DT, *DF, AA->getTargetData());
559 }
Chris Lattneraaaea512003-12-10 06:41:05 +0000560}
Chris Lattner64437692002-09-29 21:46:09 +0000561
Chris Lattnerf64f2d32002-09-26 16:52:07 +0000562/// hoist - When an instruction is found to only use loop invariant operands
563/// that is safe to hoist, this instruction is called to do the dirty work.
564///
Chris Lattneraaaea512003-12-10 06:41:05 +0000565void LICM::hoist(Instruction &I) {
Brian Gaeke661963c2004-06-17 07:26:52 +0000566 DEBUG(std::cerr << "LICM hoisting to " << Preheader->getName()
Chris Lattner289ba2a2004-05-23 21:20:19 +0000567 << ": " << I);
Chris Lattner65c11932003-12-09 19:32:44 +0000568
Chris Lattnerd57f3f52002-09-26 19:40:25 +0000569 // Remove the instruction from its current basic block... but don't delete the
570 // instruction.
Chris Lattneraaaea512003-12-10 06:41:05 +0000571 I.getParent()->getInstList().remove(&I);
Chris Lattner6ec05f52002-05-10 22:44:58 +0000572
Chris Lattner718b2212002-09-26 16:38:03 +0000573 // Insert the new node in Preheader, before the terminator.
Chris Lattneraaaea512003-12-10 06:41:05 +0000574 Preheader->getInstList().insert(Preheader->getTerminator(), &I);
Chris Lattner718b2212002-09-26 16:38:03 +0000575
Chris Lattneraaaea512003-12-10 06:41:05 +0000576 if (isa<LoadInst>(I)) ++NumMovedLoads;
Chris Lattner20cda262004-03-15 04:11:30 +0000577 else if (isa<CallInst>(I)) ++NumMovedCalls;
Chris Lattner718b2212002-09-26 16:38:03 +0000578 ++NumHoisted;
Chris Lattner6ec05f52002-05-10 22:44:58 +0000579 Changed = true;
580}
581
Chris Lattneraaaea512003-12-10 06:41:05 +0000582/// isSafeToExecuteUnconditionally - Only sink or hoist an instruction if it is
583/// not a trapping instruction or if it is a trapping instruction and is
584/// guaranteed to execute.
Tanya Lattner57c03df2003-08-05 18:45:46 +0000585///
Chris Lattneraaaea512003-12-10 06:41:05 +0000586bool LICM::isSafeToExecuteUnconditionally(Instruction &Inst) {
Chris Lattnerc0517682003-12-09 17:18:00 +0000587 // If it is not a trapping instruction, it is always safe to hoist.
588 if (!Inst.isTrapping()) return true;
589
590 // Otherwise we have to check to make sure that the instruction dominates all
591 // of the exit blocks. If it doesn't, then there is a path out of the loop
592 // which does not execute this instruction, so we can't hoist it.
Tanya Lattner57c03df2003-08-05 18:45:46 +0000593
Chris Lattnerc0517682003-12-09 17:18:00 +0000594 // If the instruction is in the header block for the loop (which is very
595 // common), it is always guaranteed to dominate the exit blocks. Since this
596 // is a common case, and can save some work, check it now.
Chris Lattneraaaea512003-12-10 06:41:05 +0000597 if (Inst.getParent() == CurLoop->getHeader())
Chris Lattnerc0517682003-12-09 17:18:00 +0000598 return true;
Tanya Lattner57c03df2003-08-05 18:45:46 +0000599
Chris Lattnerc0517682003-12-09 17:18:00 +0000600 // Get the exit blocks for the current loop.
Chris Lattner35eaa552004-04-18 22:15:13 +0000601 std::vector<BasicBlock*> ExitBlocks;
602 CurLoop->getExitBlocks(ExitBlocks);
Chris Lattnerc0517682003-12-09 17:18:00 +0000603
604 // For each exit block, get the DT node and walk up the DT until the
605 // instruction's basic block is found or we exit the loop.
Chris Lattneraaaea512003-12-10 06:41:05 +0000606 for (unsigned i = 0, e = ExitBlocks.size(); i != e; ++i)
607 if (!isExitBlockDominatedByBlockInLoop(ExitBlocks[i], Inst.getParent()))
608 return false;
Tanya Lattnerdc3c9a82003-08-05 20:39:02 +0000609
Tanya Lattner57c03df2003-08-05 18:45:46 +0000610 return true;
611}
612
Chris Lattnerd771fdf2002-09-26 16:19:31 +0000613
Chris Lattner45d67d62003-02-24 03:52:32 +0000614/// PromoteValuesInLoop - Try to promote memory values to scalars by sinking
615/// stores out of the loop and moving loads to before the loop. We do this by
616/// looping over the stores in the loop, looking for stores to Must pointers
617/// which are loop invariant. We promote these memory locations to use allocas
618/// instead. These allocas can easily be raised to register values by the
619/// PromoteMem2Reg functionality.
620///
621void LICM::PromoteValuesInLoop() {
622 // PromotedValues - List of values that are promoted out of the loop. Each
Chris Lattner216c7b82003-09-10 05:29:43 +0000623 // value has an alloca instruction for it, and a canonical version of the
Chris Lattner45d67d62003-02-24 03:52:32 +0000624 // pointer.
625 std::vector<std::pair<AllocaInst*, Value*> > PromotedValues;
626 std::map<Value*, AllocaInst*> ValueToAllocaMap; // Map of ptr to alloca
627
628 findPromotableValuesInLoop(PromotedValues, ValueToAllocaMap);
629 if (ValueToAllocaMap.empty()) return; // If there are values to promote...
630
631 Changed = true;
632 NumPromoted += PromotedValues.size();
633
634 // Emit a copy from the value into the alloca'd value in the loop preheader
635 TerminatorInst *LoopPredInst = Preheader->getTerminator();
636 for (unsigned i = 0, e = PromotedValues.size(); i != e; ++i) {
637 // Load from the memory we are promoting...
638 LoadInst *LI = new LoadInst(PromotedValues[i].second,
639 PromotedValues[i].second->getName()+".promoted",
640 LoopPredInst);
641 // Store into the temporary alloca...
642 new StoreInst(LI, PromotedValues[i].first, LoopPredInst);
643 }
644
645 // Scan the basic blocks in the loop, replacing uses of our pointers with
Chris Lattneredda1af2003-12-10 15:56:24 +0000646 // uses of the allocas in question.
Chris Lattner45d67d62003-02-24 03:52:32 +0000647 //
648 const std::vector<BasicBlock*> &LoopBBs = CurLoop->getBlocks();
649 for (std::vector<BasicBlock*>::const_iterator I = LoopBBs.begin(),
650 E = LoopBBs.end(); I != E; ++I) {
651 // Rewrite all loads and stores in the block of the pointer...
652 for (BasicBlock::iterator II = (*I)->begin(), E = (*I)->end();
653 II != E; ++II) {
Chris Lattner889f6202003-04-23 16:37:45 +0000654 if (LoadInst *L = dyn_cast<LoadInst>(II)) {
Chris Lattner45d67d62003-02-24 03:52:32 +0000655 std::map<Value*, AllocaInst*>::iterator
656 I = ValueToAllocaMap.find(L->getOperand(0));
657 if (I != ValueToAllocaMap.end())
658 L->setOperand(0, I->second); // Rewrite load instruction...
Chris Lattner889f6202003-04-23 16:37:45 +0000659 } else if (StoreInst *S = dyn_cast<StoreInst>(II)) {
Chris Lattner45d67d62003-02-24 03:52:32 +0000660 std::map<Value*, AllocaInst*>::iterator
661 I = ValueToAllocaMap.find(S->getOperand(1));
662 if (I != ValueToAllocaMap.end())
663 S->setOperand(1, I->second); // Rewrite store instruction...
664 }
665 }
Chris Lattner45d67d62003-02-24 03:52:32 +0000666 }
667
Chris Lattneredda1af2003-12-10 15:56:24 +0000668 // Now that the body of the loop uses the allocas instead of the original
669 // memory locations, insert code to copy the alloca value back into the
670 // original memory location on all exits from the loop. Note that we only
671 // want to insert one copy of the code in each exit block, though the loop may
672 // exit to the same block more than once.
673 //
674 std::set<BasicBlock*> ProcessedBlocks;
675
Chris Lattner35eaa552004-04-18 22:15:13 +0000676 std::vector<BasicBlock*> ExitBlocks;
677 CurLoop->getExitBlocks(ExitBlocks);
Chris Lattneredda1af2003-12-10 15:56:24 +0000678 for (unsigned i = 0, e = ExitBlocks.size(); i != e; ++i)
Chris Lattner48b4b852003-12-10 16:57:24 +0000679 if (ProcessedBlocks.insert(ExitBlocks[i]).second) {
Chris Lattneredda1af2003-12-10 15:56:24 +0000680 // Copy all of the allocas into their memory locations...
681 BasicBlock::iterator BI = ExitBlocks[i]->begin();
682 while (isa<PHINode>(*BI))
683 ++BI; // Skip over all of the phi nodes in the block...
684 Instruction *InsertPos = BI;
685 for (unsigned i = 0, e = PromotedValues.size(); i != e; ++i) {
686 // Load from the alloca...
687 LoadInst *LI = new LoadInst(PromotedValues[i].first, "", InsertPos);
688 // Store into the memory we promoted...
689 new StoreInst(LI, PromotedValues[i].second, InsertPos);
690 }
691 }
692
Chris Lattner45d67d62003-02-24 03:52:32 +0000693 // Now that we have done the deed, use the mem2reg functionality to promote
694 // all of the new allocas we just created into real SSA registers...
695 //
696 std::vector<AllocaInst*> PromotedAllocas;
697 PromotedAllocas.reserve(PromotedValues.size());
698 for (unsigned i = 0, e = PromotedValues.size(); i != e; ++i)
699 PromotedAllocas.push_back(PromotedValues[i].first);
Chris Lattnera906bac2003-10-05 21:20:13 +0000700 PromoteMemToReg(PromotedAllocas, *DT, *DF, AA->getTargetData());
Chris Lattner45d67d62003-02-24 03:52:32 +0000701}
702
Misha Brukman9b8d3392003-09-11 15:32:37 +0000703/// findPromotableValuesInLoop - Check the current loop for stores to definite
Chris Lattner45d67d62003-02-24 03:52:32 +0000704/// pointers, which are not loaded and stored through may aliases. If these are
705/// found, create an alloca for the value, add it to the PromotedValues list,
706/// and keep track of the mapping from value to alloca...
707///
708void LICM::findPromotableValuesInLoop(
709 std::vector<std::pair<AllocaInst*, Value*> > &PromotedValues,
710 std::map<Value*, AllocaInst*> &ValueToAllocaMap) {
711 Instruction *FnStart = CurLoop->getHeader()->getParent()->begin()->begin();
712
Chris Lattner0592bb72003-03-03 23:32:45 +0000713 // Loop over all of the alias sets in the tracker object...
714 for (AliasSetTracker::iterator I = CurAST->begin(), E = CurAST->end();
715 I != E; ++I) {
716 AliasSet &AS = *I;
717 // We can promote this alias set if it has a store, if it is a "Must" alias
Chris Lattner20cda262004-03-15 04:11:30 +0000718 // set, if the pointer is loop invariant, if if we are not eliminating any
719 // volatile loads or stores.
Chris Lattner0592bb72003-03-03 23:32:45 +0000720 if (!AS.isForwardingAliasSet() && AS.isMod() && AS.isMustAlias() &&
Chris Lattnerfc44a252004-04-18 22:46:08 +0000721 !AS.isVolatile() && CurLoop->isLoopInvariant(AS.begin()->first)) {
Chris Lattner0592bb72003-03-03 23:32:45 +0000722 assert(AS.begin() != AS.end() &&
723 "Must alias set should have at least one pointer element in it!");
724 Value *V = AS.begin()->first;
Chris Lattner45d67d62003-02-24 03:52:32 +0000725
Chris Lattner0592bb72003-03-03 23:32:45 +0000726 // Check that all of the pointers in the alias set have the same type. We
727 // cannot (yet) promote a memory location that is loaded and stored in
728 // different sizes.
729 bool PointerOk = true;
730 for (AliasSet::iterator I = AS.begin(), E = AS.end(); I != E; ++I)
731 if (V->getType() != I->first->getType()) {
732 PointerOk = false;
733 break;
Chris Lattner45d67d62003-02-24 03:52:32 +0000734 }
Chris Lattner0592bb72003-03-03 23:32:45 +0000735
736 if (PointerOk) {
737 const Type *Ty = cast<PointerType>(V->getType())->getElementType();
738 AllocaInst *AI = new AllocaInst(Ty, 0, V->getName()+".tmp", FnStart);
739 PromotedValues.push_back(std::make_pair(AI, V));
740
741 for (AliasSet::iterator I = AS.begin(), E = AS.end(); I != E; ++I)
742 ValueToAllocaMap.insert(std::make_pair(I->first, AI));
743
744 DEBUG(std::cerr << "LICM: Promoting value: " << *V << "\n");
Chris Lattner45d67d62003-02-24 03:52:32 +0000745 }
746 }
747 }
Chris Lattnera51fa882002-08-22 21:39:55 +0000748}