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
12#ifndef LLVM_LIB_TARGET_AARCH64_GISEL_AARCH64GLOBALISELUTILS_H
13#define LLVM_LIB_TARGET_AARCH64_GISEL_AARCH64GLOBALISELUTILS_H
14#include "MCTargetDesc/AArch64AddressingModes.h"
15#include "Utils/AArch64BaseInfo.h"
16#include "llvm/CodeGen/GlobalISel/MachineIRBuilder.h"
17#include "llvm/CodeGen/GlobalISel/Utils.h"
18#include "llvm/CodeGen/Register.h"
19#include "llvm/IR/InstrTypes.h"
20#include <cstdint>
21
22namespace llvm {
23
24namespace AArch64GISelUtils {
25
26/// \returns true if \p MaybeSub and \p Pred are part of a CMN tree for an
27/// integer compare.
28bool isCMN(const MachineInstr *MaybeSub, const CmpInst::Predicate &Pred,
29 const MachineRegisterInfo &MRI);
30
31/// \returns true if \p Reg is a valid immediate for a vector shift right of
32/// type \p Ty: a constant splat with 1 <= value <= element bits, stored in
33/// \p Cnt. Undef lanes (e.g. from widening odd-sized vectors) are allowed.
34bool isVShiftRImm(Register Reg, const MachineRegisterInfo &MRI, LLT Ty,
35 int64_t &Cnt);
36
37/// Replace a G_MEMSET with a value of 0 with a G_BZERO instruction if it is
38/// supported and beneficial to do so.
39///
40/// \note This only applies on Darwin.
41///
42/// \returns true if \p MI can be replaced with a G_BZERO.
43bool matchEmitBZero(const MachineInstr &MI, const MachineRegisterInfo &MRI,
44 const LibcallLoweringInfo &Libcalls, bool MinSize);
45///
46/// Replace \p MI with a G_BZERO.
47void applyEmitBZero(MachineInstr &MI, MachineIRBuilder &MIRBuilder);
48
49/// Analyze a ptrauth discriminator value to try to find the constant integer
50/// and address parts, cracking a ptrauth_blend intrinsic if there is one.
51/// \returns integer/address disc. parts, with NoRegister if no address disc.
52std::tuple<uint16_t, Register>
53extractPtrauthBlendDiscriminators(Register Disc, MachineRegisterInfo &MRI);
54
55/// Find the AArch64 condition codes necessary to represent \p P for a scalar
56/// floating point comparison.
57///
58/// \param [out] CondCode is the first condition code.
59/// \param [out] CondCode2 is the second condition code if necessary.
60/// AArch64CC::AL otherwise.
61void changeFCMPPredToAArch64CC(const CmpInst::Predicate P,
62 AArch64CC::CondCode &CondCode,
63 AArch64CC::CondCode &CondCode2);
64
65/// Find the AArch64 condition codes necessary to represent \p P for a vector
66/// floating point comparison.
67///
68/// \param [out] CondCode - The first condition code.
69/// \param [out] CondCode2 - The second condition code if necessary.
70/// AArch64CC::AL otherwise.
71/// \param [out] Invert - True if the comparison must be inverted with a NOT.
72void changeVectorFCMPPredToAArch64CC(const CmpInst::Predicate P,
73 AArch64CC::CondCode &CondCode,
74 AArch64CC::CondCode &CondCode2,
75 bool &Invert);
76
77} // namespace AArch64GISelUtils
78} // namespace llvm
79
80#endif
81