2013-07-18 02:53:29 +08:00
|
|
|
//===- InstrEmitter.h - Emit MachineInstrs for the SelectionDAG -*- C++ -*--==//
|
2009-10-10 09:32:21 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This declares the Emit routines for the SelectionDAG class, which creates
|
|
|
|
// MachineInstrs based on the decisions of the SelectionDAG instruction
|
|
|
|
// selection.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#ifndef INSTREMITTER_H
|
|
|
|
#define INSTREMITTER_H
|
|
|
|
|
|
|
|
#include "llvm/ADT/DenseMap.h"
|
2012-12-04 15:12:27 +08:00
|
|
|
#include "llvm/CodeGen/MachineBasicBlock.h"
|
|
|
|
#include "llvm/CodeGen/SelectionDAG.h"
|
2009-10-10 09:32:21 +08:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
2012-12-21 02:08:09 +08:00
|
|
|
class MachineInstrBuilder;
|
2011-06-29 03:10:37 +08:00
|
|
|
class MCInstrDesc;
|
2010-03-06 08:03:23 +08:00
|
|
|
class SDDbgValue;
|
2009-10-10 09:32:21 +08:00
|
|
|
|
2013-09-12 02:05:11 +08:00
|
|
|
class InstrEmitter {
|
2009-10-10 09:32:21 +08:00
|
|
|
MachineFunction *MF;
|
|
|
|
MachineRegisterInfo *MRI;
|
|
|
|
const TargetMachine *TM;
|
|
|
|
const TargetInstrInfo *TII;
|
|
|
|
const TargetRegisterInfo *TRI;
|
|
|
|
const TargetLowering *TLI;
|
|
|
|
|
|
|
|
MachineBasicBlock *MBB;
|
|
|
|
MachineBasicBlock::iterator InsertPos;
|
|
|
|
|
|
|
|
/// EmitCopyFromReg - Generate machine code for an CopyFromReg node or an
|
|
|
|
/// implicit physical register output.
|
|
|
|
void EmitCopyFromReg(SDNode *Node, unsigned ResNo,
|
|
|
|
bool IsClone, bool IsCloned,
|
|
|
|
unsigned SrcReg,
|
|
|
|
DenseMap<SDValue, unsigned> &VRBaseMap);
|
|
|
|
|
|
|
|
/// getDstOfCopyToRegUse - If the only use of the specified result number of
|
|
|
|
/// node is a CopyToReg, return its destination register. Return 0 otherwise.
|
|
|
|
unsigned getDstOfOnlyCopyToRegUse(SDNode *Node,
|
|
|
|
unsigned ResNo) const;
|
|
|
|
|
2012-12-21 02:08:09 +08:00
|
|
|
void CreateVirtualRegisters(SDNode *Node,
|
|
|
|
MachineInstrBuilder &MIB,
|
2011-06-29 03:10:37 +08:00
|
|
|
const MCInstrDesc &II,
|
2009-10-10 09:32:21 +08:00
|
|
|
bool IsClone, bool IsCloned,
|
|
|
|
DenseMap<SDValue, unsigned> &VRBaseMap);
|
|
|
|
|
|
|
|
/// getVR - Return the virtual register corresponding to the specified result
|
|
|
|
/// of the specified node.
|
|
|
|
unsigned getVR(SDValue Op,
|
|
|
|
DenseMap<SDValue, unsigned> &VRBaseMap);
|
|
|
|
|
|
|
|
/// AddRegisterOperand - Add the specified register as an operand to the
|
|
|
|
/// specified machine instr. Insert register copies if the register is
|
|
|
|
/// not in the required register class.
|
2012-12-21 02:08:09 +08:00
|
|
|
void AddRegisterOperand(MachineInstrBuilder &MIB,
|
|
|
|
SDValue Op,
|
2009-10-10 09:32:21 +08:00
|
|
|
unsigned IIOpNum,
|
2011-06-29 03:10:37 +08:00
|
|
|
const MCInstrDesc *II,
|
2010-03-25 09:38:16 +08:00
|
|
|
DenseMap<SDValue, unsigned> &VRBaseMap,
|
2010-05-15 06:01:14 +08:00
|
|
|
bool IsDebug, bool IsClone, bool IsCloned);
|
2009-10-10 09:32:21 +08:00
|
|
|
|
|
|
|
/// AddOperand - Add the specified operand to the specified machine instr. II
|
|
|
|
/// specifies the instruction information for the node, and IIOpNum is the
|
|
|
|
/// operand number (in the II) that we are adding. IIOpNum and II are used for
|
|
|
|
/// assertions only.
|
2012-12-21 02:08:09 +08:00
|
|
|
void AddOperand(MachineInstrBuilder &MIB,
|
|
|
|
SDValue Op,
|
2009-10-10 09:32:21 +08:00
|
|
|
unsigned IIOpNum,
|
2011-06-29 03:10:37 +08:00
|
|
|
const MCInstrDesc *II,
|
2010-03-25 09:38:16 +08:00
|
|
|
DenseMap<SDValue, unsigned> &VRBaseMap,
|
2010-05-15 06:01:14 +08:00
|
|
|
bool IsDebug, bool IsClone, bool IsCloned);
|
2009-10-10 09:32:21 +08:00
|
|
|
|
2011-10-06 04:26:40 +08:00
|
|
|
/// ConstrainForSubReg - Try to constrain VReg to a register class that
|
|
|
|
/// supports SubIdx sub-registers. Emit a copy if that isn't possible.
|
|
|
|
/// Return the virtual register to use.
|
|
|
|
unsigned ConstrainForSubReg(unsigned VReg, unsigned SubIdx,
|
2012-12-13 14:34:11 +08:00
|
|
|
MVT VT, DebugLoc DL);
|
2011-10-06 04:26:40 +08:00
|
|
|
|
2009-10-10 09:32:21 +08:00
|
|
|
/// EmitSubregNode - Generate machine code for subreg nodes.
|
|
|
|
///
|
2010-05-15 06:01:14 +08:00
|
|
|
void EmitSubregNode(SDNode *Node, DenseMap<SDValue, unsigned> &VRBaseMap,
|
|
|
|
bool IsClone, bool IsCloned);
|
2009-10-10 09:32:21 +08:00
|
|
|
|
|
|
|
/// EmitCopyToRegClassNode - Generate machine code for COPY_TO_REGCLASS nodes.
|
|
|
|
/// COPY_TO_REGCLASS is just a normal copy, except that the destination
|
|
|
|
/// register is constrained to be in a particular register class.
|
|
|
|
///
|
|
|
|
void EmitCopyToRegClassNode(SDNode *Node,
|
|
|
|
DenseMap<SDValue, unsigned> &VRBaseMap);
|
|
|
|
|
2010-05-04 08:22:40 +08:00
|
|
|
/// EmitRegSequence - Generate machine code for REG_SEQUENCE nodes.
|
|
|
|
///
|
2010-05-15 06:01:14 +08:00
|
|
|
void EmitRegSequence(SDNode *Node, DenseMap<SDValue, unsigned> &VRBaseMap,
|
|
|
|
bool IsClone, bool IsCloned);
|
2009-10-10 09:32:21 +08:00
|
|
|
public:
|
|
|
|
/// CountResults - The results of target nodes have register or immediate
|
|
|
|
/// operands first, then an optional chain, and optional flag operands
|
|
|
|
/// (which do not go into the machine instrs.)
|
|
|
|
static unsigned CountResults(SDNode *Node);
|
|
|
|
|
2010-03-25 09:38:16 +08:00
|
|
|
/// EmitDbgValue - Generate machine instruction for a dbg_value node.
|
|
|
|
///
|
|
|
|
MachineInstr *EmitDbgValue(SDDbgValue *SD,
|
2010-05-01 03:35:33 +08:00
|
|
|
DenseMap<SDValue, unsigned> &VRBaseMap);
|
2010-03-06 08:03:23 +08:00
|
|
|
|
2009-11-17 04:35:59 +08:00
|
|
|
/// EmitNode - Generate machine code for a node and needed dependencies.
|
2009-10-10 09:32:21 +08:00
|
|
|
///
|
|
|
|
void EmitNode(SDNode *Node, bool IsClone, bool IsCloned,
|
2010-05-01 08:01:06 +08:00
|
|
|
DenseMap<SDValue, unsigned> &VRBaseMap) {
|
2010-03-25 12:41:16 +08:00
|
|
|
if (Node->isMachineOpcode())
|
2010-05-01 08:01:06 +08:00
|
|
|
EmitMachineNode(Node, IsClone, IsCloned, VRBaseMap);
|
2010-03-25 12:41:16 +08:00
|
|
|
else
|
|
|
|
EmitSpecialNode(Node, IsClone, IsCloned, VRBaseMap);
|
|
|
|
}
|
2009-10-10 09:32:21 +08:00
|
|
|
|
|
|
|
/// getBlock - Return the current basic block.
|
|
|
|
MachineBasicBlock *getBlock() { return MBB; }
|
|
|
|
|
|
|
|
/// getInsertPos - Return the current insertion position.
|
|
|
|
MachineBasicBlock::iterator getInsertPos() { return InsertPos; }
|
|
|
|
|
|
|
|
/// InstrEmitter - Construct an InstrEmitter and set it to start inserting
|
|
|
|
/// at the given position in the given block.
|
|
|
|
InstrEmitter(MachineBasicBlock *mbb, MachineBasicBlock::iterator insertpos);
|
2010-03-25 12:41:16 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
void EmitMachineNode(SDNode *Node, bool IsClone, bool IsCloned,
|
2010-05-01 08:01:06 +08:00
|
|
|
DenseMap<SDValue, unsigned> &VRBaseMap);
|
2010-03-25 12:41:16 +08:00
|
|
|
void EmitSpecialNode(SDNode *Node, bool IsClone, bool IsCloned,
|
|
|
|
DenseMap<SDValue, unsigned> &VRBaseMap);
|
2009-10-10 09:32:21 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|