llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Rahul Joshi (jurahul) <details> <summary>Changes</summary> This is a part of effort to have better const correctness in TableGen backends: https://discourse.llvm.org/t/psa-planned-changes-to-tablegen-getallderiveddefinitions-api-potential-downstream-breakages/81089 --- Patch is 275.42 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/112705.diff 41 Files Affected: - (modified) clang/utils/TableGen/ClangOptionDocEmitter.cpp (+2-2) - (modified) llvm/include/llvm/TableGen/Error.h (+2-2) - (modified) llvm/include/llvm/TableGen/Record.h (+270-256) - (modified) llvm/lib/TableGen/DetailedRecordsBackend.cpp (+1-1) - (modified) llvm/lib/TableGen/Error.cpp (+2-2) - (modified) llvm/lib/TableGen/Record.cpp (+445-428) - (modified) llvm/lib/TableGen/TGParser.cpp (+220-208) - (modified) llvm/lib/TableGen/TGParser.h (+42-40) - (modified) llvm/utils/TableGen/AsmMatcherEmitter.cpp (+22-22) - (modified) llvm/utils/TableGen/AsmWriterEmitter.cpp (+3-3) - (modified) llvm/utils/TableGen/Attributes.cpp (+1-1) - (modified) llvm/utils/TableGen/Basic/CodeGenIntrinsics.cpp (+1-1) - (modified) llvm/utils/TableGen/CodeEmitterGen.cpp (+1-1) - (modified) llvm/utils/TableGen/CodeGenMapTable.cpp (+2-2) - (modified) llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp (+31-30) - (modified) llvm/utils/TableGen/Common/CodeGenDAGPatterns.h (+5-5) - (modified) llvm/utils/TableGen/Common/CodeGenInstAlias.cpp (+2-2) - (modified) llvm/utils/TableGen/Common/CodeGenInstAlias.h (+1-1) - (modified) llvm/utils/TableGen/Common/CodeGenInstruction.cpp (+11-11) - (modified) llvm/utils/TableGen/Common/CodeGenInstruction.h (+2-2) - (modified) llvm/utils/TableGen/Common/CodeGenRegisters.cpp (+8-8) - (modified) llvm/utils/TableGen/Common/CodeGenSchedule.cpp (+5-4) - (modified) llvm/utils/TableGen/Common/CodeGenTarget.cpp (+5-5) - (modified) llvm/utils/TableGen/Common/GlobalISel/PatternParser.cpp (+2-2) - (modified) llvm/utils/TableGen/Common/GlobalISel/Patterns.cpp (+1-1) - (modified) llvm/utils/TableGen/Common/VarLenCodeEmitterGen.cpp (+6-5) - (modified) llvm/utils/TableGen/CompressInstEmitter.cpp (+4-3) - (modified) llvm/utils/TableGen/DAGISelMatcherGen.cpp (+1-1) - (modified) llvm/utils/TableGen/DFAEmitter.cpp (+1-1) - (modified) llvm/utils/TableGen/DXILEmitter.cpp (+1-1) - (modified) llvm/utils/TableGen/DecoderEmitter.cpp (+18-18) - (modified) llvm/utils/TableGen/GlobalISelCombinerEmitter.cpp (+1-1) - (modified) llvm/utils/TableGen/GlobalISelEmitter.cpp (+2-2) - (modified) llvm/utils/TableGen/InstrInfoEmitter.cpp (+2-2) - (modified) llvm/utils/TableGen/OptionParserEmitter.cpp (+5-5) - (modified) llvm/utils/TableGen/RegisterInfoEmitter.cpp (+3-3) - (modified) llvm/utils/TableGen/SearchableTableEmitter.cpp (+5-4) - (modified) llvm/utils/TableGen/X86FoldTablesEmitter.cpp (+3-3) - (modified) llvm/utils/TableGen/X86InstrMappingEmitter.cpp (+1-1) - (modified) llvm/utils/TableGen/X86RecognizableInstr.cpp (+3-5) - (modified) mlir/tools/mlir-tblgen/BytecodeDialectGen.cpp (+1-2) ``````````diff diff --git a/clang/utils/TableGen/ClangOptionDocEmitter.cpp b/clang/utils/TableGen/ClangOptionDocEmitter.cpp index b67c5d1d1146c6..ba8840c1bdca78 100644 --- a/clang/utils/TableGen/ClangOptionDocEmitter.cpp +++ b/clang/utils/TableGen/ClangOptionDocEmitter.cpp @@ -367,13 +367,13 @@ void emitOption(const DocumentedOption &Option, const Record *DocInfo, for (const Record *VisibilityHelp : R->getValueAsListOfDefs("HelpTextsForVariants")) { // This is a list of visibilities. - ArrayRef<Init *> Visibilities = + ArrayRef<const Init *> Visibilities = VisibilityHelp->getValueAsListInit("Visibilities")->getValues(); // See if any of the program's visibilities are in the list. for (StringRef DocInfoMask : DocInfo->getValueAsListOfStrings("VisibilityMask")) { - for (Init *Visibility : Visibilities) { + for (const Init *Visibility : Visibilities) { if (Visibility->getAsUnquotedString() == DocInfoMask) { // Use the first one we find. Description = escapeRST(VisibilityHelp->getValueAsString("Text")); diff --git a/llvm/include/llvm/TableGen/Error.h b/llvm/include/llvm/TableGen/Error.h index 512249b0160c24..b963dcba9869fb 100644 --- a/llvm/include/llvm/TableGen/Error.h +++ b/llvm/include/llvm/TableGen/Error.h @@ -49,8 +49,8 @@ void PrintError(const RecordVal *RecVal, const Twine &Msg); [[noreturn]] void PrintFatalError(function_ref<void(raw_ostream &OS)> PrintMsg); // Returns true if the assert failed. -bool CheckAssert(SMLoc Loc, Init *Condition, Init *Message); -void dumpMessage(SMLoc Loc, Init *Message); +bool CheckAssert(SMLoc Loc, const Init *Condition, const Init *Message); +void dumpMessage(SMLoc Loc, const Init *Message); extern SourceMgr SrcMgr; extern unsigned ErrorsPrinted; diff --git a/llvm/include/llvm/TableGen/Record.h b/llvm/include/llvm/TableGen/Record.h index f856ff4cbd34b5..63267b7633f6cf 100644 --- a/llvm/include/llvm/TableGen/Record.h +++ b/llvm/include/llvm/TableGen/Record.h @@ -374,25 +374,26 @@ class Init { /// If this value is convertible to type \p Ty, return a value whose /// type is \p Ty, generating a !cast operation if required. /// Otherwise, return null. - virtual Init *getCastTo(const RecTy *Ty) const = 0; + virtual const Init *getCastTo(const RecTy *Ty) const = 0; /// Convert to a value whose type is \p Ty, or return null if this /// is not possible. This can happen if the value's type is convertible /// to \p Ty, but there are unresolved references. - virtual Init *convertInitializerTo(const RecTy *Ty) const = 0; + virtual const Init *convertInitializerTo(const RecTy *Ty) const = 0; /// This function is used to implement the bit range /// selection operator. Given a value, it selects the specified bits, /// returning them as a new \p Init of type \p bits. If it is not legal /// to use the bit selection operator on this value, null is returned. - virtual Init *convertInitializerBitRange(ArrayRef<unsigned> Bits) const { + virtual const Init * + convertInitializerBitRange(ArrayRef<unsigned> Bits) const { return nullptr; } /// This function is used to implement the FieldInit class. /// Implementors of this method should return the type of the named /// field if they are of type record. - virtual const RecTy *getFieldType(StringInit *FieldName) const { + virtual const RecTy *getFieldType(const StringInit *FieldName) const { return nullptr; } @@ -400,12 +401,12 @@ class Init { /// variables which may not be defined at the time the expression is formed. /// If a value is set for the variable later, this method will be called on /// users of the value to allow the value to propagate out. - virtual Init *resolveReferences(Resolver &R) const { + virtual const Init *resolveReferences(Resolver &R) const { return const_cast<Init *>(this); } /// Get the \p Init value of the specified bit. - virtual Init *getBit(unsigned Bit) const = 0; + virtual const Init *getBit(unsigned Bit) const = 0; }; inline raw_ostream &operator<<(raw_ostream &OS, const Init &I) { @@ -436,15 +437,16 @@ class TypedInit : public Init { /// Get the record keeper that initialized this Init. RecordKeeper &getRecordKeeper() const { return ValueTy->getRecordKeeper(); } - Init *getCastTo(const RecTy *Ty) const override; - Init *convertInitializerTo(const RecTy *Ty) const override; + const Init *getCastTo(const RecTy *Ty) const override; + const Init *convertInitializerTo(const RecTy *Ty) const override; - Init *convertInitializerBitRange(ArrayRef<unsigned> Bits) const override; + const Init * + convertInitializerBitRange(ArrayRef<unsigned> Bits) const override; /// This method is used to implement the FieldInit class. /// Implementors of this method should return the type of the named field if /// they are of type record. - const RecTy *getFieldType(StringInit *FieldName) const override; + const RecTy *getFieldType(const StringInit *FieldName) const override; }; /// '?' - Represents an uninitialized value. @@ -470,10 +472,10 @@ class UnsetInit : public Init { /// Get the record keeper that initialized this Init. RecordKeeper &getRecordKeeper() const { return RK; } - Init *getCastTo(const RecTy *Ty) const override; - Init *convertInitializerTo(const RecTy *Ty) const override; + const Init *getCastTo(const RecTy *Ty) const override; + const Init *convertInitializerTo(const RecTy *Ty) const override; - Init *getBit(unsigned Bit) const override { + const Init *getBit(unsigned Bit) const override { return const_cast<UnsetInit*>(this); } @@ -487,7 +489,7 @@ class UnsetInit : public Init { }; // Represent an argument. -using ArgAuxType = std::variant<unsigned, Init *>; +using ArgAuxType = std::variant<unsigned, const Init *>; class ArgumentInit : public Init, public FoldingSetNode { public: enum Kind { @@ -496,11 +498,11 @@ class ArgumentInit : public Init, public FoldingSetNode { }; private: - Init *Value; + const Init *Value; ArgAuxType Aux; protected: - explicit ArgumentInit(Init *Value, ArgAuxType Aux) + explicit ArgumentInit(const Init *Value, ArgAuxType Aux) : Init(IK_ArgumentInit), Value(Value), Aux(Aux) {} public: @@ -511,25 +513,27 @@ class ArgumentInit : public Init, public FoldingSetNode { RecordKeeper &getRecordKeeper() const { return Value->getRecordKeeper(); } - static ArgumentInit *get(Init *Value, ArgAuxType Aux); + static const ArgumentInit *get(const Init *Value, ArgAuxType Aux); bool isPositional() const { return Aux.index() == Positional; } bool isNamed() const { return Aux.index() == Named; } - Init *getValue() const { return Value; } + const Init *getValue() const { return Value; } unsigned getIndex() const { assert(isPositional() && "Should be positional!"); return std::get<Positional>(Aux); } - Init *getName() const { + const Init *getName() const { assert(isNamed() && "Should be named!"); return std::get<Named>(Aux); } - ArgumentInit *cloneWithValue(Init *Value) const { return get(Value, Aux); } + const ArgumentInit *cloneWithValue(const Init *Value) const { + return get(Value, Aux); + } void Profile(FoldingSetNodeID &ID) const; - Init *resolveReferences(Resolver &R) const override; + const Init *resolveReferences(Resolver &R) const override; std::string getAsString() const override { if (isPositional()) return utostr(getIndex()) + ": " + Value->getAsString(); @@ -541,11 +545,11 @@ class ArgumentInit : public Init, public FoldingSetNode { bool isComplete() const override { return false; } bool isConcrete() const override { return false; } - Init *getBit(unsigned Bit) const override { return Value->getBit(Bit); } - Init *getCastTo(const RecTy *Ty) const override { + const Init *getBit(unsigned Bit) const override { return Value->getBit(Bit); } + const Init *getCastTo(const RecTy *Ty) const override { return Value->getCastTo(Ty); } - Init *convertInitializerTo(const RecTy *Ty) const override { + const Init *convertInitializerTo(const RecTy *Ty) const override { return Value->convertInitializerTo(Ty); } }; @@ -571,9 +575,9 @@ class BitInit final : public TypedInit { bool getValue() const { return Value; } - Init *convertInitializerTo(const RecTy *Ty) const override; + const Init *convertInitializerTo(const RecTy *Ty) const override; - Init *getBit(unsigned Bit) const override { + const Init *getBit(unsigned Bit) const override { assert(Bit < 1 && "Bit index out of range!"); return const_cast<BitInit*>(this); } @@ -584,8 +588,9 @@ class BitInit final : public TypedInit { /// '{ a, b, c }' - Represents an initializer for a BitsRecTy value. /// It contains a vector of bits, whose size is determined by the type. -class BitsInit final : public TypedInit, public FoldingSetNode, - public TrailingObjects<BitsInit, Init *> { +class BitsInit final : public TypedInit, + public FoldingSetNode, + public TrailingObjects<BitsInit, const Init *> { unsigned NumBits; BitsInit(RecordKeeper &RK, unsigned N) @@ -602,14 +607,15 @@ class BitsInit final : public TypedInit, public FoldingSetNode, return I->getKind() == IK_BitsInit; } - static BitsInit *get(RecordKeeper &RK, ArrayRef<Init *> Range); + static BitsInit *get(RecordKeeper &RK, ArrayRef<const Init *> Range); void Profile(FoldingSetNodeID &ID) const; unsigned getNumBits() const { return NumBits; } - Init *convertInitializerTo(const RecTy *Ty) const override; - Init *convertInitializerBitRange(ArrayRef<unsigned> Bits) const override; + const Init *convertInitializerTo(const RecTy *Ty) const override; + const Init * + convertInitializerBitRange(ArrayRef<unsigned> Bits) const override; std::optional<int64_t> convertInitializerToInt() const; bool isComplete() const override { @@ -627,11 +633,11 @@ class BitsInit final : public TypedInit, public FoldingSetNode, bool isConcrete() const override; std::string getAsString() const override; - Init *resolveReferences(Resolver &R) const override; + const Init *resolveReferences(Resolver &R) const override; - Init *getBit(unsigned Bit) const override { + const Init *getBit(unsigned Bit) const override { assert(Bit < NumBits && "Bit index out of range!"); - return getTrailingObjects<Init *>()[Bit]; + return getTrailingObjects<const Init *>()[Bit]; } }; @@ -654,13 +660,14 @@ class IntInit : public TypedInit { int64_t getValue() const { return Value; } - Init *convertInitializerTo(const RecTy *Ty) const override; - Init *convertInitializerBitRange(ArrayRef<unsigned> Bits) const override; + const Init *convertInitializerTo(const RecTy *Ty) const override; + const Init * + convertInitializerBitRange(ArrayRef<unsigned> Bits) const override; bool isConcrete() const override { return true; } std::string getAsString() const override; - Init *getBit(unsigned Bit) const override { + const Init *getBit(unsigned Bit) const override { return BitInit::get(getRecordKeeper(), (Value & (1ULL << Bit)) != 0); } }; @@ -684,13 +691,13 @@ class AnonymousNameInit : public TypedInit { unsigned getValue() const { return Value; } - StringInit *getNameInit() const; + const StringInit *getNameInit() const; std::string getAsString() const override; - Init *resolveReferences(Resolver &R) const override; + const Init *resolveReferences(Resolver &R) const override; - Init *getBit(unsigned Bit) const override { + const Init *getBit(unsigned Bit) const override { llvm_unreachable("Illegal bit reference off string"); } }; @@ -718,8 +725,8 @@ class StringInit : public TypedInit { return I->getKind() == IK_StringInit; } - static StringInit *get(RecordKeeper &RK, StringRef, - StringFormat Fmt = SF_String); + static const StringInit *get(RecordKeeper &RK, StringRef, + StringFormat Fmt = SF_String); static StringFormat determineFormat(StringFormat Fmt1, StringFormat Fmt2) { return (Fmt1 == SF_Code || Fmt2 == SF_Code) ? SF_Code : SF_String; @@ -729,7 +736,7 @@ class StringInit : public TypedInit { StringFormat getFormat() const { return Format; } bool hasCodeFormat() const { return Format == SF_Code; } - Init *convertInitializerTo(const RecTy *Ty) const override; + const Init *convertInitializerTo(const RecTy *Ty) const override; bool isConcrete() const override { return true; } @@ -744,19 +751,20 @@ class StringInit : public TypedInit { return std::string(Value); } - Init *getBit(unsigned Bit) const override { + const Init *getBit(unsigned Bit) const override { llvm_unreachable("Illegal bit reference off string"); } }; /// [AL, AH, CL] - Represent a list of defs /// -class ListInit final : public TypedInit, public FoldingSetNode, - public TrailingObjects<ListInit, Init *> { +class ListInit final : public TypedInit, + public FoldingSetNode, + public TrailingObjects<ListInit, const Init *> { unsigned NumValues; public: - using const_iterator = Init *const *; + using const_iterator = const Init *const *; private: explicit ListInit(unsigned N, const RecTy *EltTy) @@ -772,13 +780,13 @@ class ListInit final : public TypedInit, public FoldingSetNode, static bool classof(const Init *I) { return I->getKind() == IK_ListInit; } - static ListInit *get(ArrayRef<Init *> Range, const RecTy *EltTy); + static const ListInit *get(ArrayRef<const Init *> Range, const RecTy *EltTy); void Profile(FoldingSetNodeID &ID) const; - Init *getElement(unsigned i) const { + const Init *getElement(unsigned i) const { assert(i < NumValues && "List element index out of range!"); - return getTrailingObjects<Init *>()[i]; + return getTrailingObjects<const Init *>()[i]; } const RecTy *getElementType() const { return cast<ListRecTy>(getType())->getElementType(); @@ -786,30 +794,30 @@ class ListInit final : public TypedInit, public FoldingSetNode, const Record *getElementAsRecord(unsigned i) const; - Init *convertInitializerTo(const RecTy *Ty) const override; + const Init *convertInitializerTo(const RecTy *Ty) const override; /// This method is used by classes that refer to other /// variables which may not be defined at the time they expression is formed. /// If a value is set for the variable later, this method will be called on /// users of the value to allow the value to propagate out. /// - Init *resolveReferences(Resolver &R) const override; + const Init *resolveReferences(Resolver &R) const override; bool isComplete() const override; bool isConcrete() const override; std::string getAsString() const override; - ArrayRef<Init*> getValues() const { - return ArrayRef(getTrailingObjects<Init *>(), NumValues); + ArrayRef<const Init *> getValues() const { + return ArrayRef(getTrailingObjects<const Init *>(), NumValues); } - const_iterator begin() const { return getTrailingObjects<Init *>(); } + const_iterator begin() const { return getTrailingObjects<const Init *>(); } const_iterator end () const { return begin() + NumValues; } size_t size () const { return NumValues; } bool empty() const { return NumValues == 0; } - Init *getBit(unsigned Bit) const override { + const Init *getBit(unsigned Bit) const override { llvm_unreachable("Illegal bit reference off list"); } }; @@ -831,12 +839,12 @@ class OpInit : public TypedInit { } // Clone - Clone this operator, replacing arguments with the new list - virtual OpInit *clone(ArrayRef<Init *> Operands) const = 0; + virtual const OpInit *clone(ArrayRef<const Init *> Operands) const = 0; virtual unsigned getNumOperands() const = 0; - virtual Init *getOperand(unsigned i) const = 0; + virtual const Init *getOperand(unsigned i) const = 0; - Init *getBit(unsigned Bit) const override; + const Init *getBit(unsigned Bit) const override; }; /// !op (X) - Transform an init. @@ -859,9 +867,9 @@ class UnOpInit : public OpInit, public FoldingSetNode { }; private: - Init *LHS; + const Init *LHS; - UnOpInit(UnaryOp opc, Init *lhs, const RecTy *Type) + UnOpInit(UnaryOp opc, const Init *lhs, const RecTy *Type) : OpInit(IK_UnOpInit, Type, opc), LHS(lhs) {} public: @@ -872,12 +880,12 @@ class UnOpInit : public OpInit, public FoldingSetNode { return I->getKind() == IK_UnOpInit; } - static UnOpInit *get(UnaryOp opc, Init *lhs, const RecTy *Type); + static const UnOpInit *get(UnaryOp opc, const Init *lhs, const RecTy *Type); void Profile(FoldingSetNodeID &ID) const; // Clone - Clone this operator, replacing arguments with the new list - OpInit *clone(ArrayRef<Init *> Operands) const override { + const OpInit *clone(ArrayRef<const Init *> Operands) const override { assert(Operands.size() == 1 && "Wrong number of operands for unary operation"); return UnOpInit::get(getOpcode(), *Operands.begin(), getType()); @@ -885,19 +893,19 @@ class UnOpInit : public OpInit, public FoldingSetNode { unsigned getNumOperands() const override { return 1; } - Init *getOperand(unsigned i) const override { + const Init *getOperand(unsigned i) const override { assert(i == 0 && "Invalid operand id for unary operator"); return getOperand(); } UnaryOp getOpcode() const { return (UnaryOp)Opc; } - Init *getOperand() const { return LHS; } + const Init *getOperand() const { return LHS; } // Fold - If possible, fold this to a simpler init. Return this if not // possible to fold. - Init *Fold(Record *CurRec, bool IsFinal = false) const; + const Init *Fold(const Record *CurRec, bool IsFinal = false) const; - Init *resolveReferences(Resolver &R) const override; + const Init *resolveReferences(Resolver &R) const override; std::string getAsString() const override; }; @@ -937,9 +945,9 @@ class BinOpInit : public OpInit, public FoldingSetNode { }; private: - Init *LHS, *RHS; + const Init *LHS, *RHS; - BinOpInit(BinaryOp opc, Init *lhs, Init *rhs, const RecTy *Type) + BinOpInit(BinaryOp opc, const Init *lhs, const Init *rhs, const RecTy *Type) : OpInit(IK_BinOpInit, Type, opc), LHS(lhs), RHS(rhs) {} public: @@ -950,21 +958,22 @@ class BinOpInit : public OpInit, public FoldingSetNode { return I->getKind() == IK_BinOpInit; } - static BinOpInit *get(BinaryOp opc, Init *lhs, Init *rhs, const RecTy *Type); - static Init *getStrConcat(Init *lhs, Init *rhs); - static Init *getListConcat(TypedInit *lhs, Init *rhs); + static const BinOpInit *get(BinaryOp opc, const Init *lhs, const Init *rhs, + const RecTy *Type); + static const Init *getStrConcat(const Init *lhs, const Init *rhs); + static const Init *getListConcat(const TypedInit *lhs, const Init *rhs); void Profile(FoldingSetNodeID &ID) const; // Clone - Clone this operator, replacing arguments with the new list - OpInit *clone(ArrayRef<Init *> Operands) const override { + const OpInit *clone(ArrayRef<const Init *> Operands) const override { assert(Operands.size() == 2 && "Wrong number of operands for binary operation"); return BinOpInit::get(getOpcode(), Operands[0], Operands[1], getType()); } unsigned getNumOperands() const override { return 2; } - Init *getOperand(unsigned i) const override { + const Init *getOperand(unsigned i) const override { switch (i) { default: llvm_unreachable("Invalid operand id for binary operator"); case 0: return getLHS(); @@ -973,16 +982,17 @@ class BinOpInit : public OpInit, public FoldingSetNode { } BinaryOp getOpcode() const { return (BinaryOp)Opc; } - Init *getLHS() const { return LHS; } - Init *getRHS() const { return RHS; } + const Init *getLHS() const { return LHS; } + const Init *getRHS() const { return RHS; } - std::optional<bool> CompareInit(unsigned Opc, Init *LHS, Init *RHS) const; + std::optional<bool> CompareInit(unsigned Opc, const Init *LHS, + const Init *RHS) const; // Fold - If possible, fold this to a simpler init. Return this if not // possi... [truncated] `````````` </details> https://github.com/llvm/llvm-project/pull/112705 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits