Advertisement
Guest User

InstrInfoEmitter::run

a guest
Aug 17th, 2012
21
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // run - Emit the main instruction description records for the target...
  2. void InstrInfoEmitter::run(raw_ostream &OS) {
  3.   emitEnums(OS);
  4.  
  5.   GatherItinClasses();
  6.  
  7.   EmitSourceFileHeader("Target Instruction Descriptors", OS);
  8.  
  9.   CodeGenTarget &Target = CDP.getTargetInfo();
  10.   const std::string &TargetName = Target.getName();
  11.   Record *InstrInfo = Target.getInstructionSet();
  12.   std::string Namespace = Target.getInstNamespace();
  13.  
  14.   OS << "\n#ifdef GET_INSTRINFO_MC_DESC\n";
  15.   OS << "#undef GET_INSTRINFO_MC_DESC\n";
  16.  
  17.   OS << "namespace llvm {\n";
  18.   OS << "namespace " << Namespace << " {\n\n";
  19.  
  20.   // Keep track of all of the def lists we have emitted already.
  21.   std::map<std::vector<Record*>, unsigned> EmittedLists;
  22.   unsigned ListNumber = 0;
  23.  
  24.   // Emit all of the instruction's implicit uses and defs.
  25.   for (CodeGenTarget::inst_iterator II = Target.inst_begin(),
  26.          E = Target.inst_end(); II != E; ++II) {
  27.     Record *Inst = (*II)->TheDef;
  28.     std::vector<Record*> Uses = Inst->getValueAsListOfDefs("Uses");
  29.     if (!Uses.empty()) {
  30.       unsigned &IL = EmittedLists[Uses];
  31.       if (!IL) PrintDefList(Uses, IL = ++ListNumber, OS);
  32.     }
  33.     std::vector<Record*> Defs = Inst->getValueAsListOfDefs("Defs");
  34.     if (!Defs.empty()) {
  35.       unsigned &IL = EmittedLists[Defs];
  36.       if (!IL) PrintDefList(Defs, IL = ++ListNumber, OS);
  37.     }
  38.   }
  39.  
  40.   OperandInfoMapTy OperandInfoIDs;
  41.  
  42.   // Emit all of the operand info records.
  43.   EmitOperandInfo(OS, OperandInfoIDs);
  44.  
  45.   // Emit all of the MCInstrDesc records in their ENUM ordering.
  46.   //
  47.   OS << "\nMCInstrDesc " << "Insts[] = {\n";
  48.   const std::vector<const CodeGenInstruction*> &NumberedInstructions =
  49.     Target.getInstructionsByEnumValue();
  50.  
  51.   for (unsigned i = 0, e = NumberedInstructions.size(); i != e; ++i)
  52.     emitRecord(*NumberedInstructions[i], i, InstrInfo, EmittedLists,
  53.                OperandInfoIDs, OS);
  54.   OS << "};\n\n";
  55.   OS << "} // End " << Namespace << " namespace \n";
  56.   OS << "} // End llvm namespace \n\n";
  57.  
  58.   // MCInstrInfo initialization routine.
  59.   OS << "namespace llvm {\n";
  60.   OS << "static inline void Init" << TargetName
  61.      << "MCInstrInfo(MCInstrInfo *II) {\n";
  62.   OS << "  II->InitMCInstrInfo(" << Namespace << "::Insts, "
  63.      << NumberedInstructions.size() << ");\n}\n\n";
  64.   OS << "} // End llvm namespace \n";
  65.  
  66.   OS << "#endif // GET_INSTRINFO_MC_DESC\n\n";
  67.  
  68.   // Create a TargetInstrInfo subclass to hide the MC layer initialization.
  69.   OS << "\n#ifdef GET_INSTRINFO_HEADER\n";
  70.   OS << "#undef GET_INSTRINFO_HEADER\n";
  71.  
  72.   std::string ClassName = TargetName + "GenInstrInfo";
  73.   OS << "namespace llvm {\n";
  74.   OS << "struct " << ClassName << " : public TargetInstrInfoImpl {\n"
  75.      << "  explicit " << ClassName << "(int SO = -1, int DO = -1);\n"
  76.      << "};\n";
  77.   OS << "} // End llvm namespace \n";
  78.  
  79.   OS << "#endif // GET_INSTRINFO_HEADER\n\n";
  80.  
  81.   OS << "\n#ifdef GET_INSTRINFO_CTOR\n";
  82.   OS << "#undef GET_INSTRINFO_CTOR\n";
  83.  
  84.   OS << "namespace llvm {\n";
  85.   OS << "namespace " << Namespace << " {\n";
  86.   OS << "extern MCInstrDesc " << "Insts[];\n";
  87.   OS << "} // End " << Namespace << " namespace \n";
  88.   OS << ClassName << "::" << ClassName << "(int SO, int DO)\n"
  89.      << "  : TargetInstrInfoImpl(SO, DO) {\n"
  90.      << "  InitMCInstrInfo(" << TargetName << "::Insts, "
  91.      << NumberedInstructions.size() << ");\n}\n";
  92.   OS << "} // End llvm namespace \n";
  93.  
  94.   OS << "#endif // GET_INSTRINFO_CTOR\n\n";
  95. }
Advertisement
RAW Paste Data Copied
Advertisement