1 //===---- InstrEmitter.h - Emit MachineInstrs for the SelectionDAG class ---==//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This declares the Emit routines for the SelectionDAG class, which creates
11 // MachineInstrs based on the decisions of the SelectionDAG instruction
14 //===----------------------------------------------------------------------===//
16 #ifndef INSTREMITTER_H
17 #define INSTREMITTER_H
19 #include "llvm/CodeGen/SelectionDAG.h"
20 #include "llvm/CodeGen/MachineBasicBlock.h"
21 #include "llvm/ADT/DenseMap.h"
25 class TargetInstrDesc;
29 MachineRegisterInfo *MRI;
30 const TargetMachine *TM;
31 const TargetInstrInfo *TII;
32 const TargetRegisterInfo *TRI;
33 const TargetLowering *TLI;
35 MachineBasicBlock *MBB;
36 MachineBasicBlock::iterator InsertPos;
38 /// EmitCopyFromReg - Generate machine code for an CopyFromReg node or an
39 /// implicit physical register output.
40 void EmitCopyFromReg(SDNode *Node, unsigned ResNo,
41 bool IsClone, bool IsCloned,
43 DenseMap<SDValue, unsigned> &VRBaseMap);
45 /// getDstOfCopyToRegUse - If the only use of the specified result number of
46 /// node is a CopyToReg, return its destination register. Return 0 otherwise.
47 unsigned getDstOfOnlyCopyToRegUse(SDNode *Node,
48 unsigned ResNo) const;
50 void CreateVirtualRegisters(SDNode *Node, MachineInstr *MI,
51 const TargetInstrDesc &II,
52 bool IsClone, bool IsCloned,
53 DenseMap<SDValue, unsigned> &VRBaseMap);
55 /// getVR - Return the virtual register corresponding to the specified result
56 /// of the specified node.
57 unsigned getVR(SDValue Op,
58 DenseMap<SDValue, unsigned> &VRBaseMap);
60 /// AddRegisterOperand - Add the specified register as an operand to the
61 /// specified machine instr. Insert register copies if the register is
62 /// not in the required register class.
63 void AddRegisterOperand(MachineInstr *MI, SDValue Op,
65 const TargetInstrDesc *II,
66 DenseMap<SDValue, unsigned> &VRBaseMap);
68 /// AddOperand - Add the specified operand to the specified machine instr. II
69 /// specifies the instruction information for the node, and IIOpNum is the
70 /// operand number (in the II) that we are adding. IIOpNum and II are used for
72 void AddOperand(MachineInstr *MI, SDValue Op,
74 const TargetInstrDesc *II,
75 DenseMap<SDValue, unsigned> &VRBaseMap);
77 /// EmitSubregNode - Generate machine code for subreg nodes.
79 void EmitSubregNode(SDNode *Node, DenseMap<SDValue, unsigned> &VRBaseMap);
81 /// EmitCopyToRegClassNode - Generate machine code for COPY_TO_REGCLASS nodes.
82 /// COPY_TO_REGCLASS is just a normal copy, except that the destination
83 /// register is constrained to be in a particular register class.
85 void EmitCopyToRegClassNode(SDNode *Node,
86 DenseMap<SDValue, unsigned> &VRBaseMap);
89 /// CountResults - The results of target nodes have register or immediate
90 /// operands first, then an optional chain, and optional flag operands
91 /// (which do not go into the machine instrs.)
92 static unsigned CountResults(SDNode *Node);
94 /// CountOperands - The inputs to target nodes have any actual inputs first,
95 /// followed by an optional chain operand, then flag operands. Compute
96 /// the number of actual operands that will go into the resulting
98 static unsigned CountOperands(SDNode *Node);
100 /// EmitNode - Generate machine code for a node and needed dependencies.
102 void EmitNode(SDNode *Node, bool IsClone, bool IsCloned,
103 DenseMap<SDValue, unsigned> &VRBaseMap,
104 DenseMap<MachineBasicBlock*, MachineBasicBlock*> *EM);
106 /// getBlock - Return the current basic block.
107 MachineBasicBlock *getBlock() { return MBB; }
109 /// getInsertPos - Return the current insertion position.
110 MachineBasicBlock::iterator getInsertPos() { return InsertPos; }
112 /// InstrEmitter - Construct an InstrEmitter and set it to start inserting
113 /// at the given position in the given block.
114 InstrEmitter(MachineBasicBlock *mbb, MachineBasicBlock::iterator insertpos);