ConstantFold.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. //===-- ConstantFolding.h - Internal Constant Folding Interface -*- C++ -*-===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // This file defines the (internal) constant folding interfaces for LLVM. These
  10. // interfaces are used by the ConstantExpr::get* methods to automatically fold
  11. // constants when possible.
  12. //
  13. // These operators may return a null object if they don't know how to perform
  14. // the specified operation on the specified constant types.
  15. //
  16. //===----------------------------------------------------------------------===//
  17. #ifndef LLVM_LIB_IR_CONSTANTFOLD_H
  18. #define LLVM_LIB_IR_CONSTANTFOLD_H
  19. #include "llvm/ADT/Optional.h"
  20. #include "llvm/IR/InstrTypes.h"
  21. namespace llvm {
  22. template <typename T> class ArrayRef;
  23. class Value;
  24. class Constant;
  25. class Type;
  26. // Constant fold various types of instruction...
  27. Constant *ConstantFoldCastInstruction(
  28. unsigned opcode, ///< The opcode of the cast
  29. Constant *V, ///< The source constant
  30. Type *DestTy ///< The destination type
  31. );
  32. Constant *ConstantFoldSelectInstruction(Constant *Cond,
  33. Constant *V1, Constant *V2);
  34. Constant *ConstantFoldExtractElementInstruction(Constant *Val, Constant *Idx);
  35. Constant *ConstantFoldInsertElementInstruction(Constant *Val, Constant *Elt,
  36. Constant *Idx);
  37. Constant *ConstantFoldShuffleVectorInstruction(Constant *V1, Constant *V2,
  38. ArrayRef<int> Mask);
  39. Constant *ConstantFoldExtractValueInstruction(Constant *Agg,
  40. ArrayRef<unsigned> Idxs);
  41. Constant *ConstantFoldInsertValueInstruction(Constant *Agg, Constant *Val,
  42. ArrayRef<unsigned> Idxs);
  43. Constant *ConstantFoldUnaryInstruction(unsigned Opcode, Constant *V);
  44. Constant *ConstantFoldBinaryInstruction(unsigned Opcode, Constant *V1,
  45. Constant *V2);
  46. Constant *ConstantFoldCompareInstruction(CmpInst::Predicate Predicate,
  47. Constant *C1, Constant *C2);
  48. Constant *ConstantFoldGetElementPtr(Type *Ty, Constant *C, bool InBounds,
  49. Optional<unsigned> InRangeIndex,
  50. ArrayRef<Value *> Idxs);
  51. } // End llvm namespace
  52. #endif