[llvm-commits] CVS: llvm/lib/Transforms/IPO/StripDeadPrototypes.cpp
Chris Lattner
clattner at apple.com
Mon Feb 5 13:12:01 PST 2007
> Create a pass to strip dead function declarations (prototypes).
> This is
> for use by llvm-extract and bugpoint.
Nice, thanks!
> + namespace {
> +
> + /// @brief Pass to remove unused function declarations.
> + class StripDeadPrototypesPass : public ModulePass {
Please use the horrible VISIBILITY_HIDDEN annotation thing.
> + public:
> + StripDeadPrototypesPass() { }
> + virtual bool runOnModule(Module &M);
> + };
> + RegisterPass<StripDeadPrototypesPass> X("strip-dead-prototypes",
> + "Strip Unused Function
> Prototypes");
> +
> + bool StripDeadPrototypesPass::runOnModule(Module &M) {
Pedantic: Please end the anonymous namespace before the out of line
method. It doesn't need to be nested in the namespace, and this
reduces the lexical size of the namespace.
Thanks Reid!
-Chris
> + // Collect all the functions we want to erase
> + std::vector<Function*> FuncsToErase;
> + for (Module::iterator I = M.begin(), E = M.end(); I != E; ++I)
> + if (I->isDeclaration() && // Function must be only a
> prototype
> + I->use_empty()) { // Function must not be used
> + FuncsToErase.push_back(&(*I));
> + }
> +
> + // Erase the functions
> + for (std::vector<Function*>::iterator I = FuncsToErase.begin(),
> + E = FuncsToErase.end(); I != E; ++I )
> + (*I)->eraseFromParent();
> +
> + // Increment the statistic
> + NumDeadPrototypes += FuncsToErase.size();
> +
> + // Return an indication of whether we changed anything or not.
> + return !FuncsToErase.empty();
> + }
> +
> + } // end anonymous namespace
> +
> + ModulePass *llvm::createStripDeadPrototypesPass() {
> + return new StripDeadPrototypesPass();
> + }
>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list