[PATCH] D18524: Dump function as the only defined function in its module.

Rafael EspĂ­ndola via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 28 17:06:18 PDT 2016


This is the same as llcm-extract, no?
On Mar 28, 2016 4:49 PM, "Yin Ma via llvm-commits" <
llvm-commits at lists.llvm.org> wrote:

> yinma created this revision.
> yinma added a subscriber: llvm-commits.
>
> 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.
>
> http://reviews.llvm.org/D18524
>
> Files:
>   include/llvm/IR/Function.h
>   lib/IR/Function.cpp
>
> Index: lib/IR/Function.cpp
> ===================================================================
> --- lib/IR/Function.cpp
> +++ lib/IR/Function.cpp
> @@ -1005,3 +1005,41 @@
>        }
>    return None;
>  }
> +
> +void Function::dumpAsSingleDefine()
> +{
> +  typedef std::vector<BasicBlock*> BlockList;
> +  typedef std::pair<BlockList*, GlobalValue::LinkageTypes> FuncInfo;
> +  typedef std::map<Function*, FuncInfo> FuncMap;
> +  FuncMap funcList;
> +  // Temporarily change all defined functions to be declaration
> +  // except for this one.
> +  Module* M = getParent();
> +  for (Function &F : *M)
> +    if (!F.isDeclaration() && &F != this) {
> +      BlockList* blockList = new BlockList;
> +      Function::BasicBlockListType &oldBlocks = F.getBasicBlockList();
> +      while (!oldBlocks.empty()) {
> +        blockList->push_back(&oldBlocks.back());
> +        oldBlocks.remove(oldBlocks.back());
> +      }
> +      funcList[&F]= std::make_pair(blockList, F.getLinkage());
> +      F.setLinkage(ExternalLinkage);
> +    }
> +
> +  M->dump();
> +
> +  // Restore everything back.
> +  for (auto it : funcList) {
> +    Function* F = it.first;
> +    BlockList* list = it.second.first;
> +    GlobalValue::LinkageTypes LT = it.second.second;
> +    Function::BasicBlockListType &oldBlocks = F->getBasicBlockList();
> +    while(!list->empty()) {
> +      oldBlocks.push_back(list->back());
> +      list->pop_back();
> +    }
> +    F->setLinkage(LT);
> +  }
> +}
> +
> Index: include/llvm/IR/Function.h
> ===================================================================
> --- include/llvm/IR/Function.h
> +++ include/llvm/IR/Function.h
> @@ -555,6 +555,9 @@
>               bool ShouldPreserveUseListOrder = false,
>               bool IsForDebug = false) const;
>
> +  /// Dump the function as it is the only defined function in module.
> +  void dumpAsSingleDefine();
> +
>    /// viewCFG - This function is meant for use from the debugger.  You
> can just
>    /// say 'call F->viewCFG()' and a ghostview window should pop up from
> the
>    /// program, displaying the CFG of the current function with the code
> for each
>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160328/9c2a3716/attachment.html>


More information about the llvm-commits mailing list