[llvm-commits] CVS: llvm/utils/TableGen/InstrSelectorEmitter.cpp InstrSelectorEmitter.h
Chris Lattner
lattner at cs.uiuc.edu
Mon Aug 11 16:30:05 PDT 2003
Changes in directory llvm/utils/TableGen:
InstrSelectorEmitter.cpp updated: 1.25 -> 1.26
InstrSelectorEmitter.h updated: 1.16 -> 1.17
---
Log message:
Add support for frameidx and literal immediates for instructions
---
Diffs of the changes:
Index: llvm/utils/TableGen/InstrSelectorEmitter.cpp
diff -u llvm/utils/TableGen/InstrSelectorEmitter.cpp:1.25 llvm/utils/TableGen/InstrSelectorEmitter.cpp:1.26
--- llvm/utils/TableGen/InstrSelectorEmitter.cpp:1.25 Mon Aug 11 15:32:02 2003
+++ llvm/utils/TableGen/InstrSelectorEmitter.cpp Mon Aug 11 16:28:59 2003
@@ -117,7 +117,7 @@
//
Pattern::Pattern(PatternType pty, DagInit *RawPat, Record *TheRec,
InstrSelectorEmitter &ise)
- : PTy(pty), Result(0), TheRecord(TheRec), ISE(ise) {
+ : PTy(pty), ResultNode(0), TheRecord(TheRec), ISE(ise) {
// First, parse the pattern...
Tree = ParseTreePattern(RawPat);
@@ -137,7 +137,7 @@
assert(Tree->getNumChildren() == 2 && "Set with != 2 arguments?");
if (!Tree->getChild(0)->isLeaf())
error("Arg #0 of set should be a register or register class!");
- Result = Tree->getChild(0)->getValueRecord();
+ ResultNode = Tree->getChild(0);
ResultName = Tree->getChildName(0);
Tree = Tree->getChild(1);
}
@@ -855,11 +855,14 @@
/// name.
void InstrSelectorEmitter::PrintExpanderOperand(Init *Arg,
const std::string &NameVar,
- Record *ArgDecl,
+ TreePatternNode *ArgDeclNode,
Pattern *P, bool PrintArg,
std::ostream &OS) {
if (DefInit *DI = dynamic_cast<DefInit*>(Arg)) {
Record *Arg = DI->getDef();
+ if (!ArgDeclNode->isLeaf())
+ P->error("Expected leaf node as argument!");
+ Record *ArgDecl = ArgDeclNode->getValueRecord();
if (Arg->isSubClassOf("Register")) {
// This is a physical register reference... make sure that the instruction
// requested a register!
@@ -882,8 +885,28 @@
OS << NameVar;
if (PrintArg) OS << ")";
return;
+ } else if (Arg->getName() == "frameidx") {
+ if (!PrintArg) P->error("Cannot define a new frameidx value!");
+ OS << ".addFrameIndex(" << NameVar << ")";
+ return;
}
P->error("Unknown operand type '" + Arg->getName() + "' to expander!");
+ } else if (IntInit *II = dynamic_cast<IntInit*>(Arg)) {
+ if (!NameVar.empty())
+ P->error("Illegal to specify a name for a constant initializer arg!");
+
+ // Hack this check to allow R32 values with 0 as the initializer for memory
+ // references... FIXME!
+ if (ArgDeclNode->isLeaf() && II->getValue() == 0 &&
+ ArgDeclNode->getValueRecord()->getName() == "R32") {
+ OS << ".addReg(0)";
+ } else {
+ if (ArgDeclNode->isLeaf() || ArgDeclNode->getOperator()->getName()!="imm")
+ P->error("Illegal immediate int value '" + itostr(II->getValue()) +
+ "' operand!");
+ OS << ".addZImm(" << II->getValue() << ")";
+ }
+ return;
}
P->error("Unknown operand type to expander!");
}
@@ -1201,7 +1224,8 @@
std::string ArgNameVal =
getArgName(P, DIInst->getArgName(0), Operands);
PrintExpanderOperand(DIInst->getArg(0), ArgNameVal,
- R, P, false, OS << ", ");
+ InstPat->getResultNode(), P, false,
+ OS << ", ");
}
OS << ")";
@@ -1210,7 +1234,7 @@
getArgName(P, DIInst->getArgName(i), Operands);
PrintExpanderOperand(DIInst->getArg(i), ArgNameVal,
- InstPat->getArgRec(i-hasResult), P, true, OS);
+ InstPat->getArg(i-hasResult), P, true, OS);
}
OS << ";\n";
Index: llvm/utils/TableGen/InstrSelectorEmitter.h
diff -u llvm/utils/TableGen/InstrSelectorEmitter.h:1.16 llvm/utils/TableGen/InstrSelectorEmitter.h:1.17
--- llvm/utils/TableGen/InstrSelectorEmitter.h:1.16 Mon Aug 11 15:32:02 2003
+++ llvm/utils/TableGen/InstrSelectorEmitter.h Mon Aug 11 16:28:59 2003
@@ -141,8 +141,8 @@
/// Result - If this is an instruction or expander pattern, this is the
/// register result, specified with a (set) in the pattern.
///
- Record *Result;
- std::string ResultName; // The name of the result value...
+ std::string ResultName; // The name of the result value...
+ TreePatternNode *ResultNode; // The leaf node for the result register...
/// TheRecord - The actual TableGen record corresponding to this pattern.
///
@@ -172,8 +172,9 @@
/// Pattern - Constructor used for cloning nonterminal patterns
Pattern(TreePatternNode *tree, Record *rec, bool res,
- InstrSelectorEmitter &ise) : PTy(Nonterminal), Tree(tree), Result(0),
- TheRecord(rec), Resolved(res), ISE(ise) {
+ InstrSelectorEmitter &ise)
+ : PTy(Nonterminal), Tree(tree), ResultNode(0), TheRecord(rec),
+ Resolved(res), ISE(ise) {
calculateArgs(Tree, "");
}
@@ -185,8 +186,11 @@
///
TreePatternNode *getTree() const { return Tree; }
- Record *getResult() const { return Result; }
+ Record *getResult() const {
+ return ResultNode ? ResultNode->getValueRecord() : 0;
+ }
const std::string &getResultName() const { return ResultName; }
+ TreePatternNode *getResultNode() const { return ResultNode; }
/// getRecord - Return the actual TableGen record corresponding to this
/// pattern.
@@ -201,6 +205,9 @@
Record *getArgRec(unsigned i) const {
return getArg(i)->getValueRecord();
}
+ Init *getArgVal(unsigned i) const {
+ return getArg(i)->getValue();
+ }
const std::string &getArgName(unsigned i) const {
assert(i < Args.size() && "Argument reference out of range!");
return Args[i].second;
@@ -372,7 +379,7 @@
/// to the BuildMI call. If it is false, we are printing the result register
/// name.
void PrintExpanderOperand(Init *Arg, const std::string &NameVar,
- Record *ArgDecl, Pattern *P,
+ TreePatternNode *ArgDecl, Pattern *P,
bool PrintArg, std::ostream &OS);
};
More information about the llvm-commits
mailing list