InstCombine.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- InstCombine.h - InstCombine pass -------------------------*- 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. /// \file
  14. ///
  15. /// This file provides the primary interface to the instcombine pass. This pass
  16. /// is suitable for use in the new pass manager. For a pass that works with the
  17. /// legacy pass manager, use \c createInstructionCombiningPass().
  18. ///
  19. //===----------------------------------------------------------------------===//
  20. #ifndef LLVM_TRANSFORMS_INSTCOMBINE_INSTCOMBINE_H
  21. #define LLVM_TRANSFORMS_INSTCOMBINE_INSTCOMBINE_H
  22. #include "llvm/IR/Function.h"
  23. #include "llvm/IR/PassManager.h"
  24. #define DEBUG_TYPE "instcombine"
  25. #include "llvm/Transforms/Utils/InstructionWorklist.h"
  26. namespace llvm {
  27. class InstCombinePass : public PassInfoMixin<InstCombinePass> {
  28. InstructionWorklist Worklist;
  29. const unsigned MaxIterations;
  30. public:
  31. explicit InstCombinePass();
  32. explicit InstCombinePass(unsigned MaxIterations);
  33. PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
  34. };
  35. /// The legacy pass manager's instcombine pass.
  36. ///
  37. /// This is a basic whole-function wrapper around the instcombine utility. It
  38. /// will try to combine all instructions in the function.
  39. class InstructionCombiningPass : public FunctionPass {
  40. InstructionWorklist Worklist;
  41. const unsigned MaxIterations;
  42. public:
  43. static char ID; // Pass identification, replacement for typeid
  44. explicit InstructionCombiningPass();
  45. explicit InstructionCombiningPass(unsigned MaxIterations);
  46. void getAnalysisUsage(AnalysisUsage &AU) const override;
  47. bool runOnFunction(Function &F) override;
  48. };
  49. //===----------------------------------------------------------------------===//
  50. //
  51. // InstructionCombining - Combine instructions to form fewer, simple
  52. // instructions. This pass does not modify the CFG, and has a tendency to make
  53. // instructions dead, so a subsequent DCE pass is useful.
  54. //
  55. // This pass combines things like:
  56. // %Y = add int 1, %X
  57. // %Z = add int 1, %Y
  58. // into:
  59. // %Z = add int 2, %X
  60. //
  61. FunctionPass *createInstructionCombiningPass();
  62. FunctionPass *createInstructionCombiningPass(unsigned MaxIterations);
  63. }
  64. #undef DEBUG_TYPE
  65. #endif
  66. #ifdef __GNUC__
  67. #pragma GCC diagnostic pop
  68. #endif