llvm.org GIT mirror llvm / b08b9d7
c++11: Tidy up tblgen w/ range loops. IntrInfoEmitter cleanup. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@206553 91177308-0d34-0410-b5e6-96231b3b80d8 Jim Grosbach 6 years ago
1 changed file(s) with 54 addition(s) and 63 deletion(s). Raw diff Collapse all Expand all
8787 InstrInfoEmitter::GetOperandInfo(const CodeGenInstruction &Inst) {
8888 std::vector Result;
8989
90 for (unsigned i = 0, e = Inst.Operands.size(); i != e; ++i) {
90 for (auto &Op : Inst.Operands) {
9191 // Handle aggregate operands and normal operands the same way by expanding
9292 // either case into a list of operands for this op.
9393 std::vector OperandList;
9696 // registers in their multi-operand operands. It may also be an anonymous
9797 // operand, which has a single operand, but no declared class for the
9898 // operand.
99 DagInit *MIOI = Inst.Operands[i].MIOperandInfo;
99 DagInit *MIOI = Op.MIOperandInfo;
100100
101101 if (!MIOI || MIOI->getNumArgs() == 0) {
102102 // Single, anonymous, operand.
103 OperandList.push_back(Inst.Operands[i]);
103 OperandList.push_back(Op);
104104 } else {
105 for (unsigned j = 0, e = Inst.Operands[i].MINumOperands; j != e; ++j) {
106 OperandList.push_back(Inst.Operands[i]);
105 for (unsigned j = 0, e = Op.MINumOperands; j != e; ++j) {
106 OperandList.push_back(Op);
107107
108108 Record *OpR = cast(MIOI->getArg(j))->getDef();
109109 OperandList.back().Rec = OpR;
133133
134134 // Predicate operands. Check to see if the original unexpanded operand
135135 // was of type PredicateOp.
136 if (Inst.Operands[i].Rec->isSubClassOf("PredicateOp"))
136 if (Op.Rec->isSubClassOf("PredicateOp"))
137137 Res += "|(1<
138138
139139 // Optional def operands. Check to see if the original unexpanded operand
140140 // was of type OptionalDefOperand.
141 if (Inst.Operands[i].Rec->isSubClassOf("OptionalDefOperand"))
141 if (Op.Rec->isSubClassOf("OptionalDefOperand"))
142142 Res += "|(1<
143143
144144 // Fill in operand type.
145145 Res += ", MCOI::";
146 assert(!Inst.Operands[i].OperandType.empty() && "Invalid operand type.");
147 Res += Inst.Operands[i].OperandType;
146 assert(!Op.OperandType.empty() && "Invalid operand type.");
147 Res += Op.OperandType;
148148
149149 // Fill in constraint info.
150150 Res += ", ";
151151
152152 const CGIOperandList::ConstraintInfo &Constraint =
153 Inst.Operands[i].Constraints[j];
153 Op.Constraints[j];
154154 if (Constraint.isNone())
155155 Res += "0";
156156 else if (Constraint.isEarlyClobber())
176176
177177 OS << "\n";
178178 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 OperandInfo = GetOperandInfo(**II);
179 for (const CodeGenInstruction *Inst : Target.instructions()) {
180 std::vector OperandInfo = GetOperandInfo(*Inst);
182181 unsigned &N = OperandInfoIDs[OperandInfo];
183182 if (N != 0) continue;
184183
185184 N = ++OperandListNum;
186185 OS << "static const MCOperandInfo OperandInfo" << N << "[] = { ";
187 for (unsigned i = 0, e = OperandInfo.size(); i != e; ++i)
188 OS << "{ " << OperandInfo[i] << " }, ";
186 for (const std::string &Info : OperandInfo)
187 OS << "{ " << Info << " }, ";
189188 OS << "};\n";
190189 }
191190 }
205204 OpNameMapTy &OperandMap) {
206205
207206 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")) {
207 for (const CodeGenInstruction *Inst : NumberedInstructions) {
208 if (!Inst->TheDef->getValueAsBit("UseNamedOperandTable"))
211209 continue;
212 }
213210 std::map OpList;
214 for (unsigned j = 0, je = Inst->Operands.size(); j != je; ++j) {
215 const CGIOperandList::OperandInfo &Info = Inst->Operands[j];
211 for (const auto &Info : Inst->Operands) {
216212 StrUintMapIter I = Operands.find(Info.Name);
217213
218214 if (I == Operands.end()) {
255251 OS << "namespace " << Namespace << " {\n";
256252 OS << "namespace " << OpNameNS << " { \n";
257253 OS << "enum {\n";
258 for (StrUintMapIter i = Operands.begin(), e = Operands.end(); i != e; ++i)
259 OS << " " << i->first << " = " << i->second << ",\n";
254 for (const auto &Op : Operands)
255 OS << " " << Op.first << " = " << Op.second << ",\n";
260256
261257 OS << "OPERAND_LAST";
262258 OS << "\n};\n";
273269 if (!Operands.empty()) {
274270 OS << " static const int16_t OperandMap [][" << Operands.size()
275271 << "] = {\n";
276 for (OpNameMapTy::iterator i = OperandMap.begin(), e = OperandMap.end();
277 i != e; ++i) {
278 const std::map &OpList = i->first;
272 for (const auto &Entry : OperandMap) {
273 const std::map &OpList = Entry.first;
279274 OS << "{";
280275
281276 // 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 << ", ";
277 for (unsigned i = 0, e = Operands.size(); i != e; ++i)
278 OS << (OpList.count(i) == 0 ? -1 : (int)OpList.find(i)->second) << ", ";
285279
286280 OS << "},\n";
287281 }
289283
290284 OS << " switch(Opcode) {\n";
291285 unsigned TableIndex = 0;
292 for (OpNameMapTy::iterator i = OperandMap.begin(), e = OperandMap.end();
293 i != e; ++i) {
294 std::vector &OpcodeList = i->second;
295
296 for (unsigned ii = 0, ie = OpcodeList.size(); ii != ie; ++ii)
297 OS << " case " << OpcodeList[ii] << ":\n";
286 for (const auto &Entry : OperandMap) {
287 for (const std::string &Name : Entry.second)
288 OS << " case " << Name << ":\n";
298289
299290 OS << " return OperandMap[" << TableIndex++ << "][NamedIdx];\n";
300291 }
327318 OS << "namespace OpTypes { \n";
328319 OS << "enum OperandType {\n";
329320
330 for (unsigned oi = 0, oe = Operands.size(); oi != oe; ++oi) {
331 if (!Operands[oi]->isAnonymous())
332 OS << " " << Operands[oi]->getName() << " = " << oi << ",\n";
321 unsigned EnumVal = 0;
322 for (const Record *Op : Operands) {
323 if (!Op->isAnonymous())
324 OS << " " << Op->getName() << " = " << EnumVal << ",\n";
325 ++EnumVal;
333326 }
334327
335328 OS << " OPERAND_TYPE_LIST_END" << "\n};\n";
364357 unsigned ListNumber = 0;
365358
366359 // Emit all of the instruction's implicit uses and defs.
367 for (CodeGenTarget::inst_iterator II = Target.inst_begin(),
368 E = Target.inst_end(); II != E; ++II) {
369 Record *Inst = (*II)->TheDef;
360 for (const CodeGenInstruction *II : Target.instructions()) {
361 Record *Inst = II->TheDef;
370362 std::vector Uses = Inst->getValueAsListOfDefs("Uses");
371363 if (!Uses.empty()) {
372364 unsigned &IL = EmittedLists[Uses];
390382 const std::vector &NumberedInstructions =
391383 Target.getInstructionsByEnumValue();
392384
393 for (unsigned i = 0, e = NumberedInstructions.size(); i != e; ++i)
394 emitRecord(*NumberedInstructions[i], i, InstrInfo, EmittedLists,
395 OperandInfoIDs, OS);
385 SequenceToOffsetTable InstrNames;
386 unsigned Num = 0;
387 for (const CodeGenInstruction *Inst : NumberedInstructions) {
388 // Keep a list of the instruction names.
389 InstrNames.add(Inst->TheDef->getName());
390 // Emit the record into the table.
391 emitRecord(*Inst, Num++, InstrInfo, EmittedLists, OperandInfoIDs, OS);
392 }
396393 OS << "};\n\n";
397394
398 // Build an array of instruction names
399 SequenceToOffsetTable InstrNames;
400 for (unsigned i = 0, e = NumberedInstructions.size(); i != e; ++i) {
401 const CodeGenInstruction *Instr = NumberedInstructions[i];
402 InstrNames.add(Instr->TheDef->getName());
403 }
404
395 // Emit the array of instruction names.
405396 InstrNames.layout();
406397 OS << "extern const char " << TargetName << "InstrNameData[] = {\n";
407398 InstrNames.emit(OS, printChar);
408399 OS << "};\n\n";
409400
410401 OS << "extern const unsigned " << TargetName <<"InstrNameIndices[] = {";
411 for (unsigned i = 0, e = NumberedInstructions.size(); i != e; ++i) {
412 if (i % 8 == 0)
402 Num = 0;
403 for (const CodeGenInstruction *Inst : NumberedInstructions) {
404 // Newline every eight entries.
405 if (Num % 8 == 0)
413406 OS << "\n ";
414 const CodeGenInstruction *Instr = NumberedInstructions[i];
415 OS << InstrNames.get(Instr->TheDef->getName()) << "U, ";
407 OS << InstrNames.get(Inst->TheDef->getName()) << "U, ";
408 ++Num;
416409 }
417410
418411 OS << "\n};\n\n";
585578
586579 OS << "namespace " << Namespace << " {\n";
587580 OS << " enum {\n";
588 for (unsigned i = 0, e = NumberedInstructions.size(); i != e; ++i) {
589 OS << " " << NumberedInstructions[i]->TheDef->getName()
590 << "\t= " << i << ",\n";
591 }
581 unsigned Num = 0;
582 for (const CodeGenInstruction *Inst : NumberedInstructions)
583 OS << " " << Inst->TheDef->getName() << "\t= " << Num++ << ",\n";
592584 OS << " INSTRUCTION_LIST_END = " << NumberedInstructions.size() << "\n";
593585 OS << " };\n";
594586 OS << "namespace Sched {\n";
595587 OS << " enum {\n";
596 for (unsigned i = 0, e = SchedModels.numInstrSchedClasses(); i != e; ++i) {
597 OS << " " << SchedModels.getSchedClass(i).Name
598 << "\t= " << i << ",\n";
599 }
588 Num = 0;
589 for (const auto &Class : SchedModels.explicit_classes())
590 OS << " " << Class.Name << "\t= " << Num++ << ",\n";
600591 OS << " SCHED_LIST_END = " << SchedModels.numInstrSchedClasses() << "\n";
601592 OS << " };\n}\n}\n";
602593 OS << "} // End llvm namespace \n";