1//==-- llvm/CodeGen/GlobalISel/Utils.h ---------------------------*- C++ -*-==//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10/// \file This file declares the API of helper functions used throughout the
11/// GlobalISel pipeline.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_CODEGEN_GLOBALISEL_UTILS_H
16#define LLVM_CODEGEN_GLOBALISEL_UTILS_H
17
18#include "llvm/ADT/StringRef.h"
19
20namespace llvm {
21
22class MachineFunction;
23class MachineInstr;
24class MachineOptimizationRemarkEmitter;
25class MachineOptimizationRemarkMissed;
26class MachineRegisterInfo;
27class MCInstrDesc;
28class RegisterBankInfo;
29class TargetInstrInfo;
30class TargetPassConfig;
31class TargetRegisterInfo;
32class Twine;
33class ConstantFP;
34
35/// Try to constrain Reg so that it is usable by argument OpIdx of the
36/// provided MCInstrDesc \p II. If this fails, create a new virtual
37/// register in the correct class and insert a COPY before \p InsertPt.
38/// The debug location of \p InsertPt is used for the new copy.
39///
40/// \return The virtual register constrained to the right register class.
41unsigned constrainOperandRegClass(const MachineFunction &MF,
42                                  const TargetRegisterInfo &TRI,
43                                  MachineRegisterInfo &MRI,
44                                  const TargetInstrInfo &TII,
45                                  const RegisterBankInfo &RBI,
46                                  MachineInstr &InsertPt, const MCInstrDesc &II,
47                                  unsigned Reg, unsigned OpIdx);
48
49/// Check whether an instruction \p MI is dead: it only defines dead virtual
50/// registers, and doesn't have other side effects.
51bool isTriviallyDead(const MachineInstr &MI, const MachineRegisterInfo &MRI);
52
53/// Report an ISel error as a missed optimization remark to the LLVMContext's
54/// diagnostic stream.  Set the FailedISel MachineFunction property.
55void reportGISelFailure(MachineFunction &MF, const TargetPassConfig &TPC,
56                        MachineOptimizationRemarkEmitter &MORE,
57                        MachineOptimizationRemarkMissed &R);
58
59void reportGISelFailure(MachineFunction &MF, const TargetPassConfig &TPC,
60                        MachineOptimizationRemarkEmitter &MORE,
61                        const char *PassName, StringRef Msg,
62                        const MachineInstr &MI);
63
64Optional<int64_t> getConstantVRegVal(unsigned VReg,
65                                     const MachineRegisterInfo &MRI);
66const ConstantFP* getConstantFPVRegVal(unsigned VReg,
67                                       const MachineRegisterInfo &MRI);
68
69} // End namespace llvm.
70#endif
71