<p dir="ltr">This is the same as llcm-extract, no?</p>
<div class="gmail_quote">On Mar 28, 2016 4:49 PM, "Yin Ma via llvm-commits" <<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">yinma created this revision.<br>
yinma added a subscriber: llvm-commits.<br>
<br>
This procedure could dump the module, where the function becomes the only defined function in its module. This is very useful to debug large code base where reducing from source code is difficult, like LTO.<br>
<br>
<a href="http://reviews.llvm.org/D18524" rel="noreferrer" target="_blank">http://reviews.llvm.org/D18524</a><br>
<br>
Files:<br>
  include/llvm/IR/Function.h<br>
  lib/IR/Function.cpp<br>
<br>
Index: lib/IR/Function.cpp<br>
===================================================================<br>
--- lib/IR/Function.cpp<br>
+++ lib/IR/Function.cpp<br>
@@ -1005,3 +1005,41 @@<br>
       }<br>
   return None;<br>
 }<br>
+<br>
+void Function::dumpAsSingleDefine()<br>
+{<br>
+  typedef std::vector<BasicBlock*> BlockList;<br>
+  typedef std::pair<BlockList*, GlobalValue::LinkageTypes> FuncInfo;<br>
+  typedef std::map<Function*, FuncInfo> FuncMap;<br>
+  FuncMap funcList;<br>
+  // Temporarily change all defined functions to be declaration<br>
+  // except for this one.<br>
+  Module* M = getParent();<br>
+  for (Function &F : *M)<br>
+    if (!F.isDeclaration() && &F != this) {<br>
+      BlockList* blockList = new BlockList;<br>
+      Function::BasicBlockListType &oldBlocks = F.getBasicBlockList();<br>
+      while (!oldBlocks.empty()) {<br>
+        blockList->push_back(&oldBlocks.back());<br>
+        oldBlocks.remove(oldBlocks.back());<br>
+      }<br>
+      funcList[&F]= std::make_pair(blockList, F.getLinkage());<br>
+      F.setLinkage(ExternalLinkage);<br>
+    }<br>
+<br>
+  M->dump();<br>
+<br>
+  // Restore everything back.<br>
+  for (auto it : funcList) {<br>
+    Function* F = it.first;<br>
+    BlockList* list = it.second.first;<br>
+    GlobalValue::LinkageTypes LT = it.second.second;<br>
+    Function::BasicBlockListType &oldBlocks = F->getBasicBlockList();<br>
+    while(!list->empty()) {<br>
+      oldBlocks.push_back(list->back());<br>
+      list->pop_back();<br>
+    }<br>
+    F->setLinkage(LT);<br>
+  }<br>
+}<br>
+<br>
Index: include/llvm/IR/Function.h<br>
===================================================================<br>
--- include/llvm/IR/Function.h<br>
+++ include/llvm/IR/Function.h<br>
@@ -555,6 +555,9 @@<br>
              bool ShouldPreserveUseListOrder = false,<br>
              bool IsForDebug = false) const;<br>
<br>
+  /// Dump the function as it is the only defined function in module.<br>
+  void dumpAsSingleDefine();<br>
+<br>
   /// viewCFG - This function is meant for use from the debugger.  You can just<br>
   /// say 'call F->viewCFG()' and a ghostview window should pop up from the<br>
   /// program, displaying the CFG of the current function with the code for each<br>
<br>
<br>
<br>_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits</a><br>
<br></blockquote></div>