AArch64GlobalISelUtils.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. //===- AArch64GlobalISelUtils.h ----------------------------------*- 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. /// \file APIs for AArch64-specific helper functions used in the GlobalISel
  9. /// pipeline.
  10. //===----------------------------------------------------------------------===//
  11. #ifndef LLVM_LIB_TARGET_AARCH64_GISEL_AARCH64GLOBALISELUTILS_H
  12. #define LLVM_LIB_TARGET_AARCH64_GISEL_AARCH64GLOBALISELUTILS_H
  13. #include "MCTargetDesc/AArch64AddressingModes.h"
  14. #include "Utils/AArch64BaseInfo.h"
  15. #include "llvm/CodeGen/GlobalISel/MachineIRBuilder.h"
  16. #include "llvm/CodeGen/GlobalISel/Utils.h"
  17. #include "llvm/CodeGen/Register.h"
  18. #include "llvm/IR/InstrTypes.h"
  19. #include <cstdint>
  20. namespace llvm {
  21. namespace AArch64GISelUtils {
  22. /// \returns true if \p C is a legal immediate operand for an arithmetic
  23. /// instruction.
  24. constexpr bool isLegalArithImmed(const uint64_t C) {
  25. return (C >> 12 == 0) || ((C & 0xFFFULL) == 0 && C >> 24 == 0);
  26. }
  27. /// \returns A value when \p MI is a vector splat of a Register or constant.
  28. /// Checks for generic opcodes and AArch64-specific generic opcodes.
  29. std::optional<RegOrConstant>
  30. getAArch64VectorSplat(const MachineInstr &MI, const MachineRegisterInfo &MRI);
  31. /// \returns A value when \p MI is a constant vector splat.
  32. /// Checks for generic opcodes and AArch64-specific generic opcodes.
  33. std::optional<int64_t>
  34. getAArch64VectorSplatScalar(const MachineInstr &MI,
  35. const MachineRegisterInfo &MRI);
  36. /// \returns true if \p MaybeSub and \p Pred are part of a CMN tree for an
  37. /// integer compare.
  38. bool isCMN(const MachineInstr *MaybeSub, const CmpInst::Predicate &Pred,
  39. const MachineRegisterInfo &MRI);
  40. /// Replace a G_MEMSET with a value of 0 with a G_BZERO instruction if it is
  41. /// supported and beneficial to do so.
  42. ///
  43. /// \note This only applies on Darwin.
  44. ///
  45. /// \returns true if \p MI was replaced with a G_BZERO.
  46. bool tryEmitBZero(MachineInstr &MI, MachineIRBuilder &MIRBuilder, bool MinSize);
  47. /// Find the AArch64 condition codes necessary to represent \p P for a scalar
  48. /// floating point comparison.
  49. ///
  50. /// \param [out] CondCode is the first condition code.
  51. /// \param [out] CondCode2 is the second condition code if necessary.
  52. /// AArch64CC::AL otherwise.
  53. void changeFCMPPredToAArch64CC(const CmpInst::Predicate P,
  54. AArch64CC::CondCode &CondCode,
  55. AArch64CC::CondCode &CondCode2);
  56. /// Find the AArch64 condition codes necessary to represent \p P for a vector
  57. /// floating point comparison.
  58. ///
  59. /// \param [out] CondCode - The first condition code.
  60. /// \param [out] CondCode2 - The second condition code if necessary.
  61. /// AArch64CC::AL otherwise.
  62. /// \param [out] Invert - True if the comparison must be inverted with a NOT.
  63. void changeVectorFCMPPredToAArch64CC(const CmpInst::Predicate P,
  64. AArch64CC::CondCode &CondCode,
  65. AArch64CC::CondCode &CondCode2,
  66. bool &Invert);
  67. } // namespace AArch64GISelUtils
  68. } // namespace llvm
  69. #endif