IRBuilderFolder.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- IRBuilderFolder.h - Const folder interface for IRBuilder -*- 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 for constant folding interface used by IRBuilder.
  15. // It is implemented by ConstantFolder (default), TargetFolder and NoFoler.
  16. //
  17. //===----------------------------------------------------------------------===//
  18. #ifndef LLVM_IR_IRBUILDERFOLDER_H
  19. #define LLVM_IR_IRBUILDERFOLDER_H
  20. #include "llvm/ADT/ArrayRef.h"
  21. #include "llvm/IR/InstrTypes.h"
  22. #include "llvm/IR/Instruction.h"
  23. namespace llvm {
  24. /// IRBuilderFolder - Interface for constant folding in IRBuilder.
  25. class IRBuilderFolder {
  26. public:
  27. virtual ~IRBuilderFolder();
  28. //===--------------------------------------------------------------------===//
  29. // Value-based folders.
  30. //
  31. // Return an existing value or a constant if the operation can be simplified.
  32. // Otherwise return nullptr.
  33. //===--------------------------------------------------------------------===//
  34. virtual Value *FoldBinOp(Instruction::BinaryOps Opc, Value *LHS,
  35. Value *RHS) const = 0;
  36. virtual Value *FoldExactBinOp(Instruction::BinaryOps Opc, Value *LHS,
  37. Value *RHS, bool IsExact) const = 0;
  38. virtual Value *FoldNoWrapBinOp(Instruction::BinaryOps Opc, Value *LHS,
  39. Value *RHS, bool HasNUW,
  40. bool HasNSW) const = 0;
  41. virtual Value *FoldBinOpFMF(Instruction::BinaryOps Opc, Value *LHS,
  42. Value *RHS, FastMathFlags FMF) const = 0;
  43. virtual Value *FoldUnOpFMF(Instruction::UnaryOps Opc, Value *V,
  44. FastMathFlags FMF) const = 0;
  45. virtual Value *FoldICmp(CmpInst::Predicate P, Value *LHS,
  46. Value *RHS) const = 0;
  47. virtual Value *FoldGEP(Type *Ty, Value *Ptr, ArrayRef<Value *> IdxList,
  48. bool IsInBounds = false) const = 0;
  49. virtual Value *FoldSelect(Value *C, Value *True, Value *False) const = 0;
  50. virtual Value *FoldExtractValue(Value *Agg,
  51. ArrayRef<unsigned> IdxList) const = 0;
  52. virtual Value *FoldInsertValue(Value *Agg, Value *Val,
  53. ArrayRef<unsigned> IdxList) const = 0;
  54. virtual Value *FoldExtractElement(Value *Vec, Value *Idx) const = 0;
  55. virtual Value *FoldInsertElement(Value *Vec, Value *NewElt,
  56. Value *Idx) const = 0;
  57. virtual Value *FoldShuffleVector(Value *V1, Value *V2,
  58. ArrayRef<int> Mask) const = 0;
  59. //===--------------------------------------------------------------------===//
  60. // Cast/Conversion Operators
  61. //===--------------------------------------------------------------------===//
  62. virtual Value *CreateCast(Instruction::CastOps Op, Constant *C,
  63. Type *DestTy) const = 0;
  64. virtual Value *CreatePointerCast(Constant *C, Type *DestTy) const = 0;
  65. virtual Value *CreatePointerBitCastOrAddrSpaceCast(Constant *C,
  66. Type *DestTy) const = 0;
  67. virtual Value *CreateIntCast(Constant *C, Type *DestTy,
  68. bool isSigned) const = 0;
  69. virtual Value *CreateFPCast(Constant *C, Type *DestTy) const = 0;
  70. virtual Value *CreateBitCast(Constant *C, Type *DestTy) const = 0;
  71. virtual Value *CreateIntToPtr(Constant *C, Type *DestTy) const = 0;
  72. virtual Value *CreatePtrToInt(Constant *C, Type *DestTy) const = 0;
  73. virtual Value *CreateZExtOrBitCast(Constant *C, Type *DestTy) const = 0;
  74. virtual Value *CreateSExtOrBitCast(Constant *C, Type *DestTy) const = 0;
  75. virtual Value *CreateTruncOrBitCast(Constant *C, Type *DestTy) const = 0;
  76. //===--------------------------------------------------------------------===//
  77. // Compare Instructions
  78. //===--------------------------------------------------------------------===//
  79. virtual Value *CreateFCmp(CmpInst::Predicate P, Constant *LHS,
  80. Constant *RHS) const = 0;
  81. };
  82. } // end namespace llvm
  83. #endif // LLVM_IR_IRBUILDERFOLDER_H
  84. #ifdef __GNUC__
  85. #pragma GCC diagnostic pop
  86. #endif