MachineFunctionPass.cpp 3.2 KB

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