llvm.org GIT mirror llvm / 73e43cb
Merging r370355: ------------------------------------------------------------------------ r370355 | joerg | 2019-08-29 15:22:30 +0200 (Thu, 29 Aug 2019) | 5 lines Allow replaceAndRecursivelySimplify to list unsimplified visitees. This is part of D65280 and split it to avoid ABI changes on the 9.0 release branch. ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_90@370447 91177308-0d34-0410-b5e6-96231b3b80d8 Hans Wennborg a month ago
2 changed file(s) with 27 addition(s) and 18 deletion(s). Raw diff Collapse all Expand all
3030 #ifndef LLVM_ANALYSIS_INSTRUCTIONSIMPLIFY_H
3131 #define LLVM_ANALYSIS_INSTRUCTIONSIMPLIFY_H
3232
33 #include "llvm/ADT/SetVector.h"
3334 #include "llvm/IR/Instruction.h"
3435 #include "llvm/IR/Operator.h"
3536 #include "llvm/IR/User.h"
262263 /// This first performs a normal RAUW of I with SimpleV. It then recursively
263264 /// attempts to simplify those users updated by the operation. The 'I'
264265 /// instruction must not be equal to the simplified value 'SimpleV'.
266 /// If UnsimplifiedUsers is provided, instructions that could not be simplified
267 /// are added to it.
265268 ///
266269 /// The function returns true if any simplifications were performed.
267 bool replaceAndRecursivelySimplify(Instruction *I, Value *SimpleV,
268 const TargetLibraryInfo *TLI = nullptr,
269 const DominatorTree *DT = nullptr,
270 AssumptionCache *AC = nullptr);
270 bool replaceAndRecursivelySimplify(
271 Instruction *I, Value *SimpleV, const TargetLibraryInfo *TLI = nullptr,
272 const DominatorTree *DT = nullptr, AssumptionCache *AC = nullptr,
273 SmallSetVector *UnsimplifiedUsers = nullptr);
271274
272275 /// Recursively attempt to simplify an instruction.
273276 ///
52205220 /// If we have a pre-simplified value in 'SimpleV', that is forcibly used to
52215221 /// replace the instruction 'I'. Otherwise, we simply add 'I' to the list of
52225222 /// instructions to process and attempt to simplify it using
5223 /// InstructionSimplify.
5223 /// InstructionSimplify. Recursively visited users which could not be
5224 /// simplified themselves are to the optional UnsimplifiedUsers set for
5225 /// further processing by the caller.
52245226 ///
52255227 /// This routine returns 'true' only when *it* simplifies something. The passed
52265228 /// in simplified value does not count toward this.
5227 static bool replaceAndRecursivelySimplifyImpl(Instruction *I, Value *SimpleV,
5228 const TargetLibraryInfo *TLI,
5229 const DominatorTree *DT,
5230 AssumptionCache *AC) {
5229 static bool replaceAndRecursivelySimplifyImpl(
5230 Instruction *I, Value *SimpleV, const TargetLibraryInfo *TLI,
5231 const DominatorTree *DT, AssumptionCache *AC,
5232 SmallSetVector *UnsimplifiedUsers = nullptr) {
52315233 bool Simplified = false;
52325234 SmallSetVector Worklist;
52335235 const DataLayout &DL = I->getModule()->getDataLayout();
52575259
52585260 // See if this instruction simplifies.
52595261 SimpleV = SimplifyInstruction(I, {DL, TLI, DT, AC});
5260 if (!SimpleV)
5262 if (!SimpleV) {
5263 if (UnsimplifiedUsers)
5264 UnsimplifiedUsers->insert(I);
52615265 continue;
5266 }
52625267
52635268 Simplified = true;
52645269
52845289 const TargetLibraryInfo *TLI,
52855290 const DominatorTree *DT,
52865291 AssumptionCache *AC) {
5287 return replaceAndRecursivelySimplifyImpl(I, nullptr, TLI, DT, AC);
5288 }
5289
5290 bool llvm::replaceAndRecursivelySimplify(Instruction *I, Value *SimpleV,
5291 const TargetLibraryInfo *TLI,
5292 const DominatorTree *DT,
5293 AssumptionCache *AC) {
5292 return replaceAndRecursivelySimplifyImpl(I, nullptr, TLI, DT, AC, nullptr);
5293 }
5294
5295 bool llvm::replaceAndRecursivelySimplify(
5296 Instruction *I, Value *SimpleV, const TargetLibraryInfo *TLI,
5297 const DominatorTree *DT, AssumptionCache *AC,
5298 SmallSetVector *UnsimplifiedUsers) {
52945299 assert(I != SimpleV && "replaceAndRecursivelySimplify(X,X) is not valid!");
52955300 assert(SimpleV && "Must provide a simplified value.");
5296 return replaceAndRecursivelySimplifyImpl(I, SimpleV, TLI, DT, AC);
5301 return replaceAndRecursivelySimplifyImpl(I, SimpleV, TLI, DT, AC,
5302 UnsimplifiedUsers);
52975303 }
52985304
52995305 namespace llvm {