16 #define DEBUG_TYPE "instr-emitter"
60 unsigned &NumImpUses) {
68 NumImpUses = N - NumExpUses;
69 for (
unsigned I = N;
I > NumExpUses; --
I) {
70 if (isa<RegisterMaskSDNode>(Node->
getOperand(
I - 1)))
85 EmitCopyFromReg(
SDNode *Node,
unsigned ResNo,
bool IsClone,
bool IsCloned,
93 bool isNew = VRBaseMap.
insert(std::make_pair(Op, SrcReg)).second;
95 assert(isNew &&
"Node emitted out of order - early");
101 bool MatchReg =
true;
109 if (!IsClone && !IsCloned)
121 }
else if (DestReg != SrcReg)
164 assert(UseRC->
hasType(VT) &&
"Incompatible phys register def and uses!");
178 VRBase).addReg(SrcReg);
184 bool isNew = VRBaseMap.
insert(std::make_pair(Op, VRBase)).second;
186 assert(isNew &&
"Node emitted out of order - early");
191 unsigned InstrEmitter::getDstOfOnlyCopyToRegUse(
SDNode *Node,
192 unsigned ResNo)
const {
207 void InstrEmitter::CreateVirtualRegisters(
SDNode *Node,
210 bool IsClone,
bool IsCloned,
213 "IMPLICIT_DEF should have been handled as a special case elsewhere!");
216 for (
unsigned i = 0; i < II.
getNumDefs(); ++i) {
225 if (!RC && i < NumResults)
235 if (!VRBase && !IsClone && !IsCloned)
257 assert(RC &&
"Isn't a register operand!");
265 bool isNew = VRBaseMap.
insert(std::make_pair(Op, VRBase)).second;
267 assert(isNew &&
"Node emitted out of order - early");
273 unsigned InstrEmitter::getVR(
SDValue Op,
292 assert(I != VRBaseMap.
end() &&
"Node emitted out of order - late");
306 bool IsDebug,
bool IsClone,
bool IsCloned) {
309 "Chain and glue operands should occur at end of operand list!");
311 unsigned VReg = getVR(Op, VRBaseMap);
324 if (IIOpNum < II->getNumOperands())
344 !(IsClone || IsCloned);
368 bool IsDebug,
bool IsClone,
bool IsCloned) {
370 AddRegisterOperand(MIB, Op, IIOpNum, II, VRBaseMap,
371 IsDebug, IsClone, IsCloned);
386 TGA->getTargetFlags());
388 MIB.
addMBB(BBNode->getBasicBlock());
394 int Offset = CP->getOffset();
395 unsigned Align = CP->getAlignment();
408 if (CP->isMachineConstantPoolEntry())
418 BA->getTargetFlags());
420 MIB.
addTargetIndex(TI->getIndex(), TI->getOffset(), TI->getTargetFlags());
424 "Chain and glue operands should occur at end of operand list!");
425 AddRegisterOperand(MIB, Op, IIOpNum, II, VRBaseMap,
426 IsDebug, IsClone, IsCloned);
430 unsigned InstrEmitter::ConstrainForSubReg(
unsigned VReg,
unsigned SubIdx,
447 assert(RC &&
"No legal register class for VT supports that SubIdx");
456 void InstrEmitter::EmitSubregNode(
SDNode *Node,
458 bool IsClone,
bool IsCloned) {
481 unsigned SubIdx = cast<ConstantSDNode>(Node->
getOperand(1))->getZExtValue();
485 unsigned VReg = getVR(Node->
getOperand(0), VRBaseMap);
487 unsigned SrcReg, DstReg, DefSubIdx;
490 SubIdx == DefSubIdx &&
505 VReg = ConstrainForSubReg(VReg, SubIdx,
522 unsigned SubIdx = cast<ConstantSDNode>(N2)->getZExtValue();
540 assert(SRC &&
"No register class supports VT and SubIdx for INSERT_SUBREG");
555 AddOperand(MIB, N0, 0, 0, VRBaseMap,
false,
558 AddOperand(MIB, N1, 0, 0, VRBaseMap,
false,
561 MBB->
insert(InsertPos, MIB);
563 llvm_unreachable(
"Node is not insert_subreg, extract_subreg, or subreg_to_reg");
566 bool isNew = VRBaseMap.
insert(std::make_pair(Op, VRBase)).second;
568 assert(isNew &&
"Node emitted out of order - early");
576 InstrEmitter::EmitCopyToRegClassNode(
SDNode *Node,
578 unsigned VReg = getVR(Node->
getOperand(0), VRBaseMap);
581 unsigned DstRCIdx = cast<ConstantSDNode>(Node->
getOperand(1))->getZExtValue();
586 NewVReg).addReg(VReg);
589 bool isNew = VRBaseMap.
insert(std::make_pair(Op, NewVReg)).second;
591 assert(isNew &&
"Node emitted out of order - early");
596 void InstrEmitter::EmitRegSequence(
SDNode *Node,
598 bool IsClone,
bool IsCloned) {
599 unsigned DstRCIdx = cast<ConstantSDNode>(Node->
getOperand(0))->getZExtValue();
605 assert((NumOps & 1) == 1 &&
606 "REG_SEQUENCE must have an odd number of operands!");
607 for (
unsigned i = 1; i != NumOps; ++i) {
614 unsigned SubIdx = cast<ConstantSDNode>(Op)->getZExtValue();
615 unsigned SubReg = getVR(Node->
getOperand(i-1), VRBaseMap);
619 if (SRC && SRC != RC) {
625 AddOperand(MIB, Op, i+1, &II, VRBaseMap,
false,
629 MBB->
insert(InsertPos, MIB);
631 bool isNew = VRBaseMap.
insert(std::make_pair(Op, NewVReg)).second;
633 assert(isNew &&
"Node emitted out of order - early");
663 if (I==VRBaseMap.
end())
670 if (
const ConstantInt *CI = dyn_cast<ConstantInt>(V)) {
671 if (CI->getBitWidth() > 64)
674 MIB.
addImm(CI->getSExtValue());
675 }
else if (
const ConstantFP *CF = dyn_cast<ConstantFP>(V)) {
701 EmitMachineNode(
SDNode *Node,
bool IsClone,
bool IsCloned,
709 EmitSubregNode(Node, VRBaseMap, IsClone, IsCloned);
715 EmitCopyToRegClassNode(Node, VRBaseMap);
721 EmitRegSequence(Node, VRBaseMap, IsClone, IsCloned);
732 const uint16_t *ScratchRegs = NULL;
737 NumDefs = NumResults;
741 unsigned NumImpUses = 0;
742 unsigned NodeOperands =
746 unsigned NumMIOperands = NodeOperands + NumResults;
749 "Too few operands for a variadic node!");
754 "#operands for dag node doesn't match .td file!");
763 CreateVirtualRegisters(Node, MIB, II, IsClone, IsCloned, VRBaseMap);
767 bool HasOptPRefs = NumDefs > NumResults;
768 assert((!HasOptPRefs || !HasPhysRegOuts) &&
769 "Unable to cope with optional defs and phys regs defs!");
770 unsigned NumSkip = HasOptPRefs ? NumDefs - NumResults : 0;
771 for (
unsigned i = NumSkip; i != NodeOperands; ++i)
772 AddOperand(MIB, Node->
getOperand(i), i-NumSkip+NumDefs, &II,
773 VRBaseMap,
false, IsClone, IsCloned);
777 for (
unsigned i = 0; ScratchRegs[i]; ++i)
782 MIB.setMemRefs(cast<MachineSDNode>(Node)->memoperands_begin(),
783 cast<MachineSDNode>(Node)->memoperands_end());
788 MBB->
insert(InsertPos, MIB);
808 if (HasPhysRegOuts) {
809 for (
unsigned i = NumDefs; i < NumResults; ++i) {
810 unsigned Reg = II.getImplicitDefs()[i - NumDefs];
815 EmitCopyFromReg(Node, i, IsClone, IsCloned, Reg, VRBaseMap);
835 for (
unsigned i = 0, e =
F->getNumOperands(); i != e; ++i)
837 unsigned Reg = R->
getReg();
845 if (!UsedRegs.
empty() || II.getImplicitDefs())
846 MIB->setPhysRegsDeadExcept(UsedRegs, *TRI);
850 if (II.hasPostISelHook())
858 EmitSpecialNode(
SDNode *Node,
bool IsClone,
bool IsCloned,
865 llvm_unreachable(
"This target-independent node should have been selected!");
867 llvm_unreachable(
"EntryToken should have been excluded from the schedule!");
877 SrcReg = getVR(SrcVal, VRBaseMap);
880 if (SrcReg == DestReg)
884 DestReg).addReg(SrcReg);
889 EmitCopyFromReg(Node, 0, IsClone, IsCloned, SrcReg, VRBaseMap);
893 MCSymbol *S = cast<EHLabelSDNode>(Node)->getLabel();
921 const char *AsmStr = cast<ExternalSymbolSDNode>(AsmStrV)->getSymbol();
927 cast<ConstantSDNode>(Node->
getOperand(InlineAsm::Op_ExtraInfo))->
935 for (
unsigned i = InlineAsm::Op_FirstOperand; i != NumOps;) {
937 cast<ConstantSDNode>(Node->
getOperand(i))->getZExtValue();
946 case InlineAsm::Kind_RegDef:
947 for (
unsigned j = 0; j != NumVals; ++j, ++i) {
956 case InlineAsm::Kind_RegDefEarlyClobber:
957 case InlineAsm::Kind_Clobber:
958 for (
unsigned j = 0; j != NumVals; ++j, ++i) {
964 case InlineAsm::Kind_RegUse:
965 case InlineAsm::Kind_Imm:
966 case InlineAsm::Kind_Mem:
969 for (
unsigned j = 0; j != NumVals; ++j, ++i)
970 AddOperand(MIB, Node->
getOperand(i), 0, 0, VRBaseMap,
971 false, IsClone, IsCloned);
975 unsigned DefGroup = 0;
977 unsigned DefIdx = GroupIdx[DefGroup] + 1;
978 unsigned UseIdx = GroupIdx.
back() + 1;
979 for (
unsigned j = 0; j != NumVals; ++j)
989 const MDNode *MD = cast<MDNodeSDNode>(MDV)->getMD();
993 MBB->
insert(InsertPos, MIB);
1004 MRI(&MF->getRegInfo()),
1005 TM(&MF->getTarget()),
1006 TII(
TM->getInstrInfo()),
1007 TRI(
TM->getRegisterInfo()),
1008 TLI(
TM->getTargetLowering()),
1009 MBB(mbb), InsertPos(insertpos) {
MVT getSimpleValueType() const
Return the simple ValueType of the referenced return value.
const MachineInstrBuilder & addMetadata(const MDNode *MD) const
void push_back(const T &Elt)
The machine constant pool.
unsigned getNumImplicitUses() const
Return the number of implicit uses this instruction has.
const uint16_t * getImplicitDefs() const
const TargetRegisterClass * getMinimalPhysRegClass(unsigned Reg, EVT VT=MVT::Other) const
InstrEmitter(MachineBasicBlock *mbb, MachineBasicBlock::iterator insertpos)
void dump() const
dump - Dump this node, for debugging.
unsigned getNumImplicitDefs() const
Return the number of implicit defs this instruct has.
unsigned getNumDefs() const
Return the number of MachineOperands that are register definitions. Register definitions always occur...
unsigned createVirtualRegister(const TargetRegisterClass *RegClass)
enable_if_c<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
bool hasSubClassEq(const TargetRegisterClass *RC) const
unsigned getPrefTypeAlignment(Type *Ty) const
static bool isVirtualRegister(unsigned Reg)
const uint16_t * getImplicitUses() const
Completely target-dependent object reference.
unsigned getOpcode() const
static unsigned CountResults(SDNode *Node)
const MCInstrDesc & getDesc() const
unsigned getNumOperands() const
unsigned getNumOperands() const
const TargetRegisterClass * getCommonSubClass(const TargetRegisterClass *A, const TargetRegisterClass *B) const
MDNode - a tuple of other values.
const SDValue & getOperand(unsigned Num) const
bool isVariadic() const
Return true if this instruction can have a variable number of operands. In this case, the variable operands will be after the normal operands but before the implicit definitions and uses (if any are present).
virtual void AdjustInstrPostInstrSelection(MachineInstr *MI, SDNode *Node) const
EntryToken - This is the marker used to indicate the start of a region.
static bool isUseOperandTiedToDef(unsigned Flag, unsigned &Idx)
unsigned getResNo() const
get the index which selects a specific result in the SDNode
const DebugLoc getDebugLoc() const
getDebugLoc - Return the source location info.
const HexagonInstrInfo * TII
#define llvm_unreachable(msg)
EVT getValueType(unsigned ResNo) const
const TargetRegisterClass * getRegClass(unsigned i) const
bool isReg() const
isReg - Tests if this is a MO_Register operand.
const TargetRegisterClass * getRegClass(unsigned Reg) const
unsigned getMachineOpcode() const
ID
LLVM Calling Convention Representation.
virtual const uint16_t * getScratchRegisters(CallingConv::ID CC) const
const MachineInstrBuilder & addImm(int64_t Val) const
unsigned getNumOperands() const
unsigned getNumValues() const
bool LLVM_ATTRIBUTE_UNUSED_RESULT empty() const
virtual const TargetRegisterClass * getMatchingSuperRegClass(const TargetRegisterClass *A, const TargetRegisterClass *B, unsigned Idx) const
const TargetRegisterClass * constrainRegClass(unsigned Reg, const TargetRegisterClass *RC, unsigned MinNumRegs=0)
unsigned getKillRegState(bool B)
unsigned getDebugRegState(bool B)
unsigned getDefRegState(bool B)
SDNode * getNode() const
get the SDNode which holds the desired result
bundle_iterator< MachineInstr, instr_iterator > iterator
bool isTypeLegal(EVT VT) const
bool isOptionalDef() const
const MachineOperand & getOperand(unsigned i) const
static unsigned getNumOperandRegisters(unsigned Flag)
const MachineInstrBuilder & addTargetIndex(unsigned Idx, int64_t Offset=0, unsigned char TargetFlags=0) const
static unsigned getKind(unsigned Flags)
use_iterator use_begin() const
MachineConstantPool * getConstantPool()
MachineInstrBuilder BuildMI(MachineFunction &MF, DebugLoc DL, const MCInstrDesc &MCID)
void append(in_iter in_start, in_iter in_end)
const TargetRegisterClass * getAllocatableClass(const TargetRegisterClass *RC) const
uint64_t getConstantOperandVal(unsigned Num) const
int getOperandConstraint(unsigned OpNum, MCOI::OperandConstraint Constraint) const
Returns the value of the specific constraint if it is set. Returns -1 if it is not set...
const MCInstrDesc & get(unsigned Opcode) const
std::pair< iterator, bool > insert(const std::pair< KeyT, ValueT > &KV)
Class for constant integers.
uint64_t getTypeAllocSize(Type *Ty) const
const MachineInstrBuilder & addJumpTableIndex(unsigned Idx, unsigned char TargetFlags=0) const
const MachineInstrBuilder & addCImm(const ConstantInt *Val) const
const DebugLoc getDebugLoc() const
SDNode * getGluedUser() const
bool erase(const KeyT &Val)
bool isMachineOpcode() const
const MachineInstrBuilder & addFrameIndex(int Idx) const
virtual const TargetRegisterClass * getRegClassFor(MVT VT) const
static use_iterator use_end()
static cl::opt< AlignMode > Align(cl::desc("Load/store alignment support"), cl::Hidden, cl::init(DefaultAlign), cl::values(clEnumValN(DefaultAlign,"arm-default-align","Generate unaligned accesses only on hardware/OS ""combinations that are known to support them"), clEnumValN(StrictAlign,"arm-strict-align","Disallow all unaligned memory accesses"), clEnumValN(NoStrictAlign,"arm-no-strict-align","Allow unaligned memory accesses"), clEnumValEnd))
const MachineInstrBuilder & addGlobalAddress(const GlobalValue *GV, int64_t Offset=0, unsigned char TargetFlags=0) const
static bool isPhysicalRegister(unsigned Reg)
bool hasAnyUseOfValue(unsigned Value) const
static unsigned countOperands(SDNode *Node, unsigned NumExpUses, unsigned &NumImpUses)
const MachineInstrBuilder & addExternalSymbol(const char *FnName, unsigned char TargetFlags=0) const
IMPLICIT_DEF - This is the MachineInstr-level equivalent of undef.
virtual const DataLayout * getDataLayout() const
const MachineInstrBuilder & addConstantPoolIndex(unsigned Idx, int Offset=0, unsigned char TargetFlags=0) const
DBG_VALUE - a mapping of the llvm.dbg.value intrinsic.
unsigned getImplRegState(bool B)
void clearKillFlags(unsigned Reg) const
static unsigned getReg(const void *D, unsigned RC, unsigned RegNo)
instr_iterator insert(instr_iterator I, MachineInstr *M)
bool hasType(EVT vt) const
MachineInstr * getVRegDef(unsigned Reg) const
const MachineInstrBuilder & addFPImm(const ConstantFP *Val) const
MachineInstr * EmitDbgValue(SDDbgValue *SD, DenseMap< SDValue, unsigned > &VRBaseMap)
virtual const TargetRegisterClass * getSubClassWithSubReg(const TargetRegisterClass *RC, unsigned Idx) const
LLVM Value Representation.
const MachineInstrBuilder & addMBB(MachineBasicBlock *MBB, unsigned char TargetFlags=0) const
unsigned getNumOperands() const
Return the number of declared MachineOperands for this MachineInstruction. Note that variadic (isVari...
const MCOperandInfo * OpInfo
static const Function * getParent(const Value *V)
void setRegClass(unsigned Reg, const TargetRegisterClass *RC)
const TargetRegisterClass * getRegClass(const MCInstrDesc &TID, unsigned OpNum, const TargetRegisterInfo *TRI, const MachineFunction &MF) const
const MCRegisterInfo & MRI
const MachineInstrBuilder & addBlockAddress(const BlockAddress *BA, int64_t Offset=0, unsigned char TargetFlags=0) const
const MachineInstrBuilder & addRegMask(const uint32_t *Mask) const
iterator find(const KeyT &Val)
const MachineInstrBuilder & addReg(unsigned RegNo, unsigned flags=0, unsigned SubReg=0) const
MVT getSimpleValueType(unsigned ResNo) const
virtual bool isCoalescableExtInstr(const MachineInstr &MI, unsigned &SrcReg, unsigned &DstReg, unsigned &SubIdx) const
unsigned getConstantPoolIndex(const Constant *C, unsigned Alignment)
bool isMachineOpcode() const
unsigned getMachineOpcode() const
uint64_t getZExtValue() const
void tieOperands(unsigned DefIdx, unsigned UseIdx)