Index: llvm/trunk/include/llvm/Transforms/IPO.h =================================================================== --- llvm/trunk/include/llvm/Transforms/IPO.h +++ llvm/trunk/include/llvm/Transforms/IPO.h @@ -182,6 +182,10 @@ ModulePass * createBlockExtractorPass(const SmallVectorImpl &BlocksToExtract, bool EraseFunctions); +ModulePass * +createBlockExtractorPass(const SmallVectorImpl> + &GroupsOfBlocksToExtract, + bool EraseFunctions); /// createStripDeadPrototypesPass - This pass removes any function declarations /// (prototypes) that are not used. Index: llvm/trunk/lib/Transforms/IPO/BlockExtractor.cpp =================================================================== --- llvm/trunk/lib/Transforms/IPO/BlockExtractor.cpp +++ llvm/trunk/lib/Transforms/IPO/BlockExtractor.cpp @@ -44,20 +44,40 @@ SmallVector>, 4> BlocksByName; + void init(const SmallVectorImpl> + &GroupsOfBlocksToExtract) { + for (const SmallVectorImpl &GroupOfBlocks : + GroupsOfBlocksToExtract) { + SmallVector NewGroup; + NewGroup.append(GroupOfBlocks.begin(), GroupOfBlocks.end()); + GroupsOfBlocks.emplace_back(NewGroup); + } + if (!BlockExtractorFile.empty()) + loadFile(); + } + public: static char ID; BlockExtractor(const SmallVectorImpl &BlocksToExtract, bool EraseFunctions) : ModulePass(ID), EraseFunctions(EraseFunctions) { // We want one group per element of the input list. + SmallVector, 4> MassagedGroupsOfBlocks; for (BasicBlock *BB : BlocksToExtract) { SmallVector NewGroup; NewGroup.push_back(BB); - GroupsOfBlocks.push_back(NewGroup); + MassagedGroupsOfBlocks.push_back(NewGroup); } - if (!BlockExtractorFile.empty()) - loadFile(); + init(MassagedGroupsOfBlocks); } + + BlockExtractor(const SmallVectorImpl> + &GroupsOfBlocksToExtract, + bool EraseFunctions) + : ModulePass(ID), EraseFunctions(EraseFunctions) { + init(GroupsOfBlocksToExtract); + } + BlockExtractor() : BlockExtractor(SmallVector(), false) {} bool runOnModule(Module &M) override; @@ -76,6 +96,12 @@ const SmallVectorImpl &BlocksToExtract, bool EraseFunctions) { return new BlockExtractor(BlocksToExtract, EraseFunctions); } +ModulePass *llvm::createBlockExtractorPass( + const SmallVectorImpl> + &GroupsOfBlocksToExtract, + bool EraseFunctions) { + return new BlockExtractor(GroupsOfBlocksToExtract, EraseFunctions); +} /// Gets all of the blocks specified in the input file. void BlockExtractor::loadFile() {