1 //===- CorrelatedExprs.cpp - Pass to detect and eliminated c.e.'s ---------===//
3 // The LLVM Compiler Infrastructure
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.
8 //===----------------------------------------------------------------------===//
10 // Correlated Expression Elimination propagates information from conditional
11 // branches to blocks dominated by destinations of the branch. It propagates
12 // information from the condition check itself into the body of the branch,
13 // allowing transformations like these for example:
16 // ... 4*i; // constant propagation
20 // X = M-N; // = M-M == 0;
22 // This is called Correlated Expression Elimination because we eliminate or
23 // simplify expressions that are correlated with the direction of a branch. In
24 // this way we use static information to give us some information about the
25 // dynamic value of a variable.
27 //===----------------------------------------------------------------------===//
29 #include "llvm/Transforms/Scalar.h"
30 #include "llvm/Constants.h"
31 #include "llvm/Pass.h"
32 #include "llvm/Function.h"
33 #include "llvm/Instructions.h"
34 #include "llvm/Type.h"
35 #include "llvm/Analysis/Dominators.h"
36 #include "llvm/Assembly/Writer.h"
37 #include "llvm/Transforms/Utils/Local.h"
38 #include "llvm/Transforms/Utils/BasicBlockUtils.h"
39 #include "llvm/Support/ConstantRange.h"
40 #include "llvm/Support/CFG.h"
41 #include "llvm/Support/Debug.h"
42 #include "llvm/ADT/PostOrderIterator.h"
43 #include "llvm/ADT/Statistic.h"
49 Statistic NumSetCCRemoved("cee", "Number of setcc instruction eliminated");
50 Statistic NumOperandsCann("cee", "Number of operands canonicalized");
51 Statistic BranchRevectors("cee", "Number of branches revectored");
55 Value *Val; // Relation to what value?
56 Instruction::BinaryOps Rel; // SetCC relation, or Add if no information
58 Relation(Value *V) : Val(V), Rel(Instruction::Add) {}
59 bool operator<(const Relation &R) const { return Val < R.Val; }
60 Value *getValue() const { return Val; }
61 Instruction::BinaryOps getRelation() const { return Rel; }
63 // contradicts - Return true if the relationship specified by the operand
64 // contradicts already known information.
66 bool contradicts(Instruction::BinaryOps Rel, const ValueInfo &VI) const;
68 // incorporate - Incorporate information in the argument into this relation
69 // entry. This assumes that the information doesn't contradict itself. If
70 // any new information is gained, true is returned, otherwise false is
71 // returned to indicate that nothing was updated.
73 bool incorporate(Instruction::BinaryOps Rel, ValueInfo &VI);
75 // KnownResult - Whether or not this condition determines the result of a
76 // setcc in the program. False & True are intentionally 0 & 1 so we can
77 // convert to bool by casting after checking for unknown.
79 enum KnownResult { KnownFalse = 0, KnownTrue = 1, Unknown = 2 };
81 // getImpliedResult - If this relationship between two values implies that
82 // the specified relationship is true or false, return that. If we cannot
83 // determine the result required, return Unknown.
85 KnownResult getImpliedResult(Instruction::BinaryOps Rel) const;
87 // print - Output this relation to the specified stream
88 void print(std::ostream &OS) const;
93 // ValueInfo - One instance of this record exists for every value with
94 // relationships between other values. It keeps track of all of the
95 // relationships to other values in the program (specified with Relation) that
96 // are known to be valid in a region.
99 // RelationShips - this value is know to have the specified relationships to
100 // other values. There can only be one entry per value, and this list is
101 // kept sorted by the Val field.
102 std::vector<Relation> Relationships;
104 // If information about this value is known or propagated from constant
105 // expressions, this range contains the possible values this value may hold.
106 ConstantRange Bounds;
108 // If we find that this value is equal to another value that has a lower
109 // rank, this value is used as it's replacement.
113 ValueInfo(const Type *Ty)
114 : Bounds(Ty->isIntegral() ? Ty : Type::IntTy), Replacement(0) {}
116 // getBounds() - Return the constant bounds of the value...
117 const ConstantRange &getBounds() const { return Bounds; }
118 ConstantRange &getBounds() { return Bounds; }
120 const std::vector<Relation> &getRelationships() { return Relationships; }
122 // getReplacement - Return the value this value is to be replaced with if it
123 // exists, otherwise return null.
125 Value *getReplacement() const { return Replacement; }
127 // setReplacement - Used by the replacement calculation pass to figure out
128 // what to replace this value with, if anything.
130 void setReplacement(Value *Repl) { Replacement = Repl; }
132 // getRelation - return the relationship entry for the specified value.
133 // This can invalidate references to other Relations, so use it carefully.
135 Relation &getRelation(Value *V) {
136 // Binary search for V's entry...
137 std::vector<Relation>::iterator I =
138 std::lower_bound(Relationships.begin(), Relationships.end(),
141 // If we found the entry, return it...
142 if (I != Relationships.end() && I->getValue() == V)
145 // Insert and return the new relationship...
146 return *Relationships.insert(I, V);
149 const Relation *requestRelation(Value *V) const {
150 // Binary search for V's entry...
151 std::vector<Relation>::const_iterator I =
152 std::lower_bound(Relationships.begin(), Relationships.end(),
154 if (I != Relationships.end() && I->getValue() == V)
159 // print - Output information about this value relation...
160 void print(std::ostream &OS, Value *V) const;
164 // RegionInfo - Keeps track of all of the value relationships for a region. A
165 // region is the are dominated by a basic block. RegionInfo's keep track of
166 // the RegionInfo for their dominator, because anything known in a dominator
167 // is known to be true in a dominated block as well.
172 // ValueMap - Tracks the ValueInformation known for this region
173 typedef std::map<Value*, ValueInfo> ValueMapTy;
176 RegionInfo(BasicBlock *bb) : BB(bb) {}
178 // getEntryBlock - Return the block that dominates all of the members of
180 BasicBlock *getEntryBlock() const { return BB; }
182 // empty - return true if this region has no information known about it.
183 bool empty() const { return ValueMap.empty(); }
185 const RegionInfo &operator=(const RegionInfo &RI) {
186 ValueMap = RI.ValueMap;
190 // print - Output information about this region...
191 void print(std::ostream &OS) const;
194 // Allow external access.
195 typedef ValueMapTy::iterator iterator;
196 iterator begin() { return ValueMap.begin(); }
197 iterator end() { return ValueMap.end(); }
199 ValueInfo &getValueInfo(Value *V) {
200 ValueMapTy::iterator I = ValueMap.lower_bound(V);
201 if (I != ValueMap.end() && I->first == V) return I->second;
202 return ValueMap.insert(I, std::make_pair(V, V->getType()))->second;
205 const ValueInfo *requestValueInfo(Value *V) const {
206 ValueMapTy::const_iterator I = ValueMap.find(V);
207 if (I != ValueMap.end()) return &I->second;
211 /// removeValueInfo - Remove anything known about V from our records. This
212 /// works whether or not we know anything about V.
214 void removeValueInfo(Value *V) {
219 /// CEE - Correlated Expression Elimination
220 class CEE : public FunctionPass {
221 std::map<Value*, unsigned> RankMap;
222 std::map<BasicBlock*, RegionInfo> RegionInfoMap;
226 virtual bool runOnFunction(Function &F);
228 // We don't modify the program, so we preserve all analyses
229 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
230 AU.addRequired<ETForest>();
231 AU.addRequired<DominatorTree>();
232 AU.addRequiredID(BreakCriticalEdgesID);
235 // print - Implement the standard print form to print out analysis
237 virtual void print(std::ostream &O, const Module *M) const;
240 RegionInfo &getRegionInfo(BasicBlock *BB) {
241 std::map<BasicBlock*, RegionInfo>::iterator I
242 = RegionInfoMap.lower_bound(BB);
243 if (I != RegionInfoMap.end() && I->first == BB) return I->second;
244 return RegionInfoMap.insert(I, std::make_pair(BB, BB))->second;
247 void BuildRankMap(Function &F);
248 unsigned getRank(Value *V) const {
249 if (isa<Constant>(V)) return 0;
250 std::map<Value*, unsigned>::const_iterator I = RankMap.find(V);
251 if (I != RankMap.end()) return I->second;
252 return 0; // Must be some other global thing
255 bool TransformRegion(BasicBlock *BB, std::set<BasicBlock*> &VisitedBlocks);
257 bool ForwardCorrelatedEdgeDestination(TerminatorInst *TI, unsigned SuccNo,
260 void ForwardSuccessorTo(TerminatorInst *TI, unsigned Succ, BasicBlock *D,
262 void ReplaceUsesOfValueInRegion(Value *Orig, Value *New,
263 BasicBlock *RegionDominator);
264 void CalculateRegionExitBlocks(BasicBlock *BB, BasicBlock *OldSucc,
265 std::vector<BasicBlock*> &RegionExitBlocks);
266 void InsertRegionExitMerges(PHINode *NewPHI, Instruction *OldVal,
267 const std::vector<BasicBlock*> &RegionExitBlocks);
269 void PropagateBranchInfo(BranchInst *BI);
270 void PropagateSwitchInfo(SwitchInst *SI);
271 void PropagateEquality(Value *Op0, Value *Op1, RegionInfo &RI);
272 void PropagateRelation(Instruction::BinaryOps Opcode, Value *Op0,
273 Value *Op1, RegionInfo &RI);
274 void UpdateUsersOfValue(Value *V, RegionInfo &RI);
275 void IncorporateInstruction(Instruction *Inst, RegionInfo &RI);
276 void ComputeReplacements(RegionInfo &RI);
279 // getSetCCResult - Given a setcc instruction, determine if the result is
280 // determined by facts we already know about the region under analysis.
281 // Return KnownTrue, KnownFalse, or Unknown based on what we can determine.
283 Relation::KnownResult getSetCCResult(SetCondInst *SC, const RegionInfo &RI);
286 bool SimplifyBasicBlock(BasicBlock &BB, const RegionInfo &RI);
287 bool SimplifyInstruction(Instruction *Inst, const RegionInfo &RI);
289 RegisterPass<CEE> X("cee", "Correlated Expression Elimination");
292 FunctionPass *llvm::createCorrelatedExpressionEliminationPass() {
297 bool CEE::runOnFunction(Function &F) {
298 // Build a rank map for the function...
301 // Traverse the dominator tree, computing information for each node in the
302 // tree. Note that our traversal will not even touch unreachable basic
304 EF = &getAnalysis<ETForest>();
305 DT = &getAnalysis<DominatorTree>();
307 std::set<BasicBlock*> VisitedBlocks;
308 bool Changed = TransformRegion(&F.getEntryBlock(), VisitedBlocks);
310 RegionInfoMap.clear();
315 // TransformRegion - Transform the region starting with BB according to the
316 // calculated region information for the block. Transforming the region
317 // involves analyzing any information this block provides to successors,
318 // propagating the information to successors, and finally transforming
321 // This method processes the function in depth first order, which guarantees
322 // that we process the immediate dominator of a block before the block itself.
323 // Because we are passing information from immediate dominators down to
324 // dominatees, we obviously have to process the information source before the
325 // information consumer.
327 bool CEE::TransformRegion(BasicBlock *BB, std::set<BasicBlock*> &VisitedBlocks){
328 // Prevent infinite recursion...
329 if (VisitedBlocks.count(BB)) return false;
330 VisitedBlocks.insert(BB);
332 // Get the computed region information for this block...
333 RegionInfo &RI = getRegionInfo(BB);
335 // Compute the replacement information for this block...
336 ComputeReplacements(RI);
338 // If debugging, print computed region information...
339 DEBUG(RI.print(std::cerr));
341 // Simplify the contents of this block...
342 bool Changed = SimplifyBasicBlock(*BB, RI);
344 // Get the terminator of this basic block...
345 TerminatorInst *TI = BB->getTerminator();
347 // Loop over all of the blocks that this block is the immediate dominator for.
348 // Because all information known in this region is also known in all of the
349 // blocks that are dominated by this one, we can safely propagate the
350 // information down now.
352 DominatorTree::Node *BBN = (*DT)[BB];
353 if (!RI.empty()) // Time opt: only propagate if we can change something
354 for (unsigned i = 0, e = BBN->getChildren().size(); i != e; ++i) {
355 BasicBlock *Dominated = BBN->getChildren()[i]->getBlock();
356 assert(RegionInfoMap.find(Dominated) == RegionInfoMap.end() &&
357 "RegionInfo should be calculated in dominanace order!");
358 getRegionInfo(Dominated) = RI;
361 // Now that all of our successors have information if they deserve it,
362 // propagate any information our terminator instruction finds to our
364 if (BranchInst *BI = dyn_cast<BranchInst>(TI)) {
365 if (BI->isConditional())
366 PropagateBranchInfo(BI);
367 } else if (SwitchInst *SI = dyn_cast<SwitchInst>(TI)) {
368 PropagateSwitchInfo(SI);
371 // If this is a branch to a block outside our region that simply performs
372 // another conditional branch, one whose outcome is known inside of this
373 // region, then vector this outgoing edge directly to the known destination.
375 for (unsigned i = 0, e = TI->getNumSuccessors(); i != e; ++i)
376 while (ForwardCorrelatedEdgeDestination(TI, i, RI)) {
381 // Now that all of our successors have information, recursively process them.
382 for (unsigned i = 0, e = BBN->getChildren().size(); i != e; ++i)
383 Changed |= TransformRegion(BBN->getChildren()[i]->getBlock(),VisitedBlocks);
388 // isBlockSimpleEnoughForCheck to see if the block is simple enough for us to
389 // revector the conditional branch in the bottom of the block, do so now.
391 static bool isBlockSimpleEnough(BasicBlock *BB) {
392 assert(isa<BranchInst>(BB->getTerminator()));
393 BranchInst *BI = cast<BranchInst>(BB->getTerminator());
394 assert(BI->isConditional());
396 // Check the common case first: empty block, or block with just a setcc.
397 if (BB->size() == 1 ||
398 (BB->size() == 2 && &BB->front() == BI->getCondition() &&
399 BI->getCondition()->hasOneUse()))
402 // Check the more complex case now...
403 BasicBlock::iterator I = BB->begin();
405 // FIXME: This should be reenabled once the regression with SIM is fixed!
407 // PHI Nodes are ok, just skip over them...
408 while (isa<PHINode>(*I)) ++I;
411 // Accept the setcc instruction...
412 if (&*I == BI->getCondition())
415 // Nothing else is acceptable here yet. We must not revector... unless we are
416 // at the terminator instruction.
424 bool CEE::ForwardCorrelatedEdgeDestination(TerminatorInst *TI, unsigned SuccNo,
426 // If this successor is a simple block not in the current region, which
427 // contains only a conditional branch, we decide if the outcome of the branch
428 // can be determined from information inside of the region. Instead of going
429 // to this block, we can instead go to the destination we know is the right
433 // Check to see if we dominate the block. If so, this block will get the
434 // condition turned to a constant anyway.
436 //if (EF->dominates(RI.getEntryBlock(), BB))
439 BasicBlock *BB = TI->getParent();
441 // Get the destination block of this edge...
442 BasicBlock *OldSucc = TI->getSuccessor(SuccNo);
444 // Make sure that the block ends with a conditional branch and is simple
445 // enough for use to be able to revector over.
446 BranchInst *BI = dyn_cast<BranchInst>(OldSucc->getTerminator());
447 if (BI == 0 || !BI->isConditional() || !isBlockSimpleEnough(OldSucc))
450 // We can only forward the branch over the block if the block ends with a
451 // setcc we can determine the outcome for.
453 // FIXME: we can make this more generic. Code below already handles more
455 SetCondInst *SCI = dyn_cast<SetCondInst>(BI->getCondition());
456 if (SCI == 0) return false;
458 // Make a new RegionInfo structure so that we can simulate the effect of the
459 // PHI nodes in the block we are skipping over...
461 RegionInfo NewRI(RI);
463 // Remove value information for all of the values we are simulating... to make
464 // sure we don't have any stale information.
465 for (BasicBlock::iterator I = OldSucc->begin(), E = OldSucc->end(); I!=E; ++I)
466 if (I->getType() != Type::VoidTy)
467 NewRI.removeValueInfo(I);
469 // Put the newly discovered information into the RegionInfo...
470 for (BasicBlock::iterator I = OldSucc->begin(), E = OldSucc->end(); I!=E; ++I)
471 if (PHINode *PN = dyn_cast<PHINode>(I)) {
472 int OpNum = PN->getBasicBlockIndex(BB);
473 assert(OpNum != -1 && "PHI doesn't have incoming edge for predecessor!?");
474 PropagateEquality(PN, PN->getIncomingValue(OpNum), NewRI);
475 } else if (SetCondInst *SCI = dyn_cast<SetCondInst>(I)) {
476 Relation::KnownResult Res = getSetCCResult(SCI, NewRI);
477 if (Res == Relation::Unknown) return false;
478 PropagateEquality(SCI, ConstantBool::get(Res), NewRI);
480 assert(isa<BranchInst>(*I) && "Unexpected instruction type!");
483 // Compute the facts implied by what we have discovered...
484 ComputeReplacements(NewRI);
486 ValueInfo &PredicateVI = NewRI.getValueInfo(BI->getCondition());
487 if (PredicateVI.getReplacement() &&
488 isa<Constant>(PredicateVI.getReplacement()) &&
489 !isa<GlobalValue>(PredicateVI.getReplacement())) {
490 ConstantBool *CB = cast<ConstantBool>(PredicateVI.getReplacement());
492 // Forward to the successor that corresponds to the branch we will take.
493 ForwardSuccessorTo(TI, SuccNo, BI->getSuccessor(!CB->getValue()), NewRI);
500 static Value *getReplacementOrValue(Value *V, RegionInfo &RI) {
501 if (const ValueInfo *VI = RI.requestValueInfo(V))
502 if (Value *Repl = VI->getReplacement())
507 /// ForwardSuccessorTo - We have found that we can forward successor # 'SuccNo'
508 /// of Terminator 'TI' to the 'Dest' BasicBlock. This method performs the
509 /// mechanics of updating SSA information and revectoring the branch.
511 void CEE::ForwardSuccessorTo(TerminatorInst *TI, unsigned SuccNo,
512 BasicBlock *Dest, RegionInfo &RI) {
513 // If there are any PHI nodes in the Dest BB, we must duplicate the entry
514 // in the PHI node for the old successor to now include an entry from the
515 // current basic block.
517 BasicBlock *OldSucc = TI->getSuccessor(SuccNo);
518 BasicBlock *BB = TI->getParent();
520 DEBUG(std::cerr << "Forwarding branch in basic block %" << BB->getName()
521 << " from block %" << OldSucc->getName() << " to block %"
522 << Dest->getName() << "\n");
524 DEBUG(std::cerr << "Before forwarding: " << *BB->getParent());
526 // Because we know that there cannot be critical edges in the flow graph, and
527 // that OldSucc has multiple outgoing edges, this means that Dest cannot have
528 // multiple incoming edges.
531 pred_iterator DPI = pred_begin(Dest); ++DPI;
532 assert(DPI == pred_end(Dest) && "Critical edge found!!");
535 // Loop over any PHI nodes in the destination, eliminating them, because they
536 // may only have one input.
538 while (PHINode *PN = dyn_cast<PHINode>(&Dest->front())) {
539 assert(PN->getNumIncomingValues() == 1 && "Crit edge found!");
540 // Eliminate the PHI node
541 PN->replaceAllUsesWith(PN->getIncomingValue(0));
542 Dest->getInstList().erase(PN);
545 // If there are values defined in the "OldSucc" basic block, we need to insert
546 // PHI nodes in the regions we are dealing with to emulate them. This can
547 // insert dead phi nodes, but it is more trouble to see if they are used than
548 // to just blindly insert them.
550 if (EF->dominates(OldSucc, Dest)) {
551 // RegionExitBlocks - Find all of the blocks that are not dominated by Dest,
552 // but have predecessors that are. Additionally, prune down the set to only
553 // include blocks that are dominated by OldSucc as well.
555 std::vector<BasicBlock*> RegionExitBlocks;
556 CalculateRegionExitBlocks(Dest, OldSucc, RegionExitBlocks);
558 for (BasicBlock::iterator I = OldSucc->begin(), E = OldSucc->end();
560 if (I->getType() != Type::VoidTy) {
561 // Create and insert the PHI node into the top of Dest.
562 PHINode *NewPN = new PHINode(I->getType(), I->getName()+".fw_merge",
564 // There is definitely an edge from OldSucc... add the edge now
565 NewPN->addIncoming(I, OldSucc);
567 // There is also an edge from BB now, add the edge with the calculated
568 // value from the RI.
569 NewPN->addIncoming(getReplacementOrValue(I, RI), BB);
571 // Make everything in the Dest region use the new PHI node now...
572 ReplaceUsesOfValueInRegion(I, NewPN, Dest);
574 // Make sure that exits out of the region dominated by NewPN get PHI
575 // nodes that merge the values as appropriate.
576 InsertRegionExitMerges(NewPN, I, RegionExitBlocks);
580 // If there were PHI nodes in OldSucc, we need to remove the entry for this
581 // edge from the PHI node, and we need to replace any references to the PHI
582 // node with a new value.
584 for (BasicBlock::iterator I = OldSucc->begin(); isa<PHINode>(I); ) {
585 PHINode *PN = cast<PHINode>(I);
587 // Get the value flowing across the old edge and remove the PHI node entry
588 // for this edge: we are about to remove the edge! Don't remove the PHI
589 // node yet though if this is the last edge into it.
590 Value *EdgeValue = PN->removeIncomingValue(BB, false);
592 // Make sure that anything that used to use PN now refers to EdgeValue
593 ReplaceUsesOfValueInRegion(PN, EdgeValue, Dest);
595 // If there is only one value left coming into the PHI node, replace the PHI
596 // node itself with the one incoming value left.
598 if (PN->getNumIncomingValues() == 1) {
599 assert(PN->getNumIncomingValues() == 1);
600 PN->replaceAllUsesWith(PN->getIncomingValue(0));
601 PN->getParent()->getInstList().erase(PN);
602 I = OldSucc->begin();
603 } else if (PN->getNumIncomingValues() == 0) { // Nuke the PHI
604 // If we removed the last incoming value to this PHI, nuke the PHI node
606 PN->replaceAllUsesWith(Constant::getNullValue(PN->getType()));
607 PN->getParent()->getInstList().erase(PN);
608 I = OldSucc->begin();
610 ++I; // Otherwise, move on to the next PHI node
614 // Actually revector the branch now...
615 TI->setSuccessor(SuccNo, Dest);
617 // If we just introduced a critical edge in the flow graph, make sure to break
619 SplitCriticalEdge(TI, SuccNo, this);
621 // Make sure that we don't introduce critical edges from oldsucc now!
622 for (unsigned i = 0, e = OldSucc->getTerminator()->getNumSuccessors();
624 SplitCriticalEdge(OldSucc->getTerminator(), i, this);
626 // Since we invalidated the CFG, recalculate the dominator set so that it is
627 // useful for later processing!
628 // FIXME: This is much worse than it really should be!
631 DEBUG(std::cerr << "After forwarding: " << *BB->getParent());
634 /// ReplaceUsesOfValueInRegion - This method replaces all uses of Orig with uses
635 /// of New. It only affects instructions that are defined in basic blocks that
636 /// are dominated by Head.
638 void CEE::ReplaceUsesOfValueInRegion(Value *Orig, Value *New,
639 BasicBlock *RegionDominator) {
640 assert(Orig != New && "Cannot replace value with itself");
641 std::vector<Instruction*> InstsToChange;
642 std::vector<PHINode*> PHIsToChange;
643 InstsToChange.reserve(Orig->getNumUses());
645 // Loop over instructions adding them to InstsToChange vector, this allows us
646 // an easy way to avoid invalidating the use_iterator at a bad time.
647 for (Value::use_iterator I = Orig->use_begin(), E = Orig->use_end();
649 if (Instruction *User = dyn_cast<Instruction>(*I))
650 if (EF->dominates(RegionDominator, User->getParent()))
651 InstsToChange.push_back(User);
652 else if (PHINode *PN = dyn_cast<PHINode>(User)) {
653 PHIsToChange.push_back(PN);
656 // PHIsToChange contains PHI nodes that use Orig that do not live in blocks
657 // dominated by orig. If the block the value flows in from is dominated by
658 // RegionDominator, then we rewrite the PHI
659 for (unsigned i = 0, e = PHIsToChange.size(); i != e; ++i) {
660 PHINode *PN = PHIsToChange[i];
661 for (unsigned j = 0, e = PN->getNumIncomingValues(); j != e; ++j)
662 if (PN->getIncomingValue(j) == Orig &&
663 EF->dominates(RegionDominator, PN->getIncomingBlock(j)))
664 PN->setIncomingValue(j, New);
667 // Loop over the InstsToChange list, replacing all uses of Orig with uses of
668 // New. This list contains all of the instructions in our region that use
670 for (unsigned i = 0, e = InstsToChange.size(); i != e; ++i)
671 if (PHINode *PN = dyn_cast<PHINode>(InstsToChange[i])) {
672 // PHINodes must be handled carefully. If the PHI node itself is in the
673 // region, we have to make sure to only do the replacement for incoming
674 // values that correspond to basic blocks in the region.
675 for (unsigned j = 0, e = PN->getNumIncomingValues(); j != e; ++j)
676 if (PN->getIncomingValue(j) == Orig &&
677 EF->dominates(RegionDominator, PN->getIncomingBlock(j)))
678 PN->setIncomingValue(j, New);
681 InstsToChange[i]->replaceUsesOfWith(Orig, New);
685 static void CalcRegionExitBlocks(BasicBlock *Header, BasicBlock *BB,
686 std::set<BasicBlock*> &Visited,
688 std::vector<BasicBlock*> &RegionExitBlocks) {
689 if (Visited.count(BB)) return;
692 if (EF.dominates(Header, BB)) { // Block in the region, recursively traverse
693 for (succ_iterator I = succ_begin(BB), E = succ_end(BB); I != E; ++I)
694 CalcRegionExitBlocks(Header, *I, Visited, EF, RegionExitBlocks);
696 // Header does not dominate this block, but we have a predecessor that does
697 // dominate us. Add ourself to the list.
698 RegionExitBlocks.push_back(BB);
702 /// CalculateRegionExitBlocks - Find all of the blocks that are not dominated by
703 /// BB, but have predecessors that are. Additionally, prune down the set to
704 /// only include blocks that are dominated by OldSucc as well.
706 void CEE::CalculateRegionExitBlocks(BasicBlock *BB, BasicBlock *OldSucc,
707 std::vector<BasicBlock*> &RegionExitBlocks){
708 std::set<BasicBlock*> Visited; // Don't infinite loop
710 // Recursively calculate blocks we are interested in...
711 CalcRegionExitBlocks(BB, BB, Visited, *EF, RegionExitBlocks);
713 // Filter out blocks that are not dominated by OldSucc...
714 for (unsigned i = 0; i != RegionExitBlocks.size(); ) {
715 if (EF->dominates(OldSucc, RegionExitBlocks[i]))
716 ++i; // Block is ok, keep it.
718 // Move to end of list...
719 std::swap(RegionExitBlocks[i], RegionExitBlocks.back());
720 RegionExitBlocks.pop_back(); // Nuke the end
725 void CEE::InsertRegionExitMerges(PHINode *BBVal, Instruction *OldVal,
726 const std::vector<BasicBlock*> &RegionExitBlocks) {
727 assert(BBVal->getType() == OldVal->getType() && "Should be derived values!");
728 BasicBlock *BB = BBVal->getParent();
730 // Loop over all of the blocks we have to place PHIs in, doing it.
731 for (unsigned i = 0, e = RegionExitBlocks.size(); i != e; ++i) {
732 BasicBlock *FBlock = RegionExitBlocks[i]; // Block on the frontier
734 // Create the new PHI node
735 PHINode *NewPN = new PHINode(BBVal->getType(),
736 OldVal->getName()+".fw_frontier",
739 // Add an incoming value for every predecessor of the block...
740 for (pred_iterator PI = pred_begin(FBlock), PE = pred_end(FBlock);
742 // If the incoming edge is from the region dominated by BB, use BBVal,
743 // otherwise use OldVal.
744 NewPN->addIncoming(EF->dominates(BB, *PI) ? BBVal : OldVal, *PI);
747 // Now make everyone dominated by this block use this new value!
748 ReplaceUsesOfValueInRegion(OldVal, NewPN, FBlock);
754 // BuildRankMap - This method builds the rank map data structure which gives
755 // each instruction/value in the function a value based on how early it appears
756 // in the function. We give constants and globals rank 0, arguments are
757 // numbered starting at one, and instructions are numbered in reverse post-order
758 // from where the arguments leave off. This gives instructions in loops higher
759 // values than instructions not in loops.
761 void CEE::BuildRankMap(Function &F) {
762 unsigned Rank = 1; // Skip rank zero.
764 // Number the arguments...
765 for (Function::arg_iterator I = F.arg_begin(), E = F.arg_end(); I != E; ++I)
768 // Number the instructions in reverse post order...
769 ReversePostOrderTraversal<Function*> RPOT(&F);
770 for (ReversePostOrderTraversal<Function*>::rpo_iterator I = RPOT.begin(),
771 E = RPOT.end(); I != E; ++I)
772 for (BasicBlock::iterator BBI = (*I)->begin(), E = (*I)->end();
774 if (BBI->getType() != Type::VoidTy)
775 RankMap[BBI] = Rank++;
779 // PropagateBranchInfo - When this method is invoked, we need to propagate
780 // information derived from the branch condition into the true and false
781 // branches of BI. Since we know that there aren't any critical edges in the
782 // flow graph, this can proceed unconditionally.
784 void CEE::PropagateBranchInfo(BranchInst *BI) {
785 assert(BI->isConditional() && "Must be a conditional branch!");
787 // Propagate information into the true block...
789 PropagateEquality(BI->getCondition(), ConstantBool::getTrue(),
790 getRegionInfo(BI->getSuccessor(0)));
792 // Propagate information into the false block...
794 PropagateEquality(BI->getCondition(), ConstantBool::getFalse(),
795 getRegionInfo(BI->getSuccessor(1)));
799 // PropagateSwitchInfo - We need to propagate the value tested by the
800 // switch statement through each case block.
802 void CEE::PropagateSwitchInfo(SwitchInst *SI) {
803 // Propagate information down each of our non-default case labels. We
804 // don't yet propagate information down the default label, because a
805 // potentially large number of inequality constraints provide less
806 // benefit per unit work than a single equality constraint.
808 Value *cond = SI->getCondition();
809 for (unsigned i = 1; i < SI->getNumSuccessors(); ++i)
810 PropagateEquality(cond, SI->getSuccessorValue(i),
811 getRegionInfo(SI->getSuccessor(i)));
815 // PropagateEquality - If we discover that two values are equal to each other in
816 // a specified region, propagate this knowledge recursively.
818 void CEE::PropagateEquality(Value *Op0, Value *Op1, RegionInfo &RI) {
819 if (Op0 == Op1) return; // Gee whiz. Are these really equal each other?
821 if (isa<Constant>(Op0)) // Make sure the constant is always Op1
824 // Make sure we don't already know these are equal, to avoid infinite loops...
825 ValueInfo &VI = RI.getValueInfo(Op0);
827 // Get information about the known relationship between Op0 & Op1
828 Relation &KnownRelation = VI.getRelation(Op1);
830 // If we already know they're equal, don't reprocess...
831 if (KnownRelation.getRelation() == Instruction::SetEQ)
834 // If this is boolean, check to see if one of the operands is a constant. If
835 // it's a constant, then see if the other one is one of a setcc instruction,
836 // an AND, OR, or XOR instruction.
838 if (ConstantBool *CB = dyn_cast<ConstantBool>(Op1)) {
840 if (Instruction *Inst = dyn_cast<Instruction>(Op0)) {
841 // If we know that this instruction is an AND instruction, and the result
842 // is true, this means that both operands to the OR are known to be true
845 if (CB->getValue() && Inst->getOpcode() == Instruction::And) {
846 PropagateEquality(Inst->getOperand(0), CB, RI);
847 PropagateEquality(Inst->getOperand(1), CB, RI);
850 // If we know that this instruction is an OR instruction, and the result
851 // is false, this means that both operands to the OR are know to be false
854 if (!CB->getValue() && Inst->getOpcode() == Instruction::Or) {
855 PropagateEquality(Inst->getOperand(0), CB, RI);
856 PropagateEquality(Inst->getOperand(1), CB, RI);
859 // If we know that this instruction is a NOT instruction, we know that the
860 // operand is known to be the inverse of whatever the current value is.
862 if (BinaryOperator *BOp = dyn_cast<BinaryOperator>(Inst))
863 if (BinaryOperator::isNot(BOp))
864 PropagateEquality(BinaryOperator::getNotArgument(BOp),
865 ConstantBool::get(!CB->getValue()), RI);
867 // If we know the value of a SetCC instruction, propagate the information
868 // about the relation into this region as well.
870 if (SetCondInst *SCI = dyn_cast<SetCondInst>(Inst)) {
871 if (CB->getValue()) { // If we know the condition is true...
872 // Propagate info about the LHS to the RHS & RHS to LHS
873 PropagateRelation(SCI->getOpcode(), SCI->getOperand(0),
874 SCI->getOperand(1), RI);
875 PropagateRelation(SCI->getSwappedCondition(),
876 SCI->getOperand(1), SCI->getOperand(0), RI);
878 } else { // If we know the condition is false...
879 // We know the opposite of the condition is true...
880 Instruction::BinaryOps C = SCI->getInverseCondition();
882 PropagateRelation(C, SCI->getOperand(0), SCI->getOperand(1), RI);
883 PropagateRelation(SetCondInst::getSwappedCondition(C),
884 SCI->getOperand(1), SCI->getOperand(0), RI);
890 // Propagate information about Op0 to Op1 & visa versa
891 PropagateRelation(Instruction::SetEQ, Op0, Op1, RI);
892 PropagateRelation(Instruction::SetEQ, Op1, Op0, RI);
896 // PropagateRelation - We know that the specified relation is true in all of the
897 // blocks in the specified region. Propagate the information about Op0 and
898 // anything derived from it into this region.
900 void CEE::PropagateRelation(Instruction::BinaryOps Opcode, Value *Op0,
901 Value *Op1, RegionInfo &RI) {
902 assert(Op0->getType() == Op1->getType() && "Equal types expected!");
904 // Constants are already pretty well understood. We will apply information
905 // about the constant to Op1 in another call to PropagateRelation.
907 if (isa<Constant>(Op0)) return;
909 // Get the region information for this block to update...
910 ValueInfo &VI = RI.getValueInfo(Op0);
912 // Get information about the known relationship between Op0 & Op1
913 Relation &Op1R = VI.getRelation(Op1);
915 // Quick bailout for common case if we are reprocessing an instruction...
916 if (Op1R.getRelation() == Opcode)
919 // If we already have information that contradicts the current information we
920 // are propagating, ignore this info. Something bad must have happened!
922 if (Op1R.contradicts(Opcode, VI)) {
923 Op1R.contradicts(Opcode, VI);
924 std::cerr << "Contradiction found for opcode: "
925 << Instruction::getOpcodeName(Opcode) << "\n";
926 Op1R.print(std::cerr);
930 // If the information propagated is new, then we want process the uses of this
931 // instruction to propagate the information down to them.
933 if (Op1R.incorporate(Opcode, VI))
934 UpdateUsersOfValue(Op0, RI);
938 // UpdateUsersOfValue - The information about V in this region has been updated.
939 // Propagate this to all consumers of the value.
941 void CEE::UpdateUsersOfValue(Value *V, RegionInfo &RI) {
942 for (Value::use_iterator I = V->use_begin(), E = V->use_end();
944 if (Instruction *Inst = dyn_cast<Instruction>(*I)) {
945 // If this is an instruction using a value that we know something about,
946 // try to propagate information to the value produced by the
947 // instruction. We can only do this if it is an instruction we can
948 // propagate information for (a setcc for example), and we only WANT to
949 // do this if the instruction dominates this region.
951 // If the instruction doesn't dominate this region, then it cannot be
952 // used in this region and we don't care about it. If the instruction
953 // is IN this region, then we will simplify the instruction before we
954 // get to uses of it anyway, so there is no reason to bother with it
955 // here. This check is also effectively checking to make sure that Inst
956 // is in the same function as our region (in case V is a global f.e.).
958 if (EF->properlyDominates(Inst->getParent(), RI.getEntryBlock()))
959 IncorporateInstruction(Inst, RI);
963 // IncorporateInstruction - We just updated the information about one of the
964 // operands to the specified instruction. Update the information about the
965 // value produced by this instruction
967 void CEE::IncorporateInstruction(Instruction *Inst, RegionInfo &RI) {
968 if (SetCondInst *SCI = dyn_cast<SetCondInst>(Inst)) {
969 // See if we can figure out a result for this instruction...
970 Relation::KnownResult Result = getSetCCResult(SCI, RI);
971 if (Result != Relation::Unknown) {
972 PropagateEquality(SCI, ConstantBool::get(Result != 0), RI);
978 // ComputeReplacements - Some values are known to be equal to other values in a
979 // region. For example if there is a comparison of equality between a variable
980 // X and a constant C, we can replace all uses of X with C in the region we are
981 // interested in. We generalize this replacement to replace variables with
982 // other variables if they are equal and there is a variable with lower rank
983 // than the current one. This offers a canonicalizing property that exposes
984 // more redundancies for later transformations to take advantage of.
986 void CEE::ComputeReplacements(RegionInfo &RI) {
987 // Loop over all of the values in the region info map...
988 for (RegionInfo::iterator I = RI.begin(), E = RI.end(); I != E; ++I) {
989 ValueInfo &VI = I->second;
991 // If we know that this value is a particular constant, set Replacement to
993 Value *Replacement = VI.getBounds().getSingleElement();
995 // If this value is not known to be some constant, figure out the lowest
996 // rank value that it is known to be equal to (if anything).
998 if (Replacement == 0) {
999 // Find out if there are any equality relationships with values of lower
1000 // rank than VI itself...
1001 unsigned MinRank = getRank(I->first);
1003 // Loop over the relationships known about Op0.
1004 const std::vector<Relation> &Relationships = VI.getRelationships();
1005 for (unsigned i = 0, e = Relationships.size(); i != e; ++i)
1006 if (Relationships[i].getRelation() == Instruction::SetEQ) {
1007 unsigned R = getRank(Relationships[i].getValue());
1010 Replacement = Relationships[i].getValue();
1015 // If we found something to replace this value with, keep track of it.
1017 VI.setReplacement(Replacement);
1021 // SimplifyBasicBlock - Given information about values in region RI, simplify
1022 // the instructions in the specified basic block.
1024 bool CEE::SimplifyBasicBlock(BasicBlock &BB, const RegionInfo &RI) {
1025 bool Changed = false;
1026 for (BasicBlock::iterator I = BB.begin(), E = BB.end(); I != E; ) {
1027 Instruction *Inst = I++;
1029 // Convert instruction arguments to canonical forms...
1030 Changed |= SimplifyInstruction(Inst, RI);
1032 if (SetCondInst *SCI = dyn_cast<SetCondInst>(Inst)) {
1033 // Try to simplify a setcc instruction based on inherited information
1034 Relation::KnownResult Result = getSetCCResult(SCI, RI);
1035 if (Result != Relation::Unknown) {
1036 DEBUG(std::cerr << "Replacing setcc with " << Result
1037 << " constant: " << *SCI);
1039 SCI->replaceAllUsesWith(ConstantBool::get((bool)Result));
1040 // The instruction is now dead, remove it from the program.
1041 SCI->getParent()->getInstList().erase(SCI);
1051 // SimplifyInstruction - Inspect the operands of the instruction, converting
1052 // them to their canonical form if possible. This takes care of, for example,
1053 // replacing a value 'X' with a constant 'C' if the instruction in question is
1054 // dominated by a true seteq 'X', 'C'.
1056 bool CEE::SimplifyInstruction(Instruction *I, const RegionInfo &RI) {
1057 bool Changed = false;
1059 for (unsigned i = 0, e = I->getNumOperands(); i != e; ++i)
1060 if (const ValueInfo *VI = RI.requestValueInfo(I->getOperand(i)))
1061 if (Value *Repl = VI->getReplacement()) {
1062 // If we know if a replacement with lower rank than Op0, make the
1064 DEBUG(std::cerr << "In Inst: " << *I << " Replacing operand #" << i
1065 << " with " << *Repl << "\n");
1066 I->setOperand(i, Repl);
1075 // getSetCCResult - Try to simplify a setcc instruction based on information
1076 // inherited from a dominating setcc instruction. V is one of the operands to
1077 // the setcc instruction, and VI is the set of information known about it. We
1078 // take two cases into consideration here. If the comparison is against a
1079 // constant value, we can use the constant range to see if the comparison is
1080 // possible to succeed. If it is not a comparison against a constant, we check
1081 // to see if there is a known relationship between the two values. If so, we
1082 // may be able to eliminate the check.
1084 Relation::KnownResult CEE::getSetCCResult(SetCondInst *SCI,
1085 const RegionInfo &RI) {
1086 Value *Op0 = SCI->getOperand(0), *Op1 = SCI->getOperand(1);
1087 Instruction::BinaryOps Opcode = SCI->getOpcode();
1089 if (isa<Constant>(Op0)) {
1090 if (isa<Constant>(Op1)) {
1091 if (Constant *Result = ConstantFoldInstruction(SCI)) {
1092 // Wow, this is easy, directly eliminate the SetCondInst.
1093 DEBUG(std::cerr << "Replacing setcc with constant fold: " << *SCI);
1094 return cast<ConstantBool>(Result)->getValue()
1095 ? Relation::KnownTrue : Relation::KnownFalse;
1098 // We want to swap this instruction so that operand #0 is the constant.
1099 std::swap(Op0, Op1);
1100 Opcode = SCI->getSwappedCondition();
1104 // Try to figure out what the result of this comparison will be...
1105 Relation::KnownResult Result = Relation::Unknown;
1107 // We have to know something about the relationship to prove anything...
1108 if (const ValueInfo *Op0VI = RI.requestValueInfo(Op0)) {
1110 // At this point, we know that if we have a constant argument that it is in
1111 // Op1. Check to see if we know anything about comparing value with a
1112 // constant, and if we can use this info to fold the setcc.
1114 if (ConstantIntegral *C = dyn_cast<ConstantIntegral>(Op1)) {
1115 // Check to see if we already know the result of this comparison...
1116 ConstantRange R = ConstantRange(Opcode, C);
1117 ConstantRange Int = R.intersectWith(Op0VI->getBounds());
1119 // If the intersection of the two ranges is empty, then the condition
1120 // could never be true!
1122 if (Int.isEmptySet()) {
1123 Result = Relation::KnownFalse;
1125 // Otherwise, if VI.getBounds() (the possible values) is a subset of R
1126 // (the allowed values) then we know that the condition must always be
1129 } else if (Int == Op0VI->getBounds()) {
1130 Result = Relation::KnownTrue;
1133 // If we are here, we know that the second argument is not a constant
1134 // integral. See if we know anything about Op0 & Op1 that allows us to
1135 // fold this anyway.
1137 // Do we have value information about Op0 and a relation to Op1?
1138 if (const Relation *Op2R = Op0VI->requestRelation(Op1))
1139 Result = Op2R->getImpliedResult(Opcode);
1145 //===----------------------------------------------------------------------===//
1146 // Relation Implementation
1147 //===----------------------------------------------------------------------===//
1149 // contradicts - Return true if the relationship specified by the operand
1150 // contradicts already known information.
1152 bool Relation::contradicts(Instruction::BinaryOps Op,
1153 const ValueInfo &VI) const {
1154 assert (Op != Instruction::Add && "Invalid relation argument!");
1156 // If this is a relationship with a constant, make sure that this relationship
1157 // does not contradict properties known about the bounds of the constant.
1159 if (ConstantIntegral *C = dyn_cast<ConstantIntegral>(Val))
1160 if (ConstantRange(Op, C).intersectWith(VI.getBounds()).isEmptySet())
1164 default: assert(0 && "Unknown Relationship code!");
1165 case Instruction::Add: return false; // Nothing known, nothing contradicts
1166 case Instruction::SetEQ:
1167 return Op == Instruction::SetLT || Op == Instruction::SetGT ||
1168 Op == Instruction::SetNE;
1169 case Instruction::SetNE: return Op == Instruction::SetEQ;
1170 case Instruction::SetLE: return Op == Instruction::SetGT;
1171 case Instruction::SetGE: return Op == Instruction::SetLT;
1172 case Instruction::SetLT:
1173 return Op == Instruction::SetEQ || Op == Instruction::SetGT ||
1174 Op == Instruction::SetGE;
1175 case Instruction::SetGT:
1176 return Op == Instruction::SetEQ || Op == Instruction::SetLT ||
1177 Op == Instruction::SetLE;
1181 // incorporate - Incorporate information in the argument into this relation
1182 // entry. This assumes that the information doesn't contradict itself. If any
1183 // new information is gained, true is returned, otherwise false is returned to
1184 // indicate that nothing was updated.
1186 bool Relation::incorporate(Instruction::BinaryOps Op, ValueInfo &VI) {
1187 assert(!contradicts(Op, VI) &&
1188 "Cannot incorporate contradictory information!");
1190 // If this is a relationship with a constant, make sure that we update the
1191 // range that is possible for the value to have...
1193 if (ConstantIntegral *C = dyn_cast<ConstantIntegral>(Val))
1194 VI.getBounds() = ConstantRange(Op, C).intersectWith(VI.getBounds());
1197 default: assert(0 && "Unknown prior value!");
1198 case Instruction::Add: Rel = Op; return true;
1199 case Instruction::SetEQ: return false; // Nothing is more precise
1200 case Instruction::SetNE: return false; // Nothing is more precise
1201 case Instruction::SetLT: return false; // Nothing is more precise
1202 case Instruction::SetGT: return false; // Nothing is more precise
1203 case Instruction::SetLE:
1204 if (Op == Instruction::SetEQ || Op == Instruction::SetLT) {
1207 } else if (Op == Instruction::SetNE) {
1208 Rel = Instruction::SetLT;
1212 case Instruction::SetGE: return Op == Instruction::SetLT;
1213 if (Op == Instruction::SetEQ || Op == Instruction::SetGT) {
1216 } else if (Op == Instruction::SetNE) {
1217 Rel = Instruction::SetGT;
1224 // getImpliedResult - If this relationship between two values implies that
1225 // the specified relationship is true or false, return that. If we cannot
1226 // determine the result required, return Unknown.
1228 Relation::KnownResult
1229 Relation::getImpliedResult(Instruction::BinaryOps Op) const {
1230 if (Rel == Op) return KnownTrue;
1231 if (Rel == SetCondInst::getInverseCondition(Op)) return KnownFalse;
1234 default: assert(0 && "Unknown prior value!");
1235 case Instruction::SetEQ:
1236 if (Op == Instruction::SetLE || Op == Instruction::SetGE) return KnownTrue;
1237 if (Op == Instruction::SetLT || Op == Instruction::SetGT) return KnownFalse;
1239 case Instruction::SetLT:
1240 if (Op == Instruction::SetNE || Op == Instruction::SetLE) return KnownTrue;
1241 if (Op == Instruction::SetEQ) return KnownFalse;
1243 case Instruction::SetGT:
1244 if (Op == Instruction::SetNE || Op == Instruction::SetGE) return KnownTrue;
1245 if (Op == Instruction::SetEQ) return KnownFalse;
1247 case Instruction::SetNE:
1248 case Instruction::SetLE:
1249 case Instruction::SetGE:
1250 case Instruction::Add:
1257 //===----------------------------------------------------------------------===//
1258 // Printing Support...
1259 //===----------------------------------------------------------------------===//
1261 // print - Implement the standard print form to print out analysis information.
1262 void CEE::print(std::ostream &O, const Module *M) const {
1263 O << "\nPrinting Correlated Expression Info:\n";
1264 for (std::map<BasicBlock*, RegionInfo>::const_iterator I =
1265 RegionInfoMap.begin(), E = RegionInfoMap.end(); I != E; ++I)
1269 // print - Output information about this region...
1270 void RegionInfo::print(std::ostream &OS) const {
1271 if (ValueMap.empty()) return;
1273 OS << " RegionInfo for basic block: " << BB->getName() << "\n";
1274 for (std::map<Value*, ValueInfo>::const_iterator
1275 I = ValueMap.begin(), E = ValueMap.end(); I != E; ++I)
1276 I->second.print(OS, I->first);
1280 // print - Output information about this value relation...
1281 void ValueInfo::print(std::ostream &OS, Value *V) const {
1282 if (Relationships.empty()) return;
1285 OS << " ValueInfo for: ";
1286 WriteAsOperand(OS, V);
1288 OS << "\n Bounds = " << Bounds << "\n";
1290 OS << " Replacement = ";
1291 WriteAsOperand(OS, Replacement);
1294 for (unsigned i = 0, e = Relationships.size(); i != e; ++i)
1295 Relationships[i].print(OS);
1298 // print - Output this relation to the specified stream
1299 void Relation::print(std::ostream &OS) const {
1302 default: OS << "*UNKNOWN*"; break;
1303 case Instruction::SetEQ: OS << "== "; break;
1304 case Instruction::SetNE: OS << "!= "; break;
1305 case Instruction::SetLT: OS << "< "; break;
1306 case Instruction::SetGT: OS << "> "; break;
1307 case Instruction::SetLE: OS << "<= "; break;
1308 case Instruction::SetGE: OS << ">= "; break;
1311 WriteAsOperand(OS, Val);
1315 // Don't inline these methods or else we won't be able to call them from GDB!
1316 void Relation::dump() const { print(std::cerr); }
1317 void ValueInfo::dump() const { print(std::cerr, 0); }
1318 void RegionInfo::dump() const { print(std::cerr); }