mirror of
https://github.com/RPCS3/llvm.git
synced 2025-04-14 03:50:48 +00:00
* Commit the fix (by Chris) for a tblgen type inferencing bug.
* Enhanced tblgen to handle instructions which have chain operand and writes a chain result. * Enhanced tblgen to handle instructions which produces no results. Part of the change is a temporary hack which relies on instruction property (e.g. isReturn, isBranch). The proper fix would be to change the .td syntax to separate results dag from ops dag. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@24587 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
f8ac814957
commit
1c3d19eb15
@ -84,6 +84,7 @@ namespace llvm {
|
|||||||
bool hasDelaySlot;
|
bool hasDelaySlot;
|
||||||
bool usesCustomDAGSchedInserter;
|
bool usesCustomDAGSchedInserter;
|
||||||
bool hasVariableNumberOfOperands;
|
bool hasVariableNumberOfOperands;
|
||||||
|
bool hasCtrlDep;
|
||||||
|
|
||||||
CodeGenInstruction(Record *R, const std::string &AsmStr);
|
CodeGenInstruction(Record *R, const std::string &AsmStr);
|
||||||
|
|
||||||
|
@ -268,6 +268,7 @@ CodeGenInstruction::CodeGenInstruction(Record *R, const std::string &AsmStr)
|
|||||||
isTerminator = R->getValueAsBit("isTerminator");
|
isTerminator = R->getValueAsBit("isTerminator");
|
||||||
hasDelaySlot = R->getValueAsBit("hasDelaySlot");
|
hasDelaySlot = R->getValueAsBit("hasDelaySlot");
|
||||||
usesCustomDAGSchedInserter = R->getValueAsBit("usesCustomDAGSchedInserter");
|
usesCustomDAGSchedInserter = R->getValueAsBit("usesCustomDAGSchedInserter");
|
||||||
|
hasCtrlDep = R->getValueAsBit("hasCtrlDep");
|
||||||
hasVariableNumberOfOperands = false;
|
hasVariableNumberOfOperands = false;
|
||||||
|
|
||||||
DagInit *DI;
|
DagInit *DI;
|
||||||
|
@ -84,7 +84,8 @@ SDTypeConstraint::SDTypeConstraint(Record *R) {
|
|||||||
TreePatternNode *SDTypeConstraint::getOperandNum(unsigned OpNo,
|
TreePatternNode *SDTypeConstraint::getOperandNum(unsigned OpNo,
|
||||||
TreePatternNode *N,
|
TreePatternNode *N,
|
||||||
unsigned NumResults) const {
|
unsigned NumResults) const {
|
||||||
assert(NumResults == 1 && "We only work with single result nodes so far!");
|
assert(NumResults <= 1 &&
|
||||||
|
"We only work with nodes with zero or one result so far!");
|
||||||
|
|
||||||
if (OpNo < NumResults)
|
if (OpNo < NumResults)
|
||||||
return N; // FIXME: need value #
|
return N; // FIXME: need value #
|
||||||
@ -100,7 +101,8 @@ bool SDTypeConstraint::ApplyTypeConstraint(TreePatternNode *N,
|
|||||||
const SDNodeInfo &NodeInfo,
|
const SDNodeInfo &NodeInfo,
|
||||||
TreePattern &TP) const {
|
TreePattern &TP) const {
|
||||||
unsigned NumResults = NodeInfo.getNumResults();
|
unsigned NumResults = NodeInfo.getNumResults();
|
||||||
assert(NumResults == 1 && "We only work with single result nodes so far!");
|
assert(NumResults <= 1 &&
|
||||||
|
"We only work with nodes with zero or one result so far!");
|
||||||
|
|
||||||
// Check that the number of operands is sane.
|
// Check that the number of operands is sane.
|
||||||
if (NodeInfo.getNumOperands() >= 0) {
|
if (NodeInfo.getNumOperands() >= 0) {
|
||||||
@ -234,6 +236,8 @@ SDNodeInfo::SDNodeInfo(Record *R) : Def(R) {
|
|||||||
Properties |= 1 << SDNPCommutative;
|
Properties |= 1 << SDNPCommutative;
|
||||||
} else if (PropList[i]->getName() == "SDNPAssociative") {
|
} else if (PropList[i]->getName() == "SDNPAssociative") {
|
||||||
Properties |= 1 << SDNPAssociative;
|
Properties |= 1 << SDNPAssociative;
|
||||||
|
} else if (PropList[i]->getName() == "SDNPHasChain") {
|
||||||
|
Properties |= 1 << SDNPHasChain;
|
||||||
} else {
|
} else {
|
||||||
std::cerr << "Unknown SD Node property '" << PropList[i]->getName()
|
std::cerr << "Unknown SD Node property '" << PropList[i]->getName()
|
||||||
<< "' on node '" << R->getName() << "'!\n";
|
<< "' on node '" << R->getName() << "'!\n";
|
||||||
@ -440,6 +444,7 @@ TreePatternNode *TreePatternNode::InlinePatternFragments(TreePattern &TP) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
FragTree->setName(getName());
|
FragTree->setName(getName());
|
||||||
|
FragTree->UpdateNodeType(getExtType(), TP);
|
||||||
|
|
||||||
// Get a new copy of this fragment to stitch into here.
|
// Get a new copy of this fragment to stitch into here.
|
||||||
//delete this; // FIXME: implement refcounting!
|
//delete this; // FIXME: implement refcounting!
|
||||||
@ -526,22 +531,33 @@ bool TreePatternNode::ApplyTypeConstraints(TreePattern &TP, bool NotRegisters) {
|
|||||||
bool MadeChange = NI.ApplyTypeConstraints(this, TP);
|
bool MadeChange = NI.ApplyTypeConstraints(this, TP);
|
||||||
for (unsigned i = 0, e = getNumChildren(); i != e; ++i)
|
for (unsigned i = 0, e = getNumChildren(); i != e; ++i)
|
||||||
MadeChange |= getChild(i)->ApplyTypeConstraints(TP, NotRegisters);
|
MadeChange |= getChild(i)->ApplyTypeConstraints(TP, NotRegisters);
|
||||||
|
// Branch, etc. do not produce results and top-level forms in instr pattern
|
||||||
|
// must have void types.
|
||||||
|
if (NI.getNumResults() == 0)
|
||||||
|
MadeChange |= UpdateNodeType(MVT::isVoid, TP);
|
||||||
return MadeChange;
|
return MadeChange;
|
||||||
} else if (getOperator()->isSubClassOf("Instruction")) {
|
} else if (getOperator()->isSubClassOf("Instruction")) {
|
||||||
const DAGInstruction &Inst =
|
const DAGInstruction &Inst =
|
||||||
TP.getDAGISelEmitter().getInstruction(getOperator());
|
TP.getDAGISelEmitter().getInstruction(getOperator());
|
||||||
|
bool MadeChange = false;
|
||||||
|
unsigned NumResults = Inst.getNumResults();
|
||||||
|
|
||||||
assert(Inst.getNumResults() == 1 && "Only supports one result instrs!");
|
assert(NumResults <= 1 &&
|
||||||
|
"Only supports zero or one result instrs!");
|
||||||
// Apply the result type to the node
|
// Apply the result type to the node
|
||||||
Record *ResultNode = Inst.getResult(0);
|
if (NumResults == 0) {
|
||||||
assert(ResultNode->isSubClassOf("RegisterClass") &&
|
MadeChange = UpdateNodeType(MVT::isVoid, TP);
|
||||||
"Operands should be register classes!");
|
} else {
|
||||||
|
Record *ResultNode = Inst.getResult(0);
|
||||||
|
assert(ResultNode->isSubClassOf("RegisterClass") &&
|
||||||
|
"Operands should be register classes!");
|
||||||
|
|
||||||
const CodeGenRegisterClass &RC =
|
const CodeGenRegisterClass &RC =
|
||||||
TP.getDAGISelEmitter().getTargetInfo().getRegisterClass(ResultNode);
|
TP.getDAGISelEmitter().getTargetInfo().getRegisterClass(ResultNode);
|
||||||
|
|
||||||
// Get the first ValueType in the RegClass, it's as good as any.
|
// Get the first ValueType in the RegClass, it's as good as any.
|
||||||
bool MadeChange = UpdateNodeType(RC.getValueTypeNum(0), TP);
|
MadeChange = UpdateNodeType(RC.getValueTypeNum(0), TP);
|
||||||
|
}
|
||||||
|
|
||||||
if (getNumChildren() != Inst.getNumOperands())
|
if (getNumChildren() != Inst.getNumOperands())
|
||||||
TP.error("Instruction '" + getOperator()->getName() + " expects " +
|
TP.error("Instruction '" + getOperator()->getName() + " expects " +
|
||||||
@ -655,8 +671,7 @@ TreePatternNode *TreePattern::ParseTreePattern(DagInit *Dag) {
|
|||||||
Dag->setArg(0, new DagInit(R,
|
Dag->setArg(0, new DagInit(R,
|
||||||
std::vector<std::pair<Init*, std::string> >()));
|
std::vector<std::pair<Init*, std::string> >()));
|
||||||
return ParseTreePattern(Dag);
|
return ParseTreePattern(Dag);
|
||||||
}
|
}
|
||||||
|
|
||||||
New = new TreePatternNode(DI);
|
New = new TreePatternNode(DI);
|
||||||
} else if (DagInit *DI = dynamic_cast<DagInit*>(Arg)) {
|
} else if (DagInit *DI = dynamic_cast<DagInit*>(Arg)) {
|
||||||
New = ParseTreePattern(DI);
|
New = ParseTreePattern(DI);
|
||||||
@ -1052,13 +1067,21 @@ void DAGISelEmitter::ParseInstructions() {
|
|||||||
// Doesn't even define a result?
|
// Doesn't even define a result?
|
||||||
if (InstInfo.OperandList.size() == 0)
|
if (InstInfo.OperandList.size() == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
// FIXME: temporary hack...
|
||||||
|
if (InstInfo.isReturn || InstInfo.isBranch || InstInfo.isCall ||
|
||||||
|
InstInfo.isStore) {
|
||||||
|
// These produce no results
|
||||||
|
for (unsigned j = 0, e = InstInfo.OperandList.size(); j != e; ++j)
|
||||||
|
Operands.push_back(InstInfo.OperandList[j].Rec);
|
||||||
|
} else {
|
||||||
|
// Assume the first operand is the result.
|
||||||
|
Results.push_back(InstInfo.OperandList[0].Rec);
|
||||||
|
|
||||||
// Assume the first operand is the result.
|
// The rest are inputs.
|
||||||
Results.push_back(InstInfo.OperandList[0].Rec);
|
for (unsigned j = 1, e = InstInfo.OperandList.size(); j != e; ++j)
|
||||||
|
Operands.push_back(InstInfo.OperandList[j].Rec);
|
||||||
// The rest are inputs.
|
}
|
||||||
for (unsigned j = 1, e = InstInfo.OperandList.size(); j != e; ++j)
|
|
||||||
Operands.push_back(InstInfo.OperandList[j].Rec);
|
|
||||||
|
|
||||||
// Create and insert the instruction.
|
// Create and insert the instruction.
|
||||||
Instructions.insert(std::make_pair(Instrs[i],
|
Instructions.insert(std::make_pair(Instrs[i],
|
||||||
@ -1088,11 +1111,9 @@ void DAGISelEmitter::ParseInstructions() {
|
|||||||
// fill in the InstResults map.
|
// fill in the InstResults map.
|
||||||
for (unsigned j = 0, e = I->getNumTrees(); j != e; ++j) {
|
for (unsigned j = 0, e = I->getNumTrees(); j != e; ++j) {
|
||||||
TreePatternNode *Pat = I->getTree(j);
|
TreePatternNode *Pat = I->getTree(j);
|
||||||
if (Pat->getExtType() != MVT::isVoid) {
|
if (Pat->getExtType() != MVT::isVoid)
|
||||||
I->dump();
|
|
||||||
I->error("Top-level forms in instruction pattern should have"
|
I->error("Top-level forms in instruction pattern should have"
|
||||||
" void types");
|
" void types");
|
||||||
}
|
|
||||||
|
|
||||||
// Find inputs and outputs, and verify the structure of the uses/defs.
|
// Find inputs and outputs, and verify the structure of the uses/defs.
|
||||||
FindPatternInputsAndOutputs(I, Pat, InstInputs, InstResults);
|
FindPatternInputsAndOutputs(I, Pat, InstInputs, InstResults);
|
||||||
@ -1201,7 +1222,8 @@ void DAGISelEmitter::ParseInstructions() {
|
|||||||
// If we can, convert the instructions to be patterns that are matched!
|
// If we can, convert the instructions to be patterns that are matched!
|
||||||
for (std::map<Record*, DAGInstruction>::iterator II = Instructions.begin(),
|
for (std::map<Record*, DAGInstruction>::iterator II = Instructions.begin(),
|
||||||
E = Instructions.end(); II != E; ++II) {
|
E = Instructions.end(); II != E; ++II) {
|
||||||
TreePattern *I = II->second.getPattern();
|
DAGInstruction &TheInst = II->second;
|
||||||
|
TreePattern *I = TheInst.getPattern();
|
||||||
if (I == 0) continue; // No pattern.
|
if (I == 0) continue; // No pattern.
|
||||||
|
|
||||||
if (I->getNumTrees() != 1) {
|
if (I->getNumTrees() != 1) {
|
||||||
@ -1209,19 +1231,24 @@ void DAGISelEmitter::ParseInstructions() {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
TreePatternNode *Pattern = I->getTree(0);
|
TreePatternNode *Pattern = I->getTree(0);
|
||||||
if (Pattern->getOperator()->getName() != "set")
|
TreePatternNode *SrcPattern;
|
||||||
continue; // Not a set (store or something?)
|
if (TheInst.getNumResults() == 0) {
|
||||||
|
SrcPattern = Pattern;
|
||||||
|
} else {
|
||||||
|
if (Pattern->getOperator()->getName() != "set")
|
||||||
|
continue; // Not a set (store or something?)
|
||||||
|
|
||||||
if (Pattern->getNumChildren() != 2)
|
if (Pattern->getNumChildren() != 2)
|
||||||
continue; // Not a set of a single value (not handled so far)
|
continue; // Not a set of a single value (not handled so far)
|
||||||
|
|
||||||
TreePatternNode *SrcPattern = Pattern->getChild(1)->clone();
|
SrcPattern = Pattern->getChild(1)->clone();
|
||||||
|
}
|
||||||
|
|
||||||
std::string Reason;
|
std::string Reason;
|
||||||
if (!SrcPattern->canPatternMatch(Reason, *this))
|
if (!SrcPattern->canPatternMatch(Reason, *this))
|
||||||
I->error("Instruction can never match: " + Reason);
|
I->error("Instruction can never match: " + Reason);
|
||||||
|
|
||||||
TreePatternNode *DstPattern = II->second.getResultPattern();
|
TreePatternNode *DstPattern = TheInst.getResultPattern();
|
||||||
PatternsToMatch.push_back(std::make_pair(SrcPattern, DstPattern));
|
PatternsToMatch.push_back(std::make_pair(SrcPattern, DstPattern));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1527,8 +1554,8 @@ void DAGISelEmitter::GenerateVariants() {
|
|||||||
/// pattern.
|
/// pattern.
|
||||||
static unsigned getPatternSize(TreePatternNode *P) {
|
static unsigned getPatternSize(TreePatternNode *P) {
|
||||||
assert(isExtIntegerVT(P->getExtType()) ||
|
assert(isExtIntegerVT(P->getExtType()) ||
|
||||||
isExtFloatingPointVT(P->getExtType()) &&
|
isExtFloatingPointVT(P->getExtType()) ||
|
||||||
"Not a valid pattern node to size!");
|
P->getExtType() == MVT::isVoid && "Not a valid pattern node to size!");
|
||||||
unsigned Size = 1; // The node itself.
|
unsigned Size = 1; // The node itself.
|
||||||
|
|
||||||
// Count children in the count if they are also nodes.
|
// Count children in the count if they are also nodes.
|
||||||
@ -1572,13 +1599,24 @@ struct PatternSortingPredicate {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// nodeHasChain - return true if TreePatternNode has the property
|
||||||
|
/// 'hasChain', meaning it reads a ctrl-flow chain operand and writes
|
||||||
|
/// a chain result.
|
||||||
|
static bool nodeHasChain(TreePatternNode *N, DAGISelEmitter &ISE)
|
||||||
|
{
|
||||||
|
if (N->isLeaf()) return false;
|
||||||
|
|
||||||
|
const SDNodeInfo &NodeInfo = ISE.getSDNodeInfo(N->getOperator());
|
||||||
|
return NodeInfo.hasProperty(SDNodeInfo::SDNPHasChain);
|
||||||
|
}
|
||||||
|
|
||||||
/// EmitMatchForPattern - Emit a matcher for N, going to the label for PatternNo
|
/// EmitMatchForPattern - Emit a matcher for N, going to the label for PatternNo
|
||||||
/// if the match fails. At this point, we already know that the opcode for N
|
/// if the match fails. At this point, we already know that the opcode for N
|
||||||
/// matches, and the SDNode for the result has the RootName specified name.
|
/// matches, and the SDNode for the result has the RootName specified name.
|
||||||
void DAGISelEmitter::EmitMatchForPattern(TreePatternNode *N,
|
void DAGISelEmitter::EmitMatchForPattern(TreePatternNode *N,
|
||||||
const std::string &RootName,
|
const std::string &RootName,
|
||||||
std::map<std::string,std::string> &VarMap,
|
std::map<std::string,std::string> &VarMap,
|
||||||
unsigned PatternNo, std::ostream &OS) {
|
unsigned PatternNo,std::ostream &OS) {
|
||||||
if (N->isLeaf()) {
|
if (N->isLeaf()) {
|
||||||
if (IntInit *II = dynamic_cast<IntInit*>(N->getLeafValue())) {
|
if (IntInit *II = dynamic_cast<IntInit*>(N->getLeafValue())) {
|
||||||
OS << " if (cast<ConstantSDNode>(" << RootName
|
OS << " if (cast<ConstantSDNode>(" << RootName
|
||||||
@ -1606,32 +1644,35 @@ void DAGISelEmitter::EmitMatchForPattern(TreePatternNode *N,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Emit code to load the child nodes and match their contents recursively.
|
// Emit code to load the child nodes and match their contents recursively.
|
||||||
for (unsigned i = 0, e = N->getNumChildren(); i != e; ++i) {
|
unsigned OpNo = (unsigned) nodeHasChain(N, *this);
|
||||||
OS << " SDOperand " << RootName << i <<" = " << RootName
|
for (unsigned i = 0, e = N->getNumChildren(); i != e; ++i, ++OpNo) {
|
||||||
<< ".getOperand(" << i << ");\n";
|
OS << " SDOperand " << RootName << OpNo <<" = " << RootName
|
||||||
|
<< ".getOperand(" << OpNo << ");\n";
|
||||||
TreePatternNode *Child = N->getChild(i);
|
TreePatternNode *Child = N->getChild(i);
|
||||||
|
|
||||||
if (!Child->isLeaf()) {
|
if (!Child->isLeaf()) {
|
||||||
// If it's not a leaf, recursively match.
|
// If it's not a leaf, recursively match.
|
||||||
const SDNodeInfo &CInfo = getSDNodeInfo(Child->getOperator());
|
const SDNodeInfo &CInfo = getSDNodeInfo(Child->getOperator());
|
||||||
OS << " if (" << RootName << i << ".getOpcode() != "
|
OS << " if (" << RootName << OpNo << ".getOpcode() != "
|
||||||
<< CInfo.getEnumName() << ") goto P" << PatternNo << "Fail;\n";
|
<< CInfo.getEnumName() << ") goto P" << PatternNo << "Fail;\n";
|
||||||
EmitMatchForPattern(Child, RootName + utostr(i), VarMap, PatternNo, OS);
|
EmitMatchForPattern(Child, RootName + utostr(OpNo), VarMap, PatternNo,
|
||||||
|
OS);
|
||||||
} else {
|
} else {
|
||||||
// If this child has a name associated with it, capture it in VarMap. If
|
// If this child has a name associated with it, capture it in VarMap. If
|
||||||
// we already saw this in the pattern, emit code to verify dagness.
|
// we already saw this in the pattern, emit code to verify dagness.
|
||||||
if (!Child->getName().empty()) {
|
if (!Child->getName().empty()) {
|
||||||
std::string &VarMapEntry = VarMap[Child->getName()];
|
std::string &VarMapEntry = VarMap[Child->getName()];
|
||||||
if (VarMapEntry.empty()) {
|
if (VarMapEntry.empty()) {
|
||||||
VarMapEntry = RootName + utostr(i);
|
VarMapEntry = RootName + utostr(OpNo);
|
||||||
} else {
|
} else {
|
||||||
// If we get here, this is a second reference to a specific name. Since
|
// If we get here, this is a second reference to a specific name. Since
|
||||||
// we already have checked that the first reference is valid, we don't
|
// we already have checked that the first reference is valid, we don't
|
||||||
// have to recursively match it, just check that it's the same as the
|
// have to recursively match it, just check that it's the same as the
|
||||||
// previously named thing.
|
// previously named thing.
|
||||||
OS << " if (" << VarMapEntry << " != " << RootName << i
|
OS << " if (" << VarMapEntry << " != " << RootName << OpNo
|
||||||
<< ") goto P" << PatternNo << "Fail;\n";
|
<< ") goto P" << PatternNo << "Fail;\n";
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -1645,12 +1686,12 @@ void DAGISelEmitter::EmitMatchForPattern(TreePatternNode *N,
|
|||||||
// Handle register references. Nothing to do here.
|
// Handle register references. Nothing to do here.
|
||||||
} else if (LeafRec->isSubClassOf("ValueType")) {
|
} else if (LeafRec->isSubClassOf("ValueType")) {
|
||||||
// Make sure this is the specified value type.
|
// Make sure this is the specified value type.
|
||||||
OS << " if (cast<VTSDNode>(" << RootName << i << ")->getVT() != "
|
OS << " if (cast<VTSDNode>(" << RootName << OpNo << ")->getVT() != "
|
||||||
<< "MVT::" << LeafRec->getName() << ") goto P" << PatternNo
|
<< "MVT::" << LeafRec->getName() << ") goto P" << PatternNo
|
||||||
<< "Fail;\n";
|
<< "Fail;\n";
|
||||||
} else if (LeafRec->isSubClassOf("CondCode")) {
|
} else if (LeafRec->isSubClassOf("CondCode")) {
|
||||||
// Make sure this is the specified cond code.
|
// Make sure this is the specified cond code.
|
||||||
OS << " if (cast<CondCodeSDNode>(" << RootName << i
|
OS << " if (cast<CondCodeSDNode>(" << RootName << OpNo
|
||||||
<< ")->get() != " << "ISD::" << LeafRec->getName()
|
<< ")->get() != " << "ISD::" << LeafRec->getName()
|
||||||
<< ") goto P" << PatternNo << "Fail;\n";
|
<< ") goto P" << PatternNo << "Fail;\n";
|
||||||
} else {
|
} else {
|
||||||
@ -1658,8 +1699,8 @@ void DAGISelEmitter::EmitMatchForPattern(TreePatternNode *N,
|
|||||||
assert(0 && "Unknown leaf type!");
|
assert(0 && "Unknown leaf type!");
|
||||||
}
|
}
|
||||||
} else if (IntInit *II = dynamic_cast<IntInit*>(Child->getLeafValue())) {
|
} else if (IntInit *II = dynamic_cast<IntInit*>(Child->getLeafValue())) {
|
||||||
OS << " if (!isa<ConstantSDNode>(" << RootName << i << ") ||\n"
|
OS << " if (!isa<ConstantSDNode>(" << RootName << OpNo << ") ||\n"
|
||||||
<< " cast<ConstantSDNode>(" << RootName << i
|
<< " cast<ConstantSDNode>(" << RootName << OpNo
|
||||||
<< ")->getSignExtended() != " << II->getValue() << ")\n"
|
<< ")->getSignExtended() != " << II->getValue() << ")\n"
|
||||||
<< " goto P" << PatternNo << "Fail;\n";
|
<< " goto P" << PatternNo << "Fail;\n";
|
||||||
} else {
|
} else {
|
||||||
@ -1668,7 +1709,7 @@ void DAGISelEmitter::EmitMatchForPattern(TreePatternNode *N,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If there is a node predicate for this, emit the call.
|
// If there is a node predicate for this, emit the call.
|
||||||
if (!N->getPredicateFn().empty())
|
if (!N->getPredicateFn().empty())
|
||||||
OS << " if (!" << N->getPredicateFn() << "(" << RootName
|
OS << " if (!" << N->getPredicateFn() << "(" << RootName
|
||||||
@ -1694,30 +1735,69 @@ static MVT::ValueType getRegisterValueType(Record *R, const CodeGenTarget &T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// EmitLeadChainForPattern - Emit the flag operands for the DAG that will be
|
||||||
|
/// built in CodeGenPatternResult.
|
||||||
|
void DAGISelEmitter::EmitLeadChainForPattern(TreePatternNode *N,
|
||||||
|
const std::string &RootName,
|
||||||
|
std::ostream &OS,
|
||||||
|
bool &HasChain) {
|
||||||
|
if (!N->isLeaf()) {
|
||||||
|
Record *Op = N->getOperator();
|
||||||
|
if (Op->isSubClassOf("Instruction")) {
|
||||||
|
bool HasCtrlDep = Op->getValueAsBit("hasCtrlDep");
|
||||||
|
unsigned OpNo = (unsigned) HasCtrlDep;
|
||||||
|
for (unsigned i = 0, e = N->getNumChildren(); i != e; ++i)
|
||||||
|
EmitLeadChainForPattern(N->getChild(i), RootName + utostr(OpNo),
|
||||||
|
OS, HasChain);
|
||||||
|
|
||||||
|
if (!HasChain && HasCtrlDep) {
|
||||||
|
OS << " SDOperand Chain = Select("
|
||||||
|
<< RootName << ".getOperand(0));\n";
|
||||||
|
HasChain = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// EmitCopyToRegsForPattern - Emit the flag operands for the DAG that will be
|
/// EmitCopyToRegsForPattern - Emit the flag operands for the DAG that will be
|
||||||
/// built in CodeGenPatternResult.
|
/// built in CodeGenPatternResult.
|
||||||
void DAGISelEmitter::EmitCopyToRegsForPattern(TreePatternNode *N,
|
void DAGISelEmitter::EmitCopyToRegsForPattern(TreePatternNode *N,
|
||||||
const std::string &RootName,
|
const std::string &RootName,
|
||||||
std::ostream &OS, bool &InFlag) {
|
std::ostream &OS,
|
||||||
|
bool &HasChain, bool &InFlag) {
|
||||||
const CodeGenTarget &T = getTargetInfo();
|
const CodeGenTarget &T = getTargetInfo();
|
||||||
for (unsigned i = 0, e = N->getNumChildren(); i != e; ++i) {
|
unsigned OpNo = (unsigned) nodeHasChain(N, *this);
|
||||||
|
for (unsigned i = 0, e = N->getNumChildren(); i != e; ++i, ++OpNo) {
|
||||||
TreePatternNode *Child = N->getChild(i);
|
TreePatternNode *Child = N->getChild(i);
|
||||||
if (!Child->isLeaf()) {
|
if (!Child->isLeaf()) {
|
||||||
EmitCopyToRegsForPattern(Child, RootName + utostr(i), OS, InFlag);
|
EmitCopyToRegsForPattern(Child, RootName + utostr(OpNo), OS, HasChain,
|
||||||
|
InFlag);
|
||||||
} else {
|
} else {
|
||||||
if (DefInit *DI = dynamic_cast<DefInit*>(Child->getLeafValue())) {
|
if (DefInit *DI = dynamic_cast<DefInit*>(Child->getLeafValue())) {
|
||||||
Record *RR = DI->getDef();
|
Record *RR = DI->getDef();
|
||||||
if (RR->isSubClassOf("Register")) {
|
if (RR->isSubClassOf("Register")) {
|
||||||
MVT::ValueType RVT = getRegisterValueType(RR, T);
|
MVT::ValueType RVT = getRegisterValueType(RR, T);
|
||||||
if (!InFlag) {
|
if (!InFlag) {
|
||||||
OS << " SDOperand InFlag; // Null incoming flag value.\n";
|
OS << " SDOperand InFlag;\n";
|
||||||
InFlag = true;
|
InFlag = true;
|
||||||
}
|
}
|
||||||
OS << " InFlag = CurDAG->getCopyToReg(CurDAG->getEntryNode()"
|
if (HasChain) {
|
||||||
<< ", CurDAG->getRegister(" << getQualifiedName(RR)
|
OS << " SDOperand " << RootName << "CR" << i << ";\n";
|
||||||
<< ", MVT::" << getEnumName(RVT) << ")"
|
OS << " " << RootName << "CR" << i
|
||||||
<< ", " << RootName << i << ", InFlag).getValue(1);\n";
|
<< " = CurDAG->getCopyToReg(Chain, CurDAG->getRegister("
|
||||||
|
<< getQualifiedName(RR) << ", MVT::" << getEnumName(RVT) << ")"
|
||||||
|
<< ", Select(" << RootName << OpNo << "), InFlag);\n";
|
||||||
|
OS << " Chain = " << RootName << "CR" << i
|
||||||
|
<< ".getValue(0);\n";
|
||||||
|
OS << " InFlag = " << RootName << "CR" << i
|
||||||
|
<< ".getValue(1);\n";
|
||||||
|
} else {
|
||||||
|
OS << " InFlag = CurDAG->getCopyToReg(CurDAG->getEntryNode()"
|
||||||
|
<< ", CurDAG->getRegister(" << getQualifiedName(RR)
|
||||||
|
<< ", MVT::" << getEnumName(RVT) << ")"
|
||||||
|
<< ", Select(" << RootName << OpNo
|
||||||
|
<< "), InFlag).getValue(1);\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1729,7 +1809,8 @@ void DAGISelEmitter::EmitCopyToRegsForPattern(TreePatternNode *N,
|
|||||||
unsigned DAGISelEmitter::
|
unsigned DAGISelEmitter::
|
||||||
CodeGenPatternResult(TreePatternNode *N, unsigned &Ctr,
|
CodeGenPatternResult(TreePatternNode *N, unsigned &Ctr,
|
||||||
std::map<std::string,std::string> &VariableMap,
|
std::map<std::string,std::string> &VariableMap,
|
||||||
std::ostream &OS, bool InFlag, bool isRoot) {
|
std::ostream &OS, bool &HasChain, bool InFlag,
|
||||||
|
bool isRoot) {
|
||||||
// This is something selected from the pattern we matched.
|
// This is something selected from the pattern we matched.
|
||||||
if (!N->getName().empty()) {
|
if (!N->getName().empty()) {
|
||||||
assert(!isRoot && "Root of pattern cannot be a leaf!");
|
assert(!isRoot && "Root of pattern cannot be a leaf!");
|
||||||
@ -1792,22 +1873,61 @@ CodeGenPatternResult(TreePatternNode *N, unsigned &Ctr,
|
|||||||
|
|
||||||
Record *Op = N->getOperator();
|
Record *Op = N->getOperator();
|
||||||
if (Op->isSubClassOf("Instruction")) {
|
if (Op->isSubClassOf("Instruction")) {
|
||||||
|
bool HasCtrlDep = Op->getValueAsBit("hasCtrlDep");
|
||||||
|
|
||||||
// Emit all of the operands.
|
// Emit all of the operands.
|
||||||
std::vector<unsigned> Ops;
|
std::vector<unsigned> Ops;
|
||||||
for (unsigned i = 0, e = N->getNumChildren(); i != e; ++i)
|
for (unsigned i = 0, e = N->getNumChildren(); i != e; ++i)
|
||||||
Ops.push_back(CodeGenPatternResult(N->getChild(i),
|
Ops.push_back(CodeGenPatternResult(N->getChild(i), Ctr,
|
||||||
Ctr, VariableMap, OS, InFlag));
|
VariableMap, OS, HasChain, InFlag));
|
||||||
|
|
||||||
CodeGenInstruction &II = Target.getInstruction(Op->getName());
|
CodeGenInstruction &II = Target.getInstruction(Op->getName());
|
||||||
unsigned ResNo = Ctr++;
|
unsigned ResNo = Ctr++;
|
||||||
|
|
||||||
|
const DAGInstruction &Inst = getInstruction(Op);
|
||||||
|
unsigned NumResults = Inst.getNumResults();
|
||||||
|
|
||||||
if (!isRoot) {
|
if (!isRoot) {
|
||||||
OS << " SDOperand Tmp" << ResNo << " = CurDAG->getTargetNode("
|
OS << " SDOperand Tmp" << ResNo << " = CurDAG->getTargetNode("
|
||||||
<< II.Namespace << "::" << II.TheDef->getName() << ", MVT::"
|
<< II.Namespace << "::" << II.TheDef->getName() << ", MVT::"
|
||||||
<< getEnumName(N->getType());
|
<< getEnumName(N->getType());
|
||||||
|
unsigned LastOp = 0;
|
||||||
|
for (unsigned i = 0, e = Ops.size(); i != e; ++i) {
|
||||||
|
LastOp = Ops[i];
|
||||||
|
OS << ", Tmp" << LastOp;
|
||||||
|
}
|
||||||
|
OS << ");\n";
|
||||||
|
if (HasCtrlDep) {
|
||||||
|
// Must have at least one result
|
||||||
|
OS << " Chain = Tmp" << LastOp << ".getValue("
|
||||||
|
<< NumResults << ");\n";
|
||||||
|
}
|
||||||
|
} else if (HasCtrlDep) {
|
||||||
|
if (NumResults > 0)
|
||||||
|
OS << " SDOperand Result = ";
|
||||||
|
else
|
||||||
|
OS << " Chain = CodeGenMap[N] = ";
|
||||||
|
OS << "CurDAG->getTargetNode("
|
||||||
|
<< II.Namespace << "::" << II.TheDef->getName();
|
||||||
|
if (NumResults > 0)
|
||||||
|
OS << ", MVT::" << getEnumName(N->getType()); // TODO: multiple results?
|
||||||
|
OS << ", MVT::Other";
|
||||||
for (unsigned i = 0, e = Ops.size(); i != e; ++i)
|
for (unsigned i = 0, e = Ops.size(); i != e; ++i)
|
||||||
OS << ", Tmp" << Ops[i];
|
OS << ", Tmp" << Ops[i];
|
||||||
|
OS << ", Chain";
|
||||||
|
if (InFlag)
|
||||||
|
OS << ", InFlag";
|
||||||
OS << ");\n";
|
OS << ");\n";
|
||||||
|
if (NumResults > 0) {
|
||||||
|
OS << " CodeGenMap[N.getValue(0)] = Result;\n";
|
||||||
|
OS << " CodeGenMap[N.getValue(" << NumResults
|
||||||
|
<< ")] = Result.getValue(" << NumResults << ");\n";
|
||||||
|
OS << " Chain = CodeGenMap[N].getValue(" << NumResults << ");\n";
|
||||||
|
}
|
||||||
|
if (NumResults == 0)
|
||||||
|
OS << " return Chain;\n";
|
||||||
|
else
|
||||||
|
OS << " return (N.ResNo) ? Chain : CodeGenMap[N];\n";
|
||||||
} else {
|
} else {
|
||||||
// If this instruction is the root, and if there is only one use of it,
|
// If this instruction is the root, and if there is only one use of it,
|
||||||
// use SelectNodeTo instead of getTargetNode to avoid an allocation.
|
// use SelectNodeTo instead of getTargetNode to avoid an allocation.
|
||||||
@ -1822,8 +1942,8 @@ CodeGenPatternResult(TreePatternNode *N, unsigned &Ctr,
|
|||||||
OS << ");\n";
|
OS << ");\n";
|
||||||
OS << " } else {\n";
|
OS << " } else {\n";
|
||||||
OS << " return CodeGenMap[N] = CurDAG->getTargetNode("
|
OS << " return CodeGenMap[N] = CurDAG->getTargetNode("
|
||||||
<< II.Namespace << "::" << II.TheDef->getName() << ", MVT::"
|
<< II.Namespace << "::" << II.TheDef->getName() << ", MVT::"
|
||||||
<< getEnumName(N->getType());
|
<< getEnumName(N->getType());
|
||||||
for (unsigned i = 0, e = Ops.size(); i != e; ++i)
|
for (unsigned i = 0, e = Ops.size(); i != e; ++i)
|
||||||
OS << ", Tmp" << Ops[i];
|
OS << ", Tmp" << Ops[i];
|
||||||
if (InFlag)
|
if (InFlag)
|
||||||
@ -1834,8 +1954,8 @@ CodeGenPatternResult(TreePatternNode *N, unsigned &Ctr,
|
|||||||
return ResNo;
|
return ResNo;
|
||||||
} else if (Op->isSubClassOf("SDNodeXForm")) {
|
} else if (Op->isSubClassOf("SDNodeXForm")) {
|
||||||
assert(N->getNumChildren() == 1 && "node xform should have one child!");
|
assert(N->getNumChildren() == 1 && "node xform should have one child!");
|
||||||
unsigned OpVal = CodeGenPatternResult(N->getChild(0),
|
unsigned OpVal = CodeGenPatternResult(N->getChild(0), Ctr,
|
||||||
Ctr, VariableMap, OS, InFlag);
|
VariableMap, OS, HasChain, InFlag);
|
||||||
|
|
||||||
unsigned ResNo = Ctr++;
|
unsigned ResNo = Ctr++;
|
||||||
OS << " SDOperand Tmp" << ResNo << " = Transform_" << Op->getName()
|
OS << " SDOperand Tmp" << ResNo << " = Transform_" << Op->getName()
|
||||||
@ -1866,6 +1986,7 @@ static void RemoveAllTypes(TreePatternNode *N) {
|
|||||||
/// 'Pat' may be missing types. If we find an unresolved type to add a check
|
/// 'Pat' may be missing types. If we find an unresolved type to add a check
|
||||||
/// for, this returns true otherwise false if Pat has all types.
|
/// for, this returns true otherwise false if Pat has all types.
|
||||||
static bool InsertOneTypeCheck(TreePatternNode *Pat, TreePatternNode *Other,
|
static bool InsertOneTypeCheck(TreePatternNode *Pat, TreePatternNode *Other,
|
||||||
|
DAGISelEmitter &ISE,
|
||||||
const std::string &Prefix, unsigned PatternNo,
|
const std::string &Prefix, unsigned PatternNo,
|
||||||
std::ostream &OS) {
|
std::ostream &OS) {
|
||||||
// Did we find one?
|
// Did we find one?
|
||||||
@ -1879,9 +2000,10 @@ static bool InsertOneTypeCheck(TreePatternNode *Pat, TreePatternNode *Other,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (unsigned i = 0, e = Pat->getNumChildren(); i != e; ++i)
|
unsigned OpNo = (unsigned) nodeHasChain(Pat, ISE);
|
||||||
|
for (unsigned i = 0, e = Pat->getNumChildren(); i != e; ++i, ++OpNo)
|
||||||
if (InsertOneTypeCheck(Pat->getChild(i), Other->getChild(i),
|
if (InsertOneTypeCheck(Pat->getChild(i), Other->getChild(i),
|
||||||
Prefix + utostr(i), PatternNo, OS))
|
ISE, Prefix + utostr(OpNo), PatternNo, OS))
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -1944,14 +2066,17 @@ void DAGISelEmitter::EmitCodeForPattern(PatternToMatch &Pattern,
|
|||||||
// Insert a check for an unresolved type and add it to the tree. If we find
|
// Insert a check for an unresolved type and add it to the tree. If we find
|
||||||
// an unresolved type to add a check for, this returns true and we iterate,
|
// an unresolved type to add a check for, this returns true and we iterate,
|
||||||
// otherwise we are done.
|
// otherwise we are done.
|
||||||
} while (InsertOneTypeCheck(Pat, Pattern.first, "N", PatternNo, OS));
|
} while (InsertOneTypeCheck(Pat, Pattern.first, *this, "N", PatternNo, OS));
|
||||||
|
|
||||||
|
bool HasChain = false;
|
||||||
|
EmitLeadChainForPattern(Pattern.second, "N", OS, HasChain);
|
||||||
|
|
||||||
bool InFlag = false;
|
bool InFlag = false;
|
||||||
EmitCopyToRegsForPattern(Pattern.first, "N", OS, InFlag);
|
EmitCopyToRegsForPattern(Pattern.first, "N", OS, HasChain, InFlag);
|
||||||
|
|
||||||
unsigned TmpNo = 0;
|
unsigned TmpNo = 0;
|
||||||
CodeGenPatternResult(Pattern.second,
|
CodeGenPatternResult(Pattern.second,
|
||||||
TmpNo, VariableMap, OS, InFlag, true /*the root*/);
|
TmpNo, VariableMap, OS, HasChain, InFlag, true /*the root*/);
|
||||||
delete Pat;
|
delete Pat;
|
||||||
|
|
||||||
OS << " }\n P" << PatternNo << "Fail:\n";
|
OS << " }\n P" << PatternNo << "Fail:\n";
|
||||||
|
@ -101,7 +101,7 @@ namespace llvm {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SelectionDAG node properties.
|
// SelectionDAG node properties.
|
||||||
enum SDNP { SDNPCommutative, SDNPAssociative };
|
enum SDNP { SDNPCommutative, SDNPAssociative, SDNPHasChain };
|
||||||
|
|
||||||
/// hasProperty - Return true if this node has the specified property.
|
/// hasProperty - Return true if this node has the specified property.
|
||||||
///
|
///
|
||||||
@ -324,8 +324,6 @@ namespace llvm {
|
|||||||
|
|
||||||
class DAGInstruction {
|
class DAGInstruction {
|
||||||
TreePattern *Pattern;
|
TreePattern *Pattern;
|
||||||
unsigned NumResults;
|
|
||||||
unsigned NumOperands;
|
|
||||||
std::vector<Record*> Results;
|
std::vector<Record*> Results;
|
||||||
std::vector<Record*> Operands;
|
std::vector<Record*> Operands;
|
||||||
TreePatternNode *ResultPattern;
|
TreePatternNode *ResultPattern;
|
||||||
@ -418,11 +416,13 @@ private:
|
|||||||
void EmitMatchForPattern(TreePatternNode *N, const std::string &RootName,
|
void EmitMatchForPattern(TreePatternNode *N, const std::string &RootName,
|
||||||
std::map<std::string,std::string> &VarMap,
|
std::map<std::string,std::string> &VarMap,
|
||||||
unsigned PatternNo, std::ostream &OS);
|
unsigned PatternNo, std::ostream &OS);
|
||||||
|
void EmitLeadChainForPattern(TreePatternNode *N, const std::string &RootName,
|
||||||
|
std::ostream &OS, bool &HasChain);
|
||||||
void EmitCopyToRegsForPattern(TreePatternNode *N, const std::string &RootName,
|
void EmitCopyToRegsForPattern(TreePatternNode *N, const std::string &RootName,
|
||||||
std::ostream &OS, bool &InFlag);
|
std::ostream &OS, bool &HasChain, bool &InFlag);
|
||||||
unsigned CodeGenPatternResult(TreePatternNode *N, unsigned &Ctr,
|
unsigned CodeGenPatternResult(TreePatternNode *N, unsigned &Ctr,
|
||||||
std::map<std::string,std::string> &VariableMap,
|
std::map<std::string,std::string> &VariableMap,
|
||||||
std::ostream &OS, bool InFlag,
|
std::ostream &OS, bool &HasChain, bool InFlag,
|
||||||
bool isRoot = false);
|
bool isRoot = false);
|
||||||
void EmitCodeForPattern(PatternToMatch &Pattern, std::ostream &OS);
|
void EmitCodeForPattern(PatternToMatch &Pattern, std::ostream &OS);
|
||||||
void EmitInstructionSelector(std::ostream &OS);
|
void EmitInstructionSelector(std::ostream &OS);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user