Skip to content

Commit

Permalink
Add support for the Any type. Minor fixes and enhancements for BasicB…
Browse files Browse the repository at this point in the history
…lock operands

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@7769 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
lattner committed Aug 12, 2003
1 parent c12a614 commit 6b666e8
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 14 deletions.
23 changes: 17 additions & 6 deletions support/tools/TableGen/InstrSelectorEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

NodeType::ArgResultTypes NodeType::Translate(Record *R) {
const std::string &Name = R->getName();
if (Name == "DNVT_any") return Any;
if (Name == "DNVT_void") return Void;
if (Name == "DNVT_val" ) return Val;
if (Name == "DNVT_arg0") return Arg0;
Expand Down Expand Up @@ -204,6 +205,8 @@ TreePatternNode *Pattern::ParseTreePattern(DagInit *Dag) {
New = new TreePatternNode(DI);
// If it's a regclass or something else known, set the type.
New->setType(getIntrinsicType(DI->getDef()));
} else if (DagInit *DI = dynamic_cast<DagInit*>(Arg)) {
New = ParseTreePattern(DI);
} else {
Arg->dump();
error("Unknown leaf value for tree pattern!");
Expand Down Expand Up @@ -276,6 +279,7 @@ bool Pattern::InferTypes(TreePatternNode *N, bool &MadeChange) {
AnyUnset |= InferTypes(Child, MadeChange);

switch (NT.ArgTypes[i]) {
case NodeType::Any: break;
case NodeType::I8:
MadeChange |= Child->updateNodeType(MVT::i1, TheRecord->getName());
break;
Expand All @@ -301,6 +305,7 @@ bool Pattern::InferTypes(TreePatternNode *N, bool &MadeChange) {

// See if we can infer anything about the return type now...
switch (NT.ResultType) {
case NodeType::Any: break;
case NodeType::Void:
MadeChange |= N->updateNodeType(MVT::isVoid, TheRecord->getName());
break;
Expand Down Expand Up @@ -867,9 +872,10 @@ void InstrSelectorEmitter::PrintExpanderOperand(Init *Arg,
std::ostream &OS) {
if (DefInit *DI = dynamic_cast<DefInit*>(Arg)) {
Record *Arg = DI->getDef();
if (!ArgDeclNode->isLeaf())
if (!ArgDeclNode->isLeaf() && ArgDeclNode->getNumChildren() != 0)
P->error("Expected leaf node as argument!");
Record *ArgDecl = ArgDeclNode->getValueRecord();
Record *ArgDecl = ArgDeclNode->isLeaf() ? ArgDeclNode->getValueRecord() :
ArgDeclNode->getOperator();
if (Arg->isSubClassOf("Register")) {
// This is a physical register reference... make sure that the instruction
// requested a register!
Expand All @@ -896,6 +902,10 @@ void InstrSelectorEmitter::PrintExpanderOperand(Init *Arg,
if (!PrintArg) P->error("Cannot define a new frameidx value!");
OS << ".addFrameIndex(" << NameVar << ")";
return;
} else if (Arg->getName() == "basicblock") {
if (!PrintArg) P->error("Cannot define a new basicblock value!");
OS << ".addMBB(" << NameVar << ")";
return;
}
P->error("Unknown operand type '" + Arg->getName() + "' to expander!");
} else if (IntInit *II = dynamic_cast<IntInit*>(Arg)) {
Expand All @@ -910,7 +920,7 @@ void InstrSelectorEmitter::PrintExpanderOperand(Init *Arg,
} else {
if (ArgDeclNode->isLeaf() || ArgDeclNode->getOperator()->getName()!="imm")
P->error("Illegal immediate int value '" + itostr(II->getValue()) +
"' operand!");
"' operand!");
OS << ".addZImm(" << II->getValue() << ")";
}
return;
Expand Down Expand Up @@ -1213,7 +1223,8 @@ void InstrSelectorEmitter::run(std::ostream &OS) {
for (unsigned IN = 0, e = Insts->getSize(); IN != e; ++IN) {
DagInit *DIInst = dynamic_cast<DagInit*>(Insts->getElement(IN));
if (!DIInst) P->error("Result list must contain instructions!");
Pattern *InstPat = getPattern(DIInst->getNodeType());
Record *InstRec = DIInst->getNodeType();
Pattern *InstPat = getPattern(InstRec);
if (!InstPat || InstPat->getPatternType() != Pattern::Instruction)
P->error("Instruction list must contain Instruction patterns!");

Expand All @@ -1225,10 +1236,10 @@ void InstrSelectorEmitter::run(std::ostream &OS) {

// Start emission of the instruction...
OS << " BuildMI(MBB, " << Target.getName() << "::"
<< InstPat->getRecord()->getName() << ", "
<< InstRec->getName() << ", "
<< DIInst->getNumArgs()-hasResult;
// Emit register result if necessary..
if (Record *R = InstPat->getResult()) {
if (hasResult) {
std::string ArgNameVal =
getArgName(P, DIInst->getArgName(0), Operands);
PrintExpanderOperand(DIInst->getArg(0), ArgNameVal,
Expand Down
2 changes: 1 addition & 1 deletion support/tools/TableGen/InstrSelectorEmitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class InstrSelectorEmitter;
///
struct NodeType {
enum ArgResultTypes {
// Both argument and return types...
Any, // No constraint on type
Val, // A non-void type
Arg0, // Value matches the type of Arg0
Arg1, // Value matches the type of Arg1
Expand Down
23 changes: 17 additions & 6 deletions utils/TableGen/InstrSelectorEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

NodeType::ArgResultTypes NodeType::Translate(Record *R) {
const std::string &Name = R->getName();
if (Name == "DNVT_any") return Any;
if (Name == "DNVT_void") return Void;
if (Name == "DNVT_val" ) return Val;
if (Name == "DNVT_arg0") return Arg0;
Expand Down Expand Up @@ -204,6 +205,8 @@ TreePatternNode *Pattern::ParseTreePattern(DagInit *Dag) {
New = new TreePatternNode(DI);
// If it's a regclass or something else known, set the type.
New->setType(getIntrinsicType(DI->getDef()));
} else if (DagInit *DI = dynamic_cast<DagInit*>(Arg)) {
New = ParseTreePattern(DI);
} else {
Arg->dump();
error("Unknown leaf value for tree pattern!");
Expand Down Expand Up @@ -276,6 +279,7 @@ bool Pattern::InferTypes(TreePatternNode *N, bool &MadeChange) {
AnyUnset |= InferTypes(Child, MadeChange);

switch (NT.ArgTypes[i]) {
case NodeType::Any: break;
case NodeType::I8:
MadeChange |= Child->updateNodeType(MVT::i1, TheRecord->getName());
break;
Expand All @@ -301,6 +305,7 @@ bool Pattern::InferTypes(TreePatternNode *N, bool &MadeChange) {

// See if we can infer anything about the return type now...
switch (NT.ResultType) {
case NodeType::Any: break;
case NodeType::Void:
MadeChange |= N->updateNodeType(MVT::isVoid, TheRecord->getName());
break;
Expand Down Expand Up @@ -867,9 +872,10 @@ void InstrSelectorEmitter::PrintExpanderOperand(Init *Arg,
std::ostream &OS) {
if (DefInit *DI = dynamic_cast<DefInit*>(Arg)) {
Record *Arg = DI->getDef();
if (!ArgDeclNode->isLeaf())
if (!ArgDeclNode->isLeaf() && ArgDeclNode->getNumChildren() != 0)
P->error("Expected leaf node as argument!");
Record *ArgDecl = ArgDeclNode->getValueRecord();
Record *ArgDecl = ArgDeclNode->isLeaf() ? ArgDeclNode->getValueRecord() :
ArgDeclNode->getOperator();
if (Arg->isSubClassOf("Register")) {
// This is a physical register reference... make sure that the instruction
// requested a register!
Expand All @@ -896,6 +902,10 @@ void InstrSelectorEmitter::PrintExpanderOperand(Init *Arg,
if (!PrintArg) P->error("Cannot define a new frameidx value!");
OS << ".addFrameIndex(" << NameVar << ")";
return;
} else if (Arg->getName() == "basicblock") {
if (!PrintArg) P->error("Cannot define a new basicblock value!");
OS << ".addMBB(" << NameVar << ")";
return;
}
P->error("Unknown operand type '" + Arg->getName() + "' to expander!");
} else if (IntInit *II = dynamic_cast<IntInit*>(Arg)) {
Expand All @@ -910,7 +920,7 @@ void InstrSelectorEmitter::PrintExpanderOperand(Init *Arg,
} else {
if (ArgDeclNode->isLeaf() || ArgDeclNode->getOperator()->getName()!="imm")
P->error("Illegal immediate int value '" + itostr(II->getValue()) +
"' operand!");
"' operand!");
OS << ".addZImm(" << II->getValue() << ")";
}
return;
Expand Down Expand Up @@ -1213,7 +1223,8 @@ void InstrSelectorEmitter::run(std::ostream &OS) {
for (unsigned IN = 0, e = Insts->getSize(); IN != e; ++IN) {
DagInit *DIInst = dynamic_cast<DagInit*>(Insts->getElement(IN));
if (!DIInst) P->error("Result list must contain instructions!");
Pattern *InstPat = getPattern(DIInst->getNodeType());
Record *InstRec = DIInst->getNodeType();
Pattern *InstPat = getPattern(InstRec);
if (!InstPat || InstPat->getPatternType() != Pattern::Instruction)
P->error("Instruction list must contain Instruction patterns!");

Expand All @@ -1225,10 +1236,10 @@ void InstrSelectorEmitter::run(std::ostream &OS) {

// Start emission of the instruction...
OS << " BuildMI(MBB, " << Target.getName() << "::"
<< InstPat->getRecord()->getName() << ", "
<< InstRec->getName() << ", "
<< DIInst->getNumArgs()-hasResult;
// Emit register result if necessary..
if (Record *R = InstPat->getResult()) {
if (hasResult) {
std::string ArgNameVal =
getArgName(P, DIInst->getArgName(0), Operands);
PrintExpanderOperand(DIInst->getArg(0), ArgNameVal,
Expand Down
2 changes: 1 addition & 1 deletion utils/TableGen/InstrSelectorEmitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class InstrSelectorEmitter;
///
struct NodeType {
enum ArgResultTypes {
// Both argument and return types...
Any, // No constraint on type
Val, // A non-void type
Arg0, // Value matches the type of Arg0
Arg1, // Value matches the type of Arg1
Expand Down

0 comments on commit 6b666e8

Please sign in to comment.