LLVM  6.0.0svn
InstructionNamer.cpp
Go to the documentation of this file.
1 //===- InstructionNamer.cpp - Give anonymous instructions names -----------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This is a little utility pass that gives instructions names, this is mostly
11 // useful when diffing the effect of an optimization because deleting an
12 // unnamed instruction can change all other instruction numbering, making the
13 // diff very noisy.
14 //
15 //===----------------------------------------------------------------------===//
16 
17 #include "llvm/IR/Function.h"
18 #include "llvm/IR/Type.h"
19 #include "llvm/Pass.h"
20 #include "llvm/Transforms/Scalar.h"
21 using namespace llvm;
22 
23 namespace {
24  struct InstNamer : public FunctionPass {
25  static char ID; // Pass identification, replacement for typeid
26  InstNamer() : FunctionPass(ID) {
28  }
29 
30  void getAnalysisUsage(AnalysisUsage &Info) const override {
31  Info.setPreservesAll();
32  }
33 
34  bool runOnFunction(Function &F) override {
35  for (auto &Arg : F.args())
36  if (!Arg.hasName())
37  Arg.setName("arg");
38 
39  for (BasicBlock &BB : F) {
40  if (!BB.hasName())
41  BB.setName("bb");
42 
43  for (Instruction &I : BB)
44  if (!I.hasName() && !I.getType()->isVoidTy())
45  I.setName("tmp");
46  }
47  return true;
48  }
49  };
50 
51  char InstNamer::ID = 0;
52 }
53 
54 INITIALIZE_PASS(InstNamer, "instnamer",
55  "Assign names to anonymous instructions", false, false)
56 char &llvm::InstructionNamerID = InstNamer::ID;
57 //===----------------------------------------------------------------------===//
58 //
59 // InstructionNamer - Give any unnamed non-void instructions "tmp" names.
60 //
62  return new InstNamer();
63 }
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
F(f)
void setName(const Twine &Name)
Change the name of the value.
Definition: Value.cpp:284
bool hasName() const
Definition: Value.h:251
LLVM Basic Block Representation.
Definition: BasicBlock.h:59
Represent the analysis usage information of a pass.
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:285
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:34
void setPreservesAll()
Set by analyses that do not transform their input at all.
amdgpu Simplify well known AMD library false Value Value * Arg
void initializeInstNamerPass(PassRegistry &)
#define I(x, y, z)
Definition: MD5.cpp:58
char & InstructionNamerID
FunctionPass * createInstructionNamerPass()
iterator_range< arg_iterator > args()
Definition: Function.h:621