InstCombine.h 2.5 KB

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