Close list item tag, to conform with the style in this file. It's optional
[oota-llvm.git] / utils / TableGen / SubtargetEmitter.cpp
index fc913e69e125e41eb66691c64d17f851720eb5c0..b05b9968a2e83a149f09152e63f82c2a5a44d601 100644 (file)
@@ -2,8 +2,8 @@
 //
 //                     The LLVM Compiler Infrastructure
 //
-// This file was developed by James M. Laskey and is distributed under
-// the University of Illinois Open Source License. See LICENSE.TXT for details.
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
 //
 //===----------------------------------------------------------------------===//
 //
 #include <algorithm>
 using namespace llvm;
 
-//
-// Record sort by name function.
-//
-struct LessRecord {
-  bool operator()(const Record *Rec1, const Record *Rec2) const {
-    return Rec1->getName() < Rec2->getName();
-  }
-};
-
-//
-// Record sort by field "Name" function.
-//
-struct LessRecordFieldName {
-  bool operator()(const Record *Rec1, const Record *Rec2) const {
-    return Rec1->getValueAsString("Name") < Rec2->getValueAsString("Name");
-  }
-};
-
 //
 // Enumeration - Emit the specified class as an enumeration.
 //
@@ -79,11 +61,11 @@ void SubtargetEmitter::FeatureKeyValues(std::ostream &OS) {
   // Gather and sort all the features
   std::vector<Record*> FeatureList =
                            Records.getAllDerivedDefinitions("SubtargetFeature");
-  std::sort(FeatureList.begin(), FeatureList.end(), LessRecord());
+  std::sort(FeatureList.begin(), FeatureList.end(), LessRecordFieldName());
 
   // Begin feature table
   OS << "// Sorted (by key) array of values for CPU features.\n"
-     << "static llvm::SubtargetFeatureKV FeatureKV[] = {\n";
+     << "static const llvm::SubtargetFeatureKV FeatureKV[] = {\n";
   
   // For each feature
   for (unsigned i = 0, N = FeatureList.size(); i < N; ++i) {
@@ -269,9 +251,10 @@ void SubtargetEmitter::EmitStageData(std::ostream &OS,
   if (ProcItinList.size() < 2) return;
 
   // Begin stages table
-  OS << "static llvm::InstrStage Stages[] = {\n"
+  OS << "static const llvm::InstrStage Stages[] = {\n"
         "  { 0, 0 }, // No itinerary\n";
         
+  unsigned StageCount = 1;
   unsigned ItinEnum = 1;
   std::map<std::string, unsigned> ItinMap;
   for (unsigned i = 0, N = ProcItinList.size(); i < N; i++) {
@@ -308,8 +291,10 @@ void SubtargetEmitter::EmitStageData(std::ostream &OS,
       if (Find == 0) {
         // Emit as { cycles, u1 | u2 | ... | un }, // index
         OS << ItinString << ", // " << ItinEnum << "\n";
-        // Record Itin class number
-        ItinMap[ItinString] = Find = ItinEnum++;
+        // Record Itin class number.
+        ItinMap[ItinString] = Find = StageCount;
+        StageCount += NStages;
+        ItinEnum++;
       }
       
       // Set up itinerary as location and location + stage count
@@ -362,7 +347,7 @@ void SubtargetEmitter::EmitProcessorData(std::ostream &OS,
 
     // Begin processor itinerary table
     OS << "\n";
-    OS << "static llvm::InstrItinerary " << Name << "[] = {\n";
+    OS << "static const llvm::InstrItinerary " << Name << "[] = {\n";
     
     // For each itinerary class
     std::vector<InstrItinerary> &ItinList = *ProcListIter++;
@@ -482,8 +467,12 @@ void SubtargetEmitter::ParseFeaturesFunction(std::ostream &OS) {
     const std::string &Value = R->getValueAsString("Value");
     const std::string &Attribute = R->getValueAsString("Attribute");
 
-    OS << "  if ((Bits & " << Instance << ") != 0) "
-       << Attribute << " = " << Value << ";\n";
+    if (Value=="true" || Value=="false")
+      OS << "  if ((Bits & " << Instance << ") != 0) "
+         << Attribute << " = " << Value << ";\n";
+    else
+      OS << "  if ((Bits & " << Instance << ") != 0 && " << Attribute << 
+            " < " << Value << ") " << Attribute << " = " << Value << ";\n";
   }
 
   if (HasItineraries) {