diff --git a/utils/TableGen/CodeGenDAGPatterns.cpp b/utils/TableGen/CodeGenDAGPatterns.cpp index ec57a674c65..0d61003569d 100644 --- a/utils/TableGen/CodeGenDAGPatterns.cpp +++ b/utils/TableGen/CodeGenDAGPatterns.cpp @@ -1112,12 +1112,10 @@ void TreePattern::dump() const { print(*cerr.stream()); } // // FIXME: REMOVE OSTREAM ARGUMENT -CodegenDAGPatterns::CodegenDAGPatterns(RecordKeeper &R, std::ostream &OS) - : Records(R) { - +CodegenDAGPatterns::CodegenDAGPatterns(RecordKeeper &R) : Records(R) { Intrinsics = LoadIntrinsics(Records); ParseNodeInfo(); - ParseNodeTransforms(OS); + ParseNodeTransforms(); ParseComplexPatterns(); ParsePatternFragments(); ParseDefaultOperands(); @@ -1161,26 +1159,13 @@ void CodegenDAGPatterns::ParseNodeInfo() { /// ParseNodeTransforms - Parse all SDNodeXForm instances into the SDNodeXForms /// map, and emit them to the file as functions. -void CodegenDAGPatterns::ParseNodeTransforms(std::ostream &OS) { - OS << "\n// Node transformations.\n"; +void CodegenDAGPatterns::ParseNodeTransforms() { std::vector Xforms = Records.getAllDerivedDefinitions("SDNodeXForm"); while (!Xforms.empty()) { Record *XFormNode = Xforms.back(); Record *SDNode = XFormNode->getValueAsDef("Opcode"); std::string Code = XFormNode->getValueAsCode("XFormFunction"); - SDNodeXForms.insert(std::make_pair(XFormNode, - std::make_pair(SDNode, Code))); - - if (!Code.empty()) { - std::string ClassName = getSDNodeInfo(SDNode).getSDClassName(); - const char *C2 = ClassName == "SDNode" ? "N" : "inN"; - - OS << "inline SDOperand Transform_" << XFormNode->getName() - << "(SDNode *" << C2 << ") {\n"; - if (ClassName != "SDNode") - OS << " " << ClassName << " *N = cast<" << ClassName << ">(inN);\n"; - OS << Code << "\n}\n"; - } + SDNodeXForms.insert(std::make_pair(XFormNode, NodeXForm(SDNode, Code))); Xforms.pop_back(); } diff --git a/utils/TableGen/CodeGenDAGPatterns.h b/utils/TableGen/CodeGenDAGPatterns.h index ddeadc9bb25..08b40d190d5 100644 --- a/utils/TableGen/CodeGenDAGPatterns.h +++ b/utils/TableGen/CodeGenDAGPatterns.h @@ -451,7 +451,7 @@ class CodegenDAGPatterns { /// emit. std::vector PatternsToMatch; public: - CodegenDAGPatterns(RecordKeeper &R, std::ostream &OS); + CodegenDAGPatterns(RecordKeeper &R); ~CodegenDAGPatterns(); const CodeGenTarget &getTargetInfo() const { return Target; } @@ -463,11 +463,18 @@ public: return SDNodes.find(R)->second; } - const std::pair &getSDNodeTransform(Record *R) const { + // Node transformation lookups. + typedef std::pair NodeXForm; + const NodeXForm &getSDNodeTransform(Record *R) const { assert(SDNodeXForms.count(R) && "Invalid transform!"); return SDNodeXForms.find(R)->second; } + typedef std::map::const_iterator nx_iterator; + nx_iterator nx_begin() const { return SDNodeXForms.begin(); } + nx_iterator nx_end() const { return SDNodeXForms.end(); } + + const ComplexPattern &getComplexPattern(Record *R) const { assert(ComplexPatterns.count(R) && "Unknown addressing mode!"); return ComplexPatterns.find(R)->second; @@ -530,7 +537,7 @@ public: private: void ParseNodeInfo(); - void ParseNodeTransforms(std::ostream &OS); + void ParseNodeTransforms(); void ParseComplexPatterns(); void ParsePatternFragments(); void ParseDefaultOperands(); diff --git a/utils/TableGen/DAGISelEmitter.cpp b/utils/TableGen/DAGISelEmitter.cpp index 89b41a4f311..8819538a2ec 100644 --- a/utils/TableGen/DAGISelEmitter.cpp +++ b/utils/TableGen/DAGISelEmitter.cpp @@ -206,6 +206,39 @@ static bool PatternHasProperty(TreePatternNode *N, SDNP Property, return false; } +//===----------------------------------------------------------------------===// +// Node Transformation emitter implementation. +// +void DAGISelEmitter::EmitNodeTransforms(std::ostream &OS) { + // Walk the pattern fragments, adding them to a map, which sorts them by + // name. + typedef std::map NXsByNameTy; + NXsByNameTy NXsByName; + + for (CodegenDAGPatterns::nx_iterator I = CGP->nx_begin(), E = CGP->nx_end(); + I != E; ++I) + NXsByName.insert(std::make_pair(I->first->getName(), I->second)); + + OS << "\n// Node transformations.\n"; + + for (NXsByNameTy::iterator I = NXsByName.begin(), E = NXsByName.end(); + I != E; ++I) { + Record *SDNode = I->second.first; + std::string Code = I->second.second; + + if (Code.empty()) continue; // Empty code? Skip it. + + std::string ClassName = CGP->getSDNodeInfo(SDNode).getSDClassName(); + const char *C2 = ClassName == "SDNode" ? "N" : "inN"; + + OS << "inline SDOperand Transform_" << I->first << "(SDNode *" << C2 + << ") {\n"; + if (ClassName != "SDNode") + OS << " " << ClassName << " *N = cast<" << ClassName << ">(inN);\n"; + OS << Code << "\n}\n"; + } +} + //===----------------------------------------------------------------------===// // Predicate emitter implementation. // @@ -2010,10 +2043,11 @@ OS << " unsigned NumKilled = ISelKilled.size();\n"; OS << " return Dummy.getValue();\n"; OS << "}\n"; - CodegenDAGPatterns CGP(Records, OS); + CodegenDAGPatterns CGP(Records); this->CGP = &CGP; + EmitNodeTransforms(OS); EmitPredicateFunctions(OS); DOUT << "\n\nALL PATTERNS TO MATCH:\n\n"; diff --git a/utils/TableGen/DAGISelEmitter.h b/utils/TableGen/DAGISelEmitter.h index 0fdbbafccb6..804ebdb21bc 100644 --- a/utils/TableGen/DAGISelEmitter.h +++ b/utils/TableGen/DAGISelEmitter.h @@ -33,6 +33,7 @@ public: private: + void EmitNodeTransforms(std::ostream &OS); void EmitPredicateFunctions(std::ostream &OS); void GenerateCodeForPattern(const PatternToMatch &Pattern,