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/IR/Function.h" 00019 #include "llvm/IR/Type.h" 00020 #include "llvm/Pass.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 initializeInstNamerPass(*PassRegistry::getPassRegistry()); 00028 } 00029 00030 void getAnalysisUsage(AnalysisUsage &Info) const override { 00031 Info.setPreservesAll(); 00032 } 00033 00034 bool runOnFunction(Function &F) override { 00035 for (Function::arg_iterator AI = F.arg_begin(), AE = F.arg_end(); 00036 AI != AE; ++AI) 00037 if (!AI->hasName() && !AI->getType()->isVoidTy()) 00038 AI->setName("arg"); 00039 00040 for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB) { 00041 if (!BB->hasName()) 00042 BB->setName("bb"); 00043 00044 for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I) 00045 if (!I->hasName() && !I->getType()->isVoidTy()) 00046 I->setName("tmp"); 00047 } 00048 return true; 00049 } 00050 }; 00051 00052 char InstNamer::ID = 0; 00053 } 00054 00055 INITIALIZE_PASS(InstNamer, "instnamer", 00056 "Assign names to anonymous instructions", false, false) 00057 char &llvm::InstructionNamerID = InstNamer::ID; 00058 //===----------------------------------------------------------------------===// 00059 // 00060 // InstructionNamer - Give any unnamed non-void instructions "tmp" names. 00061 // 00062 FunctionPass *llvm::createInstructionNamerPass() { 00063 return new InstNamer(); 00064 }