mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-14 11:32:34 +00:00
Emit real operand info for instructions. This currently works but is bad
in one way: the generated tables require dynamic initialization for the register classes. This will be fixed in a future patch. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22919 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
c67c18fd23
commit
d5aa3e26bb
@ -64,6 +64,24 @@ void InstrInfoEmitter::printDefList(const std::vector<Record*> &Uses,
|
|||||||
OS << "0 };\n";
|
OS << "0 };\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static std::vector<Record*> GetOperandInfo(const CodeGenInstruction &Inst) {
|
||||||
|
std::vector<Record*> Result;
|
||||||
|
if (Inst.hasVariableNumberOfOperands)
|
||||||
|
return Result; // No info for variable operand instrs.
|
||||||
|
|
||||||
|
for (unsigned i = 0, e = Inst.OperandList.size(); i != e; ++i) {
|
||||||
|
if (Inst.OperandList[i].Rec->isSubClassOf("RegisterClass"))
|
||||||
|
Result.push_back(Inst.OperandList[i].Rec);
|
||||||
|
else {
|
||||||
|
// This might be a multiple operand thing.
|
||||||
|
// FIXME: Targets like X86 have registers in their multi-operand operands.
|
||||||
|
for (unsigned j = 0, e = Inst.OperandList[i].MINumOperands; j != e; ++j)
|
||||||
|
Result.push_back(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return Result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// run - Emit the main instruction description records for the target...
|
// run - Emit the main instruction description records for the target...
|
||||||
void InstrInfoEmitter::run(std::ostream &OS) {
|
void InstrInfoEmitter::run(std::ostream &OS) {
|
||||||
@ -103,15 +121,27 @@ void InstrInfoEmitter::run(std::ostream &OS) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::map<std::vector<Record*>, unsigned> OperandInfosEmitted;
|
||||||
|
unsigned OperandListNum = 0;
|
||||||
|
OperandInfosEmitted[std::vector<Record*>()] = ++OperandListNum;
|
||||||
|
|
||||||
// Emit all of the operand info records.
|
// Emit all of the operand info records.
|
||||||
OS << "\n";
|
OS << "\n";
|
||||||
for (CodeGenTarget::inst_iterator II = Target.inst_begin(),
|
for (CodeGenTarget::inst_iterator II = Target.inst_begin(),
|
||||||
E = Target.inst_end(); II != E; ++II) {
|
E = Target.inst_end(); II != E; ++II) {
|
||||||
const CodeGenInstruction &Inst = II->second;
|
std::vector<Record*> OperandInfo = GetOperandInfo(II->second);
|
||||||
if (!Inst.hasVariableNumberOfOperands) {
|
unsigned &N = OperandInfosEmitted[OperandInfo];
|
||||||
OS << "static const TargetOperandInfo " << Inst.TheDef->getName()
|
if (N == 0) {
|
||||||
<< "_Operands[] = {";
|
N = ++OperandListNum;
|
||||||
// FIXME: Emit operand info.
|
OS << "static const TargetOperandInfo OperandInfo" << N << "[] = { ";
|
||||||
|
for (unsigned i = 0, e = OperandInfo.size(); i != e; ++i) {
|
||||||
|
if (Record *RC = OperandInfo[i]) {
|
||||||
|
// FIXME: BAD: REQUIRES RUNTIME INIT
|
||||||
|
OS << "{ " << getQualifiedName(RC) << "RegisterClass }, ";
|
||||||
|
} else {
|
||||||
|
OS << "{ 0 }, ";
|
||||||
|
}
|
||||||
|
}
|
||||||
OS << "};\n";
|
OS << "};\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -120,13 +150,15 @@ void InstrInfoEmitter::run(std::ostream &OS) {
|
|||||||
//
|
//
|
||||||
OS << "\nstatic const TargetInstrDescriptor " << TargetName
|
OS << "\nstatic const TargetInstrDescriptor " << TargetName
|
||||||
<< "Insts[] = {\n";
|
<< "Insts[] = {\n";
|
||||||
emitRecord(Target.getPHIInstruction(), 0, InstrInfo, ListNumbers, OS);
|
emitRecord(Target.getPHIInstruction(), 0, InstrInfo, ListNumbers,
|
||||||
|
OperandInfosEmitted, OS);
|
||||||
|
|
||||||
unsigned i = 0;
|
unsigned i = 0;
|
||||||
for (CodeGenTarget::inst_iterator II = Target.inst_begin(),
|
for (CodeGenTarget::inst_iterator II = Target.inst_begin(),
|
||||||
E = Target.inst_end(); II != E; ++II)
|
E = Target.inst_end(); II != E; ++II)
|
||||||
if (II->second.TheDef != PHI)
|
if (II->second.TheDef != PHI)
|
||||||
emitRecord(II->second, ++i, InstrInfo, ListNumbers, OS);
|
emitRecord(II->second, ++i, InstrInfo, ListNumbers,
|
||||||
|
OperandInfosEmitted, OS);
|
||||||
OS << "};\n";
|
OS << "};\n";
|
||||||
OS << "} // End llvm namespace \n";
|
OS << "} // End llvm namespace \n";
|
||||||
}
|
}
|
||||||
@ -134,6 +166,7 @@ void InstrInfoEmitter::run(std::ostream &OS) {
|
|||||||
void InstrInfoEmitter::emitRecord(const CodeGenInstruction &Inst, unsigned Num,
|
void InstrInfoEmitter::emitRecord(const CodeGenInstruction &Inst, unsigned Num,
|
||||||
Record *InstrInfo,
|
Record *InstrInfo,
|
||||||
std::map<ListInit*, unsigned> &ListNumbers,
|
std::map<ListInit*, unsigned> &ListNumbers,
|
||||||
|
std::map<std::vector<Record*>, unsigned> &OpInfo,
|
||||||
std::ostream &OS) {
|
std::ostream &OS) {
|
||||||
int NumOperands;
|
int NumOperands;
|
||||||
if (Inst.hasVariableNumberOfOperands)
|
if (Inst.hasVariableNumberOfOperands)
|
||||||
@ -193,10 +226,11 @@ void InstrInfoEmitter::emitRecord(const CodeGenInstruction &Inst, unsigned Num,
|
|||||||
OS << "ImplicitList" << ListNumbers[LI] << ", ";
|
OS << "ImplicitList" << ListNumbers[LI] << ", ";
|
||||||
|
|
||||||
// Emit the operand info.
|
// Emit the operand info.
|
||||||
if (NumOperands == -1)
|
std::vector<Record*> OperandInfo = GetOperandInfo(Inst);
|
||||||
OS << "0 ";
|
if (OperandInfo.empty())
|
||||||
|
OS << "0";
|
||||||
else
|
else
|
||||||
OS << Inst.TheDef->getName() << "_Operands ";
|
OS << "OperandInfo" << OpInfo[OperandInfo];
|
||||||
|
|
||||||
OS << " }, // Inst #" << Num << " = " << Inst.TheDef->getName() << "\n";
|
OS << " }, // Inst #" << Num << " = " << Inst.TheDef->getName() << "\n";
|
||||||
}
|
}
|
||||||
|
@ -42,6 +42,7 @@ private:
|
|||||||
void emitRecord(const CodeGenInstruction &Inst, unsigned Num,
|
void emitRecord(const CodeGenInstruction &Inst, unsigned Num,
|
||||||
Record *InstrInfo,
|
Record *InstrInfo,
|
||||||
std::map<ListInit*, unsigned> &ListNumbers,
|
std::map<ListInit*, unsigned> &ListNumbers,
|
||||||
|
std::map<std::vector<Record*>, unsigned> &OpInfo,
|
||||||
std::ostream &OS);
|
std::ostream &OS);
|
||||||
void emitShiftedValue(Record *R, StringInit *Val, IntInit *Shift,
|
void emitShiftedValue(Record *R, StringInit *Val, IntInit *Shift,
|
||||||
std::ostream &OS);
|
std::ostream &OS);
|
||||||
|
Loading…
Reference in New Issue
Block a user