[llvm] r240583 - opt: Add option to strip or add llvm value names

Matthias Braun matze at braunis.de
Wed Jun 24 23:44:58 PDT 2015


This was actuallu committed by accident as I learned there were already options for these features that I missed. For some reason there was never a mail about the revert commit on this list.

- Matthias

> On Jun 24, 2015, at 7:36 PM, Sean Silva <chisophugis at gmail.com> wrote:
> 
> Please update docs/CommandGuide/opt.rst
> 
> IIRC correctly in the past Rafael spoke up against me adding features to opt (or was it llvm-link?) that weren't needed for testing. CC'ing him in case he has an opinion.
> 
> -- Sean Silva
> 
> On Wed, Jun 24, 2015 at 1:03 PM, Matthias Braun <matze at braunis.de <mailto:matze at braunis.de>> wrote:
> Author: matze
> Date: Wed Jun 24 15:03:33 2015
> New Revision: 240583
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=240583&view=rev <http://llvm.org/viewvc/llvm-project?rev=240583&view=rev>
> Log:
> opt: Add option to strip or add llvm value names
> 
> Modified:
>     llvm/trunk/tools/opt/opt.cpp
> 
> Modified: llvm/trunk/tools/opt/opt.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/opt/opt.cpp?rev=240583&r1=240582&r2=240583&view=diff <http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/opt/opt.cpp?rev=240583&r1=240582&r2=240583&view=diff>
> ==============================================================================
> --- llvm/trunk/tools/opt/opt.cpp (original)
> +++ llvm/trunk/tools/opt/opt.cpp Wed Jun 24 15:03:33 2015
> @@ -105,6 +105,12 @@ StripDebug("strip-debug",
>             cl::desc("Strip debugger symbol info from translation unit"));
> 
>  static cl::opt<bool>
> +StripValueNames("strip-value-names", cl::desc("Remove llvm value names"));
> +
> +static cl::opt<bool>
> +NameValues("name-values", cl::desc("Give anonymous llvm values a name"));
> +
> +static cl::opt<bool>
>  DisableInline("disable-inlining", cl::desc("Do not run the inliner pass"));
> 
>  static cl::opt<bool>
> @@ -281,6 +287,37 @@ static TargetMachine* GetTargetMachine(T
>                                          GetCodeGenOptLevel());
>  }
> 
> +static void removeValueNames(Module &Mod) {
> +  for (Function &F : Mod) {
> +    for (BasicBlock &BB : F) {
> +      BB.setName("");
> +      for (Instruction &I : BB)
> +        I.setName("");
> +    }
> +  }
> +}
> +
> +static void nameValuesInFunction(Function &F) {
> +  bool FirstBB = true;
> +  for (BasicBlock &BB : F) {
> +    if (!BB.hasName())
> +      BB.setName(FirstBB ? "entry" : "BB");
> +    FirstBB = false;
> +
> +    for (Instruction &I : BB) {
> +      if (I.getType()->isVoidTy())
> +        continue;
> +      if (!I.hasName())
> +        I.setName("v");
> +    }
> +  }
> +}
> +
> +static void nameValues(Module &Mod) {
> +  for (Function &F : Mod)
> +    nameValuesInFunction(F);
> +}
> +
>  #ifdef LINK_POLLY_INTO_TOOLS
>  namespace polly {
>  void initializePollyPasses(llvm::PassRegistry &Registry);
> @@ -351,6 +388,12 @@ int main(int argc, char **argv) {
>    if (StripDebug)
>      StripDebugInfo(*M);
> 
> +  if (StripValueNames)
> +    removeValueNames(*M);
> +
> +  if (NameValues)
> +    nameValues(*M);
> +
>    // Immediately run the verifier to catch any problems before starting up the
>    // pass pipelines.  Otherwise we can crash on broken code during
>    // doInitialization().
> 
> 
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu <mailto:llvm-commits at cs.uiuc.edu>
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits <http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits>
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150624/fffbf01a/attachment.html>


More information about the llvm-commits mailing list