Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

102 lines
4.8 KiB

  1. //===-- ConstantFolding.h - Fold instructions into constants --------------===//
  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 declares routines for folding instructions into constants when all
  11. // operands are constants, for example "sub i32 1, 0" -> "1".
  12. //
  13. // Also, to supplement the basic VMCore ConstantExpr simplifications,
  14. // this file declares some additional folding routines that can make use of
  15. // DataLayout information. These functions cannot go in VMCore due to library
  16. // dependency issues.
  17. //
  18. //===----------------------------------------------------------------------===//
  19. #ifndef LLVM_ANALYSIS_CONSTANTFOLDING_H
  20. #define LLVM_ANALYSIS_CONSTANTFOLDING_H
  21. namespace llvm {
  22. class Constant;
  23. class ConstantExpr;
  24. class Instruction;
  25. class DataLayout;
  26. class TargetLibraryInfo;
  27. class Function;
  28. class Type;
  29. template<typename T>
  30. class ArrayRef;
  31. /// ConstantFoldInstruction - Try to constant fold the specified instruction.
  32. /// If successful, the constant result is returned, if not, null is returned.
  33. /// Note that this fails if not all of the operands are constant. Otherwise,
  34. /// this function can only fail when attempting to fold instructions like loads
  35. /// and stores, which have no constant expression form.
  36. Constant *ConstantFoldInstruction(Instruction *I, const DataLayout *TD = 0,
  37. const TargetLibraryInfo *TLI = 0);
  38. /// ConstantFoldConstantExpression - Attempt to fold the constant expression
  39. /// using the specified DataLayout. If successful, the constant result is
  40. /// result is returned, if not, null is returned.
  41. Constant *ConstantFoldConstantExpression(const ConstantExpr *CE,
  42. const DataLayout *TD = 0,
  43. const TargetLibraryInfo *TLI = 0);
  44. /// ConstantFoldInstOperands - Attempt to constant fold an instruction with the
  45. /// specified operands. If successful, the constant result is returned, if not,
  46. /// null is returned. Note that this function can fail when attempting to
  47. /// fold instructions like loads and stores, which have no constant expression
  48. /// form.
  49. ///
  50. Constant *ConstantFoldInstOperands(unsigned Opcode, Type *DestTy,
  51. ArrayRef<Constant *> Ops,
  52. const DataLayout *TD = 0,
  53. const TargetLibraryInfo *TLI = 0);
  54. /// ConstantFoldCompareInstOperands - Attempt to constant fold a compare
  55. /// instruction (icmp/fcmp) with the specified operands. If it fails, it
  56. /// returns a constant expression of the specified operands.
  57. ///
  58. Constant *ConstantFoldCompareInstOperands(unsigned Predicate,
  59. Constant *LHS, Constant *RHS,
  60. const DataLayout *TD = 0,
  61. const TargetLibraryInfo *TLI = 0);
  62. /// ConstantFoldInsertValueInstruction - Attempt to constant fold an insertvalue
  63. /// instruction with the specified operands and indices. The constant result is
  64. /// returned if successful; if not, null is returned.
  65. Constant *ConstantFoldInsertValueInstruction(Constant *Agg, Constant *Val,
  66. ArrayRef<unsigned> Idxs);
  67. /// ConstantFoldLoadFromConstPtr - Return the value that a load from C would
  68. /// produce if it is constant and determinable. If this is not determinable,
  69. /// return null.
  70. Constant *ConstantFoldLoadFromConstPtr(Constant *C, const DataLayout *TD = 0);
  71. /// ConstantFoldLoadThroughGEPConstantExpr - Given a constant and a
  72. /// getelementptr constantexpr, return the constant value being addressed by the
  73. /// constant expression, or null if something is funny and we can't decide.
  74. Constant *ConstantFoldLoadThroughGEPConstantExpr(Constant *C, ConstantExpr *CE);
  75. /// ConstantFoldLoadThroughGEPIndices - Given a constant and getelementptr
  76. /// indices (with an *implied* zero pointer index that is not in the list),
  77. /// return the constant value being addressed by a virtual load, or null if
  78. /// something is funny and we can't decide.
  79. Constant *ConstantFoldLoadThroughGEPIndices(Constant *C,
  80. ArrayRef<Constant*> Indices);
  81. /// canConstantFoldCallTo - Return true if its even possible to fold a call to
  82. /// the specified function.
  83. bool canConstantFoldCallTo(const Function *F);
  84. /// ConstantFoldCall - Attempt to constant fold a call to the specified function
  85. /// with the specified arguments, returning null if unsuccessful.
  86. Constant *ConstantFoldCall(Function *F, ArrayRef<Constant *> Operands,
  87. const TargetLibraryInfo *TLI = 0);
  88. }
  89. #endif