mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-24 03:33:20 +01:00
pull a bunch of huge inline methods in the PatternCodeEmitter
class out of line. llvm-svn: 96113
This commit is contained in:
parent
b9c4a15ad5
commit
d971210bd9
@ -463,6 +463,124 @@ public:
|
||||
/// matches, and the SDNode for the result has the RootName specified name.
|
||||
void EmitMatchCode(TreePatternNode *N, TreePatternNode *P,
|
||||
const std::string &RootName, const std::string &ChainSuffix,
|
||||
bool &FoundChain);
|
||||
|
||||
void EmitChildMatchCode(TreePatternNode *Child, TreePatternNode *Parent,
|
||||
const std::string &RootName,
|
||||
const std::string &ChainSuffix, bool &FoundChain);
|
||||
|
||||
/// EmitResultCode - Emit the action for a pattern. Now that it has matched
|
||||
/// we actually have to build a DAG!
|
||||
std::vector<std::string>
|
||||
EmitResultCode(TreePatternNode *N, std::vector<Record*> DstRegs,
|
||||
bool InFlagDecled, bool ResNodeDecled,
|
||||
bool LikeLeaf = false, bool isRoot = false);
|
||||
|
||||
/// InsertOneTypeCheck - Insert a type-check for an unresolved type in 'Pat'
|
||||
/// and add it to the tree. 'Pat' and 'Other' are isomorphic trees except that
|
||||
/// '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.
|
||||
bool InsertOneTypeCheck(TreePatternNode *Pat, TreePatternNode *Other,
|
||||
const std::string &Prefix, bool isRoot = false) {
|
||||
// Did we find one?
|
||||
if (Pat->getExtTypes() != Other->getExtTypes()) {
|
||||
// Move a type over from 'other' to 'pat'.
|
||||
Pat->setTypes(Other->getExtTypes());
|
||||
// The top level node type is checked outside of the select function.
|
||||
if (!isRoot)
|
||||
emitCheck(Prefix + ".getValueType() == " +
|
||||
getName(Pat->getTypeNum(0)));
|
||||
return true;
|
||||
}
|
||||
|
||||
unsigned OpNo =
|
||||
(unsigned) NodeHasProperty(Pat, SDNPHasChain, CGP);
|
||||
for (unsigned i = 0, e = Pat->getNumChildren(); i != e; ++i, ++OpNo)
|
||||
if (InsertOneTypeCheck(Pat->getChild(i), Other->getChild(i),
|
||||
Prefix + utostr(OpNo)))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
private:
|
||||
/// EmitInFlagSelectCode - Emit the flag operands for the DAG that is
|
||||
/// being built.
|
||||
void EmitInFlagSelectCode(TreePatternNode *N, const std::string &RootName,
|
||||
bool &ChainEmitted, bool &InFlagDecled,
|
||||
bool &ResNodeDecled, bool isRoot = false) {
|
||||
const CodeGenTarget &T = CGP.getTargetInfo();
|
||||
unsigned OpNo =
|
||||
(unsigned) NodeHasProperty(N, SDNPHasChain, CGP);
|
||||
bool HasInFlag = NodeHasProperty(N, SDNPInFlag, CGP);
|
||||
for (unsigned i = 0, e = N->getNumChildren(); i != e; ++i, ++OpNo) {
|
||||
TreePatternNode *Child = N->getChild(i);
|
||||
if (!Child->isLeaf()) {
|
||||
EmitInFlagSelectCode(Child, RootName + utostr(OpNo), ChainEmitted,
|
||||
InFlagDecled, ResNodeDecled);
|
||||
} else {
|
||||
if (DefInit *DI = dynamic_cast<DefInit*>(Child->getLeafValue())) {
|
||||
if (!Child->getName().empty()) {
|
||||
std::string Name = RootName + utostr(OpNo);
|
||||
if (Duplicates.find(Name) != Duplicates.end())
|
||||
// A duplicate! Do not emit a copy for this node.
|
||||
continue;
|
||||
}
|
||||
|
||||
Record *RR = DI->getDef();
|
||||
if (RR->isSubClassOf("Register")) {
|
||||
MVT::SimpleValueType RVT = getRegisterValueType(RR, T);
|
||||
if (RVT == MVT::Flag) {
|
||||
if (!InFlagDecled) {
|
||||
emitCode("SDValue InFlag = " +
|
||||
getValueName(RootName + utostr(OpNo)) + ";");
|
||||
InFlagDecled = true;
|
||||
} else
|
||||
emitCode("InFlag = " +
|
||||
getValueName(RootName + utostr(OpNo)) + ";");
|
||||
} else {
|
||||
if (!ChainEmitted) {
|
||||
emitCode("SDValue Chain = CurDAG->getEntryNode();");
|
||||
ChainName = "Chain";
|
||||
ChainEmitted = true;
|
||||
}
|
||||
if (!InFlagDecled) {
|
||||
emitCode("SDValue InFlag(0, 0);");
|
||||
InFlagDecled = true;
|
||||
}
|
||||
std::string Decl = (!ResNodeDecled) ? "SDNode *" : "";
|
||||
emitCode(Decl + "ResNode = CurDAG->getCopyToReg(" + ChainName +
|
||||
", " + getNodeName(RootName) + "->getDebugLoc()" +
|
||||
", " + getQualifiedName(RR) +
|
||||
", " + getValueName(RootName + utostr(OpNo)) +
|
||||
", InFlag).getNode();");
|
||||
ResNodeDecled = true;
|
||||
emitCode(ChainName + " = SDValue(ResNode, 0);");
|
||||
emitCode("InFlag = SDValue(ResNode, 1);");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (HasInFlag) {
|
||||
if (!InFlagDecled) {
|
||||
emitCode("SDValue InFlag = " + getNodeName(RootName) +
|
||||
"->getOperand(" + utostr(OpNo) + ");");
|
||||
InFlagDecled = true;
|
||||
} else
|
||||
emitCode("InFlag = " + getNodeName(RootName) +
|
||||
"->getOperand(" + utostr(OpNo) + ");");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/// EmitMatchCode - 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
|
||||
/// matches, and the SDNode for the result has the RootName specified name.
|
||||
void PatternCodeEmitter::EmitMatchCode(TreePatternNode *N, TreePatternNode *P,
|
||||
const std::string &RootName,
|
||||
const std::string &ChainSuffix,
|
||||
bool &FoundChain) {
|
||||
|
||||
// Save loads/stores matched by a pattern.
|
||||
@ -674,9 +792,11 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
void EmitChildMatchCode(TreePatternNode *Child, TreePatternNode *Parent,
|
||||
void PatternCodeEmitter::EmitChildMatchCode(TreePatternNode *Child,
|
||||
TreePatternNode *Parent,
|
||||
const std::string &RootName,
|
||||
const std::string &ChainSuffix, bool &FoundChain) {
|
||||
const std::string &ChainSuffix,
|
||||
bool &FoundChain) {
|
||||
if (!Child->isLeaf()) {
|
||||
// If it's not a leaf, recursively match.
|
||||
const SDNodeInfo &CInfo = CGP.getSDNodeInfo(Child->getOperator());
|
||||
@ -798,9 +918,10 @@ public:
|
||||
/// EmitResultCode - Emit the action for a pattern. Now that it has matched
|
||||
/// we actually have to build a DAG!
|
||||
std::vector<std::string>
|
||||
EmitResultCode(TreePatternNode *N, std::vector<Record*> DstRegs,
|
||||
PatternCodeEmitter::EmitResultCode(TreePatternNode *N,
|
||||
std::vector<Record*> DstRegs,
|
||||
bool InFlagDecled, bool ResNodeDecled,
|
||||
bool LikeLeaf = false, bool isRoot = false) {
|
||||
bool LikeLeaf, bool isRoot) {
|
||||
// List of arguments of getMachineNode() or SelectNodeTo().
|
||||
std::vector<std::string> NodeOps;
|
||||
// This is something selected from the pattern we matched.
|
||||
@ -1325,10 +1446,11 @@ public:
|
||||
|
||||
if (GenDebug) {
|
||||
if (!isRoot) {
|
||||
emitCode("CurDAG->setSubgraphColor(" + NodeName +".getNode(), \"yellow\");");
|
||||
emitCode("CurDAG->setSubgraphColor(" + NodeName +".getNode(), \"black\");");
|
||||
}
|
||||
else {
|
||||
emitCode("CurDAG->setSubgraphColor(" +
|
||||
NodeName +".getNode(), \"yellow\");");
|
||||
emitCode("CurDAG->setSubgraphColor(" +
|
||||
NodeName +".getNode(), \"black\");");
|
||||
} else {
|
||||
emitCode("CurDAG->setSubgraphColor(" + NodeName +", \"yellow\");");
|
||||
emitCode("CurDAG->setSubgraphColor(" + NodeName +", \"black\");");
|
||||
}
|
||||
@ -1360,103 +1482,6 @@ public:
|
||||
throw std::string("Unknown node in result pattern!");
|
||||
}
|
||||
|
||||
/// InsertOneTypeCheck - Insert a type-check for an unresolved type in 'Pat'
|
||||
/// and add it to the tree. 'Pat' and 'Other' are isomorphic trees except that
|
||||
/// '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.
|
||||
bool InsertOneTypeCheck(TreePatternNode *Pat, TreePatternNode *Other,
|
||||
const std::string &Prefix, bool isRoot = false) {
|
||||
// Did we find one?
|
||||
if (Pat->getExtTypes() != Other->getExtTypes()) {
|
||||
// Move a type over from 'other' to 'pat'.
|
||||
Pat->setTypes(Other->getExtTypes());
|
||||
// The top level node type is checked outside of the select function.
|
||||
if (!isRoot)
|
||||
emitCheck(Prefix + ".getValueType() == " +
|
||||
getName(Pat->getTypeNum(0)));
|
||||
return true;
|
||||
}
|
||||
|
||||
unsigned OpNo =
|
||||
(unsigned) NodeHasProperty(Pat, SDNPHasChain, CGP);
|
||||
for (unsigned i = 0, e = Pat->getNumChildren(); i != e; ++i, ++OpNo)
|
||||
if (InsertOneTypeCheck(Pat->getChild(i), Other->getChild(i),
|
||||
Prefix + utostr(OpNo)))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
private:
|
||||
/// EmitInFlagSelectCode - Emit the flag operands for the DAG that is
|
||||
/// being built.
|
||||
void EmitInFlagSelectCode(TreePatternNode *N, const std::string &RootName,
|
||||
bool &ChainEmitted, bool &InFlagDecled,
|
||||
bool &ResNodeDecled, bool isRoot = false) {
|
||||
const CodeGenTarget &T = CGP.getTargetInfo();
|
||||
unsigned OpNo =
|
||||
(unsigned) NodeHasProperty(N, SDNPHasChain, CGP);
|
||||
bool HasInFlag = NodeHasProperty(N, SDNPInFlag, CGP);
|
||||
for (unsigned i = 0, e = N->getNumChildren(); i != e; ++i, ++OpNo) {
|
||||
TreePatternNode *Child = N->getChild(i);
|
||||
if (!Child->isLeaf()) {
|
||||
EmitInFlagSelectCode(Child, RootName + utostr(OpNo), ChainEmitted,
|
||||
InFlagDecled, ResNodeDecled);
|
||||
} else {
|
||||
if (DefInit *DI = dynamic_cast<DefInit*>(Child->getLeafValue())) {
|
||||
if (!Child->getName().empty()) {
|
||||
std::string Name = RootName + utostr(OpNo);
|
||||
if (Duplicates.find(Name) != Duplicates.end())
|
||||
// A duplicate! Do not emit a copy for this node.
|
||||
continue;
|
||||
}
|
||||
|
||||
Record *RR = DI->getDef();
|
||||
if (RR->isSubClassOf("Register")) {
|
||||
MVT::SimpleValueType RVT = getRegisterValueType(RR, T);
|
||||
if (RVT == MVT::Flag) {
|
||||
if (!InFlagDecled) {
|
||||
emitCode("SDValue InFlag = " +
|
||||
getValueName(RootName + utostr(OpNo)) + ";");
|
||||
InFlagDecled = true;
|
||||
} else
|
||||
emitCode("InFlag = " +
|
||||
getValueName(RootName + utostr(OpNo)) + ";");
|
||||
} else {
|
||||
if (!ChainEmitted) {
|
||||
emitCode("SDValue Chain = CurDAG->getEntryNode();");
|
||||
ChainName = "Chain";
|
||||
ChainEmitted = true;
|
||||
}
|
||||
if (!InFlagDecled) {
|
||||
emitCode("SDValue InFlag(0, 0);");
|
||||
InFlagDecled = true;
|
||||
}
|
||||
std::string Decl = (!ResNodeDecled) ? "SDNode *" : "";
|
||||
emitCode(Decl + "ResNode = CurDAG->getCopyToReg(" + ChainName +
|
||||
", " + getNodeName(RootName) + "->getDebugLoc()" +
|
||||
", " + getQualifiedName(RR) +
|
||||
", " + getValueName(RootName + utostr(OpNo)) +
|
||||
", InFlag).getNode();");
|
||||
ResNodeDecled = true;
|
||||
emitCode(ChainName + " = SDValue(ResNode, 0);");
|
||||
emitCode("InFlag = SDValue(ResNode, 1);");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (HasInFlag) {
|
||||
if (!InFlagDecled) {
|
||||
emitCode("SDValue InFlag = " + getNodeName(RootName) +
|
||||
"->getOperand(" + utostr(OpNo) + ");");
|
||||
InFlagDecled = true;
|
||||
} else
|
||||
emitCode("InFlag = " + getNodeName(RootName) +
|
||||
"->getOperand(" + utostr(OpNo) + ");");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/// EmitCodeForPattern - Given a pattern to match, emit code to the specified
|
||||
/// stream to match the pattern, and generate the code for the match if it
|
||||
@ -1831,9 +1856,8 @@ void DAGISelEmitter::EmitInstructionSelector(raw_ostream &OS) {
|
||||
|
||||
// Replace the emission code within selection routines with calls to the
|
||||
// emission functions.
|
||||
if (GenDebug) {
|
||||
if (GenDebug)
|
||||
GeneratedCode.push_back(std::make_pair(0, "CurDAG->setSubgraphColor(N, \"red\");"));
|
||||
}
|
||||
CallerCode = "SDNode *Result = Emit_" + utostr(EmitFuncNum) + CallerCode;
|
||||
GeneratedCode.push_back(std::make_pair(3, CallerCode));
|
||||
if (GenDebug) {
|
||||
|
Loading…
Reference in New Issue
Block a user