1 //===- InstrInfoEmitter.cpp - Generate a Instruction Set Desc. ------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // This tablegen backend is responsible for emitting a description of the target 11 // instruction set for the code generator. 12 // 13 //===----------------------------------------------------------------------===// 14 15 16 #include "CodeGenDAGPatterns.h" 17 #include "CodeGenSchedule.h" 18 #include "CodeGenTarget.h" 19 #include "SequenceToOffsetTable.h" 20 #include "TableGenBackends.h" 21 #include "llvm/ADT/StringExtras.h" 22 #include "llvm/TableGen/Error.h" 23 #include "llvm/TableGen/Record.h" 24 #include "llvm/TableGen/TableGenBackend.h" 25 #include <algorithm> 26 #include <cstdio> 27 #include <map> 28 #include <vector> 29 using namespace llvm; 30 31 namespace { 32 class InstrInfoEmitter { 33 RecordKeeper &Records; 34 CodeGenDAGPatterns CDP; 35 const CodeGenSchedModels &SchedModels; 36 37 public: 38 InstrInfoEmitter(RecordKeeper &R): 39 Records(R), CDP(R), SchedModels(CDP.getTargetInfo().getSchedModels()) {} 40 41 // run - Output the instruction set description. 42 void run(raw_ostream &OS); 43 44 private: 45 void emitEnums(raw_ostream &OS); 46 47 typedef std::map<std::vector<std::string>, unsigned> OperandInfoMapTy; 48 49 /// The keys of this map are maps which have OpName enum values as their keys 50 /// and instruction operand indices as their values. The values of this map 51 /// are lists of instruction names. 52 typedef std::map<std::map<unsigned, unsigned>, 53 std::vector<std::string> > OpNameMapTy; 54 typedef std::map<std::string, unsigned>::iterator StrUintMapIter; 55 void emitRecord(const CodeGenInstruction &Inst, unsigned Num, 56 Record *InstrInfo, 57 std::map<std::vector<Record*>, unsigned> &EL, 58 const OperandInfoMapTy &OpInfo, 59 raw_ostream &OS); 60 void initOperandMapData( 61 const std::vector<const CodeGenInstruction *> NumberedInstructions, 62 const std::string &Namespace, 63 std::map<std::string, unsigned> &Operands, 64 OpNameMapTy &OperandMap); 65 void emitOperandNameMappings(raw_ostream &OS, const CodeGenTarget &Target, 66 const std::vector<const CodeGenInstruction*> &NumberedInstructions); 67 68 // Operand information. 69 void EmitOperandInfo(raw_ostream &OS, OperandInfoMapTy &OperandInfoIDs); 70 std::vector<std::string> GetOperandInfo(const CodeGenInstruction &Inst); 71 }; 72 } // End anonymous namespace 73 74 static void PrintDefList(const std::vector<Record*> &Uses, 75 unsigned Num, raw_ostream &OS) { 76 OS << "static const uint16_t ImplicitList" << Num << "[] = { "; 77 for (unsigned i = 0, e = Uses.size(); i != e; ++i) 78 OS << getQualifiedName(Uses[i]) << ", "; 79 OS << "0 };\n"; 80 } 81 82 //===----------------------------------------------------------------------===// 83 // Operand Info Emission. 84 //===----------------------------------------------------------------------===// 85 86 std::vector<std::string> 87 InstrInfoEmitter::GetOperandInfo(const CodeGenInstruction &Inst) { 88 std::vector<std::string> Result; 89 90 for (unsigned i = 0, e = Inst.Operands.size(); i != e; ++i) { 91 // Handle aggregate operands and normal operands the same way by expanding 92 // either case into a list of operands for this op. 93 std::vector<CGIOperandList::OperandInfo> OperandList; 94 95 // This might be a multiple operand thing. Targets like X86 have 96 // registers in their multi-operand operands. It may also be an anonymous 97 // operand, which has a single operand, but no declared class for the 98 // operand. 99 DagInit *MIOI = Inst.Operands[i].MIOperandInfo; 100 101 if (!MIOI || MIOI->getNumArgs() == 0) { 102 // Single, anonymous, operand. 103 OperandList.push_back(Inst.Operands[i]); 104 } else { 105 for (unsigned j = 0, e = Inst.Operands[i].MINumOperands; j != e; ++j) { 106 OperandList.push_back(Inst.Operands[i]); 107 108 Record *OpR = cast<DefInit>(MIOI->getArg(j))->getDef(); 109 OperandList.back().Rec = OpR; 110 } 111 } 112 113 for (unsigned j = 0, e = OperandList.size(); j != e; ++j) { 114 Record *OpR = OperandList[j].Rec; 115 std::string Res; 116 117 if (OpR->isSubClassOf("RegisterOperand")) 118 OpR = OpR->getValueAsDef("RegClass"); 119 if (OpR->isSubClassOf("RegisterClass")) 120 Res += getQualifiedName(OpR) + "RegClassID, "; 121 else if (OpR->isSubClassOf("PointerLikeRegClass")) 122 Res += utostr(OpR->getValueAsInt("RegClassKind")) + ", "; 123 else 124 // -1 means the operand does not have a fixed register class. 125 Res += "-1, "; 126 127 // Fill in applicable flags. 128 Res += "0"; 129 130 // Ptr value whose register class is resolved via callback. 131 if (OpR->isSubClassOf("PointerLikeRegClass")) 132 Res += "|(1<<MCOI::LookupPtrRegClass)"; 133 134 // Predicate operands. Check to see if the original unexpanded operand 135 // was of type PredicateOperand. 136 if (Inst.Operands[i].Rec->isSubClassOf("PredicateOperand")) 137 Res += "|(1<<MCOI::Predicate)"; 138 139 // Optional def operands. Check to see if the original unexpanded operand 140 // was of type OptionalDefOperand. 141 if (Inst.Operands[i].Rec->isSubClassOf("OptionalDefOperand")) 142 Res += "|(1<<MCOI::OptionalDef)"; 143 144 // Fill in operand type. 145 Res += ", MCOI::"; 146 assert(!Inst.Operands[i].OperandType.empty() && "Invalid operand type."); 147 Res += Inst.Operands[i].OperandType; 148 149 // Fill in constraint info. 150 Res += ", "; 151 152 const CGIOperandList::ConstraintInfo &Constraint = 153 Inst.Operands[i].Constraints[j]; 154 if (Constraint.isNone()) 155 Res += "0"; 156 else if (Constraint.isEarlyClobber()) 157 Res += "(1 << MCOI::EARLY_CLOBBER)"; 158 else { 159 assert(Constraint.isTied()); 160 Res += "((" + utostr(Constraint.getTiedOperand()) + 161 " << 16) | (1 << MCOI::TIED_TO))"; 162 } 163 164 Result.push_back(Res); 165 } 166 } 167 168 return Result; 169 } 170 171 void InstrInfoEmitter::EmitOperandInfo(raw_ostream &OS, 172 OperandInfoMapTy &OperandInfoIDs) { 173 // ID #0 is for no operand info. 174 unsigned OperandListNum = 0; 175 OperandInfoIDs[std::vector<std::string>()] = ++OperandListNum; 176 177 OS << "\n"; 178 const CodeGenTarget &Target = CDP.getTargetInfo(); 179 for (CodeGenTarget::inst_iterator II = Target.inst_begin(), 180 E = Target.inst_end(); II != E; ++II) { 181 std::vector<std::string> OperandInfo = GetOperandInfo(**II); 182 unsigned &N = OperandInfoIDs[OperandInfo]; 183 if (N != 0) continue; 184 185 N = ++OperandListNum; 186 OS << "static const MCOperandInfo OperandInfo" << N << "[] = { "; 187 for (unsigned i = 0, e = OperandInfo.size(); i != e; ++i) 188 OS << "{ " << OperandInfo[i] << " }, "; 189 OS << "};\n"; 190 } 191 } 192 193 194 /// Initialize data structures for generating operand name mappings. 195 /// 196 /// \param Operands [out] A map used to generate the OpName enum with operand 197 /// names as its keys and operand enum values as its values. 198 /// \param OperandMap [out] A map for representing the operand name mappings for 199 /// each instructions. This is used to generate the OperandMap table as 200 /// well as the getNamedOperandIdx() function. 201 void InstrInfoEmitter::initOperandMapData( 202 const std::vector<const CodeGenInstruction *> NumberedInstructions, 203 const std::string &Namespace, 204 std::map<std::string, unsigned> &Operands, 205 OpNameMapTy &OperandMap) { 206 207 unsigned NumOperands = 0; 208 for (unsigned i = 0, e = NumberedInstructions.size(); i != e; ++i) { 209 const CodeGenInstruction *Inst = NumberedInstructions[i]; 210 if (!Inst->TheDef->getValueAsBit("UseNamedOperandTable")) { 211 continue; 212 } 213 std::map<unsigned, unsigned> OpList; 214 for (unsigned j = 0, je = Inst->Operands.size(); j != je; ++j) { 215 const CGIOperandList::OperandInfo &Info = Inst->Operands[j]; 216 StrUintMapIter I = Operands.find(Info.Name); 217 218 if (I == Operands.end()) { 219 I = Operands.insert(Operands.begin(), 220 std::pair<std::string, unsigned>(Info.Name, NumOperands++)); 221 } 222 OpList[I->second] = Info.MIOperandNo; 223 } 224 OperandMap[OpList].push_back(Namespace + "::" + Inst->TheDef->getName()); 225 } 226 } 227 228 /// Generate a table and function for looking up the indices of operands by 229 /// name. 230 /// 231 /// This code generates: 232 /// - An enum in the llvm::TargetNamespace::OpName namespace, with one entry 233 /// for each operand name. 234 /// - A 2-dimensional table called OperandMap for mapping OpName enum values to 235 /// operand indices. 236 /// - A function called getNamedOperandIdx(uint16_t Opcode, uint16_t NamedIdx) 237 /// for looking up the operand index for an instruction, given a value from 238 /// OpName enum 239 void InstrInfoEmitter::emitOperandNameMappings(raw_ostream &OS, 240 const CodeGenTarget &Target, 241 const std::vector<const CodeGenInstruction*> &NumberedInstructions) { 242 243 const std::string &Namespace = Target.getInstNamespace(); 244 std::string OpNameNS = "OpName"; 245 // Map of operand names to their enumeration value. This will be used to 246 // generate the OpName enum. 247 std::map<std::string, unsigned> Operands; 248 OpNameMapTy OperandMap; 249 250 initOperandMapData(NumberedInstructions, Namespace, Operands, OperandMap); 251 252 OS << "#ifdef GET_INSTRINFO_OPERAND_ENUM\n"; 253 OS << "#undef GET_INSTRINFO_OPERAND_ENUM\n"; 254 OS << "namespace llvm {"; 255 OS << "namespace " << Namespace << " {\n"; 256 OS << "namespace " << OpNameNS << " { \n"; 257 OS << "enum {\n"; 258 for (StrUintMapIter i = Operands.begin(), e = Operands.end(); i != e; ++i) 259 OS << " " << i->first << " = " << i->second << ",\n"; 260 261 OS << "OPERAND_LAST"; 262 OS << "\n};\n"; 263 OS << "} // End namespace OpName\n"; 264 OS << "} // End namespace " << Namespace << "\n"; 265 OS << "} // End namespace llvm\n"; 266 OS << "#endif //GET_INSTRINFO_OPERAND_ENUM\n"; 267 268 OS << "#ifdef GET_INSTRINFO_NAMED_OPS\n"; 269 OS << "#undef GET_INSTRINFO_NAMED_OPS\n"; 270 OS << "namespace llvm {"; 271 OS << "namespace " << Namespace << " {\n"; 272 OS << "int16_t getNamedOperandIdx(uint16_t Opcode, uint16_t NamedIdx) {\n"; 273 if (!Operands.empty()) { 274 OS << " static const int16_t OperandMap [][" << Operands.size() 275 << "] = {\n"; 276 for (OpNameMapTy::iterator i = OperandMap.begin(), e = OperandMap.end(); 277 i != e; ++i) { 278 const std::map<unsigned, unsigned> &OpList = i->first; 279 OS << "{"; 280 281 // Emit a row of the OperandMap table 282 for (unsigned ii = 0, ie = Operands.size(); ii != ie; ++ii) 283 OS << (OpList.count(ii) == 0 ? -1 : (int)OpList.find(ii)->second) 284 << ", "; 285 286 OS << "},\n"; 287 } 288 OS << "};\n"; 289 290 OS << " switch(Opcode) {\n"; 291 unsigned TableIndex = 0; 292 for (OpNameMapTy::iterator i = OperandMap.begin(), e = OperandMap.end(); 293 i != e; ++i) { 294 std::vector<std::string> &OpcodeList = i->second; 295 296 for (unsigned ii = 0, ie = OpcodeList.size(); ii != ie; ++ii) 297 OS << " case " << OpcodeList[ii] << ":\n"; 298 299 OS << " return OperandMap[" << TableIndex++ << "][NamedIdx];\n"; 300 } 301 OS << " default: return -1;\n"; 302 OS << " }\n"; 303 } else { 304 // There are no operands, so no need to emit anything 305 OS << " return -1;\n"; 306 } 307 OS << "}\n"; 308 OS << "} // End namespace " << Namespace << "\n"; 309 OS << "} // End namespace llvm\n"; 310 OS << "#endif //GET_INSTRINFO_NAMED_OPS\n"; 311 312 } 313 314 //===----------------------------------------------------------------------===// 315 // Main Output. 316 //===----------------------------------------------------------------------===// 317 318 // run - Emit the main instruction description records for the target... 319 void InstrInfoEmitter::run(raw_ostream &OS) { 320 emitSourceFileHeader("Target Instruction Enum Values", OS); 321 emitEnums(OS); 322 323 emitSourceFileHeader("Target Instruction Descriptors", OS); 324 325 OS << "\n#ifdef GET_INSTRINFO_MC_DESC\n"; 326 OS << "#undef GET_INSTRINFO_MC_DESC\n"; 327 328 OS << "namespace llvm {\n\n"; 329 330 CodeGenTarget &Target = CDP.getTargetInfo(); 331 const std::string &TargetName = Target.getName(); 332 Record *InstrInfo = Target.getInstructionSet(); 333 334 // Keep track of all of the def lists we have emitted already. 335 std::map<std::vector<Record*>, unsigned> EmittedLists; 336 unsigned ListNumber = 0; 337 338 // Emit all of the instruction's implicit uses and defs. 339 for (CodeGenTarget::inst_iterator II = Target.inst_begin(), 340 E = Target.inst_end(); II != E; ++II) { 341 Record *Inst = (*II)->TheDef; 342 std::vector<Record*> Uses = Inst->getValueAsListOfDefs("Uses"); 343 if (!Uses.empty()) { 344 unsigned &IL = EmittedLists[Uses]; 345 if (!IL) PrintDefList(Uses, IL = ++ListNumber, OS); 346 } 347 std::vector<Record*> Defs = Inst->getValueAsListOfDefs("Defs"); 348 if (!Defs.empty()) { 349 unsigned &IL = EmittedLists[Defs]; 350 if (!IL) PrintDefList(Defs, IL = ++ListNumber, OS); 351 } 352 } 353 354 OperandInfoMapTy OperandInfoIDs; 355 356 // Emit all of the operand info records. 357 EmitOperandInfo(OS, OperandInfoIDs); 358 359 // Emit all of the MCInstrDesc records in their ENUM ordering. 360 // 361 OS << "\nextern const MCInstrDesc " << TargetName << "Insts[] = {\n"; 362 const std::vector<const CodeGenInstruction*> &NumberedInstructions = 363 Target.getInstructionsByEnumValue(); 364 365 for (unsigned i = 0, e = NumberedInstructions.size(); i != e; ++i) 366 emitRecord(*NumberedInstructions[i], i, InstrInfo, EmittedLists, 367 OperandInfoIDs, OS); 368 OS << "};\n\n"; 369 370 // Build an array of instruction names 371 SequenceToOffsetTable<std::string> InstrNames; 372 for (unsigned i = 0, e = NumberedInstructions.size(); i != e; ++i) { 373 const CodeGenInstruction *Instr = NumberedInstructions[i]; 374 InstrNames.add(Instr->TheDef->getName()); 375 } 376 377 InstrNames.layout(); 378 OS << "extern const char " << TargetName << "InstrNameData[] = {\n"; 379 InstrNames.emit(OS, printChar); 380 OS << "};\n\n"; 381 382 OS << "extern const unsigned " << TargetName <<"InstrNameIndices[] = {"; 383 for (unsigned i = 0, e = NumberedInstructions.size(); i != e; ++i) { 384 if (i % 8 == 0) 385 OS << "\n "; 386 const CodeGenInstruction *Instr = NumberedInstructions[i]; 387 OS << InstrNames.get(Instr->TheDef->getName()) << "U, "; 388 } 389 390 OS << "\n};\n\n"; 391 392 // MCInstrInfo initialization routine. 393 OS << "static inline void Init" << TargetName 394 << "MCInstrInfo(MCInstrInfo *II) {\n"; 395 OS << " II->InitMCInstrInfo(" << TargetName << "Insts, " 396 << TargetName << "InstrNameIndices, " << TargetName << "InstrNameData, " 397 << NumberedInstructions.size() << ");\n}\n\n"; 398 399 OS << "} // End llvm namespace \n"; 400 401 OS << "#endif // GET_INSTRINFO_MC_DESC\n\n"; 402 403 // Create a TargetInstrInfo subclass to hide the MC layer initialization. 404 OS << "\n#ifdef GET_INSTRINFO_HEADER\n"; 405 OS << "#undef GET_INSTRINFO_HEADER\n"; 406 407 std::string ClassName = TargetName + "GenInstrInfo"; 408 OS << "namespace llvm {\n"; 409 OS << "struct " << ClassName << " : public TargetInstrInfo {\n" 410 << " explicit " << ClassName << "(int SO = -1, int DO = -1);\n" 411 << "};\n"; 412 OS << "} // End llvm namespace \n"; 413 414 OS << "#endif // GET_INSTRINFO_HEADER\n\n"; 415 416 OS << "\n#ifdef GET_INSTRINFO_CTOR\n"; 417 OS << "#undef GET_INSTRINFO_CTOR\n"; 418 419 OS << "namespace llvm {\n"; 420 OS << "extern const MCInstrDesc " << TargetName << "Insts[];\n"; 421 OS << "extern const unsigned " << TargetName << "InstrNameIndices[];\n"; 422 OS << "extern const char " << TargetName << "InstrNameData[];\n"; 423 OS << ClassName << "::" << ClassName << "(int SO, int DO)\n" 424 << " : TargetInstrInfo(SO, DO) {\n" 425 << " InitMCInstrInfo(" << TargetName << "Insts, " 426 << TargetName << "InstrNameIndices, " << TargetName << "InstrNameData, " 427 << NumberedInstructions.size() << ");\n}\n"; 428 OS << "} // End llvm namespace \n"; 429 430 OS << "#endif // GET_INSTRINFO_CTOR\n\n"; 431 432 emitOperandNameMappings(OS, Target, NumberedInstructions); 433 } 434 435 void InstrInfoEmitter::emitRecord(const CodeGenInstruction &Inst, unsigned Num, 436 Record *InstrInfo, 437 std::map<std::vector<Record*>, unsigned> &EmittedLists, 438 const OperandInfoMapTy &OpInfo, 439 raw_ostream &OS) { 440 int MinOperands = 0; 441 if (!Inst.Operands.empty()) 442 // Each logical operand can be multiple MI operands. 443 MinOperands = Inst.Operands.back().MIOperandNo + 444 Inst.Operands.back().MINumOperands; 445 446 OS << " { "; 447 OS << Num << ",\t" << MinOperands << ",\t" 448 << Inst.Operands.NumDefs << ",\t" 449 << SchedModels.getSchedClassIdx(Inst) << ",\t" 450 << Inst.TheDef->getValueAsInt("Size") << ",\t0"; 451 452 // Emit all of the target indepedent flags... 453 if (Inst.isPseudo) OS << "|(1<<MCID::Pseudo)"; 454 if (Inst.isReturn) OS << "|(1<<MCID::Return)"; 455 if (Inst.isBranch) OS << "|(1<<MCID::Branch)"; 456 if (Inst.isIndirectBranch) OS << "|(1<<MCID::IndirectBranch)"; 457 if (Inst.isCompare) OS << "|(1<<MCID::Compare)"; 458 if (Inst.isMoveImm) OS << "|(1<<MCID::MoveImm)"; 459 if (Inst.isBitcast) OS << "|(1<<MCID::Bitcast)"; 460 if (Inst.isSelect) OS << "|(1<<MCID::Select)"; 461 if (Inst.isBarrier) OS << "|(1<<MCID::Barrier)"; 462 if (Inst.hasDelaySlot) OS << "|(1<<MCID::DelaySlot)"; 463 if (Inst.isCall) OS << "|(1<<MCID::Call)"; 464 if (Inst.canFoldAsLoad) OS << "|(1<<MCID::FoldableAsLoad)"; 465 if (Inst.mayLoad) OS << "|(1<<MCID::MayLoad)"; 466 if (Inst.mayStore) OS << "|(1<<MCID::MayStore)"; 467 if (Inst.isPredicable) OS << "|(1<<MCID::Predicable)"; 468 if (Inst.isConvertibleToThreeAddress) OS << "|(1<<MCID::ConvertibleTo3Addr)"; 469 if (Inst.isCommutable) OS << "|(1<<MCID::Commutable)"; 470 if (Inst.isTerminator) OS << "|(1<<MCID::Terminator)"; 471 if (Inst.isReMaterializable) OS << "|(1<<MCID::Rematerializable)"; 472 if (Inst.isNotDuplicable) OS << "|(1<<MCID::NotDuplicable)"; 473 if (Inst.Operands.hasOptionalDef) OS << "|(1<<MCID::HasOptionalDef)"; 474 if (Inst.usesCustomInserter) OS << "|(1<<MCID::UsesCustomInserter)"; 475 if (Inst.hasPostISelHook) OS << "|(1<<MCID::HasPostISelHook)"; 476 if (Inst.Operands.isVariadic)OS << "|(1<<MCID::Variadic)"; 477 if (Inst.hasSideEffects) OS << "|(1<<MCID::UnmodeledSideEffects)"; 478 if (Inst.isAsCheapAsAMove) OS << "|(1<<MCID::CheapAsAMove)"; 479 if (Inst.hasExtraSrcRegAllocReq) OS << "|(1<<MCID::ExtraSrcRegAllocReq)"; 480 if (Inst.hasExtraDefRegAllocReq) OS << "|(1<<MCID::ExtraDefRegAllocReq)"; 481 482 // Emit all of the target-specific flags... 483 BitsInit *TSF = Inst.TheDef->getValueAsBitsInit("TSFlags"); 484 if (!TSF) 485 PrintFatalError("no TSFlags?"); 486 uint64_t Value = 0; 487 for (unsigned i = 0, e = TSF->getNumBits(); i != e; ++i) { 488 if (BitInit *Bit = dyn_cast<BitInit>(TSF->getBit(i))) 489 Value |= uint64_t(Bit->getValue()) << i; 490 else 491 PrintFatalError("Invalid TSFlags bit in " + Inst.TheDef->getName()); 492 } 493 OS << ", 0x"; 494 OS.write_hex(Value); 495 OS << "ULL, "; 496 497 // Emit the implicit uses and defs lists... 498 std::vector<Record*> UseList = Inst.TheDef->getValueAsListOfDefs("Uses"); 499 if (UseList.empty()) 500 OS << "NULL, "; 501 else 502 OS << "ImplicitList" << EmittedLists[UseList] << ", "; 503 504 std::vector<Record*> DefList = Inst.TheDef->getValueAsListOfDefs("Defs"); 505 if (DefList.empty()) 506 OS << "NULL, "; 507 else 508 OS << "ImplicitList" << EmittedLists[DefList] << ", "; 509 510 // Emit the operand info. 511 std::vector<std::string> OperandInfo = GetOperandInfo(Inst); 512 if (OperandInfo.empty()) 513 OS << "0"; 514 else 515 OS << "OperandInfo" << OpInfo.find(OperandInfo)->second; 516 517 OS << " }, // Inst #" << Num << " = " << Inst.TheDef->getName() << "\n"; 518 } 519 520 // emitEnums - Print out enum values for all of the instructions. 521 void InstrInfoEmitter::emitEnums(raw_ostream &OS) { 522 523 OS << "\n#ifdef GET_INSTRINFO_ENUM\n"; 524 OS << "#undef GET_INSTRINFO_ENUM\n"; 525 526 OS << "namespace llvm {\n\n"; 527 528 CodeGenTarget Target(Records); 529 530 // We must emit the PHI opcode first... 531 std::string Namespace = Target.getInstNamespace(); 532 533 if (Namespace.empty()) { 534 fprintf(stderr, "No instructions defined!\n"); 535 exit(1); 536 } 537 538 const std::vector<const CodeGenInstruction*> &NumberedInstructions = 539 Target.getInstructionsByEnumValue(); 540 541 OS << "namespace " << Namespace << " {\n"; 542 OS << " enum {\n"; 543 for (unsigned i = 0, e = NumberedInstructions.size(); i != e; ++i) { 544 OS << " " << NumberedInstructions[i]->TheDef->getName() 545 << "\t= " << i << ",\n"; 546 } 547 OS << " INSTRUCTION_LIST_END = " << NumberedInstructions.size() << "\n"; 548 OS << " };\n}\n"; 549 OS << "} // End llvm namespace \n"; 550 551 OS << "#endif // GET_INSTRINFO_ENUM\n\n"; 552 } 553 554 namespace llvm { 555 556 void EmitInstrInfo(RecordKeeper &RK, raw_ostream &OS) { 557 InstrInfoEmitter(RK).run(OS); 558 EmitMapTable(RK, OS); 559 } 560 561 } // End llvm namespace 562