MachineFunctionPass.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===-- MachineFunctionPass.h - Pass for MachineFunctions --------*-C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // This file defines the MachineFunctionPass class. MachineFunctionPass's are
  15. // just FunctionPass's, except they operate on machine code as part of a code
  16. // generator. Because they operate on machine code, not the LLVM
  17. // representation, MachineFunctionPass's are not allowed to modify the LLVM
  18. // representation. Due to this limitation, the MachineFunctionPass class takes
  19. // care of declaring that no LLVM passes are invalidated.
  20. //
  21. //===----------------------------------------------------------------------===//
  22. #ifndef LLVM_CODEGEN_MACHINEFUNCTIONPASS_H
  23. #define LLVM_CODEGEN_MACHINEFUNCTIONPASS_H
  24. #include "llvm/CodeGen/MachineFunction.h"
  25. #include "llvm/Pass.h"
  26. namespace llvm {
  27. /// MachineFunctionPass - This class adapts the FunctionPass interface to
  28. /// allow convenient creation of passes that operate on the MachineFunction
  29. /// representation. Instead of overriding runOnFunction, subclasses
  30. /// override runOnMachineFunction.
  31. class MachineFunctionPass : public FunctionPass {
  32. public:
  33. bool doInitialization(Module&) override {
  34. // Cache the properties info at module-init time so we don't have to
  35. // construct them for every function.
  36. RequiredProperties = getRequiredProperties();
  37. SetProperties = getSetProperties();
  38. ClearedProperties = getClearedProperties();
  39. return false;
  40. }
  41. protected:
  42. explicit MachineFunctionPass(char &ID) : FunctionPass(ID) {}
  43. /// runOnMachineFunction - This method must be overloaded to perform the
  44. /// desired machine code transformation or analysis.
  45. ///
  46. virtual bool runOnMachineFunction(MachineFunction &MF) = 0;
  47. /// getAnalysisUsage - Subclasses that override getAnalysisUsage
  48. /// must call this.
  49. ///
  50. /// For MachineFunctionPasses, calling AU.preservesCFG() indicates that
  51. /// the pass does not modify the MachineBasicBlock CFG.
  52. ///
  53. void getAnalysisUsage(AnalysisUsage &AU) const override;
  54. virtual MachineFunctionProperties getRequiredProperties() const {
  55. return MachineFunctionProperties();
  56. }
  57. virtual MachineFunctionProperties getSetProperties() const {
  58. return MachineFunctionProperties();
  59. }
  60. virtual MachineFunctionProperties getClearedProperties() const {
  61. return MachineFunctionProperties();
  62. }
  63. private:
  64. MachineFunctionProperties RequiredProperties;
  65. MachineFunctionProperties SetProperties;
  66. MachineFunctionProperties ClearedProperties;
  67. /// createPrinterPass - Get a machine function printer pass.
  68. Pass *createPrinterPass(raw_ostream &O,
  69. const std::string &Banner) const override;
  70. bool runOnFunction(Function &F) override;
  71. };
  72. } // End llvm namespace
  73. #endif
  74. #ifdef __GNUC__
  75. #pragma GCC diagnostic pop
  76. #endif