LLVM API Documentation
00001 //===- InstructionNamer.cpp - Give anonymous instructions names -----------===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This is a little utility pass that gives instructions names, this is mostly 00011 // useful when diffing the effect of an optimization because deleting an 00012 // unnamed instruction can change all other instruction numbering, making the 00013 // diff very noisy. 00014 // 00015 //===----------------------------------------------------------------------===// 00016 00017 #include "llvm/Transforms/Scalar.h" 00018 #include "llvm/Function.h" 00019 #include "llvm/Pass.h" 00020 #include "llvm/Type.h" 00021 using namespace llvm; 00022 00023 namespace { 00024 struct InstNamer : public FunctionPass { 00025 static char ID; // Pass identification, replacement for typeid 00026 InstNamer() : FunctionPass(&ID) {} 00027 00028 void getAnalysisUsage(AnalysisUsage &Info) const { 00029 Info.setPreservesAll(); 00030 } 00031 00032 bool runOnFunction(Function &F) { 00033 for (Function::arg_iterator AI = F.arg_begin(), AE = F.arg_end(); 00034 AI != AE; ++AI) 00035 if (!AI->hasName() && AI->getType() != Type::VoidTy) 00036 AI->setName("tmp"); 00037 00038 for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB) { 00039 if (!BB->hasName()) 00040 BB->setName("BB"); 00041 00042 for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I) 00043 if (!I->hasName() && I->getType() != Type::VoidTy) 00044 I->setName("tmp"); 00045 } 00046 return true; 00047 } 00048 }; 00049 00050 char InstNamer::ID = 0; 00051 static RegisterPass<InstNamer> X("instnamer", 00052 "Assign names to anonymous instructions"); 00053 } 00054 00055 00056 const PassInfo *const llvm::InstructionNamerID = &X; 00057 //===----------------------------------------------------------------------===// 00058 // 00059 // InstructionNamer - Give any unnamed non-void instructions "tmp" names. 00060 // 00061 FunctionPass *llvm::createInstructionNamerPass() { 00062 return new InstNamer(); 00063 }