From: Chris Lattner Date: Sun, 16 Jan 2011 00:27:10 +0000 (+0000) Subject: remove the partial specialization pass. It is unmaintained and has bugs. X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=0092b1142f5d35d204f35ec3cfe19d8de082400f;p=oota-llvm.git remove the partial specialization pass. It is unmaintained and has bugs. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123554 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/Analysis/CodeMetrics.h b/include/llvm/Analysis/CodeMetrics.h index aa42de7898b..75edfbbed2e 100644 --- a/include/llvm/Analysis/CodeMetrics.h +++ b/include/llvm/Analysis/CodeMetrics.h @@ -7,9 +7,8 @@ // //===----------------------------------------------------------------------===// // -// This file implements various weight measurements for a function, helping -// the Inliner and PartialSpecialization decide whether to duplicate its -// contents. +// This file implements various weight measurements for code, helping +// the Inliner and other passes decide whether to duplicate its contents. // //===----------------------------------------------------------------------===// diff --git a/include/llvm/InitializePasses.h b/include/llvm/InitializePasses.h index d86b19992ec..6c5fc89e1d4 100644 --- a/include/llvm/InitializePasses.h +++ b/include/llvm/InitializePasses.h @@ -161,7 +161,6 @@ void initializeOptimalEdgeProfilerPass(PassRegistry&); void initializeOptimizePHIsPass(PassRegistry&); void initializePEIPass(PassRegistry&); void initializePHIEliminationPass(PassRegistry&); -void initializePartSpecPass(PassRegistry&); void initializePartialInlinerPass(PassRegistry&); void initializePeepholeOptimizerPass(PassRegistry&); void initializePostDomOnlyPrinterPass(PassRegistry&); diff --git a/include/llvm/LinkAllPasses.h b/include/llvm/LinkAllPasses.h index 7dd8ebd6c97..a6f89c5938d 100644 --- a/include/llvm/LinkAllPasses.h +++ b/include/llvm/LinkAllPasses.h @@ -135,7 +135,6 @@ namespace { (void) llvm::createPostDomTree(); (void) llvm::createPostDomFrontier(); (void) llvm::createInstructionNamerPass(); - (void) llvm::createPartialSpecializationPass(); (void) llvm::createFunctionAttrsPass(); (void) llvm::createMergeFunctionsPass(); (void) llvm::createPrintModulePass(0); diff --git a/include/llvm/Transforms/IPO.h b/include/llvm/Transforms/IPO.h index 40ef9bbbd64..12398813cc7 100644 --- a/include/llvm/Transforms/IPO.h +++ b/include/llvm/Transforms/IPO.h @@ -188,12 +188,6 @@ ModulePass *createBlockExtractorPass(); /// (prototypes) that are not used. ModulePass *createStripDeadPrototypesPass(); -//===----------------------------------------------------------------------===// -/// createPartialSpecializationPass - This pass specializes functions for -/// constant arguments. -/// -ModulePass *createPartialSpecializationPass(); - //===----------------------------------------------------------------------===// /// createFunctionAttrsPass - This pass discovers functions that do not access /// memory, or only read memory, and gives them the readnone/readonly attribute. diff --git a/lib/Transforms/IPO/CMakeLists.txt b/lib/Transforms/IPO/CMakeLists.txt index 92bef3bb75e..efdeec56405 100644 --- a/lib/Transforms/IPO/CMakeLists.txt +++ b/lib/Transforms/IPO/CMakeLists.txt @@ -17,7 +17,6 @@ add_llvm_library(LLVMipo LowerSetJmp.cpp MergeFunctions.cpp PartialInlining.cpp - PartialSpecialization.cpp PruneEH.cpp StripDeadPrototypes.cpp StripSymbols.cpp diff --git a/lib/Transforms/IPO/IPO.cpp b/lib/Transforms/IPO/IPO.cpp index 87932375c0b..fbe90ce6759 100644 --- a/lib/Transforms/IPO/IPO.cpp +++ b/lib/Transforms/IPO/IPO.cpp @@ -39,7 +39,6 @@ void llvm::initializeIPO(PassRegistry &Registry) { initializeLowerSetJmpPass(Registry); initializeMergeFunctionsPass(Registry); initializePartialInlinerPass(Registry); - initializePartSpecPass(Registry); initializePruneEHPass(Registry); initializeStripDeadPrototypesPassPass(Registry); initializeStripSymbolsPass(Registry); diff --git a/lib/Transforms/IPO/PartialSpecialization.cpp b/lib/Transforms/IPO/PartialSpecialization.cpp deleted file mode 100644 index 61c071f5bd3..00000000000 --- a/lib/Transforms/IPO/PartialSpecialization.cpp +++ /dev/null @@ -1,228 +0,0 @@ -//===-- PartialSpecialization.cpp - Specialize for common constants--------===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// This pass finds function arguments that are often a common constant and -// specializes a version of the called function for that constant. -// -// This pass simply does the cloning for functions it specializes. It depends -// on IPSCCP and DAE to clean up the results. -// -// The initial heuristic favors constant arguments that are used in control -// flow. -// -//===----------------------------------------------------------------------===// - -#define DEBUG_TYPE "partialspecialization" -#include "llvm/Transforms/IPO.h" -#include "llvm/Constant.h" -#include "llvm/Instructions.h" -#include "llvm/Module.h" -#include "llvm/Pass.h" -#include "llvm/ADT/Statistic.h" -#include "llvm/Analysis/InlineCost.h" -#include "llvm/Transforms/Utils/Cloning.h" -#include "llvm/Support/CallSite.h" -#include "llvm/ADT/DenseSet.h" -#include -using namespace llvm; - -STATISTIC(numSpecialized, "Number of specialized functions created"); -STATISTIC(numReplaced, "Number of callers replaced by specialization"); - -// Maximum number of arguments markable interested -static const int MaxInterests = 6; - -namespace { - typedef SmallVector InterestingArgVector; - class PartSpec : public ModulePass { - void scanForInterest(Function&, InterestingArgVector&); - int scanDistribution(Function&, int, std::map&); - InlineCostAnalyzer CA; - public : - static char ID; // Pass identification, replacement for typeid - PartSpec() : ModulePass(ID) { - initializePartSpecPass(*PassRegistry::getPassRegistry()); - } - bool runOnModule(Module &M); - }; -} - -char PartSpec::ID = 0; -INITIALIZE_PASS(PartSpec, "partialspecialization", - "Partial Specialization", false, false) - -// Specialize F by replacing the arguments (keys) in replacements with the -// constants (values). Replace all calls to F with those constants with -// a call to the specialized function. Returns the specialized function -static Function* -SpecializeFunction(Function* F, - ValueToValueMapTy& replacements) { - // arg numbers of deleted arguments - DenseMap deleted; - for (ValueToValueMapTy::iterator - repb = replacements.begin(), repe = replacements.end(); - repb != repe; ++repb) { - Argument const *arg = cast(repb->first); - deleted[arg->getArgNo()] = arg; - } - - Function* NF = CloneFunction(F, replacements, - /*ModuleLevelChanges=*/false); - NF->setLinkage(GlobalValue::InternalLinkage); - F->getParent()->getFunctionList().push_back(NF); - - // FIXME: Specialized versions getting the same constants should also get - // the same name. That way, specializations for public functions can be - // marked linkonce_odr and reused across modules. - - for (Value::use_iterator ii = F->use_begin(), ee = F->use_end(); - ii != ee; ) { - Value::use_iterator i = ii; - ++ii; - User *U = *i; - CallSite CS(U); - if (CS) { - if (CS.getCalledFunction() == F) { - SmallVector args; - // Assemble the non-specialized arguments for the updated callsite. - // In the process, make sure that the specialized arguments are - // constant and match the specialization. If that's not the case, - // this callsite needs to call the original or some other - // specialization; don't change it here. - CallSite::arg_iterator as = CS.arg_begin(), ae = CS.arg_end(); - for (CallSite::arg_iterator ai = as; ai != ae; ++ai) { - DenseMap::iterator delit = deleted.find( - std::distance(as, ai)); - if (delit == deleted.end()) - args.push_back(cast(ai)); - else { - Constant *ci = dyn_cast(ai); - if (!(ci && ci == replacements[delit->second])) - goto next_use; - } - } - Value* NCall; - if (CallInst *CI = dyn_cast(U)) { - NCall = CallInst::Create(NF, args.begin(), args.end(), - CI->getName(), CI); - cast(NCall)->setTailCall(CI->isTailCall()); - cast(NCall)->setCallingConv(CI->getCallingConv()); - } else { - InvokeInst *II = cast(U); - NCall = InvokeInst::Create(NF, II->getNormalDest(), - II->getUnwindDest(), - args.begin(), args.end(), - II->getName(), II); - cast(NCall)->setCallingConv(II->getCallingConv()); - } - CS.getInstruction()->replaceAllUsesWith(NCall); - CS.getInstruction()->eraseFromParent(); - ++numReplaced; - } - } - next_use:; - } - return NF; -} - - -bool PartSpec::runOnModule(Module &M) { - bool Changed = false; - for (Module::iterator I = M.begin(); I != M.end(); ++I) { - Function &F = *I; - if (F.isDeclaration() || F.mayBeOverridden()) continue; - InterestingArgVector interestingArgs; - scanForInterest(F, interestingArgs); - - // Find the first interesting Argument that we can specialize on - // If there are multiple interesting Arguments, then those will be found - // when processing the cloned function. - bool breakOuter = false; - for (unsigned int x = 0; !breakOuter && x < interestingArgs.size(); ++x) { - std::map distribution; - scanDistribution(F, interestingArgs[x], distribution); - for (std::map::iterator ii = distribution.begin(), - ee = distribution.end(); ii != ee; ++ii) { - // The distribution map might have an entry for NULL (i.e., one or more - // callsites were passing a non-constant there). We allow that to - // happen so that we can see whether any callsites pass a non-constant; - // if none do and the function is internal, we might have an opportunity - // to kill the original function. - if (!ii->first) continue; - int bonus = ii->second; - SmallVector argnos; - argnos.push_back(interestingArgs[x]); - InlineCost cost = CA.getSpecializationCost(&F, argnos); - // FIXME: If this is the last constant entry, and no non-constant - // entries exist, and the target function is internal, the cost should - // be reduced by the original size of the target function, almost - // certainly making it negative and causing a specialization that will - // leave the original function dead and removable. - if (cost.isAlways() || - (cost.isVariable() && cost.getValue() < bonus)) { - ValueToValueMapTy m; - Function::arg_iterator arg = F.arg_begin(); - for (int y = 0; y < interestingArgs[x]; ++y) - ++arg; - m[&*arg] = ii->first; - SpecializeFunction(&F, m); - ++numSpecialized; - breakOuter = true; - Changed = true; - } - } - } - } - return Changed; -} - -/// scanForInterest - This function decides which arguments would be worth -/// specializing on. -void PartSpec::scanForInterest(Function& F, InterestingArgVector& args) { - for(Function::arg_iterator ii = F.arg_begin(), ee = F.arg_end(); - ii != ee; ++ii) { - int argno = std::distance(F.arg_begin(), ii); - SmallVector argnos; - argnos.push_back(argno); - int bonus = CA.getSpecializationBonus(&F, argnos); - if (bonus > 0) { - args.push_back(argno); - } - } -} - -/// scanDistribution - Construct a histogram of constants for arg of F at arg. -/// For each distinct constant, we'll compute the total of the specialization -/// bonus across all callsites passing that constant; if that total exceeds -/// the specialization cost, we will create the specialization. -int PartSpec::scanDistribution(Function& F, int arg, - std::map& dist) { - bool hasIndirect = false; - int total = 0; - for (Value::use_iterator ii = F.use_begin(), ee = F.use_end(); - ii != ee; ++ii) { - User *U = *ii; - CallSite CS(U); - if (CS && CS.getCalledFunction() == &F) { - SmallVector argnos; - argnos.push_back(arg); - dist[dyn_cast(CS.getArgument(arg))] += - CA.getSpecializationBonus(&F, argnos); - ++total; - } else - hasIndirect = true; - } - - // Preserve the original address taken function even if all other uses - // will be specialized. - if (hasIndirect) ++total; - return total; -} - -ModulePass* llvm::createPartialSpecializationPass() { return new PartSpec(); } diff --git a/test/Transforms/PartialSpecialize/dg.exp b/test/Transforms/PartialSpecialize/dg.exp deleted file mode 100644 index f2005891a59..00000000000 --- a/test/Transforms/PartialSpecialize/dg.exp +++ /dev/null @@ -1,3 +0,0 @@ -load_lib llvm.exp - -RunLLVMTests [lsort [glob -nocomplain $srcdir/$subdir/*.{ll,c,cpp}]] diff --git a/test/Transforms/PartialSpecialize/heuristics.ll b/test/Transforms/PartialSpecialize/heuristics.ll deleted file mode 100644 index 5ccf9ad86ef..00000000000 --- a/test/Transforms/PartialSpecialize/heuristics.ll +++ /dev/null @@ -1,49 +0,0 @@ -; If there are not enough callsites for a particular specialization to -; justify its existence, the specialization shouldn't be created. -; -; RUN: opt -S -partialspecialization -disable-inlining %s | FileCheck %s -declare void @callback1() -declare void @callback2() - -declare void @othercall() - -define internal void @UseCallback(void()* %pCallback) { - call void %pCallback() - call void @othercall() - call void @othercall() - call void @othercall() - call void @othercall() - call void @othercall() - call void @othercall() - call void @othercall() - call void @othercall() - call void @othercall() - call void @othercall() - call void @othercall() - call void @othercall() - call void @othercall() - call void @othercall() - call void @othercall() - call void @othercall() - call void @othercall() - call void @othercall() - ret void -} - -define void @foo(void()* %pNonConstCallback) -{ -Entry: -; CHECK: Entry -; CHECK-NOT: call void @UseCallback(void ()* @callback1) -; CHECK: call void @UseCallback(void ()* @callback2) -; CHECK-NEXT: call void @UseCallback(void ()* @callback2) -; CHECK-NEXT: ret void - call void @UseCallback(void()* @callback1) - call void @UseCallback(void()* @callback1) - call void @UseCallback(void()* @callback1) - call void @UseCallback(void()* @callback1) - call void @UseCallback(void()* @callback2) - call void @UseCallback(void()* @callback2) - - ret void -} diff --git a/test/Transforms/PartialSpecialize/two-specializations.ll b/test/Transforms/PartialSpecialize/two-specializations.ll deleted file mode 100644 index bc3da22e185..00000000000 --- a/test/Transforms/PartialSpecialize/two-specializations.ll +++ /dev/null @@ -1,37 +0,0 @@ -; If there are two specializations of a function, make sure each callsite -; calls the right one. -; -; RUN: opt -S -partialspecialization -disable-inlining %s | opt -S -inline | FileCheck %s -check-prefix=CORRECT -; RUN: opt -S -partialspecialization -disable-inlining %s | FileCheck %s -declare void @callback1() -declare void @callback2() - -define internal void @UseCallback(void()* %pCallback) { - call void %pCallback() - ret void -} - -define void @foo(void()* %pNonConstCallback) -{ -Entry: -; CORRECT: Entry -; CORRECT-NEXT: call void @callback1() -; CORRECT-NEXT: call void @callback1() -; CORRECT-NEXT: call void @callback2() -; CORRECT-NEXT: call void %pNonConstCallback() -; CORRECT-NEXT: call void @callback1() -; CORRECT-NEXT: call void @callback2() -; CORRECT-NEXT: call void @callback2() -; CHECK: Entry -; CHECK-NOT: call void @UseCallback(void ()* @callback1) -; CHECK-NOT: call void @UseCallback(void ()* @callback2) -; CHECK: ret void - call void @UseCallback(void()* @callback1) - call void @UseCallback(void()* @callback1) - call void @UseCallback(void()* @callback2) - call void @UseCallback(void()* %pNonConstCallback) - call void @UseCallback(void()* @callback1) - call void @UseCallback(void()* @callback2) - call void @UseCallback(void()* @callback2) - ret void -}