mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-02-21 06:30:16 +00:00
Constants are now added to the constant pool only when a load
instruction is actually generated for them. Rename the different versions of SetMachineOperand. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@1903 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
1ed009f66e
commit
42f632041d
@ -30,7 +30,8 @@ using std::vector;
|
|||||||
|
|
||||||
|
|
||||||
static TmpInstruction*
|
static TmpInstruction*
|
||||||
InsertCodeToLoadConstant(Value* opValue,
|
InsertCodeToLoadConstant(Method* method,
|
||||||
|
Value* opValue,
|
||||||
Instruction* vmInstr,
|
Instruction* vmInstr,
|
||||||
vector<MachineInstr*>& loadConstVec,
|
vector<MachineInstr*>& loadConstVec,
|
||||||
TargetMachine& target)
|
TargetMachine& target)
|
||||||
@ -42,7 +43,7 @@ InsertCodeToLoadConstant(Value* opValue,
|
|||||||
MachineCodeForInstruction &MCFI = MachineCodeForInstruction::get(vmInstr);
|
MachineCodeForInstruction &MCFI = MachineCodeForInstruction::get(vmInstr);
|
||||||
MCFI.addTemp(tmpReg);
|
MCFI.addTemp(tmpReg);
|
||||||
|
|
||||||
target.getInstrInfo().CreateCodeToLoadConst(opValue, tmpReg,
|
target.getInstrInfo().CreateCodeToLoadConst(method, opValue, tmpReg,
|
||||||
loadConstVec, tempVec);
|
loadConstVec, tempVec);
|
||||||
|
|
||||||
// Register the new tmp values created for this m/c instruction sequence
|
// Register the new tmp values created for this m/c instruction sequence
|
||||||
@ -194,20 +195,20 @@ Set3OperandsFromInstr(MachineInstr* minstr,
|
|||||||
assert(resultPosition >= 0);
|
assert(resultPosition >= 0);
|
||||||
|
|
||||||
// operand 1
|
// operand 1
|
||||||
minstr->SetMachineOperand(op1Position, MachineOperand::MO_VirtualRegister,
|
minstr->SetMachineOperandVal(op1Position, MachineOperand::MO_VirtualRegister,
|
||||||
vmInstrNode->leftChild()->getValue());
|
vmInstrNode->leftChild()->getValue());
|
||||||
|
|
||||||
// operand 2 (if any)
|
// operand 2 (if any)
|
||||||
if (op2Position >= 0)
|
if (op2Position >= 0)
|
||||||
minstr->SetMachineOperand(op2Position, MachineOperand::MO_VirtualRegister,
|
minstr->SetMachineOperandVal(op2Position, MachineOperand::MO_VirtualRegister,
|
||||||
vmInstrNode->rightChild()->getValue());
|
vmInstrNode->rightChild()->getValue());
|
||||||
|
|
||||||
// result operand: if it can be discarded, use a dead register if one exists
|
// result operand: if it can be discarded, use a dead register if one exists
|
||||||
if (canDiscardResult && target.getRegInfo().getZeroRegNum() >= 0)
|
if (canDiscardResult && target.getRegInfo().getZeroRegNum() >= 0)
|
||||||
minstr->SetMachineOperand(resultPosition,
|
minstr->SetMachineOperandReg(resultPosition,
|
||||||
target.getRegInfo().getZeroRegNum());
|
target.getRegInfo().getZeroRegNum());
|
||||||
else
|
else
|
||||||
minstr->SetMachineOperand(resultPosition,
|
minstr->SetMachineOperandVal(resultPosition,
|
||||||
MachineOperand::MO_VirtualRegister, vmInstrNode->getValue());
|
MachineOperand::MO_VirtualRegister, vmInstrNode->getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -328,33 +329,29 @@ FixConstantOperandsForInstr(Instruction* vmInstr,
|
|||||||
Value* opValue = mop.getVRegValue();
|
Value* opValue = mop.getVRegValue();
|
||||||
bool constantThatMustBeLoaded = false;
|
bool constantThatMustBeLoaded = false;
|
||||||
|
|
||||||
if (Constant *OpConst = dyn_cast<Constant>(opValue)) {
|
if (Constant *opConst = dyn_cast<Constant>(opValue))
|
||||||
|
{
|
||||||
unsigned int machineRegNum;
|
unsigned int machineRegNum;
|
||||||
int64_t immedValue;
|
int64_t immedValue;
|
||||||
MachineOperand::MachineOperandType opType =
|
MachineOperand::MachineOperandType opType =
|
||||||
ChooseRegOrImmed(opValue, minstr->getOpCode(), target,
|
ChooseRegOrImmed(opValue, minstr->getOpCode(), target,
|
||||||
(target.getInstrInfo().getImmmedConstantPos(minstr->getOpCode()) == (int) op),
|
(target.getInstrInfo().getImmedConstantPos(minstr->getOpCode()) == (int) op),
|
||||||
machineRegNum, immedValue);
|
machineRegNum, immedValue);
|
||||||
|
|
||||||
if (opType == MachineOperand::MO_MachineRegister)
|
if (opType == MachineOperand::MO_MachineRegister)
|
||||||
minstr->SetMachineOperand(op, machineRegNum);
|
minstr->SetMachineOperandReg(op, machineRegNum);
|
||||||
else if (opType == MachineOperand::MO_VirtualRegister)
|
else if (opType == MachineOperand::MO_VirtualRegister)
|
||||||
constantThatMustBeLoaded = true; // load is generated below
|
constantThatMustBeLoaded = true; // load is generated below
|
||||||
else
|
else
|
||||||
minstr->SetMachineOperand(op, opType, immedValue);
|
minstr->SetMachineOperandConst(op, opType, immedValue);
|
||||||
|
|
||||||
if (constantThatMustBeLoaded)
|
|
||||||
{ // register the value so it is emitted in the assembly
|
|
||||||
MachineCodeForMethod::get(method).addToConstantPool(OpConst);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (constantThatMustBeLoaded || isa<GlobalValue>(opValue))
|
if (constantThatMustBeLoaded || isa<GlobalValue>(opValue))
|
||||||
{ // opValue is a constant that must be explicitly loaded into a reg.
|
{ // opValue is a constant that must be explicitly loaded into a reg.
|
||||||
TmpInstruction* tmpReg = InsertCodeToLoadConstant(opValue, vmInstr,
|
TmpInstruction* tmpReg = InsertCodeToLoadConstant(method, opValue, vmInstr,
|
||||||
loadConstVec, target);
|
loadConstVec, target);
|
||||||
minstr->SetMachineOperand(op, MachineOperand::MO_VirtualRegister,
|
minstr->SetMachineOperandVal(op, MachineOperand::MO_VirtualRegister,
|
||||||
tmpReg);
|
tmpReg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -374,13 +371,8 @@ FixConstantOperandsForInstr(Instruction* vmInstr,
|
|||||||
{
|
{
|
||||||
Value* oldVal = minstr->getImplicitRef(i);
|
Value* oldVal = minstr->getImplicitRef(i);
|
||||||
TmpInstruction* tmpReg =
|
TmpInstruction* tmpReg =
|
||||||
InsertCodeToLoadConstant(oldVal, vmInstr, loadConstVec, target);
|
InsertCodeToLoadConstant(method, oldVal, vmInstr, loadConstVec, target);
|
||||||
minstr->setImplicitRef(i, tmpReg);
|
minstr->setImplicitRef(i, tmpReg);
|
||||||
|
|
||||||
if (Constant *C = dyn_cast<Constant>(oldVal))
|
|
||||||
{ // register the value so it is emitted in the assembly
|
|
||||||
MachineCodeForMethod::get(method).addToConstantPool(C);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return loadConstVec;
|
return loadConstVec;
|
||||||
|
@ -30,7 +30,8 @@ using std::vector;
|
|||||||
|
|
||||||
|
|
||||||
static TmpInstruction*
|
static TmpInstruction*
|
||||||
InsertCodeToLoadConstant(Value* opValue,
|
InsertCodeToLoadConstant(Method* method,
|
||||||
|
Value* opValue,
|
||||||
Instruction* vmInstr,
|
Instruction* vmInstr,
|
||||||
vector<MachineInstr*>& loadConstVec,
|
vector<MachineInstr*>& loadConstVec,
|
||||||
TargetMachine& target)
|
TargetMachine& target)
|
||||||
@ -42,7 +43,7 @@ InsertCodeToLoadConstant(Value* opValue,
|
|||||||
MachineCodeForInstruction &MCFI = MachineCodeForInstruction::get(vmInstr);
|
MachineCodeForInstruction &MCFI = MachineCodeForInstruction::get(vmInstr);
|
||||||
MCFI.addTemp(tmpReg);
|
MCFI.addTemp(tmpReg);
|
||||||
|
|
||||||
target.getInstrInfo().CreateCodeToLoadConst(opValue, tmpReg,
|
target.getInstrInfo().CreateCodeToLoadConst(method, opValue, tmpReg,
|
||||||
loadConstVec, tempVec);
|
loadConstVec, tempVec);
|
||||||
|
|
||||||
// Register the new tmp values created for this m/c instruction sequence
|
// Register the new tmp values created for this m/c instruction sequence
|
||||||
@ -194,20 +195,20 @@ Set3OperandsFromInstr(MachineInstr* minstr,
|
|||||||
assert(resultPosition >= 0);
|
assert(resultPosition >= 0);
|
||||||
|
|
||||||
// operand 1
|
// operand 1
|
||||||
minstr->SetMachineOperand(op1Position, MachineOperand::MO_VirtualRegister,
|
minstr->SetMachineOperandVal(op1Position, MachineOperand::MO_VirtualRegister,
|
||||||
vmInstrNode->leftChild()->getValue());
|
vmInstrNode->leftChild()->getValue());
|
||||||
|
|
||||||
// operand 2 (if any)
|
// operand 2 (if any)
|
||||||
if (op2Position >= 0)
|
if (op2Position >= 0)
|
||||||
minstr->SetMachineOperand(op2Position, MachineOperand::MO_VirtualRegister,
|
minstr->SetMachineOperandVal(op2Position, MachineOperand::MO_VirtualRegister,
|
||||||
vmInstrNode->rightChild()->getValue());
|
vmInstrNode->rightChild()->getValue());
|
||||||
|
|
||||||
// result operand: if it can be discarded, use a dead register if one exists
|
// result operand: if it can be discarded, use a dead register if one exists
|
||||||
if (canDiscardResult && target.getRegInfo().getZeroRegNum() >= 0)
|
if (canDiscardResult && target.getRegInfo().getZeroRegNum() >= 0)
|
||||||
minstr->SetMachineOperand(resultPosition,
|
minstr->SetMachineOperandReg(resultPosition,
|
||||||
target.getRegInfo().getZeroRegNum());
|
target.getRegInfo().getZeroRegNum());
|
||||||
else
|
else
|
||||||
minstr->SetMachineOperand(resultPosition,
|
minstr->SetMachineOperandVal(resultPosition,
|
||||||
MachineOperand::MO_VirtualRegister, vmInstrNode->getValue());
|
MachineOperand::MO_VirtualRegister, vmInstrNode->getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -328,33 +329,29 @@ FixConstantOperandsForInstr(Instruction* vmInstr,
|
|||||||
Value* opValue = mop.getVRegValue();
|
Value* opValue = mop.getVRegValue();
|
||||||
bool constantThatMustBeLoaded = false;
|
bool constantThatMustBeLoaded = false;
|
||||||
|
|
||||||
if (Constant *OpConst = dyn_cast<Constant>(opValue)) {
|
if (Constant *opConst = dyn_cast<Constant>(opValue))
|
||||||
|
{
|
||||||
unsigned int machineRegNum;
|
unsigned int machineRegNum;
|
||||||
int64_t immedValue;
|
int64_t immedValue;
|
||||||
MachineOperand::MachineOperandType opType =
|
MachineOperand::MachineOperandType opType =
|
||||||
ChooseRegOrImmed(opValue, minstr->getOpCode(), target,
|
ChooseRegOrImmed(opValue, minstr->getOpCode(), target,
|
||||||
(target.getInstrInfo().getImmmedConstantPos(minstr->getOpCode()) == (int) op),
|
(target.getInstrInfo().getImmedConstantPos(minstr->getOpCode()) == (int) op),
|
||||||
machineRegNum, immedValue);
|
machineRegNum, immedValue);
|
||||||
|
|
||||||
if (opType == MachineOperand::MO_MachineRegister)
|
if (opType == MachineOperand::MO_MachineRegister)
|
||||||
minstr->SetMachineOperand(op, machineRegNum);
|
minstr->SetMachineOperandReg(op, machineRegNum);
|
||||||
else if (opType == MachineOperand::MO_VirtualRegister)
|
else if (opType == MachineOperand::MO_VirtualRegister)
|
||||||
constantThatMustBeLoaded = true; // load is generated below
|
constantThatMustBeLoaded = true; // load is generated below
|
||||||
else
|
else
|
||||||
minstr->SetMachineOperand(op, opType, immedValue);
|
minstr->SetMachineOperandConst(op, opType, immedValue);
|
||||||
|
|
||||||
if (constantThatMustBeLoaded)
|
|
||||||
{ // register the value so it is emitted in the assembly
|
|
||||||
MachineCodeForMethod::get(method).addToConstantPool(OpConst);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (constantThatMustBeLoaded || isa<GlobalValue>(opValue))
|
if (constantThatMustBeLoaded || isa<GlobalValue>(opValue))
|
||||||
{ // opValue is a constant that must be explicitly loaded into a reg.
|
{ // opValue is a constant that must be explicitly loaded into a reg.
|
||||||
TmpInstruction* tmpReg = InsertCodeToLoadConstant(opValue, vmInstr,
|
TmpInstruction* tmpReg = InsertCodeToLoadConstant(method, opValue, vmInstr,
|
||||||
loadConstVec, target);
|
loadConstVec, target);
|
||||||
minstr->SetMachineOperand(op, MachineOperand::MO_VirtualRegister,
|
minstr->SetMachineOperandVal(op, MachineOperand::MO_VirtualRegister,
|
||||||
tmpReg);
|
tmpReg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -374,13 +371,8 @@ FixConstantOperandsForInstr(Instruction* vmInstr,
|
|||||||
{
|
{
|
||||||
Value* oldVal = minstr->getImplicitRef(i);
|
Value* oldVal = minstr->getImplicitRef(i);
|
||||||
TmpInstruction* tmpReg =
|
TmpInstruction* tmpReg =
|
||||||
InsertCodeToLoadConstant(oldVal, vmInstr, loadConstVec, target);
|
InsertCodeToLoadConstant(method, oldVal, vmInstr, loadConstVec, target);
|
||||||
minstr->setImplicitRef(i, tmpReg);
|
minstr->setImplicitRef(i, tmpReg);
|
||||||
|
|
||||||
if (Constant *C = dyn_cast<Constant>(oldVal))
|
|
||||||
{ // register the value so it is emitted in the assembly
|
|
||||||
MachineCodeForMethod::get(method).addToConstantPool(C);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return loadConstVec;
|
return loadConstVec;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user