Please use GitHub pull requests for new patches. Phabricator shutdown timeline
Changeset View
Changeset View
Standalone View
Standalone View
llvm/lib/Transforms/Scalar/JumpThreading.cpp
Show First 20 Lines • Show All 94 Lines • ▼ Show 20 Lines | |||||
static cl::opt<unsigned> | static cl::opt<unsigned> | ||||
ImplicationSearchThreshold( | ImplicationSearchThreshold( | ||||
"jump-threading-implication-search-threshold", | "jump-threading-implication-search-threshold", | ||||
cl::desc("The number of predecessors to search for a stronger " | cl::desc("The number of predecessors to search for a stronger " | ||||
"condition to use to thread over a weaker condition"), | "condition to use to thread over a weaker condition"), | ||||
cl::init(3), cl::Hidden); | cl::init(3), cl::Hidden); | ||||
static cl::opt<unsigned> PhiDuplicateThreshold( | |||||
"jump-threading-phi-threshold", | |||||
cl::desc("Max PHIs in BB to duplicate for jump threading"), cl::init(76), | |||||
cl::Hidden); | |||||
static cl::opt<bool> PrintLVIAfterJumpThreading( | static cl::opt<bool> PrintLVIAfterJumpThreading( | ||||
"print-lvi-after-jump-threading", | "print-lvi-after-jump-threading", | ||||
cl::desc("Print the LazyValueInfo cache after JumpThreading"), cl::init(false), | cl::desc("Print the LazyValueInfo cache after JumpThreading"), cl::init(false), | ||||
cl::Hidden); | cl::Hidden); | ||||
static cl::opt<bool> ThreadAcrossLoopHeaders( | static cl::opt<bool> ThreadAcrossLoopHeaders( | ||||
"jump-threading-across-loop-headers", | "jump-threading-across-loop-headers", | ||||
cl::desc("Allow JumpThreading to thread across loop headers, for testing"), | cl::desc("Allow JumpThreading to thread across loop headers, for testing"), | ||||
▲ Show 20 Lines • Show All 402 Lines • ▼ Show 20 Lines | |||||
/// Return the cost of duplicating a piece of this block from first non-phi | /// Return the cost of duplicating a piece of this block from first non-phi | ||||
/// and before StopAt instruction to thread across it. Stop scanning the block | /// and before StopAt instruction to thread across it. Stop scanning the block | ||||
/// when exceeding the threshold. If duplication is impossible, returns ~0U. | /// when exceeding the threshold. If duplication is impossible, returns ~0U. | ||||
static unsigned getJumpThreadDuplicationCost(const TargetTransformInfo *TTI, | static unsigned getJumpThreadDuplicationCost(const TargetTransformInfo *TTI, | ||||
BasicBlock *BB, | BasicBlock *BB, | ||||
Instruction *StopAt, | Instruction *StopAt, | ||||
unsigned Threshold) { | unsigned Threshold) { | ||||
assert(StopAt->getParent() == BB && "Not an instruction from proper BB?"); | assert(StopAt->getParent() == BB && "Not an instruction from proper BB?"); | ||||
// Do not duplicate the BB if it has a lot of PHI nodes. | |||||
// If a threadable chain is too long then the number of PHI nodes can add up, | |||||
// leading to a substantial increase in compile time when rewriting the SSA. | |||||
unsigned PhiCount = 0; | |||||
Instruction *FirstNonPHI = nullptr; | |||||
for (Instruction &I : *BB) { | |||||
if (!isa<PHINode>(&I)) { | |||||
FirstNonPHI = &I; | |||||
break; | |||||
} | |||||
if (++PhiCount > PhiDuplicateThreshold) | |||||
return ~0U; | |||||
} | |||||
/// Ignore PHI nodes, these will be flattened when duplication happens. | /// Ignore PHI nodes, these will be flattened when duplication happens. | ||||
BasicBlock::const_iterator I(BB->getFirstNonPHI()); | BasicBlock::const_iterator I(FirstNonPHI); | ||||
efriedma: Since we're iterating over the beginning of the block anyway, can we use the computed non-PHI… | |||||
// FIXME: THREADING will delete values that are just used to compute the | // FIXME: THREADING will delete values that are just used to compute the | ||||
// branch, so they shouldn't count against the duplication cost. | // branch, so they shouldn't count against the duplication cost. | ||||
unsigned Bonus = 0; | unsigned Bonus = 0; | ||||
if (BB->getTerminator() == StopAt) { | if (BB->getTerminator() == StopAt) { | ||||
// Threading through a switch statement is particularly profitable. If this | // Threading through a switch statement is particularly profitable. If this | ||||
// block ends in a switch, decrease its cost to make it more likely to | // block ends in a switch, decrease its cost to make it more likely to | ||||
▲ Show 20 Lines • Show All 2,531 Lines • Show Last 20 Lines |
Since we're iterating over the beginning of the block anyway, can we use the computed non-PHI instruction?