/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/lib/Transforms/Utils/InstructionNamer.cpp
Line | Count | Source (jump to first uncovered line) |
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 | | |
16 | | #include "llvm/IR/Function.h" |
17 | | #include "llvm/IR/Type.h" |
18 | | #include "llvm/Pass.h" |
19 | | #include "llvm/Transforms/Utils.h" |
20 | | using namespace llvm; |
21 | | |
22 | | namespace { |
23 | | struct InstNamer : public FunctionPass { |
24 | | static char ID; // Pass identification, replacement for typeid |
25 | 25 | InstNamer() : FunctionPass(ID) { |
26 | 25 | initializeInstNamerPass(*PassRegistry::getPassRegistry()); |
27 | 25 | } |
28 | | |
29 | 25 | void getAnalysisUsage(AnalysisUsage &Info) const override { |
30 | 25 | Info.setPreservesAll(); |
31 | 25 | } |
32 | | |
33 | 208 | bool runOnFunction(Function &F) override { |
34 | 208 | for (auto &Arg : F.args()) |
35 | 247 | if (!Arg.hasName()) |
36 | 14 | Arg.setName("arg"); |
37 | 208 | |
38 | 941 | for (BasicBlock &BB : F) { |
39 | 941 | if (!BB.hasName()) |
40 | 2 | BB.setName("bb"); |
41 | 941 | |
42 | 941 | for (Instruction &I : BB) |
43 | 4.45k | if (!I.hasName() && !I.getType()->isVoidTy()3.65k ) |
44 | 1.72k | I.setName("tmp"); |
45 | 941 | } |
46 | 208 | return true; |
47 | 208 | } |
48 | | }; |
49 | | |
50 | | char InstNamer::ID = 0; |
51 | | } |
52 | | |
53 | | INITIALIZE_PASS(InstNamer, "instnamer", |
54 | | "Assign names to anonymous instructions", false, false) |
55 | | char &llvm::InstructionNamerID = InstNamer::ID; |
56 | | //===----------------------------------------------------------------------===// |
57 | | // |
58 | | // InstructionNamer - Give any unnamed non-void instructions "tmp" names. |
59 | | // |
60 | 0 | FunctionPass *llvm::createInstructionNamerPass() { |
61 | 0 | return new InstNamer(); |
62 | 0 | } |