diff --git a/clang/utils/TableGen/ClangOpcodesEmitter.cpp b/clang/utils/TableGen/ClangOpcodesEmitter.cpp index db88c990d5f9b..e624cb4d8cc6a 100644 --- a/clang/utils/TableGen/ClangOpcodesEmitter.cpp +++ b/clang/utils/TableGen/ClangOpcodesEmitter.cpp @@ -60,7 +60,7 @@ class ClangOpcodesEmitter { void Enumerate(const Record *R, StringRef N, std::function, Twine)> &&F) { llvm::SmallVector TypePath; - auto *Types = R->getValueAsListInit("Types"); + const auto *Types = R->getValueAsListInit("Types"); std::function Rec; Rec = [&TypePath, Types, &Rec, &F](size_t I, const Twine &ID) { @@ -69,8 +69,9 @@ void Enumerate(const Record *R, StringRef N, return; } - if (auto *TypeClass = dyn_cast(Types->getElement(I))) { - for (auto *Type : TypeClass->getDef()->getValueAsListOfDefs("Types")) { + if (const auto *TypeClass = dyn_cast(Types->getElement(I))) { + for (const auto *Type : + TypeClass->getDef()->getValueAsListOfDefs("Types")) { TypePath.push_back(Type); Rec(I + 1, ID + Type->getName()); TypePath.pop_back(); @@ -85,7 +86,7 @@ void Enumerate(const Record *R, StringRef N, } // namespace void ClangOpcodesEmitter::run(raw_ostream &OS) { - for (auto *Opcode : Records.getAllDerivedDefinitions(Root.getName())) { + for (const auto *Opcode : Records.getAllDerivedDefinitions(Root.getName())) { // The name is the record name, unless overriden. StringRef N = Opcode->getValueAsString("Name"); if (N.empty()) @@ -118,7 +119,7 @@ void ClangOpcodesEmitter::EmitInterp(raw_ostream &OS, StringRef N, [this, R, &OS, &N](ArrayRef TS, const Twine &ID) { bool CanReturn = R->getValueAsBit("CanReturn"); bool ChangesPC = R->getValueAsBit("ChangesPC"); - auto Args = R->getValueAsListOfDefs("Args"); + const auto &Args = R->getValueAsListOfDefs("Args"); OS << "case OP_" << ID << ": {\n"; @@ -171,7 +172,7 @@ void ClangOpcodesEmitter::EmitDisasm(raw_ostream &OS, StringRef N, OS << " PrintName(\"" << ID << "\");\n"; OS << " OS << \"\\t\""; - for (auto *Arg : R->getValueAsListOfDefs("Args")) { + for (const auto *Arg : R->getValueAsListOfDefs("Args")) { OS << " << ReadArg<" << Arg->getValueAsString("Name") << ">(P, PC)"; OS << " << \" \""; } @@ -189,7 +190,7 @@ void ClangOpcodesEmitter::EmitEmitter(raw_ostream &OS, StringRef N, OS << "#ifdef GET_LINK_IMPL\n"; Enumerate(R, N, [R, &OS](ArrayRef, const Twine &ID) { - auto Args = R->getValueAsListOfDefs("Args"); + const auto &Args = R->getValueAsListOfDefs("Args"); // Emit the list of arguments. OS << "bool ByteCodeEmitter::emit" << ID << "("; @@ -236,7 +237,7 @@ void ClangOpcodesEmitter::EmitProto(raw_ostream &OS, StringRef N, } OS << ">\n"; OS << "bool emit" << N << "("; - for (auto *Arg : Args) + for (const auto *Arg : Args) OS << Arg->getValueAsString("Name") << ", "; OS << "const SourceInfo &);\n"; OS << "#endif\n"; @@ -250,8 +251,8 @@ void ClangOpcodesEmitter::EmitGroup(raw_ostream &OS, StringRef N, if (!R->getValueAsBit("HasGroup")) return; - auto *Types = R->getValueAsListInit("Types"); - auto Args = R->getValueAsListOfDefs("Args"); + const auto *Types = R->getValueAsListInit("Types"); + const auto &Args = R->getValueAsListOfDefs("Args"); Twine EmitFuncName = "emit" + N;