1 //===- InstructionNamer.cpp - Give anonymous instructions names -----------===//
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
7 //===----------------------------------------------------------------------===//
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
14 //===----------------------------------------------------------------------===//
16 #include "llvm/IR/Function.h"
17 #include "llvm/IR/Type.h"
18 #include "llvm/Pass.h"
19 #include "llvm/Transforms/Utils.h"
23 struct InstNamer
: public FunctionPass
{
24 static char ID
; // Pass identification, replacement for typeid
25 InstNamer() : FunctionPass(ID
) {
26 initializeInstNamerPass(*PassRegistry::getPassRegistry());
29 void getAnalysisUsage(AnalysisUsage
&Info
) const override
{
30 Info
.setPreservesAll();
33 bool runOnFunction(Function
&F
) override
{
34 for (auto &Arg
: F
.args())
38 for (BasicBlock
&BB
: F
) {
42 for (Instruction
&I
: BB
)
43 if (!I
.hasName() && !I
.getType()->isVoidTy())
50 char InstNamer::ID
= 0;
53 INITIALIZE_PASS(InstNamer
, "instnamer",
54 "Assign names to anonymous instructions", false, false)
55 char &llvm::InstructionNamerID
= InstNamer::ID
;
56 //===----------------------------------------------------------------------===//
58 // InstructionNamer - Give any unnamed non-void instructions "tmp" names.
60 FunctionPass
*llvm::createInstructionNamerPass() {
61 return new InstNamer();