~ubuntu-branches/ubuntu/quantal/llvm-3.1/quantal

« back to all changes in this revision

Viewing changes to utils/TableGen/RegisterInfoEmitter.cpp

  • Committer: Package Import Robot
  • Author(s): Sylvestre Ledru
  • Date: 2012-04-10 23:38:33 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20120410233833-5ibwguerdnr58six
Tags: 3.1~svn154439-1
* New snapshot release
* Change the soname to match what Debian is expecting
* Clean up the dh_shlibdeps call

Show diffs side-by-side

added added

removed removed

Lines of Context:
118
118
  OS << "#endif // GET_REGINFO_ENUM\n\n";
119
119
}
120
120
 
 
121
void RegisterInfoEmitter::
 
122
EmitRegUnitPressure(raw_ostream &OS, const CodeGenRegBank &RegBank,
 
123
                    const std::string &ClassName) {
 
124
  unsigned NumRCs = RegBank.getRegClasses().size();
 
125
  unsigned NumSets = RegBank.getNumRegPressureSets();
 
126
 
 
127
  OS << "/// Get the weight in units of pressure for this register class.\n"
 
128
     << "unsigned " << ClassName << "::\n"
 
129
     << "getRegClassWeight(const TargetRegisterClass *RC) const {\n"
 
130
     << "  static const unsigned RCWeightTable[] = {\n";
 
131
  for (unsigned i = 0, e = NumRCs; i != e; ++i) {
 
132
    const CodeGenRegisterClass &RC = *RegBank.getRegClasses()[i];
 
133
    const CodeGenRegister::Set &Regs = RC.getMembers();
 
134
    if (Regs.empty())
 
135
      OS << "    0";
 
136
    else
 
137
      OS << "    " << (*Regs.begin())->getWeight(RegBank);
 
138
    OS << ",  \t// " << RC.getName() << "\n";
 
139
  }
 
140
  OS << "    0 };\n"
 
141
     << "  return RCWeightTable[RC->getID()];\n"
 
142
     << "}\n\n";
 
143
 
 
144
  OS << "\n"
 
145
     << "// Get the number of dimensions of register pressure.\n"
 
146
     << "unsigned " << ClassName << "::getNumRegPressureSets() const {\n"
 
147
     << "  return " << NumSets << ";\n}\n\n";
 
148
 
 
149
  OS << "// Get the register unit pressure limit for this dimension.\n"
 
150
     << "// This limit must be adjusted dynamically for reserved registers.\n"
 
151
     << "unsigned " << ClassName << "::\n"
 
152
     << "getRegPressureSetLimit(unsigned Idx) const {\n"
 
153
     << "  static const unsigned PressureLimitTable[] = {\n";
 
154
  for (unsigned i = 0; i < NumSets; ++i ) {
 
155
    OS << "    " << RegBank.getRegPressureSet(i).Units.size()
 
156
       << ",  \t// " << i << ": " << RegBank.getRegPressureSet(i).Name << "\n";
 
157
  }
 
158
  OS << "    0 };\n"
 
159
     << "  return PressureLimitTable[Idx];\n"
 
160
     << "}\n\n";
 
161
 
 
162
  OS << "/// Get the dimensions of register pressure "
 
163
     << "impacted by this register class.\n"
 
164
     << "/// Returns a -1 terminated array of pressure set IDs\n"
 
165
     << "const int* " << ClassName << "::\n"
 
166
     << "getRegClassPressureSets(const TargetRegisterClass *RC) const {\n"
 
167
     << "  static const int RCSetsTable[] = {\n    ";
 
168
  std::vector<unsigned> RCSetStarts(NumRCs);
 
169
  for (unsigned i = 0, StartIdx = 0, e = NumRCs; i != e; ++i) {
 
170
    RCSetStarts[i] = StartIdx;
 
171
    ArrayRef<unsigned> PSetIDs = RegBank.getRCPressureSetIDs(i);
 
172
    for (ArrayRef<unsigned>::iterator PSetI = PSetIDs.begin(),
 
173
           PSetE = PSetIDs.end(); PSetI != PSetE; ++PSetI) {
 
174
      OS << *PSetI << ",  ";
 
175
      ++StartIdx;
 
176
    }
 
177
    OS << "-1,  \t// " << RegBank.getRegClasses()[i]->getName() << "\n    ";
 
178
    ++StartIdx;
 
179
  }
 
180
  OS << "-1 };\n";
 
181
  OS << "  static const unsigned RCSetStartTable[] = {\n    ";
 
182
  for (unsigned i = 0, e = NumRCs; i != e; ++i) {
 
183
    OS << RCSetStarts[i] << ",";
 
184
  }
 
185
  OS << "0 };\n"
 
186
     << "  unsigned SetListStart = RCSetStartTable[RC->getID()];\n"
 
187
     << "  return &RCSetsTable[SetListStart];\n"
 
188
     << "}\n\n";
 
189
}
121
190
 
122
191
void
123
192
RegisterInfoEmitter::EmitRegMappingTables(raw_ostream &OS,
578
647
  const std::string &TargetName = Target.getName();
579
648
  std::string ClassName = TargetName + "GenRegisterInfo";
580
649
 
581
 
  OS << "#include \"llvm/Target/TargetRegisterInfo.h\"\n";
582
 
  OS << "#include <string>\n\n";
 
650
  OS << "#include \"llvm/Target/TargetRegisterInfo.h\"\n\n";
583
651
 
584
652
  OS << "namespace llvm {\n\n";
585
653
 
594
662
     << "  const TargetRegisterClass *getMatchingSuperRegClass("
595
663
        "const TargetRegisterClass*, const TargetRegisterClass*, "
596
664
        "unsigned) const;\n"
 
665
     << "  unsigned getRegClassWeight(const TargetRegisterClass *RC) const;\n"
 
666
     << "  unsigned getNumRegPressureSets() const;\n"
 
667
     << "  unsigned getRegPressureSetLimit(unsigned Idx) const;\n"
 
668
     << "  const int *getRegClassPressureSets("
 
669
     << "const TargetRegisterClass *RC) const;\n"
597
670
     << "};\n\n";
598
671
 
599
672
  ArrayRef<CodeGenRegisterClass*> RegisterClasses = RegBank.getRegClasses();
812
885
 
813
886
  // Emit extra information about registers.
814
887
  const std::string &TargetName = Target.getName();
815
 
  OS << "\n  static const TargetRegisterInfoDesc "
816
 
     << TargetName << "RegInfoDesc[] = "
817
 
     << "{ // Extra Descriptors\n";
818
 
  OS << "    { 0, 0 },\n";
 
888
  OS << "\nstatic const TargetRegisterInfoDesc "
 
889
     << TargetName << "RegInfoDesc[] = { // Extra Descriptors\n";
 
890
  OS << "  { 0, 0 },\n";
819
891
 
820
892
  const std::vector<CodeGenRegister*> &Regs = RegBank.getRegisters();
821
893
  for (unsigned i = 0, e = Regs.size(); i != e; ++i) {
822
894
    const CodeGenRegister &Reg = *Regs[i];
823
 
    OS << "    { ";
 
895
    OS << "  { ";
824
896
    OS << Reg.CostPerUse << ", "
825
897
       << int(AllocatableRegs.count(Reg.TheDef)) << " },\n";
826
898
  }
827
 
  OS << "  };\n";      // End of register descriptors...
 
899
  OS << "};\n";      // End of register descriptors...
828
900
 
829
901
 
830
902
  // Calculate the mapping of subregister+index pairs to physical registers.
833
905
 
834
906
  // Emit SubRegIndex names, skipping 0
835
907
  ArrayRef<CodeGenSubRegIndex*> SubRegIndices = RegBank.getSubRegIndices();
836
 
  OS << "\n  static const char *const " << TargetName
 
908
  OS << "\nstatic const char *const " << TargetName
837
909
     << "SubRegIndexTable[] = { \"";
838
910
  for (unsigned i = 0, e = SubRegIndices.size(); i != e; ++i) {
839
911
    OS << SubRegIndices[i]->getName();
963
1035
  }
964
1036
  OS << "}\n\n";
965
1037
 
 
1038
  EmitRegUnitPressure(OS, RegBank, ClassName);
 
1039
 
966
1040
  // Emit the constructor of the class...
967
1041
  OS << "extern const MCRegisterDesc " << TargetName << "RegDesc[];\n";
968
1042
  OS << "extern const uint16_t " << TargetName << "RegLists[];\n";