| Nuno Lopes | a2f6cec | 2012-05-22 17:19:09 +0000 | [diff] [blame] | 1 | //===- BoundsChecking.cpp - Instrumentation for run-time bounds checking --===// | 
|  | 2 | // | 
| Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | 
|  | 4 | // See https://llvm.org/LICENSE.txt for license information. | 
|  | 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | 
| Nuno Lopes | a2f6cec | 2012-05-22 17:19:09 +0000 | [diff] [blame] | 6 | // | 
|  | 7 | //===----------------------------------------------------------------------===// | 
| Nuno Lopes | a2f6cec | 2012-05-22 17:19:09 +0000 | [diff] [blame] | 8 |  | 
| Chandler Carruth | 00a301d | 2017-11-14 01:30:04 +0000 | [diff] [blame] | 9 | #include "llvm/Transforms/Instrumentation/BoundsChecking.h" | 
| Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 10 | #include "llvm/ADT/Statistic.h" | 
| Eugene Zelenko | bff0ef0 | 2017-10-19 22:07:16 +0000 | [diff] [blame] | 11 | #include "llvm/ADT/Twine.h" | 
| Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 12 | #include "llvm/Analysis/MemoryBuiltins.h" | 
| Joel Galenson | 8dbcc58 | 2018-07-24 15:21:54 +0000 | [diff] [blame] | 13 | #include "llvm/Analysis/ScalarEvolution.h" | 
| Chandler Carruth | 452a007 | 2014-03-04 11:59:06 +0000 | [diff] [blame] | 14 | #include "llvm/Analysis/TargetFolder.h" | 
| Benjamin Kramer | 799003b | 2015-03-23 19:32:43 +0000 | [diff] [blame] | 15 | #include "llvm/Analysis/TargetLibraryInfo.h" | 
| Eugene Zelenko | bff0ef0 | 2017-10-19 22:07:16 +0000 | [diff] [blame] | 16 | #include "llvm/IR/BasicBlock.h" | 
|  | 17 | #include "llvm/IR/Constants.h" | 
| Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 18 | #include "llvm/IR/DataLayout.h" | 
| Eugene Zelenko | bff0ef0 | 2017-10-19 22:07:16 +0000 | [diff] [blame] | 19 | #include "llvm/IR/Function.h" | 
| Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 20 | #include "llvm/IR/IRBuilder.h" | 
| Chandler Carruth | 8394857 | 2014-03-04 10:30:26 +0000 | [diff] [blame] | 21 | #include "llvm/IR/InstIterator.h" | 
| Eugene Zelenko | bff0ef0 | 2017-10-19 22:07:16 +0000 | [diff] [blame] | 22 | #include "llvm/IR/InstrTypes.h" | 
|  | 23 | #include "llvm/IR/Instruction.h" | 
|  | 24 | #include "llvm/IR/Instructions.h" | 
| Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 25 | #include "llvm/IR/Intrinsics.h" | 
| Eugene Zelenko | bff0ef0 | 2017-10-19 22:07:16 +0000 | [diff] [blame] | 26 | #include "llvm/IR/Value.h" | 
| Chandler Carruth | aafe091 | 2012-06-29 12:38:19 +0000 | [diff] [blame] | 27 | #include "llvm/Pass.h" | 
| Eugene Zelenko | bff0ef0 | 2017-10-19 22:07:16 +0000 | [diff] [blame] | 28 | #include "llvm/Support/Casting.h" | 
| Nuno Lopes | 288e86ff6 | 2012-05-31 22:58:48 +0000 | [diff] [blame] | 29 | #include "llvm/Support/CommandLine.h" | 
| Nuno Lopes | a2f6cec | 2012-05-22 17:19:09 +0000 | [diff] [blame] | 30 | #include "llvm/Support/Debug.h" | 
| Eugene Zelenko | bff0ef0 | 2017-10-19 22:07:16 +0000 | [diff] [blame] | 31 | #include "llvm/Support/ErrorHandling.h" | 
| Chandler Carruth | aafe091 | 2012-06-29 12:38:19 +0000 | [diff] [blame] | 32 | #include "llvm/Support/raw_ostream.h" | 
| Eugene Zelenko | bff0ef0 | 2017-10-19 22:07:16 +0000 | [diff] [blame] | 33 | #include <cstdint> | 
|  | 34 | #include <vector> | 
|  | 35 |  | 
| Nuno Lopes | a2f6cec | 2012-05-22 17:19:09 +0000 | [diff] [blame] | 36 | using namespace llvm; | 
|  | 37 |  | 
| Chandler Carruth | 964daaa | 2014-04-22 02:55:47 +0000 | [diff] [blame] | 38 | #define DEBUG_TYPE "bounds-checking" | 
|  | 39 |  | 
| Nuno Lopes | 0e967e0 | 2012-06-21 15:59:53 +0000 | [diff] [blame] | 40 | static cl::opt<bool> SingleTrapBB("bounds-checking-single-trap", | 
|  | 41 | cl::desc("Use one trap block per function")); | 
| Nuno Lopes | 288e86ff6 | 2012-05-31 22:58:48 +0000 | [diff] [blame] | 42 |  | 
| Nuno Lopes | a2f6cec | 2012-05-22 17:19:09 +0000 | [diff] [blame] | 43 | STATISTIC(ChecksAdded, "Bounds checks added"); | 
|  | 44 | STATISTIC(ChecksSkipped, "Bounds checks skipped"); | 
|  | 45 | STATISTIC(ChecksUnable, "Bounds checks unable to add"); | 
|  | 46 |  | 
| Eugene Zelenko | bff0ef0 | 2017-10-19 22:07:16 +0000 | [diff] [blame] | 47 | using BuilderTy = IRBuilder<TargetFolder>; | 
| Nuno Lopes | a2f6cec | 2012-05-22 17:19:09 +0000 | [diff] [blame] | 48 |  | 
| Joel Galenson | cfe5bc1 | 2018-08-03 17:12:23 +0000 | [diff] [blame] | 49 | /// Gets the conditions under which memory accessing instructions will overflow. | 
| Chandler Carruth | 1594fee | 2017-11-14 01:13:59 +0000 | [diff] [blame] | 50 | /// | 
|  | 51 | /// \p Ptr is the pointer that will be read/written, and \p InstVal is either | 
|  | 52 | /// the result from the load or the value being stored. It is used to determine | 
|  | 53 | /// the size of memory block that is touched. | 
|  | 54 | /// | 
| Joel Galenson | cfe5bc1 | 2018-08-03 17:12:23 +0000 | [diff] [blame] | 55 | /// Returns the condition under which the access will overflow. | 
|  | 56 | static Value *getBoundsCheckCond(Value *Ptr, Value *InstVal, | 
|  | 57 | const DataLayout &DL, TargetLibraryInfo &TLI, | 
|  | 58 | ObjectSizeOffsetEvaluator &ObjSizeEval, | 
|  | 59 | BuilderTy &IRB, ScalarEvolution &SE) { | 
| Mehdi Amini | a28d91d | 2015-03-10 02:37:25 +0000 | [diff] [blame] | 60 | uint64_t NeededSize = DL.getTypeStoreSize(InstVal->getType()); | 
| Nicola Zaghen | d34e60c | 2018-05-14 12:53:11 +0000 | [diff] [blame] | 61 | LLVM_DEBUG(dbgs() << "Instrument " << *Ptr << " for " << Twine(NeededSize) | 
|  | 62 | << " bytes\n"); | 
| Nuno Lopes | a2f6cec | 2012-05-22 17:19:09 +0000 | [diff] [blame] | 63 |  | 
| Chandler Carruth | 1594fee | 2017-11-14 01:13:59 +0000 | [diff] [blame] | 64 | SizeOffsetEvalType SizeOffset = ObjSizeEval.compute(Ptr); | 
| Nuno Lopes | a2f6cec | 2012-05-22 17:19:09 +0000 | [diff] [blame] | 65 |  | 
| Chandler Carruth | 1594fee | 2017-11-14 01:13:59 +0000 | [diff] [blame] | 66 | if (!ObjSizeEval.bothKnown(SizeOffset)) { | 
| Nuno Lopes | a2f6cec | 2012-05-22 17:19:09 +0000 | [diff] [blame] | 67 | ++ChecksUnable; | 
| Joel Galenson | cfe5bc1 | 2018-08-03 17:12:23 +0000 | [diff] [blame] | 68 | return nullptr; | 
| Nuno Lopes | a2f6cec | 2012-05-22 17:19:09 +0000 | [diff] [blame] | 69 | } | 
| Nuno Lopes | a2f6cec | 2012-05-22 17:19:09 +0000 | [diff] [blame] | 70 |  | 
| Nuno Lopes | 0e967e0 | 2012-06-21 15:59:53 +0000 | [diff] [blame] | 71 | Value *Size   = SizeOffset.first; | 
|  | 72 | Value *Offset = SizeOffset.second; | 
| Nuno Lopes | 1e8dffd | 2012-07-03 17:30:18 +0000 | [diff] [blame] | 73 | ConstantInt *SizeCI = dyn_cast<ConstantInt>(Size); | 
| Nuno Lopes | 0e967e0 | 2012-06-21 15:59:53 +0000 | [diff] [blame] | 74 |  | 
| Mehdi Amini | a28d91d | 2015-03-10 02:37:25 +0000 | [diff] [blame] | 75 | Type *IntTy = DL.getIntPtrType(Ptr->getType()); | 
| Nuno Lopes | 0e967e0 | 2012-06-21 15:59:53 +0000 | [diff] [blame] | 76 | Value *NeededSizeVal = ConstantInt::get(IntTy, NeededSize); | 
|  | 77 |  | 
| Joel Galenson | 8dbcc58 | 2018-07-24 15:21:54 +0000 | [diff] [blame] | 78 | auto SizeRange = SE.getUnsignedRange(SE.getSCEV(Size)); | 
|  | 79 | auto OffsetRange = SE.getUnsignedRange(SE.getSCEV(Offset)); | 
|  | 80 | auto NeededSizeRange = SE.getUnsignedRange(SE.getSCEV(NeededSizeVal)); | 
|  | 81 |  | 
| Nuno Lopes | 7d00061 | 2012-05-31 22:45:40 +0000 | [diff] [blame] | 82 | // three checks are required to ensure safety: | 
|  | 83 | // . Offset >= 0  (since the offset is given from the base ptr) | 
|  | 84 | // . Size >= Offset  (unsigned) | 
|  | 85 | // . Size - Offset >= NeededSize  (unsigned) | 
| Nuno Lopes | 1e8dffd | 2012-07-03 17:30:18 +0000 | [diff] [blame] | 86 | // | 
|  | 87 | // optimization: if Size >= 0 (signed), skip 1st check | 
| Nuno Lopes | 7d00061 | 2012-05-31 22:45:40 +0000 | [diff] [blame] | 88 | // FIXME: add NSW/NUW here?  -- we dont care if the subtraction overflows | 
| Chandler Carruth | 1594fee | 2017-11-14 01:13:59 +0000 | [diff] [blame] | 89 | Value *ObjSize = IRB.CreateSub(Size, Offset); | 
| Joel Galenson | 8dbcc58 | 2018-07-24 15:21:54 +0000 | [diff] [blame] | 90 | Value *Cmp2 = SizeRange.getUnsignedMin().uge(OffsetRange.getUnsignedMax()) | 
|  | 91 | ? ConstantInt::getFalse(Ptr->getContext()) | 
|  | 92 | : IRB.CreateICmpULT(Size, Offset); | 
|  | 93 | Value *Cmp3 = SizeRange.sub(OffsetRange) | 
|  | 94 | .getUnsignedMin() | 
|  | 95 | .uge(NeededSizeRange.getUnsignedMax()) | 
|  | 96 | ? ConstantInt::getFalse(Ptr->getContext()) | 
|  | 97 | : IRB.CreateICmpULT(ObjSize, NeededSizeVal); | 
| Chandler Carruth | 1594fee | 2017-11-14 01:13:59 +0000 | [diff] [blame] | 98 | Value *Or = IRB.CreateOr(Cmp2, Cmp3); | 
| Joel Galenson | 8dbcc58 | 2018-07-24 15:21:54 +0000 | [diff] [blame] | 99 | if ((!SizeCI || SizeCI->getValue().slt(0)) && | 
|  | 100 | !SizeRange.getSignedMin().isNonNegative()) { | 
| Chandler Carruth | 1594fee | 2017-11-14 01:13:59 +0000 | [diff] [blame] | 101 | Value *Cmp1 = IRB.CreateICmpSLT(Offset, ConstantInt::get(IntTy, 0)); | 
|  | 102 | Or = IRB.CreateOr(Cmp1, Or); | 
| Nuno Lopes | 1e8dffd | 2012-07-03 17:30:18 +0000 | [diff] [blame] | 103 | } | 
| Nuno Lopes | a2f6cec | 2012-05-22 17:19:09 +0000 | [diff] [blame] | 104 |  | 
| Joel Galenson | cfe5bc1 | 2018-08-03 17:12:23 +0000 | [diff] [blame] | 105 | return Or; | 
|  | 106 | } | 
|  | 107 |  | 
|  | 108 | /// Adds run-time bounds checks to memory accessing instructions. | 
|  | 109 | /// | 
|  | 110 | /// \p Or is the condition that should guard the trap. | 
|  | 111 | /// | 
|  | 112 | /// \p GetTrapBB is a callable that returns the trap BB to use on failure. | 
|  | 113 | template <typename GetTrapBBT> | 
|  | 114 | static void insertBoundsCheck(Value *Or, BuilderTy IRB, GetTrapBBT GetTrapBB) { | 
| Chandler Carruth | 3f0e056 | 2017-10-18 22:42:36 +0000 | [diff] [blame] | 115 | // check if the comparison is always false | 
|  | 116 | ConstantInt *C = dyn_cast_or_null<ConstantInt>(Or); | 
|  | 117 | if (C) { | 
|  | 118 | ++ChecksSkipped; | 
|  | 119 | // If non-zero, nothing to do. | 
|  | 120 | if (!C->getZExtValue()) | 
| Joel Galenson | cfe5bc1 | 2018-08-03 17:12:23 +0000 | [diff] [blame] | 121 | return; | 
| Chandler Carruth | 3f0e056 | 2017-10-18 22:42:36 +0000 | [diff] [blame] | 122 | } | 
|  | 123 | ++ChecksAdded; | 
|  | 124 |  | 
| Chandler Carruth | 1594fee | 2017-11-14 01:13:59 +0000 | [diff] [blame] | 125 | BasicBlock::iterator SplitI = IRB.GetInsertPoint(); | 
| Chandler Carruth | 3f0e056 | 2017-10-18 22:42:36 +0000 | [diff] [blame] | 126 | BasicBlock *OldBB = SplitI->getParent(); | 
|  | 127 | BasicBlock *Cont = OldBB->splitBasicBlock(SplitI); | 
|  | 128 | OldBB->getTerminator()->eraseFromParent(); | 
|  | 129 |  | 
|  | 130 | if (C) { | 
|  | 131 | // If we have a constant zero, unconditionally branch. | 
|  | 132 | // FIXME: We should really handle this differently to bypass the splitting | 
|  | 133 | // the block. | 
| Chandler Carruth | 1594fee | 2017-11-14 01:13:59 +0000 | [diff] [blame] | 134 | BranchInst::Create(GetTrapBB(IRB), OldBB); | 
| Joel Galenson | cfe5bc1 | 2018-08-03 17:12:23 +0000 | [diff] [blame] | 135 | return; | 
| Chandler Carruth | 3f0e056 | 2017-10-18 22:42:36 +0000 | [diff] [blame] | 136 | } | 
|  | 137 |  | 
|  | 138 | // Create the conditional branch. | 
| Chandler Carruth | 1594fee | 2017-11-14 01:13:59 +0000 | [diff] [blame] | 139 | BranchInst::Create(GetTrapBB(IRB), Cont, Or, OldBB); | 
| Nuno Lopes | a2f6cec | 2012-05-22 17:19:09 +0000 | [diff] [blame] | 140 | } | 
|  | 141 |  | 
| Joel Galenson | 8dbcc58 | 2018-07-24 15:21:54 +0000 | [diff] [blame] | 142 | static bool addBoundsChecking(Function &F, TargetLibraryInfo &TLI, | 
|  | 143 | ScalarEvolution &SE) { | 
| Mehdi Amini | a28d91d | 2015-03-10 02:37:25 +0000 | [diff] [blame] | 144 | const DataLayout &DL = F.getParent()->getDataLayout(); | 
| Erik Pilkington | 600e9de | 2019-01-30 20:34:35 +0000 | [diff] [blame] | 145 | ObjectSizeOpts EvalOpts; | 
|  | 146 | EvalOpts.RoundToAlign = true; | 
|  | 147 | ObjectSizeOffsetEvaluator ObjSizeEval(DL, &TLI, F.getContext(), EvalOpts); | 
| Nuno Lopes | a2f6cec | 2012-05-22 17:19:09 +0000 | [diff] [blame] | 148 |  | 
|  | 149 | // check HANDLE_MEMORY_INST in include/llvm/Instruction.def for memory | 
|  | 150 | // touching instructions | 
| Joel Galenson | cfe5bc1 | 2018-08-03 17:12:23 +0000 | [diff] [blame] | 151 | SmallVector<std::pair<Instruction *, Value *>, 4> TrapInfo; | 
| Chandler Carruth | 1594fee | 2017-11-14 01:13:59 +0000 | [diff] [blame] | 152 | for (Instruction &I : instructions(F)) { | 
| Joel Galenson | cfe5bc1 | 2018-08-03 17:12:23 +0000 | [diff] [blame] | 153 | Value *Or = nullptr; | 
|  | 154 | BuilderTy IRB(I.getParent(), BasicBlock::iterator(&I), TargetFolder(DL)); | 
|  | 155 | if (LoadInst *LI = dyn_cast<LoadInst>(&I)) { | 
|  | 156 | Or = getBoundsCheckCond(LI->getPointerOperand(), LI, DL, TLI, | 
|  | 157 | ObjSizeEval, IRB, SE); | 
|  | 158 | } else if (StoreInst *SI = dyn_cast<StoreInst>(&I)) { | 
|  | 159 | Or = getBoundsCheckCond(SI->getPointerOperand(), SI->getValueOperand(), | 
|  | 160 | DL, TLI, ObjSizeEval, IRB, SE); | 
|  | 161 | } else if (AtomicCmpXchgInst *AI = dyn_cast<AtomicCmpXchgInst>(&I)) { | 
|  | 162 | Or = getBoundsCheckCond(AI->getPointerOperand(), AI->getCompareOperand(), | 
|  | 163 | DL, TLI, ObjSizeEval, IRB, SE); | 
|  | 164 | } else if (AtomicRMWInst *AI = dyn_cast<AtomicRMWInst>(&I)) { | 
|  | 165 | Or = getBoundsCheckCond(AI->getPointerOperand(), AI->getValOperand(), DL, | 
|  | 166 | TLI, ObjSizeEval, IRB, SE); | 
|  | 167 | } | 
|  | 168 | if (Or) | 
|  | 169 | TrapInfo.push_back(std::make_pair(&I, Or)); | 
| Nuno Lopes | a2f6cec | 2012-05-22 17:19:09 +0000 | [diff] [blame] | 170 | } | 
|  | 171 |  | 
| Chandler Carruth | 1594fee | 2017-11-14 01:13:59 +0000 | [diff] [blame] | 172 | // Create a trapping basic block on demand using a callback. Depending on | 
|  | 173 | // flags, this will either create a single block for the entire function or | 
|  | 174 | // will create a fresh block every time it is called. | 
|  | 175 | BasicBlock *TrapBB = nullptr; | 
|  | 176 | auto GetTrapBB = [&TrapBB](BuilderTy &IRB) { | 
|  | 177 | if (TrapBB && SingleTrapBB) | 
|  | 178 | return TrapBB; | 
| Nuno Lopes | a2f6cec | 2012-05-22 17:19:09 +0000 | [diff] [blame] | 179 |  | 
| Chandler Carruth | 1594fee | 2017-11-14 01:13:59 +0000 | [diff] [blame] | 180 | Function *Fn = IRB.GetInsertBlock()->getParent(); | 
|  | 181 | // FIXME: This debug location doesn't make a lot of sense in the | 
|  | 182 | // `SingleTrapBB` case. | 
|  | 183 | auto DebugLoc = IRB.getCurrentDebugLocation(); | 
|  | 184 | IRBuilder<>::InsertPointGuard Guard(IRB); | 
|  | 185 | TrapBB = BasicBlock::Create(Fn->getContext(), "trap", Fn); | 
|  | 186 | IRB.SetInsertPoint(TrapBB); | 
|  | 187 |  | 
|  | 188 | auto *F = Intrinsic::getDeclaration(Fn->getParent(), Intrinsic::trap); | 
|  | 189 | CallInst *TrapCall = IRB.CreateCall(F, {}); | 
|  | 190 | TrapCall->setDoesNotReturn(); | 
|  | 191 | TrapCall->setDoesNotThrow(); | 
|  | 192 | TrapCall->setDebugLoc(DebugLoc); | 
|  | 193 | IRB.CreateUnreachable(); | 
|  | 194 |  | 
|  | 195 | return TrapBB; | 
|  | 196 | }; | 
|  | 197 |  | 
| Joel Galenson | cfe5bc1 | 2018-08-03 17:12:23 +0000 | [diff] [blame] | 198 | // Add the checks. | 
|  | 199 | for (const auto &Entry : TrapInfo) { | 
|  | 200 | Instruction *Inst = Entry.first; | 
| Chandler Carruth | 1594fee | 2017-11-14 01:13:59 +0000 | [diff] [blame] | 201 | BuilderTy IRB(Inst->getParent(), BasicBlock::iterator(Inst), TargetFolder(DL)); | 
| Joel Galenson | cfe5bc1 | 2018-08-03 17:12:23 +0000 | [diff] [blame] | 202 | insertBoundsCheck(Entry.second, IRB, GetTrapBB); | 
| Nuno Lopes | a2f6cec | 2012-05-22 17:19:09 +0000 | [diff] [blame] | 203 | } | 
| Joel Galenson | cfe5bc1 | 2018-08-03 17:12:23 +0000 | [diff] [blame] | 204 |  | 
|  | 205 | return !TrapInfo.empty(); | 
| Nuno Lopes | a2f6cec | 2012-05-22 17:19:09 +0000 | [diff] [blame] | 206 | } | 
|  | 207 |  | 
| Chandler Carruth | 00a301d | 2017-11-14 01:30:04 +0000 | [diff] [blame] | 208 | PreservedAnalyses BoundsCheckingPass::run(Function &F, FunctionAnalysisManager &AM) { | 
|  | 209 | auto &TLI = AM.getResult<TargetLibraryAnalysis>(F); | 
| Joel Galenson | 8dbcc58 | 2018-07-24 15:21:54 +0000 | [diff] [blame] | 210 | auto &SE = AM.getResult<ScalarEvolutionAnalysis>(F); | 
| Chandler Carruth | 00a301d | 2017-11-14 01:30:04 +0000 | [diff] [blame] | 211 |  | 
| Joel Galenson | 8dbcc58 | 2018-07-24 15:21:54 +0000 | [diff] [blame] | 212 | if (!addBoundsChecking(F, TLI, SE)) | 
| Chandler Carruth | 00a301d | 2017-11-14 01:30:04 +0000 | [diff] [blame] | 213 | return PreservedAnalyses::all(); | 
|  | 214 |  | 
|  | 215 | return PreservedAnalyses::none(); | 
|  | 216 | } | 
|  | 217 |  | 
|  | 218 | namespace { | 
|  | 219 | struct BoundsCheckingLegacyPass : public FunctionPass { | 
|  | 220 | static char ID; | 
|  | 221 |  | 
|  | 222 | BoundsCheckingLegacyPass() : FunctionPass(ID) { | 
|  | 223 | initializeBoundsCheckingLegacyPassPass(*PassRegistry::getPassRegistry()); | 
|  | 224 | } | 
|  | 225 |  | 
|  | 226 | bool runOnFunction(Function &F) override { | 
|  | 227 | auto &TLI = getAnalysis<TargetLibraryInfoWrapperPass>().getTLI(); | 
| Joel Galenson | 8dbcc58 | 2018-07-24 15:21:54 +0000 | [diff] [blame] | 228 | auto &SE = getAnalysis<ScalarEvolutionWrapperPass>().getSE(); | 
|  | 229 | return addBoundsChecking(F, TLI, SE); | 
| Chandler Carruth | 00a301d | 2017-11-14 01:30:04 +0000 | [diff] [blame] | 230 | } | 
|  | 231 |  | 
|  | 232 | void getAnalysisUsage(AnalysisUsage &AU) const override { | 
|  | 233 | AU.addRequired<TargetLibraryInfoWrapperPass>(); | 
| Joel Galenson | 8dbcc58 | 2018-07-24 15:21:54 +0000 | [diff] [blame] | 234 | AU.addRequired<ScalarEvolutionWrapperPass>(); | 
| Chandler Carruth | 00a301d | 2017-11-14 01:30:04 +0000 | [diff] [blame] | 235 | } | 
|  | 236 | }; | 
|  | 237 | } // namespace | 
|  | 238 |  | 
|  | 239 | char BoundsCheckingLegacyPass::ID = 0; | 
|  | 240 | INITIALIZE_PASS_BEGIN(BoundsCheckingLegacyPass, "bounds-checking", | 
|  | 241 | "Run-time bounds checking", false, false) | 
|  | 242 | INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass) | 
|  | 243 | INITIALIZE_PASS_END(BoundsCheckingLegacyPass, "bounds-checking", | 
|  | 244 | "Run-time bounds checking", false, false) | 
|  | 245 |  | 
|  | 246 | FunctionPass *llvm::createBoundsCheckingLegacyPass() { | 
|  | 247 | return new BoundsCheckingLegacyPass(); | 
| Nuno Lopes | a2f6cec | 2012-05-22 17:19:09 +0000 | [diff] [blame] | 248 | } |