Index: docs/Passes.rst =================================================================== --- docs/Passes.rst +++ docs/Passes.rst @@ -1143,6 +1143,13 @@ instruction can change all other instruction numbering, making the diff very noisy. +``-instanonymizer``: Remove names from instructions +--------------------------------------------------- + +This is a little utility pass that removes names from instructions. This is +useful when building a library of bitcode files that will be used in a toolchain +that is sensitive to compile time. + .. _passes-verify: ``-verify``: Module Verifier Index: include/llvm/InitializePasses.h =================================================================== --- include/llvm/InitializePasses.h +++ include/llvm/InitializePasses.h @@ -175,6 +175,7 @@ void initializeInferAddressSpacesPass(PassRegistry&); void initializeInferFunctionAttrsLegacyPassPass(PassRegistry&); void initializeInlineCostAnalysisPass(PassRegistry&); +void initializeInstAnonymizerPass(PassRegistry&); void initializeInstCountPass(PassRegistry&); void initializeInstNamerPass(PassRegistry&); void initializeInstSimplifyLegacyPassPass(PassRegistry &); Index: include/llvm/LinkAllPasses.h =================================================================== --- include/llvm/LinkAllPasses.h +++ include/llvm/LinkAllPasses.h @@ -186,6 +186,7 @@ (void) llvm::createLoopDeletionPass(); (void) llvm::createPostDomTree(); (void) llvm::createInstructionNamerPass(); + (void) llvm::createInstructionAnonymizerPass(); (void) llvm::createMetaRenamerPass(); (void) llvm::createPostOrderFunctionAttrsLegacyPass(); (void) llvm::createReversePostOrderFunctionAttrsPass(); Index: include/llvm/Transforms/Utils.h =================================================================== --- include/llvm/Transforms/Utils.h +++ include/llvm/Transforms/Utils.h @@ -41,6 +41,13 @@ FunctionPass *createInstructionNamerPass(); extern char &InstructionNamerID; +//===----------------------------------------------------------------------===// +// +// InstructionAnonymizer - Remove names from instructions. +// +FunctionPass *createInstructionAnonymizerPass(); +extern char &InstructionAnonymizerID; + //===----------------------------------------------------------------------===// // // LowerSwitch - This pass converts SwitchInst instructions into a sequence of Index: lib/Transforms/Utils/CMakeLists.txt =================================================================== --- lib/Transforms/Utils/CMakeLists.txt +++ lib/Transforms/Utils/CMakeLists.txt @@ -21,6 +21,7 @@ GuardUtils.cpp InlineFunction.cpp ImportedFunctionsInliningStatistics.cpp + InstructionAnonymizer.cpp InstructionNamer.cpp IntegerDivision.cpp LCSSA.cpp Index: lib/Transforms/Utils/InstructionAnonymizer.cpp =================================================================== --- /dev/null +++ lib/Transforms/Utils/InstructionAnonymizer.cpp @@ -0,0 +1,61 @@ +//===- InstructionAnonymizer.cpp - Remove names from instructions ---------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This is a little utility pass that removes names from instructions. This is +// useful when building a library of bc files where the toolchain using the +// library is sensitive to compile time. +// +//===----------------------------------------------------------------------===// + +#include "llvm/IR/Function.h" +#include "llvm/IR/Type.h" +#include "llvm/Pass.h" +#include "llvm/Transforms/Utils.h" +using namespace llvm; + +namespace { + struct InstAnonymizer : public FunctionPass { + static char ID; // Pass identification, replacement for typeid + InstAnonymizer() : FunctionPass(ID) { + initializeInstAnonymizerPass(*PassRegistry::getPassRegistry()); + } + + void getAnalysisUsage(AnalysisUsage &Info) const override { + Info.setPreservesAll(); + } + + bool runOnFunction(Function &F) override { + for (auto &Arg : F.args()) + Arg.setName(""); + + for (BasicBlock &BB : F) { + BB.setName(""); + + for (Instruction &I : BB) + if (!I.getType()->isVoidTy()) + I.setName(""); + } + return true; + } + }; + + char InstAnonymizer::ID = 0; +} + +INITIALIZE_PASS(InstAnonymizer, "instanonymizer", + "Remove names from instructions", false, false) +char &llvm::InstructionAnonymizerID = InstAnonymizer::ID; +//===----------------------------------------------------------------------===// +// +// InstructionAnonymizer - Remove names from instructions. +// +FunctionPass *llvm::createInstructionAnonymizerPass() { + return new InstAnonymizer(); +} + Index: lib/Transforms/Utils/Utils.cpp =================================================================== --- lib/Transforms/Utils/Utils.cpp +++ lib/Transforms/Utils/Utils.cpp @@ -27,6 +27,7 @@ initializeAddDiscriminatorsLegacyPassPass(Registry); initializeBreakCriticalEdgesPass(Registry); initializeInstNamerPass(Registry); + initializeInstAnonymizerPass(Registry); initializeLCSSAWrapperPassPass(Registry); initializeLibCallsShrinkWrapLegacyPassPass(Registry); initializeLoopSimplifyPass(Registry); Index: test/Transforms/InstAnonymizer/basic.ll =================================================================== --- /dev/null +++ test/Transforms/InstAnonymizer/basic.ll @@ -0,0 +1,20 @@ +; RUN: opt -S -instanonymizer < %s | FileCheck %s + +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +define i32 @f_0(i32 %arg) { +; CHECK: @f_0(i32) +; CHECK-NOT: bb: +; CHECK-NEXT: %2 = add i32 %0, 2 +; CHECK-NEXT: br label %3 +; CHECK: ;