ConstantFold.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //==-- ConstantFold.h - DL-independent Constant Folding Interface -*- 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 the DataLayout-independent constant folding interface.
  15. // When possible, the DataLayout-aware constant folding interface in
  16. // Analysis/ConstantFolding.h should be preferred.
  17. //
  18. // These interfaces are used by the ConstantExpr::get* methods to automatically
  19. // fold constants when possible.
  20. //
  21. // These operators may return a null object if they don't know how to perform
  22. // the specified operation on the specified constant types.
  23. //
  24. //===----------------------------------------------------------------------===//
  25. #ifndef LLVM_IR_CONSTANTFOLD_H
  26. #define LLVM_IR_CONSTANTFOLD_H
  27. #include "llvm/IR/InstrTypes.h"
  28. #include <optional>
  29. namespace llvm {
  30. template <typename T> class ArrayRef;
  31. class Value;
  32. class Constant;
  33. class Type;
  34. // Constant fold various types of instruction...
  35. Constant *ConstantFoldCastInstruction(
  36. unsigned opcode, ///< The opcode of the cast
  37. Constant *V, ///< The source constant
  38. Type *DestTy ///< The destination type
  39. );
  40. Constant *ConstantFoldSelectInstruction(Constant *Cond,
  41. Constant *V1, Constant *V2);
  42. Constant *ConstantFoldExtractElementInstruction(Constant *Val, Constant *Idx);
  43. Constant *ConstantFoldInsertElementInstruction(Constant *Val, Constant *Elt,
  44. Constant *Idx);
  45. Constant *ConstantFoldShuffleVectorInstruction(Constant *V1, Constant *V2,
  46. ArrayRef<int> Mask);
  47. Constant *ConstantFoldExtractValueInstruction(Constant *Agg,
  48. ArrayRef<unsigned> Idxs);
  49. Constant *ConstantFoldInsertValueInstruction(Constant *Agg, Constant *Val,
  50. ArrayRef<unsigned> Idxs);
  51. Constant *ConstantFoldUnaryInstruction(unsigned Opcode, Constant *V);
  52. Constant *ConstantFoldBinaryInstruction(unsigned Opcode, Constant *V1,
  53. Constant *V2);
  54. Constant *ConstantFoldCompareInstruction(CmpInst::Predicate Predicate,
  55. Constant *C1, Constant *C2);
  56. Constant *ConstantFoldGetElementPtr(Type *Ty, Constant *C, bool InBounds,
  57. std::optional<unsigned> InRangeIndex,
  58. ArrayRef<Value *> Idxs);
  59. } // End llvm namespace
  60. #endif
  61. #ifdef __GNUC__
  62. #pragma GCC diagnostic pop
  63. #endif