Skip to content

[TableGen] Change getValueAsListOfDefs to return const pointer vector #110713

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clang/utils/TableGen/ASTTableGen.h
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ class PropertyType : public WrappedRecord {
}

std::vector<const llvm::Record *> getBufferElementTypes() const {
return get()->getValueAsListOfConstDefs(BufferElementTypesFieldName);
return get()->getValueAsListOfDefs(BufferElementTypesFieldName);
}

static llvm::StringRef getTableGenNodeClassName() {
Expand Down
55 changes: 25 additions & 30 deletions clang/utils/TableGen/ClangAttrEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1746,8 +1746,7 @@ getSpellingListIndex(const std::vector<FlattenedSpelling> &SpellingList,
}

static void writeAttrAccessorDefinition(const Record &R, raw_ostream &OS) {
std::vector<const Record *> Accessors =
R.getValueAsListOfConstDefs("Accessors");
std::vector<const Record *> Accessors = R.getValueAsListOfDefs("Accessors");
if (Accessors.empty())
return;

Expand Down Expand Up @@ -1964,19 +1963,19 @@ struct AttributeSubjectMatchRule {

std::vector<const Record *> getSubjects() const {
return (Constraint ? Constraint : MetaSubject)
->getValueAsListOfConstDefs("Subjects");
->getValueAsListOfDefs("Subjects");
}

std::vector<const Record *> getLangOpts() const {
if (Constraint) {
// Lookup the options in the sub-rule first, in case the sub-rule
// overrides the rules options.
std::vector<const Record *> Opts =
Constraint->getValueAsListOfConstDefs("LangOpts");
Constraint->getValueAsListOfDefs("LangOpts");
if (!Opts.empty())
return Opts;
}
return MetaSubject->getValueAsListOfConstDefs("LangOpts");
return MetaSubject->getValueAsListOfDefs("LangOpts");
}

// Abstract rules are used only for sub-rules
Expand Down Expand Up @@ -2105,7 +2104,7 @@ PragmaClangAttributeSupport::PragmaClangAttributeSupport(
const Record *Constraint) {
Rules.emplace_back(MetaSubject, Constraint);
for (const Record *Subject :
SubjectContainer->getValueAsListOfConstDefs("Subjects")) {
SubjectContainer->getValueAsListOfDefs("Subjects")) {
bool Inserted =
SubjectsToRules
.try_emplace(Subject, RuleOrAggregateRuleSet::getRule(
Expand Down Expand Up @@ -2503,7 +2502,7 @@ static void emitClangAttrTypeArgList(const RecordKeeper &Records,
std::map<std::string, FSIVecTy> FSIMap;
for (const auto *Attr : Records.getAllDerivedDefinitions("Attr")) {
// Determine whether the first argument is a type.
std::vector<const Record *> Args = Attr->getValueAsListOfConstDefs("Args");
std::vector<const Record *> Args = Attr->getValueAsListOfDefs("Args");
if (Args.empty())
continue;

Expand Down Expand Up @@ -2581,7 +2580,7 @@ static void emitClangAttrVariadicIdentifierArgList(const RecordKeeper &Records,
std::map<std::string, FSIVecTy> FSIMap;
for (const auto *A : Records.getAllDerivedDefinitions("Attr")) {
// Determine whether the first argument is a variadic identifier.
std::vector<const Record *> Args = A->getValueAsListOfConstDefs("Args");
std::vector<const Record *> Args = A->getValueAsListOfDefs("Args");
if (Args.empty() || !isVariadicIdentifierArgument(Args[0]))
continue;
generateFlattenedSpellingInfo(*A, FSIMap);
Expand Down Expand Up @@ -2614,7 +2613,7 @@ emitClangAttrUnevaluatedStringLiteralList(const RecordKeeper &Records,
std::map<std::string, FSIVecTy> FSIMap;
for (const auto *Attr : Records.getAllDerivedDefinitions("Attr")) {
// Determine whether there are any string arguments.
uint32_t ArgMask = MakeMask(Attr->getValueAsListOfConstDefs("Args"));
uint32_t ArgMask = MakeMask(Attr->getValueAsListOfDefs("Args"));
if (!ArgMask)
continue;
generateFlattenedSpellingInfo(*Attr, FSIMap, ArgMask);
Expand All @@ -2630,7 +2629,7 @@ static void emitClangAttrIdentifierArgList(const RecordKeeper &Records,
std::map<std::string, FSIVecTy> FSIMap;
for (const auto *Attr : Records.getAllDerivedDefinitions("Attr")) {
// Determine whether the first argument is an identifier.
std::vector<const Record *> Args = Attr->getValueAsListOfConstDefs("Args");
std::vector<const Record *> Args = Attr->getValueAsListOfDefs("Args");
if (Args.empty() || !isIdentifierArgument(Args[0]))
continue;
generateFlattenedSpellingInfo(*Attr, FSIMap);
Expand All @@ -2648,7 +2647,7 @@ static void emitClangAttrStrictIdentifierArgList(const RecordKeeper &Records,
if (!Attr->getValueAsBit("StrictEnumParameters"))
continue;
// Check that there is really an identifier argument.
std::vector<const Record *> Args = Attr->getValueAsListOfConstDefs("Args");
std::vector<const Record *> Args = Attr->getValueAsListOfDefs("Args");
if (none_of(Args, [&](const Record *R) { return isIdentifierArgument(R); }))
continue;
generateFlattenedSpellingInfo(*Attr, FSIMap);
Expand All @@ -2670,7 +2669,7 @@ static void emitClangAttrThisIsaIdentifierArgList(const RecordKeeper &Records,
std::map<std::string, FSIVecTy> FSIMap;
for (const auto *A : Records.getAllDerivedDefinitions("Attr")) {
// Determine whether the first argument is a variadic identifier.
std::vector<const Record *> Args = A->getValueAsListOfConstDefs("Args");
std::vector<const Record *> Args = A->getValueAsListOfDefs("Args");
if (Args.empty() || !keywordThisIsaIdentifierInArgument(Args[0]))
continue;
generateFlattenedSpellingInfo(*A, FSIMap);
Expand Down Expand Up @@ -2763,8 +2762,7 @@ static void emitAttributes(const RecordKeeper &Records, raw_ostream &OS,
else
OS << "\n// " << R.getName() << "Attr implementation\n\n";

std::vector<const Record *> ArgRecords =
R.getValueAsListOfConstDefs("Args");
std::vector<const Record *> ArgRecords = R.getValueAsListOfDefs("Args");
std::vector<std::unique_ptr<Argument>> Args;
Args.reserve(ArgRecords.size());

Expand Down Expand Up @@ -3539,7 +3537,7 @@ void EmitClangAttrPCHRead(const RecordKeeper &Records, raw_ostream &OS) {
std::make_unique<VariadicExprArgument>("DelayedArgs", R.getName());
DelayedArgs->writePCHReadDecls(OS);
}
ArgRecords = R.getValueAsListOfConstDefs("Args");
ArgRecords = R.getValueAsListOfDefs("Args");
Args.clear();
for (const auto *Arg : ArgRecords) {
Args.emplace_back(createArgument(*Arg, R.getName()));
Expand Down Expand Up @@ -3578,7 +3576,7 @@ void EmitClangAttrPCHWrite(const RecordKeeper &Records, raw_ostream &OS) {
if (!R.getValueAsBit("ASTNode"))
continue;
OS << " case attr::" << R.getName() << ": {\n";
std::vector<const Record *> Args = R.getValueAsListOfConstDefs("Args");
std::vector<const Record *> Args = R.getValueAsListOfDefs("Args");
if (R.isSubClassOf(InhClass) || !Args.empty())
OS << " const auto *SA = cast<" << R.getName()
<< "Attr>(A);\n";
Expand Down Expand Up @@ -3769,7 +3767,7 @@ void EmitClangRegularKeywordAttributeInfo(const RecordKeeper &Records,
for (const auto &S : GetFlattenedSpellings(*R)) {
if (!isRegularKeywordAttribute(S))
continue;
std::vector<const Record *> Args = R->getValueAsListOfConstDefs("Args");
std::vector<const Record *> Args = R->getValueAsListOfDefs("Args");
bool HasArgs = any_of(
Args, [](const Record *Arg) { return !Arg->getValueAsBit("Fake"); });

Expand Down Expand Up @@ -3999,8 +3997,7 @@ void EmitClangAttrTemplateInstantiateHelper(ArrayRef<const Record *> Attrs,
continue;
}

std::vector<const Record *> ArgRecords =
R.getValueAsListOfConstDefs("Args");
std::vector<const Record *> ArgRecords = R.getValueAsListOfDefs("Args");
std::vector<std::unique_ptr<Argument>> Args;
Args.reserve(ArgRecords.size());

Expand Down Expand Up @@ -4205,7 +4202,7 @@ static void GenerateAppertainsTo(const Record &Attr, raw_ostream &OS) {

const Record *SubjectObj = Attr.getValueAsDef("Subjects");
std::vector<const Record *> Subjects =
SubjectObj->getValueAsListOfConstDefs("Subjects");
SubjectObj->getValueAsListOfDefs("Subjects");

// If the list of subjects is empty, it is assumed that the attribute
// appertains to everything.
Expand Down Expand Up @@ -4337,7 +4334,7 @@ static void GenerateMutualExclusionsChecks(const Record &Attr,
for (const Record *Exclusion :
Records.getAllDerivedDefinitions("MutualExclusions")) {
std::vector<const Record *> MutuallyExclusiveAttrs =
Exclusion->getValueAsListOfConstDefs("Exclusions");
Exclusion->getValueAsListOfDefs("Exclusions");
auto IsCurAttr = [Attr](const Record *R) {
return R->getName() == Attr.getName();
};
Expand Down Expand Up @@ -4483,8 +4480,7 @@ static void GenerateLangOptRequirements(const Record &R,
raw_ostream &OS) {
// If the attribute has an empty or unset list of language requirements,
// use the default handler.
std::vector<const Record *> LangOpts =
R.getValueAsListOfConstDefs("LangOpts");
std::vector<const Record *> LangOpts = R.getValueAsListOfDefs("LangOpts");
if (LangOpts.empty())
return;

Expand Down Expand Up @@ -4629,7 +4625,7 @@ static bool isParamExpr(const Record *Arg) {
void GenerateIsParamExpr(const Record &Attr, raw_ostream &OS) {
OS << "bool isParamExpr(size_t N) const override {\n";
OS << " return ";
auto Args = Attr.getValueAsListOfConstDefs("Args");
auto Args = Attr.getValueAsListOfDefs("Args");
for (size_t I = 0; I < Args.size(); ++I)
if (isParamExpr(Args[I]))
OS << "(N == " << I << ") || ";
Expand Down Expand Up @@ -4792,7 +4788,7 @@ void EmitClangAttrParsedAttrImpl(const RecordKeeper &Records, raw_ostream &OS) {
GenerateLangOptRequirements(Attr, OS);
GenerateTargetRequirements(Attr, Dupes, OS);
GenerateSpellingTargetRequirements(
Attr, Attr.getValueAsListOfConstDefs("TargetSpecificSpellings"), OS);
Attr, Attr.getValueAsListOfDefs("TargetSpecificSpellings"), OS);
GenerateSpellingIndexToSemanticSpelling(Attr, OS);
PragmaAttributeSupport.generateStrictConformsTo(*I->second, OS);
GenerateHandleDeclAttribute(Attr, OS);
Expand Down Expand Up @@ -4959,7 +4955,7 @@ void EmitClangAttrTextNodeDump(const RecordKeeper &Records, raw_ostream &OS) {
if (Spellings.size() > 1 && !SpellingNamesAreCommon(Spellings))
SS << " OS << \" \" << A->getSpelling();\n";

std::vector<const Record *> Args = R.getValueAsListOfConstDefs("Args");
std::vector<const Record *> Args = R.getValueAsListOfDefs("Args");
for (const auto *Arg : Args)
createArgument(*Arg, R.getName())->writeDump(SS);

Expand Down Expand Up @@ -4989,7 +4985,7 @@ void EmitClangAttrNodeTraverse(const RecordKeeper &Records, raw_ostream &OS) {
std::string FunctionContent;
raw_string_ostream SS(FunctionContent);

std::vector<const Record *> Args = R.getValueAsListOfConstDefs("Args");
std::vector<const Record *> Args = R.getValueAsListOfDefs("Args");
for (const auto *Arg : Args)
createArgument(*Arg, R.getName())->writeDumpChildren(SS);
if (Attr->getValueAsBit("AcceptsExprPack"))
Expand Down Expand Up @@ -5033,8 +5029,7 @@ void EmitClangAttrDocTable(const RecordKeeper &Records, raw_ostream &OS) {
for (const auto *A : Records.getAllDerivedDefinitions("Attr")) {
if (!A->getValueAsBit("ASTNode"))
continue;
std::vector<const Record *> Docs =
A->getValueAsListOfConstDefs("Documentation");
std::vector<const Record *> Docs = A->getValueAsListOfDefs("Documentation");
assert(!Docs.empty());
// Only look at the first documentation if there are several.
// (Currently there's only one such attr, revisit if this becomes common).
Expand Down Expand Up @@ -5254,7 +5249,7 @@ void EmitClangAttrDocs(const RecordKeeper &Records, raw_ostream &OS) {
for (const auto *A : Records.getAllDerivedDefinitions("Attr")) {
const Record &Attr = *A;
std::vector<const Record *> Docs =
Attr.getValueAsListOfConstDefs("Documentation");
Attr.getValueAsListOfDefs("Documentation");
for (const auto *D : Docs) {
const Record &Doc = *D;
const Record *Category = Doc.getValueAsDef("Category");
Expand Down
2 changes: 1 addition & 1 deletion clang/utils/TableGen/ClangDiagnosticsEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class DiagGroupParentMap {
Records.getAllDerivedDefinitions("DiagGroup");
for (unsigned i = 0, e = DiagGroups.size(); i != e; ++i) {
std::vector<const Record *> SubGroups =
DiagGroups[i]->getValueAsListOfConstDefs("SubGroups");
DiagGroups[i]->getValueAsListOfDefs("SubGroups");
for (unsigned j = 0, e = SubGroups.size(); j != e; ++j)
Mapping[SubGroups[j]].push_back(DiagGroups[i]);
}
Expand Down
16 changes: 8 additions & 8 deletions clang/utils/TableGen/ClangOpcodesEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void Enumerate(const Record *R, StringRef N,

if (const auto *TypeClass = dyn_cast<DefInit>(Types->getElement(I))) {
for (const auto *Type :
TypeClass->getDef()->getValueAsListOfConstDefs("Types")) {
TypeClass->getDef()->getValueAsListOfDefs("Types")) {
TypePath.push_back(Type);
Rec(I + 1, ID + Type->getName());
TypePath.pop_back();
Expand Down Expand Up @@ -117,7 +117,7 @@ void ClangOpcodesEmitter::EmitInterp(raw_ostream &OS, StringRef N,
[this, R, &OS, &N](ArrayRef<const Record *> TS, const Twine &ID) {
bool CanReturn = R->getValueAsBit("CanReturn");
bool ChangesPC = R->getValueAsBit("ChangesPC");
const auto &Args = R->getValueAsListOfConstDefs("Args");
const auto &Args = R->getValueAsListOfDefs("Args");

OS << "case OP_" << ID << ": {\n";

Expand Down Expand Up @@ -176,7 +176,7 @@ void ClangOpcodesEmitter::EmitDisasm(raw_ostream &OS, StringRef N,
OS << " PrintName(\"" << ID << "\");\n";
OS << " OS << \"\\t\"";

for (const auto *Arg : R->getValueAsListOfConstDefs("Args")) {
for (const auto *Arg : R->getValueAsListOfDefs("Args")) {
OS << " << ReadArg<" << Arg->getValueAsString("Name") << ">(P, PC)";
OS << " << \" \"";
}
Expand All @@ -194,7 +194,7 @@ void ClangOpcodesEmitter::EmitEmitter(raw_ostream &OS, StringRef N,

OS << "#ifdef GET_LINK_IMPL\n";
Enumerate(R, N, [R, &OS](ArrayRef<const Record *>, const Twine &ID) {
const auto &Args = R->getValueAsListOfConstDefs("Args");
const auto &Args = R->getValueAsListOfDefs("Args");

// Emit the list of arguments.
OS << "bool ByteCodeEmitter::emit" << ID << "(";
Expand Down Expand Up @@ -227,7 +227,7 @@ void ClangOpcodesEmitter::EmitEmitter(raw_ostream &OS, StringRef N,
void ClangOpcodesEmitter::EmitProto(raw_ostream &OS, StringRef N,
const Record *R) {
OS << "#if defined(GET_EVAL_PROTO) || defined(GET_LINK_PROTO)\n";
auto Args = R->getValueAsListOfConstDefs("Args");
auto Args = R->getValueAsListOfDefs("Args");
Enumerate(R, N, [&OS, &Args](ArrayRef<const Record *> TS, const Twine &ID) {
OS << "bool emit" << ID << "(";
for (size_t I = 0, N = Args.size(); I < N; ++I) {
Expand Down Expand Up @@ -268,7 +268,7 @@ void ClangOpcodesEmitter::EmitGroup(raw_ostream &OS, StringRef N,
return;

const auto *Types = R->getValueAsListInit("Types");
const auto &Args = R->getValueAsListOfConstDefs("Args");
const auto &Args = R->getValueAsListOfDefs("Args");

Twine EmitFuncName = "emit" + N;

Expand Down Expand Up @@ -333,7 +333,7 @@ void ClangOpcodesEmitter::EmitGroup(raw_ostream &OS, StringRef N,
// Print a switch statement selecting T.
if (auto *TypeClass = dyn_cast<DefInit>(Types->getElement(I))) {
OS << " switch (T" << I << ") {\n";
auto Cases = TypeClass->getDef()->getValueAsListOfConstDefs("Types");
auto Cases = TypeClass->getDef()->getValueAsListOfDefs("Types");
for (auto *Case : Cases) {
OS << " case PT_" << Case->getName() << ":\n";
TS.push_back(Case);
Expand Down Expand Up @@ -364,7 +364,7 @@ void ClangOpcodesEmitter::EmitEval(raw_ostream &OS, StringRef N,
OS << "#ifdef GET_EVAL_IMPL\n";
Enumerate(R, N,
[this, R, &N, &OS](ArrayRef<const Record *> TS, const Twine &ID) {
auto Args = R->getValueAsListOfConstDefs("Args");
auto Args = R->getValueAsListOfDefs("Args");

OS << "bool EvalEmitter::emit" << ID << "(";
for (size_t I = 0, N = Args.size(); I < N; ++I) {
Expand Down
20 changes: 9 additions & 11 deletions clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -480,9 +480,8 @@ static void VerifySignature(ArrayRef<const Record *> Signature,
}

// Check number of data types.
unsigned NTypes = T->getValueAsDef("TypeList")
->getValueAsListOfConstDefs("List")
.size();
unsigned NTypes =
T->getValueAsDef("TypeList")->getValueAsListOfDefs("List").size();
if (NTypes != GenTypeTypes && NTypes != 1) {
if (GenTypeTypes > 1) {
// We already saw a gentype with a different number of types.
Expand Down Expand Up @@ -512,7 +511,7 @@ void BuiltinNameEmitter::GetOverloads() {
StringRef BName = B->getValueAsString("Name");
FctOverloadMap.try_emplace(BName);

auto Signature = B->getValueAsListOfConstDefs("Signature");
auto Signature = B->getValueAsListOfDefs("Signature");
// Reuse signatures to avoid unnecessary duplicates.
auto it =
find_if(SignaturesList,
Expand Down Expand Up @@ -636,8 +635,8 @@ void BuiltinNameEmitter::EmitBuiltinTable() {
Overload.first->getValueAsDef("MaxVersion")->getValueAsInt("ID");

OS << " { " << Overload.second << ", "
<< Overload.first->getValueAsListOfConstDefs("Signature").size()
<< ", " << (Overload.first->getValueAsBit("IsPure")) << ", "
<< Overload.first->getValueAsListOfDefs("Signature").size() << ", "
<< (Overload.first->getValueAsBit("IsPure")) << ", "
<< (Overload.first->getValueAsBit("IsConst")) << ", "
<< (Overload.first->getValueAsBit("IsConv")) << ", "
<< FunctionExtensionIndex[ExtName] << ", "
Expand Down Expand Up @@ -852,7 +851,7 @@ static void OCL2Qual(Sema &S, const OpenCLTypeStruct &Ty,
// the plain scalar types for now; other type information such as vector
// size and type qualifiers will be added after the switch statement.
std::vector<const Record *> BaseTypes =
GenType->getValueAsDef("TypeList")->getValueAsListOfConstDefs("List");
GenType->getValueAsDef("TypeList")->getValueAsListOfDefs("List");

// Collect all QualTypes for a single vector size into TypeList.
OS << " SmallVector<QualType, " << BaseTypes.size() << "> TypeList;\n";
Expand Down Expand Up @@ -1028,8 +1027,7 @@ void OpenCLBuiltinFileEmitterBase::getTypeLists(
std::vector<int64_t> &VectorList) const {
bool isGenType = Type->isSubClassOf("GenericType");
if (isGenType) {
TypeList =
Type->getValueAsDef("TypeList")->getValueAsListOfConstDefs("List");
TypeList = Type->getValueAsDef("TypeList")->getValueAsListOfDefs("List");
VectorList =
Type->getValueAsDef("VectorList")->getValueAsListOfInts("List");
return;
Expand Down Expand Up @@ -1215,7 +1213,7 @@ void OpenCLBuiltinTestEmitter::emit() {
StringRef Name = B->getValueAsString("Name");

SmallVector<SmallVector<std::string, 2>, 4> FTypes;
expandTypesInSignature(B->getValueAsListOfConstDefs("Signature"), FTypes);
expandTypesInSignature(B->getValueAsListOfDefs("Signature"), FTypes);

OS << "// Test " << Name << "\n";

Expand Down Expand Up @@ -1284,7 +1282,7 @@ void OpenCLBuiltinHeaderEmitter::emit() {
std::string OptionalVersionEndif = emitVersionGuard(B);

SmallVector<SmallVector<std::string, 2>, 4> FTypes;
expandTypesInSignature(B->getValueAsListOfConstDefs("Signature"), FTypes);
expandTypesInSignature(B->getValueAsListOfDefs("Signature"), FTypes);

for (const auto &Signature : FTypes) {
StringRef OptionalTypeExtEndif = emitTypeExtensionGuards(Signature);
Expand Down
Loading
Loading