[PATCH] D60971: [BlockExtractor] Expose a constructor for the group extraction

Quentin Colombet via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 29 09:14:42 PDT 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rL359463: [BlockExtractor] Expose a constructor for the group extraction (authored by qcolombet, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D60971?vs=196097&id=197127#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60971/new/

https://reviews.llvm.org/D60971

Files:
  llvm/trunk/include/llvm/Transforms/IPO.h
  llvm/trunk/lib/Transforms/IPO/BlockExtractor.cpp


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<std::pair<std::string, SmallVector<std::string, 4>>, 4>
       BlocksByName;
 
+  void init(const SmallVectorImpl<SmallVector<BasicBlock *, 16>>
+                &GroupsOfBlocksToExtract) {
+    for (const SmallVectorImpl<BasicBlock *> &GroupOfBlocks :
+         GroupsOfBlocksToExtract) {
+      SmallVector<BasicBlock *, 16> NewGroup;
+      NewGroup.append(GroupOfBlocks.begin(), GroupOfBlocks.end());
+      GroupsOfBlocks.emplace_back(NewGroup);
+    }
+    if (!BlockExtractorFile.empty())
+      loadFile();
+  }
+
 public:
   static char ID;
   BlockExtractor(const SmallVectorImpl<BasicBlock *> &BlocksToExtract,
                  bool EraseFunctions)
       : ModulePass(ID), EraseFunctions(EraseFunctions) {
     // We want one group per element of the input list.
+    SmallVector<SmallVector<BasicBlock *, 16>, 4> MassagedGroupsOfBlocks;
     for (BasicBlock *BB : BlocksToExtract) {
       SmallVector<BasicBlock *, 16> NewGroup;
       NewGroup.push_back(BB);
-      GroupsOfBlocks.push_back(NewGroup);
+      MassagedGroupsOfBlocks.push_back(NewGroup);
     }
-    if (!BlockExtractorFile.empty())
-      loadFile();
+    init(MassagedGroupsOfBlocks);
   }
+
+  BlockExtractor(const SmallVectorImpl<SmallVector<BasicBlock *, 16>>
+                     &GroupsOfBlocksToExtract,
+                 bool EraseFunctions)
+      : ModulePass(ID), EraseFunctions(EraseFunctions) {
+    init(GroupsOfBlocksToExtract);
+  }
+
   BlockExtractor() : BlockExtractor(SmallVector<BasicBlock *, 0>(), false) {}
   bool runOnModule(Module &M) override;
 
@@ -76,6 +96,12 @@
     const SmallVectorImpl<BasicBlock *> &BlocksToExtract, bool EraseFunctions) {
   return new BlockExtractor(BlocksToExtract, EraseFunctions);
 }
+ModulePass *llvm::createBlockExtractorPass(
+    const SmallVectorImpl<SmallVector<BasicBlock *, 16>>
+        &GroupsOfBlocksToExtract,
+    bool EraseFunctions) {
+  return new BlockExtractor(GroupsOfBlocksToExtract, EraseFunctions);
+}
 
 /// Gets all of the blocks specified in the input file.
 void BlockExtractor::loadFile() {
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<BasicBlock *> &BlocksToExtract,
                          bool EraseFunctions);
+ModulePass *
+createBlockExtractorPass(const SmallVectorImpl<SmallVector<BasicBlock *, 16>>
+                             &GroupsOfBlocksToExtract,
+                         bool EraseFunctions);
 
 /// createStripDeadPrototypesPass - This pass removes any function declarations
 /// (prototypes) that are not used.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D60971.197127.patch
Type: text/x-patch
Size: 3008 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190429/7e4b4163/attachment.bin>


More information about the llvm-commits mailing list