// and thus control compile-times / code-size.
//
// Todos:
-// - Limit the times a recursive function get specialized when
-// `func-specialization-max-iters`
-// increases linearly. See discussion in https://reviews.llvm.org/D106426 for
-// details.
+// - Specializing recursive functions relies on running the transformation a
+// number of times, which is controlled by option
+// `func-specialization-max-iters`. Thus, increasing this value and the
+// number of iterations, will linearly increase the number of times recursive
+// functions get specialized, see also the discussion in
+// https://reviews.llvm.org/D106426 for details. Perhaps there is a
+// compile-time friendlier way to control/limit the number of specialisations
+// for recursive functions.
// - Don't transform the function if there is no function specialization
-// happens.
+// happens.
//
//===----------------------------------------------------------------------===//
SmallVectorImpl<Function *> &Specializations) {
// Do not specialize the cloned function again.
- if (SpecializedFuncs.contains(F)) {
+ if (SpecializedFuncs.contains(F))
return false;
- }
// If we're optimizing the function for size, we shouldn't specialize it.
if (F->hasOptSize() ||
auto *V = CS.getArgOperand(A->getArgNo());
// TrackValueOfGlobalVariable only tracks scalar global variables.
- if (auto *GV = dyn_cast<GlobalVariable>(V)) {
- if (!GV->getValueType()->isSingleValueType()) {
+ if (auto *GV = dyn_cast<GlobalVariable>(V))
+ if (!GV->getValueType()->isSingleValueType())
return false;
- }
- }
if (isa<Constant>(V) && (Solver.getLatticeValueFor(V).isConstant() ||
EnableSpecializationForLiteralConstant))
for (BasicBlock &BB : *F) {
if (!Solver.isBlockExecutable(&BB))
continue;
+ // FIXME: The solver may make changes to the function here, so set
+ // Changed, even if later function specialization does not trigger.
for (auto &I : make_early_inc_range(BB))
- // FIXME: The solver may make changes to the function here, so set Changed, even if later
- // function specialization does not trigger.
Changed |= FS.tryToReplaceWithConstant(&I);
}
}
// Run the solver for the specialized functions.
RunSCCPSolver(CurrentSpecializations);
- // Replace some unresolved constant arguments
+ // Replace some unresolved constant arguments.
constantArgPropagation(FuncDecls, M, Solver);
CurrentSpecializations.clear();