Index: llvm/lib/Transforms/IPO/CMakeLists.txt =================================================================== --- llvm/lib/Transforms/IPO/CMakeLists.txt +++ llvm/lib/Transforms/IPO/CMakeLists.txt @@ -15,6 +15,7 @@ ForceFunctionAttrs.cpp FunctionAttrs.cpp FunctionImport.cpp + FunctionSpecialization.cpp GlobalDCE.cpp GlobalOpt.cpp GlobalSplit.cpp Index: llvm/lib/Transforms/IPO/FunctionSpecialization.cpp =================================================================== --- llvm/lib/Transforms/IPO/FunctionSpecialization.cpp +++ llvm/lib/Transforms/IPO/FunctionSpecialization.cpp @@ -120,6 +120,8 @@ LLVM_DEBUG(dbgs() << "FnSpecialization: Replaced constant argument: " << Arg.getName() << "\n"); } + + NumFuncSpecialized += FunctionsSpecialized; return Changed; } @@ -141,6 +143,8 @@ } private: + int FunctionsSpecialized = 0; + /// This function decides whether to specialize function \p F based on the /// known constant values its arguments can take on. Specialization is /// performed on the first interesting argument. Specializations based on @@ -217,7 +221,7 @@ // Mark all the specialized functions Specializations.push_back(Clone); - NumFuncSpecialized++; + FunctionsSpecialized++; } // TODO: if we want to support specialize specialized functions, and if @@ -247,7 +251,7 @@ // Otherwise, set the specialization cost to be the cost of all the // instructions in the function and penalty for specializing more functions. - unsigned Penalty = (NumFuncSpecialized + 1); + unsigned Penalty = FunctionsSpecialized + 1; return Metrics.NumInsts * InlineConstants::InstrCost * Penalty; } @@ -506,7 +510,6 @@ CallSitesToRewrite.push_back(&CS); } for (auto *CS : CallSitesToRewrite) { - if ((CS->getFunction() == Clone && CS->getArgOperand(ArgNo) == &Arg) || CS->getArgOperand(ArgNo) == C) { CS->setCalledFunction(Clone); @@ -632,6 +635,5 @@ // Clean up the IR by removing ssa_copy intrinsics. cleanup(M); - return Changed; } Index: llvm/lib/Transforms/Scalar/CMakeLists.txt =================================================================== --- llvm/lib/Transforms/Scalar/CMakeLists.txt +++ llvm/lib/Transforms/Scalar/CMakeLists.txt @@ -13,7 +13,6 @@ EarlyCSE.cpp FlattenCFGPass.cpp Float2Int.cpp - FunctionSpecialization.cpp GuardWidening.cpp GVN.cpp GVNHoist.cpp