ReplaceConstant.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- ReplaceConstant.h - Replacing LLVM constant expressions --*- 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 declares the utility function for replacing LLVM constant
  15. // expressions by instructions.
  16. //
  17. //===----------------------------------------------------------------------===//
  18. #ifndef LLVM_IR_REPLACECONSTANT_H
  19. #define LLVM_IR_REPLACECONSTANT_H
  20. #include <map>
  21. #include <vector>
  22. namespace llvm {
  23. class ConstantExpr;
  24. class Instruction;
  25. class Use;
  26. template <typename PtrType> class SmallPtrSetImpl;
  27. /// The given instruction \p I contains given constant expression \p CE as one
  28. /// of its operands, possibly nested within constant expression trees. Convert
  29. /// all reachable paths from contant expression operands of \p I to \p CE into
  30. /// corresponding instructions, insert them before \p I, update operands of \p I
  31. /// accordingly, and if required, return all such converted instructions at
  32. /// \p Insts.
  33. void convertConstantExprsToInstructions(
  34. Instruction *I, ConstantExpr *CE,
  35. SmallPtrSetImpl<Instruction *> *Insts = nullptr);
  36. /// The given instruction \p I contains constant expression CE within the
  37. /// constant expression trees of it`s constant expression operands, and
  38. /// \p CEPaths holds all the reachable paths (to CE) from such constant
  39. /// expression trees of \p I. Convert constant expressions within these paths
  40. /// into corresponding instructions, insert them before \p I, update operands of
  41. /// \p I accordingly, and if required, return all such converted instructions at
  42. /// \p Insts.
  43. void convertConstantExprsToInstructions(
  44. Instruction *I,
  45. std::map<Use *, std::vector<std::vector<ConstantExpr *>>> &CEPaths,
  46. SmallPtrSetImpl<Instruction *> *Insts = nullptr);
  47. /// Given an instruction \p I which uses given constant expression \p CE as
  48. /// operand, either directly or nested within other constant expressions, return
  49. /// all reachable paths from the constant expression operands of \p I to \p CE,
  50. /// and return collected paths at \p CEPaths.
  51. void collectConstantExprPaths(
  52. Instruction *I, ConstantExpr *CE,
  53. std::map<Use *, std::vector<std::vector<ConstantExpr *>>> &CEPaths);
  54. } // end namespace llvm
  55. #endif // LLVM_IR_REPLACECONSTANT_H
  56. #ifdef __GNUC__
  57. #pragma GCC diagnostic pop
  58. #endif