summaryrefslogtreecommitdiff
path: root/llvm/utils/TableGen/InstrInfoEmitter.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/utils/TableGen/InstrInfoEmitter.cpp')
-rw-r--r--llvm/utils/TableGen/InstrInfoEmitter.cpp108
1 files changed, 81 insertions, 27 deletions
diff --git a/llvm/utils/TableGen/InstrInfoEmitter.cpp b/llvm/utils/TableGen/InstrInfoEmitter.cpp
index 6ab58bd26a2c8..f3141735a9957 100644
--- a/llvm/utils/TableGen/InstrInfoEmitter.cpp
+++ b/llvm/utils/TableGen/InstrInfoEmitter.cpp
@@ -524,7 +524,7 @@ void InstrInfoEmitter::run(raw_ostream &OS) {
OS << "namespace llvm {\n\n";
CodeGenTarget &Target = CDP.getTargetInfo();
- const std::string &TargetName = Target.getName();
+ const std::string &TargetName = std::string(Target.getName());
Record *InstrInfo = Target.getInstructionSet();
// Keep track of all of the def lists we have emitted already.
@@ -561,7 +561,7 @@ void InstrInfoEmitter::run(raw_ostream &OS) {
unsigned Num = 0;
for (const CodeGenInstruction *Inst : NumberedInstructions) {
// Keep a list of the instruction names.
- InstrNames.add(Inst->TheDef->getName());
+ InstrNames.add(std::string(Inst->TheDef->getName()));
// Emit the record into the table.
emitRecord(*Inst, Num++, InstrInfo, EmittedLists, OperandInfoIDs, OS);
}
@@ -569,9 +569,8 @@ void InstrInfoEmitter::run(raw_ostream &OS) {
// Emit the array of instruction names.
InstrNames.layout();
- OS << "extern const char " << TargetName << "InstrNameData[] = {\n";
- InstrNames.emit(OS, printChar);
- OS << "};\n\n";
+ InstrNames.emitStringLiteralDef(OS, Twine("extern const char ") + TargetName +
+ "InstrNameData[]");
OS << "extern const unsigned " << TargetName <<"InstrNameIndices[] = {";
Num = 0;
@@ -579,18 +578,69 @@ void InstrInfoEmitter::run(raw_ostream &OS) {
// Newline every eight entries.
if (Num % 8 == 0)
OS << "\n ";
- OS << InstrNames.get(Inst->TheDef->getName()) << "U, ";
+ OS << InstrNames.get(std::string(Inst->TheDef->getName())) << "U, ";
++Num;
}
-
OS << "\n};\n\n";
+ bool HasDeprecationFeatures =
+ llvm::any_of(NumberedInstructions, [](const CodeGenInstruction *Inst) {
+ return !Inst->HasComplexDeprecationPredicate &&
+ !Inst->DeprecatedReason.empty();
+ });
+ if (HasDeprecationFeatures) {
+ OS << "extern const uint8_t " << TargetName
+ << "InstrDeprecationFeatures[] = {";
+ Num = 0;
+ for (const CodeGenInstruction *Inst : NumberedInstructions) {
+ if (Num % 8 == 0)
+ OS << "\n ";
+ if (!Inst->HasComplexDeprecationPredicate &&
+ !Inst->DeprecatedReason.empty())
+ OS << Target.getInstNamespace() << "::" << Inst->DeprecatedReason
+ << ", ";
+ else
+ OS << "uint8_t(-1), ";
+ ++Num;
+ }
+ OS << "\n};\n\n";
+ }
+
+ bool HasComplexDeprecationInfos =
+ llvm::any_of(NumberedInstructions, [](const CodeGenInstruction *Inst) {
+ return Inst->HasComplexDeprecationPredicate;
+ });
+ if (HasComplexDeprecationInfos) {
+ OS << "extern const MCInstrInfo::ComplexDeprecationPredicate " << TargetName
+ << "InstrComplexDeprecationInfos[] = {";
+ Num = 0;
+ for (const CodeGenInstruction *Inst : NumberedInstructions) {
+ if (Num % 8 == 0)
+ OS << "\n ";
+ if (Inst->HasComplexDeprecationPredicate)
+ // Emit a function pointer to the complex predicate method.
+ OS << "&get" << Inst->DeprecatedReason << "DeprecationInfo, ";
+ else
+ OS << "nullptr, ";
+ ++Num;
+ }
+ OS << "\n};\n\n";
+ }
+
// MCInstrInfo initialization routine.
OS << "static inline void Init" << TargetName
<< "MCInstrInfo(MCInstrInfo *II) {\n";
- OS << " II->InitMCInstrInfo(" << TargetName << "Insts, "
- << TargetName << "InstrNameIndices, " << TargetName << "InstrNameData, "
- << NumberedInstructions.size() << ");\n}\n\n";
+ OS << " II->InitMCInstrInfo(" << TargetName << "Insts, " << TargetName
+ << "InstrNameIndices, " << TargetName << "InstrNameData, ";
+ if (HasDeprecationFeatures)
+ OS << TargetName << "InstrDeprecationFeatures, ";
+ else
+ OS << "nullptr, ";
+ if (HasComplexDeprecationInfos)
+ OS << TargetName << "InstrComplexDeprecationInfos, ";
+ else
+ OS << "nullptr, ";
+ OS << NumberedInstructions.size() << ");\n}\n\n";
OS << "} // end namespace llvm\n";
@@ -630,12 +680,28 @@ void InstrInfoEmitter::run(raw_ostream &OS) {
OS << "extern const MCInstrDesc " << TargetName << "Insts[];\n";
OS << "extern const unsigned " << TargetName << "InstrNameIndices[];\n";
OS << "extern const char " << TargetName << "InstrNameData[];\n";
+ if (HasDeprecationFeatures)
+ OS << "extern const uint8_t " << TargetName
+ << "InstrDeprecationFeatures[];\n";
+ if (HasComplexDeprecationInfos)
+ OS << "extern const MCInstrInfo::ComplexDeprecationPredicate " << TargetName
+ << "InstrComplexDeprecationInfos[];\n";
OS << ClassName << "::" << ClassName
- << "(int CFSetupOpcode, int CFDestroyOpcode, int CatchRetOpcode, int ReturnOpcode)\n"
- << " : TargetInstrInfo(CFSetupOpcode, CFDestroyOpcode, CatchRetOpcode, ReturnOpcode) {\n"
+ << "(int CFSetupOpcode, int CFDestroyOpcode, int CatchRetOpcode, int "
+ "ReturnOpcode)\n"
+ << " : TargetInstrInfo(CFSetupOpcode, CFDestroyOpcode, CatchRetOpcode, "
+ "ReturnOpcode) {\n"
<< " InitMCInstrInfo(" << TargetName << "Insts, " << TargetName
- << "InstrNameIndices, " << TargetName << "InstrNameData, "
- << NumberedInstructions.size() << ");\n}\n";
+ << "InstrNameIndices, " << TargetName << "InstrNameData, ";
+ if (HasDeprecationFeatures)
+ OS << TargetName << "InstrDeprecationFeatures, ";
+ else
+ OS << "nullptr, ";
+ if (HasComplexDeprecationInfos)
+ OS << TargetName << "InstrComplexDeprecationInfos, ";
+ else
+ OS << "nullptr, ";
+ OS << NumberedInstructions.size() << ");\n}\n";
OS << "} // end namespace llvm\n";
OS << "#endif // GET_INSTRINFO_CTOR_DTOR\n\n";
@@ -746,18 +812,6 @@ void InstrInfoEmitter::emitRecord(const CodeGenInstruction &Inst, unsigned Num,
else
OS << "OperandInfo" << OpInfo.find(OperandInfo)->second;
- if (Inst.HasComplexDeprecationPredicate)
- // Emit a function pointer to the complex predicate method.
- OS << ", -1 "
- << ",&get" << Inst.DeprecatedReason << "DeprecationInfo";
- else if (!Inst.DeprecatedReason.empty())
- // Emit the Subtarget feature.
- OS << ", " << Target.getInstNamespace() << "::" << Inst.DeprecatedReason
- << " ,nullptr";
- else
- // Instruction isn't deprecated.
- OS << ", -1 ,nullptr";
-
OS << " }, // Inst #" << Num << " = " << Inst.TheDef->getName() << "\n";
}
@@ -768,7 +822,7 @@ void InstrInfoEmitter::emitEnums(raw_ostream &OS) {
OS << "namespace llvm {\n\n";
- CodeGenTarget Target(Records);
+ const CodeGenTarget &Target = CDP.getTargetInfo();
// We must emit the PHI opcode first...
StringRef Namespace = Target.getInstNamespace();