blob: fd3daa5bef408d1146e5171222da9084b2b65a90 [file] [log] [blame]
Chris Lattner138a1242001-06-27 23:38:11 +00001//===- SCCP.cpp - Sparse Conditional Constant Propogation -----------------===//
2//
3// This file implements sparse conditional constant propogation and merging:
4//
5// Specifically, this:
6// * Assumes values are constant unless proven otherwise
7// * Assumes BasicBlocks are dead unless proven otherwise
8// * Proves values to be constant, and replaces them with constants
9// . Proves conditional branches constant, and unconditionalizes them
10// * Folds multiple identical constants in the constant pool together
11//
12// Notice that:
13// * This pass has a habit of making definitions be dead. It is a good idea
14// to to run a DCE pass sometime after running this pass.
15//
16//===----------------------------------------------------------------------===//
17
Chris Lattner59b6b8e2002-01-21 23:17:48 +000018#include "llvm/Transforms/Scalar/ConstantProp.h"
Chris Lattner968ddc92002-04-08 20:18:09 +000019#include "llvm/ConstantHandling.h"
Chris Lattner79df7c02002-03-26 18:01:55 +000020#include "llvm/Function.h"
Chris Lattner138a1242001-06-27 23:38:11 +000021#include "llvm/BasicBlock.h"
Chris Lattnere9bb2df2001-12-03 22:26:30 +000022#include "llvm/ConstantVals.h"
Chris Lattner7061dc52001-12-03 18:02:31 +000023#include "llvm/iPHINode.h"
Chris Lattner3b7bfdb2001-07-14 06:11:51 +000024#include "llvm/iMemory.h"
Chris Lattner138a1242001-06-27 23:38:11 +000025#include "llvm/iTerminators.h"
Chris Lattner7061dc52001-12-03 18:02:31 +000026#include "llvm/iOther.h"
Chris Lattnerbd0ef772002-02-26 21:46:54 +000027#include "llvm/Pass.h"
Chris Lattner2a632552002-04-18 15:13:15 +000028#include "llvm/Support/InstVisitor.h"
Chris Lattnercee8f9a2001-11-27 00:03:19 +000029#include "Support/STLExtras.h"
Chris Lattner138a1242001-06-27 23:38:11 +000030#include <algorithm>
31#include <map>
32#include <set>
Chris Lattner697954c2002-01-20 22:54:45 +000033#include <iostream>
34using std::cerr;
Chris Lattner138a1242001-06-27 23:38:11 +000035
Chris Lattner138a1242001-06-27 23:38:11 +000036// InstVal class - This class represents the different lattice values that an
37// instruction may occupy. It is a simple class with value semantics. The
38// potential constant value that is pointed to is owned by the constant pool
39// for the method being optimized.
40//
41class InstVal {
42 enum {
Chris Lattnere9bb2df2001-12-03 22:26:30 +000043 undefined, // This instruction has no known value
44 constant, // This instruction has a constant value
Chris Lattner138a1242001-06-27 23:38:11 +000045 // Range, // This instruction is known to fall within a range
Chris Lattnere9bb2df2001-12-03 22:26:30 +000046 overdefined // This instruction has an unknown value
47 } LatticeValue; // The current lattice position
48 Constant *ConstantVal; // If Constant value, the current value
Chris Lattner138a1242001-06-27 23:38:11 +000049public:
Chris Lattnere9bb2df2001-12-03 22:26:30 +000050 inline InstVal() : LatticeValue(undefined), ConstantVal(0) {}
Chris Lattner138a1242001-06-27 23:38:11 +000051
52 // markOverdefined - Return true if this is a new status to be in...
53 inline bool markOverdefined() {
Chris Lattnere9bb2df2001-12-03 22:26:30 +000054 if (LatticeValue != overdefined) {
55 LatticeValue = overdefined;
Chris Lattner138a1242001-06-27 23:38:11 +000056 return true;
57 }
58 return false;
59 }
60
61 // markConstant - Return true if this is a new status for us...
Chris Lattnere9bb2df2001-12-03 22:26:30 +000062 inline bool markConstant(Constant *V) {
63 if (LatticeValue != constant) {
64 LatticeValue = constant;
Chris Lattner138a1242001-06-27 23:38:11 +000065 ConstantVal = V;
66 return true;
67 } else {
Chris Lattnerb70d82f2001-09-07 16:43:22 +000068 assert(ConstantVal == V && "Marking constant with different value");
Chris Lattner138a1242001-06-27 23:38:11 +000069 }
70 return false;
71 }
72
Chris Lattnere9bb2df2001-12-03 22:26:30 +000073 inline bool isUndefined() const { return LatticeValue == undefined; }
74 inline bool isConstant() const { return LatticeValue == constant; }
75 inline bool isOverdefined() const { return LatticeValue == overdefined; }
Chris Lattner138a1242001-06-27 23:38:11 +000076
Chris Lattnere9bb2df2001-12-03 22:26:30 +000077 inline Constant *getConstant() const { return ConstantVal; }
Chris Lattner138a1242001-06-27 23:38:11 +000078};
79
80
81
82//===----------------------------------------------------------------------===//
83// SCCP Class
84//
85// This class does all of the work of Sparse Conditional Constant Propogation.
86// It's public interface consists of a constructor and a doSCCP() method.
87//
Chris Lattner2a632552002-04-18 15:13:15 +000088class SCCP : public InstVisitor<SCCP> {
Chris Lattner79df7c02002-03-26 18:01:55 +000089 Function *M; // The function that we are working on
Chris Lattner138a1242001-06-27 23:38:11 +000090
Chris Lattner697954c2002-01-20 22:54:45 +000091 std::set<BasicBlock*> BBExecutable;// The basic blocks that are executable
92 std::map<Value*, InstVal> ValueState; // The state each value is in...
Chris Lattner138a1242001-06-27 23:38:11 +000093
Chris Lattner697954c2002-01-20 22:54:45 +000094 std::vector<Instruction*> InstWorkList;// The instruction work list
95 std::vector<BasicBlock*> BBWorkList; // The BasicBlock work list
Chris Lattner138a1242001-06-27 23:38:11 +000096
97 //===--------------------------------------------------------------------===//
98 // The public interface for this class
99 //
100public:
101
102 // SCCP Ctor - Save the method to operate on...
Chris Lattner79df7c02002-03-26 18:01:55 +0000103 inline SCCP(Function *f) : M(f) {}
Chris Lattner138a1242001-06-27 23:38:11 +0000104
105 // doSCCP() - Run the Sparse Conditional Constant Propogation algorithm, and
106 // return true if the method was modified.
107 bool doSCCP();
108
109 //===--------------------------------------------------------------------===//
110 // The implementation of this class
111 //
112private:
Chris Lattner2a632552002-04-18 15:13:15 +0000113 friend class InstVisitor<SCCP>; // Allow callbacks from visitor
Chris Lattner138a1242001-06-27 23:38:11 +0000114
115 // markValueOverdefined - Make a value be marked as "constant". If the value
116 // is not already a constant, add it to the instruction work list so that
117 // the users of the instruction are updated later.
118 //
Chris Lattnere9bb2df2001-12-03 22:26:30 +0000119 inline bool markConstant(Instruction *I, Constant *V) {
Chris Lattner138a1242001-06-27 23:38:11 +0000120 //cerr << "markConstant: " << V << " = " << I;
121 if (ValueState[I].markConstant(V)) {
122 InstWorkList.push_back(I);
123 return true;
124 }
125 return false;
126 }
127
128 // markValueOverdefined - Make a value be marked as "overdefined". If the
129 // value is not already overdefined, add it to the instruction work list so
130 // that the users of the instruction are updated later.
131 //
132 inline bool markOverdefined(Value *V) {
133 if (ValueState[V].markOverdefined()) {
Chris Lattner9636a912001-10-01 16:18:37 +0000134 if (Instruction *I = dyn_cast<Instruction>(V)) {
Chris Lattner138a1242001-06-27 23:38:11 +0000135 //cerr << "markOverdefined: " << V;
136 InstWorkList.push_back(I); // Only instructions go on the work list
137 }
138 return true;
139 }
140 return false;
141 }
142
143 // getValueState - Return the InstVal object that corresponds to the value.
144 // This function is neccesary because not all values should start out in the
Chris Lattner73e21422002-04-09 19:48:49 +0000145 // underdefined state... Argument's should be overdefined, and
Chris Lattner79df7c02002-03-26 18:01:55 +0000146 // constants should be marked as constants. If a value is not known to be an
Chris Lattner138a1242001-06-27 23:38:11 +0000147 // Instruction object, then use this accessor to get its value from the map.
148 //
149 inline InstVal &getValueState(Value *V) {
Chris Lattner697954c2002-01-20 22:54:45 +0000150 std::map<Value*, InstVal>::iterator I = ValueState.find(V);
Chris Lattner138a1242001-06-27 23:38:11 +0000151 if (I != ValueState.end()) return I->second; // Common case, in the map
152
Chris Lattnere9bb2df2001-12-03 22:26:30 +0000153 if (Constant *CPV = dyn_cast<Constant>(V)) { // Constants are constant
Chris Lattner138a1242001-06-27 23:38:11 +0000154 ValueState[CPV].markConstant(CPV);
Chris Lattner73e21422002-04-09 19:48:49 +0000155 } else if (isa<Argument>(V)) { // Arguments are overdefined
Chris Lattner138a1242001-06-27 23:38:11 +0000156 ValueState[V].markOverdefined();
157 }
158 // All others are underdefined by default...
159 return ValueState[V];
160 }
161
162 // markExecutable - Mark a basic block as executable, adding it to the BB
163 // work list if it is not already executable...
164 //
165 void markExecutable(BasicBlock *BB) {
166 if (BBExecutable.count(BB)) return;
167 //cerr << "Marking BB Executable: " << BB;
168 BBExecutable.insert(BB); // Basic block is executable!
169 BBWorkList.push_back(BB); // Add the block to the work list!
170 }
171
Chris Lattner138a1242001-06-27 23:38:11 +0000172
Chris Lattner2a632552002-04-18 15:13:15 +0000173 // visit implementations - Something changed in this instruction... Either an
Chris Lattnercb056de2001-06-29 23:56:23 +0000174 // operand made a transition, or the instruction is newly executable. Change
175 // the value type of I to reflect these changes if appropriate.
176 //
Chris Lattner2a632552002-04-18 15:13:15 +0000177 void visitPHINode(PHINode *I);
178
179 // Terminators
180 void visitReturnInst(ReturnInst *I) { /*does not have an effect*/ }
181 void visitBranchInst(BranchInst *I);
182 void visitSwitchInst(SwitchInst *I);
183
184 void visitUnaryOperator(Instruction *I);
185 void visitCastInst(CastInst *I) { visitUnaryOperator(I); }
186 void visitBinaryOperator(Instruction *I);
187 void visitShiftInst(ShiftInst *I) { visitBinaryOperator(I); }
188
189 // Instructions that cannot be folded away...
190 void visitMemAccessInst (Instruction *I) { markOverdefined(I); }
191 void visitCallInst (Instruction *I) { markOverdefined(I); }
192 void visitInvokeInst (Instruction *I) { markOverdefined(I); }
193 void visitAllocationInst(Instruction *I) { markOverdefined(I); }
194 void visitFreeInst (Instruction *I) { markOverdefined(I); }
195
196 void visitInstruction(Instruction *I) {
197 // If a new instruction is added to LLVM that we don't handle...
198 cerr << "SCCP: Don't know how to handle: " << I;
199 markOverdefined(I); // Just in case
200 }
Chris Lattnercb056de2001-06-29 23:56:23 +0000201
202 // OperandChangedState - This method is invoked on all of the users of an
203 // instruction that was just changed state somehow.... Based on this
204 // information, we need to update the specified user of this instruction.
205 //
206 void OperandChangedState(User *U);
207};
Chris Lattner138a1242001-06-27 23:38:11 +0000208
209
210//===----------------------------------------------------------------------===//
211// SCCP Class Implementation
212
213
214// doSCCP() - Run the Sparse Conditional Constant Propogation algorithm, and
215// return true if the method was modified.
216//
217bool SCCP::doSCCP() {
218 // Mark the first block of the method as being executable...
219 markExecutable(M->front());
220
221 // Process the work lists until their are empty!
222 while (!BBWorkList.empty() || !InstWorkList.empty()) {
223 // Process the instruction work list...
224 while (!InstWorkList.empty()) {
225 Instruction *I = InstWorkList.back();
226 InstWorkList.pop_back();
227
228 //cerr << "\nPopped off I-WL: " << I;
229
230
231 // "I" got into the work list because it either made the transition from
232 // bottom to constant, or to Overdefined.
233 //
234 // Update all of the users of this instruction's value...
235 //
236 for_each(I->use_begin(), I->use_end(),
237 bind_obj(this, &SCCP::OperandChangedState));
238 }
239
240 // Process the basic block work list...
241 while (!BBWorkList.empty()) {
242 BasicBlock *BB = BBWorkList.back();
243 BBWorkList.pop_back();
244
245 //cerr << "\nPopped off BBWL: " << BB;
246
247 // If this block only has a single successor, mark it as executable as
248 // well... if not, terminate the do loop.
249 //
250 if (BB->getTerminator()->getNumSuccessors() == 1)
Chris Lattner5b7d42b2001-11-26 18:57:38 +0000251 markExecutable(BB->getTerminator()->getSuccessor(0));
Chris Lattner138a1242001-06-27 23:38:11 +0000252
Chris Lattner2a632552002-04-18 15:13:15 +0000253 // Notify all instructions in this basic block that they are newly
254 // executable.
255 visit(BB);
Chris Lattner138a1242001-06-27 23:38:11 +0000256 }
257 }
258
259#if 0
Chris Lattner79df7c02002-03-26 18:01:55 +0000260 for (Function::iterator BBI = M->begin(), BBEnd = M->end();
261 BBI != BBEnd; ++BBI)
Chris Lattner138a1242001-06-27 23:38:11 +0000262 if (!BBExecutable.count(*BBI))
263 cerr << "BasicBlock Dead:" << *BBI;
264#endif
265
266
267 // Iterate over all of the instructions in a method, replacing them with
268 // constants if we have found them to be of constant values.
269 //
270 bool MadeChanges = false;
Chris Lattner79df7c02002-03-26 18:01:55 +0000271 for (Function::iterator MI = M->begin(), ME = M->end(); MI != ME; ++MI) {
Chris Lattner221d6882002-02-12 21:07:25 +0000272 BasicBlock *BB = *MI;
273 for (BasicBlock::iterator BI = BB->begin(); BI != BB->end();) {
274 Instruction *Inst = *BI;
275 InstVal &IV = ValueState[Inst];
276 if (IV.isConstant()) {
277 Constant *Const = IV.getConstant();
278 // cerr << "Constant: " << Inst << " is: " << Const;
Chris Lattner5b7d42b2001-11-26 18:57:38 +0000279
Chris Lattner221d6882002-02-12 21:07:25 +0000280 // Replaces all of the uses of a variable with uses of the constant.
281 Inst->replaceAllUsesWith(Const);
Chris Lattner138a1242001-06-27 23:38:11 +0000282
Chris Lattner221d6882002-02-12 21:07:25 +0000283 // Remove the operator from the list of definitions...
284 BB->getInstList().remove(BI);
Chris Lattner5b7d42b2001-11-26 18:57:38 +0000285
Chris Lattner221d6882002-02-12 21:07:25 +0000286 // The new constant inherits the old name of the operator...
287 if (Inst->hasName() && !Const->hasName())
288 Const->setName(Inst->getName(), M->getSymbolTableSure());
Chris Lattner5b7d42b2001-11-26 18:57:38 +0000289
Chris Lattner221d6882002-02-12 21:07:25 +0000290 // Delete the operator now...
291 delete Inst;
Chris Lattner138a1242001-06-27 23:38:11 +0000292
Chris Lattner221d6882002-02-12 21:07:25 +0000293 // Hey, we just changed something!
294 MadeChanges = true;
295 } else if (TerminatorInst *TI = dyn_cast<TerminatorInst>(Inst)) {
Chris Lattner0fce76a2002-03-11 22:11:07 +0000296 MadeChanges |= ConstantFoldTerminator(BB, BI, TI);
Chris Lattner221d6882002-02-12 21:07:25 +0000297 }
Chris Lattner138a1242001-06-27 23:38:11 +0000298
Chris Lattner221d6882002-02-12 21:07:25 +0000299 ++BI;
Chris Lattner138a1242001-06-27 23:38:11 +0000300 }
301 }
302
303 // Merge identical constants last: this is important because we may have just
304 // introduced constants that already exist, and we don't want to pollute later
305 // stages with extraneous constants.
306 //
Chris Lattnerb70d82f2001-09-07 16:43:22 +0000307 return MadeChanges;
Chris Lattner138a1242001-06-27 23:38:11 +0000308}
309
310
Chris Lattner2a632552002-04-18 15:13:15 +0000311// visit Implementations - Something changed in this instruction... Either an
Chris Lattner138a1242001-06-27 23:38:11 +0000312// operand made a transition, or the instruction is newly executable. Change
313// the value type of I to reflect these changes if appropriate. This method
314// makes sure to do the following actions:
315//
316// 1. If a phi node merges two constants in, and has conflicting value coming
317// from different branches, or if the PHI node merges in an overdefined
318// value, then the PHI node becomes overdefined.
319// 2. If a phi node merges only constants in, and they all agree on value, the
320// PHI node becomes a constant value equal to that.
321// 3. If V <- x (op) y && isConstant(x) && isConstant(y) V = Constant
322// 4. If V <- x (op) y && (isOverdefined(x) || isOverdefined(y)) V = Overdefined
323// 5. If V <- MEM or V <- CALL or V <- (unknown) then V = Overdefined
324// 6. If a conditional branch has a value that is constant, make the selected
325// destination executable
326// 7. If a conditional branch has a value that is overdefined, make all
327// successors executable.
328//
Chris Lattner138a1242001-06-27 23:38:11 +0000329
Chris Lattner2a632552002-04-18 15:13:15 +0000330void SCCP::visitPHINode(PHINode *PN) {
331 unsigned NumValues = PN->getNumIncomingValues(), i;
332 InstVal *OperandIV = 0;
Chris Lattner138a1242001-06-27 23:38:11 +0000333
Chris Lattner2a632552002-04-18 15:13:15 +0000334 // Look at all of the executable operands of the PHI node. If any of them
335 // are overdefined, the PHI becomes overdefined as well. If they are all
336 // constant, and they agree with each other, the PHI becomes the identical
337 // constant. If they are constant and don't agree, the PHI is overdefined.
338 // If there are no executable operands, the PHI remains undefined.
339 //
340 for (i = 0; i < NumValues; ++i) {
341 if (BBExecutable.count(PN->getIncomingBlock(i))) {
342 InstVal &IV = getValueState(PN->getIncomingValue(i));
343 if (IV.isUndefined()) continue; // Doesn't influence PHI node.
344 if (IV.isOverdefined()) { // PHI node becomes overdefined!
345 markOverdefined(PN);
346 return;
347 }
Chris Lattner138a1242001-06-27 23:38:11 +0000348
Chris Lattner2a632552002-04-18 15:13:15 +0000349 if (OperandIV == 0) { // Grab the first value...
350 OperandIV = &IV;
351 } else { // Another value is being merged in!
352 // There is already a reachable operand. If we conflict with it,
353 // then the PHI node becomes overdefined. If we agree with it, we
354 // can continue on.
Chris Lattner5b7d42b2001-11-26 18:57:38 +0000355
Chris Lattner2a632552002-04-18 15:13:15 +0000356 // Check to see if there are two different constants merging...
357 if (IV.getConstant() != OperandIV->getConstant()) {
358 // Yes there is. This means the PHI node is not constant.
359 // You must be overdefined poor PHI.
360 //
361 markOverdefined(PN); // The PHI node now becomes overdefined
362 return; // I'm done analyzing you
Chris Lattner5b7d42b2001-11-26 18:57:38 +0000363 }
Chris Lattner138a1242001-06-27 23:38:11 +0000364 }
365 }
Chris Lattner138a1242001-06-27 23:38:11 +0000366 }
367
Chris Lattner2a632552002-04-18 15:13:15 +0000368 // If we exited the loop, this means that the PHI node only has constant
369 // arguments that agree with each other(and OperandIV is a pointer to one
370 // of their InstVal's) or OperandIV is null because there are no defined
371 // incoming arguments. If this is the case, the PHI remains undefined.
Chris Lattner138a1242001-06-27 23:38:11 +0000372 //
Chris Lattner2a632552002-04-18 15:13:15 +0000373 if (OperandIV) {
374 assert(OperandIV->isConstant() && "Should only be here for constants!");
375 markConstant(PN, OperandIV->getConstant()); // Aquire operand value
Chris Lattner138a1242001-06-27 23:38:11 +0000376 }
Chris Lattner138a1242001-06-27 23:38:11 +0000377}
378
Chris Lattner2a632552002-04-18 15:13:15 +0000379void SCCP::visitBranchInst(BranchInst *BI) {
380 if (BI->isUnconditional())
381 return; // Unconditional branches are already handled!
Chris Lattner138a1242001-06-27 23:38:11 +0000382
Chris Lattner2a632552002-04-18 15:13:15 +0000383 InstVal &BCValue = getValueState(BI->getCondition());
384 if (BCValue.isOverdefined()) {
385 // Overdefined condition variables mean the branch could go either way.
386 markExecutable(BI->getSuccessor(0));
387 markExecutable(BI->getSuccessor(1));
388 } else if (BCValue.isConstant()) {
389 // Constant condition variables mean the branch can only go a single way.
390 if (BCValue.getConstant() == ConstantBool::True)
391 markExecutable(BI->getSuccessor(0));
392 else
393 markExecutable(BI->getSuccessor(1));
394 }
395}
396
397void SCCP::visitSwitchInst(SwitchInst *SI) {
398 InstVal &SCValue = getValueState(SI->getCondition());
399 if (SCValue.isOverdefined()) { // Overdefined condition? All dests are exe
400 for(unsigned i = 0; BasicBlock *Succ = SI->getSuccessor(i); ++i)
401 markExecutable(Succ);
402 } else if (SCValue.isConstant()) {
403 Constant *CPV = SCValue.getConstant();
404 // Make sure to skip the "default value" which isn't a value
405 for (unsigned i = 1, E = SI->getNumSuccessors(); i != E; ++i) {
406 if (SI->getSuccessorValue(i) == CPV) {// Found the right branch...
407 markExecutable(SI->getSuccessor(i));
408 return;
409 }
410 }
411
412 // Constant value not equal to any of the branches... must execute
413 // default branch then...
414 markExecutable(SI->getDefaultDest());
415 }
416}
417
418void SCCP::visitUnaryOperator(Instruction *I) {
419 Value *V = I->getOperand(0);
420 InstVal &VState = getValueState(V);
421 if (VState.isOverdefined()) { // Inherit overdefinedness of operand
422 markOverdefined(I);
423 } else if (VState.isConstant()) { // Propogate constant value
424 Constant *Result = isa<CastInst>(I)
425 ? ConstantFoldCastInstruction(VState.getConstant(), I->getType())
426 : ConstantFoldUnaryInstruction(I->getOpcode(), VState.getConstant());
427
428 if (Result) {
429 // This instruction constant folds!
430 markConstant(I, Result);
431 } else {
432 markOverdefined(I); // Don't know how to fold this instruction. :(
433 }
434 }
435}
436
437// Handle BinaryOperators and Shift Instructions...
438void SCCP::visitBinaryOperator(Instruction *I) {
439 InstVal &V1State = getValueState(I->getOperand(0));
440 InstVal &V2State = getValueState(I->getOperand(1));
441 if (V1State.isOverdefined() || V2State.isOverdefined()) {
442 markOverdefined(I);
443 } else if (V1State.isConstant() && V2State.isConstant()) {
444 Constant *Result = ConstantFoldBinaryInstruction(I->getOpcode(),
445 V1State.getConstant(),
446 V2State.getConstant());
447 if (Result)
448 markConstant(I, Result); // This instruction constant fold!s
449 else
450 markOverdefined(I); // Don't know how to fold this instruction. :(
451 }
452}
Chris Lattner138a1242001-06-27 23:38:11 +0000453
454// OperandChangedState - This method is invoked on all of the users of an
455// instruction that was just changed state somehow.... Based on this
456// information, we need to update the specified user of this instruction.
457//
458void SCCP::OperandChangedState(User *U) {
459 // Only instructions use other variable values!
Chris Lattner9636a912001-10-01 16:18:37 +0000460 Instruction *I = cast<Instruction>(U);
Chris Lattner138a1242001-06-27 23:38:11 +0000461 if (!BBExecutable.count(I->getParent())) return; // Inst not executable yet!
462
Chris Lattner2a632552002-04-18 15:13:15 +0000463 visit(I);
Chris Lattner138a1242001-06-27 23:38:11 +0000464}
465
Chris Lattnerbd0ef772002-02-26 21:46:54 +0000466namespace {
467 // SCCPPass - Use Sparse Conditional Constant Propogation
468 // to prove whether a value is constant and whether blocks are used.
469 //
470 struct SCCPPass : public MethodPass {
Chris Lattner79df7c02002-03-26 18:01:55 +0000471 inline bool runOnMethod(Function *F) {
472 SCCP S(F);
Chris Lattnerbd0ef772002-02-26 21:46:54 +0000473 return S.doSCCP();
474 }
475 };
476}
Chris Lattner138a1242001-06-27 23:38:11 +0000477
Chris Lattnerbd0ef772002-02-26 21:46:54 +0000478Pass *createSCCPPass() {
479 return new SCCPPass();
Chris Lattner138a1242001-06-27 23:38:11 +0000480}