mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-08 19:25:47 +00:00
TableGen: Refactor DAG patterns to enable parsing one pattern at a time.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@193526 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -2675,54 +2675,13 @@ static bool checkOperandClass(CGIOperandList::OperandInfo &OI,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ParseInstructions - Parse all of the instructions, inlining and resolving
|
const DAGInstruction &CodeGenDAGPatterns::parseInstructionPattern(
|
||||||
/// any fragments involved. This populates the Instructions list with fully
|
CodeGenInstruction &CGI, ListInit *Pat, DAGInstMap &DAGInsts) {
|
||||||
/// resolved instructions.
|
|
||||||
void CodeGenDAGPatterns::ParseInstructions() {
|
|
||||||
std::vector<Record*> Instrs = Records.getAllDerivedDefinitions("Instruction");
|
|
||||||
|
|
||||||
for (unsigned i = 0, e = Instrs.size(); i != e; ++i) {
|
assert(!DAGInsts.count(CGI.TheDef) && "Instruction already parsed!");
|
||||||
ListInit *LI = 0;
|
|
||||||
|
|
||||||
if (isa<ListInit>(Instrs[i]->getValueInit("Pattern")))
|
|
||||||
LI = Instrs[i]->getValueAsListInit("Pattern");
|
|
||||||
|
|
||||||
// If there is no pattern, only collect minimal information about the
|
|
||||||
// instruction for its operand list. We have to assume that there is one
|
|
||||||
// result, as we have no detailed info. A pattern which references the
|
|
||||||
// null_frag operator is as-if no pattern were specified. Normally this
|
|
||||||
// is from a multiclass expansion w/ a SDPatternOperator passed in as
|
|
||||||
// null_frag.
|
|
||||||
if (!LI || LI->getSize() == 0 || hasNullFragReference(LI)) {
|
|
||||||
std::vector<Record*> Results;
|
|
||||||
std::vector<Record*> Operands;
|
|
||||||
|
|
||||||
CodeGenInstruction &InstInfo = Target.getInstruction(Instrs[i]);
|
|
||||||
|
|
||||||
if (InstInfo.Operands.size() != 0) {
|
|
||||||
if (InstInfo.Operands.NumDefs == 0) {
|
|
||||||
// These produce no results
|
|
||||||
for (unsigned j = 0, e = InstInfo.Operands.size(); j < e; ++j)
|
|
||||||
Operands.push_back(InstInfo.Operands[j].Rec);
|
|
||||||
} else {
|
|
||||||
// Assume the first operand is the result.
|
|
||||||
Results.push_back(InstInfo.Operands[0].Rec);
|
|
||||||
|
|
||||||
// The rest are inputs.
|
|
||||||
for (unsigned j = 1, e = InstInfo.Operands.size(); j < e; ++j)
|
|
||||||
Operands.push_back(InstInfo.Operands[j].Rec);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create and insert the instruction.
|
|
||||||
std::vector<Record*> ImpResults;
|
|
||||||
Instructions.insert(std::make_pair(Instrs[i],
|
|
||||||
DAGInstruction(0, Results, Operands, ImpResults)));
|
|
||||||
continue; // no pattern.
|
|
||||||
}
|
|
||||||
|
|
||||||
// Parse the instruction.
|
// Parse the instruction.
|
||||||
TreePattern *I = new TreePattern(Instrs[i], LI, true, *this);
|
TreePattern *I = new TreePattern(CGI.TheDef, Pat, true, *this);
|
||||||
// Inline pattern fragments into it.
|
// Inline pattern fragments into it.
|
||||||
I->InlinePatternFragments();
|
I->InlinePatternFragments();
|
||||||
|
|
||||||
@@ -2761,7 +2720,6 @@ void CodeGenDAGPatterns::ParseInstructions() {
|
|||||||
|
|
||||||
// Parse the operands list from the (ops) list, validating it.
|
// Parse the operands list from the (ops) list, validating it.
|
||||||
assert(I->getArgList().empty() && "Args list should still be empty here!");
|
assert(I->getArgList().empty() && "Args list should still be empty here!");
|
||||||
CodeGenInstruction &CGI = Target.getInstruction(Instrs[i]);
|
|
||||||
|
|
||||||
// Check that all of the results occur first in the list.
|
// Check that all of the results occur first in the list.
|
||||||
std::vector<Record*> Results;
|
std::vector<Record*> Results;
|
||||||
@@ -2860,18 +2818,70 @@ void CodeGenDAGPatterns::ParseInstructions() {
|
|||||||
// Create and insert the instruction.
|
// Create and insert the instruction.
|
||||||
// FIXME: InstImpResults should not be part of DAGInstruction.
|
// FIXME: InstImpResults should not be part of DAGInstruction.
|
||||||
DAGInstruction TheInst(I, Results, Operands, InstImpResults);
|
DAGInstruction TheInst(I, Results, Operands, InstImpResults);
|
||||||
Instructions.insert(std::make_pair(I->getRecord(), TheInst));
|
DAGInsts.insert(std::make_pair(I->getRecord(), TheInst));
|
||||||
|
|
||||||
// Use a temporary tree pattern to infer all types and make sure that the
|
// Use a temporary tree pattern to infer all types and make sure that the
|
||||||
// constructed result is correct. This depends on the instruction already
|
// constructed result is correct. This depends on the instruction already
|
||||||
// being inserted into the Instructions map.
|
// being inserted into the DAGInsts map.
|
||||||
TreePattern Temp(I->getRecord(), ResultPattern, false, *this);
|
TreePattern Temp(I->getRecord(), ResultPattern, false, *this);
|
||||||
Temp.InferAllTypes(&I->getNamedNodesMap());
|
Temp.InferAllTypes(&I->getNamedNodesMap());
|
||||||
|
|
||||||
DAGInstruction &TheInsertedInst = Instructions.find(I->getRecord())->second;
|
DAGInstruction &TheInsertedInst = DAGInsts.find(I->getRecord())->second;
|
||||||
TheInsertedInst.setResultPattern(Temp.getOnlyTree());
|
TheInsertedInst.setResultPattern(Temp.getOnlyTree());
|
||||||
|
|
||||||
DEBUG(I->dump());
|
return TheInsertedInst;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// ParseInstructions - Parse all of the instructions, inlining and resolving
|
||||||
|
/// any fragments involved. This populates the Instructions list with fully
|
||||||
|
/// resolved instructions.
|
||||||
|
void CodeGenDAGPatterns::ParseInstructions() {
|
||||||
|
std::vector<Record*> Instrs = Records.getAllDerivedDefinitions("Instruction");
|
||||||
|
|
||||||
|
for (unsigned i = 0, e = Instrs.size(); i != e; ++i) {
|
||||||
|
ListInit *LI = 0;
|
||||||
|
|
||||||
|
if (isa<ListInit>(Instrs[i]->getValueInit("Pattern")))
|
||||||
|
LI = Instrs[i]->getValueAsListInit("Pattern");
|
||||||
|
|
||||||
|
// If there is no pattern, only collect minimal information about the
|
||||||
|
// instruction for its operand list. We have to assume that there is one
|
||||||
|
// result, as we have no detailed info. A pattern which references the
|
||||||
|
// null_frag operator is as-if no pattern were specified. Normally this
|
||||||
|
// is from a multiclass expansion w/ a SDPatternOperator passed in as
|
||||||
|
// null_frag.
|
||||||
|
if (!LI || LI->getSize() == 0 || hasNullFragReference(LI)) {
|
||||||
|
std::vector<Record*> Results;
|
||||||
|
std::vector<Record*> Operands;
|
||||||
|
|
||||||
|
CodeGenInstruction &InstInfo = Target.getInstruction(Instrs[i]);
|
||||||
|
|
||||||
|
if (InstInfo.Operands.size() != 0) {
|
||||||
|
if (InstInfo.Operands.NumDefs == 0) {
|
||||||
|
// These produce no results
|
||||||
|
for (unsigned j = 0, e = InstInfo.Operands.size(); j < e; ++j)
|
||||||
|
Operands.push_back(InstInfo.Operands[j].Rec);
|
||||||
|
} else {
|
||||||
|
// Assume the first operand is the result.
|
||||||
|
Results.push_back(InstInfo.Operands[0].Rec);
|
||||||
|
|
||||||
|
// The rest are inputs.
|
||||||
|
for (unsigned j = 1, e = InstInfo.Operands.size(); j < e; ++j)
|
||||||
|
Operands.push_back(InstInfo.Operands[j].Rec);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create and insert the instruction.
|
||||||
|
std::vector<Record*> ImpResults;
|
||||||
|
Instructions.insert(std::make_pair(Instrs[i],
|
||||||
|
DAGInstruction(0, Results, Operands, ImpResults)));
|
||||||
|
continue; // no pattern.
|
||||||
|
}
|
||||||
|
|
||||||
|
CodeGenInstruction &CGI = Target.getInstruction(Instrs[i]);
|
||||||
|
const DAGInstruction &DI = parseInstructionPattern(CGI, LI, Instructions);
|
||||||
|
|
||||||
|
DEBUG(DI.getPattern()->dump());
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we can, convert the instructions to be patterns that are matched!
|
// If we can, convert the instructions to be patterns that are matched!
|
||||||
|
@@ -778,7 +778,11 @@ public:
|
|||||||
ptm_iterator ptm_begin() const { return PatternsToMatch.begin(); }
|
ptm_iterator ptm_begin() const { return PatternsToMatch.begin(); }
|
||||||
ptm_iterator ptm_end() const { return PatternsToMatch.end(); }
|
ptm_iterator ptm_end() const { return PatternsToMatch.end(); }
|
||||||
|
|
||||||
|
/// Parse the Pattern for an instruction, and insert the result in DAGInsts.
|
||||||
|
typedef std::map<Record*, DAGInstruction, LessRecordByID> DAGInstMap;
|
||||||
|
const DAGInstruction &parseInstructionPattern(
|
||||||
|
CodeGenInstruction &CGI, ListInit *Pattern,
|
||||||
|
DAGInstMap &DAGInsts);
|
||||||
|
|
||||||
const DAGInstruction &getInstruction(Record *R) const {
|
const DAGInstruction &getInstruction(Record *R) const {
|
||||||
assert(Instructions.count(R) && "Unknown instruction!");
|
assert(Instructions.count(R) && "Unknown instruction!");
|
||||||
|
Reference in New Issue
Block a user