mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-08-26 07:29:55 +00:00
reapply 99444/99445, which I speculatively reverted in
r99453. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@99482 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
5d428511ca
commit
3d7d07ef03
@ -548,93 +548,98 @@ MachineInstr *InstrEmitter::EmitDbgValue(SDDbgValue *SD,
|
||||
return &*MIB;
|
||||
}
|
||||
|
||||
/// EmitNode - Generate machine code for a node and needed dependencies.
|
||||
/// EmitMachineNode - Generate machine code for a target-specific node and
|
||||
/// needed dependencies.
|
||||
///
|
||||
void InstrEmitter::EmitNode(SDNode *Node, bool IsClone, bool IsCloned,
|
||||
DenseMap<SDValue, unsigned> &VRBaseMap,
|
||||
DenseMap<MachineBasicBlock*, MachineBasicBlock*> *EM) {
|
||||
// If machine instruction
|
||||
if (Node->isMachineOpcode()) {
|
||||
unsigned Opc = Node->getMachineOpcode();
|
||||
|
||||
// Handle subreg insert/extract specially
|
||||
if (Opc == TargetOpcode::EXTRACT_SUBREG ||
|
||||
Opc == TargetOpcode::INSERT_SUBREG ||
|
||||
Opc == TargetOpcode::SUBREG_TO_REG) {
|
||||
EmitSubregNode(Node, VRBaseMap);
|
||||
return;
|
||||
}
|
||||
|
||||
// Handle COPY_TO_REGCLASS specially.
|
||||
if (Opc == TargetOpcode::COPY_TO_REGCLASS) {
|
||||
EmitCopyToRegClassNode(Node, VRBaseMap);
|
||||
return;
|
||||
}
|
||||
|
||||
if (Opc == TargetOpcode::IMPLICIT_DEF)
|
||||
// We want a unique VR for each IMPLICIT_DEF use.
|
||||
return;
|
||||
|
||||
const TargetInstrDesc &II = TII->get(Opc);
|
||||
unsigned NumResults = CountResults(Node);
|
||||
unsigned NodeOperands = CountOperands(Node);
|
||||
bool HasPhysRegOuts = (NumResults > II.getNumDefs()) &&
|
||||
II.getImplicitDefs() != 0;
|
||||
#ifndef NDEBUG
|
||||
unsigned NumMIOperands = NodeOperands + NumResults;
|
||||
assert((II.getNumOperands() == NumMIOperands ||
|
||||
HasPhysRegOuts || II.isVariadic()) &&
|
||||
"#operands for dag node doesn't match .td file!");
|
||||
#endif
|
||||
|
||||
// Create the new machine instruction.
|
||||
MachineInstr *MI = BuildMI(*MF, Node->getDebugLoc(), II);
|
||||
|
||||
// Add result register values for things that are defined by this
|
||||
// instruction.
|
||||
if (NumResults)
|
||||
CreateVirtualRegisters(Node, MI, II, IsClone, IsCloned, VRBaseMap);
|
||||
|
||||
// Emit all of the actual operands of this instruction, adding them to the
|
||||
// instruction as appropriate.
|
||||
bool HasOptPRefs = II.getNumDefs() > NumResults;
|
||||
assert((!HasOptPRefs || !HasPhysRegOuts) &&
|
||||
"Unable to cope with optional defs and phys regs defs!");
|
||||
unsigned NumSkip = HasOptPRefs ? II.getNumDefs() - NumResults : 0;
|
||||
for (unsigned i = NumSkip; i != NodeOperands; ++i)
|
||||
AddOperand(MI, Node->getOperand(i), i-NumSkip+II.getNumDefs(), &II,
|
||||
VRBaseMap);
|
||||
|
||||
// Transfer all of the memory reference descriptions of this instruction.
|
||||
MI->setMemRefs(cast<MachineSDNode>(Node)->memoperands_begin(),
|
||||
cast<MachineSDNode>(Node)->memoperands_end());
|
||||
|
||||
if (II.usesCustomInsertionHook()) {
|
||||
// Insert this instruction into the basic block using a target
|
||||
// specific inserter which may returns a new basic block.
|
||||
MBB = TLI->EmitInstrWithCustomInserter(MI, MBB, EM);
|
||||
InsertPos = MBB->end();
|
||||
} else {
|
||||
MBB->insert(InsertPos, MI);
|
||||
}
|
||||
|
||||
// Additional results must be an physical register def.
|
||||
if (HasPhysRegOuts) {
|
||||
for (unsigned i = II.getNumDefs(); i < NumResults; ++i) {
|
||||
unsigned Reg = II.getImplicitDefs()[i - II.getNumDefs()];
|
||||
if (Node->hasAnyUseOfValue(i))
|
||||
EmitCopyFromReg(Node, i, IsClone, IsCloned, Reg, VRBaseMap);
|
||||
// If there are no uses, mark the register as dead now, so that
|
||||
// MachineLICM/Sink can see that it's dead. Don't do this if the
|
||||
// node has a Flag value, for the benefit of targets still using
|
||||
// Flag for values in physregs.
|
||||
else if (Node->getValueType(Node->getNumValues()-1) != MVT::Flag)
|
||||
MI->addRegisterDead(Reg, TRI);
|
||||
}
|
||||
}
|
||||
void InstrEmitter::
|
||||
EmitMachineNode(SDNode *Node, bool IsClone, bool IsCloned,
|
||||
DenseMap<SDValue, unsigned> &VRBaseMap,
|
||||
DenseMap<MachineBasicBlock*, MachineBasicBlock*> *EM) {
|
||||
unsigned Opc = Node->getMachineOpcode();
|
||||
|
||||
// Handle subreg insert/extract specially
|
||||
if (Opc == TargetOpcode::EXTRACT_SUBREG ||
|
||||
Opc == TargetOpcode::INSERT_SUBREG ||
|
||||
Opc == TargetOpcode::SUBREG_TO_REG) {
|
||||
EmitSubregNode(Node, VRBaseMap);
|
||||
return;
|
||||
}
|
||||
|
||||
// Handle COPY_TO_REGCLASS specially.
|
||||
if (Opc == TargetOpcode::COPY_TO_REGCLASS) {
|
||||
EmitCopyToRegClassNode(Node, VRBaseMap);
|
||||
return;
|
||||
}
|
||||
|
||||
if (Opc == TargetOpcode::IMPLICIT_DEF)
|
||||
// We want a unique VR for each IMPLICIT_DEF use.
|
||||
return;
|
||||
|
||||
const TargetInstrDesc &II = TII->get(Opc);
|
||||
unsigned NumResults = CountResults(Node);
|
||||
unsigned NodeOperands = CountOperands(Node);
|
||||
bool HasPhysRegOuts = (NumResults > II.getNumDefs()) &&
|
||||
II.getImplicitDefs() != 0;
|
||||
#ifndef NDEBUG
|
||||
unsigned NumMIOperands = NodeOperands + NumResults;
|
||||
assert((II.getNumOperands() == NumMIOperands ||
|
||||
HasPhysRegOuts || II.isVariadic()) &&
|
||||
"#operands for dag node doesn't match .td file!");
|
||||
#endif
|
||||
|
||||
// Create the new machine instruction.
|
||||
MachineInstr *MI = BuildMI(*MF, Node->getDebugLoc(), II);
|
||||
|
||||
// Add result register values for things that are defined by this
|
||||
// instruction.
|
||||
if (NumResults)
|
||||
CreateVirtualRegisters(Node, MI, II, IsClone, IsCloned, VRBaseMap);
|
||||
|
||||
// Emit all of the actual operands of this instruction, adding them to the
|
||||
// instruction as appropriate.
|
||||
bool HasOptPRefs = II.getNumDefs() > NumResults;
|
||||
assert((!HasOptPRefs || !HasPhysRegOuts) &&
|
||||
"Unable to cope with optional defs and phys regs defs!");
|
||||
unsigned NumSkip = HasOptPRefs ? II.getNumDefs() - NumResults : 0;
|
||||
for (unsigned i = NumSkip; i != NodeOperands; ++i)
|
||||
AddOperand(MI, Node->getOperand(i), i-NumSkip+II.getNumDefs(), &II,
|
||||
VRBaseMap);
|
||||
|
||||
// Transfer all of the memory reference descriptions of this instruction.
|
||||
MI->setMemRefs(cast<MachineSDNode>(Node)->memoperands_begin(),
|
||||
cast<MachineSDNode>(Node)->memoperands_end());
|
||||
|
||||
if (II.usesCustomInsertionHook()) {
|
||||
// Insert this instruction into the basic block using a target
|
||||
// specific inserter which may returns a new basic block.
|
||||
MBB = TLI->EmitInstrWithCustomInserter(MI, MBB, EM);
|
||||
InsertPos = MBB->end();
|
||||
} else {
|
||||
MBB->insert(InsertPos, MI);
|
||||
}
|
||||
|
||||
// Additional results must be an physical register def.
|
||||
if (HasPhysRegOuts) {
|
||||
for (unsigned i = II.getNumDefs(); i < NumResults; ++i) {
|
||||
unsigned Reg = II.getImplicitDefs()[i - II.getNumDefs()];
|
||||
if (Node->hasAnyUseOfValue(i))
|
||||
EmitCopyFromReg(Node, i, IsClone, IsCloned, Reg, VRBaseMap);
|
||||
// If there are no uses, mark the register as dead now, so that
|
||||
// MachineLICM/Sink can see that it's dead. Don't do this if the
|
||||
// node has a Flag value, for the benefit of targets still using
|
||||
// Flag for values in physregs.
|
||||
else if (Node->getValueType(Node->getNumValues()-1) != MVT::Flag)
|
||||
MI->addRegisterDead(Reg, TRI);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/// EmitSpecialNode - Generate machine code for a target-independent node and
|
||||
/// needed dependencies.
|
||||
void InstrEmitter::
|
||||
EmitSpecialNode(SDNode *Node, bool IsClone, bool IsCloned,
|
||||
DenseMap<SDValue, unsigned> &VRBaseMap) {
|
||||
switch (Node->getOpcode()) {
|
||||
default:
|
||||
#ifndef NDEBUG
|
||||
|
@ -111,7 +111,12 @@ public:
|
||||
///
|
||||
void EmitNode(SDNode *Node, bool IsClone, bool IsCloned,
|
||||
DenseMap<SDValue, unsigned> &VRBaseMap,
|
||||
DenseMap<MachineBasicBlock*, MachineBasicBlock*> *EM);
|
||||
DenseMap<MachineBasicBlock*, MachineBasicBlock*> *EM) {
|
||||
if (Node->isMachineOpcode())
|
||||
EmitMachineNode(Node, IsClone, IsCloned, VRBaseMap, EM);
|
||||
else
|
||||
EmitSpecialNode(Node, IsClone, IsCloned, VRBaseMap);
|
||||
}
|
||||
|
||||
/// getBlock - Return the current basic block.
|
||||
MachineBasicBlock *getBlock() { return MBB; }
|
||||
@ -122,6 +127,13 @@ public:
|
||||
/// InstrEmitter - Construct an InstrEmitter and set it to start inserting
|
||||
/// at the given position in the given block.
|
||||
InstrEmitter(MachineBasicBlock *mbb, MachineBasicBlock::iterator insertpos);
|
||||
|
||||
private:
|
||||
void EmitMachineNode(SDNode *Node, bool IsClone, bool IsCloned,
|
||||
DenseMap<SDValue, unsigned> &VRBaseMap,
|
||||
DenseMap<MachineBasicBlock*, MachineBasicBlock*> *EM);
|
||||
void EmitSpecialNode(SDNode *Node, bool IsClone, bool IsCloned,
|
||||
DenseMap<SDValue, unsigned> &VRBaseMap);
|
||||
};
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user