//===- InstrInfoEmitter.cpp - Generate a Instruction Set Desc. ------------===//
//
// This tablegen backend is responsible for emitting a description of the target
// instruction set for the code generator.
//
//===----------------------------------------------------------------------===//
#include "InstrSelectorEmitter.h"
#include "CodeGenWrappers.h"
#include "Record.h"
#include "Support/Debug.h"
#include "Support/StringExtras.h"
#include <set>
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;
if (Name == "DNVT_arg1") return Arg1;
if (Name == "DNVT_ptr" ) return Ptr;
if (Name == "DNVT_i8" ) return I8;
throw "Unknown DagNodeValType '" + Name + "'!";
}
//===----------------------------------------------------------------------===//
// TreePatternNode implementation
//
/// getValueRecord - Returns the value of this tree node as a record. For now
/// we only allow DefInit's as our leaf values, so this is used.
Record *TreePatternNode::getValueRecord() const {
DefInit *DI = dynamic_cast<DefInit*>(getValue());
assert(DI && "Instruction Selector does not yet support non-def leaves!");
return DI->getDef();
}
// updateNodeType - Set the node type of N to VT if VT contains information. If
// N already contains a conflicting type, then throw an exception
//
bool TreePatternNode::updateNodeType(MVT::ValueType VT,
const std::string &RecName) {
if (VT == MVT::Other || getType() == VT) return false;
if (getType() == MVT::Other) {
setType(VT);
return true;
}
throw "Type inferfence contradiction found for pattern " + RecName;
}
/// InstantiateNonterminals - If this pattern refers to any nonterminals which
/// are not themselves completely resolved, clone the nonterminal and resolve it
/// with the using context we provide.
///
void TreePatternNode::InstantiateNonterminals(InstrSelectorEmitter &ISE) {
if (!isLeaf()) {
for (unsigned i = 0, e = getNumChildren(); i != e; ++i)
getChild(i)