mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-02-01 05:01:59 +01:00
[CodeGenPrepare] Cut off FindAllMemoryUses if there are too many uses.
This avoids excessive compile time. The case I'm looking at is Function.cpp from an old version of LLVM that still had the giant memcmp string matcher in it. Before r308322 this compiled in about 2 minutes, after it, clang takes infinite* time to compile it. With this patch we're at 5 min, which is still bad but this is a pathological case. The cut off at 20 uses was chosen by looking at other cut-offs in LLVM for user scanning. It's probably too high, but does the job and is very unlikely to regress anything. Fixes PR33900. * I'm impatient and aborted after 15 minutes, on the bug report it was killed after 2h. llvm-svn: 308891
This commit is contained in:
parent
83cfeeb8dd
commit
1f64ef8e8c
@ -4016,14 +4016,18 @@ static bool IsOperandAMemoryOperand(CallInst *CI, InlineAsm *IA, Value *OpVal,
|
||||
return true;
|
||||
}
|
||||
|
||||
// Max number of memory uses to look at before aborting the search to conserve
|
||||
// compile time.
|
||||
static constexpr int MaxMemoryUsesToScan = 20;
|
||||
|
||||
/// Recursively walk all the uses of I until we find a memory use.
|
||||
/// If we find an obviously non-foldable instruction, return true.
|
||||
/// Add the ultimately found memory instructions to MemoryUses.
|
||||
static bool FindAllMemoryUses(
|
||||
Instruction *I,
|
||||
SmallVectorImpl<std::pair<Instruction *, unsigned>> &MemoryUses,
|
||||
SmallPtrSetImpl<Instruction *> &ConsideredInsts,
|
||||
const TargetLowering &TLI, const TargetRegisterInfo &TRI) {
|
||||
SmallPtrSetImpl<Instruction *> &ConsideredInsts, const TargetLowering &TLI,
|
||||
const TargetRegisterInfo &TRI, int SeenInsts = 0) {
|
||||
// If we already considered this instruction, we're done.
|
||||
if (!ConsideredInsts.insert(I).second)
|
||||
return false;
|
||||
@ -4036,8 +4040,12 @@ static bool FindAllMemoryUses(
|
||||
|
||||
// Loop over all the uses, recursively processing them.
|
||||
for (Use &U : I->uses()) {
|
||||
Instruction *UserI = cast<Instruction>(U.getUser());
|
||||
// Conservatively return true if we're seeing a large number or a deep chain
|
||||
// of users. This avoids excessive compilation times in pathological cases.
|
||||
if (SeenInsts++ >= MaxMemoryUsesToScan)
|
||||
return true;
|
||||
|
||||
Instruction *UserI = cast<Instruction>(U.getUser());
|
||||
if (LoadInst *LI = dyn_cast<LoadInst>(UserI)) {
|
||||
MemoryUses.push_back(std::make_pair(LI, U.getOperandNo()));
|
||||
continue;
|
||||
@ -4082,7 +4090,8 @@ static bool FindAllMemoryUses(
|
||||
continue;
|
||||
}
|
||||
|
||||
if (FindAllMemoryUses(UserI, MemoryUses, ConsideredInsts, TLI, TRI))
|
||||
if (FindAllMemoryUses(UserI, MemoryUses, ConsideredInsts, TLI, TRI,
|
||||
SeenInsts))
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user