[llvm] 1e6905f - [TableGen] Only track reference locations if asked
River Riddle via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 28 00:48:25 PDT 2022
Author: River Riddle
Date: 2022-09-28T00:47:57-07:00
New Revision: 1e6905f13dedf12ba41ebd656f3f969ace59516f
URL: https://github.com/llvm/llvm-project/commit/1e6905f13dedf12ba41ebd656f3f969ace59516f
DIFF: https://github.com/llvm/llvm-project/commit/1e6905f13dedf12ba41ebd656f3f969ace59516f.diff
LOG: [TableGen] Only track reference locations if asked
Normal compilation doesn't care about tracking references,
and shouldn't pay the compilation time cost.
Added:
Modified:
llvm/lib/TableGen/Parser.cpp
llvm/lib/TableGen/TGParser.cpp
llvm/lib/TableGen/TGParser.h
Removed:
################################################################################
diff --git a/llvm/lib/TableGen/Parser.cpp b/llvm/lib/TableGen/Parser.cpp
index 818ded19432b..fd98a538a65e 100644
--- a/llvm/lib/TableGen/Parser.cpp
+++ b/llvm/lib/TableGen/Parser.cpp
@@ -28,7 +28,9 @@ bool llvm::TableGenParseFile(SourceMgr &InputSrcMgr, RecordKeeper &Records) {
auto *MainFileBuffer = SrcMgr.getMemoryBuffer(SrcMgr.getMainFileID());
Records.saveInputFilename(MainFileBuffer->getBufferIdentifier().str());
- TGParser Parser(SrcMgr, /*Macros=*/None, Records);
+ TGParser Parser(SrcMgr, /*Macros=*/None, Records,
+ /*NoWarnOnUnusedTemplateArgs=*/false,
+ /*TrackReferenceLocs=*/true);
bool ParseResult = Parser.ParseFile();
// After parsing, reclaim the source manager buffers from TableGen's global
diff --git a/llvm/lib/TableGen/TGParser.cpp b/llvm/lib/TableGen/TGParser.cpp
index 82a589a7a77e..a574d20a75e9 100644
--- a/llvm/lib/TableGen/TGParser.cpp
+++ b/llvm/lib/TableGen/TGParser.cpp
@@ -586,7 +586,7 @@ Record *TGParser::ParseClassID() {
Lex.getCurStrVal() + "'");
else
TokError(Msg);
- } else {
+ } else if (TrackReferenceLocs) {
Result->appendReferenceLoc(Lex.getLocRange());
}
@@ -873,7 +873,8 @@ Init *TGParser::ParseIDValue(Record *CurRec, StringInit *Name, SMRange NameLoc,
IDParseMode Mode) {
if (CurRec) {
if (RecordVal *RV = CurRec->getValue(Name)) {
- RV->addReferenceLoc(NameLoc);
+ if (TrackReferenceLocs)
+ RV->addReferenceLoc(NameLoc);
return VarInit::get(Name, RV->getType());
}
}
@@ -891,7 +892,8 @@ Init *TGParser::ParseIDValue(Record *CurRec, StringInit *Name, SMRange NameLoc,
RecordVal *RV = TemplateRec->getValue(TemplateArgName);
assert(RV && "Template arg doesn't exist??");
RV->setUsed(true);
- RV->addReferenceLoc(NameLoc);
+ if (TrackReferenceLocs)
+ RV->addReferenceLoc(NameLoc);
return VarInit::get(TemplateArgName, RV->getType());
} else if (Name->getValue() == "NAME") {
return VarInit::get(TemplateArgName, StringRecTy::get(Records));
@@ -916,8 +918,10 @@ Init *TGParser::ParseIDValue(Record *CurRec, StringInit *Name, SMRange NameLoc,
if (Init *I = Records.getGlobal(Name->getValue())) {
// Add a reference to the global if it's a record.
- if (auto *Def = dyn_cast<DefInit>(I))
- Def->getDef()->appendReferenceLoc(NameLoc);
+ if (TrackReferenceLocs) {
+ if (auto *Def = dyn_cast<DefInit>(I))
+ Def->getDef()->appendReferenceLoc(NameLoc);
+ }
return I;
}
@@ -2229,7 +2233,8 @@ Init *TGParser::ParseSimpleValue(Record *CurRec, RecTy *ItemType,
}
}
- Class->appendReferenceLoc(NameLoc);
+ if (TrackReferenceLocs)
+ Class->appendReferenceLoc(NameLoc);
return VarDefInit::get(Class, Args)->Fold();
}
case tgtok::l_brace: { // Value ::= '{' ValueList '}'
@@ -2530,13 +2535,15 @@ Init *TGParser::ParseValue(Record *CurRec, RecTy *ItemType, IDParseMode Mode) {
}
// Add a reference to this field if we know the record class.
- if (auto *DI = dyn_cast<DefInit>(Result)) {
- DI->getDef()->getValue(FieldName)->addReferenceLoc(FieldNameLoc);
- } else if (auto *TI = dyn_cast<TypedInit>(Result)) {
- if (auto *RecTy = dyn_cast<RecordRecTy>(TI->getType())) {
- for (Record *R : RecTy->getClasses())
- if (auto *RV = R->getValue(FieldName))
- RV->addReferenceLoc(FieldNameLoc);
+ if (TrackReferenceLocs) {
+ if (auto *DI = dyn_cast<DefInit>(Result)) {
+ DI->getDef()->getValue(FieldName)->addReferenceLoc(FieldNameLoc);
+ } else if (auto *TI = dyn_cast<TypedInit>(Result)) {
+ if (auto *RecTy = dyn_cast<RecordRecTy>(TI->getType())) {
+ for (Record *R : RecTy->getClasses())
+ if (auto *RV = R->getValue(FieldName))
+ RV->addReferenceLoc(FieldNameLoc);
+ }
}
}
diff --git a/llvm/lib/TableGen/TGParser.h b/llvm/lib/TableGen/TGParser.h
index 0e630dc99186..f7271a5e79c3 100644
--- a/llvm/lib/TableGen/TGParser.h
+++ b/llvm/lib/TableGen/TGParser.h
@@ -161,12 +161,15 @@ class TGParser {
};
bool NoWarnOnUnusedTemplateArgs = false;
+ bool TrackReferenceLocs = false;
public:
TGParser(SourceMgr &SM, ArrayRef<std::string> Macros, RecordKeeper &records,
- const bool NoWarnOnUnusedTemplateArgs = false)
+ const bool NoWarnOnUnusedTemplateArgs = false,
+ const bool TrackReferenceLocs = false)
: Lex(SM, Macros), CurMultiClass(nullptr), Records(records),
- NoWarnOnUnusedTemplateArgs(NoWarnOnUnusedTemplateArgs) {}
+ NoWarnOnUnusedTemplateArgs(NoWarnOnUnusedTemplateArgs),
+ TrackReferenceLocs(TrackReferenceLocs) {}
/// ParseFile - Main entrypoint for parsing a tblgen file. These parser
/// routines return true on error, or false on success.
More information about the llvm-commits
mailing list