Chris Lattner | 3793325 | 2008-08-23 06:07:02 +0000 | [diff] [blame] | 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/Transforms/Scalar.h" |
| 18 | #include "llvm/Function.h" |
| 19 | #include "llvm/Pass.h" |
| 20 | #include "llvm/Type.h" |
| 21 | using namespace llvm; |
| 22 | |
| 23 | namespace { |
| 24 | struct InstNamer : public FunctionPass { |
| 25 | static char ID; // Pass identification, replacement for typeid |
Owen Anderson | 081c34b | 2010-10-19 17:21:58 +0000 | [diff] [blame^] | 26 | InstNamer() : FunctionPass(ID) { |
| 27 | initializeInstNamerPass(*PassRegistry::getPassRegistry()); |
| 28 | } |
Chris Lattner | 3793325 | 2008-08-23 06:07:02 +0000 | [diff] [blame] | 29 | |
Devang Patel | 33e868f | 2008-11-06 01:00:16 +0000 | [diff] [blame] | 30 | void getAnalysisUsage(AnalysisUsage &Info) const { |
| 31 | Info.setPreservesAll(); |
| 32 | } |
| 33 | |
Chris Lattner | 3793325 | 2008-08-23 06:07:02 +0000 | [diff] [blame] | 34 | bool runOnFunction(Function &F) { |
Devang Patel | e0de705 | 2008-11-20 19:50:17 +0000 | [diff] [blame] | 35 | for (Function::arg_iterator AI = F.arg_begin(), AE = F.arg_end(); |
| 36 | AI != AE; ++AI) |
Benjamin Kramer | f012705 | 2010-01-05 13:12:22 +0000 | [diff] [blame] | 37 | if (!AI->hasName() && !AI->getType()->isVoidTy()) |
Dan Gohman | e02a698 | 2009-10-19 14:47:32 +0000 | [diff] [blame] | 38 | AI->setName("arg"); |
Devang Patel | e0de705 | 2008-11-20 19:50:17 +0000 | [diff] [blame] | 39 | |
Chris Lattner | 24313e7 | 2008-12-18 00:33:11 +0000 | [diff] [blame] | 40 | for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB) { |
| 41 | if (!BB->hasName()) |
Dan Gohman | e02a698 | 2009-10-19 14:47:32 +0000 | [diff] [blame] | 42 | BB->setName("bb"); |
Chris Lattner | 24313e7 | 2008-12-18 00:33:11 +0000 | [diff] [blame] | 43 | |
Chris Lattner | 3793325 | 2008-08-23 06:07:02 +0000 | [diff] [blame] | 44 | for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I) |
Benjamin Kramer | f012705 | 2010-01-05 13:12:22 +0000 | [diff] [blame] | 45 | if (!I->hasName() && !I->getType()->isVoidTy()) |
Chris Lattner | 3793325 | 2008-08-23 06:07:02 +0000 | [diff] [blame] | 46 | I->setName("tmp"); |
Chris Lattner | 24313e7 | 2008-12-18 00:33:11 +0000 | [diff] [blame] | 47 | } |
Chris Lattner | 3793325 | 2008-08-23 06:07:02 +0000 | [diff] [blame] | 48 | return true; |
| 49 | } |
| 50 | }; |
| 51 | |
| 52 | char InstNamer::ID = 0; |
Chris Lattner | 3793325 | 2008-08-23 06:07:02 +0000 | [diff] [blame] | 53 | } |
| 54 | |
Owen Anderson | 7180234 | 2010-10-07 04:13:08 +0000 | [diff] [blame] | 55 | INITIALIZE_PASS(InstNamer, "instnamer", |
Owen Anderson | ce665bd | 2010-10-07 22:25:06 +0000 | [diff] [blame] | 56 | "Assign names to anonymous instructions", false, false) |
Owen Anderson | 90c579d | 2010-08-06 18:33:48 +0000 | [diff] [blame] | 57 | char &llvm::InstructionNamerID = InstNamer::ID; |
Chris Lattner | 3793325 | 2008-08-23 06:07:02 +0000 | [diff] [blame] | 58 | //===----------------------------------------------------------------------===// |
| 59 | // |
| 60 | // InstructionNamer - Give any unnamed non-void instructions "tmp" names. |
| 61 | // |
| 62 | FunctionPass *llvm::createInstructionNamerPass() { |
| 63 | return new InstNamer(); |
| 64 | } |