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 |
| 26 | InstNamer() : FunctionPass(&ID) {} |
| 27 | |
| 28 | bool runOnFunction(Function &F) { |
| 29 | for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB) |
| 30 | for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I) |
| 31 | if (!I->hasName() && I->getType() != Type::VoidTy) |
| 32 | I->setName("tmp"); |
| 33 | return true; |
| 34 | } |
| 35 | }; |
| 36 | |
| 37 | char InstNamer::ID = 0; |
| 38 | static RegisterPass<InstNamer> X("instnamer", |
| 39 | "Assign names to anonymous instructions"); |
| 40 | } |
| 41 | |
| 42 | |
| 43 | //===----------------------------------------------------------------------===// |
| 44 | // |
| 45 | // InstructionNamer - Give any unnamed non-void instructions "tmp" names. |
| 46 | // |
| 47 | FunctionPass *llvm::createInstructionNamerPass() { |
| 48 | return new InstNamer(); |
| 49 | } |