Nick Lewycky | 7ed1dbf | 2013-06-10 23:10:59 +0000 | [diff] [blame] | 1 | //===- MemoryDependenceAnalysis.cpp - Mem Deps Implementation -------------===// |
Owen Anderson | c0daf5f | 2007-07-06 23:14:35 +0000 | [diff] [blame] | 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | f3ebc3f | 2007-12-29 20:36:04 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Owen Anderson | c0daf5f | 2007-07-06 23:14:35 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file implements an analysis that determines, for a given memory |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 11 | // operation, what preceding memory operations it depends on. It builds on |
Owen Anderson | fa78835 | 2007-08-08 22:01:54 +0000 | [diff] [blame] | 12 | // alias analysis information, and tries to provide a lazy, caching interface to |
Owen Anderson | c0daf5f | 2007-07-06 23:14:35 +0000 | [diff] [blame] | 13 | // a common kind of alias information query. |
| 14 | // |
| 15 | //===----------------------------------------------------------------------===// |
| 16 | |
| 17 | #include "llvm/Analysis/MemoryDependenceAnalysis.h" |
Eugene Zelenko | 1804a77 | 2016-08-25 00:45:04 +0000 | [diff] [blame] | 18 | #include "llvm/ADT/SmallSet.h" |
| 19 | #include "llvm/ADT/SmallVector.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 20 | #include "llvm/ADT/STLExtras.h" |
| 21 | #include "llvm/ADT/Statistic.h" |
Owen Anderson | c0daf5f | 2007-07-06 23:14:35 +0000 | [diff] [blame] | 22 | #include "llvm/Analysis/AliasAnalysis.h" |
Daniel Jasper | aec2fa3 | 2016-12-19 08:22:17 +0000 | [diff] [blame] | 23 | #include "llvm/Analysis/AssumptionCache.h" |
Victor Hernandez | f390e04 | 2009-10-27 20:05:49 +0000 | [diff] [blame] | 24 | #include "llvm/Analysis/MemoryBuiltins.h" |
Chris Lattner | 972e6d8 | 2009-12-09 01:59:31 +0000 | [diff] [blame] | 25 | #include "llvm/Analysis/PHITransAddr.h" |
Bruno Cardoso Lopes | dfc1d96 | 2015-07-31 14:31:35 +0000 | [diff] [blame] | 26 | #include "llvm/Analysis/OrderedBasicBlock.h" |
Dan Gohman | a4fcd24 | 2010-12-15 20:02:24 +0000 | [diff] [blame] | 27 | #include "llvm/Analysis/ValueTracking.h" |
Chandler Carruth | d06034d | 2015-08-12 17:47:44 +0000 | [diff] [blame] | 28 | #include "llvm/Analysis/TargetLibraryInfo.h" |
Eugene Zelenko | 1804a77 | 2016-08-25 00:45:04 +0000 | [diff] [blame] | 29 | #include "llvm/IR/CallSite.h" |
| 30 | #include "llvm/IR/Constants.h" |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 31 | #include "llvm/IR/DataLayout.h" |
Eugene Zelenko | 1804a77 | 2016-08-25 00:45:04 +0000 | [diff] [blame] | 32 | #include "llvm/IR/DerivedTypes.h" |
Chandler Carruth | 5ad5f15 | 2014-01-13 09:26:24 +0000 | [diff] [blame] | 33 | #include "llvm/IR/Dominators.h" |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 34 | #include "llvm/IR/Function.h" |
Eugene Zelenko | 1804a77 | 2016-08-25 00:45:04 +0000 | [diff] [blame] | 35 | #include "llvm/IR/Instruction.h" |
Chandler Carruth | 9fb823b | 2013-01-02 11:36:10 +0000 | [diff] [blame] | 36 | #include "llvm/IR/Instructions.h" |
| 37 | #include "llvm/IR/IntrinsicInst.h" |
| 38 | #include "llvm/IR/LLVMContext.h" |
Chandler Carruth | aa0ab63 | 2014-03-04 12:09:19 +0000 | [diff] [blame] | 39 | #include "llvm/IR/PredIteratorCache.h" |
Eugene Zelenko | 1804a77 | 2016-08-25 00:45:04 +0000 | [diff] [blame] | 40 | #include "llvm/Support/AtomicOrdering.h" |
| 41 | #include "llvm/Support/Casting.h" |
| 42 | #include "llvm/Support/CommandLine.h" |
| 43 | #include "llvm/Support/Compiler.h" |
Chandler Carruth | ed0881b | 2012-12-03 16:50:05 +0000 | [diff] [blame] | 44 | #include "llvm/Support/Debug.h" |
Eugene Zelenko | 1804a77 | 2016-08-25 00:45:04 +0000 | [diff] [blame] | 45 | #include "llvm/Support/MathExtras.h" |
| 46 | #include <algorithm> |
| 47 | #include <cassert> |
| 48 | #include <iterator> |
| 49 | |
Owen Anderson | c0daf5f | 2007-07-06 23:14:35 +0000 | [diff] [blame] | 50 | using namespace llvm; |
| 51 | |
Chandler Carruth | f1221bd | 2014-04-22 02:48:03 +0000 | [diff] [blame] | 52 | #define DEBUG_TYPE "memdep" |
| 53 | |
Chris Lattner | 7e61daf | 2008-12-01 01:15:42 +0000 | [diff] [blame] | 54 | STATISTIC(NumCacheNonLocal, "Number of fully cached non-local responses"); |
| 55 | STATISTIC(NumCacheDirtyNonLocal, "Number of dirty cached non-local responses"); |
Chris Lattner | e7d7e13 | 2008-11-29 22:02:15 +0000 | [diff] [blame] | 56 | STATISTIC(NumUncacheNonLocal, "Number of uncached non-local responses"); |
Chris Lattner | a28355d | 2008-12-07 08:50:20 +0000 | [diff] [blame] | 57 | |
| 58 | STATISTIC(NumCacheNonLocalPtr, |
| 59 | "Number of fully cached non-local ptr responses"); |
| 60 | STATISTIC(NumCacheDirtyNonLocalPtr, |
| 61 | "Number of cached, but dirty, non-local ptr responses"); |
Chandler Carruth | 60fb1b4 | 2016-03-07 10:19:30 +0000 | [diff] [blame] | 62 | STATISTIC(NumUncacheNonLocalPtr, "Number of uncached non-local ptr responses"); |
Chris Lattner | 5ed409e | 2008-12-08 07:31:50 +0000 | [diff] [blame] | 63 | STATISTIC(NumCacheCompleteNonLocalPtr, |
| 64 | "Number of block queries that were completely cached"); |
Chris Lattner | a28355d | 2008-12-07 08:50:20 +0000 | [diff] [blame] | 65 | |
Eli Friedman | 8b098b0 | 2011-06-15 23:59:25 +0000 | [diff] [blame] | 66 | // Limit for the number of instructions to scan in a block. |
Jingyue Wu | d058ea9 | 2015-07-21 21:50:39 +0000 | [diff] [blame] | 67 | |
| 68 | static cl::opt<unsigned> BlockScanLimit( |
| 69 | "memdep-block-scan-limit", cl::Hidden, cl::init(100), |
| 70 | cl::desc("The number of instructions to scan in a block in memory " |
| 71 | "dependency analysis (default = 100)")); |
Eli Friedman | 8b098b0 | 2011-06-15 23:59:25 +0000 | [diff] [blame] | 72 | |
Chandler Carruth | 60fb1b4 | 2016-03-07 10:19:30 +0000 | [diff] [blame] | 73 | static cl::opt<unsigned> |
| 74 | BlockNumberLimit("memdep-block-number-limit", cl::Hidden, cl::init(1000), |
| 75 | cl::desc("The number of blocks to scan during memory " |
| 76 | "dependency analysis (default = 1000)")); |
Joerg Sonnenberger | 36894dc | 2016-02-20 11:24:44 +0000 | [diff] [blame] | 77 | |
Bruno Cardoso Lopes | e3c513a | 2014-10-01 20:07:13 +0000 | [diff] [blame] | 78 | // Limit on the number of memdep results to process. |
Aaron Ballman | 254dd7e | 2014-10-02 13:17:11 +0000 | [diff] [blame] | 79 | static const unsigned int NumResultsLimit = 100; |
Bruno Cardoso Lopes | e3c513a | 2014-10-01 20:07:13 +0000 | [diff] [blame] | 80 | |
Chandler Carruth | 40e21f2 | 2016-03-07 12:30:06 +0000 | [diff] [blame] | 81 | /// This is a helper function that removes Val from 'Inst's set in ReverseMap. |
| 82 | /// |
| 83 | /// If the set becomes empty, remove Inst's entry. |
Chris Lattner | de4440c | 2008-12-07 18:39:13 +0000 | [diff] [blame] | 84 | template <typename KeyTy> |
Chandler Carruth | 60fb1b4 | 2016-03-07 10:19:30 +0000 | [diff] [blame] | 85 | static void |
| 86 | RemoveFromReverseMap(DenseMap<Instruction *, SmallPtrSet<KeyTy, 4>> &ReverseMap, |
| 87 | Instruction *Inst, KeyTy Val) { |
| 88 | typename DenseMap<Instruction *, SmallPtrSet<KeyTy, 4>>::iterator InstIt = |
| 89 | ReverseMap.find(Inst); |
Chris Lattner | de4440c | 2008-12-07 18:39:13 +0000 | [diff] [blame] | 90 | assert(InstIt != ReverseMap.end() && "Reverse map out of sync?"); |
| 91 | bool Found = InstIt->second.erase(Val); |
Chandler Carruth | 60fb1b4 | 2016-03-07 10:19:30 +0000 | [diff] [blame] | 92 | assert(Found && "Invalid reverse map!"); |
| 93 | (void)Found; |
Chris Lattner | de4440c | 2008-12-07 18:39:13 +0000 | [diff] [blame] | 94 | if (InstIt->second.empty()) |
| 95 | ReverseMap.erase(InstIt); |
| 96 | } |
| 97 | |
Chandler Carruth | 40e21f2 | 2016-03-07 12:30:06 +0000 | [diff] [blame] | 98 | /// If the given instruction references a specific memory location, fill in Loc |
| 99 | /// with the details, otherwise set Loc.Ptr to null. |
| 100 | /// |
| 101 | /// Returns a ModRefInfo value describing the general behavior of the |
Dan Gohman | 1d760ce | 2010-11-10 21:51:35 +0000 | [diff] [blame] | 102 | /// instruction. |
Chandler Carruth | 194f59c | 2015-07-22 23:15:57 +0000 | [diff] [blame] | 103 | static ModRefInfo GetLocation(const Instruction *Inst, MemoryLocation &Loc, |
Chandler Carruth | d06034d | 2015-08-12 17:47:44 +0000 | [diff] [blame] | 104 | const TargetLibraryInfo &TLI) { |
Dan Gohman | 1d760ce | 2010-11-10 21:51:35 +0000 | [diff] [blame] | 105 | if (const LoadInst *LI = dyn_cast<LoadInst>(Inst)) { |
Eli Friedman | 5494ada | 2011-08-15 20:54:19 +0000 | [diff] [blame] | 106 | if (LI->isUnordered()) { |
Chandler Carruth | 70c61c1 | 2015-06-04 02:03:15 +0000 | [diff] [blame] | 107 | Loc = MemoryLocation::get(LI); |
Chandler Carruth | 194f59c | 2015-07-22 23:15:57 +0000 | [diff] [blame] | 108 | return MRI_Ref; |
Jakub Staszak | fa41def | 2013-03-20 23:53:45 +0000 | [diff] [blame] | 109 | } |
JF Bastien | 800f87a | 2016-04-06 21:19:33 +0000 | [diff] [blame] | 110 | if (LI->getOrdering() == AtomicOrdering::Monotonic) { |
Chandler Carruth | 70c61c1 | 2015-06-04 02:03:15 +0000 | [diff] [blame] | 111 | Loc = MemoryLocation::get(LI); |
Chandler Carruth | 194f59c | 2015-07-22 23:15:57 +0000 | [diff] [blame] | 112 | return MRI_ModRef; |
Dan Gohman | 1d760ce | 2010-11-10 21:51:35 +0000 | [diff] [blame] | 113 | } |
Chandler Carruth | ac80dc7 | 2015-06-17 07:18:54 +0000 | [diff] [blame] | 114 | Loc = MemoryLocation(); |
Chandler Carruth | 194f59c | 2015-07-22 23:15:57 +0000 | [diff] [blame] | 115 | return MRI_ModRef; |
Dan Gohman | 1d760ce | 2010-11-10 21:51:35 +0000 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | if (const StoreInst *SI = dyn_cast<StoreInst>(Inst)) { |
Eli Friedman | 5494ada | 2011-08-15 20:54:19 +0000 | [diff] [blame] | 119 | if (SI->isUnordered()) { |
Chandler Carruth | 70c61c1 | 2015-06-04 02:03:15 +0000 | [diff] [blame] | 120 | Loc = MemoryLocation::get(SI); |
Chandler Carruth | 194f59c | 2015-07-22 23:15:57 +0000 | [diff] [blame] | 121 | return MRI_Mod; |
Jakub Staszak | fa41def | 2013-03-20 23:53:45 +0000 | [diff] [blame] | 122 | } |
JF Bastien | 800f87a | 2016-04-06 21:19:33 +0000 | [diff] [blame] | 123 | if (SI->getOrdering() == AtomicOrdering::Monotonic) { |
Chandler Carruth | 70c61c1 | 2015-06-04 02:03:15 +0000 | [diff] [blame] | 124 | Loc = MemoryLocation::get(SI); |
Chandler Carruth | 194f59c | 2015-07-22 23:15:57 +0000 | [diff] [blame] | 125 | return MRI_ModRef; |
Dan Gohman | 1d760ce | 2010-11-10 21:51:35 +0000 | [diff] [blame] | 126 | } |
Chandler Carruth | ac80dc7 | 2015-06-17 07:18:54 +0000 | [diff] [blame] | 127 | Loc = MemoryLocation(); |
Chandler Carruth | 194f59c | 2015-07-22 23:15:57 +0000 | [diff] [blame] | 128 | return MRI_ModRef; |
Dan Gohman | 1d760ce | 2010-11-10 21:51:35 +0000 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | if (const VAArgInst *V = dyn_cast<VAArgInst>(Inst)) { |
Chandler Carruth | 70c61c1 | 2015-06-04 02:03:15 +0000 | [diff] [blame] | 132 | Loc = MemoryLocation::get(V); |
Chandler Carruth | 194f59c | 2015-07-22 23:15:57 +0000 | [diff] [blame] | 133 | return MRI_ModRef; |
Dan Gohman | 1d760ce | 2010-11-10 21:51:35 +0000 | [diff] [blame] | 134 | } |
| 135 | |
Chandler Carruth | d06034d | 2015-08-12 17:47:44 +0000 | [diff] [blame] | 136 | if (const CallInst *CI = isFreeCall(Inst, &TLI)) { |
Dan Gohman | 1d760ce | 2010-11-10 21:51:35 +0000 | [diff] [blame] | 137 | // calls to free() deallocate the entire structure |
Chandler Carruth | ac80dc7 | 2015-06-17 07:18:54 +0000 | [diff] [blame] | 138 | Loc = MemoryLocation(CI->getArgOperand(0)); |
Chandler Carruth | 194f59c | 2015-07-22 23:15:57 +0000 | [diff] [blame] | 139 | return MRI_Mod; |
Dan Gohman | 1d760ce | 2010-11-10 21:51:35 +0000 | [diff] [blame] | 140 | } |
| 141 | |
Hal Finkel | cc39b67 | 2014-07-24 12:16:19 +0000 | [diff] [blame] | 142 | if (const IntrinsicInst *II = dyn_cast<IntrinsicInst>(Inst)) { |
| 143 | AAMDNodes AAInfo; |
| 144 | |
Dan Gohman | 1d760ce | 2010-11-10 21:51:35 +0000 | [diff] [blame] | 145 | switch (II->getIntrinsicID()) { |
| 146 | case Intrinsic::lifetime_start: |
| 147 | case Intrinsic::lifetime_end: |
| 148 | case Intrinsic::invariant_start: |
Hal Finkel | cc39b67 | 2014-07-24 12:16:19 +0000 | [diff] [blame] | 149 | II->getAAMetadata(AAInfo); |
Chandler Carruth | ac80dc7 | 2015-06-17 07:18:54 +0000 | [diff] [blame] | 150 | Loc = MemoryLocation( |
| 151 | II->getArgOperand(1), |
| 152 | cast<ConstantInt>(II->getArgOperand(0))->getZExtValue(), AAInfo); |
Dan Gohman | 1d760ce | 2010-11-10 21:51:35 +0000 | [diff] [blame] | 153 | // These intrinsics don't really modify the memory, but returning Mod |
| 154 | // will allow them to be handled conservatively. |
Chandler Carruth | 194f59c | 2015-07-22 23:15:57 +0000 | [diff] [blame] | 155 | return MRI_Mod; |
Dan Gohman | 1d760ce | 2010-11-10 21:51:35 +0000 | [diff] [blame] | 156 | case Intrinsic::invariant_end: |
Hal Finkel | cc39b67 | 2014-07-24 12:16:19 +0000 | [diff] [blame] | 157 | II->getAAMetadata(AAInfo); |
Chandler Carruth | ac80dc7 | 2015-06-17 07:18:54 +0000 | [diff] [blame] | 158 | Loc = MemoryLocation( |
| 159 | II->getArgOperand(2), |
| 160 | cast<ConstantInt>(II->getArgOperand(1))->getZExtValue(), AAInfo); |
Dan Gohman | 1d760ce | 2010-11-10 21:51:35 +0000 | [diff] [blame] | 161 | // These intrinsics don't really modify the memory, but returning Mod |
| 162 | // will allow them to be handled conservatively. |
Chandler Carruth | 194f59c | 2015-07-22 23:15:57 +0000 | [diff] [blame] | 163 | return MRI_Mod; |
Dan Gohman | 1d760ce | 2010-11-10 21:51:35 +0000 | [diff] [blame] | 164 | default: |
| 165 | break; |
| 166 | } |
Hal Finkel | cc39b67 | 2014-07-24 12:16:19 +0000 | [diff] [blame] | 167 | } |
Dan Gohman | 1d760ce | 2010-11-10 21:51:35 +0000 | [diff] [blame] | 168 | |
| 169 | // Otherwise, just do the coarse-grained thing that always works. |
| 170 | if (Inst->mayWriteToMemory()) |
Chandler Carruth | 194f59c | 2015-07-22 23:15:57 +0000 | [diff] [blame] | 171 | return MRI_ModRef; |
Dan Gohman | 1d760ce | 2010-11-10 21:51:35 +0000 | [diff] [blame] | 172 | if (Inst->mayReadFromMemory()) |
Chandler Carruth | 194f59c | 2015-07-22 23:15:57 +0000 | [diff] [blame] | 173 | return MRI_Ref; |
| 174 | return MRI_NoModRef; |
Dan Gohman | 1d760ce | 2010-11-10 21:51:35 +0000 | [diff] [blame] | 175 | } |
Chris Lattner | 7e61daf | 2008-12-01 01:15:42 +0000 | [diff] [blame] | 176 | |
Chandler Carruth | 40e21f2 | 2016-03-07 12:30:06 +0000 | [diff] [blame] | 177 | /// Private helper for finding the local dependencies of a call site. |
Chandler Carruth | 61440d2 | 2016-03-10 00:55:30 +0000 | [diff] [blame] | 178 | MemDepResult MemoryDependenceResults::getCallSiteDependencyFrom( |
Chandler Carruth | 60fb1b4 | 2016-03-07 10:19:30 +0000 | [diff] [blame] | 179 | CallSite CS, bool isReadOnlyCall, BasicBlock::iterator ScanIt, |
| 180 | BasicBlock *BB) { |
Eli Friedman | 8b098b0 | 2011-06-15 23:59:25 +0000 | [diff] [blame] | 181 | unsigned Limit = BlockScanLimit; |
| 182 | |
Henric Karlsson | 54a53bd | 2016-10-06 10:58:41 +0000 | [diff] [blame] | 183 | // Walk backwards through the block, looking for dependencies. |
Chris Lattner | 51ba8d0 | 2008-11-29 03:47:00 +0000 | [diff] [blame] | 184 | while (ScanIt != BB->begin()) { |
Eli Friedman | 8b098b0 | 2011-06-15 23:59:25 +0000 | [diff] [blame] | 185 | // Limit the amount of scanning we do so we don't end up with quadratic |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 186 | // running time on extreme testcases. |
Eli Friedman | 8b098b0 | 2011-06-15 23:59:25 +0000 | [diff] [blame] | 187 | --Limit; |
| 188 | if (!Limit) |
| 189 | return MemDepResult::getUnknown(); |
| 190 | |
Duncan P. N. Exon Smith | 5a82c91 | 2015-10-10 00:53:03 +0000 | [diff] [blame] | 191 | Instruction *Inst = &*--ScanIt; |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 192 | |
Owen Anderson | 9c88457 | 2007-07-10 17:59:22 +0000 | [diff] [blame] | 193 | // If this inst is a memory op, get the pointer it accessed |
Chandler Carruth | ac80dc7 | 2015-06-17 07:18:54 +0000 | [diff] [blame] | 194 | MemoryLocation Loc; |
Chandler Carruth | 61440d2 | 2016-03-10 00:55:30 +0000 | [diff] [blame] | 195 | ModRefInfo MR = GetLocation(Inst, Loc, TLI); |
Dan Gohman | 1d760ce | 2010-11-10 21:51:35 +0000 | [diff] [blame] | 196 | if (Loc.Ptr) { |
| 197 | // A simple instruction. |
Chandler Carruth | 61440d2 | 2016-03-10 00:55:30 +0000 | [diff] [blame] | 198 | if (AA.getModRefInfo(CS, Loc) != MRI_NoModRef) |
Dan Gohman | 1d760ce | 2010-11-10 21:51:35 +0000 | [diff] [blame] | 199 | return MemDepResult::getClobber(Inst); |
| 200 | continue; |
| 201 | } |
| 202 | |
Benjamin Kramer | 3a09ef6 | 2015-04-10 14:50:08 +0000 | [diff] [blame] | 203 | if (auto InstCS = CallSite(Inst)) { |
Owen Anderson | f9a9cf9 | 2009-03-09 05:12:38 +0000 | [diff] [blame] | 204 | // Debug intrinsics don't cause dependences. |
Chandler Carruth | 60fb1b4 | 2016-03-07 10:19:30 +0000 | [diff] [blame] | 205 | if (isa<DbgInfoIntrinsic>(Inst)) |
| 206 | continue; |
Chris Lattner | 0e3d633 | 2008-12-05 21:04:20 +0000 | [diff] [blame] | 207 | // If these two calls do not interfere, look past it. |
Chandler Carruth | 61440d2 | 2016-03-10 00:55:30 +0000 | [diff] [blame] | 208 | switch (AA.getModRefInfo(CS, InstCS)) { |
Chandler Carruth | 194f59c | 2015-07-22 23:15:57 +0000 | [diff] [blame] | 209 | case MRI_NoModRef: |
Dan Gohman | 26ef7c7 | 2010-08-05 22:09:15 +0000 | [diff] [blame] | 210 | // If the two calls are the same, return InstCS as a Def, so that |
| 211 | // CS can be found redundant and eliminated. |
Chandler Carruth | 194f59c | 2015-07-22 23:15:57 +0000 | [diff] [blame] | 212 | if (isReadOnlyCall && !(MR & MRI_Mod) && |
Dan Gohman | 26ef7c7 | 2010-08-05 22:09:15 +0000 | [diff] [blame] | 213 | CS.getInstruction()->isIdenticalToWhenDefined(Inst)) |
| 214 | return MemDepResult::getDef(Inst); |
| 215 | |
| 216 | // Otherwise if the two calls don't interact (e.g. InstCS is readnone) |
| 217 | // keep scanning. |
Nadav Rotem | 5d4e205 | 2012-08-13 23:03:43 +0000 | [diff] [blame] | 218 | continue; |
Chris Lattner | 702e46e | 2008-12-09 21:19:42 +0000 | [diff] [blame] | 219 | default: |
Chris Lattner | 0e3d633 | 2008-12-05 21:04:20 +0000 | [diff] [blame] | 220 | return MemDepResult::getClobber(Inst); |
Chris Lattner | 702e46e | 2008-12-09 21:19:42 +0000 | [diff] [blame] | 221 | } |
Chris Lattner | ff862c4 | 2008-11-30 01:44:00 +0000 | [diff] [blame] | 222 | } |
Nadav Rotem | 5d4e205 | 2012-08-13 23:03:43 +0000 | [diff] [blame] | 223 | |
| 224 | // If we could not obtain a pointer for the instruction and the instruction |
| 225 | // touches memory then assume that this is a dependency. |
Chandler Carruth | 194f59c | 2015-07-22 23:15:57 +0000 | [diff] [blame] | 226 | if (MR != MRI_NoModRef) |
Nadav Rotem | 5d4e205 | 2012-08-13 23:03:43 +0000 | [diff] [blame] | 227 | return MemDepResult::getClobber(Inst); |
Owen Anderson | 9c88457 | 2007-07-10 17:59:22 +0000 | [diff] [blame] | 228 | } |
Nadav Rotem | 5d4e205 | 2012-08-13 23:03:43 +0000 | [diff] [blame] | 229 | |
Eli Friedman | 7d58bc7 | 2011-06-15 00:47:34 +0000 | [diff] [blame] | 230 | // No dependence found. If this is the entry block of the function, it is |
| 231 | // unknown, otherwise it is non-local. |
Chris Lattner | 2faa2c7 | 2008-12-07 02:15:47 +0000 | [diff] [blame] | 232 | if (BB != &BB->getParent()->getEntryBlock()) |
| 233 | return MemDepResult::getNonLocal(); |
Eli Friedman | c1702c8 | 2011-10-13 22:14:57 +0000 | [diff] [blame] | 234 | return MemDepResult::getNonFuncLocal(); |
Owen Anderson | 9c88457 | 2007-07-10 17:59:22 +0000 | [diff] [blame] | 235 | } |
| 236 | |
Chandler Carruth | 61440d2 | 2016-03-10 00:55:30 +0000 | [diff] [blame] | 237 | unsigned MemoryDependenceResults::getLoadLoadClobberFullWidthSize( |
Mehdi Amini | a28d91d | 2015-03-10 02:37:25 +0000 | [diff] [blame] | 238 | const Value *MemLocBase, int64_t MemLocOffs, unsigned MemLocSize, |
| 239 | const LoadInst *LI) { |
Eli Friedman | 5494ada | 2011-08-15 20:54:19 +0000 | [diff] [blame] | 240 | // We can only extend simple integer loads. |
Chandler Carruth | 60fb1b4 | 2016-03-07 10:19:30 +0000 | [diff] [blame] | 241 | if (!isa<IntegerType>(LI->getType()) || !LI->isSimple()) |
| 242 | return 0; |
Kostya Serebryany | 3838f27 | 2013-02-13 05:59:45 +0000 | [diff] [blame] | 243 | |
| 244 | // Load widening is hostile to ThreadSanitizer: it may cause false positives |
| 245 | // or make the reports more cryptic (access sizes are wrong). |
Duncan P. N. Exon Smith | b3fc83c | 2015-02-14 00:12:15 +0000 | [diff] [blame] | 246 | if (LI->getParent()->getParent()->hasFnAttribute(Attribute::SanitizeThread)) |
Kostya Serebryany | 3838f27 | 2013-02-13 05:59:45 +0000 | [diff] [blame] | 247 | return 0; |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 248 | |
Mehdi Amini | a28d91d | 2015-03-10 02:37:25 +0000 | [diff] [blame] | 249 | const DataLayout &DL = LI->getModule()->getDataLayout(); |
| 250 | |
Chris Lattner | 7aab279 | 2011-04-26 22:42:01 +0000 | [diff] [blame] | 251 | // Get the base of this load. |
| 252 | int64_t LIOffs = 0; |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 253 | const Value *LIBase = |
Mehdi Amini | a28d91d | 2015-03-10 02:37:25 +0000 | [diff] [blame] | 254 | GetPointerBaseWithConstantOffset(LI->getPointerOperand(), LIOffs, DL); |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 255 | |
Chris Lattner | 7aab279 | 2011-04-26 22:42:01 +0000 | [diff] [blame] | 256 | // If the two pointers are not based on the same pointer, we can't tell that |
| 257 | // they are related. |
Chandler Carruth | 60fb1b4 | 2016-03-07 10:19:30 +0000 | [diff] [blame] | 258 | if (LIBase != MemLocBase) |
| 259 | return 0; |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 260 | |
Chris Lattner | 7aab279 | 2011-04-26 22:42:01 +0000 | [diff] [blame] | 261 | // Okay, the two values are based on the same pointer, but returned as |
| 262 | // no-alias. This happens when we have things like two byte loads at "P+1" |
| 263 | // and "P+3". Check to see if increasing the size of the "LI" load up to its |
| 264 | // alignment (or the largest native integer type) will allow us to load all |
| 265 | // the bits required by MemLoc. |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 266 | |
Chris Lattner | 7aab279 | 2011-04-26 22:42:01 +0000 | [diff] [blame] | 267 | // If MemLoc is before LI, then no widening of LI will help us out. |
Chandler Carruth | 60fb1b4 | 2016-03-07 10:19:30 +0000 | [diff] [blame] | 268 | if (MemLocOffs < LIOffs) |
| 269 | return 0; |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 270 | |
Chris Lattner | 7aab279 | 2011-04-26 22:42:01 +0000 | [diff] [blame] | 271 | // Get the alignment of the load in bytes. We assume that it is safe to load |
| 272 | // any legal integer up to this size without a problem. For example, if we're |
| 273 | // looking at an i8 load on x86-32 that is known 1024 byte aligned, we can |
| 274 | // widen it up to an i32 load. If it is known 2-byte aligned, we can widen it |
| 275 | // to i16. |
| 276 | unsigned LoadAlign = LI->getAlignment(); |
| 277 | |
Chandler Carruth | 60fb1b4 | 2016-03-07 10:19:30 +0000 | [diff] [blame] | 278 | int64_t MemLocEnd = MemLocOffs + MemLocSize; |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 279 | |
Chris Lattner | 7aab279 | 2011-04-26 22:42:01 +0000 | [diff] [blame] | 280 | // If no amount of rounding up will let MemLoc fit into LI, then bail out. |
Chandler Carruth | 60fb1b4 | 2016-03-07 10:19:30 +0000 | [diff] [blame] | 281 | if (LIOffs + LoadAlign < MemLocEnd) |
| 282 | return 0; |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 283 | |
Chris Lattner | 7aab279 | 2011-04-26 22:42:01 +0000 | [diff] [blame] | 284 | // This is the size of the load to try. Start with the next larger power of |
| 285 | // two. |
Chandler Carruth | 60fb1b4 | 2016-03-07 10:19:30 +0000 | [diff] [blame] | 286 | unsigned NewLoadByteSize = LI->getType()->getPrimitiveSizeInBits() / 8U; |
Chris Lattner | 7aab279 | 2011-04-26 22:42:01 +0000 | [diff] [blame] | 287 | NewLoadByteSize = NextPowerOf2(NewLoadByteSize); |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 288 | |
Eugene Zelenko | 1804a77 | 2016-08-25 00:45:04 +0000 | [diff] [blame] | 289 | while (true) { |
Chris Lattner | 7aab279 | 2011-04-26 22:42:01 +0000 | [diff] [blame] | 290 | // If this load size is bigger than our known alignment or would not fit |
| 291 | // into a native integer register, then we fail. |
| 292 | if (NewLoadByteSize > LoadAlign || |
Chandler Carruth | 60fb1b4 | 2016-03-07 10:19:30 +0000 | [diff] [blame] | 293 | !DL.fitsInLegalInteger(NewLoadByteSize * 8)) |
Chris Lattner | 827a270 | 2011-04-28 07:29:08 +0000 | [diff] [blame] | 294 | return 0; |
Chris Lattner | 7aab279 | 2011-04-26 22:42:01 +0000 | [diff] [blame] | 295 | |
Duncan P. N. Exon Smith | b3fc83c | 2015-02-14 00:12:15 +0000 | [diff] [blame] | 296 | if (LIOffs + NewLoadByteSize > MemLocEnd && |
| 297 | LI->getParent()->getParent()->hasFnAttribute( |
| 298 | Attribute::SanitizeAddress)) |
Kostya Serebryany | 9e0d377 | 2012-02-06 22:48:56 +0000 | [diff] [blame] | 299 | // We will be reading past the location accessed by the original program. |
| 300 | // While this is safe in a regular build, Address Safety analysis tools |
| 301 | // may start reporting false warnings. So, don't do widening. |
| 302 | return 0; |
Kostya Serebryany | 9e0d377 | 2012-02-06 22:48:56 +0000 | [diff] [blame] | 303 | |
Chris Lattner | 7aab279 | 2011-04-26 22:42:01 +0000 | [diff] [blame] | 304 | // If a load of this width would include all of MemLoc, then we succeed. |
Chandler Carruth | 60fb1b4 | 2016-03-07 10:19:30 +0000 | [diff] [blame] | 305 | if (LIOffs + NewLoadByteSize >= MemLocEnd) |
Chris Lattner | 827a270 | 2011-04-28 07:29:08 +0000 | [diff] [blame] | 306 | return NewLoadByteSize; |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 307 | |
Chris Lattner | 7aab279 | 2011-04-26 22:42:01 +0000 | [diff] [blame] | 308 | NewLoadByteSize <<= 1; |
| 309 | } |
Chris Lattner | 7aab279 | 2011-04-26 22:42:01 +0000 | [diff] [blame] | 310 | } |
| 311 | |
Philip Reames | a7ad6a5 | 2015-01-26 18:54:27 +0000 | [diff] [blame] | 312 | static bool isVolatile(Instruction *Inst) { |
| 313 | if (LoadInst *LI = dyn_cast<LoadInst>(Inst)) |
| 314 | return LI->isVolatile(); |
| 315 | else if (StoreInst *SI = dyn_cast<StoreInst>(Inst)) |
| 316 | return SI->isVolatile(); |
| 317 | else if (AtomicCmpXchgInst *AI = dyn_cast<AtomicCmpXchgInst>(Inst)) |
| 318 | return AI->isVolatile(); |
| 319 | return false; |
| 320 | } |
| 321 | |
Chandler Carruth | 61440d2 | 2016-03-10 00:55:30 +0000 | [diff] [blame] | 322 | MemDepResult MemoryDependenceResults::getPointerDependencyFrom( |
Chandler Carruth | ac80dc7 | 2015-06-17 07:18:54 +0000 | [diff] [blame] | 323 | const MemoryLocation &MemLoc, bool isLoad, BasicBlock::iterator ScanIt, |
Bob Haarman | 3db1764 | 2016-08-26 16:34:27 +0000 | [diff] [blame] | 324 | BasicBlock *BB, Instruction *QueryInst, unsigned *Limit) { |
Chris Lattner | 2faa2c7 | 2008-12-07 02:15:47 +0000 | [diff] [blame] | 325 | |
Piotr Padlewski | dc9b2cf | 2015-10-02 22:12:22 +0000 | [diff] [blame] | 326 | if (QueryInst != nullptr) { |
| 327 | if (auto *LI = dyn_cast<LoadInst>(QueryInst)) { |
| 328 | MemDepResult invariantGroupDependency = |
| 329 | getInvariantGroupPointerDependency(LI, BB); |
| 330 | |
| 331 | if (invariantGroupDependency.isDef()) |
| 332 | return invariantGroupDependency; |
| 333 | } |
| 334 | } |
Bob Haarman | 3db1764 | 2016-08-26 16:34:27 +0000 | [diff] [blame] | 335 | return getSimplePointerDependencyFrom(MemLoc, isLoad, ScanIt, BB, QueryInst, |
| 336 | Limit); |
Piotr Padlewski | dc9b2cf | 2015-10-02 22:12:22 +0000 | [diff] [blame] | 337 | } |
| 338 | |
| 339 | MemDepResult |
Chandler Carruth | 61440d2 | 2016-03-10 00:55:30 +0000 | [diff] [blame] | 340 | MemoryDependenceResults::getInvariantGroupPointerDependency(LoadInst *LI, |
Piotr Padlewski | 01659cb | 2016-11-08 18:20:51 +0000 | [diff] [blame] | 341 | BasicBlock *BB) { |
Piotr Padlewski | dc9b2cf | 2015-10-02 22:12:22 +0000 | [diff] [blame] | 342 | Value *LoadOperand = LI->getPointerOperand(); |
| 343 | // It's is not safe to walk the use list of global value, because function |
| 344 | // passes aren't allowed to look outside their functions. |
| 345 | if (isa<GlobalValue>(LoadOperand)) |
| 346 | return MemDepResult::getUnknown(); |
| 347 | |
| 348 | auto *InvariantGroupMD = LI->getMetadata(LLVMContext::MD_invariant_group); |
| 349 | if (!InvariantGroupMD) |
| 350 | return MemDepResult::getUnknown(); |
| 351 | |
Eugene Zelenko | 1804a77 | 2016-08-25 00:45:04 +0000 | [diff] [blame] | 352 | SmallSet<Value *, 14> Seen; |
Piotr Padlewski | dc9b2cf | 2015-10-02 22:12:22 +0000 | [diff] [blame] | 353 | // Queue to process all pointers that are equivalent to load operand. |
Eugene Zelenko | 1804a77 | 2016-08-25 00:45:04 +0000 | [diff] [blame] | 354 | SmallVector<Value *, 8> LoadOperandsQueue; |
Piotr Padlewski | dc9b2cf | 2015-10-02 22:12:22 +0000 | [diff] [blame] | 355 | LoadOperandsQueue.push_back(LoadOperand); |
Piotr Padlewski | 2202aa9 | 2016-12-27 15:06:07 +0000 | [diff] [blame] | 356 | Seen.insert(LoadOperand); |
Piotr Padlewski | dc9b2cf | 2015-10-02 22:12:22 +0000 | [diff] [blame] | 357 | while (!LoadOperandsQueue.empty()) { |
| 358 | Value *Ptr = LoadOperandsQueue.pop_back_val(); |
| 359 | if (isa<GlobalValue>(Ptr)) |
| 360 | continue; |
| 361 | |
| 362 | if (auto *BCI = dyn_cast<BitCastInst>(Ptr)) { |
Benjamin Kramer | 4dea8f5 | 2016-06-17 18:59:41 +0000 | [diff] [blame] | 363 | if (Seen.insert(BCI->getOperand(0)).second) { |
Piotr Padlewski | dc9b2cf | 2015-10-02 22:12:22 +0000 | [diff] [blame] | 364 | LoadOperandsQueue.push_back(BCI->getOperand(0)); |
Piotr Padlewski | dc9b2cf | 2015-10-02 22:12:22 +0000 | [diff] [blame] | 365 | } |
| 366 | } |
| 367 | |
| 368 | for (Use &Us : Ptr->uses()) { |
| 369 | auto *U = dyn_cast<Instruction>(Us.getUser()); |
Chandler Carruth | aef32bd | 2016-03-11 13:46:00 +0000 | [diff] [blame] | 370 | if (!U || U == LI || !DT.dominates(U, LI)) |
Piotr Padlewski | dc9b2cf | 2015-10-02 22:12:22 +0000 | [diff] [blame] | 371 | continue; |
| 372 | |
| 373 | if (auto *BCI = dyn_cast<BitCastInst>(U)) { |
Benjamin Kramer | 4dea8f5 | 2016-06-17 18:59:41 +0000 | [diff] [blame] | 374 | if (Seen.insert(BCI).second) { |
Piotr Padlewski | dc9b2cf | 2015-10-02 22:12:22 +0000 | [diff] [blame] | 375 | LoadOperandsQueue.push_back(BCI); |
Piotr Padlewski | dc9b2cf | 2015-10-02 22:12:22 +0000 | [diff] [blame] | 376 | } |
| 377 | continue; |
| 378 | } |
| 379 | // If we hit load/store with the same invariant.group metadata (and the |
| 380 | // same pointer operand) we can assume that value pointed by pointer |
| 381 | // operand didn't change. |
| 382 | if ((isa<LoadInst>(U) || isa<StoreInst>(U)) && U->getParent() == BB && |
| 383 | U->getMetadata(LLVMContext::MD_invariant_group) == InvariantGroupMD) |
| 384 | return MemDepResult::getDef(U); |
| 385 | } |
| 386 | } |
Piotr Padlewski | 383edba | 2016-12-23 13:13:32 +0000 | [diff] [blame] | 387 | return MemDepResult::getUnknown(); |
Piotr Padlewski | dc9b2cf | 2015-10-02 22:12:22 +0000 | [diff] [blame] | 388 | } |
| 389 | |
Chandler Carruth | 61440d2 | 2016-03-10 00:55:30 +0000 | [diff] [blame] | 390 | MemDepResult MemoryDependenceResults::getSimplePointerDependencyFrom( |
Piotr Padlewski | dc9b2cf | 2015-10-02 22:12:22 +0000 | [diff] [blame] | 391 | const MemoryLocation &MemLoc, bool isLoad, BasicBlock::iterator ScanIt, |
Bob Haarman | 3db1764 | 2016-08-26 16:34:27 +0000 | [diff] [blame] | 392 | BasicBlock *BB, Instruction *QueryInst, unsigned *Limit) { |
Shuxin Yang | 408bdad | 2013-03-06 17:48:48 +0000 | [diff] [blame] | 393 | bool isInvariantLoad = false; |
Robin Morisset | 163ef04 | 2014-08-29 20:32:58 +0000 | [diff] [blame] | 394 | |
Bob Haarman | 3db1764 | 2016-08-26 16:34:27 +0000 | [diff] [blame] | 395 | if (!Limit) { |
| 396 | unsigned DefaultLimit = BlockScanLimit; |
| 397 | return getSimplePointerDependencyFrom(MemLoc, isLoad, ScanIt, BB, QueryInst, |
| 398 | &DefaultLimit); |
| 399 | } |
| 400 | |
Robin Morisset | 163ef04 | 2014-08-29 20:32:58 +0000 | [diff] [blame] | 401 | // We must be careful with atomic accesses, as they may allow another thread |
Chad Rosier | 02e831c | 2016-06-28 17:19:10 +0000 | [diff] [blame] | 402 | // to touch this location, clobbering it. We are conservative: if the |
Robin Morisset | 163ef04 | 2014-08-29 20:32:58 +0000 | [diff] [blame] | 403 | // QueryInst is not a simple (non-atomic) memory access, we automatically |
| 404 | // return getClobber. |
| 405 | // If it is simple, we know based on the results of |
| 406 | // "Compiler testing via a theory of sound optimisations in the C11/C++11 |
| 407 | // memory model" in PLDI 2013, that a non-atomic location can only be |
| 408 | // clobbered between a pair of a release and an acquire action, with no |
| 409 | // access to the location in between. |
| 410 | // Here is an example for giving the general intuition behind this rule. |
| 411 | // In the following code: |
| 412 | // store x 0; |
| 413 | // release action; [1] |
| 414 | // acquire action; [4] |
| 415 | // %val = load x; |
| 416 | // It is unsafe to replace %val by 0 because another thread may be running: |
| 417 | // acquire action; [2] |
| 418 | // store x 42; |
| 419 | // release action; [3] |
| 420 | // with synchronization from 1 to 2 and from 3 to 4, resulting in %val |
| 421 | // being 42. A key property of this program however is that if either |
| 422 | // 1 or 4 were missing, there would be a race between the store of 42 |
Chad Rosier | 02e831c | 2016-06-28 17:19:10 +0000 | [diff] [blame] | 423 | // either the store of 0 or the load (making the whole program racy). |
Nick Lewycky | 947ca8a | 2016-01-04 16:44:44 +0000 | [diff] [blame] | 424 | // The paper mentioned above shows that the same property is respected |
Chad Rosier | 02e831c | 2016-06-28 17:19:10 +0000 | [diff] [blame] | 425 | // by every program that can detect any optimization of that kind: either |
Robin Morisset | 163ef04 | 2014-08-29 20:32:58 +0000 | [diff] [blame] | 426 | // it is racy (undefined) or there is a release followed by an acquire |
| 427 | // between the pair of accesses under consideration. |
Robin Morisset | 163ef04 | 2014-08-29 20:32:58 +0000 | [diff] [blame] | 428 | |
Philip Reames | 4dbd88f | 2015-03-24 23:54:54 +0000 | [diff] [blame] | 429 | // If the load is invariant, we "know" that it doesn't alias *any* write. We |
| 430 | // do want to respect mustalias results since defs are useful for value |
| 431 | // forwarding, but any mayalias write can be assumed to be noalias. |
| 432 | // Arguably, this logic should be pushed inside AliasAnalysis itself. |
Shuxin Yang | 408bdad | 2013-03-06 17:48:48 +0000 | [diff] [blame] | 433 | if (isLoad && QueryInst) { |
| 434 | LoadInst *LI = dyn_cast<LoadInst>(QueryInst); |
Craig Topper | 9f00886 | 2014-04-15 04:59:12 +0000 | [diff] [blame] | 435 | if (LI && LI->getMetadata(LLVMContext::MD_invariant_load) != nullptr) |
Shuxin Yang | 408bdad | 2013-03-06 17:48:48 +0000 | [diff] [blame] | 436 | isInvariantLoad = true; |
| 437 | } |
Eli Friedman | 8b098b0 | 2011-06-15 23:59:25 +0000 | [diff] [blame] | 438 | |
Mehdi Amini | a28d91d | 2015-03-10 02:37:25 +0000 | [diff] [blame] | 439 | const DataLayout &DL = BB->getModule()->getDataLayout(); |
| 440 | |
Bruno Cardoso Lopes | dfc1d96 | 2015-07-31 14:31:35 +0000 | [diff] [blame] | 441 | // Create a numbered basic block to lazily compute and cache instruction |
| 442 | // positions inside a BB. This is used to provide fast queries for relative |
| 443 | // position between two instructions in a BB and can be used by |
| 444 | // AliasAnalysis::callCapturesBefore. |
| 445 | OrderedBasicBlock OBB(BB); |
| 446 | |
Krzysztof Parzyszek | e261e5a | 2016-02-22 23:07:43 +0000 | [diff] [blame] | 447 | // Return "true" if and only if the instruction I is either a non-simple |
| 448 | // load or a non-simple store. |
Chandler Carruth | 60fb1b4 | 2016-03-07 10:19:30 +0000 | [diff] [blame] | 449 | auto isNonSimpleLoadOrStore = [](Instruction *I) -> bool { |
Krzysztof Parzyszek | e261e5a | 2016-02-22 23:07:43 +0000 | [diff] [blame] | 450 | if (auto *LI = dyn_cast<LoadInst>(I)) |
| 451 | return !LI->isSimple(); |
| 452 | if (auto *SI = dyn_cast<StoreInst>(I)) |
| 453 | return !SI->isSimple(); |
| 454 | return false; |
| 455 | }; |
| 456 | |
| 457 | // Return "true" if I is not a load and not a store, but it does access |
| 458 | // memory. |
Chandler Carruth | 60fb1b4 | 2016-03-07 10:19:30 +0000 | [diff] [blame] | 459 | auto isOtherMemAccess = [](Instruction *I) -> bool { |
Krzysztof Parzyszek | e261e5a | 2016-02-22 23:07:43 +0000 | [diff] [blame] | 460 | return !isa<LoadInst>(I) && !isa<StoreInst>(I) && I->mayReadOrWriteMemory(); |
| 461 | }; |
| 462 | |
Chris Lattner | a28355d | 2008-12-07 08:50:20 +0000 | [diff] [blame] | 463 | // Walk backwards through the basic block, looking for dependencies. |
Philip Reames | 090a824 | 2015-02-15 19:07:31 +0000 | [diff] [blame] | 464 | while (ScanIt != BB->begin()) { |
Duncan P. N. Exon Smith | 5a82c91 | 2015-10-10 00:53:03 +0000 | [diff] [blame] | 465 | Instruction *Inst = &*--ScanIt; |
Yunzhong Gao | 5cbcf56 | 2013-11-14 01:10:52 +0000 | [diff] [blame] | 466 | |
| 467 | if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(Inst)) |
| 468 | // Debug intrinsics don't (and can't) cause dependencies. |
Chandler Carruth | 60fb1b4 | 2016-03-07 10:19:30 +0000 | [diff] [blame] | 469 | if (isa<DbgInfoIntrinsic>(II)) |
| 470 | continue; |
Yunzhong Gao | 5cbcf56 | 2013-11-14 01:10:52 +0000 | [diff] [blame] | 471 | |
Eli Friedman | 8b098b0 | 2011-06-15 23:59:25 +0000 | [diff] [blame] | 472 | // Limit the amount of scanning we do so we don't end up with quadratic |
| 473 | // running time on extreme testcases. |
Bob Haarman | 3db1764 | 2016-08-26 16:34:27 +0000 | [diff] [blame] | 474 | --*Limit; |
| 475 | if (!*Limit) |
Eli Friedman | 8b098b0 | 2011-06-15 23:59:25 +0000 | [diff] [blame] | 476 | return MemDepResult::getUnknown(); |
| 477 | |
Chris Lattner | 506b858 | 2009-12-01 21:15:15 +0000 | [diff] [blame] | 478 | if (IntrinsicInst *II = dyn_cast<IntrinsicInst>(Inst)) { |
Owen Anderson | 2b2bd28 | 2009-10-28 07:05:35 +0000 | [diff] [blame] | 479 | // If we reach a lifetime begin or end marker, then the query ends here |
| 480 | // because the value is undefined. |
Chris Lattner | a58edd1 | 2010-09-06 03:58:04 +0000 | [diff] [blame] | 481 | if (II->getIntrinsicID() == Intrinsic::lifetime_start) { |
Owen Anderson | b9878ee | 2009-12-02 07:35:19 +0000 | [diff] [blame] | 482 | // FIXME: This only considers queries directly on the invariant-tagged |
| 483 | // pointer, not on query pointers that are indexed off of them. It'd |
Chris Lattner | 7aab279 | 2011-04-26 22:42:01 +0000 | [diff] [blame] | 484 | // be nice to handle that at some point (the right approach is to use |
| 485 | // GetPointerBaseWithConstantOffset). |
Chandler Carruth | 61440d2 | 2016-03-10 00:55:30 +0000 | [diff] [blame] | 486 | if (AA.isMustAlias(MemoryLocation(II->getArgOperand(1)), MemLoc)) |
Owen Anderson | 2b2bd28 | 2009-10-28 07:05:35 +0000 | [diff] [blame] | 487 | return MemDepResult::getDef(II); |
Chris Lattner | a58edd1 | 2010-09-06 03:58:04 +0000 | [diff] [blame] | 488 | continue; |
Owen Anderson | d0e86d5 | 2009-10-28 06:18:42 +0000 | [diff] [blame] | 489 | } |
| 490 | } |
| 491 | |
Chandler Carruth | 60fb1b4 | 2016-03-07 10:19:30 +0000 | [diff] [blame] | 492 | // Values depend on loads if the pointers are must aliased. This means |
| 493 | // that a load depends on another must aliased load from the same value. |
| 494 | // One exception is atomic loads: a value can depend on an atomic load that |
| 495 | // it does not alias with when this atomic load indicates that another |
| 496 | // thread may be accessing the location. |
Chris Lattner | 0e3d633 | 2008-12-05 21:04:20 +0000 | [diff] [blame] | 497 | if (LoadInst *LI = dyn_cast<LoadInst>(Inst)) { |
Philip Reames | a7ad6a5 | 2015-01-26 18:54:27 +0000 | [diff] [blame] | 498 | |
| 499 | // While volatile access cannot be eliminated, they do not have to clobber |
| 500 | // non-aliasing locations, as normal accesses, for example, can be safely |
| 501 | // reordered with volatile accesses. |
| 502 | if (LI->isVolatile()) { |
| 503 | if (!QueryInst) |
| 504 | // Original QueryInst *may* be volatile |
| 505 | return MemDepResult::getClobber(LI); |
| 506 | if (isVolatile(QueryInst)) |
| 507 | // Ordering required if QueryInst is itself volatile |
| 508 | return MemDepResult::getClobber(LI); |
| 509 | // Otherwise, volatile doesn't imply any special ordering |
| 510 | } |
Krzysztof Parzyszek | e261e5a | 2016-02-22 23:07:43 +0000 | [diff] [blame] | 511 | |
Eli Friedman | 5494ada | 2011-08-15 20:54:19 +0000 | [diff] [blame] | 512 | // Atomic loads have complications involved. |
Chandler Carruth | 60fb1b4 | 2016-03-07 10:19:30 +0000 | [diff] [blame] | 513 | // A Monotonic (or higher) load is OK if the query inst is itself not |
| 514 | // atomic. |
Eli Friedman | 5494ada | 2011-08-15 20:54:19 +0000 | [diff] [blame] | 515 | // FIXME: This is overly conservative. |
JF Bastien | 800f87a | 2016-04-06 21:19:33 +0000 | [diff] [blame] | 516 | if (LI->isAtomic() && isStrongerThanUnordered(LI->getOrdering())) { |
Krzysztof Parzyszek | e261e5a | 2016-02-22 23:07:43 +0000 | [diff] [blame] | 517 | if (!QueryInst || isNonSimpleLoadOrStore(QueryInst) || |
| 518 | isOtherMemAccess(QueryInst)) |
Robin Morisset | 9e98e7f | 2014-08-18 22:18:14 +0000 | [diff] [blame] | 519 | return MemDepResult::getClobber(LI); |
JF Bastien | 800f87a | 2016-04-06 21:19:33 +0000 | [diff] [blame] | 520 | if (LI->getOrdering() != AtomicOrdering::Monotonic) |
David Majnemer | e165502 | 2015-03-21 06:19:17 +0000 | [diff] [blame] | 521 | return MemDepResult::getClobber(LI); |
Robin Morisset | 4ffe8aa | 2014-08-18 22:18:11 +0000 | [diff] [blame] | 522 | } |
Eli Friedman | 5494ada | 2011-08-15 20:54:19 +0000 | [diff] [blame] | 523 | |
Chandler Carruth | ac80dc7 | 2015-06-17 07:18:54 +0000 | [diff] [blame] | 524 | MemoryLocation LoadLoc = MemoryLocation::get(LI); |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 525 | |
Chris Lattner | 0e3d633 | 2008-12-05 21:04:20 +0000 | [diff] [blame] | 526 | // If we found a pointer, check if it could be the same as our pointer. |
Chandler Carruth | 61440d2 | 2016-03-10 00:55:30 +0000 | [diff] [blame] | 527 | AliasResult R = AA.alias(LoadLoc, MemLoc); |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 528 | |
Chris Lattner | 6f83d06 | 2011-04-26 01:21:15 +0000 | [diff] [blame] | 529 | if (isLoad) { |
Dehao Chen | 22ce5eb | 2016-09-09 18:42:35 +0000 | [diff] [blame] | 530 | if (R == NoAlias) |
Chris Lattner | 7aab279 | 2011-04-26 22:42:01 +0000 | [diff] [blame] | 531 | continue; |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 532 | |
Chris Lattner | 6f83d06 | 2011-04-26 01:21:15 +0000 | [diff] [blame] | 533 | // Must aliased loads are defs of each other. |
Chandler Carruth | c3f49eb | 2015-06-22 02:16:51 +0000 | [diff] [blame] | 534 | if (R == MustAlias) |
Chris Lattner | 6f83d06 | 2011-04-26 01:21:15 +0000 | [diff] [blame] | 535 | return MemDepResult::getDef(Inst); |
| 536 | |
Dan Gohman | a471751 | 2011-06-04 06:48:50 +0000 | [diff] [blame] | 537 | #if 0 // FIXME: Temporarily disabled. GVN is cleverly rewriting loads |
| 538 | // in terms of clobbering loads, but since it does this by looking |
| 539 | // at the clobbering load directly, it doesn't know about any |
| 540 | // phi translation that may have happened along the way. |
| 541 | |
Chris Lattner | 6f83d06 | 2011-04-26 01:21:15 +0000 | [diff] [blame] | 542 | // If we have a partial alias, then return this as a clobber for the |
| 543 | // client to handle. |
Chandler Carruth | c3f49eb | 2015-06-22 02:16:51 +0000 | [diff] [blame] | 544 | if (R == PartialAlias) |
Chris Lattner | 6f83d06 | 2011-04-26 01:21:15 +0000 | [diff] [blame] | 545 | return MemDepResult::getClobber(Inst); |
Dan Gohman | a471751 | 2011-06-04 06:48:50 +0000 | [diff] [blame] | 546 | #endif |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 547 | |
Chris Lattner | 6f83d06 | 2011-04-26 01:21:15 +0000 | [diff] [blame] | 548 | // Random may-alias loads don't depend on each other without a |
| 549 | // dependence. |
Chris Lattner | 80c0818 | 2008-11-29 09:09:48 +0000 | [diff] [blame] | 550 | continue; |
Chris Lattner | 6f83d06 | 2011-04-26 01:21:15 +0000 | [diff] [blame] | 551 | } |
Dan Gohman | 15a4396 | 2010-10-29 01:14:04 +0000 | [diff] [blame] | 552 | |
Chris Lattner | 7aab279 | 2011-04-26 22:42:01 +0000 | [diff] [blame] | 553 | // Stores don't depend on other no-aliased accesses. |
Chandler Carruth | c3f49eb | 2015-06-22 02:16:51 +0000 | [diff] [blame] | 554 | if (R == NoAlias) |
Chris Lattner | 7aab279 | 2011-04-26 22:42:01 +0000 | [diff] [blame] | 555 | continue; |
| 556 | |
Dan Gohman | 15a4396 | 2010-10-29 01:14:04 +0000 | [diff] [blame] | 557 | // Stores don't alias loads from read-only memory. |
Chandler Carruth | 61440d2 | 2016-03-10 00:55:30 +0000 | [diff] [blame] | 558 | if (AA.pointsToConstantMemory(LoadLoc)) |
Dan Gohman | 15a4396 | 2010-10-29 01:14:04 +0000 | [diff] [blame] | 559 | continue; |
| 560 | |
Chris Lattner | 6f83d06 | 2011-04-26 01:21:15 +0000 | [diff] [blame] | 561 | // Stores depend on may/must aliased loads. |
Chris Lattner | 0e3d633 | 2008-12-05 21:04:20 +0000 | [diff] [blame] | 562 | return MemDepResult::getDef(Inst); |
| 563 | } |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 564 | |
Chris Lattner | 0e3d633 | 2008-12-05 21:04:20 +0000 | [diff] [blame] | 565 | if (StoreInst *SI = dyn_cast<StoreInst>(Inst)) { |
Eli Friedman | 5494ada | 2011-08-15 20:54:19 +0000 | [diff] [blame] | 566 | // Atomic stores have complications involved. |
Robin Morisset | 163ef04 | 2014-08-29 20:32:58 +0000 | [diff] [blame] | 567 | // A Monotonic store is OK if the query inst is itself not atomic. |
Eli Friedman | 5494ada | 2011-08-15 20:54:19 +0000 | [diff] [blame] | 568 | // FIXME: This is overly conservative. |
Krzysztof Parzyszek | e261e5a | 2016-02-22 23:07:43 +0000 | [diff] [blame] | 569 | if (!SI->isUnordered() && SI->isAtomic()) { |
| 570 | if (!QueryInst || isNonSimpleLoadOrStore(QueryInst) || |
| 571 | isOtherMemAccess(QueryInst)) |
Robin Morisset | 9e98e7f | 2014-08-18 22:18:14 +0000 | [diff] [blame] | 572 | return MemDepResult::getClobber(SI); |
JF Bastien | 800f87a | 2016-04-06 21:19:33 +0000 | [diff] [blame] | 573 | if (SI->getOrdering() != AtomicOrdering::Monotonic) |
David Majnemer | e165502 | 2015-03-21 06:19:17 +0000 | [diff] [blame] | 574 | return MemDepResult::getClobber(SI); |
Robin Morisset | 4ffe8aa | 2014-08-18 22:18:11 +0000 | [diff] [blame] | 575 | } |
Eli Friedman | 5494ada | 2011-08-15 20:54:19 +0000 | [diff] [blame] | 576 | |
Robin Morisset | 9e98e7f | 2014-08-18 22:18:14 +0000 | [diff] [blame] | 577 | // FIXME: this is overly conservative. |
| 578 | // While volatile access cannot be eliminated, they do not have to clobber |
| 579 | // non-aliasing locations, as normal accesses can for example be reordered |
| 580 | // with volatile accesses. |
| 581 | if (SI->isVolatile()) |
Krzysztof Parzyszek | e261e5a | 2016-02-22 23:07:43 +0000 | [diff] [blame] | 582 | if (!QueryInst || isNonSimpleLoadOrStore(QueryInst) || |
| 583 | isOtherMemAccess(QueryInst)) |
| 584 | return MemDepResult::getClobber(SI); |
Robin Morisset | 9e98e7f | 2014-08-18 22:18:14 +0000 | [diff] [blame] | 585 | |
Chris Lattner | 02274a7 | 2009-05-25 21:28:56 +0000 | [diff] [blame] | 586 | // If alias analysis can tell that this store is guaranteed to not modify |
| 587 | // the query pointer, ignore it. Use getModRefInfo to handle cases where |
| 588 | // the query pointer points to constant memory etc. |
Chandler Carruth | 61440d2 | 2016-03-10 00:55:30 +0000 | [diff] [blame] | 589 | if (AA.getModRefInfo(SI, MemLoc) == MRI_NoModRef) |
Chris Lattner | 02274a7 | 2009-05-25 21:28:56 +0000 | [diff] [blame] | 590 | continue; |
| 591 | |
| 592 | // Ok, this store might clobber the query pointer. Check to see if it is |
| 593 | // a must alias: in this case, we want to return this as a def. |
Chandler Carruth | ac80dc7 | 2015-06-17 07:18:54 +0000 | [diff] [blame] | 594 | MemoryLocation StoreLoc = MemoryLocation::get(SI); |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 595 | |
Chris Lattner | 0e3d633 | 2008-12-05 21:04:20 +0000 | [diff] [blame] | 596 | // If we found a pointer, check if it could be the same as our pointer. |
Chandler Carruth | 61440d2 | 2016-03-10 00:55:30 +0000 | [diff] [blame] | 597 | AliasResult R = AA.alias(StoreLoc, MemLoc); |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 598 | |
Chandler Carruth | c3f49eb | 2015-06-22 02:16:51 +0000 | [diff] [blame] | 599 | if (R == NoAlias) |
Chris Lattner | 0e3d633 | 2008-12-05 21:04:20 +0000 | [diff] [blame] | 600 | continue; |
Chandler Carruth | c3f49eb | 2015-06-22 02:16:51 +0000 | [diff] [blame] | 601 | if (R == MustAlias) |
Dan Gohman | ba5d0ab | 2010-12-13 22:47:57 +0000 | [diff] [blame] | 602 | return MemDepResult::getDef(Inst); |
Shuxin Yang | 408bdad | 2013-03-06 17:48:48 +0000 | [diff] [blame] | 603 | if (isInvariantLoad) |
Chandler Carruth | 60fb1b4 | 2016-03-07 10:19:30 +0000 | [diff] [blame] | 604 | continue; |
Dan Gohman | ba5d0ab | 2010-12-13 22:47:57 +0000 | [diff] [blame] | 605 | return MemDepResult::getClobber(Inst); |
Owen Anderson | c0daf5f | 2007-07-06 23:14:35 +0000 | [diff] [blame] | 606 | } |
Chris Lattner | 3ff6d01 | 2008-11-30 01:39:32 +0000 | [diff] [blame] | 607 | |
| 608 | // If this is an allocation, and if we know that the accessed pointer is to |
Chris Lattner | 0e3d633 | 2008-12-05 21:04:20 +0000 | [diff] [blame] | 609 | // the allocation, return Def. This means that there is no dependence and |
Chris Lattner | 3ff6d01 | 2008-11-30 01:39:32 +0000 | [diff] [blame] | 610 | // the access can be optimized based on that. For example, a load could |
Philip Reames | d9f4a3d | 2016-03-09 23:19:56 +0000 | [diff] [blame] | 611 | // turn into undef. Note that we can bypass the allocation itself when |
| 612 | // looking for a clobber in many cases; that's an alias property and is |
| 613 | // handled by BasicAA. |
Chandler Carruth | 61440d2 | 2016-03-10 00:55:30 +0000 | [diff] [blame] | 614 | if (isa<AllocaInst>(Inst) || isNoAliasFn(Inst, &TLI)) { |
Rafael Espindola | 7c68beb | 2014-02-18 15:33:12 +0000 | [diff] [blame] | 615 | const Value *AccessPtr = GetUnderlyingObject(MemLoc.Ptr, DL); |
Chandler Carruth | 61440d2 | 2016-03-10 00:55:30 +0000 | [diff] [blame] | 616 | if (AccessPtr == Inst || AA.isMustAlias(Inst, AccessPtr)) |
Victor Hernandez | 537d8d9 | 2009-09-18 21:34:51 +0000 | [diff] [blame] | 617 | return MemDepResult::getDef(Inst); |
Victor Hernandez | 537d8d9 | 2009-09-18 21:34:51 +0000 | [diff] [blame] | 618 | } |
| 619 | |
Philip Reames | 4dbd88f | 2015-03-24 23:54:54 +0000 | [diff] [blame] | 620 | if (isInvariantLoad) |
Chandler Carruth | 60fb1b4 | 2016-03-07 10:19:30 +0000 | [diff] [blame] | 621 | continue; |
Philip Reames | 4dbd88f | 2015-03-24 23:54:54 +0000 | [diff] [blame] | 622 | |
Philip Reames | b568113 | 2016-03-25 22:40:35 +0000 | [diff] [blame] | 623 | // A release fence requires that all stores complete before it, but does |
| 624 | // not prevent the reordering of following loads or stores 'before' the |
| 625 | // fence. As a result, we look past it when finding a dependency for |
| 626 | // loads. DSE uses this to find preceeding stores to delete and thus we |
| 627 | // can't bypass the fence if the query instruction is a store. |
| 628 | if (FenceInst *FI = dyn_cast<FenceInst>(Inst)) |
JF Bastien | 800f87a | 2016-04-06 21:19:33 +0000 | [diff] [blame] | 629 | if (isLoad && FI->getOrdering() == AtomicOrdering::Release) |
Philip Reames | b568113 | 2016-03-25 22:40:35 +0000 | [diff] [blame] | 630 | continue; |
JF Bastien | 800f87a | 2016-04-06 21:19:33 +0000 | [diff] [blame] | 631 | |
Chris Lattner | 0e3d633 | 2008-12-05 21:04:20 +0000 | [diff] [blame] | 632 | // See if this instruction (e.g. a call or vaarg) mod/ref's the pointer. |
Chandler Carruth | 61440d2 | 2016-03-10 00:55:30 +0000 | [diff] [blame] | 633 | ModRefInfo MR = AA.getModRefInfo(Inst, MemLoc); |
Chad Rosier | a968caf | 2012-05-14 20:35:04 +0000 | [diff] [blame] | 634 | // If necessary, perform additional analysis. |
Chandler Carruth | 194f59c | 2015-07-22 23:15:57 +0000 | [diff] [blame] | 635 | if (MR == MRI_ModRef) |
Chandler Carruth | aef32bd | 2016-03-11 13:46:00 +0000 | [diff] [blame] | 636 | MR = AA.callCapturesBefore(Inst, MemLoc, &DT, &OBB); |
Chad Rosier | a968caf | 2012-05-14 20:35:04 +0000 | [diff] [blame] | 637 | switch (MR) { |
Chandler Carruth | 194f59c | 2015-07-22 23:15:57 +0000 | [diff] [blame] | 638 | case MRI_NoModRef: |
Chris Lattner | 41efb68 | 2008-12-09 19:47:40 +0000 | [diff] [blame] | 639 | // If the call has no effect on the queried pointer, just ignore it. |
Chris Lattner | 81f19e9 | 2008-11-29 08:51:16 +0000 | [diff] [blame] | 640 | continue; |
Chandler Carruth | 194f59c | 2015-07-22 23:15:57 +0000 | [diff] [blame] | 641 | case MRI_Mod: |
Owen Anderson | fc16e5a | 2009-10-28 06:30:52 +0000 | [diff] [blame] | 642 | return MemDepResult::getClobber(Inst); |
Chandler Carruth | 194f59c | 2015-07-22 23:15:57 +0000 | [diff] [blame] | 643 | case MRI_Ref: |
Chris Lattner | 41efb68 | 2008-12-09 19:47:40 +0000 | [diff] [blame] | 644 | // If the call is known to never store to the pointer, and if this is a |
| 645 | // load query, we can safely ignore it (scan past it). |
| 646 | if (isLoad) |
| 647 | continue; |
Chris Lattner | 41efb68 | 2008-12-09 19:47:40 +0000 | [diff] [blame] | 648 | default: |
| 649 | // Otherwise, there is a potential dependence. Return a clobber. |
| 650 | return MemDepResult::getClobber(Inst); |
| 651 | } |
Owen Anderson | c0daf5f | 2007-07-06 23:14:35 +0000 | [diff] [blame] | 652 | } |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 653 | |
Eli Friedman | 7d58bc7 | 2011-06-15 00:47:34 +0000 | [diff] [blame] | 654 | // No dependence found. If this is the entry block of the function, it is |
| 655 | // unknown, otherwise it is non-local. |
Chris Lattner | 2faa2c7 | 2008-12-07 02:15:47 +0000 | [diff] [blame] | 656 | if (BB != &BB->getParent()->getEntryBlock()) |
| 657 | return MemDepResult::getNonLocal(); |
Eli Friedman | c1702c8 | 2011-10-13 22:14:57 +0000 | [diff] [blame] | 658 | return MemDepResult::getNonFuncLocal(); |
Owen Anderson | c0daf5f | 2007-07-06 23:14:35 +0000 | [diff] [blame] | 659 | } |
| 660 | |
Chandler Carruth | 61440d2 | 2016-03-10 00:55:30 +0000 | [diff] [blame] | 661 | MemDepResult MemoryDependenceResults::getDependency(Instruction *QueryInst) { |
Chris Lattner | 51ba8d0 | 2008-11-29 03:47:00 +0000 | [diff] [blame] | 662 | Instruction *ScanPos = QueryInst; |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 663 | |
Chris Lattner | 51ba8d0 | 2008-11-29 03:47:00 +0000 | [diff] [blame] | 664 | // Check for a cached result |
Chris Lattner | 47e81d0 | 2008-11-30 23:17:19 +0000 | [diff] [blame] | 665 | MemDepResult &LocalCache = LocalDeps[QueryInst]; |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 666 | |
Chris Lattner | e7d7e13 | 2008-11-29 22:02:15 +0000 | [diff] [blame] | 667 | // If the cached entry is non-dirty, just return it. Note that this depends |
Chris Lattner | 47e81d0 | 2008-11-30 23:17:19 +0000 | [diff] [blame] | 668 | // on MemDepResult's default constructing to 'dirty'. |
| 669 | if (!LocalCache.isDirty()) |
| 670 | return LocalCache; |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 671 | |
Chris Lattner | 51ba8d0 | 2008-11-29 03:47:00 +0000 | [diff] [blame] | 672 | // Otherwise, if we have a dirty entry, we know we can start the scan at that |
| 673 | // instruction, which may save us some work. |
Chris Lattner | 47e81d0 | 2008-11-30 23:17:19 +0000 | [diff] [blame] | 674 | if (Instruction *Inst = LocalCache.getInst()) { |
Chris Lattner | 51ba8d0 | 2008-11-29 03:47:00 +0000 | [diff] [blame] | 675 | ScanPos = Inst; |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 676 | |
Chris Lattner | de4440c | 2008-12-07 18:39:13 +0000 | [diff] [blame] | 677 | RemoveFromReverseMap(ReverseLocalDeps, Inst, QueryInst); |
Chris Lattner | 4410427 | 2008-11-30 02:52:26 +0000 | [diff] [blame] | 678 | } |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 679 | |
Chris Lattner | 5a78604 | 2008-12-07 01:50:16 +0000 | [diff] [blame] | 680 | BasicBlock *QueryParent = QueryInst->getParent(); |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 681 | |
Chris Lattner | 51ba8d0 | 2008-11-29 03:47:00 +0000 | [diff] [blame] | 682 | // Do the scan. |
Chris Lattner | 5a78604 | 2008-12-07 01:50:16 +0000 | [diff] [blame] | 683 | if (BasicBlock::iterator(QueryInst) == QueryParent->begin()) { |
Piotr Padlewski | 01659cb | 2016-11-08 18:20:51 +0000 | [diff] [blame] | 684 | // No dependence found. If this is the entry block of the function, it is |
Eli Friedman | 7d58bc7 | 2011-06-15 00:47:34 +0000 | [diff] [blame] | 685 | // unknown, otherwise it is non-local. |
Chris Lattner | 2faa2c7 | 2008-12-07 02:15:47 +0000 | [diff] [blame] | 686 | if (QueryParent != &QueryParent->getParent()->getEntryBlock()) |
| 687 | LocalCache = MemDepResult::getNonLocal(); |
| 688 | else |
Eli Friedman | c1702c8 | 2011-10-13 22:14:57 +0000 | [diff] [blame] | 689 | LocalCache = MemDepResult::getNonFuncLocal(); |
Dan Gohman | 1d760ce | 2010-11-10 21:51:35 +0000 | [diff] [blame] | 690 | } else { |
Chandler Carruth | ac80dc7 | 2015-06-17 07:18:54 +0000 | [diff] [blame] | 691 | MemoryLocation MemLoc; |
Chandler Carruth | 61440d2 | 2016-03-10 00:55:30 +0000 | [diff] [blame] | 692 | ModRefInfo MR = GetLocation(QueryInst, MemLoc, TLI); |
Dan Gohman | 1d760ce | 2010-11-10 21:51:35 +0000 | [diff] [blame] | 693 | if (MemLoc.Ptr) { |
| 694 | // If we can do a pointer scan, make it happen. |
Chandler Carruth | 194f59c | 2015-07-22 23:15:57 +0000 | [diff] [blame] | 695 | bool isLoad = !(MR & MRI_Mod); |
Piotr Padlewski | 01659cb | 2016-11-08 18:20:51 +0000 | [diff] [blame] | 696 | if (auto *II = dyn_cast<IntrinsicInst>(QueryInst)) |
Owen Anderson | 97f0cf3 | 2011-05-17 00:05:49 +0000 | [diff] [blame] | 697 | isLoad |= II->getIntrinsicID() == Intrinsic::lifetime_start; |
Chris Lattner | e48c31c | 2010-11-21 07:34:32 +0000 | [diff] [blame] | 698 | |
Duncan P. N. Exon Smith | 5a82c91 | 2015-10-10 00:53:03 +0000 | [diff] [blame] | 699 | LocalCache = getPointerDependencyFrom( |
| 700 | MemLoc, isLoad, ScanPos->getIterator(), QueryParent, QueryInst); |
Dan Gohman | 1d760ce | 2010-11-10 21:51:35 +0000 | [diff] [blame] | 701 | } else if (isa<CallInst>(QueryInst) || isa<InvokeInst>(QueryInst)) { |
Gabor Greif | ef1ca24 | 2010-07-27 22:02:00 +0000 | [diff] [blame] | 702 | CallSite QueryCS(QueryInst); |
Chandler Carruth | 61440d2 | 2016-03-10 00:55:30 +0000 | [diff] [blame] | 703 | bool isReadOnly = AA.onlyReadsMemory(QueryCS); |
Duncan P. N. Exon Smith | 5a82c91 | 2015-10-10 00:53:03 +0000 | [diff] [blame] | 704 | LocalCache = getCallSiteDependencyFrom( |
| 705 | QueryCS, isReadOnly, ScanPos->getIterator(), QueryParent); |
Dan Gohman | 1d760ce | 2010-11-10 21:51:35 +0000 | [diff] [blame] | 706 | } else |
| 707 | // Non-memory instruction. |
Eli Friedman | 7d58bc7 | 2011-06-15 00:47:34 +0000 | [diff] [blame] | 708 | LocalCache = MemDepResult::getUnknown(); |
Nick Lewycky | 218a339 | 2009-11-28 21:27:49 +0000 | [diff] [blame] | 709 | } |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 710 | |
Chris Lattner | 51ba8d0 | 2008-11-29 03:47:00 +0000 | [diff] [blame] | 711 | // Remember the result! |
Chris Lattner | 47e81d0 | 2008-11-30 23:17:19 +0000 | [diff] [blame] | 712 | if (Instruction *I = LocalCache.getInst()) |
Chris Lattner | 9f1988ab | 2008-11-29 09:20:15 +0000 | [diff] [blame] | 713 | ReverseLocalDeps[I].insert(QueryInst); |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 714 | |
Chris Lattner | 47e81d0 | 2008-11-30 23:17:19 +0000 | [diff] [blame] | 715 | return LocalCache; |
Chris Lattner | 51ba8d0 | 2008-11-29 03:47:00 +0000 | [diff] [blame] | 716 | } |
| 717 | |
Chris Lattner | f09619d | 2009-01-22 07:04:01 +0000 | [diff] [blame] | 718 | #ifndef NDEBUG |
Chandler Carruth | 40e21f2 | 2016-03-07 12:30:06 +0000 | [diff] [blame] | 719 | /// This method is used when -debug is specified to verify that cache arrays |
| 720 | /// are properly kept sorted. |
Chandler Carruth | 61440d2 | 2016-03-10 00:55:30 +0000 | [diff] [blame] | 721 | static void AssertSorted(MemoryDependenceResults::NonLocalDepInfo &Cache, |
Chris Lattner | f09619d | 2009-01-22 07:04:01 +0000 | [diff] [blame] | 722 | int Count = -1) { |
Chandler Carruth | 60fb1b4 | 2016-03-07 10:19:30 +0000 | [diff] [blame] | 723 | if (Count == -1) |
| 724 | Count = Cache.size(); |
Craig Topper | e30b8ca | 2016-01-03 19:43:40 +0000 | [diff] [blame] | 725 | assert(std::is_sorted(Cache.begin(), Cache.begin() + Count) && |
| 726 | "Cache isn't sorted!"); |
Chris Lattner | f09619d | 2009-01-22 07:04:01 +0000 | [diff] [blame] | 727 | } |
| 728 | #endif |
| 729 | |
Chandler Carruth | 61440d2 | 2016-03-10 00:55:30 +0000 | [diff] [blame] | 730 | const MemoryDependenceResults::NonLocalDepInfo & |
| 731 | MemoryDependenceResults::getNonLocalCallDependency(CallSite QueryCS) { |
Chris Lattner | 254314e | 2008-12-09 19:38:05 +0000 | [diff] [blame] | 732 | assert(getDependency(QueryCS.getInstruction()).isNonLocal() && |
Chandler Carruth | 60fb1b4 | 2016-03-07 10:19:30 +0000 | [diff] [blame] | 733 | "getNonLocalCallDependency should only be used on calls with " |
| 734 | "non-local deps!"); |
Chris Lattner | 254314e | 2008-12-09 19:38:05 +0000 | [diff] [blame] | 735 | PerInstNLInfo &CacheP = NonLocalDeps[QueryCS.getInstruction()]; |
Chris Lattner | 7e61daf | 2008-12-01 01:15:42 +0000 | [diff] [blame] | 736 | NonLocalDepInfo &Cache = CacheP.first; |
Chris Lattner | 2059753 | 2008-11-30 01:18:27 +0000 | [diff] [blame] | 737 | |
Chandler Carruth | 40e21f2 | 2016-03-07 12:30:06 +0000 | [diff] [blame] | 738 | // This is the set of blocks that need to be recomputed. In the cached case, |
| 739 | // this can happen due to instructions being deleted etc. In the uncached |
| 740 | // case, this starts out as the set of predecessors we care about. |
Chandler Carruth | 60fb1b4 | 2016-03-07 10:19:30 +0000 | [diff] [blame] | 741 | SmallVector<BasicBlock *, 32> DirtyBlocks; |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 742 | |
Chris Lattner | 2059753 | 2008-11-30 01:18:27 +0000 | [diff] [blame] | 743 | if (!Cache.empty()) { |
Chris Lattner | 7e61daf | 2008-12-01 01:15:42 +0000 | [diff] [blame] | 744 | // Okay, we have a cache entry. If we know it is not dirty, just return it |
| 745 | // with no computation. |
| 746 | if (!CacheP.second) { |
Dan Gohman | d2d1ae1 | 2010-06-22 15:08:57 +0000 | [diff] [blame] | 747 | ++NumCacheNonLocal; |
Chris Lattner | 7e61daf | 2008-12-01 01:15:42 +0000 | [diff] [blame] | 748 | return Cache; |
| 749 | } |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 750 | |
Chris Lattner | 2059753 | 2008-11-30 01:18:27 +0000 | [diff] [blame] | 751 | // If we already have a partially computed set of results, scan them to |
Chris Lattner | 7e61daf | 2008-12-01 01:15:42 +0000 | [diff] [blame] | 752 | // determine what is dirty, seeding our initial DirtyBlocks worklist. |
Chandler Carruth | af8321e | 2016-03-07 15:12:57 +0000 | [diff] [blame] | 753 | for (auto &Entry : Cache) |
| 754 | if (Entry.getResult().isDirty()) |
| 755 | DirtyBlocks.push_back(Entry.getBB()); |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 756 | |
Chris Lattner | 7e61daf | 2008-12-01 01:15:42 +0000 | [diff] [blame] | 757 | // Sort the cache so that we can do fast binary search lookups below. |
| 758 | std::sort(Cache.begin(), Cache.end()); |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 759 | |
Chris Lattner | 7e61daf | 2008-12-01 01:15:42 +0000 | [diff] [blame] | 760 | ++NumCacheDirtyNonLocal; |
Chandler Carruth | 60fb1b4 | 2016-03-07 10:19:30 +0000 | [diff] [blame] | 761 | // cerr << "CACHED CASE: " << DirtyBlocks.size() << " dirty: " |
Chris Lattner | 2059753 | 2008-11-30 01:18:27 +0000 | [diff] [blame] | 762 | // << Cache.size() << " cached: " << *QueryInst; |
| 763 | } else { |
| 764 | // Seed DirtyBlocks with each of the preds of QueryInst's block. |
Chris Lattner | 254314e | 2008-12-09 19:38:05 +0000 | [diff] [blame] | 765 | BasicBlock *QueryBB = QueryCS.getInstruction()->getParent(); |
Daniel Berlin | b4e7a4a | 2015-04-21 21:11:50 +0000 | [diff] [blame] | 766 | for (BasicBlock *Pred : PredCache.get(QueryBB)) |
| 767 | DirtyBlocks.push_back(Pred); |
Dan Gohman | d2d1ae1 | 2010-06-22 15:08:57 +0000 | [diff] [blame] | 768 | ++NumUncacheNonLocal; |
Chris Lattner | 2059753 | 2008-11-30 01:18:27 +0000 | [diff] [blame] | 769 | } |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 770 | |
Chris Lattner | 702e46e | 2008-12-09 21:19:42 +0000 | [diff] [blame] | 771 | // isReadonlyCall - If this is a read-only call, we can be more aggressive. |
Chandler Carruth | 61440d2 | 2016-03-10 00:55:30 +0000 | [diff] [blame] | 772 | bool isReadonlyCall = AA.onlyReadsMemory(QueryCS); |
Chris Lattner | ff9f3db | 2008-12-15 03:35:32 +0000 | [diff] [blame] | 773 | |
Chandler Carruth | 60fb1b4 | 2016-03-07 10:19:30 +0000 | [diff] [blame] | 774 | SmallPtrSet<BasicBlock *, 32> Visited; |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 775 | |
Chris Lattner | 7e61daf | 2008-12-01 01:15:42 +0000 | [diff] [blame] | 776 | unsigned NumSortedEntries = Cache.size(); |
Chris Lattner | f09619d | 2009-01-22 07:04:01 +0000 | [diff] [blame] | 777 | DEBUG(AssertSorted(Cache)); |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 778 | |
Chris Lattner | 2059753 | 2008-11-30 01:18:27 +0000 | [diff] [blame] | 779 | // Iterate while we still have blocks to update. |
| 780 | while (!DirtyBlocks.empty()) { |
| 781 | BasicBlock *DirtyBB = DirtyBlocks.back(); |
| 782 | DirtyBlocks.pop_back(); |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 783 | |
Chris Lattner | 7e61daf | 2008-12-01 01:15:42 +0000 | [diff] [blame] | 784 | // Already processed this block? |
David Blaikie | 70573dc | 2014-11-19 07:49:26 +0000 | [diff] [blame] | 785 | if (!Visited.insert(DirtyBB).second) |
Chris Lattner | 7e61daf | 2008-12-01 01:15:42 +0000 | [diff] [blame] | 786 | continue; |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 787 | |
Chris Lattner | 7e61daf | 2008-12-01 01:15:42 +0000 | [diff] [blame] | 788 | // Do a binary search to see if we already have an entry for this block in |
| 789 | // the cache set. If so, find it. |
Chris Lattner | f09619d | 2009-01-22 07:04:01 +0000 | [diff] [blame] | 790 | DEBUG(AssertSorted(Cache, NumSortedEntries)); |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 791 | NonLocalDepInfo::iterator Entry = |
Chandler Carruth | 60fb1b4 | 2016-03-07 10:19:30 +0000 | [diff] [blame] | 792 | std::upper_bound(Cache.begin(), Cache.begin() + NumSortedEntries, |
| 793 | NonLocalDepEntry(DirtyBB)); |
Benjamin Kramer | b6d0bd4 | 2014-03-02 12:27:27 +0000 | [diff] [blame] | 794 | if (Entry != Cache.begin() && std::prev(Entry)->getBB() == DirtyBB) |
Chris Lattner | 7e61daf | 2008-12-01 01:15:42 +0000 | [diff] [blame] | 795 | --Entry; |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 796 | |
Craig Topper | 9f00886 | 2014-04-15 04:59:12 +0000 | [diff] [blame] | 797 | NonLocalDepEntry *ExistingResult = nullptr; |
Chandler Carruth | 60fb1b4 | 2016-03-07 10:19:30 +0000 | [diff] [blame] | 798 | if (Entry != Cache.begin() + NumSortedEntries && |
Chris Lattner | 0c31547 | 2009-12-09 07:08:01 +0000 | [diff] [blame] | 799 | Entry->getBB() == DirtyBB) { |
Chris Lattner | 7e61daf | 2008-12-01 01:15:42 +0000 | [diff] [blame] | 800 | // If we already have an entry, and if it isn't already dirty, the block |
| 801 | // is done. |
Chris Lattner | 0c31547 | 2009-12-09 07:08:01 +0000 | [diff] [blame] | 802 | if (!Entry->getResult().isDirty()) |
Chris Lattner | 7e61daf | 2008-12-01 01:15:42 +0000 | [diff] [blame] | 803 | continue; |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 804 | |
Chris Lattner | 7e61daf | 2008-12-01 01:15:42 +0000 | [diff] [blame] | 805 | // Otherwise, remember this slot so we can update the value. |
Chris Lattner | 0c31547 | 2009-12-09 07:08:01 +0000 | [diff] [blame] | 806 | ExistingResult = &*Entry; |
Chris Lattner | 7e61daf | 2008-12-01 01:15:42 +0000 | [diff] [blame] | 807 | } |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 808 | |
Chris Lattner | 2059753 | 2008-11-30 01:18:27 +0000 | [diff] [blame] | 809 | // If the dirty entry has a pointer, start scanning from it so we don't have |
| 810 | // to rescan the entire block. |
| 811 | BasicBlock::iterator ScanPos = DirtyBB->end(); |
Chris Lattner | 7e61daf | 2008-12-01 01:15:42 +0000 | [diff] [blame] | 812 | if (ExistingResult) { |
Chris Lattner | 0c31547 | 2009-12-09 07:08:01 +0000 | [diff] [blame] | 813 | if (Instruction *Inst = ExistingResult->getResult().getInst()) { |
Duncan P. N. Exon Smith | 5a82c91 | 2015-10-10 00:53:03 +0000 | [diff] [blame] | 814 | ScanPos = Inst->getIterator(); |
Chris Lattner | 7e61daf | 2008-12-01 01:15:42 +0000 | [diff] [blame] | 815 | // We're removing QueryInst's use of Inst. |
Chris Lattner | 254314e | 2008-12-09 19:38:05 +0000 | [diff] [blame] | 816 | RemoveFromReverseMap(ReverseNonLocalDeps, Inst, |
| 817 | QueryCS.getInstruction()); |
Chris Lattner | 7e61daf | 2008-12-01 01:15:42 +0000 | [diff] [blame] | 818 | } |
Chris Lattner | 1b810bd | 2008-11-30 02:28:25 +0000 | [diff] [blame] | 819 | } |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 820 | |
Chris Lattner | 60444f8 | 2008-11-30 01:26:32 +0000 | [diff] [blame] | 821 | // Find out if this block has a local dependency for QueryInst. |
Chris Lattner | ed494f7 | 2008-12-07 01:21:14 +0000 | [diff] [blame] | 822 | MemDepResult Dep; |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 823 | |
Chris Lattner | 254314e | 2008-12-09 19:38:05 +0000 | [diff] [blame] | 824 | if (ScanPos != DirtyBB->begin()) { |
Chandler Carruth | 60fb1b4 | 2016-03-07 10:19:30 +0000 | [diff] [blame] | 825 | Dep = |
| 826 | getCallSiteDependencyFrom(QueryCS, isReadonlyCall, ScanPos, DirtyBB); |
Chris Lattner | 254314e | 2008-12-09 19:38:05 +0000 | [diff] [blame] | 827 | } else if (DirtyBB != &DirtyBB->getParent()->getEntryBlock()) { |
| 828 | // No dependence found. If this is the entry block of the function, it is |
Eli Friedman | 7d58bc7 | 2011-06-15 00:47:34 +0000 | [diff] [blame] | 829 | // a clobber, otherwise it is unknown. |
Chris Lattner | 254314e | 2008-12-09 19:38:05 +0000 | [diff] [blame] | 830 | Dep = MemDepResult::getNonLocal(); |
Chris Lattner | 5a78604 | 2008-12-07 01:50:16 +0000 | [diff] [blame] | 831 | } else { |
Eli Friedman | c1702c8 | 2011-10-13 22:14:57 +0000 | [diff] [blame] | 832 | Dep = MemDepResult::getNonFuncLocal(); |
Chris Lattner | 5a78604 | 2008-12-07 01:50:16 +0000 | [diff] [blame] | 833 | } |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 834 | |
Chris Lattner | 7e61daf | 2008-12-01 01:15:42 +0000 | [diff] [blame] | 835 | // If we had a dirty entry for the block, update it. Otherwise, just add |
| 836 | // a new entry. |
| 837 | if (ExistingResult) |
Chris Lattner | 9b7d99e | 2009-12-22 04:25:02 +0000 | [diff] [blame] | 838 | ExistingResult->setResult(Dep); |
Chris Lattner | 7e61daf | 2008-12-01 01:15:42 +0000 | [diff] [blame] | 839 | else |
Chris Lattner | 9b7d99e | 2009-12-22 04:25:02 +0000 | [diff] [blame] | 840 | Cache.push_back(NonLocalDepEntry(DirtyBB, Dep)); |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 841 | |
Chris Lattner | 2059753 | 2008-11-30 01:18:27 +0000 | [diff] [blame] | 842 | // If the block has a dependency (i.e. it isn't completely transparent to |
Chris Lattner | 7e61daf | 2008-12-01 01:15:42 +0000 | [diff] [blame] | 843 | // the value), remember the association! |
| 844 | if (!Dep.isNonLocal()) { |
Chris Lattner | 2059753 | 2008-11-30 01:18:27 +0000 | [diff] [blame] | 845 | // Keep the ReverseNonLocalDeps map up to date so we can efficiently |
| 846 | // update this when we remove instructions. |
Chris Lattner | 7e61daf | 2008-12-01 01:15:42 +0000 | [diff] [blame] | 847 | if (Instruction *Inst = Dep.getInst()) |
Chris Lattner | 254314e | 2008-12-09 19:38:05 +0000 | [diff] [blame] | 848 | ReverseNonLocalDeps[Inst].insert(QueryCS.getInstruction()); |
Chris Lattner | 7e61daf | 2008-12-01 01:15:42 +0000 | [diff] [blame] | 849 | } else { |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 850 | |
Chris Lattner | 7e61daf | 2008-12-01 01:15:42 +0000 | [diff] [blame] | 851 | // If the block *is* completely transparent to the load, we need to check |
| 852 | // the predecessors of this block. Add them to our worklist. |
Daniel Berlin | b4e7a4a | 2015-04-21 21:11:50 +0000 | [diff] [blame] | 853 | for (BasicBlock *Pred : PredCache.get(DirtyBB)) |
| 854 | DirtyBlocks.push_back(Pred); |
Chris Lattner | 7e61daf | 2008-12-01 01:15:42 +0000 | [diff] [blame] | 855 | } |
Chris Lattner | 2059753 | 2008-11-30 01:18:27 +0000 | [diff] [blame] | 856 | } |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 857 | |
Chris Lattner | 7e61daf | 2008-12-01 01:15:42 +0000 | [diff] [blame] | 858 | return Cache; |
Chris Lattner | 2059753 | 2008-11-30 01:18:27 +0000 | [diff] [blame] | 859 | } |
| 860 | |
Chandler Carruth | 61440d2 | 2016-03-10 00:55:30 +0000 | [diff] [blame] | 861 | void MemoryDependenceResults::getNonLocalPointerDependency( |
Chandler Carruth | 60fb1b4 | 2016-03-07 10:19:30 +0000 | [diff] [blame] | 862 | Instruction *QueryInst, SmallVectorImpl<NonLocalDepResult> &Result) { |
Chandler Carruth | ac80dc7 | 2015-06-17 07:18:54 +0000 | [diff] [blame] | 863 | const MemoryLocation Loc = MemoryLocation::get(QueryInst); |
Philip Reames | 567feb9 | 2015-01-09 00:04:22 +0000 | [diff] [blame] | 864 | bool isLoad = isa<LoadInst>(QueryInst); |
| 865 | BasicBlock *FromBB = QueryInst->getParent(); |
| 866 | assert(FromBB); |
Philip Reames | 33d7f9d | 2015-01-09 00:26:45 +0000 | [diff] [blame] | 867 | |
| 868 | assert(Loc.Ptr->getType()->isPointerTy() && |
| 869 | "Can't get pointer deps of a non-pointer!"); |
| 870 | Result.clear(); |
Krzysztof Parzyszek | e261e5a | 2016-02-22 23:07:43 +0000 | [diff] [blame] | 871 | |
Philip Reames | 33d7f9d | 2015-01-09 00:26:45 +0000 | [diff] [blame] | 872 | // This routine does not expect to deal with volatile instructions. |
| 873 | // Doing so would require piping through the QueryInst all the way through. |
Philip Reames | 567feb9 | 2015-01-09 00:04:22 +0000 | [diff] [blame] | 874 | // TODO: volatiles can't be elided, but they can be reordered with other |
Philip Reames | 33d7f9d | 2015-01-09 00:26:45 +0000 | [diff] [blame] | 875 | // non-volatile accesses. |
Philip Reames | a7ad6a5 | 2015-01-26 18:54:27 +0000 | [diff] [blame] | 876 | |
Philip Reames | 567feb9 | 2015-01-09 00:04:22 +0000 | [diff] [blame] | 877 | // We currently give up on any instruction which is ordered, but we do handle |
| 878 | // atomic instructions which are unordered. |
| 879 | // TODO: Handle ordered instructions |
| 880 | auto isOrdered = [](Instruction *Inst) { |
| 881 | if (LoadInst *LI = dyn_cast<LoadInst>(Inst)) { |
| 882 | return !LI->isUnordered(); |
| 883 | } else if (StoreInst *SI = dyn_cast<StoreInst>(Inst)) { |
| 884 | return !SI->isUnordered(); |
| 885 | } |
| 886 | return false; |
| 887 | }; |
Philip Reames | 33d7f9d | 2015-01-09 00:26:45 +0000 | [diff] [blame] | 888 | if (isVolatile(QueryInst) || isOrdered(QueryInst)) { |
Chandler Carruth | 60fb1b4 | 2016-03-07 10:19:30 +0000 | [diff] [blame] | 889 | Result.push_back(NonLocalDepResult(FromBB, MemDepResult::getUnknown(), |
Philip Reames | 33d7f9d | 2015-01-09 00:26:45 +0000 | [diff] [blame] | 890 | const_cast<Value *>(Loc.Ptr))); |
| 891 | return; |
| 892 | } |
Mehdi Amini | a28d91d | 2015-03-10 02:37:25 +0000 | [diff] [blame] | 893 | const DataLayout &DL = FromBB->getModule()->getDataLayout(); |
Daniel Jasper | aec2fa3 | 2016-12-19 08:22:17 +0000 | [diff] [blame] | 894 | PHITransAddr Address(const_cast<Value *>(Loc.Ptr), DL, &AC); |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 895 | |
Chris Lattner | ff9f3db | 2008-12-15 03:35:32 +0000 | [diff] [blame] | 896 | // This is the set of blocks we've inspected, and the pointer we consider in |
| 897 | // each block. Because of critical edges, we currently bail out if querying |
| 898 | // a block with multiple different pointers. This can happen during PHI |
| 899 | // translation. |
Chandler Carruth | 60fb1b4 | 2016-03-07 10:19:30 +0000 | [diff] [blame] | 900 | DenseMap<BasicBlock *, Value *> Visited; |
Chandler Carruth | b32febe | 2016-03-07 12:45:07 +0000 | [diff] [blame] | 901 | if (getNonLocalPointerDepFromBB(QueryInst, Address, Loc, isLoad, FromBB, |
Chris Lattner | ff9f3db | 2008-12-15 03:35:32 +0000 | [diff] [blame] | 902 | Result, Visited, true)) |
| 903 | return; |
Chris Lattner | 7ed5ccc | 2008-12-15 04:58:29 +0000 | [diff] [blame] | 904 | Result.clear(); |
Chandler Carruth | 60fb1b4 | 2016-03-07 10:19:30 +0000 | [diff] [blame] | 905 | Result.push_back(NonLocalDepResult(FromBB, MemDepResult::getUnknown(), |
Dan Gohman | 2348393 | 2010-09-22 21:41:02 +0000 | [diff] [blame] | 906 | const_cast<Value *>(Loc.Ptr))); |
Chris Lattner | 7564a3b | 2008-12-07 02:56:57 +0000 | [diff] [blame] | 907 | } |
| 908 | |
Chandler Carruth | 40e21f2 | 2016-03-07 12:30:06 +0000 | [diff] [blame] | 909 | /// Compute the memdep value for BB with Pointer/PointeeSize using either |
| 910 | /// cached information in Cache or by doing a lookup (which may use dirty cache |
| 911 | /// info if available). |
| 912 | /// |
| 913 | /// If we do a lookup, add the result to the cache. |
Chandler Carruth | 61440d2 | 2016-03-10 00:55:30 +0000 | [diff] [blame] | 914 | MemDepResult MemoryDependenceResults::GetNonLocalInfoForBlock( |
Chandler Carruth | ac80dc7 | 2015-06-17 07:18:54 +0000 | [diff] [blame] | 915 | Instruction *QueryInst, const MemoryLocation &Loc, bool isLoad, |
| 916 | BasicBlock *BB, NonLocalDepInfo *Cache, unsigned NumSortedEntries) { |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 917 | |
Chris Lattner | f903fe1 | 2008-12-09 07:47:11 +0000 | [diff] [blame] | 918 | // Do a binary search to see if we already have an entry for this block in |
| 919 | // the cache set. If so, find it. |
Chandler Carruth | 60fb1b4 | 2016-03-07 10:19:30 +0000 | [diff] [blame] | 920 | NonLocalDepInfo::iterator Entry = std::upper_bound( |
| 921 | Cache->begin(), Cache->begin() + NumSortedEntries, NonLocalDepEntry(BB)); |
| 922 | if (Entry != Cache->begin() && (Entry - 1)->getBB() == BB) |
Chris Lattner | f903fe1 | 2008-12-09 07:47:11 +0000 | [diff] [blame] | 923 | --Entry; |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 924 | |
Craig Topper | 9f00886 | 2014-04-15 04:59:12 +0000 | [diff] [blame] | 925 | NonLocalDepEntry *ExistingResult = nullptr; |
Chandler Carruth | 60fb1b4 | 2016-03-07 10:19:30 +0000 | [diff] [blame] | 926 | if (Entry != Cache->begin() + NumSortedEntries && Entry->getBB() == BB) |
Chris Lattner | 0c31547 | 2009-12-09 07:08:01 +0000 | [diff] [blame] | 927 | ExistingResult = &*Entry; |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 928 | |
Chris Lattner | f903fe1 | 2008-12-09 07:47:11 +0000 | [diff] [blame] | 929 | // If we have a cached entry, and it is non-dirty, use it as the value for |
| 930 | // this dependency. |
Chris Lattner | 0c31547 | 2009-12-09 07:08:01 +0000 | [diff] [blame] | 931 | if (ExistingResult && !ExistingResult->getResult().isDirty()) { |
Chris Lattner | f903fe1 | 2008-12-09 07:47:11 +0000 | [diff] [blame] | 932 | ++NumCacheNonLocalPtr; |
Chris Lattner | 0c31547 | 2009-12-09 07:08:01 +0000 | [diff] [blame] | 933 | return ExistingResult->getResult(); |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 934 | } |
| 935 | |
Chris Lattner | f903fe1 | 2008-12-09 07:47:11 +0000 | [diff] [blame] | 936 | // Otherwise, we have to scan for the value. If we have a dirty cache |
| 937 | // entry, start scanning from its position, otherwise we scan from the end |
| 938 | // of the block. |
| 939 | BasicBlock::iterator ScanPos = BB->end(); |
Chris Lattner | 0c31547 | 2009-12-09 07:08:01 +0000 | [diff] [blame] | 940 | if (ExistingResult && ExistingResult->getResult().getInst()) { |
| 941 | assert(ExistingResult->getResult().getInst()->getParent() == BB && |
Chris Lattner | f903fe1 | 2008-12-09 07:47:11 +0000 | [diff] [blame] | 942 | "Instruction invalidated?"); |
| 943 | ++NumCacheDirtyNonLocalPtr; |
Duncan P. N. Exon Smith | 5a82c91 | 2015-10-10 00:53:03 +0000 | [diff] [blame] | 944 | ScanPos = ExistingResult->getResult().getInst()->getIterator(); |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 945 | |
Chris Lattner | f903fe1 | 2008-12-09 07:47:11 +0000 | [diff] [blame] | 946 | // Eliminating the dirty entry from 'Cache', so update the reverse info. |
Dan Gohman | 2348393 | 2010-09-22 21:41:02 +0000 | [diff] [blame] | 947 | ValueIsLoadPair CacheKey(Loc.Ptr, isLoad); |
Duncan P. N. Exon Smith | 5a82c91 | 2015-10-10 00:53:03 +0000 | [diff] [blame] | 948 | RemoveFromReverseMap(ReverseNonLocalPtrDeps, &*ScanPos, CacheKey); |
Chris Lattner | f903fe1 | 2008-12-09 07:47:11 +0000 | [diff] [blame] | 949 | } else { |
| 950 | ++NumUncacheNonLocalPtr; |
| 951 | } |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 952 | |
Chris Lattner | f903fe1 | 2008-12-09 07:47:11 +0000 | [diff] [blame] | 953 | // Scan the block for the dependency. |
Chandler Carruth | 60fb1b4 | 2016-03-07 10:19:30 +0000 | [diff] [blame] | 954 | MemDepResult Dep = |
| 955 | getPointerDependencyFrom(Loc, isLoad, ScanPos, BB, QueryInst); |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 956 | |
Chris Lattner | f903fe1 | 2008-12-09 07:47:11 +0000 | [diff] [blame] | 957 | // If we had a dirty entry for the block, update it. Otherwise, just add |
| 958 | // a new entry. |
| 959 | if (ExistingResult) |
Chris Lattner | 9b7d99e | 2009-12-22 04:25:02 +0000 | [diff] [blame] | 960 | ExistingResult->setResult(Dep); |
Chris Lattner | f903fe1 | 2008-12-09 07:47:11 +0000 | [diff] [blame] | 961 | else |
Chris Lattner | 9b7d99e | 2009-12-22 04:25:02 +0000 | [diff] [blame] | 962 | Cache->push_back(NonLocalDepEntry(BB, Dep)); |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 963 | |
Chris Lattner | f903fe1 | 2008-12-09 07:47:11 +0000 | [diff] [blame] | 964 | // If the block has a dependency (i.e. it isn't completely transparent to |
| 965 | // the value), remember the reverse association because we just added it |
| 966 | // to Cache! |
Eli Friedman | c1702c8 | 2011-10-13 22:14:57 +0000 | [diff] [blame] | 967 | if (!Dep.isDef() && !Dep.isClobber()) |
Chris Lattner | f903fe1 | 2008-12-09 07:47:11 +0000 | [diff] [blame] | 968 | return Dep; |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 969 | |
Chris Lattner | f903fe1 | 2008-12-09 07:47:11 +0000 | [diff] [blame] | 970 | // Keep the ReverseNonLocalPtrDeps map up to date so we can efficiently |
| 971 | // update MemDep when we remove instructions. |
| 972 | Instruction *Inst = Dep.getInst(); |
| 973 | assert(Inst && "Didn't depend on anything?"); |
Dan Gohman | 2348393 | 2010-09-22 21:41:02 +0000 | [diff] [blame] | 974 | ValueIsLoadPair CacheKey(Loc.Ptr, isLoad); |
Chris Lattner | 8eda11b | 2009-03-29 00:24:04 +0000 | [diff] [blame] | 975 | ReverseNonLocalPtrDeps[Inst].insert(CacheKey); |
Chris Lattner | f903fe1 | 2008-12-09 07:47:11 +0000 | [diff] [blame] | 976 | return Dep; |
| 977 | } |
| 978 | |
Chandler Carruth | 40e21f2 | 2016-03-07 12:30:06 +0000 | [diff] [blame] | 979 | /// Sort the NonLocalDepInfo cache, given a certain number of elements in the |
| 980 | /// array that are already properly ordered. |
| 981 | /// |
| 982 | /// This is optimized for the case when only a few entries are added. |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 983 | static void |
Chandler Carruth | 61440d2 | 2016-03-10 00:55:30 +0000 | [diff] [blame] | 984 | SortNonLocalDepInfoCache(MemoryDependenceResults::NonLocalDepInfo &Cache, |
Chris Lattner | 370aada | 2009-07-13 17:20:05 +0000 | [diff] [blame] | 985 | unsigned NumSortedEntries) { |
| 986 | switch (Cache.size() - NumSortedEntries) { |
| 987 | case 0: |
| 988 | // done, no new entries. |
| 989 | break; |
| 990 | case 2: { |
| 991 | // Two new entries, insert the last one into place. |
Chris Lattner | 0c31547 | 2009-12-09 07:08:01 +0000 | [diff] [blame] | 992 | NonLocalDepEntry Val = Cache.back(); |
Chris Lattner | 370aada | 2009-07-13 17:20:05 +0000 | [diff] [blame] | 993 | Cache.pop_back(); |
Chandler Carruth | 61440d2 | 2016-03-10 00:55:30 +0000 | [diff] [blame] | 994 | MemoryDependenceResults::NonLocalDepInfo::iterator Entry = |
Chandler Carruth | 60fb1b4 | 2016-03-07 10:19:30 +0000 | [diff] [blame] | 995 | std::upper_bound(Cache.begin(), Cache.end() - 1, Val); |
Chris Lattner | 370aada | 2009-07-13 17:20:05 +0000 | [diff] [blame] | 996 | Cache.insert(Entry, Val); |
Justin Bogner | cd1d5aa | 2016-08-17 20:30:52 +0000 | [diff] [blame] | 997 | LLVM_FALLTHROUGH; |
Chris Lattner | 370aada | 2009-07-13 17:20:05 +0000 | [diff] [blame] | 998 | } |
| 999 | case 1: |
| 1000 | // One new entry, Just insert the new value at the appropriate position. |
| 1001 | if (Cache.size() != 1) { |
Chris Lattner | 0c31547 | 2009-12-09 07:08:01 +0000 | [diff] [blame] | 1002 | NonLocalDepEntry Val = Cache.back(); |
Chris Lattner | 370aada | 2009-07-13 17:20:05 +0000 | [diff] [blame] | 1003 | Cache.pop_back(); |
Chandler Carruth | 61440d2 | 2016-03-10 00:55:30 +0000 | [diff] [blame] | 1004 | MemoryDependenceResults::NonLocalDepInfo::iterator Entry = |
Chandler Carruth | 60fb1b4 | 2016-03-07 10:19:30 +0000 | [diff] [blame] | 1005 | std::upper_bound(Cache.begin(), Cache.end(), Val); |
Chris Lattner | 370aada | 2009-07-13 17:20:05 +0000 | [diff] [blame] | 1006 | Cache.insert(Entry, Val); |
| 1007 | } |
| 1008 | break; |
| 1009 | default: |
| 1010 | // Added many values, do a full scale sort. |
| 1011 | std::sort(Cache.begin(), Cache.end()); |
| 1012 | break; |
| 1013 | } |
| 1014 | } |
| 1015 | |
Chandler Carruth | 40e21f2 | 2016-03-07 12:30:06 +0000 | [diff] [blame] | 1016 | /// Perform a dependency query based on pointer/pointeesize starting at the end |
| 1017 | /// of StartBB. |
| 1018 | /// |
| 1019 | /// Add any clobber/def results to the results vector and keep track of which |
| 1020 | /// blocks are visited in 'Visited'. |
Chris Lattner | ff9f3db | 2008-12-15 03:35:32 +0000 | [diff] [blame] | 1021 | /// |
| 1022 | /// This has special behavior for the first block queries (when SkipFirstBlock |
| 1023 | /// is true). In this special case, it ignores the contents of the specified |
| 1024 | /// block and starts returning dependence info for its predecessors. |
| 1025 | /// |
Chandler Carruth | b32febe | 2016-03-07 12:45:07 +0000 | [diff] [blame] | 1026 | /// This function returns true on success, or false to indicate that it could |
Chris Lattner | ff9f3db | 2008-12-15 03:35:32 +0000 | [diff] [blame] | 1027 | /// not compute dependence information for some reason. This should be treated |
| 1028 | /// as a clobber dependence on the first instruction in the predecessor block. |
Chandler Carruth | 61440d2 | 2016-03-10 00:55:30 +0000 | [diff] [blame] | 1029 | bool MemoryDependenceResults::getNonLocalPointerDepFromBB( |
Chandler Carruth | ac80dc7 | 2015-06-17 07:18:54 +0000 | [diff] [blame] | 1030 | Instruction *QueryInst, const PHITransAddr &Pointer, |
| 1031 | const MemoryLocation &Loc, bool isLoad, BasicBlock *StartBB, |
| 1032 | SmallVectorImpl<NonLocalDepResult> &Result, |
| 1033 | DenseMap<BasicBlock *, Value *> &Visited, bool SkipFirstBlock) { |
Chris Lattner | a28355d | 2008-12-07 08:50:20 +0000 | [diff] [blame] | 1034 | // Look up the cached info for Pointer. |
Chris Lattner | 972e6d8 | 2009-12-09 01:59:31 +0000 | [diff] [blame] | 1035 | ValueIsLoadPair CacheKey(Pointer.getAddr(), isLoad); |
Dan Gohman | 2348393 | 2010-09-22 21:41:02 +0000 | [diff] [blame] | 1036 | |
Dan Gohman | 0a6021a | 2010-11-10 20:37:15 +0000 | [diff] [blame] | 1037 | // Set up a temporary NLPI value. If the map doesn't yet have an entry for |
| 1038 | // CacheKey, this value will be inserted as the associated value. Otherwise, |
| 1039 | // it'll be ignored, and we'll have to check to see if the cached size and |
Hal Finkel | cc39b67 | 2014-07-24 12:16:19 +0000 | [diff] [blame] | 1040 | // aa tags are consistent with the current query. |
Dan Gohman | 0a6021a | 2010-11-10 20:37:15 +0000 | [diff] [blame] | 1041 | NonLocalPointerInfo InitialNLPI; |
| 1042 | InitialNLPI.Size = Loc.Size; |
Hal Finkel | cc39b67 | 2014-07-24 12:16:19 +0000 | [diff] [blame] | 1043 | InitialNLPI.AATags = Loc.AATags; |
Dan Gohman | 0a6021a | 2010-11-10 20:37:15 +0000 | [diff] [blame] | 1044 | |
| 1045 | // Get the NLPI for CacheKey, inserting one into the map if it doesn't |
| 1046 | // already have one. |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 1047 | std::pair<CachedNonLocalPointerInfo::iterator, bool> Pair = |
Chandler Carruth | 60fb1b4 | 2016-03-07 10:19:30 +0000 | [diff] [blame] | 1048 | NonLocalPointerDeps.insert(std::make_pair(CacheKey, InitialNLPI)); |
Dan Gohman | 0a6021a | 2010-11-10 20:37:15 +0000 | [diff] [blame] | 1049 | NonLocalPointerInfo *CacheInfo = &Pair.first->second; |
| 1050 | |
Dan Gohman | 2e8ca44 | 2010-11-10 21:45:11 +0000 | [diff] [blame] | 1051 | // If we already have a cache entry for this CacheKey, we may need to do some |
| 1052 | // work to reconcile the cache entry and the current query. |
Dan Gohman | 0a6021a | 2010-11-10 20:37:15 +0000 | [diff] [blame] | 1053 | if (!Pair.second) { |
Dan Gohman | 2e8ca44 | 2010-11-10 21:45:11 +0000 | [diff] [blame] | 1054 | if (CacheInfo->Size < Loc.Size) { |
| 1055 | // The query's Size is greater than the cached one. Throw out the |
Benjamin Kramer | bde9176 | 2012-06-02 10:20:22 +0000 | [diff] [blame] | 1056 | // cached data and proceed with the query at the greater size. |
Dan Gohman | 2e8ca44 | 2010-11-10 21:45:11 +0000 | [diff] [blame] | 1057 | CacheInfo->Pair = BBSkipFirstBlockPair(); |
| 1058 | CacheInfo->Size = Loc.Size; |
Chandler Carruth | af8321e | 2016-03-07 15:12:57 +0000 | [diff] [blame] | 1059 | for (auto &Entry : CacheInfo->NonLocalDeps) |
| 1060 | if (Instruction *Inst = Entry.getResult().getInst()) |
Dan Gohman | 6791936 | 2010-11-10 22:35:02 +0000 | [diff] [blame] | 1061 | RemoveFromReverseMap(ReverseNonLocalPtrDeps, Inst, CacheKey); |
Dan Gohman | 2e8ca44 | 2010-11-10 21:45:11 +0000 | [diff] [blame] | 1062 | CacheInfo->NonLocalDeps.clear(); |
| 1063 | } else if (CacheInfo->Size > Loc.Size) { |
| 1064 | // This query's Size is less than the cached one. Conservatively restart |
| 1065 | // the query using the greater size. |
Chandler Carruth | 60fb1b4 | 2016-03-07 10:19:30 +0000 | [diff] [blame] | 1066 | return getNonLocalPointerDepFromBB( |
| 1067 | QueryInst, Pointer, Loc.getWithNewSize(CacheInfo->Size), isLoad, |
| 1068 | StartBB, Result, Visited, SkipFirstBlock); |
Dan Gohman | 0a6021a | 2010-11-10 20:37:15 +0000 | [diff] [blame] | 1069 | } |
| 1070 | |
Hal Finkel | cc39b67 | 2014-07-24 12:16:19 +0000 | [diff] [blame] | 1071 | // If the query's AATags are inconsistent with the cached one, |
Dan Gohman | 2e8ca44 | 2010-11-10 21:45:11 +0000 | [diff] [blame] | 1072 | // conservatively throw out the cached data and restart the query with |
| 1073 | // no tag if needed. |
Hal Finkel | cc39b67 | 2014-07-24 12:16:19 +0000 | [diff] [blame] | 1074 | if (CacheInfo->AATags != Loc.AATags) { |
| 1075 | if (CacheInfo->AATags) { |
Dan Gohman | 2e8ca44 | 2010-11-10 21:45:11 +0000 | [diff] [blame] | 1076 | CacheInfo->Pair = BBSkipFirstBlockPair(); |
Hal Finkel | cc39b67 | 2014-07-24 12:16:19 +0000 | [diff] [blame] | 1077 | CacheInfo->AATags = AAMDNodes(); |
Chandler Carruth | af8321e | 2016-03-07 15:12:57 +0000 | [diff] [blame] | 1078 | for (auto &Entry : CacheInfo->NonLocalDeps) |
| 1079 | if (Instruction *Inst = Entry.getResult().getInst()) |
Dan Gohman | 6791936 | 2010-11-10 22:35:02 +0000 | [diff] [blame] | 1080 | RemoveFromReverseMap(ReverseNonLocalPtrDeps, Inst, CacheKey); |
Dan Gohman | 2e8ca44 | 2010-11-10 21:45:11 +0000 | [diff] [blame] | 1081 | CacheInfo->NonLocalDeps.clear(); |
| 1082 | } |
Hal Finkel | cc39b67 | 2014-07-24 12:16:19 +0000 | [diff] [blame] | 1083 | if (Loc.AATags) |
Chandler Carruth | 60fb1b4 | 2016-03-07 10:19:30 +0000 | [diff] [blame] | 1084 | return getNonLocalPointerDepFromBB( |
| 1085 | QueryInst, Pointer, Loc.getWithoutAATags(), isLoad, StartBB, Result, |
| 1086 | Visited, SkipFirstBlock); |
Dan Gohman | 0a6021a | 2010-11-10 20:37:15 +0000 | [diff] [blame] | 1087 | } |
Dan Gohman | 2348393 | 2010-09-22 21:41:02 +0000 | [diff] [blame] | 1088 | } |
| 1089 | |
| 1090 | NonLocalDepInfo *Cache = &CacheInfo->NonLocalDeps; |
Chris Lattner | 5ed409e | 2008-12-08 07:31:50 +0000 | [diff] [blame] | 1091 | |
| 1092 | // If we have valid cached information for exactly the block we are |
| 1093 | // investigating, just return it with no recomputation. |
Dan Gohman | 2348393 | 2010-09-22 21:41:02 +0000 | [diff] [blame] | 1094 | if (CacheInfo->Pair == BBSkipFirstBlockPair(StartBB, SkipFirstBlock)) { |
Chris Lattner | 8b4be37 | 2008-12-16 07:10:09 +0000 | [diff] [blame] | 1095 | // We have a fully cached result for this query then we can just return the |
| 1096 | // cached results and populate the visited set. However, we have to verify |
| 1097 | // that we don't already have conflicting results for these blocks. Check |
| 1098 | // to ensure that if a block in the results set is in the visited set that |
| 1099 | // it was for the same pointer query. |
| 1100 | if (!Visited.empty()) { |
Chandler Carruth | af8321e | 2016-03-07 15:12:57 +0000 | [diff] [blame] | 1101 | for (auto &Entry : *Cache) { |
| 1102 | DenseMap<BasicBlock *, Value *>::iterator VI = |
| 1103 | Visited.find(Entry.getBB()); |
Chris Lattner | 972e6d8 | 2009-12-09 01:59:31 +0000 | [diff] [blame] | 1104 | if (VI == Visited.end() || VI->second == Pointer.getAddr()) |
| 1105 | continue; |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 1106 | |
Chandler Carruth | b32febe | 2016-03-07 12:45:07 +0000 | [diff] [blame] | 1107 | // We have a pointer mismatch in a block. Just return false, saying |
Chris Lattner | 8b4be37 | 2008-12-16 07:10:09 +0000 | [diff] [blame] | 1108 | // that something was clobbered in this result. We could also do a |
| 1109 | // non-fully cached query, but there is little point in doing this. |
Chandler Carruth | b32febe | 2016-03-07 12:45:07 +0000 | [diff] [blame] | 1110 | return false; |
Chris Lattner | 8b4be37 | 2008-12-16 07:10:09 +0000 | [diff] [blame] | 1111 | } |
| 1112 | } |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 1113 | |
Chris Lattner | 9b7d99e | 2009-12-22 04:25:02 +0000 | [diff] [blame] | 1114 | Value *Addr = Pointer.getAddr(); |
Chandler Carruth | af8321e | 2016-03-07 15:12:57 +0000 | [diff] [blame] | 1115 | for (auto &Entry : *Cache) { |
| 1116 | Visited.insert(std::make_pair(Entry.getBB(), Addr)); |
| 1117 | if (Entry.getResult().isNonLocal()) { |
Matt Arsenault | c23753a | 2013-05-06 02:07:24 +0000 | [diff] [blame] | 1118 | continue; |
| 1119 | } |
| 1120 | |
Chandler Carruth | aef32bd | 2016-03-11 13:46:00 +0000 | [diff] [blame] | 1121 | if (DT.isReachableFromEntry(Entry.getBB())) { |
Chandler Carruth | af8321e | 2016-03-07 15:12:57 +0000 | [diff] [blame] | 1122 | Result.push_back( |
| 1123 | NonLocalDepResult(Entry.getBB(), Entry.getResult(), Addr)); |
Matt Arsenault | c23753a | 2013-05-06 02:07:24 +0000 | [diff] [blame] | 1124 | } |
Chris Lattner | 8b4be37 | 2008-12-16 07:10:09 +0000 | [diff] [blame] | 1125 | } |
Chris Lattner | 5ed409e | 2008-12-08 07:31:50 +0000 | [diff] [blame] | 1126 | ++NumCacheCompleteNonLocalPtr; |
Chandler Carruth | b32febe | 2016-03-07 12:45:07 +0000 | [diff] [blame] | 1127 | return true; |
Chris Lattner | 5ed409e | 2008-12-08 07:31:50 +0000 | [diff] [blame] | 1128 | } |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 1129 | |
Chris Lattner | 5ed409e | 2008-12-08 07:31:50 +0000 | [diff] [blame] | 1130 | // Otherwise, either this is a new block, a block with an invalid cache |
| 1131 | // pointer or one that we're about to invalidate by putting more info into it |
| 1132 | // than its valid cache info. If empty, the result will be valid cache info, |
| 1133 | // otherwise it isn't. |
Chris Lattner | ff9f3db | 2008-12-15 03:35:32 +0000 | [diff] [blame] | 1134 | if (Cache->empty()) |
Dan Gohman | 2348393 | 2010-09-22 21:41:02 +0000 | [diff] [blame] | 1135 | CacheInfo->Pair = BBSkipFirstBlockPair(StartBB, SkipFirstBlock); |
Dan Gohman | c87c843 | 2010-11-11 00:42:22 +0000 | [diff] [blame] | 1136 | else |
Dan Gohman | 2348393 | 2010-09-22 21:41:02 +0000 | [diff] [blame] | 1137 | CacheInfo->Pair = BBSkipFirstBlockPair(); |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 1138 | |
Chandler Carruth | 60fb1b4 | 2016-03-07 10:19:30 +0000 | [diff] [blame] | 1139 | SmallVector<BasicBlock *, 32> Worklist; |
Chris Lattner | 5ed409e | 2008-12-08 07:31:50 +0000 | [diff] [blame] | 1140 | Worklist.push_back(StartBB); |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 1141 | |
Eli Friedman | 4b6eeb9 | 2011-06-01 23:16:53 +0000 | [diff] [blame] | 1142 | // PredList used inside loop. |
Chandler Carruth | 60fb1b4 | 2016-03-07 10:19:30 +0000 | [diff] [blame] | 1143 | SmallVector<std::pair<BasicBlock *, PHITransAddr>, 16> PredList; |
Eli Friedman | 4b6eeb9 | 2011-06-01 23:16:53 +0000 | [diff] [blame] | 1144 | |
Chris Lattner | a28355d | 2008-12-07 08:50:20 +0000 | [diff] [blame] | 1145 | // Keep track of the entries that we know are sorted. Previously cached |
| 1146 | // entries will all be sorted. The entries we add we only sort on demand (we |
| 1147 | // don't insert every element into its sorted position). We know that we |
| 1148 | // won't get any reuse from currently inserted values, because we don't |
| 1149 | // revisit blocks after we insert info for them. |
| 1150 | unsigned NumSortedEntries = Cache->size(); |
Joerg Sonnenberger | 36894dc | 2016-02-20 11:24:44 +0000 | [diff] [blame] | 1151 | unsigned WorklistEntries = BlockNumberLimit; |
| 1152 | bool GotWorklistLimit = false; |
Chris Lattner | f09619d | 2009-01-22 07:04:01 +0000 | [diff] [blame] | 1153 | DEBUG(AssertSorted(*Cache)); |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 1154 | |
Chris Lattner | 2faa2c7 | 2008-12-07 02:15:47 +0000 | [diff] [blame] | 1155 | while (!Worklist.empty()) { |
Chris Lattner | 7564a3b | 2008-12-07 02:56:57 +0000 | [diff] [blame] | 1156 | BasicBlock *BB = Worklist.pop_back_val(); |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 1157 | |
Bruno Cardoso Lopes | e3c513a | 2014-10-01 20:07:13 +0000 | [diff] [blame] | 1158 | // If we do process a large number of blocks it becomes very expensive and |
| 1159 | // likely it isn't worth worrying about |
| 1160 | if (Result.size() > NumResultsLimit) { |
| 1161 | Worklist.clear(); |
| 1162 | // Sort it now (if needed) so that recursive invocations of |
| 1163 | // getNonLocalPointerDepFromBB and other routines that could reuse the |
| 1164 | // cache value will only see properly sorted cache arrays. |
| 1165 | if (Cache && NumSortedEntries != Cache->size()) { |
| 1166 | SortNonLocalDepInfoCache(*Cache, NumSortedEntries); |
Bruno Cardoso Lopes | e3c513a | 2014-10-01 20:07:13 +0000 | [diff] [blame] | 1167 | } |
| 1168 | // Since we bail out, the "Cache" set won't contain all of the |
| 1169 | // results for the query. This is ok (we can still use it to accelerate |
| 1170 | // specific block queries) but we can't do the fastpath "return all |
| 1171 | // results from the set". Clear out the indicator for this. |
| 1172 | CacheInfo->Pair = BBSkipFirstBlockPair(); |
Chandler Carruth | b32febe | 2016-03-07 12:45:07 +0000 | [diff] [blame] | 1173 | return false; |
Bruno Cardoso Lopes | e3c513a | 2014-10-01 20:07:13 +0000 | [diff] [blame] | 1174 | } |
| 1175 | |
Chris Lattner | 75510d8 | 2008-12-09 07:52:59 +0000 | [diff] [blame] | 1176 | // Skip the first block if we have it. |
Chris Lattner | ff9f3db | 2008-12-15 03:35:32 +0000 | [diff] [blame] | 1177 | if (!SkipFirstBlock) { |
Chris Lattner | 75510d8 | 2008-12-09 07:52:59 +0000 | [diff] [blame] | 1178 | // Analyze the dependency of *Pointer in FromBB. See if we already have |
| 1179 | // been here. |
Chris Lattner | ff9f3db | 2008-12-15 03:35:32 +0000 | [diff] [blame] | 1180 | assert(Visited.count(BB) && "Should check 'visited' before adding to WL"); |
Chris Lattner | a28355d | 2008-12-07 08:50:20 +0000 | [diff] [blame] | 1181 | |
Chris Lattner | 75510d8 | 2008-12-09 07:52:59 +0000 | [diff] [blame] | 1182 | // Get the dependency info for Pointer in BB. If we have cached |
| 1183 | // information, we will use it, otherwise we compute it. |
Chris Lattner | f09619d | 2009-01-22 07:04:01 +0000 | [diff] [blame] | 1184 | DEBUG(AssertSorted(*Cache, NumSortedEntries)); |
Chandler Carruth | 60fb1b4 | 2016-03-07 10:19:30 +0000 | [diff] [blame] | 1185 | MemDepResult Dep = GetNonLocalInfoForBlock(QueryInst, Loc, isLoad, BB, |
| 1186 | Cache, NumSortedEntries); |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 1187 | |
Chris Lattner | 75510d8 | 2008-12-09 07:52:59 +0000 | [diff] [blame] | 1188 | // If we got a Def or Clobber, add this to the list of results. |
Matt Arsenault | c23753a | 2013-05-06 02:07:24 +0000 | [diff] [blame] | 1189 | if (!Dep.isNonLocal()) { |
Chandler Carruth | aef32bd | 2016-03-11 13:46:00 +0000 | [diff] [blame] | 1190 | if (DT.isReachableFromEntry(BB)) { |
Matt Arsenault | c23753a | 2013-05-06 02:07:24 +0000 | [diff] [blame] | 1191 | Result.push_back(NonLocalDepResult(BB, Dep, Pointer.getAddr())); |
| 1192 | continue; |
| 1193 | } |
Chris Lattner | 75510d8 | 2008-12-09 07:52:59 +0000 | [diff] [blame] | 1194 | } |
Chris Lattner | 2faa2c7 | 2008-12-07 02:15:47 +0000 | [diff] [blame] | 1195 | } |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 1196 | |
Chris Lattner | ff9f3db | 2008-12-15 03:35:32 +0000 | [diff] [blame] | 1197 | // If 'Pointer' is an instruction defined in this block, then we need to do |
| 1198 | // phi translation to change it into a value live in the predecessor block. |
Chris Lattner | 972e6d8 | 2009-12-09 01:59:31 +0000 | [diff] [blame] | 1199 | // If not, we just add the predecessors to the worklist and scan them with |
| 1200 | // the same Pointer. |
| 1201 | if (!Pointer.NeedsPHITranslationFromBlock(BB)) { |
Chris Lattner | ff9f3db | 2008-12-15 03:35:32 +0000 | [diff] [blame] | 1202 | SkipFirstBlock = false; |
Chandler Carruth | 60fb1b4 | 2016-03-07 10:19:30 +0000 | [diff] [blame] | 1203 | SmallVector<BasicBlock *, 16> NewBlocks; |
Daniel Berlin | b4e7a4a | 2015-04-21 21:11:50 +0000 | [diff] [blame] | 1204 | for (BasicBlock *Pred : PredCache.get(BB)) { |
Chris Lattner | ff9f3db | 2008-12-15 03:35:32 +0000 | [diff] [blame] | 1205 | // Verify that we haven't looked at this block yet. |
Chandler Carruth | 60fb1b4 | 2016-03-07 10:19:30 +0000 | [diff] [blame] | 1206 | std::pair<DenseMap<BasicBlock *, Value *>::iterator, bool> InsertRes = |
| 1207 | Visited.insert(std::make_pair(Pred, Pointer.getAddr())); |
Chris Lattner | ff9f3db | 2008-12-15 03:35:32 +0000 | [diff] [blame] | 1208 | if (InsertRes.second) { |
| 1209 | // First time we've looked at *PI. |
Daniel Berlin | b4e7a4a | 2015-04-21 21:11:50 +0000 | [diff] [blame] | 1210 | NewBlocks.push_back(Pred); |
Chris Lattner | ff9f3db | 2008-12-15 03:35:32 +0000 | [diff] [blame] | 1211 | continue; |
| 1212 | } |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 1213 | |
Chris Lattner | ff9f3db | 2008-12-15 03:35:32 +0000 | [diff] [blame] | 1214 | // If we have seen this block before, but it was with a different |
| 1215 | // pointer then we have a phi translation failure and we have to treat |
| 1216 | // this as a clobber. |
Eli Friedman | 4b6eeb9 | 2011-06-01 23:16:53 +0000 | [diff] [blame] | 1217 | if (InsertRes.first->second != Pointer.getAddr()) { |
| 1218 | // Make sure to clean up the Visited map before continuing on to |
| 1219 | // PredTranslationFailure. |
| 1220 | for (unsigned i = 0; i < NewBlocks.size(); i++) |
| 1221 | Visited.erase(NewBlocks[i]); |
Chris Lattner | ff9f3db | 2008-12-15 03:35:32 +0000 | [diff] [blame] | 1222 | goto PredTranslationFailure; |
Eli Friedman | 4b6eeb9 | 2011-06-01 23:16:53 +0000 | [diff] [blame] | 1223 | } |
Chris Lattner | ff9f3db | 2008-12-15 03:35:32 +0000 | [diff] [blame] | 1224 | } |
Joerg Sonnenberger | 36894dc | 2016-02-20 11:24:44 +0000 | [diff] [blame] | 1225 | if (NewBlocks.size() > WorklistEntries) { |
| 1226 | // Make sure to clean up the Visited map before continuing on to |
| 1227 | // PredTranslationFailure. |
| 1228 | for (unsigned i = 0; i < NewBlocks.size(); i++) |
| 1229 | Visited.erase(NewBlocks[i]); |
| 1230 | GotWorklistLimit = true; |
| 1231 | goto PredTranslationFailure; |
| 1232 | } |
| 1233 | WorklistEntries -= NewBlocks.size(); |
Eli Friedman | 4b6eeb9 | 2011-06-01 23:16:53 +0000 | [diff] [blame] | 1234 | Worklist.append(NewBlocks.begin(), NewBlocks.end()); |
Chris Lattner | ff9f3db | 2008-12-15 03:35:32 +0000 | [diff] [blame] | 1235 | continue; |
| 1236 | } |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 1237 | |
Chris Lattner | 972e6d8 | 2009-12-09 01:59:31 +0000 | [diff] [blame] | 1238 | // We do need to do phi translation, if we know ahead of time we can't phi |
| 1239 | // translate this value, don't even try. |
| 1240 | if (!Pointer.IsPotentiallyPHITranslatable()) |
| 1241 | goto PredTranslationFailure; |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 1242 | |
Chris Lattner | 2f0c1c4 | 2009-07-13 17:14:23 +0000 | [diff] [blame] | 1243 | // We may have added values to the cache list before this PHI translation. |
| 1244 | // If so, we haven't done anything to ensure that the cache remains sorted. |
| 1245 | // Sort it now (if needed) so that recursive invocations of |
| 1246 | // getNonLocalPointerDepFromBB and other routines that could reuse the cache |
| 1247 | // value will only see properly sorted cache arrays. |
| 1248 | if (Cache && NumSortedEntries != Cache->size()) { |
Chris Lattner | 370aada | 2009-07-13 17:20:05 +0000 | [diff] [blame] | 1249 | SortNonLocalDepInfoCache(*Cache, NumSortedEntries); |
Chris Lattner | 2f0c1c4 | 2009-07-13 17:14:23 +0000 | [diff] [blame] | 1250 | NumSortedEntries = Cache->size(); |
| 1251 | } |
Craig Topper | 9f00886 | 2014-04-15 04:59:12 +0000 | [diff] [blame] | 1252 | Cache = nullptr; |
Eli Friedman | 4b6eeb9 | 2011-06-01 23:16:53 +0000 | [diff] [blame] | 1253 | |
| 1254 | PredList.clear(); |
Daniel Berlin | b4e7a4a | 2015-04-21 21:11:50 +0000 | [diff] [blame] | 1255 | for (BasicBlock *Pred : PredCache.get(BB)) { |
Eli Friedman | 4b6eeb9 | 2011-06-01 23:16:53 +0000 | [diff] [blame] | 1256 | PredList.push_back(std::make_pair(Pred, Pointer)); |
| 1257 | |
Chris Lattner | 972e6d8 | 2009-12-09 01:59:31 +0000 | [diff] [blame] | 1258 | // Get the PHI translated pointer in this predecessor. This can fail if |
| 1259 | // not translatable, in which case the getAddr() returns null. |
Eli Friedman | 4b6eeb9 | 2011-06-01 23:16:53 +0000 | [diff] [blame] | 1260 | PHITransAddr &PredPointer = PredList.back().second; |
Chandler Carruth | aef32bd | 2016-03-11 13:46:00 +0000 | [diff] [blame] | 1261 | PredPointer.PHITranslateValue(BB, Pred, &DT, /*MustDominate=*/false); |
Chris Lattner | 972e6d8 | 2009-12-09 01:59:31 +0000 | [diff] [blame] | 1262 | Value *PredPtrVal = PredPointer.getAddr(); |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 1263 | |
Chris Lattner | ac32329 | 2009-11-27 08:37:22 +0000 | [diff] [blame] | 1264 | // Check to see if we have already visited this pred block with another |
| 1265 | // pointer. If so, we can't do this lookup. This failure can occur |
| 1266 | // with PHI translation when a critical edge exists and the PHI node in |
| 1267 | // the successor translates to a pointer value different than the |
| 1268 | // pointer the block was first analyzed with. |
Chandler Carruth | 60fb1b4 | 2016-03-07 10:19:30 +0000 | [diff] [blame] | 1269 | std::pair<DenseMap<BasicBlock *, Value *>::iterator, bool> InsertRes = |
| 1270 | Visited.insert(std::make_pair(Pred, PredPtrVal)); |
Chris Lattner | ff9f3db | 2008-12-15 03:35:32 +0000 | [diff] [blame] | 1271 | |
Chris Lattner | ac32329 | 2009-11-27 08:37:22 +0000 | [diff] [blame] | 1272 | if (!InsertRes.second) { |
Eli Friedman | 4b6eeb9 | 2011-06-01 23:16:53 +0000 | [diff] [blame] | 1273 | // We found the pred; take it off the list of preds to visit. |
| 1274 | PredList.pop_back(); |
| 1275 | |
Chris Lattner | ac32329 | 2009-11-27 08:37:22 +0000 | [diff] [blame] | 1276 | // If the predecessor was visited with PredPtr, then we already did |
| 1277 | // the analysis and can ignore it. |
Chris Lattner | 972e6d8 | 2009-12-09 01:59:31 +0000 | [diff] [blame] | 1278 | if (InsertRes.first->second == PredPtrVal) |
Chris Lattner | ac32329 | 2009-11-27 08:37:22 +0000 | [diff] [blame] | 1279 | continue; |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 1280 | |
Chris Lattner | ac32329 | 2009-11-27 08:37:22 +0000 | [diff] [blame] | 1281 | // Otherwise, the block was previously analyzed with a different |
| 1282 | // pointer. We can't represent the result of this case, so we just |
| 1283 | // treat this as a phi translation failure. |
Eli Friedman | 4b6eeb9 | 2011-06-01 23:16:53 +0000 | [diff] [blame] | 1284 | |
| 1285 | // Make sure to clean up the Visited map before continuing on to |
| 1286 | // PredTranslationFailure. |
Matt Arsenault | 2080ecd | 2013-03-29 18:48:42 +0000 | [diff] [blame] | 1287 | for (unsigned i = 0, n = PredList.size(); i < n; ++i) |
Eli Friedman | 4b6eeb9 | 2011-06-01 23:16:53 +0000 | [diff] [blame] | 1288 | Visited.erase(PredList[i].first); |
| 1289 | |
Chris Lattner | ac32329 | 2009-11-27 08:37:22 +0000 | [diff] [blame] | 1290 | goto PredTranslationFailure; |
Chris Lattner | ff9f3db | 2008-12-15 03:35:32 +0000 | [diff] [blame] | 1291 | } |
Eli Friedman | 4b6eeb9 | 2011-06-01 23:16:53 +0000 | [diff] [blame] | 1292 | } |
| 1293 | |
| 1294 | // Actually process results here; this need to be a separate loop to avoid |
| 1295 | // calling getNonLocalPointerDepFromBB for blocks we don't want to return |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 1296 | // any results for. (getNonLocalPointerDepFromBB will modify our |
Eli Friedman | 4b6eeb9 | 2011-06-01 23:16:53 +0000 | [diff] [blame] | 1297 | // datastructures in ways the code after the PredTranslationFailure label |
| 1298 | // doesn't expect.) |
Matt Arsenault | 2080ecd | 2013-03-29 18:48:42 +0000 | [diff] [blame] | 1299 | for (unsigned i = 0, n = PredList.size(); i < n; ++i) { |
Eli Friedman | 4b6eeb9 | 2011-06-01 23:16:53 +0000 | [diff] [blame] | 1300 | BasicBlock *Pred = PredList[i].first; |
| 1301 | PHITransAddr &PredPointer = PredList[i].second; |
| 1302 | Value *PredPtrVal = PredPointer.getAddr(); |
| 1303 | |
| 1304 | bool CanTranslate = true; |
Chris Lattner | 2be52e7 | 2009-11-27 22:05:15 +0000 | [diff] [blame] | 1305 | // If PHI translation was unable to find an available pointer in this |
| 1306 | // predecessor, then we have to assume that the pointer is clobbered in |
| 1307 | // that predecessor. We can still do PRE of the load, which would insert |
| 1308 | // a computation of the pointer in this predecessor. |
Craig Topper | 9f00886 | 2014-04-15 04:59:12 +0000 | [diff] [blame] | 1309 | if (!PredPtrVal) |
Eli Friedman | 4b6eeb9 | 2011-06-01 23:16:53 +0000 | [diff] [blame] | 1310 | CanTranslate = false; |
| 1311 | |
| 1312 | // FIXME: it is entirely possible that PHI translating will end up with |
| 1313 | // the same value. Consider PHI translating something like: |
| 1314 | // X = phi [x, bb1], [y, bb2]. PHI translating for bb1 doesn't *need* |
| 1315 | // to recurse here, pedantically speaking. |
| 1316 | |
| 1317 | // If getNonLocalPointerDepFromBB fails here, that means the cached |
| 1318 | // result conflicted with the Visited list; we have to conservatively |
Eli Friedman | 7d58bc7 | 2011-06-15 00:47:34 +0000 | [diff] [blame] | 1319 | // assume it is unknown, but this also does not block PRE of the load. |
Eli Friedman | 4b6eeb9 | 2011-06-01 23:16:53 +0000 | [diff] [blame] | 1320 | if (!CanTranslate || |
Chandler Carruth | b32febe | 2016-03-07 12:45:07 +0000 | [diff] [blame] | 1321 | !getNonLocalPointerDepFromBB(QueryInst, PredPointer, |
Chandler Carruth | 60fb1b4 | 2016-03-07 10:19:30 +0000 | [diff] [blame] | 1322 | Loc.getWithNewPtr(PredPtrVal), isLoad, |
| 1323 | Pred, Result, Visited)) { |
Chris Lattner | 9c2053b | 2009-12-01 07:33:32 +0000 | [diff] [blame] | 1324 | // Add the entry to the Result list. |
Eli Friedman | 7d58bc7 | 2011-06-15 00:47:34 +0000 | [diff] [blame] | 1325 | NonLocalDepResult Entry(Pred, MemDepResult::getUnknown(), PredPtrVal); |
Chris Lattner | 9c2053b | 2009-12-01 07:33:32 +0000 | [diff] [blame] | 1326 | Result.push_back(Entry); |
| 1327 | |
Chris Lattner | 25bf6f8 | 2009-12-19 21:29:22 +0000 | [diff] [blame] | 1328 | // Since we had a phi translation failure, the cache for CacheKey won't |
| 1329 | // include all of the entries that we need to immediately satisfy future |
| 1330 | // queries. Mark this in NonLocalPointerDeps by setting the |
| 1331 | // BBSkipFirstBlockPair pointer to null. This requires reuse of the |
| 1332 | // cached value to do more work but not miss the phi trans failure. |
Dan Gohman | 2348393 | 2010-09-22 21:41:02 +0000 | [diff] [blame] | 1333 | NonLocalPointerInfo &NLPI = NonLocalPointerDeps[CacheKey]; |
| 1334 | NLPI.Pair = BBSkipFirstBlockPair(); |
Chris Lattner | 2be52e7 | 2009-11-27 22:05:15 +0000 | [diff] [blame] | 1335 | continue; |
Chris Lattner | 2be52e7 | 2009-11-27 22:05:15 +0000 | [diff] [blame] | 1336 | } |
Chris Lattner | ff9f3db | 2008-12-15 03:35:32 +0000 | [diff] [blame] | 1337 | } |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 1338 | |
Chris Lattner | ac32329 | 2009-11-27 08:37:22 +0000 | [diff] [blame] | 1339 | // Refresh the CacheInfo/Cache pointer so that it isn't invalidated. |
| 1340 | CacheInfo = &NonLocalPointerDeps[CacheKey]; |
Dan Gohman | 2348393 | 2010-09-22 21:41:02 +0000 | [diff] [blame] | 1341 | Cache = &CacheInfo->NonLocalDeps; |
Chris Lattner | ac32329 | 2009-11-27 08:37:22 +0000 | [diff] [blame] | 1342 | NumSortedEntries = Cache->size(); |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 1343 | |
Chris Lattner | ac32329 | 2009-11-27 08:37:22 +0000 | [diff] [blame] | 1344 | // Since we did phi translation, the "Cache" set won't contain all of the |
| 1345 | // results for the query. This is ok (we can still use it to accelerate |
| 1346 | // specific block queries) but we can't do the fastpath "return all |
| 1347 | // results from the set" Clear out the indicator for this. |
Dan Gohman | 2348393 | 2010-09-22 21:41:02 +0000 | [diff] [blame] | 1348 | CacheInfo->Pair = BBSkipFirstBlockPair(); |
Chris Lattner | ac32329 | 2009-11-27 08:37:22 +0000 | [diff] [blame] | 1349 | SkipFirstBlock = false; |
| 1350 | continue; |
Chris Lattner | c49f5ac | 2009-11-26 23:18:49 +0000 | [diff] [blame] | 1351 | |
Chris Lattner | ff9f3db | 2008-12-15 03:35:32 +0000 | [diff] [blame] | 1352 | PredTranslationFailure: |
Eli Friedman | 4b6eeb9 | 2011-06-01 23:16:53 +0000 | [diff] [blame] | 1353 | // The following code is "failure"; we can't produce a sane translation |
| 1354 | // for the given block. It assumes that we haven't modified any of |
| 1355 | // our datastructures while processing the current block. |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 1356 | |
Craig Topper | 9f00886 | 2014-04-15 04:59:12 +0000 | [diff] [blame] | 1357 | if (!Cache) { |
Chris Lattner | 3f4591c | 2009-01-23 07:12:16 +0000 | [diff] [blame] | 1358 | // Refresh the CacheInfo/Cache pointer if it got invalidated. |
| 1359 | CacheInfo = &NonLocalPointerDeps[CacheKey]; |
Dan Gohman | 2348393 | 2010-09-22 21:41:02 +0000 | [diff] [blame] | 1360 | Cache = &CacheInfo->NonLocalDeps; |
Chris Lattner | 3f4591c | 2009-01-23 07:12:16 +0000 | [diff] [blame] | 1361 | NumSortedEntries = Cache->size(); |
Chris Lattner | 3f4591c | 2009-01-23 07:12:16 +0000 | [diff] [blame] | 1362 | } |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 1363 | |
Chris Lattner | 25bf6f8 | 2009-12-19 21:29:22 +0000 | [diff] [blame] | 1364 | // Since we failed phi translation, the "Cache" set won't contain all of the |
Chris Lattner | ff9f3db | 2008-12-15 03:35:32 +0000 | [diff] [blame] | 1365 | // results for the query. This is ok (we can still use it to accelerate |
| 1366 | // specific block queries) but we can't do the fastpath "return all |
Chris Lattner | 25bf6f8 | 2009-12-19 21:29:22 +0000 | [diff] [blame] | 1367 | // results from the set". Clear out the indicator for this. |
Dan Gohman | 2348393 | 2010-09-22 21:41:02 +0000 | [diff] [blame] | 1368 | CacheInfo->Pair = BBSkipFirstBlockPair(); |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 1369 | |
Eli Friedman | 7d58bc7 | 2011-06-15 00:47:34 +0000 | [diff] [blame] | 1370 | // If *nothing* works, mark the pointer as unknown. |
Chris Lattner | ff9f3db | 2008-12-15 03:35:32 +0000 | [diff] [blame] | 1371 | // |
| 1372 | // If this is the magic first block, return this as a clobber of the whole |
| 1373 | // incoming value. Since we can't phi translate to one of the predecessors, |
| 1374 | // we have to bail out. |
| 1375 | if (SkipFirstBlock) |
Chandler Carruth | b32febe | 2016-03-07 12:45:07 +0000 | [diff] [blame] | 1376 | return false; |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 1377 | |
Joerg Sonnenberger | 36894dc | 2016-02-20 11:24:44 +0000 | [diff] [blame] | 1378 | bool foundBlock = false; |
Chandler Carruth | 60fb1b4 | 2016-03-07 10:19:30 +0000 | [diff] [blame] | 1379 | for (NonLocalDepEntry &I : llvm::reverse(*Cache)) { |
Joerg Sonnenberger | 36894dc | 2016-02-20 11:24:44 +0000 | [diff] [blame] | 1380 | if (I.getBB() != BB) |
Chris Lattner | ff9f3db | 2008-12-15 03:35:32 +0000 | [diff] [blame] | 1381 | continue; |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 1382 | |
Chandler Carruth | 60fb1b4 | 2016-03-07 10:19:30 +0000 | [diff] [blame] | 1383 | assert((GotWorklistLimit || I.getResult().isNonLocal() || |
Chandler Carruth | aef32bd | 2016-03-11 13:46:00 +0000 | [diff] [blame] | 1384 | !DT.isReachableFromEntry(BB)) && |
Chris Lattner | ff9f3db | 2008-12-15 03:35:32 +0000 | [diff] [blame] | 1385 | "Should only be here with transparent block"); |
Joerg Sonnenberger | 36894dc | 2016-02-20 11:24:44 +0000 | [diff] [blame] | 1386 | foundBlock = true; |
| 1387 | I.setResult(MemDepResult::getUnknown()); |
Chandler Carruth | 60fb1b4 | 2016-03-07 10:19:30 +0000 | [diff] [blame] | 1388 | Result.push_back( |
| 1389 | NonLocalDepResult(I.getBB(), I.getResult(), Pointer.getAddr())); |
Chris Lattner | ff9f3db | 2008-12-15 03:35:32 +0000 | [diff] [blame] | 1390 | break; |
Chris Lattner | 7564a3b | 2008-12-07 02:56:57 +0000 | [diff] [blame] | 1391 | } |
Mehdi Amini | 89038a1 | 2016-04-02 05:34:19 +0000 | [diff] [blame] | 1392 | (void)foundBlock; (void)GotWorklistLimit; |
Joerg Sonnenberger | 36894dc | 2016-02-20 11:24:44 +0000 | [diff] [blame] | 1393 | assert((foundBlock || GotWorklistLimit) && "Current block not in cache?"); |
Chris Lattner | 2faa2c7 | 2008-12-07 02:15:47 +0000 | [diff] [blame] | 1394 | } |
Chris Lattner | 3f4591c | 2009-01-23 07:12:16 +0000 | [diff] [blame] | 1395 | |
Chris Lattner | f903fe1 | 2008-12-09 07:47:11 +0000 | [diff] [blame] | 1396 | // Okay, we're done now. If we added new values to the cache, re-sort it. |
Chris Lattner | 370aada | 2009-07-13 17:20:05 +0000 | [diff] [blame] | 1397 | SortNonLocalDepInfoCache(*Cache, NumSortedEntries); |
Chris Lattner | f09619d | 2009-01-22 07:04:01 +0000 | [diff] [blame] | 1398 | DEBUG(AssertSorted(*Cache)); |
Chandler Carruth | b32febe | 2016-03-07 12:45:07 +0000 | [diff] [blame] | 1399 | return true; |
Chris Lattner | a28355d | 2008-12-07 08:50:20 +0000 | [diff] [blame] | 1400 | } |
| 1401 | |
Chandler Carruth | 40e21f2 | 2016-03-07 12:30:06 +0000 | [diff] [blame] | 1402 | /// If P exists in CachedNonLocalPointerInfo, remove it. |
Chandler Carruth | 61440d2 | 2016-03-10 00:55:30 +0000 | [diff] [blame] | 1403 | void MemoryDependenceResults::RemoveCachedNonLocalPointerDependencies( |
Chandler Carruth | 60fb1b4 | 2016-03-07 10:19:30 +0000 | [diff] [blame] | 1404 | ValueIsLoadPair P) { |
| 1405 | CachedNonLocalPointerInfo::iterator It = NonLocalPointerDeps.find(P); |
| 1406 | if (It == NonLocalPointerDeps.end()) |
| 1407 | return; |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 1408 | |
Chris Lattner | a28355d | 2008-12-07 08:50:20 +0000 | [diff] [blame] | 1409 | // Remove all of the entries in the BB->val map. This involves removing |
| 1410 | // instructions from the reverse map. |
Dan Gohman | 2348393 | 2010-09-22 21:41:02 +0000 | [diff] [blame] | 1411 | NonLocalDepInfo &PInfo = It->second.NonLocalDeps; |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 1412 | |
Chris Lattner | a28355d | 2008-12-07 08:50:20 +0000 | [diff] [blame] | 1413 | for (unsigned i = 0, e = PInfo.size(); i != e; ++i) { |
Chris Lattner | 0c31547 | 2009-12-09 07:08:01 +0000 | [diff] [blame] | 1414 | Instruction *Target = PInfo[i].getResult().getInst(); |
Chandler Carruth | 60fb1b4 | 2016-03-07 10:19:30 +0000 | [diff] [blame] | 1415 | if (!Target) |
| 1416 | continue; // Ignore non-local dep results. |
Chris Lattner | 0c31547 | 2009-12-09 07:08:01 +0000 | [diff] [blame] | 1417 | assert(Target->getParent() == PInfo[i].getBB()); |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 1418 | |
Chris Lattner | a28355d | 2008-12-07 08:50:20 +0000 | [diff] [blame] | 1419 | // Eliminating the dirty entry from 'Cache', so update the reverse info. |
Chris Lattner | 8eda11b | 2009-03-29 00:24:04 +0000 | [diff] [blame] | 1420 | RemoveFromReverseMap(ReverseNonLocalPtrDeps, Target, P); |
Chris Lattner | a28355d | 2008-12-07 08:50:20 +0000 | [diff] [blame] | 1421 | } |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 1422 | |
Chris Lattner | a28355d | 2008-12-07 08:50:20 +0000 | [diff] [blame] | 1423 | // Remove P from NonLocalPointerDeps (which deletes NonLocalDepInfo). |
| 1424 | NonLocalPointerDeps.erase(It); |
Chris Lattner | 2faa2c7 | 2008-12-07 02:15:47 +0000 | [diff] [blame] | 1425 | } |
| 1426 | |
Chandler Carruth | 61440d2 | 2016-03-10 00:55:30 +0000 | [diff] [blame] | 1427 | void MemoryDependenceResults::invalidateCachedPointerInfo(Value *Ptr) { |
Chris Lattner | fa9f99a | 2008-12-09 22:06:23 +0000 | [diff] [blame] | 1428 | // If Ptr isn't really a pointer, just ignore it. |
Chandler Carruth | 60fb1b4 | 2016-03-07 10:19:30 +0000 | [diff] [blame] | 1429 | if (!Ptr->getType()->isPointerTy()) |
| 1430 | return; |
Chris Lattner | fa9f99a | 2008-12-09 22:06:23 +0000 | [diff] [blame] | 1431 | // Flush store info for the pointer. |
| 1432 | RemoveCachedNonLocalPointerDependencies(ValueIsLoadPair(Ptr, false)); |
| 1433 | // Flush load info for the pointer. |
| 1434 | RemoveCachedNonLocalPointerDependencies(ValueIsLoadPair(Ptr, true)); |
| 1435 | } |
| 1436 | |
Chandler Carruth | 61440d2 | 2016-03-10 00:55:30 +0000 | [diff] [blame] | 1437 | void MemoryDependenceResults::invalidateCachedPredecessors() { |
Daniel Berlin | b4e7a4a | 2015-04-21 21:11:50 +0000 | [diff] [blame] | 1438 | PredCache.clear(); |
Bob Wilson | 92cdb6e | 2010-02-16 19:51:59 +0000 | [diff] [blame] | 1439 | } |
| 1440 | |
Chandler Carruth | 61440d2 | 2016-03-10 00:55:30 +0000 | [diff] [blame] | 1441 | void MemoryDependenceResults::removeInstruction(Instruction *RemInst) { |
Chris Lattner | a25d3952 | 2008-11-28 22:04:47 +0000 | [diff] [blame] | 1442 | // Walk through the Non-local dependencies, removing this one as the value |
| 1443 | // for any cached queries. |
Chris Lattner | 1b810bd | 2008-11-30 02:28:25 +0000 | [diff] [blame] | 1444 | NonLocalDepMapType::iterator NLDI = NonLocalDeps.find(RemInst); |
| 1445 | if (NLDI != NonLocalDeps.end()) { |
Chris Lattner | 7e61daf | 2008-12-01 01:15:42 +0000 | [diff] [blame] | 1446 | NonLocalDepInfo &BlockMap = NLDI->second.first; |
Chandler Carruth | af8321e | 2016-03-07 15:12:57 +0000 | [diff] [blame] | 1447 | for (auto &Entry : BlockMap) |
| 1448 | if (Instruction *Inst = Entry.getResult().getInst()) |
Chris Lattner | de4440c | 2008-12-07 18:39:13 +0000 | [diff] [blame] | 1449 | RemoveFromReverseMap(ReverseNonLocalDeps, Inst, RemInst); |
Chris Lattner | 1b810bd | 2008-11-30 02:28:25 +0000 | [diff] [blame] | 1450 | NonLocalDeps.erase(NLDI); |
| 1451 | } |
Owen Anderson | 086b2c4 | 2007-12-08 01:37:09 +0000 | [diff] [blame] | 1452 | |
Chris Lattner | a25d3952 | 2008-11-28 22:04:47 +0000 | [diff] [blame] | 1453 | // If we have a cached local dependence query for this instruction, remove it. |
Chris Lattner | 73c2545 | 2008-11-28 22:28:27 +0000 | [diff] [blame] | 1454 | // |
Chris Lattner | de04e11 | 2008-11-29 01:43:36 +0000 | [diff] [blame] | 1455 | LocalDepMapType::iterator LocalDepEntry = LocalDeps.find(RemInst); |
| 1456 | if (LocalDepEntry != LocalDeps.end()) { |
Chris Lattner | ada1f87 | 2008-11-30 01:09:30 +0000 | [diff] [blame] | 1457 | // Remove us from DepInst's reverse set now that the local dep info is gone. |
Chris Lattner | de4440c | 2008-12-07 18:39:13 +0000 | [diff] [blame] | 1458 | if (Instruction *Inst = LocalDepEntry->second.getInst()) |
| 1459 | RemoveFromReverseMap(ReverseLocalDeps, Inst, RemInst); |
Chris Lattner | ada1f87 | 2008-11-30 01:09:30 +0000 | [diff] [blame] | 1460 | |
Chris Lattner | 73c2545 | 2008-11-28 22:28:27 +0000 | [diff] [blame] | 1461 | // Remove this local dependency info. |
Chris Lattner | de04e11 | 2008-11-29 01:43:36 +0000 | [diff] [blame] | 1462 | LocalDeps.erase(LocalDepEntry); |
Chris Lattner | a28355d | 2008-12-07 08:50:20 +0000 | [diff] [blame] | 1463 | } |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 1464 | |
Chris Lattner | a28355d | 2008-12-07 08:50:20 +0000 | [diff] [blame] | 1465 | // If we have any cached pointer dependencies on this instruction, remove |
| 1466 | // them. If the instruction has non-pointer type, then it can't be a pointer |
| 1467 | // base. |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 1468 | |
Chris Lattner | a28355d | 2008-12-07 08:50:20 +0000 | [diff] [blame] | 1469 | // Remove it from both the load info and the store info. The instruction |
| 1470 | // can't be in either of these maps if it is non-pointer. |
Duncan Sands | 19d0b47 | 2010-02-16 11:11:14 +0000 | [diff] [blame] | 1471 | if (RemInst->getType()->isPointerTy()) { |
Chris Lattner | a28355d | 2008-12-07 08:50:20 +0000 | [diff] [blame] | 1472 | RemoveCachedNonLocalPointerDependencies(ValueIsLoadPair(RemInst, false)); |
| 1473 | RemoveCachedNonLocalPointerDependencies(ValueIsLoadPair(RemInst, true)); |
| 1474 | } |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 1475 | |
Chris Lattner | d3d9111 | 2008-11-28 22:51:08 +0000 | [diff] [blame] | 1476 | // Loop over all of the things that depend on the instruction we're removing. |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 1477 | // |
Chandler Carruth | 60fb1b4 | 2016-03-07 10:19:30 +0000 | [diff] [blame] | 1478 | SmallVector<std::pair<Instruction *, Instruction *>, 8> ReverseDepsToAdd; |
Chris Lattner | 82b7034 | 2008-12-07 18:42:51 +0000 | [diff] [blame] | 1479 | |
| 1480 | // If we find RemInst as a clobber or Def in any of the maps for other values, |
| 1481 | // we need to replace its entry with a dirty version of the instruction after |
| 1482 | // it. If RemInst is a terminator, we use a null dirty value. |
| 1483 | // |
| 1484 | // Using a dirty version of the instruction after RemInst saves having to scan |
| 1485 | // the entire block to get to this point. |
| 1486 | MemDepResult NewDirtyVal; |
| 1487 | if (!RemInst->isTerminator()) |
Duncan P. N. Exon Smith | 5a82c91 | 2015-10-10 00:53:03 +0000 | [diff] [blame] | 1488 | NewDirtyVal = MemDepResult::getDirty(&*++RemInst->getIterator()); |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 1489 | |
Chris Lattner | 9f1988ab | 2008-11-29 09:20:15 +0000 | [diff] [blame] | 1490 | ReverseDepMapType::iterator ReverseDepIt = ReverseLocalDeps.find(RemInst); |
| 1491 | if (ReverseDepIt != ReverseLocalDeps.end()) { |
Chris Lattner | a28355d | 2008-12-07 08:50:20 +0000 | [diff] [blame] | 1492 | // RemInst can't be the terminator if it has local stuff depending on it. |
Craig Topper | 4627679 | 2014-08-24 23:23:06 +0000 | [diff] [blame] | 1493 | assert(!ReverseDepIt->second.empty() && !isa<TerminatorInst>(RemInst) && |
Chris Lattner | ada1f87 | 2008-11-30 01:09:30 +0000 | [diff] [blame] | 1494 | "Nothing can locally depend on a terminator"); |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 1495 | |
Craig Topper | 4627679 | 2014-08-24 23:23:06 +0000 | [diff] [blame] | 1496 | for (Instruction *InstDependingOnRemInst : ReverseDepIt->second) { |
Chris Lattner | 1b810bd | 2008-11-30 02:28:25 +0000 | [diff] [blame] | 1497 | assert(InstDependingOnRemInst != RemInst && |
| 1498 | "Already removed our local dep info"); |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 1499 | |
Chris Lattner | 82b7034 | 2008-12-07 18:42:51 +0000 | [diff] [blame] | 1500 | LocalDeps[InstDependingOnRemInst] = NewDirtyVal; |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 1501 | |
Chris Lattner | ada1f87 | 2008-11-30 01:09:30 +0000 | [diff] [blame] | 1502 | // Make sure to remember that new things depend on NewDepInst. |
Chandler Carruth | 60fb1b4 | 2016-03-07 10:19:30 +0000 | [diff] [blame] | 1503 | assert(NewDirtyVal.getInst() && |
| 1504 | "There is no way something else can have " |
Chris Lattner | 82b7034 | 2008-12-07 18:42:51 +0000 | [diff] [blame] | 1505 | "a local dep on this if it is a terminator!"); |
Chandler Carruth | 60fb1b4 | 2016-03-07 10:19:30 +0000 | [diff] [blame] | 1506 | ReverseDepsToAdd.push_back( |
| 1507 | std::make_pair(NewDirtyVal.getInst(), InstDependingOnRemInst)); |
Chris Lattner | d3d9111 | 2008-11-28 22:51:08 +0000 | [diff] [blame] | 1508 | } |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 1509 | |
Chris Lattner | 63bd586 | 2008-11-29 23:30:39 +0000 | [diff] [blame] | 1510 | ReverseLocalDeps.erase(ReverseDepIt); |
| 1511 | |
| 1512 | // Add new reverse deps after scanning the set, to avoid invalidating the |
| 1513 | // 'ReverseDeps' reference. |
| 1514 | while (!ReverseDepsToAdd.empty()) { |
Chandler Carruth | 60fb1b4 | 2016-03-07 10:19:30 +0000 | [diff] [blame] | 1515 | ReverseLocalDeps[ReverseDepsToAdd.back().first].insert( |
| 1516 | ReverseDepsToAdd.back().second); |
Chris Lattner | 63bd586 | 2008-11-29 23:30:39 +0000 | [diff] [blame] | 1517 | ReverseDepsToAdd.pop_back(); |
| 1518 | } |
Owen Anderson | c0daf5f | 2007-07-06 23:14:35 +0000 | [diff] [blame] | 1519 | } |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 1520 | |
Chris Lattner | 9f1988ab | 2008-11-29 09:20:15 +0000 | [diff] [blame] | 1521 | ReverseDepIt = ReverseNonLocalDeps.find(RemInst); |
| 1522 | if (ReverseDepIt != ReverseNonLocalDeps.end()) { |
Craig Topper | 4627679 | 2014-08-24 23:23:06 +0000 | [diff] [blame] | 1523 | for (Instruction *I : ReverseDepIt->second) { |
| 1524 | assert(I != RemInst && "Already removed NonLocalDep info for RemInst"); |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 1525 | |
Craig Topper | 4627679 | 2014-08-24 23:23:06 +0000 | [diff] [blame] | 1526 | PerInstNLInfo &INLD = NonLocalDeps[I]; |
Chris Lattner | 4410427 | 2008-11-30 02:52:26 +0000 | [diff] [blame] | 1527 | // The information is now dirty! |
Chris Lattner | 7e61daf | 2008-12-01 01:15:42 +0000 | [diff] [blame] | 1528 | INLD.second = true; |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 1529 | |
Chandler Carruth | af8321e | 2016-03-07 15:12:57 +0000 | [diff] [blame] | 1530 | for (auto &Entry : INLD.first) { |
| 1531 | if (Entry.getResult().getInst() != RemInst) |
Chandler Carruth | 60fb1b4 | 2016-03-07 10:19:30 +0000 | [diff] [blame] | 1532 | continue; |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 1533 | |
Chris Lattner | 1b810bd | 2008-11-30 02:28:25 +0000 | [diff] [blame] | 1534 | // Convert to a dirty entry for the subsequent instruction. |
Chandler Carruth | af8321e | 2016-03-07 15:12:57 +0000 | [diff] [blame] | 1535 | Entry.setResult(NewDirtyVal); |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 1536 | |
Chris Lattner | 82b7034 | 2008-12-07 18:42:51 +0000 | [diff] [blame] | 1537 | if (Instruction *NextI = NewDirtyVal.getInst()) |
Craig Topper | 4627679 | 2014-08-24 23:23:06 +0000 | [diff] [blame] | 1538 | ReverseDepsToAdd.push_back(std::make_pair(NextI, I)); |
Chris Lattner | 1b810bd | 2008-11-30 02:28:25 +0000 | [diff] [blame] | 1539 | } |
| 1540 | } |
Chris Lattner | 63bd586 | 2008-11-29 23:30:39 +0000 | [diff] [blame] | 1541 | |
| 1542 | ReverseNonLocalDeps.erase(ReverseDepIt); |
| 1543 | |
Chris Lattner | e7d7e13 | 2008-11-29 22:02:15 +0000 | [diff] [blame] | 1544 | // Add new reverse deps after scanning the set, to avoid invalidating 'Set' |
| 1545 | while (!ReverseDepsToAdd.empty()) { |
Chandler Carruth | 60fb1b4 | 2016-03-07 10:19:30 +0000 | [diff] [blame] | 1546 | ReverseNonLocalDeps[ReverseDepsToAdd.back().first].insert( |
| 1547 | ReverseDepsToAdd.back().second); |
Chris Lattner | e7d7e13 | 2008-11-29 22:02:15 +0000 | [diff] [blame] | 1548 | ReverseDepsToAdd.pop_back(); |
| 1549 | } |
Owen Anderson | 5f208be | 2007-08-16 21:27:05 +0000 | [diff] [blame] | 1550 | } |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 1551 | |
Chris Lattner | a28355d | 2008-12-07 08:50:20 +0000 | [diff] [blame] | 1552 | // If the instruction is in ReverseNonLocalPtrDeps then it appears as a |
| 1553 | // value in the NonLocalPointerDeps info. |
| 1554 | ReverseNonLocalPtrDepTy::iterator ReversePtrDepIt = |
Chandler Carruth | 60fb1b4 | 2016-03-07 10:19:30 +0000 | [diff] [blame] | 1555 | ReverseNonLocalPtrDeps.find(RemInst); |
Chris Lattner | a28355d | 2008-12-07 08:50:20 +0000 | [diff] [blame] | 1556 | if (ReversePtrDepIt != ReverseNonLocalPtrDeps.end()) { |
Chandler Carruth | 60fb1b4 | 2016-03-07 10:19:30 +0000 | [diff] [blame] | 1557 | SmallVector<std::pair<Instruction *, ValueIsLoadPair>, 8> |
| 1558 | ReversePtrDepsToAdd; |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 1559 | |
Craig Topper | 4627679 | 2014-08-24 23:23:06 +0000 | [diff] [blame] | 1560 | for (ValueIsLoadPair P : ReversePtrDepIt->second) { |
Chris Lattner | a28355d | 2008-12-07 08:50:20 +0000 | [diff] [blame] | 1561 | assert(P.getPointer() != RemInst && |
| 1562 | "Already removed NonLocalPointerDeps info for RemInst"); |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 1563 | |
Dan Gohman | 2348393 | 2010-09-22 21:41:02 +0000 | [diff] [blame] | 1564 | NonLocalDepInfo &NLPDI = NonLocalPointerDeps[P].NonLocalDeps; |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 1565 | |
Chris Lattner | 5ed409e | 2008-12-08 07:31:50 +0000 | [diff] [blame] | 1566 | // The cache is not valid for any specific block anymore. |
Dan Gohman | 2348393 | 2010-09-22 21:41:02 +0000 | [diff] [blame] | 1567 | NonLocalPointerDeps[P].Pair = BBSkipFirstBlockPair(); |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 1568 | |
Chris Lattner | a28355d | 2008-12-07 08:50:20 +0000 | [diff] [blame] | 1569 | // Update any entries for RemInst to use the instruction after it. |
Chandler Carruth | af8321e | 2016-03-07 15:12:57 +0000 | [diff] [blame] | 1570 | for (auto &Entry : NLPDI) { |
| 1571 | if (Entry.getResult().getInst() != RemInst) |
Chandler Carruth | 60fb1b4 | 2016-03-07 10:19:30 +0000 | [diff] [blame] | 1572 | continue; |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 1573 | |
Chris Lattner | a28355d | 2008-12-07 08:50:20 +0000 | [diff] [blame] | 1574 | // Convert to a dirty entry for the subsequent instruction. |
Chandler Carruth | af8321e | 2016-03-07 15:12:57 +0000 | [diff] [blame] | 1575 | Entry.setResult(NewDirtyVal); |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 1576 | |
Chris Lattner | a28355d | 2008-12-07 08:50:20 +0000 | [diff] [blame] | 1577 | if (Instruction *NewDirtyInst = NewDirtyVal.getInst()) |
| 1578 | ReversePtrDepsToAdd.push_back(std::make_pair(NewDirtyInst, P)); |
| 1579 | } |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 1580 | |
Chris Lattner | 3f4591c | 2009-01-23 07:12:16 +0000 | [diff] [blame] | 1581 | // Re-sort the NonLocalDepInfo. Changing the dirty entry to its |
| 1582 | // subsequent value may invalidate the sortedness. |
| 1583 | std::sort(NLPDI.begin(), NLPDI.end()); |
Chris Lattner | a28355d | 2008-12-07 08:50:20 +0000 | [diff] [blame] | 1584 | } |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 1585 | |
Chris Lattner | a28355d | 2008-12-07 08:50:20 +0000 | [diff] [blame] | 1586 | ReverseNonLocalPtrDeps.erase(ReversePtrDepIt); |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 1587 | |
Chris Lattner | a28355d | 2008-12-07 08:50:20 +0000 | [diff] [blame] | 1588 | while (!ReversePtrDepsToAdd.empty()) { |
Chandler Carruth | 60fb1b4 | 2016-03-07 10:19:30 +0000 | [diff] [blame] | 1589 | ReverseNonLocalPtrDeps[ReversePtrDepsToAdd.back().first].insert( |
| 1590 | ReversePtrDepsToAdd.back().second); |
Chris Lattner | a28355d | 2008-12-07 08:50:20 +0000 | [diff] [blame] | 1591 | ReversePtrDepsToAdd.pop_back(); |
| 1592 | } |
| 1593 | } |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 1594 | |
Chris Lattner | 1b810bd | 2008-11-30 02:28:25 +0000 | [diff] [blame] | 1595 | assert(!NonLocalDeps.count(RemInst) && "RemInst got reinserted?"); |
Jakob Stoklund Olesen | 087f207 | 2011-01-11 04:05:39 +0000 | [diff] [blame] | 1596 | DEBUG(verifyRemoved(RemInst)); |
Owen Anderson | c0daf5f | 2007-07-06 23:14:35 +0000 | [diff] [blame] | 1597 | } |
Chandler Carruth | 40e21f2 | 2016-03-07 12:30:06 +0000 | [diff] [blame] | 1598 | |
| 1599 | /// Verify that the specified instruction does not occur in our internal data |
| 1600 | /// structures. |
| 1601 | /// |
| 1602 | /// This function verifies by asserting in debug builds. |
Chandler Carruth | 61440d2 | 2016-03-10 00:55:30 +0000 | [diff] [blame] | 1603 | void MemoryDependenceResults::verifyRemoved(Instruction *D) const { |
Craig Topper | 4627679 | 2014-08-24 23:23:06 +0000 | [diff] [blame] | 1604 | #ifndef NDEBUG |
Chandler Carruth | af8321e | 2016-03-07 15:12:57 +0000 | [diff] [blame] | 1605 | for (const auto &DepKV : LocalDeps) { |
| 1606 | assert(DepKV.first != D && "Inst occurs in data structures"); |
| 1607 | assert(DepKV.second.getInst() != D && "Inst occurs in data structures"); |
Chris Lattner | b8ec75b | 2008-11-29 21:25:10 +0000 | [diff] [blame] | 1608 | } |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 1609 | |
Chandler Carruth | af8321e | 2016-03-07 15:12:57 +0000 | [diff] [blame] | 1610 | for (const auto &DepKV : NonLocalPointerDeps) { |
| 1611 | assert(DepKV.first.getPointer() != D && "Inst occurs in NLPD map key"); |
| 1612 | for (const auto &Entry : DepKV.second.NonLocalDeps) |
| 1613 | assert(Entry.getResult().getInst() != D && "Inst occurs as NLPD value"); |
Chris Lattner | a28355d | 2008-12-07 08:50:20 +0000 | [diff] [blame] | 1614 | } |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 1615 | |
Chandler Carruth | af8321e | 2016-03-07 15:12:57 +0000 | [diff] [blame] | 1616 | for (const auto &DepKV : NonLocalDeps) { |
| 1617 | assert(DepKV.first != D && "Inst occurs in data structures"); |
| 1618 | const PerInstNLInfo &INLD = DepKV.second; |
| 1619 | for (const auto &Entry : INLD.first) |
| 1620 | assert(Entry.getResult().getInst() != D && |
Chandler Carruth | 60fb1b4 | 2016-03-07 10:19:30 +0000 | [diff] [blame] | 1621 | "Inst occurs in data structures"); |
Chris Lattner | b8ec75b | 2008-11-29 21:25:10 +0000 | [diff] [blame] | 1622 | } |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 1623 | |
Chandler Carruth | af8321e | 2016-03-07 15:12:57 +0000 | [diff] [blame] | 1624 | for (const auto &DepKV : ReverseLocalDeps) { |
| 1625 | assert(DepKV.first != D && "Inst occurs in data structures"); |
| 1626 | for (Instruction *Inst : DepKV.second) |
Craig Topper | 4627679 | 2014-08-24 23:23:06 +0000 | [diff] [blame] | 1627 | assert(Inst != D && "Inst occurs in data structures"); |
Chris Lattner | 1b810bd | 2008-11-30 02:28:25 +0000 | [diff] [blame] | 1628 | } |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 1629 | |
Chandler Carruth | af8321e | 2016-03-07 15:12:57 +0000 | [diff] [blame] | 1630 | for (const auto &DepKV : ReverseNonLocalDeps) { |
| 1631 | assert(DepKV.first != D && "Inst occurs in data structures"); |
| 1632 | for (Instruction *Inst : DepKV.second) |
Craig Topper | 4627679 | 2014-08-24 23:23:06 +0000 | [diff] [blame] | 1633 | assert(Inst != D && "Inst occurs in data structures"); |
Chris Lattner | 1b810bd | 2008-11-30 02:28:25 +0000 | [diff] [blame] | 1634 | } |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 1635 | |
Chandler Carruth | af8321e | 2016-03-07 15:12:57 +0000 | [diff] [blame] | 1636 | for (const auto &DepKV : ReverseNonLocalPtrDeps) { |
| 1637 | assert(DepKV.first != D && "Inst occurs in rev NLPD map"); |
Jakub Staszak | b0a7eed | 2013-03-20 21:47:51 +0000 | [diff] [blame] | 1638 | |
Chandler Carruth | af8321e | 2016-03-07 15:12:57 +0000 | [diff] [blame] | 1639 | for (ValueIsLoadPair P : DepKV.second) |
Chandler Carruth | 60fb1b4 | 2016-03-07 10:19:30 +0000 | [diff] [blame] | 1640 | assert(P != ValueIsLoadPair(D, false) && P != ValueIsLoadPair(D, true) && |
Chris Lattner | a28355d | 2008-12-07 08:50:20 +0000 | [diff] [blame] | 1641 | "Inst occurs in ReverseNonLocalPtrDeps map"); |
| 1642 | } |
Craig Topper | 4627679 | 2014-08-24 23:23:06 +0000 | [diff] [blame] | 1643 | #endif |
Chris Lattner | b8ec75b | 2008-11-29 21:25:10 +0000 | [diff] [blame] | 1644 | } |
Chandler Carruth | 61440d2 | 2016-03-10 00:55:30 +0000 | [diff] [blame] | 1645 | |
Chandler Carruth | dab4eae | 2016-11-23 17:53:26 +0000 | [diff] [blame] | 1646 | AnalysisKey MemoryDependenceAnalysis::Key; |
Chandler Carruth | b4faf13 | 2016-03-11 10:22:49 +0000 | [diff] [blame] | 1647 | |
Chandler Carruth | 61440d2 | 2016-03-10 00:55:30 +0000 | [diff] [blame] | 1648 | MemoryDependenceResults |
Sean Silva | 36e0d01 | 2016-08-09 00:28:15 +0000 | [diff] [blame] | 1649 | MemoryDependenceAnalysis::run(Function &F, FunctionAnalysisManager &AM) { |
Chandler Carruth | b47f801 | 2016-03-11 11:05:24 +0000 | [diff] [blame] | 1650 | auto &AA = AM.getResult<AAManager>(F); |
Daniel Jasper | aec2fa3 | 2016-12-19 08:22:17 +0000 | [diff] [blame] | 1651 | auto &AC = AM.getResult<AssumptionAnalysis>(F); |
Chandler Carruth | b47f801 | 2016-03-11 11:05:24 +0000 | [diff] [blame] | 1652 | auto &TLI = AM.getResult<TargetLibraryAnalysis>(F); |
Chandler Carruth | aef32bd | 2016-03-11 13:46:00 +0000 | [diff] [blame] | 1653 | auto &DT = AM.getResult<DominatorTreeAnalysis>(F); |
Daniel Jasper | aec2fa3 | 2016-12-19 08:22:17 +0000 | [diff] [blame] | 1654 | return MemoryDependenceResults(AA, AC, TLI, DT); |
Chandler Carruth | 61440d2 | 2016-03-10 00:55:30 +0000 | [diff] [blame] | 1655 | } |
| 1656 | |
| 1657 | char MemoryDependenceWrapperPass::ID = 0; |
| 1658 | |
| 1659 | INITIALIZE_PASS_BEGIN(MemoryDependenceWrapperPass, "memdep", |
| 1660 | "Memory Dependence Analysis", false, true) |
Daniel Jasper | aec2fa3 | 2016-12-19 08:22:17 +0000 | [diff] [blame] | 1661 | INITIALIZE_PASS_DEPENDENCY(AssumptionCacheTracker) |
Chandler Carruth | 61440d2 | 2016-03-10 00:55:30 +0000 | [diff] [blame] | 1662 | INITIALIZE_PASS_DEPENDENCY(AAResultsWrapperPass) |
Chandler Carruth | aef32bd | 2016-03-11 13:46:00 +0000 | [diff] [blame] | 1663 | INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass) |
Chandler Carruth | 61440d2 | 2016-03-10 00:55:30 +0000 | [diff] [blame] | 1664 | INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass) |
| 1665 | INITIALIZE_PASS_END(MemoryDependenceWrapperPass, "memdep", |
| 1666 | "Memory Dependence Analysis", false, true) |
| 1667 | |
| 1668 | MemoryDependenceWrapperPass::MemoryDependenceWrapperPass() : FunctionPass(ID) { |
| 1669 | initializeMemoryDependenceWrapperPassPass(*PassRegistry::getPassRegistry()); |
| 1670 | } |
Eugene Zelenko | 1804a77 | 2016-08-25 00:45:04 +0000 | [diff] [blame] | 1671 | |
Chandler Carruth | 61440d2 | 2016-03-10 00:55:30 +0000 | [diff] [blame] | 1672 | MemoryDependenceWrapperPass::~MemoryDependenceWrapperPass() {} |
| 1673 | |
| 1674 | void MemoryDependenceWrapperPass::releaseMemory() { |
| 1675 | MemDep.reset(); |
| 1676 | } |
| 1677 | |
| 1678 | void MemoryDependenceWrapperPass::getAnalysisUsage(AnalysisUsage &AU) const { |
| 1679 | AU.setPreservesAll(); |
Daniel Jasper | aec2fa3 | 2016-12-19 08:22:17 +0000 | [diff] [blame] | 1680 | AU.addRequired<AssumptionCacheTracker>(); |
Chandler Carruth | aef32bd | 2016-03-11 13:46:00 +0000 | [diff] [blame] | 1681 | AU.addRequired<DominatorTreeWrapperPass>(); |
Chandler Carruth | 61440d2 | 2016-03-10 00:55:30 +0000 | [diff] [blame] | 1682 | AU.addRequiredTransitive<AAResultsWrapperPass>(); |
| 1683 | AU.addRequiredTransitive<TargetLibraryInfoWrapperPass>(); |
| 1684 | } |
| 1685 | |
Chandler Carruth | e14524c | 2016-12-27 19:33:04 +0000 | [diff] [blame] | 1686 | bool MemoryDependenceResults::invalidate(Function &F, const PreservedAnalyses &PA, |
| 1687 | FunctionAnalysisManager::Invalidator &Inv) { |
| 1688 | // Check whether our analysis is preserved. |
| 1689 | auto PAC = PA.getChecker<MemoryDependenceAnalysis>(); |
| 1690 | if (!PAC.preserved() && !PAC.preservedSet<AllAnalysesOn<Function>>()) |
| 1691 | // If not, give up now. |
| 1692 | return true; |
| 1693 | |
| 1694 | // Check whether the analyses we depend on became invalid for any reason. |
| 1695 | if (Inv.invalidate<AAManager>(F, PA) || |
| 1696 | Inv.invalidate<AssumptionAnalysis>(F, PA) || |
| 1697 | Inv.invalidate<DominatorTreeAnalysis>(F, PA)) |
| 1698 | return true; |
| 1699 | |
| 1700 | // Otherwise this analysis result remains valid. |
| 1701 | return false; |
| 1702 | } |
| 1703 | |
Bob Haarman | 3db1764 | 2016-08-26 16:34:27 +0000 | [diff] [blame] | 1704 | unsigned MemoryDependenceResults::getDefaultBlockScanLimit() const { |
| 1705 | return BlockScanLimit; |
| 1706 | } |
| 1707 | |
Chandler Carruth | 61440d2 | 2016-03-10 00:55:30 +0000 | [diff] [blame] | 1708 | bool MemoryDependenceWrapperPass::runOnFunction(Function &F) { |
| 1709 | auto &AA = getAnalysis<AAResultsWrapperPass>().getAAResults(); |
Daniel Jasper | aec2fa3 | 2016-12-19 08:22:17 +0000 | [diff] [blame] | 1710 | auto &AC = getAnalysis<AssumptionCacheTracker>().getAssumptionCache(F); |
Chandler Carruth | 61440d2 | 2016-03-10 00:55:30 +0000 | [diff] [blame] | 1711 | auto &TLI = getAnalysis<TargetLibraryInfoWrapperPass>().getTLI(); |
Chandler Carruth | aef32bd | 2016-03-11 13:46:00 +0000 | [diff] [blame] | 1712 | auto &DT = getAnalysis<DominatorTreeWrapperPass>().getDomTree(); |
Daniel Jasper | aec2fa3 | 2016-12-19 08:22:17 +0000 | [diff] [blame] | 1713 | MemDep.emplace(AA, AC, TLI, DT); |
Chandler Carruth | 61440d2 | 2016-03-10 00:55:30 +0000 | [diff] [blame] | 1714 | return false; |
| 1715 | } |