LLVM  15.0.0git
InstructionNamer.cpp
Go to the documentation of this file.
1 //===- InstructionNamer.cpp - Give anonymous instructions names -----------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This is a little utility pass that gives instructions names, this is mostly
10 // useful when diffing the effect of an optimization because deleting an
11 // unnamed instruction can change all other instruction numbering, making the
12 // diff very noisy.
13 //
14 //===----------------------------------------------------------------------===//
15 
17 #include "llvm/IR/Function.h"
18 #include "llvm/IR/PassManager.h"
19 #include "llvm/IR/Type.h"
20 #include "llvm/InitializePasses.h"
21 #include "llvm/Pass.h"
22 #include "llvm/Transforms/Utils.h"
23 
24 using namespace llvm;
25 
26 namespace {
27 void nameInstructions(Function &F) {
28  for (auto &Arg : F.args()) {
29  if (!Arg.hasName())
30  Arg.setName("arg");
31  }
32 
33  for (BasicBlock &BB : F) {
34  if (!BB.hasName())
35  BB.setName("bb");
36 
37  for (Instruction &I : BB) {
38  if (!I.hasName() && !I.getType()->isVoidTy())
39  I.setName("i");
40  }
41  }
42 }
43 
44 struct InstNamer : public FunctionPass {
45  static char ID; // Pass identification, replacement for typeid
46  InstNamer() : FunctionPass(ID) {
48  }
49 
50  void getAnalysisUsage(AnalysisUsage &Info) const override {
51  Info.setPreservesAll();
52  }
53 
54  bool runOnFunction(Function &F) override {
55  nameInstructions(F);
56  return true;
57  }
58 };
59 
60  char InstNamer::ID = 0;
61  } // namespace
62 
63 INITIALIZE_PASS(InstNamer, "instnamer",
64  "Assign names to anonymous instructions", false, false)
65 char &llvm::InstructionNamerID = InstNamer::ID;
66 //===----------------------------------------------------------------------===//
67 //
68 // InstructionNamer - Give any unnamed non-void instructions "tmp" names.
69 //
71  return new InstNamer();
72 }
73 
76  nameInstructions(F);
77  return PreservedAnalyses::all();
78 }
llvm::PreservedAnalyses
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:152
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
llvm::InstructionNamerID
char & InstructionNamerID
llvm::Function
Definition: Function.h:60
InstructionNamer.h
Pass.h
FAM
FunctionAnalysisManager FAM
Definition: PassBuilderBindings.cpp:59
llvm::createInstructionNamerPass
FunctionPass * createInstructionNamerPass()
F
#define F(x, y, z)
Definition: MD5.cpp:55
llvm::BasicBlock
LLVM Basic Block Representation.
Definition: BasicBlock.h:55
Arg
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
Definition: AMDGPULibCalls.cpp:186
llvm::PassRegistry::getPassRegistry
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
Definition: PassRegistry.cpp:31
INITIALIZE_PASS
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:37
llvm::AnalysisUsage
Represent the analysis usage information of a pass.
Definition: PassAnalysisSupport.h:47
llvm::Instruction
Definition: Instruction.h:42
Info
Analysis containing CSE Info
Definition: CSEInfo.cpp:27
Utils.h
llvm::CallingConv::ID
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition: CallingConv.h:24
Type.h
llvm::InstructionNamerPass::run
PreservedAnalyses run(Function &, FunctionAnalysisManager &)
Definition: InstructionNamer.cpp:74
I
#define I(x, y, z)
Definition: MD5.cpp:58
runOnFunction
static bool runOnFunction(Function &F, bool PostInlining)
Definition: EntryExitInstrumenter.cpp:69
llvm::PreservedAnalyses::all
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition: PassManager.h:158
Function.h
PassManager.h
llvm::AnalysisManager
A container for analyses that lazily runs them and caches their results.
Definition: InstructionSimplify.h:42
llvm::FunctionPass
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:308
BB
Common register allocation spilling lr str ldr sxth r3 ldr mla r4 can lr mov lr str ldr sxth r3 mla r4 and then merge mul and lr str ldr sxth r3 mla r4 It also increase the likelihood the store may become dead bb27 Successors according to LLVM BB
Definition: README.txt:39
llvm::initializeInstNamerPass
void initializeInstNamerPass(PassRegistry &)
InitializePasses.h
llvm::Intrinsic::ID
unsigned ID
Definition: TargetTransformInfo.h:38