start building the instruction dest pattern correctly. Change the xform

functions to preserve the Record for the xform instead of making it into a
function name.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23361 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2005-09-14 22:55:26 +00:00
parent 7da852fbab
commit b0276200e6
2 changed files with 27 additions and 15 deletions

View File

@ -203,8 +203,8 @@ void TreePatternNode::print(std::ostream &OS) const {
if (!PredicateFn.empty()) if (!PredicateFn.empty())
OS << "<<P:" << PredicateFn << ">>"; OS << "<<P:" << PredicateFn << ">>";
if (!TransformFn.empty()) if (TransformFn)
OS << "<<X:" << TransformFn << ">>"; OS << "<<X:" << TransformFn->getName() << ">>";
if (!getName().empty()) if (!getName().empty())
OS << ":$" << getName(); OS << ":$" << getName();
@ -598,7 +598,7 @@ void DAGISelEmitter::ParseAndResolvePatternFragments(std::ostream &OS) {
// it. // it.
Record *Transform = Fragments[i]->getValueAsDef("OperandTransform"); Record *Transform = Fragments[i]->getValueAsDef("OperandTransform");
if (!getSDNodeTransform(Transform).second.empty()) // not noop xform? if (!getSDNodeTransform(Transform).second.empty()) // not noop xform?
P->getOnlyTree()->setTransformFn("Transform_"+Transform->getName()); P->getOnlyTree()->setTransformFn(Transform);
} }
OS << "\n\n"; OS << "\n\n";
@ -815,6 +815,7 @@ void DAGISelEmitter::ParseAndResolveInstructions() {
// the copy while we're checking the inputs. // the copy while we're checking the inputs.
std::map<std::string, TreePatternNode*> InstInputsCheck(InstInputs); std::map<std::string, TreePatternNode*> InstInputsCheck(InstInputs);
std::vector<TreePatternNode*> ResultNodeOperands;
for (unsigned i = NumResults, e = CGI.OperandList.size(); i != e; ++i) { for (unsigned i = NumResults, e = CGI.OperandList.size(); i != e; ++i) {
const std::string &OpName = CGI.OperandList[i].Name; const std::string &OpName = CGI.OperandList[i].Name;
if (OpName.empty()) if (OpName.empty())
@ -824,20 +825,26 @@ void DAGISelEmitter::ParseAndResolveInstructions() {
I->error("Operand $" + OpName + I->error("Operand $" + OpName +
" does not appear in the instruction pattern"); " does not appear in the instruction pattern");
TreePatternNode *InVal = InstInputsCheck[OpName]; TreePatternNode *InVal = InstInputsCheck[OpName];
InstInputsCheck.erase(OpName); InstInputsCheck.erase(OpName); // It occurred, remove from map.
if (CGI.OperandList[i].Ty != InVal->getType()) if (CGI.OperandList[i].Ty != InVal->getType())
I->error("Operand $" + OpName + I->error("Operand $" + OpName +
"'s type disagrees between the operand and pattern"); "'s type disagrees between the operand and pattern");
ResultNodeOperands.push_back(InVal->clone());
} }
if (!InstInputsCheck.empty()) if (!InstInputsCheck.empty())
I->error("Input operand $" + InstInputsCheck.begin()->first + I->error("Input operand $" + InstInputsCheck.begin()->first +
" occurs in pattern but not in operands list!"); " occurs in pattern but not in operands list!");
TreePatternNode *ResultPattern =
new TreePatternNode(I->getRecord(), ResultNodeOperands);
unsigned NumOperands = CGI.OperandList.size()-NumResults; unsigned NumOperands = CGI.OperandList.size()-NumResults;
DEBUG(I->dump()); DEBUG(I->dump());
Instructions.push_back(DAGInstruction(I, NumResults, NumOperands)); Instructions.push_back(DAGInstruction(I, NumResults, NumOperands,
ResultPattern));
} }
// If we can, convert the instructions to be patterns that are matched! // If we can, convert the instructions to be patterns that are matched!
@ -856,7 +863,7 @@ void DAGISelEmitter::ParseAndResolveInstructions() {
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(); TreePatternNode *SrcPattern = Pattern->getChild(1)->clone();
TreePatternNode *DstPattern = SrcPattern->clone(); // FIXME: WRONG TreePatternNode *DstPattern = Instructions[i].getResultPattern();
PatternsToMatch.push_back(std::make_pair(SrcPattern, DstPattern)); PatternsToMatch.push_back(std::make_pair(SrcPattern, DstPattern));
DEBUG(std::cerr << "PATTERN TO MATCH: "; SrcPattern->dump(); DEBUG(std::cerr << "PATTERN TO MATCH: "; SrcPattern->dump();
std::cerr << "\nRESULT DAG : "; std::cerr << "\nRESULT DAG : ";

View File

@ -122,14 +122,15 @@ namespace llvm {
/// TransformFn - The transformation function to execute on this node before /// TransformFn - The transformation function to execute on this node before
/// it can be substituted into the resulting instruction on a pattern match. /// it can be substituted into the resulting instruction on a pattern match.
std::string TransformFn; Record *TransformFn;
std::vector<TreePatternNode*> Children; std::vector<TreePatternNode*> Children;
public: public:
TreePatternNode(Record *Op, const std::vector<TreePatternNode*> &Ch) TreePatternNode(Record *Op, const std::vector<TreePatternNode*> &Ch)
: Ty(MVT::LAST_VALUETYPE), Operator(Op), Val(0), Children(Ch) {} : Ty(MVT::LAST_VALUETYPE), Operator(Op), Val(0), TransformFn(0),
Children(Ch) {}
TreePatternNode(Init *val) // leaf ctor TreePatternNode(Init *val) // leaf ctor
: Ty(MVT::LAST_VALUETYPE), Operator(0), Val(val) {} : Ty(MVT::LAST_VALUETYPE), Operator(0), Val(val), TransformFn(0) {}
~TreePatternNode(); ~TreePatternNode();
const std::string &getName() const { return Name; } const std::string &getName() const { return Name; }
@ -152,8 +153,8 @@ namespace llvm {
const std::string &getPredicateFn() const { return PredicateFn; } const std::string &getPredicateFn() const { return PredicateFn; }
void setPredicateFn(const std::string &Fn) { PredicateFn = Fn; } void setPredicateFn(const std::string &Fn) { PredicateFn = Fn; }
const std::string &getTransformFn() const { return TransformFn; } Record *getTransformFn() const { return TransformFn; }
void setTransformFn(const std::string &Fn) { TransformFn = Fn; } void setTransformFn(Record *Fn) { TransformFn = Fn; }
void print(std::ostream &OS) const; void print(std::ostream &OS) const;
void dump() const; void dump() const;
@ -278,13 +279,17 @@ namespace llvm {
TreePattern *Pattern; TreePattern *Pattern;
unsigned NumResults; unsigned NumResults;
unsigned NumOperands; unsigned NumOperands;
TreePatternNode *ResultPattern;
public: public:
DAGInstruction(TreePattern *TP, unsigned results, unsigned ops) DAGInstruction(TreePattern *TP, unsigned results, unsigned ops,
: Pattern(TP), NumResults(results), NumOperands(ops) {} TreePatternNode *resultPattern)
: Pattern(TP), NumResults(results), NumOperands(ops),
ResultPattern(resultPattern) {}
TreePattern *getPattern() const { return Pattern; } TreePattern *getPattern() const { return Pattern; }
unsigned getNumResults() const { return NumResults; } unsigned getNumResults() const { return NumResults; }
unsigned getNumOperands() const { return NumOperands; } unsigned getNumOperands() const { return NumOperands; }
TreePatternNode *getResultPattern() const { return ResultPattern; }
}; };