InstructionNamer.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. #include "llvm/Transforms/Scalar.h"
  17. #include "llvm/Function.h"
  18. #include "llvm/Pass.h"
  19. #include "llvm/Type.h"
  20. using namespace llvm;
  21. namespace {
  22. struct InstNamer : public FunctionPass {
  23. static char ID; // Pass identification, replacement for typeid
  24. InstNamer() : FunctionPass(ID) {}
  25. void getAnalysisUsage(AnalysisUsage &Info) const {
  26. Info.setPreservesAll();
  27. }
  28. bool runOnFunction(Function &F) {
  29. for (Function::arg_iterator AI = F.arg_begin(), AE = F.arg_end();
  30. AI != AE; ++AI)
  31. if (!AI->hasName() && !AI->getType()->isVoidTy())
  32. AI->setName("arg");
  33. for (Function::iterator BB = F.begin(), E = F.end(); BB != E; ++BB) {
  34. if (!BB->hasName())
  35. BB->setName("bb");
  36. for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I != E; ++I)
  37. if (!I->hasName() && !I->getType()->isVoidTy())
  38. I->setName("tmp");
  39. }
  40. return true;
  41. }
  42. };
  43. char InstNamer::ID = 0;
  44. INITIALIZE_PASS(InstNamer, "instnamer",
  45. "Assign names to anonymous instructions", false, false);
  46. }
  47. char &llvm::InstructionNamerID = InstNamer::ID;
  48. //===----------------------------------------------------------------------===//
  49. //
  50. // InstructionNamer - Give any unnamed non-void instructions "tmp" names.
  51. //
  52. FunctionPass *llvm::createInstructionNamerPass() {
  53. return new InstNamer();
  54. }