#include <set>
using namespace llvm;
+//===----------------------------------------------------------------------===//
+// SDNodeInfo implementation
+//
+SDNodeInfo::SDNodeInfo(Record *R) : Def(R) {
+ EnumName = R->getValueAsString("Opcode");
+ SDClassName = R->getValueAsString("SDClass");
+}
//===----------------------------------------------------------------------===//
// TreePatternNode implementation
// DAGISelEmitter implementation
//
+// Parse all of the SDNode definitions for the target, populating SDNodes.
+void DAGISelEmitter::ParseNodeInfo() {
+ std::vector<Record*> Nodes = Records.getAllDerivedDefinitions("SDNode");
+ while (!Nodes.empty()) {
+ SDNodes.insert(std::make_pair(Nodes.back(), Nodes.back()));
+ Nodes.pop_back();
+ }
+}
+
/// ParseAndResolvePatternFragments - Parse all of the PatFrag definitions in
/// the .td file, building up the PatternFragments map. After we've collected
/// them all, inline fragments together as necessary, so that there are no
EmitSourceFileHeader("DAG Instruction Selector for the " + Target.getName() +
" target", OS);
+ ParseNodeInfo();
ParseAndResolvePatternFragments(OS);
ParseAndResolveInstructions();
class DagInit;
class TreePattern;
class DAGISelEmitter;
+
+ /// SDNodeInfo - One of these records is created for each SDNode instance in
+ /// the target .td file. This represents the various dag nodes we will be
+ /// processing.
+ class SDNodeInfo {
+ Record *Def;
+ std::string EnumName;
+ std::string SDClassName;
+ public:
+ SDNodeInfo(Record *R); // Parse the specified record.
+
+ Record *getRecord() const { return Def; }
+ const std::string &getEnumName() const { return EnumName; }
+ const std::string &getSDClassName() const { return SDClassName; }
+ };
/// FIXME: TreePatternNode's can be shared in some cases (due to dag-shaped
/// patterns), and as such should be ref counted. We currently just leak all
RecordKeeper &Records;
CodeGenTarget Target;
+ std::map<Record*, SDNodeInfo> SDNodes;
std::map<Record*, TreePattern*> PatternFragments;
std::vector<TreePattern*> Instructions;
public:
// run - Output the isel, returning true on failure.
void run(std::ostream &OS);
+
+ const SDNodeInfo &getSDNodeInfo(Record *R) const {
+ assert(SDNodes.count(R) && "Unknown node!");
+ return SDNodes.find(R)->second;
+ }
TreePattern *getPatternFragment(Record *R) const {
assert(PatternFragments.count(R) && "Invalid pattern fragment request!");
}
private:
+ void ParseNodeInfo();
void ParseAndResolvePatternFragments(std::ostream &OS);
void ParseAndResolveInstructions();
void EmitInstructionSelector(std::ostream &OS);