]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/lib/Transforms/Utils/InstructionNamer.cpp
Merge clang 7.0.1 and several follow-up changes
[FreeBSD/FreeBSD.git] / contrib / llvm / lib / Transforms / Utils / InstructionNamer.cpp
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/Utils.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) {
27       initializeInstNamerPass(*PassRegistry::getPassRegistry());
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 //
61 FunctionPass *llvm::createInstructionNamerPass() {
62   return new InstNamer();
63 }