LLVM  8.0.1
Utils.h
Go to the documentation of this file.
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 
20 namespace llvm {
21 
22 class AnalysisUsage;
23 class MachineFunction;
24 class MachineInstr;
25 class MachineOperand;
26 class MachineOptimizationRemarkEmitter;
27 class MachineOptimizationRemarkMissed;
28 class MachineRegisterInfo;
29 class MCInstrDesc;
30 class RegisterBankInfo;
31 class TargetInstrInfo;
32 class TargetPassConfig;
33 class TargetRegisterInfo;
34 class TargetRegisterClass;
35 class Twine;
36 class ConstantFP;
37 class APFloat;
38 
39 /// Try to constrain Reg to the specified register class. If this fails,
40 /// create a new virtual register in the correct class and insert a COPY before
41 /// \p InsertPt. The debug location of \p InsertPt is used for the new copy.
42 ///
43 /// \return The virtual register constrained to the right register class.
44 unsigned constrainRegToClass(MachineRegisterInfo &MRI,
45  const TargetInstrInfo &TII,
46  const RegisterBankInfo &RBI,
47  MachineInstr &InsertPt, unsigned Reg,
48  const TargetRegisterClass &RegClass);
49 
50 /// Try to constrain Reg so that it is usable by argument OpIdx of the
51 /// provided MCInstrDesc \p II. If this fails, create a new virtual
52 /// register in the correct class and insert a COPY before \p InsertPt.
53 /// This is equivalent to constrainRegToClass() with RegClass obtained from the
54 /// MCInstrDesc. The debug location of \p InsertPt is used for the new copy.
55 ///
56 /// \return The virtual register constrained to the right register class.
57 unsigned constrainOperandRegClass(const MachineFunction &MF,
58  const TargetRegisterInfo &TRI,
59  MachineRegisterInfo &MRI,
60  const TargetInstrInfo &TII,
61  const RegisterBankInfo &RBI,
62  MachineInstr &InsertPt, const MCInstrDesc &II,
63  const MachineOperand &RegMO, unsigned OpIdx);
64 
65 /// Mutate the newly-selected instruction \p I to constrain its (possibly
66 /// generic) virtual register operands to the instruction's register class.
67 /// This could involve inserting COPYs before (for uses) or after (for defs).
68 /// This requires the number of operands to match the instruction description.
69 /// \returns whether operand regclass constraining succeeded.
70 ///
71 // FIXME: Not all instructions have the same number of operands. We should
72 // probably expose a constrain helper per operand and let the target selector
73 // constrain individual registers, like fast-isel.
74 bool constrainSelectedInstRegOperands(MachineInstr &I,
75  const TargetInstrInfo &TII,
76  const TargetRegisterInfo &TRI,
77  const RegisterBankInfo &RBI);
78 /// Check whether an instruction \p MI is dead: it only defines dead virtual
79 /// registers, and doesn't have other side effects.
80 bool isTriviallyDead(const MachineInstr &MI, const MachineRegisterInfo &MRI);
81 
82 /// Report an ISel error as a missed optimization remark to the LLVMContext's
83 /// diagnostic stream. Set the FailedISel MachineFunction property.
84 void reportGISelFailure(MachineFunction &MF, const TargetPassConfig &TPC,
85  MachineOptimizationRemarkEmitter &MORE,
86  MachineOptimizationRemarkMissed &R);
87 
88 void reportGISelFailure(MachineFunction &MF, const TargetPassConfig &TPC,
89  MachineOptimizationRemarkEmitter &MORE,
90  const char *PassName, StringRef Msg,
91  const MachineInstr &MI);
92 
93 Optional<int64_t> getConstantVRegVal(unsigned VReg,
94  const MachineRegisterInfo &MRI);
95 const ConstantFP* getConstantFPVRegVal(unsigned VReg,
96  const MachineRegisterInfo &MRI);
97 
98 /// See if Reg is defined by an single def instruction that is
99 /// Opcode. Also try to do trivial folding if it's a COPY with
100 /// same types. Returns null otherwise.
101 MachineInstr *getOpcodeDef(unsigned Opcode, unsigned Reg,
102  const MachineRegisterInfo &MRI);
103 
104 /// Returns an APFloat from Val converted to the appropriate size.
105 APFloat getAPFloatFromSize(double Val, unsigned Size);
106 
107 /// Modify analysis usage so it preserves passes required for the SelectionDAG
108 /// fallback.
109 void getSelectionDAGFallbackAnalysisUsage(AnalysisUsage &AU);
110 
111 Optional<APInt> ConstantFoldBinOp(unsigned Opcode, const unsigned Op1,
112  const unsigned Op2,
113  const MachineRegisterInfo &MRI);
114 } // End namespace llvm.
115 #endif
This class represents lattice values for constants.
Definition: AllocatorList.h:24
void getSelectionDAGFallbackAnalysisUsage(AnalysisUsage &AU)
Modify analysis usage so it preserves passes required for the SelectionDAG fallback.
Definition: Utils.cpp:289
const ConstantFP * getConstantFPVRegVal(unsigned VReg, const MachineRegisterInfo &MRI)
Definition: Utils.cpp:201
unsigned Reg
unsigned const TargetRegisterInfo * TRI
const HexagonInstrInfo * TII
Optional< APInt > ConstantFoldBinOp(unsigned Opcode, const unsigned Op1, const unsigned Op2, const MachineRegisterInfo &MRI)
Definition: Utils.cpp:238
APFloat getAPFloatFromSize(double Val, unsigned Size)
Returns an APFloat from Val converted to the appropriate size.
Definition: Utils.cpp:225
MachineInstr * getOpcodeDef(unsigned Opcode, unsigned Reg, const MachineRegisterInfo &MRI)
See if Reg is defined by an single def instruction that is Opcode.
Definition: Utils.cpp:209
unsigned const MachineRegisterInfo * MRI
unsigned constrainRegToClass(MachineRegisterInfo &MRI, const TargetInstrInfo &TII, const RegisterBankInfo &RBI, MachineInstr &InsertPt, unsigned Reg, const TargetRegisterClass &RegClass)
Try to constrain Reg to the specified register class.
Definition: Utils.cpp:31
#define MORE()
Definition: regcomp.c:251
bool constrainSelectedInstRegOperands(MachineInstr &I, const TargetInstrInfo &TII, const TargetRegisterInfo &TRI, const RegisterBankInfo &RBI)
Mutate the newly-selected instruction I to constrain its (possibly generic) virtual register operands...
Definition: Utils.cpp:88
RegisterBankInfo(RegisterBank **RegBanks, unsigned NumRegBanks)
Create a RegisterBankInfo that can accommodate up to NumRegBanks RegisterBank instances.
Optional< int64_t > getConstantVRegVal(unsigned VReg, const MachineRegisterInfo &MRI)
Definition: Utils.cpp:185
bool isTriviallyDead(const MachineInstr &MI, const MachineRegisterInfo &MRI)
Check whether an instruction MI is dead: it only defines dead virtual registers, and doesn&#39;t have oth...
Definition: Utils.cpp:135
#define I(x, y, z)
Definition: MD5.cpp:58
uint32_t Size
Definition: Profile.cpp:47
IRTranslator LLVM IR MI
unsigned constrainOperandRegClass(const MachineFunction &MF, const TargetRegisterInfo &TRI, MachineRegisterInfo &MRI, const TargetInstrInfo &TII, const RegisterBankInfo &RBI, MachineInstr &InsertPt, const MCInstrDesc &II, const MachineOperand &RegMO, unsigned OpIdx)
Try to constrain Reg so that it is usable by argument OpIdx of the provided MCInstrDesc II...
Definition: Utils.cpp:47
void reportGISelFailure(MachineFunction &MF, const TargetPassConfig &TPC, MachineOptimizationRemarkEmitter &MORE, MachineOptimizationRemarkMissed &R)
Report an ISel error as a missed optimization remark to the LLVMContext&#39;s diagnostic stream...
Definition: Utils.cpp:156