xref: /aosp_15_r20/external/llvm/lib/CodeGen/SelectionDAG/InstrEmitter.h (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker //===- InstrEmitter.h - Emit MachineInstrs for the SelectionDAG -*- C++ -*--==//
2*9880d681SAndroid Build Coastguard Worker //
3*9880d681SAndroid Build Coastguard Worker //                     The LLVM Compiler Infrastructure
4*9880d681SAndroid Build Coastguard Worker //
5*9880d681SAndroid Build Coastguard Worker // This file is distributed under the University of Illinois Open Source
6*9880d681SAndroid Build Coastguard Worker // License. See LICENSE.TXT for details.
7*9880d681SAndroid Build Coastguard Worker //
8*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
9*9880d681SAndroid Build Coastguard Worker //
10*9880d681SAndroid Build Coastguard Worker // This declares the Emit routines for the SelectionDAG class, which creates
11*9880d681SAndroid Build Coastguard Worker // MachineInstrs based on the decisions of the SelectionDAG instruction
12*9880d681SAndroid Build Coastguard Worker // selection.
13*9880d681SAndroid Build Coastguard Worker //
14*9880d681SAndroid Build Coastguard Worker //===----------------------------------------------------------------------===//
15*9880d681SAndroid Build Coastguard Worker 
16*9880d681SAndroid Build Coastguard Worker #ifndef LLVM_LIB_CODEGEN_SELECTIONDAG_INSTREMITTER_H
17*9880d681SAndroid Build Coastguard Worker #define LLVM_LIB_CODEGEN_SELECTIONDAG_INSTREMITTER_H
18*9880d681SAndroid Build Coastguard Worker 
19*9880d681SAndroid Build Coastguard Worker #include "llvm/ADT/DenseMap.h"
20*9880d681SAndroid Build Coastguard Worker #include "llvm/CodeGen/MachineBasicBlock.h"
21*9880d681SAndroid Build Coastguard Worker #include "llvm/CodeGen/SelectionDAG.h"
22*9880d681SAndroid Build Coastguard Worker 
23*9880d681SAndroid Build Coastguard Worker namespace llvm {
24*9880d681SAndroid Build Coastguard Worker 
25*9880d681SAndroid Build Coastguard Worker class MachineInstrBuilder;
26*9880d681SAndroid Build Coastguard Worker class MCInstrDesc;
27*9880d681SAndroid Build Coastguard Worker class SDDbgValue;
28*9880d681SAndroid Build Coastguard Worker 
29*9880d681SAndroid Build Coastguard Worker class LLVM_LIBRARY_VISIBILITY InstrEmitter {
30*9880d681SAndroid Build Coastguard Worker   MachineFunction *MF;
31*9880d681SAndroid Build Coastguard Worker   MachineRegisterInfo *MRI;
32*9880d681SAndroid Build Coastguard Worker   const TargetInstrInfo *TII;
33*9880d681SAndroid Build Coastguard Worker   const TargetRegisterInfo *TRI;
34*9880d681SAndroid Build Coastguard Worker   const TargetLowering *TLI;
35*9880d681SAndroid Build Coastguard Worker 
36*9880d681SAndroid Build Coastguard Worker   MachineBasicBlock *MBB;
37*9880d681SAndroid Build Coastguard Worker   MachineBasicBlock::iterator InsertPos;
38*9880d681SAndroid Build Coastguard Worker 
39*9880d681SAndroid Build Coastguard Worker   /// EmitCopyFromReg - Generate machine code for an CopyFromReg node or an
40*9880d681SAndroid Build Coastguard Worker   /// implicit physical register output.
41*9880d681SAndroid Build Coastguard Worker   void EmitCopyFromReg(SDNode *Node, unsigned ResNo,
42*9880d681SAndroid Build Coastguard Worker                        bool IsClone, bool IsCloned,
43*9880d681SAndroid Build Coastguard Worker                        unsigned SrcReg,
44*9880d681SAndroid Build Coastguard Worker                        DenseMap<SDValue, unsigned> &VRBaseMap);
45*9880d681SAndroid Build Coastguard Worker 
46*9880d681SAndroid Build Coastguard Worker   /// getDstOfCopyToRegUse - If the only use of the specified result number of
47*9880d681SAndroid Build Coastguard Worker   /// node is a CopyToReg, return its destination register. Return 0 otherwise.
48*9880d681SAndroid Build Coastguard Worker   unsigned getDstOfOnlyCopyToRegUse(SDNode *Node,
49*9880d681SAndroid Build Coastguard Worker                                     unsigned ResNo) const;
50*9880d681SAndroid Build Coastguard Worker 
51*9880d681SAndroid Build Coastguard Worker   void CreateVirtualRegisters(SDNode *Node,
52*9880d681SAndroid Build Coastguard Worker                               MachineInstrBuilder &MIB,
53*9880d681SAndroid Build Coastguard Worker                               const MCInstrDesc &II,
54*9880d681SAndroid Build Coastguard Worker                               bool IsClone, bool IsCloned,
55*9880d681SAndroid Build Coastguard Worker                               DenseMap<SDValue, unsigned> &VRBaseMap);
56*9880d681SAndroid Build Coastguard Worker 
57*9880d681SAndroid Build Coastguard Worker   /// getVR - Return the virtual register corresponding to the specified result
58*9880d681SAndroid Build Coastguard Worker   /// of the specified node.
59*9880d681SAndroid Build Coastguard Worker   unsigned getVR(SDValue Op,
60*9880d681SAndroid Build Coastguard Worker                  DenseMap<SDValue, unsigned> &VRBaseMap);
61*9880d681SAndroid Build Coastguard Worker 
62*9880d681SAndroid Build Coastguard Worker   /// AddRegisterOperand - Add the specified register as an operand to the
63*9880d681SAndroid Build Coastguard Worker   /// specified machine instr. Insert register copies if the register is
64*9880d681SAndroid Build Coastguard Worker   /// not in the required register class.
65*9880d681SAndroid Build Coastguard Worker   void AddRegisterOperand(MachineInstrBuilder &MIB,
66*9880d681SAndroid Build Coastguard Worker                           SDValue Op,
67*9880d681SAndroid Build Coastguard Worker                           unsigned IIOpNum,
68*9880d681SAndroid Build Coastguard Worker                           const MCInstrDesc *II,
69*9880d681SAndroid Build Coastguard Worker                           DenseMap<SDValue, unsigned> &VRBaseMap,
70*9880d681SAndroid Build Coastguard Worker                           bool IsDebug, bool IsClone, bool IsCloned);
71*9880d681SAndroid Build Coastguard Worker 
72*9880d681SAndroid Build Coastguard Worker   /// AddOperand - Add the specified operand to the specified machine instr.  II
73*9880d681SAndroid Build Coastguard Worker   /// specifies the instruction information for the node, and IIOpNum is the
74*9880d681SAndroid Build Coastguard Worker   /// operand number (in the II) that we are adding. IIOpNum and II are used for
75*9880d681SAndroid Build Coastguard Worker   /// assertions only.
76*9880d681SAndroid Build Coastguard Worker   void AddOperand(MachineInstrBuilder &MIB,
77*9880d681SAndroid Build Coastguard Worker                   SDValue Op,
78*9880d681SAndroid Build Coastguard Worker                   unsigned IIOpNum,
79*9880d681SAndroid Build Coastguard Worker                   const MCInstrDesc *II,
80*9880d681SAndroid Build Coastguard Worker                   DenseMap<SDValue, unsigned> &VRBaseMap,
81*9880d681SAndroid Build Coastguard Worker                   bool IsDebug, bool IsClone, bool IsCloned);
82*9880d681SAndroid Build Coastguard Worker 
83*9880d681SAndroid Build Coastguard Worker   /// ConstrainForSubReg - Try to constrain VReg to a register class that
84*9880d681SAndroid Build Coastguard Worker   /// supports SubIdx sub-registers.  Emit a copy if that isn't possible.
85*9880d681SAndroid Build Coastguard Worker   /// Return the virtual register to use.
86*9880d681SAndroid Build Coastguard Worker   unsigned ConstrainForSubReg(unsigned VReg, unsigned SubIdx, MVT VT,
87*9880d681SAndroid Build Coastguard Worker                               const DebugLoc &DL);
88*9880d681SAndroid Build Coastguard Worker 
89*9880d681SAndroid Build Coastguard Worker   /// EmitSubregNode - Generate machine code for subreg nodes.
90*9880d681SAndroid Build Coastguard Worker   ///
91*9880d681SAndroid Build Coastguard Worker   void EmitSubregNode(SDNode *Node, DenseMap<SDValue, unsigned> &VRBaseMap,
92*9880d681SAndroid Build Coastguard Worker                       bool IsClone, bool IsCloned);
93*9880d681SAndroid Build Coastguard Worker 
94*9880d681SAndroid Build Coastguard Worker   /// EmitCopyToRegClassNode - Generate machine code for COPY_TO_REGCLASS nodes.
95*9880d681SAndroid Build Coastguard Worker   /// COPY_TO_REGCLASS is just a normal copy, except that the destination
96*9880d681SAndroid Build Coastguard Worker   /// register is constrained to be in a particular register class.
97*9880d681SAndroid Build Coastguard Worker   ///
98*9880d681SAndroid Build Coastguard Worker   void EmitCopyToRegClassNode(SDNode *Node,
99*9880d681SAndroid Build Coastguard Worker                               DenseMap<SDValue, unsigned> &VRBaseMap);
100*9880d681SAndroid Build Coastguard Worker 
101*9880d681SAndroid Build Coastguard Worker   /// EmitRegSequence - Generate machine code for REG_SEQUENCE nodes.
102*9880d681SAndroid Build Coastguard Worker   ///
103*9880d681SAndroid Build Coastguard Worker   void EmitRegSequence(SDNode *Node, DenseMap<SDValue, unsigned> &VRBaseMap,
104*9880d681SAndroid Build Coastguard Worker                        bool IsClone, bool IsCloned);
105*9880d681SAndroid Build Coastguard Worker public:
106*9880d681SAndroid Build Coastguard Worker   /// CountResults - The results of target nodes have register or immediate
107*9880d681SAndroid Build Coastguard Worker   /// operands first, then an optional chain, and optional flag operands
108*9880d681SAndroid Build Coastguard Worker   /// (which do not go into the machine instrs.)
109*9880d681SAndroid Build Coastguard Worker   static unsigned CountResults(SDNode *Node);
110*9880d681SAndroid Build Coastguard Worker 
111*9880d681SAndroid Build Coastguard Worker   /// EmitDbgValue - Generate machine instruction for a dbg_value node.
112*9880d681SAndroid Build Coastguard Worker   ///
113*9880d681SAndroid Build Coastguard Worker   MachineInstr *EmitDbgValue(SDDbgValue *SD,
114*9880d681SAndroid Build Coastguard Worker                              DenseMap<SDValue, unsigned> &VRBaseMap);
115*9880d681SAndroid Build Coastguard Worker 
116*9880d681SAndroid Build Coastguard Worker   /// EmitNode - Generate machine code for a node and needed dependencies.
117*9880d681SAndroid Build Coastguard Worker   ///
EmitNode(SDNode * Node,bool IsClone,bool IsCloned,DenseMap<SDValue,unsigned> & VRBaseMap)118*9880d681SAndroid Build Coastguard Worker   void EmitNode(SDNode *Node, bool IsClone, bool IsCloned,
119*9880d681SAndroid Build Coastguard Worker                 DenseMap<SDValue, unsigned> &VRBaseMap) {
120*9880d681SAndroid Build Coastguard Worker     if (Node->isMachineOpcode())
121*9880d681SAndroid Build Coastguard Worker       EmitMachineNode(Node, IsClone, IsCloned, VRBaseMap);
122*9880d681SAndroid Build Coastguard Worker     else
123*9880d681SAndroid Build Coastguard Worker       EmitSpecialNode(Node, IsClone, IsCloned, VRBaseMap);
124*9880d681SAndroid Build Coastguard Worker   }
125*9880d681SAndroid Build Coastguard Worker 
126*9880d681SAndroid Build Coastguard Worker   /// getBlock - Return the current basic block.
getBlock()127*9880d681SAndroid Build Coastguard Worker   MachineBasicBlock *getBlock() { return MBB; }
128*9880d681SAndroid Build Coastguard Worker 
129*9880d681SAndroid Build Coastguard Worker   /// getInsertPos - Return the current insertion position.
getInsertPos()130*9880d681SAndroid Build Coastguard Worker   MachineBasicBlock::iterator getInsertPos() { return InsertPos; }
131*9880d681SAndroid Build Coastguard Worker 
132*9880d681SAndroid Build Coastguard Worker   /// InstrEmitter - Construct an InstrEmitter and set it to start inserting
133*9880d681SAndroid Build Coastguard Worker   /// at the given position in the given block.
134*9880d681SAndroid Build Coastguard Worker   InstrEmitter(MachineBasicBlock *mbb, MachineBasicBlock::iterator insertpos);
135*9880d681SAndroid Build Coastguard Worker 
136*9880d681SAndroid Build Coastguard Worker private:
137*9880d681SAndroid Build Coastguard Worker   void EmitMachineNode(SDNode *Node, bool IsClone, bool IsCloned,
138*9880d681SAndroid Build Coastguard Worker                        DenseMap<SDValue, unsigned> &VRBaseMap);
139*9880d681SAndroid Build Coastguard Worker   void EmitSpecialNode(SDNode *Node, bool IsClone, bool IsCloned,
140*9880d681SAndroid Build Coastguard Worker                        DenseMap<SDValue, unsigned> &VRBaseMap);
141*9880d681SAndroid Build Coastguard Worker };
142*9880d681SAndroid Build Coastguard Worker 
143*9880d681SAndroid Build Coastguard Worker }
144*9880d681SAndroid Build Coastguard Worker 
145*9880d681SAndroid Build Coastguard Worker #endif
146