Mercurial > hg > CbC > CbC_llvm
comparison lib/Analysis/Lint.cpp @ 83:60c9769439b8 LLVM3.7
LLVM 3.7
author | Tatsuki IHA <e125716@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 18 Feb 2015 14:55:36 +0900 |
parents | 54457678186b |
children | afa8332a0e37 |
comparison
equal
deleted
inserted
replaced
78:af83660cff7b | 83:60c9769439b8 |
---|---|
34 // | 34 // |
35 //===----------------------------------------------------------------------===// | 35 //===----------------------------------------------------------------------===// |
36 | 36 |
37 #include "llvm/Analysis/Lint.h" | 37 #include "llvm/Analysis/Lint.h" |
38 #include "llvm/ADT/STLExtras.h" | 38 #include "llvm/ADT/STLExtras.h" |
39 #include "llvm/ADT/SmallSet.h" | |
39 #include "llvm/Analysis/AliasAnalysis.h" | 40 #include "llvm/Analysis/AliasAnalysis.h" |
40 #include "llvm/Analysis/AssumptionTracker.h" | 41 #include "llvm/Analysis/AssumptionCache.h" |
41 #include "llvm/Analysis/ConstantFolding.h" | 42 #include "llvm/Analysis/ConstantFolding.h" |
42 #include "llvm/Analysis/InstructionSimplify.h" | 43 #include "llvm/Analysis/InstructionSimplify.h" |
43 #include "llvm/Analysis/Loads.h" | 44 #include "llvm/Analysis/Loads.h" |
44 #include "llvm/Analysis/Passes.h" | 45 #include "llvm/Analysis/Passes.h" |
46 #include "llvm/Analysis/TargetLibraryInfo.h" | |
45 #include "llvm/Analysis/ValueTracking.h" | 47 #include "llvm/Analysis/ValueTracking.h" |
46 #include "llvm/IR/CallSite.h" | 48 #include "llvm/IR/CallSite.h" |
47 #include "llvm/IR/DataLayout.h" | 49 #include "llvm/IR/DataLayout.h" |
48 #include "llvm/IR/Dominators.h" | 50 #include "llvm/IR/Dominators.h" |
49 #include "llvm/IR/Function.h" | 51 #include "llvm/IR/Function.h" |
50 #include "llvm/IR/InstVisitor.h" | 52 #include "llvm/IR/InstVisitor.h" |
51 #include "llvm/IR/IntrinsicInst.h" | 53 #include "llvm/IR/IntrinsicInst.h" |
54 #include "llvm/IR/LegacyPassManager.h" | |
52 #include "llvm/Pass.h" | 55 #include "llvm/Pass.h" |
53 #include "llvm/PassManager.h" | |
54 #include "llvm/Support/Debug.h" | 56 #include "llvm/Support/Debug.h" |
55 #include "llvm/Support/raw_ostream.h" | 57 #include "llvm/Support/raw_ostream.h" |
56 #include "llvm/Target/TargetLibraryInfo.h" | |
57 using namespace llvm; | 58 using namespace llvm; |
58 | 59 |
59 namespace { | 60 namespace { |
60 namespace MemRef { | 61 namespace MemRef { |
61 static unsigned Read = 1; | 62 static unsigned Read = 1; |
71 | 72 |
72 void visitCallSite(CallSite CS); | 73 void visitCallSite(CallSite CS); |
73 void visitMemoryReference(Instruction &I, Value *Ptr, | 74 void visitMemoryReference(Instruction &I, Value *Ptr, |
74 uint64_t Size, unsigned Align, | 75 uint64_t Size, unsigned Align, |
75 Type *Ty, unsigned Flags); | 76 Type *Ty, unsigned Flags); |
77 void visitEHBeginCatch(IntrinsicInst *II); | |
78 void visitEHEndCatch(IntrinsicInst *II); | |
76 | 79 |
77 void visitCallInst(CallInst &I); | 80 void visitCallInst(CallInst &I); |
78 void visitInvokeInst(InvokeInst &I); | 81 void visitInvokeInst(InvokeInst &I); |
79 void visitReturnInst(ReturnInst &I); | 82 void visitReturnInst(ReturnInst &I); |
80 void visitLoadInst(LoadInst &I); | 83 void visitLoadInst(LoadInst &I); |
100 SmallPtrSetImpl<Value *> &Visited) const; | 103 SmallPtrSetImpl<Value *> &Visited) const; |
101 | 104 |
102 public: | 105 public: |
103 Module *Mod; | 106 Module *Mod; |
104 AliasAnalysis *AA; | 107 AliasAnalysis *AA; |
105 AssumptionTracker *AT; | 108 AssumptionCache *AC; |
106 DominatorTree *DT; | 109 DominatorTree *DT; |
107 const DataLayout *DL; | 110 const DataLayout *DL; |
108 TargetLibraryInfo *TLI; | 111 TargetLibraryInfo *TLI; |
109 | 112 |
110 std::string Messages; | 113 std::string Messages; |
118 bool runOnFunction(Function &F) override; | 121 bool runOnFunction(Function &F) override; |
119 | 122 |
120 void getAnalysisUsage(AnalysisUsage &AU) const override { | 123 void getAnalysisUsage(AnalysisUsage &AU) const override { |
121 AU.setPreservesAll(); | 124 AU.setPreservesAll(); |
122 AU.addRequired<AliasAnalysis>(); | 125 AU.addRequired<AliasAnalysis>(); |
123 AU.addRequired<AssumptionTracker>(); | 126 AU.addRequired<AssumptionCacheTracker>(); |
124 AU.addRequired<TargetLibraryInfo>(); | 127 AU.addRequired<TargetLibraryInfoWrapperPass>(); |
125 AU.addRequired<DominatorTreeWrapperPass>(); | 128 AU.addRequired<DominatorTreeWrapperPass>(); |
126 } | 129 } |
127 void print(raw_ostream &O, const Module *M) const override {} | 130 void print(raw_ostream &O, const Module *M) const override {} |
128 | 131 |
129 void WriteValue(const Value *V) { | 132 void WriteValue(const Value *V) { |
152 } | 155 } |
153 | 156 |
154 char Lint::ID = 0; | 157 char Lint::ID = 0; |
155 INITIALIZE_PASS_BEGIN(Lint, "lint", "Statically lint-checks LLVM IR", | 158 INITIALIZE_PASS_BEGIN(Lint, "lint", "Statically lint-checks LLVM IR", |
156 false, true) | 159 false, true) |
157 INITIALIZE_PASS_DEPENDENCY(AssumptionTracker) | 160 INITIALIZE_PASS_DEPENDENCY(AssumptionCacheTracker) |
158 INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfo) | 161 INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass) |
159 INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass) | 162 INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass) |
160 INITIALIZE_AG_DEPENDENCY(AliasAnalysis) | 163 INITIALIZE_AG_DEPENDENCY(AliasAnalysis) |
161 INITIALIZE_PASS_END(Lint, "lint", "Statically lint-checks LLVM IR", | 164 INITIALIZE_PASS_END(Lint, "lint", "Statically lint-checks LLVM IR", |
162 false, true) | 165 false, true) |
163 | 166 |
177 // function. | 180 // function. |
178 // | 181 // |
179 bool Lint::runOnFunction(Function &F) { | 182 bool Lint::runOnFunction(Function &F) { |
180 Mod = F.getParent(); | 183 Mod = F.getParent(); |
181 AA = &getAnalysis<AliasAnalysis>(); | 184 AA = &getAnalysis<AliasAnalysis>(); |
182 AT = &getAnalysis<AssumptionTracker>(); | 185 AC = &getAnalysis<AssumptionCacheTracker>().getAssumptionCache(F); |
183 DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree(); | 186 DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree(); |
184 DataLayoutPass *DLP = getAnalysisIfAvailable<DataLayoutPass>(); | 187 DataLayoutPass *DLP = getAnalysisIfAvailable<DataLayoutPass>(); |
185 DL = DLP ? &DLP->getDataLayout() : nullptr; | 188 DL = DLP ? &DLP->getDataLayout() : nullptr; |
186 TLI = &getAnalysis<TargetLibraryInfo>(); | 189 TLI = &getAnalysis<TargetLibraryInfoWrapperPass>().getTLI(); |
187 visit(F); | 190 visit(F); |
188 dbgs() << MessagesStr.str(); | 191 dbgs() << MessagesStr.str(); |
189 Messages.clear(); | 192 Messages.clear(); |
190 return false; | 193 return false; |
191 } | 194 } |
343 // Stackrestore doesn't read or write memory, but it sets the | 346 // Stackrestore doesn't read or write memory, but it sets the |
344 // stack pointer, which the compiler may read from or write to | 347 // stack pointer, which the compiler may read from or write to |
345 // at any time, so check it for both readability and writeability. | 348 // at any time, so check it for both readability and writeability. |
346 visitMemoryReference(I, CS.getArgument(0), AliasAnalysis::UnknownSize, | 349 visitMemoryReference(I, CS.getArgument(0), AliasAnalysis::UnknownSize, |
347 0, nullptr, MemRef::Read | MemRef::Write); | 350 0, nullptr, MemRef::Read | MemRef::Write); |
351 break; | |
352 | |
353 case Intrinsic::eh_begincatch: | |
354 visitEHBeginCatch(II); | |
355 break; | |
356 case Intrinsic::eh_endcatch: | |
357 visitEHEndCatch(II); | |
348 break; | 358 break; |
349 } | 359 } |
350 } | 360 } |
351 | 361 |
352 void Lint::visitCallInst(CallInst &I) { | 362 void Lint::visitCallInst(CallInst &I) { |
507 dyn_cast<ConstantInt>(findValue(I.getOperand(1), /*OffsetOk=*/false))) | 517 dyn_cast<ConstantInt>(findValue(I.getOperand(1), /*OffsetOk=*/false))) |
508 Assert1(CI->getValue().ult(cast<IntegerType>(I.getType())->getBitWidth()), | 518 Assert1(CI->getValue().ult(cast<IntegerType>(I.getType())->getBitWidth()), |
509 "Undefined result: Shift count out of range", &I); | 519 "Undefined result: Shift count out of range", &I); |
510 } | 520 } |
511 | 521 |
522 static bool | |
523 allPredsCameFromLandingPad(BasicBlock *BB, | |
524 SmallSet<BasicBlock *, 4> &VisitedBlocks) { | |
525 VisitedBlocks.insert(BB); | |
526 if (BB->isLandingPad()) | |
527 return true; | |
528 // If we find a block with no predecessors, the search failed. | |
529 if (pred_empty(BB)) | |
530 return false; | |
531 for (BasicBlock *Pred : predecessors(BB)) { | |
532 if (VisitedBlocks.count(Pred)) | |
533 continue; | |
534 if (!allPredsCameFromLandingPad(Pred, VisitedBlocks)) | |
535 return false; | |
536 } | |
537 return true; | |
538 } | |
539 | |
540 static bool | |
541 allSuccessorsReachEndCatch(BasicBlock *BB, BasicBlock::iterator InstBegin, | |
542 IntrinsicInst **SecondBeginCatch, | |
543 SmallSet<BasicBlock *, 4> &VisitedBlocks) { | |
544 VisitedBlocks.insert(BB); | |
545 for (BasicBlock::iterator I = InstBegin, E = BB->end(); I != E; ++I) { | |
546 IntrinsicInst *IC = dyn_cast<IntrinsicInst>(I); | |
547 if (IC && IC->getIntrinsicID() == Intrinsic::eh_endcatch) | |
548 return true; | |
549 // If we find another begincatch while looking for an endcatch, | |
550 // that's also an error. | |
551 if (IC && IC->getIntrinsicID() == Intrinsic::eh_begincatch) { | |
552 *SecondBeginCatch = IC; | |
553 return false; | |
554 } | |
555 } | |
556 | |
557 // If we reach a block with no successors while searching, the | |
558 // search has failed. | |
559 if (succ_empty(BB)) | |
560 return false; | |
561 // Otherwise, search all of the successors. | |
562 for (BasicBlock *Succ : successors(BB)) { | |
563 if (VisitedBlocks.count(Succ)) | |
564 continue; | |
565 if (!allSuccessorsReachEndCatch(Succ, Succ->begin(), SecondBeginCatch, | |
566 VisitedBlocks)) | |
567 return false; | |
568 } | |
569 return true; | |
570 } | |
571 | |
572 void Lint::visitEHBeginCatch(IntrinsicInst *II) { | |
573 // The checks in this function make a potentially dubious assumption about | |
574 // the CFG, namely that any block involved in a catch is only used for the | |
575 // catch. This will very likely be true of IR generated by a front end, | |
576 // but it may cease to be true, for example, if the IR is run through a | |
577 // pass which combines similar blocks. | |
578 // | |
579 // In general, if we encounter a block the isn't dominated by the catch | |
580 // block while we are searching the catch block's successors for a call | |
581 // to end catch intrinsic, then it is possible that it will be legal for | |
582 // a path through this block to never reach a call to llvm.eh.endcatch. | |
583 // An analogous statement could be made about our search for a landing | |
584 // pad among the catch block's predecessors. | |
585 // | |
586 // What is actually required is that no path is possible at runtime that | |
587 // reaches a call to llvm.eh.begincatch without having previously visited | |
588 // a landingpad instruction and that no path is possible at runtime that | |
589 // calls llvm.eh.begincatch and does not subsequently call llvm.eh.endcatch | |
590 // (mentally adjusting for the fact that in reality these calls will be | |
591 // removed before code generation). | |
592 // | |
593 // Because this is a lint check, we take a pessimistic approach and warn if | |
594 // the control flow is potentially incorrect. | |
595 | |
596 SmallSet<BasicBlock *, 4> VisitedBlocks; | |
597 BasicBlock *CatchBB = II->getParent(); | |
598 | |
599 // The begin catch must occur in a landing pad block or all paths | |
600 // to it must have come from a landing pad. | |
601 Assert1(allPredsCameFromLandingPad(CatchBB, VisitedBlocks), | |
602 "llvm.eh.begincatch may be reachable without passing a landingpad", | |
603 II); | |
604 | |
605 // Reset the visited block list. | |
606 VisitedBlocks.clear(); | |
607 | |
608 IntrinsicInst *SecondBeginCatch = nullptr; | |
609 | |
610 // This has to be called before it is asserted. Otherwise, the first assert | |
611 // below can never be hit. | |
612 bool EndCatchFound = allSuccessorsReachEndCatch( | |
613 CatchBB, std::next(static_cast<BasicBlock::iterator>(II)), | |
614 &SecondBeginCatch, VisitedBlocks); | |
615 Assert2( | |
616 SecondBeginCatch == nullptr, | |
617 "llvm.eh.begincatch may be called a second time before llvm.eh.endcatch", | |
618 II, SecondBeginCatch); | |
619 Assert1(EndCatchFound, | |
620 "Some paths from llvm.eh.begincatch may not reach llvm.eh.endcatch", | |
621 II); | |
622 } | |
623 | |
624 static bool allPredCameFromBeginCatch( | |
625 BasicBlock *BB, BasicBlock::reverse_iterator InstRbegin, | |
626 IntrinsicInst **SecondEndCatch, SmallSet<BasicBlock *, 4> &VisitedBlocks) { | |
627 VisitedBlocks.insert(BB); | |
628 // Look for a begincatch in this block. | |
629 for (BasicBlock::reverse_iterator RI = InstRbegin, RE = BB->rend(); RI != RE; | |
630 ++RI) { | |
631 IntrinsicInst *IC = dyn_cast<IntrinsicInst>(&*RI); | |
632 if (IC && IC->getIntrinsicID() == Intrinsic::eh_begincatch) | |
633 return true; | |
634 // If we find another end catch before we find a begin catch, that's | |
635 // an error. | |
636 if (IC && IC->getIntrinsicID() == Intrinsic::eh_endcatch) { | |
637 *SecondEndCatch = IC; | |
638 return false; | |
639 } | |
640 // If we encounter a landingpad instruction, the search failed. | |
641 if (isa<LandingPadInst>(*RI)) | |
642 return false; | |
643 } | |
644 // If while searching we find a block with no predeccesors, | |
645 // the search failed. | |
646 if (pred_empty(BB)) | |
647 return false; | |
648 // Search any predecessors we haven't seen before. | |
649 for (BasicBlock *Pred : predecessors(BB)) { | |
650 if (VisitedBlocks.count(Pred)) | |
651 continue; | |
652 if (!allPredCameFromBeginCatch(Pred, Pred->rbegin(), SecondEndCatch, | |
653 VisitedBlocks)) | |
654 return false; | |
655 } | |
656 return true; | |
657 } | |
658 | |
659 void Lint::visitEHEndCatch(IntrinsicInst *II) { | |
660 // The check in this function makes a potentially dubious assumption about | |
661 // the CFG, namely that any block involved in a catch is only used for the | |
662 // catch. This will very likely be true of IR generated by a front end, | |
663 // but it may cease to be true, for example, if the IR is run through a | |
664 // pass which combines similar blocks. | |
665 // | |
666 // In general, if we encounter a block the isn't post-dominated by the | |
667 // end catch block while we are searching the end catch block's predecessors | |
668 // for a call to the begin catch intrinsic, then it is possible that it will | |
669 // be legal for a path to reach the end catch block without ever having | |
670 // called llvm.eh.begincatch. | |
671 // | |
672 // What is actually required is that no path is possible at runtime that | |
673 // reaches a call to llvm.eh.endcatch without having previously visited | |
674 // a call to llvm.eh.begincatch (mentally adjusting for the fact that in | |
675 // reality these calls will be removed before code generation). | |
676 // | |
677 // Because this is a lint check, we take a pessimistic approach and warn if | |
678 // the control flow is potentially incorrect. | |
679 | |
680 BasicBlock *EndCatchBB = II->getParent(); | |
681 | |
682 // Alls paths to the end catch call must pass through a begin catch call. | |
683 | |
684 // If llvm.eh.begincatch wasn't called in the current block, we'll use this | |
685 // lambda to recursively look for it in predecessors. | |
686 SmallSet<BasicBlock *, 4> VisitedBlocks; | |
687 IntrinsicInst *SecondEndCatch = nullptr; | |
688 | |
689 // This has to be called before it is asserted. Otherwise, the first assert | |
690 // below can never be hit. | |
691 bool BeginCatchFound = | |
692 allPredCameFromBeginCatch(EndCatchBB, BasicBlock::reverse_iterator(II), | |
693 &SecondEndCatch, VisitedBlocks); | |
694 Assert2( | |
695 SecondEndCatch == nullptr, | |
696 "llvm.eh.endcatch may be called a second time after llvm.eh.begincatch", | |
697 II, SecondEndCatch); | |
698 Assert1( | |
699 BeginCatchFound, | |
700 "llvm.eh.endcatch may be reachable without passing llvm.eh.begincatch", | |
701 II); | |
702 } | |
703 | |
512 static bool isZero(Value *V, const DataLayout *DL, DominatorTree *DT, | 704 static bool isZero(Value *V, const DataLayout *DL, DominatorTree *DT, |
513 AssumptionTracker *AT) { | 705 AssumptionCache *AC) { |
514 // Assume undef could be zero. | 706 // Assume undef could be zero. |
515 if (isa<UndefValue>(V)) | 707 if (isa<UndefValue>(V)) |
516 return true; | 708 return true; |
517 | 709 |
518 VectorType *VecTy = dyn_cast<VectorType>(V->getType()); | 710 VectorType *VecTy = dyn_cast<VectorType>(V->getType()); |
519 if (!VecTy) { | 711 if (!VecTy) { |
520 unsigned BitWidth = V->getType()->getIntegerBitWidth(); | 712 unsigned BitWidth = V->getType()->getIntegerBitWidth(); |
521 APInt KnownZero(BitWidth, 0), KnownOne(BitWidth, 0); | 713 APInt KnownZero(BitWidth, 0), KnownOne(BitWidth, 0); |
522 computeKnownBits(V, KnownZero, KnownOne, DL, | 714 computeKnownBits(V, KnownZero, KnownOne, DL, 0, AC, |
523 0, AT, dyn_cast<Instruction>(V), DT); | 715 dyn_cast<Instruction>(V), DT); |
524 return KnownZero.isAllOnesValue(); | 716 return KnownZero.isAllOnesValue(); |
525 } | 717 } |
526 | 718 |
527 // Per-component check doesn't work with zeroinitializer | 719 // Per-component check doesn't work with zeroinitializer |
528 Constant *C = dyn_cast<Constant>(V); | 720 Constant *C = dyn_cast<Constant>(V); |
548 | 740 |
549 return false; | 741 return false; |
550 } | 742 } |
551 | 743 |
552 void Lint::visitSDiv(BinaryOperator &I) { | 744 void Lint::visitSDiv(BinaryOperator &I) { |
553 Assert1(!isZero(I.getOperand(1), DL, DT, AT), | 745 Assert1(!isZero(I.getOperand(1), DL, DT, AC), |
554 "Undefined behavior: Division by zero", &I); | 746 "Undefined behavior: Division by zero", &I); |
555 } | 747 } |
556 | 748 |
557 void Lint::visitUDiv(BinaryOperator &I) { | 749 void Lint::visitUDiv(BinaryOperator &I) { |
558 Assert1(!isZero(I.getOperand(1), DL, DT, AT), | 750 Assert1(!isZero(I.getOperand(1), DL, DT, AC), |
559 "Undefined behavior: Division by zero", &I); | 751 "Undefined behavior: Division by zero", &I); |
560 } | 752 } |
561 | 753 |
562 void Lint::visitSRem(BinaryOperator &I) { | 754 void Lint::visitSRem(BinaryOperator &I) { |
563 Assert1(!isZero(I.getOperand(1), DL, DT, AT), | 755 Assert1(!isZero(I.getOperand(1), DL, DT, AC), |
564 "Undefined behavior: Division by zero", &I); | 756 "Undefined behavior: Division by zero", &I); |
565 } | 757 } |
566 | 758 |
567 void Lint::visitURem(BinaryOperator &I) { | 759 void Lint::visitURem(BinaryOperator &I) { |
568 Assert1(!isZero(I.getOperand(1), DL, DT, AT), | 760 Assert1(!isZero(I.getOperand(1), DL, DT, AC), |
569 "Undefined behavior: Division by zero", &I); | 761 "Undefined behavior: Division by zero", &I); |
570 } | 762 } |
571 | 763 |
572 void Lint::visitAllocaInst(AllocaInst &I) { | 764 void Lint::visitAllocaInst(AllocaInst &I) { |
573 if (isa<ConstantInt>(I.getArraySize())) | 765 if (isa<ConstantInt>(I.getArraySize())) |
629 | 821 |
630 /// findValueImpl - Implementation helper for findValue. | 822 /// findValueImpl - Implementation helper for findValue. |
631 Value *Lint::findValueImpl(Value *V, bool OffsetOk, | 823 Value *Lint::findValueImpl(Value *V, bool OffsetOk, |
632 SmallPtrSetImpl<Value *> &Visited) const { | 824 SmallPtrSetImpl<Value *> &Visited) const { |
633 // Detect self-referential values. | 825 // Detect self-referential values. |
634 if (!Visited.insert(V)) | 826 if (!Visited.insert(V).second) |
635 return UndefValue::get(V->getType()); | 827 return UndefValue::get(V->getType()); |
636 | 828 |
637 // TODO: Look through sext or zext cast, when the result is known to | 829 // TODO: Look through sext or zext cast, when the result is known to |
638 // be interpreted as signed or unsigned, respectively. | 830 // be interpreted as signed or unsigned, respectively. |
639 // TODO: Look through eliminable cast pairs. | 831 // TODO: Look through eliminable cast pairs. |
643 if (LoadInst *L = dyn_cast<LoadInst>(V)) { | 835 if (LoadInst *L = dyn_cast<LoadInst>(V)) { |
644 BasicBlock::iterator BBI = L; | 836 BasicBlock::iterator BBI = L; |
645 BasicBlock *BB = L->getParent(); | 837 BasicBlock *BB = L->getParent(); |
646 SmallPtrSet<BasicBlock *, 4> VisitedBlocks; | 838 SmallPtrSet<BasicBlock *, 4> VisitedBlocks; |
647 for (;;) { | 839 for (;;) { |
648 if (!VisitedBlocks.insert(BB)) break; | 840 if (!VisitedBlocks.insert(BB).second) |
841 break; | |
649 if (Value *U = FindAvailableLoadedValue(L->getPointerOperand(), | 842 if (Value *U = FindAvailableLoadedValue(L->getPointerOperand(), |
650 BB, BBI, 6, AA)) | 843 BB, BBI, 6, AA)) |
651 return findValueImpl(U, OffsetOk, Visited); | 844 return findValueImpl(U, OffsetOk, Visited); |
652 if (BBI != BB->begin()) break; | 845 if (BBI != BB->begin()) break; |
653 BB = BB->getUniquePredecessor(); | 846 BB = BB->getUniquePredecessor(); |
683 } | 876 } |
684 } | 877 } |
685 | 878 |
686 // As a last resort, try SimplifyInstruction or constant folding. | 879 // As a last resort, try SimplifyInstruction or constant folding. |
687 if (Instruction *Inst = dyn_cast<Instruction>(V)) { | 880 if (Instruction *Inst = dyn_cast<Instruction>(V)) { |
688 if (Value *W = SimplifyInstruction(Inst, DL, TLI, DT, AT)) | 881 if (Value *W = SimplifyInstruction(Inst, DL, TLI, DT, AC)) |
689 return findValueImpl(W, OffsetOk, Visited); | 882 return findValueImpl(W, OffsetOk, Visited); |
690 } else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(V)) { | 883 } else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(V)) { |
691 if (Value *W = ConstantFoldConstantExpression(CE, DL, TLI)) | 884 if (Value *W = ConstantFoldConstantExpression(CE, DL, TLI)) |
692 if (W != V) | 885 if (W != V) |
693 return findValueImpl(W, OffsetOk, Visited); | 886 return findValueImpl(W, OffsetOk, Visited); |
708 /// | 901 /// |
709 void llvm::lintFunction(const Function &f) { | 902 void llvm::lintFunction(const Function &f) { |
710 Function &F = const_cast<Function&>(f); | 903 Function &F = const_cast<Function&>(f); |
711 assert(!F.isDeclaration() && "Cannot lint external functions"); | 904 assert(!F.isDeclaration() && "Cannot lint external functions"); |
712 | 905 |
713 FunctionPassManager FPM(F.getParent()); | 906 legacy::FunctionPassManager FPM(F.getParent()); |
714 Lint *V = new Lint(); | 907 Lint *V = new Lint(); |
715 FPM.add(V); | 908 FPM.add(V); |
716 FPM.run(F); | 909 FPM.run(F); |
717 } | 910 } |
718 | 911 |
719 /// lintModule - Check a module for errors, printing messages on stderr. | 912 /// lintModule - Check a module for errors, printing messages on stderr. |
720 /// | 913 /// |
721 void llvm::lintModule(const Module &M) { | 914 void llvm::lintModule(const Module &M) { |
722 PassManager PM; | 915 legacy::PassManager PM; |
723 Lint *V = new Lint(); | 916 Lint *V = new Lint(); |
724 PM.add(V); | 917 PM.add(V); |
725 PM.run(const_cast<Module&>(M)); | 918 PM.run(const_cast<Module&>(M)); |
726 } | 919 } |