MachineFunctionPass.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. //===-- MachineFunctionPass.cpp -------------------------------------------===//
  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 file contains the definitions of the MachineFunctionPass members.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #include "llvm/CodeGen/MachineFunctionPass.h"
  14. #include "llvm/Analysis/AliasAnalysis.h"
  15. #include "llvm/Analysis/BasicAliasAnalysis.h"
  16. #include "llvm/Analysis/DominanceFrontier.h"
  17. #include "llvm/Analysis/GlobalsModRef.h"
  18. #include "llvm/Analysis/IVUsers.h"
  19. #include "llvm/Analysis/LoopInfo.h"
  20. #include "llvm/Analysis/MemoryDependenceAnalysis.h"
  21. #include "llvm/Analysis/ScalarEvolution.h"
  22. #include "llvm/Analysis/ScalarEvolutionAliasAnalysis.h"
  23. #include "llvm/CodeGen/MachineFunction.h"
  24. #include "llvm/CodeGen/MachineModuleInfo.h"
  25. #include "llvm/CodeGen/Passes.h"
  26. #include "llvm/CodeGen/StackProtector.h"
  27. #include "llvm/IR/Dominators.h"
  28. #include "llvm/IR/Function.h"
  29. using namespace llvm;
  30. Pass *MachineFunctionPass::createPrinterPass(raw_ostream &O,
  31. const std::string &Banner) const {
  32. return createMachineFunctionPrinterPass(O, Banner);
  33. }
  34. bool MachineFunctionPass::runOnFunction(Function &F) {
  35. // Do not codegen any 'available_externally' functions at all, they have
  36. // definitions outside the translation unit.
  37. if (F.hasAvailableExternallyLinkage()) {
  38. setExecuted(false);
  39. return false;
  40. }
  41. MachineModuleInfo &MMI = getAnalysis<MachineModuleInfo>();
  42. MachineFunction &MF = MMI.getMachineFunction(F);
  43. MachineFunctionProperties &MFProps = MF.getProperties();
  44. #ifndef NDEBUG
  45. if (!MFProps.verifyRequiredProperties(RequiredProperties)) {
  46. errs() << "MachineFunctionProperties required by " << getPassName()
  47. << " pass are not met by function " << F.getName() << ".\n"
  48. << "Required properties: ";
  49. RequiredProperties.print(errs());
  50. errs() << "\nCurrent properties: ";
  51. MFProps.print(errs());
  52. errs() << "\n";
  53. llvm_unreachable("MachineFunctionProperties check failed");
  54. }
  55. #endif
  56. bool RV = runOnMachineFunction(MF);
  57. MFProps.set(SetProperties);
  58. MFProps.reset(ClearedProperties);
  59. return RV;
  60. }
  61. void MachineFunctionPass::getAnalysisUsage(AnalysisUsage &AU) const {
  62. AU.addRequired<MachineModuleInfo>();
  63. AU.addPreserved<MachineModuleInfo>();
  64. // MachineFunctionPass preserves all LLVM IR passes, but there's no
  65. // high-level way to express this. Instead, just list a bunch of
  66. // passes explicitly. This does not include setPreservesCFG,
  67. // because CodeGen overloads that to mean preserving the MachineBasicBlock
  68. // CFG in addition to the LLVM IR CFG.
  69. AU.addPreserved<BasicAAWrapperPass>();
  70. AU.addPreserved<DominanceFrontierWrapperPass>();
  71. AU.addPreserved<DominatorTreeWrapperPass>();
  72. AU.addPreserved<AAResultsWrapperPass>();
  73. AU.addPreserved<GlobalsAAWrapperPass>();
  74. AU.addPreserved<IVUsersWrapperPass>();
  75. AU.addPreserved<LoopInfoWrapperPass>();
  76. AU.addPreserved<MemoryDependenceWrapperPass>();
  77. AU.addPreserved<ScalarEvolutionWrapperPass>();
  78. AU.addPreserved<SCEVAAWrapperPass>();
  79. AU.addPreserved<StackProtector>();
  80. FunctionPass::getAnalysisUsage(AU);
  81. }