ConstantFold.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. namespace llvm {
  21. template <typename T> class ArrayRef;
  22. class Value;
  23. class Constant;
  24. class Type;
  25. // Constant fold various types of instruction...
  26. Constant *ConstantFoldCastInstruction(
  27. unsigned opcode, ///< The opcode of the cast
  28. Constant *V, ///< The source constant
  29. Type *DestTy ///< The destination type
  30. );
  31. Constant *ConstantFoldSelectInstruction(Constant *Cond,
  32. Constant *V1, Constant *V2);
  33. Constant *ConstantFoldExtractElementInstruction(Constant *Val, Constant *Idx);
  34. Constant *ConstantFoldInsertElementInstruction(Constant *Val, Constant *Elt,
  35. Constant *Idx);
  36. Constant *ConstantFoldShuffleVectorInstruction(Constant *V1, Constant *V2,
  37. ArrayRef<int> Mask);
  38. Constant *ConstantFoldExtractValueInstruction(Constant *Agg,
  39. ArrayRef<unsigned> Idxs);
  40. Constant *ConstantFoldInsertValueInstruction(Constant *Agg, Constant *Val,
  41. ArrayRef<unsigned> Idxs);
  42. Constant *ConstantFoldUnaryInstruction(unsigned Opcode, Constant *V);
  43. Constant *ConstantFoldBinaryInstruction(unsigned Opcode, Constant *V1,
  44. Constant *V2);
  45. Constant *ConstantFoldCompareInstruction(unsigned short predicate,
  46. Constant *C1, Constant *C2);
  47. Constant *ConstantFoldGetElementPtr(Type *Ty, Constant *C, bool InBounds,
  48. Optional<unsigned> InRangeIndex,
  49. ArrayRef<Value *> Idxs);
  50. } // End llvm namespace
  51. #endif