[llvm] b7b61fe - [FuncSpec] Create helper to update state. NFC.
Sjoerd Meijer via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 17 04:15:05 PST 2021
Author: Sjoerd Meijer
Date: 2021-12-17T12:14:33Z
New Revision: b7b61fe091a78dff8248ccbdef6800179150620b
URL: https://github.com/llvm/llvm-project/commit/b7b61fe091a78dff8248ccbdef6800179150620b
DIFF: https://github.com/llvm/llvm-project/commit/b7b61fe091a78dff8248ccbdef6800179150620b.diff
LOG: [FuncSpec] Create helper to update state. NFC.
This creates a helper function updateSpecializedFuncs and is a NFC just to make
the function that drives the transformation easier to read.
Added:
Modified:
llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp b/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
index 8b69f02da569a..c745760fa6dbc 100644
--- a/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
+++ b/llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
@@ -111,6 +111,9 @@ struct ArgInfo {
};
} // Anonymous namespace
+using FuncList = SmallVectorImpl<Function *>;
+using ConstList = SmallVectorImpl<Constant *>;
+
// Helper to check if \p LV is either a constant or a constant
// range with a single element. This should cover exactly the same cases as the
// old ValueLatticeElement::isConstant() and is intended to be used in the
@@ -188,7 +191,7 @@ static Constant *getConstantStackValue(CallInst *Call, Value *Val,
// ret void
// }
//
-static void constantArgPropagation(SmallVectorImpl<Function *> &WorkList,
+static void constantArgPropagation(FuncList &WorkList,
Module &M, SCCPSolver &Solver) {
// Iterate over the argument tracked functions see if there
// are any new constant values for the call instruction via
@@ -273,8 +276,8 @@ class FunctionSpecializer {
///
/// \returns true if at least one function is specialized.
bool
- specializeFunctions(SmallVectorImpl<Function *> &FuncDecls,
- SmallVectorImpl<Function *> &CurrentSpecializations) {
+ specializeFunctions(FuncList &FuncDecls,
+ FuncList &CurrentSpecializations) {
bool Changed = false;
for (auto *F : FuncDecls) {
if (!isCandidateFunction(F, CurrentSpecializations))
@@ -299,25 +302,7 @@ class FunctionSpecializer {
}
}
- for (auto *SpecializedFunc : CurrentSpecializations) {
- SpecializedFuncs.insert(SpecializedFunc);
-
- // Initialize the state of the newly created functions, marking them
- // argument-tracked and executable.
- if (SpecializedFunc->hasExactDefinition() &&
- !SpecializedFunc->hasFnAttribute(Attribute::Naked))
- Solver.addTrackedFunction(SpecializedFunc);
- Solver.addArgumentTrackedFunction(SpecializedFunc);
- FuncDecls.push_back(SpecializedFunc);
- Solver.markBlockExecutable(&SpecializedFunc->front());
-
- // Replace the function arguments for the specialized functions.
- for (Argument &Arg : SpecializedFunc->args())
- if (!Arg.use_empty() && tryToReplaceWithConstant(&Arg))
- LLVM_DEBUG(dbgs() << "FnSpecialization: Replaced constant argument: "
- << Arg.getName() << "\n");
- }
-
+ updateSpecializedFuncs(FuncDecls, CurrentSpecializations);
NumFuncSpecialized += NbFunctionsSpecialized;
return Changed;
}
@@ -439,8 +424,7 @@ class FunctionSpecializer {
return Worklist;
}
- bool isCandidateFunction(Function *F,
- SmallVectorImpl<Function *> &Specializations) {
+ bool isCandidateFunction(Function *F, FuncList &Specializations) {
// Do not specialize the cloned function again.
if (SpecializedFuncs.contains(F))
return false;
@@ -464,8 +448,7 @@ class FunctionSpecializer {
return true;
}
- void specializeFunction(ArgInfo &AI,
- SmallVectorImpl<Function *> &Specializations) {
+ void specializeFunction(ArgInfo &AI, FuncList &Specializations) {
Function *Clone = cloneCandidateFunction(AI.Fn);
Argument *ClonedArg = Clone->getArg(AI.Arg->getArgNo());
@@ -626,8 +609,7 @@ class FunctionSpecializer {
///
/// \returns true if the function should be specialized on the given
/// argument.
- bool isArgumentInteresting(Argument *A,
- SmallVectorImpl<Constant *> &Constants,
+ bool isArgumentInteresting(Argument *A, ConstList &Constants,
bool &IsPartial) {
// For now, don't attempt to specialize functions based on the values of
// composite types.
@@ -666,8 +648,7 @@ class FunctionSpecializer {
/// \returns true if all of the values the argument can take on are constant
/// (e.g., the argument's parent function cannot be called with an
/// overdefined value).
- bool getPossibleConstants(Argument *A,
- SmallVectorImpl<Constant *> &Constants) {
+ bool getPossibleConstants(Argument *A, ConstList &Constants) {
Function *F = A->getParent();
bool AllConstant = true;
@@ -750,6 +731,29 @@ class FunctionSpecializer {
}
}
}
+
+ void updateSpecializedFuncs(FuncList &FuncDecls,
+ FuncList &CurrentSpecializations) {
+ for (auto *SpecializedFunc : CurrentSpecializations) {
+ SpecializedFuncs.insert(SpecializedFunc);
+
+ // Initialize the state of the newly created functions, marking them
+ // argument-tracked and executable.
+ if (SpecializedFunc->hasExactDefinition() &&
+ !SpecializedFunc->hasFnAttribute(Attribute::Naked))
+ Solver.addTrackedFunction(SpecializedFunc);
+
+ Solver.addArgumentTrackedFunction(SpecializedFunc);
+ FuncDecls.push_back(SpecializedFunc);
+ Solver.markBlockExecutable(&SpecializedFunc->front());
+
+ // Replace the function arguments for the specialized functions.
+ for (Argument &Arg : SpecializedFunc->args())
+ if (!Arg.use_empty() && tryToReplaceWithConstant(&Arg))
+ LLVM_DEBUG(dbgs() << "FnSpecialization: Replaced constant argument: "
+ << Arg.getName() << "\n");
+ }
+ }
};
} // namespace
More information about the llvm-commits
mailing list