From 226fd2b61abedd47145642cdceb306794e5cab03 Mon Sep 17 00:00:00 2001 From: Quentin Colombet Date: Mon, 29 Apr 2019 16:14:02 +0000 Subject: [PATCH] [BlockExtractor] Expose a constructor for the group extraction NFC Differential Revision: https://reviews.llvm.org/D60971 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@359463 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Transforms/IPO.h | 4 ++++ lib/Transforms/IPO/BlockExtractor.cpp | 32 +++++++++++++++++++++++++++++--- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/include/llvm/Transforms/IPO.h b/include/llvm/Transforms/IPO.h index 4f7a1bae12b..de0c80f5b19 100644 --- a/include/llvm/Transforms/IPO.h +++ b/include/llvm/Transforms/IPO.h @@ -182,6 +182,10 @@ ModulePass *createBlockExtractorPass(); 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. diff --git a/lib/Transforms/IPO/BlockExtractor.cpp b/lib/Transforms/IPO/BlockExtractor.cpp index 5cf2235bbff..6c365f3f3cb 100644 --- a/lib/Transforms/IPO/BlockExtractor.cpp +++ b/lib/Transforms/IPO/BlockExtractor.cpp @@ -44,20 +44,40 @@ class BlockExtractor : public ModulePass { 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 @@ ModulePass *llvm::createBlockExtractorPass( 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() { -- 2.11.0