Skip to content

Commit 4cbdcb3

Browse files
committed
Check for Target if default arguments of template functions are resolved.
1 parent 2d044a1 commit 4cbdcb3

File tree

4 files changed

+41
-35
lines changed

4 files changed

+41
-35
lines changed

llvm/utils/TableGen/AsmWriterEmitter.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -984,14 +984,15 @@ void AsmWriterEmitter::run() {
984984
namespace llvm {
985985

986986
void EmitAsmWriter(RecordKeeper &RK, raw_ostream &OS) {
987+
CodeGenTarget CGTarget(RK);
987988
PrinterLanguage const PL = PrinterLLVM::getLanguage();
988989
PrinterLLVM *PI;
989990

990991
formatted_raw_ostream FOS(OS);
991992
if (PL == PRINTER_LANG_CPP) {
992-
PI = new PrinterLLVM(FOS);
993+
PI = new PrinterLLVM(FOS, CGTarget.getName().str());
993994
} else if (PL == PRINTER_LANG_CAPSTONE_C) {
994-
PI = new PrinterCapstone(FOS);
995+
PI = new PrinterCapstone(FOS, CGTarget.getName().str());
995996
} else {
996997
llvm_unreachable("AsmWriterEmitter does not support the given output language.");
997998
}

llvm/utils/TableGen/AsmWriterInst.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,7 @@ std::string AsmWriterOperand::getCode(bool PassSubtarget) const {
5555
} else
5656
Result = Str;
5757

58-
if (Str.find("<") != std::string::npos &&
59-
LangCS)
60-
Result = PrinterCapstone::translateToC(Result) + "(MI";
61-
else
62-
Result = Result + "(MI";
58+
Result = Result + "(MI";
6359

6460
if (PCRel)
6561
Result += ", Address";

llvm/utils/TableGen/Printer.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -957,9 +957,8 @@ class PrinterLLVM {
957957
std::string Repr) const;
958958
virtual void searchableTablesEmitIndexArrayII() const;
959959
virtual void searchableTablesEmitIndexArrayI() const;
960-
virtual void
961-
searchableTablesEmitIndexTypeStruct(const GenericTable &Table,
962-
const SearchIndex &Index);
960+
virtual void searchableTablesEmitIndexTypeStruct(const GenericTable &Table,
961+
const SearchIndex &Index);
963962
virtual void searchableTablesEmitReturns(const GenericTable &Table,
964963
const SearchIndex &Index,
965964
bool IsPrimary);
@@ -1010,7 +1009,8 @@ class PrinterCapstone : public PrinterLLVM {
10101009
bool Newline = true,
10111010
bool UndefAtEnd = false) const override;
10121011

1013-
static std::string translateToC(std::string const &Dec);
1012+
static std::string translateToC(std::string const &TargetName,
1013+
std::string const &Dec);
10141014

10151015
//------------------------
10161016
// Backend: RegisterInfo
@@ -1807,9 +1807,8 @@ class PrinterCapstone : public PrinterLLVM {
18071807
std::string Repr) const override;
18081808
void searchableTablesEmitIndexArrayII() const override;
18091809
void searchableTablesEmitIndexArrayI() const override;
1810-
void
1811-
searchableTablesEmitIndexTypeStruct(const GenericTable &Table,
1812-
const SearchIndex &Index) override;
1810+
void searchableTablesEmitIndexTypeStruct(const GenericTable &Table,
1811+
const SearchIndex &Index) override;
18131812
void searchableTablesEmitReturns(const GenericTable &Table,
18141813
const SearchIndex &Index,
18151814
bool IsPrimary) override;

llvm/utils/TableGen/PrinterCapstone.cpp

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -658,14 +658,20 @@ std::string edgeCaseTemplArg(std::string &Code) {
658658
PrintFatalNote("Edge case for C++ code not handled: " + Code);
659659
}
660660

661-
static std::string handleDefaultArg(std::string &Code) {
661+
static std::string handleDefaultArg(const std::string &TargetName,
662+
std::string &Code) {
662663
static SmallVector<std::pair<std::string, std::string>>
663-
TemplFuncWithDefaults = {// Default is 1
664-
{"printVectorIndex", "1"},
665-
// Default is false == 0
666-
{"printPrefetchOp", "0"}};
664+
AArch64TemplFuncWithDefaults = {// Default is 1
665+
{"printVectorIndex", "1"},
666+
// Default is false == 0
667+
{"printPrefetchOp", "0"}};
668+
SmallVector<std::pair<std::string, std::string>> *TemplFuncWithDefaults;
669+
if (TargetName == "AArch64")
670+
TemplFuncWithDefaults = &AArch64TemplFuncWithDefaults;
671+
else
672+
return Code;
667673

668-
for (std::pair Func : TemplFuncWithDefaults) {
674+
for (std::pair Func : *TemplFuncWithDefaults) {
669675
if (Code.find(Func.first) != std::string::npos) {
670676
unsigned long const B =
671677
Code.find(Func.first) + std::string(Func.first).size();
@@ -681,11 +687,12 @@ static std::string handleDefaultArg(std::string &Code) {
681687
return Code;
682688
}
683689

684-
static void patchTemplateArgs(std::string &Code) {
690+
static void patchTemplateArgs(const std::string &TargetName,
691+
std::string &Code) {
685692
unsigned long const B = Code.find_first_of("<");
686693
unsigned long const E = Code.find(">");
687694
if (B == std::string::npos) {
688-
Code = handleDefaultArg(Code);
695+
Code = handleDefaultArg(TargetName, Code);
689696
return;
690697
}
691698
std::string const &DecName = Code.substr(0, B);
@@ -707,12 +714,13 @@ static void patchTemplateArgs(std::string &Code) {
707714
Code = DecName + "_" + Args + Rest;
708715
}
709716

710-
std::string PrinterCapstone::translateToC(std::string const &Code) {
717+
std::string PrinterCapstone::translateToC(std::string const &TargetName,
718+
std::string const &Code) {
711719
std::string PatchedCode(Code);
712720
patchQualifier(PatchedCode);
713721
patchNullptr(PatchedCode);
714722
patchIsGetImmReg(PatchedCode);
715-
patchTemplateArgs(PatchedCode);
723+
patchTemplateArgs(TargetName, PatchedCode);
716724
return PatchedCode;
717725
}
718726

@@ -721,7 +729,7 @@ void PrinterCapstone::decoderEmitterEmitOpDecoder(raw_ostream &DecoderOS,
721729
unsigned const Indent = 4;
722730
DecoderOS.indent(Indent) << GuardPrefix;
723731
if (Op.Decoder.find("<") != std::string::npos) {
724-
DecoderOS << translateToC(Op.Decoder);
732+
DecoderOS << translateToC(TargetName, Op.Decoder);
725733
} else {
726734
DecoderOS << Op.Decoder;
727735
}
@@ -735,7 +743,7 @@ void PrinterCapstone::decoderEmitterEmitOpBinaryParser(
735743
raw_ostream &DecOS, const OperandInfo &OpInfo) const {
736744
unsigned const Indent = 4;
737745
const std::string &Decoder = (OpInfo.Decoder.find("<") != std::string::npos)
738-
? translateToC(OpInfo.Decoder)
746+
? translateToC(TargetName, OpInfo.Decoder)
739747
: OpInfo.Decoder;
740748

741749
bool const UseInsertBits = OpInfo.numFields() != 1 || OpInfo.InitValue != 0;
@@ -1387,11 +1395,11 @@ void PrinterCapstone::asmWriterEmitPrintInstruction(
13871395
// Emit two possibilitys with if/else.
13881396
OS << " if ((Bits >> " << (OpcodeInfoBits - BitsLeft) << ") & "
13891397
<< ((1 << NumBits) - 1) << ") {\n"
1390-
<< translateToC(Commands[1]) << " } else {\n"
1391-
<< translateToC(Commands[0]) << " }\n\n";
1398+
<< translateToC(TargetName, Commands[1]) << " } else {\n"
1399+
<< translateToC(TargetName, Commands[0]) << " }\n\n";
13921400
} else if (Commands.size() == 1) {
13931401
// Emit a single possibility.
1394-
OS << translateToC(Commands[0]) << "\n\n";
1402+
OS << translateToC(TargetName, Commands[0]) << "\n\n";
13951403
} else {
13961404
OS << " switch ((Bits >> " << (OpcodeInfoBits - BitsLeft) << ") & "
13971405
<< ((1 << NumBits) - 1) << ") {\n"
@@ -1400,7 +1408,7 @@ void PrinterCapstone::asmWriterEmitPrintInstruction(
14001408
// Print out all the cases.
14011409
for (unsigned J = 0, F = Commands.size(); J != F; ++J) {
14021410
OS << " case " << J << ":\n";
1403-
OS << translateToC(Commands[J]);
1411+
OS << translateToC(TargetName, Commands[J]);
14041412
OS << " break;\n";
14051413
}
14061414
OS << " }\n\n";
@@ -1425,7 +1433,7 @@ void PrinterCapstone::asmWriterEmitOpCases(
14251433
}
14261434

14271435
// Finally, emit the code.
1428-
OS << "\n " << TheOp.getCode(PassSubtarget);
1436+
OS << "\n " << translateToC(TargetName, TheOp.getCode(PassSubtarget));
14291437
OS << "\n break;\n";
14301438
}
14311439

@@ -1459,7 +1467,7 @@ void PrinterCapstone::asmWriterEmitInstruction(
14591467
for (unsigned I = 0, E = FirstInst.Operands.size(); I != E; ++I) {
14601468
if (I != DifferingOperand) {
14611469
// If the operand is the same for all instructions, just print it.
1462-
OS << " " << FirstInst.Operands[I].getCode(PassSubtarget);
1470+
OS << " " << translateToC(TargetName, FirstInst.Operands[I].getCode(PassSubtarget));
14631471
} else {
14641472
// If this is the operand that varies between all of the instructions,
14651473
// emit a switch for just this operand now.
@@ -1768,7 +1776,7 @@ void PrinterCapstone::asmWriterEmitPrintAliasOp(
17681776
for (unsigned I = 0; I < PrintMethods.size(); ++I) {
17691777
OS << " case " << I << ":\n";
17701778
std::string PrintMethod =
1771-
PrinterCapstone::translateToC(PrintMethods[I].first);
1779+
PrinterCapstone::translateToC(TargetName, PrintMethods[I].first);
17721780
OS << " " << PrintMethod << "(MI, "
17731781
<< (PrintMethods[I].second ? "Address, " : "") << "OpIdx, "
17741782
<< "OS);\n"
@@ -1796,7 +1804,8 @@ void PrinterCapstone::asmWriterEmitPrintMC(
17961804
StringRef const MCOpPred =
17971805
MCOpPredicates[I]->getValueAsString("MCOperandPredicate");
17981806
OS << " case " << I + 1 << ": {\n";
1799-
std::string PrintMethod = PrinterCapstone::translateToC(MCOpPred.data());
1807+
std::string PrintMethod =
1808+
PrinterCapstone::translateToC(TargetName, MCOpPred.data());
18001809
OS << PrintMethod << "\n"
18011810
<< " }\n";
18021811
}
@@ -2908,7 +2917,8 @@ void printOpPrintGroupEnum(StringRef const &TargetName,
29082917

29092918
for (const CGIOperandList::OperandInfo &Op : CGI->Operands) {
29102919
std::string OpGroup =
2911-
PrinterCapstone::translateToC(Op.PrinterMethodName).substr(5);
2920+
PrinterCapstone::translateToC(TargetName.str(), Op.PrinterMethodName)
2921+
.substr(5);
29122922
if (OpGroups.find(OpGroup) != OpGroups.end())
29132923
continue;
29142924
OpGroupEnum.indent(2) << TargetName + "_OP_GROUP_" + OpGroup + " = "

0 commit comments

Comments
 (0)