[llvm] 9d95e26 - [TableGen] Change all type pointers to const (#110602)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 1 06:54:20 PDT 2024
Author: Rahul Joshi
Date: 2024-10-01T06:54:17-07:00
New Revision: 9d95e2614e425f154cb5720d9eb276c25a26524e
URL: https://github.com/llvm/llvm-project/commit/9d95e2614e425f154cb5720d9eb276c25a26524e
DIFF: https://github.com/llvm/llvm-project/commit/9d95e2614e425f154cb5720d9eb276c25a26524e.diff
LOG: [TableGen] Change all type pointers to const (#110602)
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
Added:
Modified:
llvm/include/llvm/TableGen/Record.h
llvm/lib/TableGen/Record.cpp
llvm/lib/TableGen/TGParser.cpp
llvm/lib/TableGen/TGParser.h
llvm/utils/TableGen/Common/CodeGenRegisters.cpp
llvm/utils/TableGen/SearchableTableEmitter.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/TableGen/Record.h b/llvm/include/llvm/TableGen/Record.h
index 6c07391893c88d..f39a2ee9f1d9bb 100644
--- a/llvm/include/llvm/TableGen/Record.h
+++ b/llvm/include/llvm/TableGen/Record.h
@@ -73,8 +73,9 @@ class RecTy {
RecTyKind Kind;
/// The RecordKeeper that uniqued this Type.
RecordKeeper &RK;
- /// ListRecTy of the list that has elements of this type.
- ListRecTy *ListTy = nullptr;
+ /// ListRecTy of the list that has elements of this type. Its a cache that
+ /// is populated on demand.
+ mutable const ListRecTy *ListTy = nullptr;
public:
RecTy(RecTyKind K, RecordKeeper &RK) : Kind(K), RK(RK) {}
@@ -98,7 +99,7 @@ class RecTy {
virtual bool typeIsA(const RecTy *RHS) const;
/// Returns the type representing list<thistype>.
- ListRecTy *getListTy();
+ const ListRecTy *getListTy() const;
};
inline raw_ostream &operator<<(raw_ostream &OS, const RecTy &Ty) {
@@ -117,7 +118,7 @@ class BitRecTy : public RecTy {
return RT->getRecTyKind() == BitRecTyKind;
}
- static BitRecTy *get(RecordKeeper &RK);
+ static const BitRecTy *get(RecordKeeper &RK);
std::string getAsString() const override { return "bit"; }
@@ -136,7 +137,7 @@ class BitsRecTy : public RecTy {
return RT->getRecTyKind() == BitsRecTyKind;
}
- static BitsRecTy *get(RecordKeeper &RK, unsigned Sz);
+ static const BitsRecTy *get(RecordKeeper &RK, unsigned Sz);
unsigned getNumBits() const { return Size; }
@@ -156,7 +157,7 @@ class IntRecTy : public RecTy {
return RT->getRecTyKind() == IntRecTyKind;
}
- static IntRecTy *get(RecordKeeper &RK);
+ static const IntRecTy *get(RecordKeeper &RK);
std::string getAsString() const override { return "int"; }
@@ -174,7 +175,7 @@ class StringRecTy : public RecTy {
return RT->getRecTyKind() == StringRecTyKind;
}
- static StringRecTy *get(RecordKeeper &RK);
+ static const StringRecTy *get(RecordKeeper &RK);
std::string getAsString() const override;
@@ -184,11 +185,11 @@ class StringRecTy : public RecTy {
/// 'list<Ty>' - Represent a list of element values, all of which must be of
/// the specified type. The type is stored in ElementTy.
class ListRecTy : public RecTy {
- friend ListRecTy *RecTy::getListTy();
+ friend const ListRecTy *RecTy::getListTy() const;
- RecTy *ElementTy;
+ const RecTy *ElementTy;
- explicit ListRecTy(RecTy *T)
+ explicit ListRecTy(const RecTy *T)
: RecTy(ListRecTyKind, T->getRecordKeeper()), ElementTy(T) {}
public:
@@ -196,8 +197,8 @@ class ListRecTy : public RecTy {
return RT->getRecTyKind() == ListRecTyKind;
}
- static ListRecTy *get(RecTy *T) { return T->getListTy(); }
- RecTy *getElementType() const { return ElementTy; }
+ static const ListRecTy *get(const RecTy *T) { return T->getListTy(); }
+ const RecTy *getElementType() const { return ElementTy; }
std::string getAsString() const override;
@@ -217,7 +218,7 @@ class DagRecTy : public RecTy {
return RT->getRecTyKind() == DagRecTyKind;
}
- static DagRecTy *get(RecordKeeper &RK);
+ static const DagRecTy *get(RecordKeeper &RK);
std::string getAsString() const override;
};
@@ -249,8 +250,9 @@ class RecordRecTy final : public RecTy,
}
/// Get the record type with the given non-redundant list of superclasses.
- static RecordRecTy *get(RecordKeeper &RK, ArrayRef<const Record *> Classes);
- static RecordRecTy *get(const Record *Class);
+ static const RecordRecTy *get(RecordKeeper &RK,
+ ArrayRef<const Record *> Classes);
+ static const RecordRecTy *get(const Record *Class);
void Profile(FoldingSetNodeID &ID) const;
@@ -273,7 +275,7 @@ class RecordRecTy final : public RecTy,
/// Find a common type that T1 and T2 convert to.
/// Return 0 if no such type exists.
-RecTy *resolveTypes(RecTy *T1, RecTy *T2);
+const RecTy *resolveTypes(const RecTy *T1, const RecTy *T2);
//===----------------------------------------------------------------------===//
// Initializer Classes
@@ -371,12 +373,12 @@ 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(RecTy *Ty) const = 0;
+ virtual 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(RecTy *Ty) const = 0;
+ virtual 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,
@@ -389,7 +391,7 @@ class Init {
/// 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 RecTy *getFieldType(StringInit *FieldName) const {
+ virtual const RecTy *getFieldType(StringInit *FieldName) const {
return nullptr;
}
@@ -412,10 +414,10 @@ inline raw_ostream &operator<<(raw_ostream &OS, const Init &I) {
/// This is the common superclass of types that have a specific,
/// explicit type, stored in ValueTy.
class TypedInit : public Init {
- RecTy *ValueTy;
+ const RecTy *ValueTy;
protected:
- explicit TypedInit(InitKind K, RecTy *T, uint8_t Opc = 0)
+ explicit TypedInit(InitKind K, const RecTy *T, uint8_t Opc = 0)
: Init(K, Opc), ValueTy(T) {}
public:
@@ -428,20 +430,20 @@ class TypedInit : public Init {
}
/// Get the type of the Init as a RecTy.
- RecTy *getType() const { return ValueTy; }
+ const RecTy *getType() const { return ValueTy; }
/// Get the record keeper that initialized this Init.
RecordKeeper &getRecordKeeper() const { return ValueTy->getRecordKeeper(); }
- Init *getCastTo(RecTy *Ty) const override;
- Init *convertInitializerTo(RecTy *Ty) const override;
+ Init *getCastTo(const RecTy *Ty) const override;
+ Init *convertInitializerTo(const RecTy *Ty) const override;
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.
- RecTy *getFieldType(StringInit *FieldName) const override;
+ const RecTy *getFieldType(StringInit *FieldName) const override;
};
/// '?' - Represents an uninitialized value.
@@ -467,8 +469,8 @@ class UnsetInit : public Init {
/// Get the record keeper that initialized this Init.
RecordKeeper &getRecordKeeper() const { return RK; }
- Init *getCastTo(RecTy *Ty) const override;
- Init *convertInitializerTo(RecTy *Ty) const override;
+ Init *getCastTo(const RecTy *Ty) const override;
+ Init *convertInitializerTo(const RecTy *Ty) const override;
Init *getBit(unsigned Bit) const override {
return const_cast<UnsetInit*>(this);
@@ -539,8 +541,10 @@ 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(RecTy *Ty) const override { return Value->getCastTo(Ty); }
- Init *convertInitializerTo(RecTy *Ty) const override {
+ Init *getCastTo(const RecTy *Ty) const override {
+ return Value->getCastTo(Ty);
+ }
+ Init *convertInitializerTo(const RecTy *Ty) const override {
return Value->convertInitializerTo(Ty);
}
};
@@ -551,7 +555,8 @@ class BitInit final : public TypedInit {
bool Value;
- explicit BitInit(bool V, RecTy *T) : TypedInit(IK_BitInit, T), Value(V) {}
+ explicit BitInit(bool V, const RecTy *T)
+ : TypedInit(IK_BitInit, T), Value(V) {}
public:
BitInit(const BitInit &) = delete;
@@ -565,7 +570,7 @@ class BitInit final : public TypedInit {
bool getValue() const { return Value; }
- Init *convertInitializerTo(RecTy *Ty) const override;
+ Init *convertInitializerTo(const RecTy *Ty) const override;
Init *getBit(unsigned Bit) const override {
assert(Bit < 1 && "Bit index out of range!");
@@ -602,7 +607,7 @@ class BitsInit final : public TypedInit, public FoldingSetNode,
unsigned getNumBits() const { return NumBits; }
- Init *convertInitializerTo(RecTy *Ty) const override;
+ Init *convertInitializerTo(const RecTy *Ty) const override;
Init *convertInitializerBitRange(ArrayRef<unsigned> Bits) const override;
std::optional<int64_t> convertInitializerToInt() const;
@@ -648,7 +653,7 @@ class IntInit : public TypedInit {
int64_t getValue() const { return Value; }
- Init *convertInitializerTo(RecTy *Ty) const override;
+ Init *convertInitializerTo(const RecTy *Ty) const override;
Init *convertInitializerBitRange(ArrayRef<unsigned> Bits) const override;
bool isConcrete() const override { return true; }
@@ -723,7 +728,7 @@ class StringInit : public TypedInit {
StringFormat getFormat() const { return Format; }
bool hasCodeFormat() const { return Format == SF_Code; }
- Init *convertInitializerTo(RecTy *Ty) const override;
+ Init *convertInitializerTo(const RecTy *Ty) const override;
bool isConcrete() const override { return true; }
@@ -753,7 +758,7 @@ class ListInit final : public TypedInit, public FoldingSetNode,
using const_iterator = Init *const *;
private:
- explicit ListInit(unsigned N, RecTy *EltTy)
+ explicit ListInit(unsigned N, const RecTy *EltTy)
: TypedInit(IK_ListInit, ListRecTy::get(EltTy)), NumValues(N) {}
public:
@@ -766,7 +771,7 @@ class ListInit final : public TypedInit, public FoldingSetNode,
static bool classof(const Init *I) {
return I->getKind() == IK_ListInit;
}
- static ListInit *get(ArrayRef<Init *> Range, RecTy *EltTy);
+ static ListInit *get(ArrayRef<Init *> Range, const RecTy *EltTy);
void Profile(FoldingSetNodeID &ID) const;
@@ -774,13 +779,13 @@ class ListInit final : public TypedInit, public FoldingSetNode,
assert(i < NumValues && "List element index out of range!");
return getTrailingObjects<Init *>()[i];
}
- RecTy *getElementType() const {
+ const RecTy *getElementType() const {
return cast<ListRecTy>(getType())->getElementType();
}
Record *getElementAsRecord(unsigned i) const;
- Init *convertInitializerTo(RecTy *Ty) const override;
+ 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.
@@ -812,8 +817,8 @@ class ListInit final : public TypedInit, public FoldingSetNode,
///
class OpInit : public TypedInit {
protected:
- explicit OpInit(InitKind K, RecTy *Type, uint8_t Opc)
- : TypedInit(K, Type, Opc) {}
+ explicit OpInit(InitKind K, const RecTy *Type, uint8_t Opc)
+ : TypedInit(K, Type, Opc) {}
public:
OpInit(const OpInit &) = delete;
@@ -855,8 +860,8 @@ class UnOpInit : public OpInit, public FoldingSetNode {
private:
Init *LHS;
- UnOpInit(UnaryOp opc, Init *lhs, RecTy *Type)
- : OpInit(IK_UnOpInit, Type, opc), LHS(lhs) {}
+ UnOpInit(UnaryOp opc, Init *lhs, const RecTy *Type)
+ : OpInit(IK_UnOpInit, Type, opc), LHS(lhs) {}
public:
UnOpInit(const UnOpInit &) = delete;
@@ -866,7 +871,7 @@ class UnOpInit : public OpInit, public FoldingSetNode {
return I->getKind() == IK_UnOpInit;
}
- static UnOpInit *get(UnaryOp opc, Init *lhs, RecTy *Type);
+ static UnOpInit *get(UnaryOp opc, Init *lhs, const RecTy *Type);
void Profile(FoldingSetNodeID &ID) const;
@@ -933,8 +938,8 @@ class BinOpInit : public OpInit, public FoldingSetNode {
private:
Init *LHS, *RHS;
- BinOpInit(BinaryOp opc, Init *lhs, Init *rhs, RecTy *Type) :
- OpInit(IK_BinOpInit, Type, opc), LHS(lhs), RHS(rhs) {}
+ BinOpInit(BinaryOp opc, Init *lhs, Init *rhs, const RecTy *Type)
+ : OpInit(IK_BinOpInit, Type, opc), LHS(lhs), RHS(rhs) {}
public:
BinOpInit(const BinOpInit &) = delete;
@@ -944,8 +949,7 @@ class BinOpInit : public OpInit, public FoldingSetNode {
return I->getKind() == IK_BinOpInit;
}
- static BinOpInit *get(BinaryOp opc, Init *lhs, Init *rhs,
- RecTy *Type);
+ 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);
@@ -1001,9 +1005,8 @@ class TernOpInit : public OpInit, public FoldingSetNode {
private:
Init *LHS, *MHS, *RHS;
- TernOpInit(TernaryOp opc, Init *lhs, Init *mhs, Init *rhs,
- RecTy *Type) :
- OpInit(IK_TernOpInit, Type, opc), LHS(lhs), MHS(mhs), RHS(rhs) {}
+ TernOpInit(TernaryOp opc, Init *lhs, Init *mhs, Init *rhs, const RecTy *Type)
+ : OpInit(IK_TernOpInit, Type, opc), LHS(lhs), MHS(mhs), RHS(rhs) {}
public:
TernOpInit(const TernOpInit &) = delete;
@@ -1013,9 +1016,8 @@ class TernOpInit : public OpInit, public FoldingSetNode {
return I->getKind() == IK_TernOpInit;
}
- static TernOpInit *get(TernaryOp opc, Init *lhs,
- Init *mhs, Init *rhs,
- RecTy *Type);
+ static TernOpInit *get(TernaryOp opc, Init *lhs, Init *mhs, Init *rhs,
+ const RecTy *Type);
void Profile(FoldingSetNodeID &ID) const;
@@ -1061,11 +1063,10 @@ class TernOpInit : public OpInit, public FoldingSetNode {
class CondOpInit final : public TypedInit, public FoldingSetNode,
public TrailingObjects<CondOpInit, Init *> {
unsigned NumConds;
- RecTy *ValType;
+ const RecTy *ValType;
- CondOpInit(unsigned NC, RecTy *Type)
- : TypedInit(IK_CondOpInit, Type),
- NumConds(NC), ValType(Type) {}
+ CondOpInit(unsigned NC, const RecTy *Type)
+ : TypedInit(IK_CondOpInit, Type), NumConds(NC), ValType(Type) {}
size_t numTrailingObjects(OverloadToken<Init *>) const {
return 2*NumConds;
@@ -1079,12 +1080,12 @@ class CondOpInit final : public TypedInit, public FoldingSetNode,
return I->getKind() == IK_CondOpInit;
}
- static CondOpInit *get(ArrayRef<Init*> C, ArrayRef<Init*> V,
- RecTy *Type);
+ static CondOpInit *get(ArrayRef<Init *> C, ArrayRef<Init *> V,
+ const RecTy *Type);
void Profile(FoldingSetNodeID &ID) const;
- RecTy *getValType() const { return ValType; }
+ const RecTy *getValType() const { return ValType; }
unsigned getNumConds() const { return NumConds; }
@@ -1141,7 +1142,8 @@ class FoldOpInit : public TypedInit, public FoldingSetNode {
Init *B;
Init *Expr;
- FoldOpInit(Init *Start, Init *List, Init *A, Init *B, Init *Expr, RecTy *Type)
+ FoldOpInit(Init *Start, Init *List, Init *A, Init *B, Init *Expr,
+ const RecTy *Type)
: TypedInit(IK_FoldOpInit, Type), Start(Start), List(List), A(A), B(B),
Expr(Expr) {}
@@ -1152,7 +1154,7 @@ class FoldOpInit : public TypedInit, public FoldingSetNode {
static bool classof(const Init *I) { return I->getKind() == IK_FoldOpInit; }
static FoldOpInit *get(Init *Start, Init *List, Init *A, Init *B, Init *Expr,
- RecTy *Type);
+ const RecTy *Type);
void Profile(FoldingSetNodeID &ID) const;
@@ -1172,10 +1174,10 @@ class FoldOpInit : public TypedInit, public FoldingSetNode {
/// !isa<type>(expr) - Dynamically determine the type of an expression.
class IsAOpInit : public TypedInit, public FoldingSetNode {
private:
- RecTy *CheckType;
+ const RecTy *CheckType;
Init *Expr;
- IsAOpInit(RecTy *CheckType, Init *Expr)
+ IsAOpInit(const RecTy *CheckType, Init *Expr)
: TypedInit(IK_IsAOpInit, IntRecTy::get(CheckType->getRecordKeeper())),
CheckType(CheckType), Expr(Expr) {}
@@ -1185,7 +1187,7 @@ class IsAOpInit : public TypedInit, public FoldingSetNode {
static bool classof(const Init *I) { return I->getKind() == IK_IsAOpInit; }
- static IsAOpInit *get(RecTy *CheckType, Init *Expr);
+ static IsAOpInit *get(const RecTy *CheckType, Init *Expr);
void Profile(FoldingSetNodeID &ID) const;
@@ -1206,10 +1208,10 @@ class IsAOpInit : public TypedInit, public FoldingSetNode {
/// `expr` exists.
class ExistsOpInit : public TypedInit, public FoldingSetNode {
private:
- RecTy *CheckType;
+ const RecTy *CheckType;
Init *Expr;
- ExistsOpInit(RecTy *CheckType, Init *Expr)
+ ExistsOpInit(const RecTy *CheckType, Init *Expr)
: TypedInit(IK_ExistsOpInit, IntRecTy::get(CheckType->getRecordKeeper())),
CheckType(CheckType), Expr(Expr) {}
@@ -1219,7 +1221,7 @@ class ExistsOpInit : public TypedInit, public FoldingSetNode {
static bool classof(const Init *I) { return I->getKind() == IK_ExistsOpInit; }
- static ExistsOpInit *get(RecTy *CheckType, Init *Expr);
+ static ExistsOpInit *get(const RecTy *CheckType, Init *Expr);
void Profile(FoldingSetNodeID &ID) const;
@@ -1240,7 +1242,7 @@ class ExistsOpInit : public TypedInit, public FoldingSetNode {
class VarInit : public TypedInit {
Init *VarName;
- explicit VarInit(Init *VN, RecTy *T)
+ explicit VarInit(Init *VN, const RecTy *T)
: TypedInit(IK_VarInit, T), VarName(VN) {}
public:
@@ -1251,8 +1253,8 @@ class VarInit : public TypedInit {
return I->getKind() == IK_VarInit;
}
- static VarInit *get(StringRef VN, RecTy *T);
- static VarInit *get(Init *VN, RecTy *T);
+ static VarInit *get(StringRef VN, const RecTy *T);
+ static VarInit *get(Init *VN, const RecTy *T);
StringRef getName() const;
Init *getNameInit() const { return VarName; }
@@ -1326,11 +1328,11 @@ class DefInit : public TypedInit {
return I->getKind() == IK_DefInit;
}
- Init *convertInitializerTo(RecTy *Ty) const override;
+ Init *convertInitializerTo(const RecTy *Ty) const override;
Record *getDef() const { return Def; }
- RecTy *getFieldType(StringInit *FieldName) const override;
+ const RecTy *getFieldType(StringInit *FieldName) const override;
bool isConcrete() const override { return true; }
std::string getAsString() const override;
@@ -1552,7 +1554,7 @@ class RecordVal {
private:
Init *Name;
SMLoc Loc; // Source location of definition of name.
- PointerIntPair<RecTy *, 2, FieldKind> TyAndKind;
+ PointerIntPair<const RecTy *, 2, FieldKind> TyAndKind;
Init *Value;
bool IsUsed = false;
@@ -1560,8 +1562,8 @@ class RecordVal {
SmallVector<SMRange> ReferenceLocs;
public:
- RecordVal(Init *N, RecTy *T, FieldKind K);
- RecordVal(Init *N, SMLoc Loc, RecTy *T, FieldKind K);
+ RecordVal(Init *N, const RecTy *T, FieldKind K);
+ RecordVal(Init *N, SMLoc Loc, const RecTy *T, FieldKind K);
/// Get the record keeper used to unique this value.
RecordKeeper &getRecordKeeper() const { return Name->getRecordKeeper(); }
@@ -1591,7 +1593,7 @@ class RecordVal {
}
/// Get the type of the field value as a RecTy.
- RecTy *getType() const { return TyAndKind.getPointer(); }
+ const RecTy *getType() const { return TyAndKind.getPointer(); }
/// Get the type of the field for printing purposes.
std::string getPrintType() const;
@@ -1736,7 +1738,7 @@ class Record {
void updateClassLoc(SMLoc Loc);
// Make the type that this record should have based on its superclasses.
- RecordRecTy *getType() const;
+ const RecordRecTy *getType() const;
/// get the corresponding DefInit.
DefInit *getDefInit() const;
diff --git a/llvm/lib/TableGen/Record.cpp b/llvm/lib/TableGen/Record.cpp
index 2973ef40642554..0a5d384239d5ed 100644
--- a/llvm/lib/TableGen/Record.cpp
+++ b/llvm/lib/TableGen/Record.cpp
@@ -82,7 +82,7 @@ struct RecordKeeperImpl {
FoldingSet<FoldOpInit> TheFoldOpInitPool;
FoldingSet<IsAOpInit> TheIsAOpInitPool;
FoldingSet<ExistsOpInit> TheExistsOpInitPool;
- DenseMap<std::pair<RecTy *, Init *>, VarInit *> TheVarInitPool;
+ DenseMap<std::pair<const RecTy *, Init *>, VarInit *> TheVarInitPool;
DenseMap<std::pair<TypedInit *, unsigned>, VarBitInit *> TheVarBitInitPool;
FoldingSet<VarDefInit> TheVarDefInitPool;
DenseMap<std::pair<Init *, StringInit *>, FieldInit *> TheFieldInitPool;
@@ -133,7 +133,7 @@ void detail::RecordKeeperImpl::dumpAllocationStats(raw_ostream &OS) const {
LLVM_DUMP_METHOD void RecTy::dump() const { print(errs()); }
#endif
-ListRecTy *RecTy::getListTy() {
+const ListRecTy *RecTy::getListTy() const {
if (!ListTy)
ListTy = new (RK.getImpl().Allocator) ListRecTy(this);
return ListTy;
@@ -146,7 +146,7 @@ bool RecTy::typeIsConvertibleTo(const RecTy *RHS) const {
bool RecTy::typeIsA(const RecTy *RHS) const { return this == RHS; }
-BitRecTy *BitRecTy::get(RecordKeeper &RK) {
+const BitRecTy *BitRecTy::get(RecordKeeper &RK) {
return &RK.getImpl().SharedBitRecTy;
}
@@ -158,7 +158,7 @@ bool BitRecTy::typeIsConvertibleTo(const RecTy *RHS) const{
return false;
}
-BitsRecTy *BitsRecTy::get(RecordKeeper &RK, unsigned Sz) {
+const BitsRecTy *BitsRecTy::get(RecordKeeper &RK, unsigned Sz) {
detail::RecordKeeperImpl &RKImpl = RK.getImpl();
if (Sz >= RKImpl.SharedBitsRecTys.size())
RKImpl.SharedBitsRecTys.resize(Sz + 1);
@@ -179,7 +179,7 @@ bool BitsRecTy::typeIsConvertibleTo(const RecTy *RHS) const {
return (kind == BitRecTyKind && Size == 1) || (kind == IntRecTyKind);
}
-IntRecTy *IntRecTy::get(RecordKeeper &RK) {
+const IntRecTy *IntRecTy::get(RecordKeeper &RK) {
return &RK.getImpl().SharedIntRecTy;
}
@@ -188,7 +188,7 @@ bool IntRecTy::typeIsConvertibleTo(const RecTy *RHS) const {
return kind==BitRecTyKind || kind==BitsRecTyKind || kind==IntRecTyKind;
}
-StringRecTy *StringRecTy::get(RecordKeeper &RK) {
+const StringRecTy *StringRecTy::get(RecordKeeper &RK) {
return &RK.getImpl().SharedStringRecTy;
}
@@ -217,7 +217,7 @@ bool ListRecTy::typeIsA(const RecTy *RHS) const {
return false;
}
-DagRecTy *DagRecTy::get(RecordKeeper &RK) {
+const DagRecTy *DagRecTy::get(RecordKeeper &RK) {
return &RK.getImpl().SharedDagRecTy;
}
@@ -232,8 +232,8 @@ static void ProfileRecordRecTy(FoldingSetNodeID &ID,
ID.AddPointer(R);
}
-RecordRecTy *RecordRecTy::get(RecordKeeper &RK,
- ArrayRef<const Record *> UnsortedClasses) {
+const RecordRecTy *RecordRecTy::get(RecordKeeper &RK,
+ ArrayRef<const Record *> UnsortedClasses) {
detail::RecordKeeperImpl &RKImpl = RK.getImpl();
if (UnsortedClasses.empty())
return &RKImpl.AnyRecord;
@@ -270,7 +270,8 @@ RecordRecTy *RecordRecTy::get(RecordKeeper &RK,
ThePool.InsertNode(Ty, IP);
return Ty;
}
-RecordRecTy *RecordRecTy::get(const Record *Class) {
+
+const RecordRecTy *RecordRecTy::get(const Record *Class) {
assert(Class && "unexpected null class");
return get(Class->getRecords(), {Class});
}
@@ -318,7 +319,8 @@ bool RecordRecTy::typeIsA(const RecTy *RHS) const {
return typeIsConvertibleTo(RHS);
}
-static RecordRecTy *resolveRecordTypes(RecordRecTy *T1, RecordRecTy *T2) {
+static const RecordRecTy *resolveRecordTypes(const RecordRecTy *T1,
+ const RecordRecTy *T2) {
SmallVector<const Record *, 4> CommonSuperClasses;
SmallVector<const Record *, 4> Stack(T1->getClasses());
@@ -335,12 +337,12 @@ static RecordRecTy *resolveRecordTypes(RecordRecTy *T1, RecordRecTy *T2) {
return RecordRecTy::get(T1->getRecordKeeper(), CommonSuperClasses);
}
-RecTy *llvm::resolveTypes(RecTy *T1, RecTy *T2) {
+const RecTy *llvm::resolveTypes(const RecTy *T1, const RecTy *T2) {
if (T1 == T2)
return T1;
- if (RecordRecTy *RecTy1 = dyn_cast<RecordRecTy>(T1)) {
- if (RecordRecTy *RecTy2 = dyn_cast<RecordRecTy>(T2))
+ if (const RecordRecTy *RecTy1 = dyn_cast<RecordRecTy>(T1)) {
+ if (const RecordRecTy *RecTy2 = dyn_cast<RecordRecTy>(T2))
return resolveRecordTypes(RecTy1, RecTy2);
}
@@ -352,10 +354,10 @@ RecTy *llvm::resolveTypes(RecTy *T1, RecTy *T2) {
if (T2->typeIsConvertibleTo(T1))
return T1;
- if (ListRecTy *ListTy1 = dyn_cast<ListRecTy>(T1)) {
- if (ListRecTy *ListTy2 = dyn_cast<ListRecTy>(T2)) {
- RecTy* NewType = resolveTypes(ListTy1->getElementType(),
- ListTy2->getElementType());
+ if (const ListRecTy *ListTy1 = dyn_cast<ListRecTy>(T1)) {
+ if (const ListRecTy *ListTy2 = dyn_cast<ListRecTy>(T2)) {
+ const RecTy *NewType =
+ resolveTypes(ListTy1->getElementType(), ListTy2->getElementType());
if (NewType)
return NewType->getListTy();
}
@@ -386,11 +388,11 @@ UnsetInit *UnsetInit::get(RecordKeeper &RK) {
return &RK.getImpl().TheUnsetInit;
}
-Init *UnsetInit::getCastTo(RecTy *Ty) const {
+Init *UnsetInit::getCastTo(const RecTy *Ty) const {
return const_cast<UnsetInit *>(this);
}
-Init *UnsetInit::convertInitializerTo(RecTy *Ty) const {
+Init *UnsetInit::convertInitializerTo(const RecTy *Ty) const {
return const_cast<UnsetInit *>(this);
}
@@ -436,7 +438,7 @@ BitInit *BitInit::get(RecordKeeper &RK, bool V) {
return V ? &RK.getImpl().TrueBitInit : &RK.getImpl().FalseBitInit;
}
-Init *BitInit::convertInitializerTo(RecTy *Ty) const {
+Init *BitInit::convertInitializerTo(const RecTy *Ty) const {
if (isa<BitRecTy>(Ty))
return const_cast<BitInit *>(this);
@@ -482,7 +484,7 @@ void BitsInit::Profile(FoldingSetNodeID &ID) const {
ProfileBitsInit(ID, ArrayRef(getTrailingObjects<Init *>(), NumBits));
}
-Init *BitsInit::convertInitializerTo(RecTy *Ty) const {
+Init *BitsInit::convertInitializerTo(const RecTy *Ty) const {
if (isa<BitRecTy>(Ty)) {
if (getNumBits() != 1) return nullptr; // Only accept if just one bit!
return getBit(0);
@@ -600,7 +602,7 @@ static bool canFitInBitfield(int64_t Value, unsigned NumBits) {
(Value >> NumBits == 0) || (Value >> (NumBits-1) == -1);
}
-Init *IntInit::convertInitializerTo(RecTy *Ty) const {
+Init *IntInit::convertInitializerTo(const RecTy *Ty) const {
if (isa<IntRecTy>(Ty))
return const_cast<IntInit *>(this);
@@ -673,16 +675,15 @@ StringInit *StringInit::get(RecordKeeper &RK, StringRef V, StringFormat Fmt) {
return Entry.second;
}
-Init *StringInit::convertInitializerTo(RecTy *Ty) const {
+Init *StringInit::convertInitializerTo(const RecTy *Ty) const {
if (isa<StringRecTy>(Ty))
return const_cast<StringInit *>(this);
return nullptr;
}
-static void ProfileListInit(FoldingSetNodeID &ID,
- ArrayRef<Init *> Range,
- RecTy *EltTy) {
+static void ProfileListInit(FoldingSetNodeID &ID, ArrayRef<Init *> Range,
+ const RecTy *EltTy) {
ID.AddInteger(Range.size());
ID.AddPointer(EltTy);
@@ -690,7 +691,7 @@ static void ProfileListInit(FoldingSetNodeID &ID,
ID.AddPointer(I);
}
-ListInit *ListInit::get(ArrayRef<Init *> Range, RecTy *EltTy) {
+ListInit *ListInit::get(ArrayRef<Init *> Range, const RecTy *EltTy) {
FoldingSetNodeID ID;
ProfileListInit(ID, Range, EltTy);
@@ -712,12 +713,12 @@ ListInit *ListInit::get(ArrayRef<Init *> Range, RecTy *EltTy) {
}
void ListInit::Profile(FoldingSetNodeID &ID) const {
- RecTy *EltTy = cast<ListRecTy>(getType())->getElementType();
+ const RecTy *EltTy = cast<ListRecTy>(getType())->getElementType();
ProfileListInit(ID, getValues(), EltTy);
}
-Init *ListInit::convertInitializerTo(RecTy *Ty) const {
+Init *ListInit::convertInitializerTo(const RecTy *Ty) const {
if (getType() == Ty)
return const_cast<ListInit*>(this);
@@ -728,7 +729,7 @@ Init *ListInit::convertInitializerTo(RecTy *Ty) const {
// Verify that all of the elements of the list are subclasses of the
// appropriate class!
bool Changed = false;
- RecTy *ElementType = LRT->getElementType();
+ const RecTy *ElementType = LRT->getElementType();
for (Init *I : getValues())
if (Init *CI = I->convertInitializerTo(ElementType)) {
Elements.push_back(CI);
@@ -802,14 +803,14 @@ Init *OpInit::getBit(unsigned Bit) const {
return VarBitInit::get(const_cast<OpInit*>(this), Bit);
}
-static void
-ProfileUnOpInit(FoldingSetNodeID &ID, unsigned Opcode, Init *Op, RecTy *Type) {
+static void ProfileUnOpInit(FoldingSetNodeID &ID, unsigned Opcode, Init *Op,
+ const RecTy *Type) {
ID.AddInteger(Opcode);
ID.AddPointer(Op);
ID.AddPointer(Type);
}
-UnOpInit *UnOpInit::get(UnaryOp Opc, Init *LHS, RecTy *Type) {
+UnOpInit *UnOpInit::get(UnaryOp Opc, Init *LHS, const RecTy *Type) {
FoldingSetNodeID ID;
ProfileUnOpInit(ID, Opc, LHS, Type);
@@ -988,7 +989,8 @@ Init *UnOpInit::Fold(Record *CurRec, bool IsFinal) const {
case LISTFLATTEN:
if (ListInit *LHSList = dyn_cast<ListInit>(LHS)) {
- ListRecTy *InnerListTy = dyn_cast<ListRecTy>(LHSList->getElementType());
+ const ListRecTy *InnerListTy =
+ dyn_cast<ListRecTy>(LHSList->getElementType());
// list of non-lists, !listflatten() is a NOP.
if (!InnerListTy)
return LHS;
@@ -1051,16 +1053,16 @@ std::string UnOpInit::getAsString() const {
return Result + "(" + LHS->getAsString() + ")";
}
-static void
-ProfileBinOpInit(FoldingSetNodeID &ID, unsigned Opcode, Init *LHS, Init *RHS,
- RecTy *Type) {
+static void ProfileBinOpInit(FoldingSetNodeID &ID, unsigned Opcode, Init *LHS,
+ Init *RHS, const RecTy *Type) {
ID.AddInteger(Opcode);
ID.AddPointer(LHS);
ID.AddPointer(RHS);
ID.AddPointer(Type);
}
-BinOpInit *BinOpInit::get(BinaryOp Opc, Init *LHS, Init *RHS, RecTy *Type) {
+BinOpInit *BinOpInit::get(BinaryOp Opc, Init *LHS, Init *RHS,
+ const RecTy *Type) {
FoldingSetNodeID ID;
ProfileBinOpInit(ID, Opc, LHS, RHS, Type);
@@ -1586,9 +1588,8 @@ std::string BinOpInit::getAsString() const {
return Result + "(" + LHS->getAsString() + ", " + RHS->getAsString() + ")";
}
-static void
-ProfileTernOpInit(FoldingSetNodeID &ID, unsigned Opcode, Init *LHS, Init *MHS,
- Init *RHS, RecTy *Type) {
+static void ProfileTernOpInit(FoldingSetNodeID &ID, unsigned Opcode, Init *LHS,
+ Init *MHS, Init *RHS, const RecTy *Type) {
ID.AddInteger(Opcode);
ID.AddPointer(LHS);
ID.AddPointer(MHS);
@@ -1597,7 +1598,7 @@ ProfileTernOpInit(FoldingSetNodeID &ID, unsigned Opcode, Init *LHS, Init *MHS,
}
TernOpInit *TernOpInit::get(TernaryOp Opc, Init *LHS, Init *MHS, Init *RHS,
- RecTy *Type) {
+ const RecTy *Type) {
FoldingSetNodeID ID;
ProfileTernOpInit(ID, Opc, LHS, MHS, RHS, Type);
@@ -1650,7 +1651,7 @@ static Init *ForeachDagApply(Init *LHS, DagInit *MHSd, Init *RHS,
}
// Applies RHS to all elements of MHS, using LHS as a temp variable.
-static Init *ForeachHelper(Init *LHS, Init *MHS, Init *RHS, RecTy *Type,
+static Init *ForeachHelper(Init *LHS, Init *MHS, Init *RHS, const RecTy *Type,
Record *CurRec) {
if (DagInit *MHSd = dyn_cast<DagInit>(MHS))
return ForeachDagApply(LHS, MHSd, RHS, CurRec);
@@ -1671,7 +1672,7 @@ static Init *ForeachHelper(Init *LHS, Init *MHS, Init *RHS, RecTy *Type,
// Evaluates RHS for all elements of MHS, using LHS as a temp variable.
// Creates a new list with the elements that evaluated to true.
-static Init *FilterHelper(Init *LHS, Init *MHS, Init *RHS, RecTy *Type,
+static Init *FilterHelper(Init *LHS, Init *MHS, Init *RHS, const RecTy *Type,
Record *CurRec) {
if (ListInit *MHSl = dyn_cast<ListInit>(MHS)) {
SmallVector<Init *, 8> NewList;
@@ -1954,7 +1955,7 @@ std::string TernOpInit::getAsString() const {
}
static void ProfileFoldOpInit(FoldingSetNodeID &ID, Init *Start, Init *List,
- Init *A, Init *B, Init *Expr, RecTy *Type) {
+ Init *A, Init *B, Init *Expr, const RecTy *Type) {
ID.AddPointer(Start);
ID.AddPointer(List);
ID.AddPointer(A);
@@ -1964,7 +1965,7 @@ static void ProfileFoldOpInit(FoldingSetNodeID &ID, Init *Start, Init *List,
}
FoldOpInit *FoldOpInit::get(Init *Start, Init *List, Init *A, Init *B,
- Init *Expr, RecTy *Type) {
+ Init *Expr, const RecTy *Type) {
FoldingSetNodeID ID;
ProfileFoldOpInit(ID, Start, List, A, B, Expr, Type);
@@ -2022,13 +2023,13 @@ std::string FoldOpInit::getAsString() const {
.str();
}
-static void ProfileIsAOpInit(FoldingSetNodeID &ID, RecTy *CheckType,
+static void ProfileIsAOpInit(FoldingSetNodeID &ID, const RecTy *CheckType,
Init *Expr) {
ID.AddPointer(CheckType);
ID.AddPointer(Expr);
}
-IsAOpInit *IsAOpInit::get(RecTy *CheckType, Init *Expr) {
+IsAOpInit *IsAOpInit::get(const RecTy *CheckType, Init *Expr) {
FoldingSetNodeID ID;
ProfileIsAOpInit(ID, CheckType, Expr);
@@ -2084,13 +2085,13 @@ std::string IsAOpInit::getAsString() const {
.str();
}
-static void ProfileExistsOpInit(FoldingSetNodeID &ID, RecTy *CheckType,
+static void ProfileExistsOpInit(FoldingSetNodeID &ID, const RecTy *CheckType,
Init *Expr) {
ID.AddPointer(CheckType);
ID.AddPointer(Expr);
}
-ExistsOpInit *ExistsOpInit::get(RecTy *CheckType, Init *Expr) {
+ExistsOpInit *ExistsOpInit::get(const RecTy *CheckType, Init *Expr) {
FoldingSetNodeID ID;
ProfileExistsOpInit(ID, CheckType, Expr);
@@ -2159,8 +2160,8 @@ std::string ExistsOpInit::getAsString() const {
.str();
}
-RecTy *TypedInit::getFieldType(StringInit *FieldName) const {
- if (RecordRecTy *RecordType = dyn_cast<RecordRecTy>(getType())) {
+const RecTy *TypedInit::getFieldType(StringInit *FieldName) const {
+ if (const RecordRecTy *RecordType = dyn_cast<RecordRecTy>(getType())) {
for (const Record *Rec : RecordType->getClasses()) {
if (const RecordVal *Field = Rec->getValue(FieldName))
return Field->getType();
@@ -2169,8 +2170,7 @@ RecTy *TypedInit::getFieldType(StringInit *FieldName) const {
return nullptr;
}
-Init *
-TypedInit::convertInitializerTo(RecTy *Ty) const {
+Init *TypedInit::convertInitializerTo(const RecTy *Ty) const {
if (getType() == Ty || getType()->typeIsA(Ty))
return const_cast<TypedInit *>(this);
@@ -2182,7 +2182,7 @@ TypedInit::convertInitializerTo(RecTy *Ty) const {
}
Init *TypedInit::convertInitializerBitRange(ArrayRef<unsigned> Bits) const {
- BitsRecTy *T = dyn_cast<BitsRecTy>(getType());
+ const BitsRecTy *T = dyn_cast<BitsRecTy>(getType());
if (!T) return nullptr; // Cannot subscript a non-bits variable.
unsigned NumBits = T->getNumBits();
@@ -2197,7 +2197,7 @@ Init *TypedInit::convertInitializerBitRange(ArrayRef<unsigned> Bits) const {
return BitsInit::get(getRecordKeeper(), NewBits);
}
-Init *TypedInit::getCastTo(RecTy *Ty) const {
+Init *TypedInit::getCastTo(const RecTy *Ty) const {
// Handle the common case quickly
if (getType() == Ty || getType()->typeIsA(Ty))
return const_cast<TypedInit *>(this);
@@ -2215,12 +2215,12 @@ Init *TypedInit::getCastTo(RecTy *Ty) const {
->Fold(nullptr);
}
-VarInit *VarInit::get(StringRef VN, RecTy *T) {
+VarInit *VarInit::get(StringRef VN, const RecTy *T) {
Init *Value = StringInit::get(T->getRecordKeeper(), VN);
return VarInit::get(Value, T);
}
-VarInit *VarInit::get(Init *VN, RecTy *T) {
+VarInit *VarInit::get(Init *VN, const RecTy *T) {
detail::RecordKeeperImpl &RK = T->getRecordKeeper().getImpl();
VarInit *&I = RK.TheVarInitPool[std::make_pair(T, VN)];
if (!I)
@@ -2268,14 +2268,14 @@ Init *VarBitInit::resolveReferences(Resolver &R) const {
DefInit::DefInit(Record *D)
: TypedInit(IK_DefInit, D->getType()), Def(D) {}
-Init *DefInit::convertInitializerTo(RecTy *Ty) const {
+Init *DefInit::convertInitializerTo(const RecTy *Ty) const {
if (auto *RRT = dyn_cast<RecordRecTy>(Ty))
if (getType()->typeIsConvertibleTo(RRT))
return const_cast<DefInit *>(this);
return nullptr;
}
-RecTy *DefInit::getFieldType(StringInit *FieldName) const {
+const RecTy *DefInit::getFieldType(StringInit *FieldName) const {
if (const RecordVal *RV = Def->getValue(FieldName))
return RV->getType();
return nullptr;
@@ -2489,7 +2489,7 @@ void CondOpInit::Profile(FoldingSetNodeID &ID) const {
}
CondOpInit *CondOpInit::get(ArrayRef<Init *> CondRange,
- ArrayRef<Init *> ValRange, RecTy *Ty) {
+ ArrayRef<Init *> ValRange, const RecTy *Ty) {
assert(CondRange.size() == ValRange.size() &&
"Number of conditions and values must match!");
@@ -2718,7 +2718,7 @@ std::string DagInit::getAsString() const {
// Other implementations
//===----------------------------------------------------------------------===//
-RecordVal::RecordVal(Init *N, RecTy *T, FieldKind K)
+RecordVal::RecordVal(Init *N, const RecTy *T, FieldKind K)
: Name(N), TyAndKind(T, K) {
setValue(UnsetInit::get(N->getRecordKeeper()));
assert(Value && "Cannot create unset value for current type!");
@@ -2726,7 +2726,7 @@ RecordVal::RecordVal(Init *N, RecTy *T, FieldKind K)
// This constructor accepts the same arguments as the above, but also
// a source location.
-RecordVal::RecordVal(Init *N, SMLoc Loc, RecTy *T, FieldKind K)
+RecordVal::RecordVal(Init *N, SMLoc Loc, const RecTy *T, FieldKind K)
: Name(N), Loc(Loc), TyAndKind(T, K) {
setValue(UnsetInit::get(N->getRecordKeeper()));
assert(Value && "Cannot create unset value for current type!");
@@ -2757,7 +2757,7 @@ bool RecordVal::setValue(Init *V) {
if (Value) {
assert(!isa<TypedInit>(Value) ||
cast<TypedInit>(Value)->getType()->typeIsA(getType()));
- if (BitsRecTy *BTy = dyn_cast<BitsRecTy>(getType())) {
+ if (const BitsRecTy *BTy = dyn_cast<BitsRecTy>(getType())) {
if (!isa<BitsInit>(Value)) {
SmallVector<Init *, 64> Bits;
Bits.reserve(BTy->getNumBits());
@@ -2782,7 +2782,7 @@ bool RecordVal::setValue(Init *V, SMLoc NewLoc) {
if (Value) {
assert(!isa<TypedInit>(Value) ||
cast<TypedInit>(Value)->getType()->typeIsA(getType()));
- if (BitsRecTy *BTy = dyn_cast<BitsRecTy>(getType())) {
+ if (const BitsRecTy *BTy = dyn_cast<BitsRecTy>(getType())) {
if (!isa<BitsInit>(Value)) {
SmallVector<Init *, 64> Bits;
Bits.reserve(BTy->getNumBits());
@@ -2829,7 +2829,7 @@ void Record::checkName() {
"' is not a string!");
}
-RecordRecTy *Record::getType() const {
+const RecordRecTy *Record::getType() const {
SmallVector<const Record *, 4> DirectSCs;
getDirectSuperClasses(DirectSCs);
return RecordRecTy::get(TrackedRecords, DirectSCs);
diff --git a/llvm/lib/TableGen/TGParser.cpp b/llvm/lib/TableGen/TGParser.cpp
index 5e7b885246eb30..91a3617f8579e0 100644
--- a/llvm/lib/TableGen/TGParser.cpp
+++ b/llvm/lib/TableGen/TGParser.cpp
@@ -1087,7 +1087,7 @@ bool TGParser::ParseOptionalBitList(SmallVectorImpl<unsigned> &Ranges) {
/// Type ::= DAG // dag type
/// Type ::= ClassID // Record Type
///
-RecTy *TGParser::ParseType() {
+const RecTy *TGParser::ParseType() {
switch (Lex.getCode()) {
default: TokError("Unknown token when expecting a type"); return nullptr;
case tgtok::String:
@@ -1137,7 +1137,7 @@ RecTy *TGParser::ParseType() {
return nullptr;
}
Lex.Lex(); // Eat '<'
- RecTy *SubType = ParseType();
+ const RecTy *SubType = ParseType();
if (!SubType) return nullptr;
if (!consume(tgtok::greater)) {
@@ -1182,7 +1182,7 @@ Init *TGParser::ParseIDValue(Record *CurRec, StringInit *Name, SMRange NameLoc,
///
/// Operation ::= XOperator ['<' Type '>'] '(' Args ')'
///
-Init *TGParser::ParseOperation(Record *CurRec, RecTy *ItemType) {
+Init *TGParser::ParseOperation(Record *CurRec, const RecTy *ItemType) {
switch (Lex.getCode()) {
default:
TokError("unknown bang operator");
@@ -1200,7 +1200,7 @@ Init *TGParser::ParseOperation(Record *CurRec, RecTy *ItemType) {
case tgtok::XRepr:
case tgtok::XGetDagOp: { // Value ::= !unop '(' Value ')'
UnOpInit::UnaryOp Code;
- RecTy *Type = nullptr;
+ const RecTy *Type = nullptr;
switch (Lex.getCode()) {
default: llvm_unreachable("Unhandled code!");
@@ -1305,10 +1305,7 @@ Init *TGParser::ParseOperation(Record *CurRec, RecTy *ItemType) {
return nullptr;
}
if (LHSt) {
- ListRecTy *LType = dyn_cast<ListRecTy>(LHSt->getType());
- StringRecTy *SType = dyn_cast<StringRecTy>(LHSt->getType());
- DagRecTy *DType = dyn_cast<DagRecTy>(LHSt->getType());
- if (!LType && !SType && !DType) {
+ if (!isa<ListRecTy, StringRecTy, DagRecTy>(LHSt->getType())) {
TokError("expected string, list, or dag type argument in unary operator");
return nullptr;
}
@@ -1324,8 +1321,7 @@ Init *TGParser::ParseOperation(Record *CurRec, RecTy *ItemType) {
return nullptr;
}
if (LHSt) {
- ListRecTy *LType = dyn_cast<ListRecTy>(LHSt->getType());
- if (!LType) {
+ if (!isa<ListRecTy>(LHSt->getType())) {
TokError("expected list type argument in unary operator");
return nullptr;
}
@@ -1348,14 +1344,14 @@ Init *TGParser::ParseOperation(Record *CurRec, RecTy *ItemType) {
: ListRecTy::get(Itemt->getType());
} else {
assert(LHSt && "expected list type argument in unary operator");
- ListRecTy *LType = dyn_cast<ListRecTy>(LHSt->getType());
+ const ListRecTy *LType = dyn_cast<ListRecTy>(LHSt->getType());
Type = UseElementType ? LType->getElementType() : LType;
}
// for !listflatten, we expect a list of lists, but also support a list of
// non-lists, where !listflatten will be a NOP.
if (Code == UnOpInit::LISTFLATTEN) {
- ListRecTy *InnerListTy = dyn_cast<ListRecTy>(Type);
+ const ListRecTy *InnerListTy = dyn_cast<ListRecTy>(Type);
if (InnerListTy) {
// listflatten will convert list<list<X>> to list<X>.
Type = ListRecTy::get(InnerListTy->getElementType());
@@ -1377,7 +1373,7 @@ Init *TGParser::ParseOperation(Record *CurRec, RecTy *ItemType) {
// Value ::= !isa '<' Type '>' '(' Value ')'
Lex.Lex(); // eat the operation
- RecTy *Type = ParseOperatorType();
+ const RecTy *Type = ParseOperatorType();
if (!Type)
return nullptr;
@@ -1402,7 +1398,7 @@ Init *TGParser::ParseOperation(Record *CurRec, RecTy *ItemType) {
// Value ::= !exists '<' Type '>' '(' Value ')'
Lex.Lex(); // eat the operation.
- RecTy *Type = ParseOperatorType();
+ const RecTy *Type = ParseOperatorType();
if (!Type)
return nullptr;
@@ -1422,7 +1418,7 @@ Init *TGParser::ParseOperation(Record *CurRec, RecTy *ItemType) {
return nullptr;
}
- RecordRecTy *RecType = dyn_cast<RecordRecTy>(ExprType->getType());
+ const RecordRecTy *RecType = dyn_cast<RecordRecTy>(ExprType->getType());
if (RecType) {
Error(ExprLoc,
"expected string type argument in !exists operator, please "
@@ -1430,7 +1426,7 @@ Init *TGParser::ParseOperation(Record *CurRec, RecTy *ItemType) {
return nullptr;
}
- StringRecTy *SType = dyn_cast<StringRecTy>(ExprType->getType());
+ const StringRecTy *SType = dyn_cast<StringRecTy>(ExprType->getType());
if (!SType) {
Error(ExprLoc, "expected string type argument in !exists operator");
return nullptr;
@@ -1509,8 +1505,8 @@ Init *TGParser::ParseOperation(Record *CurRec, RecTy *ItemType) {
break;
}
- RecTy *Type = nullptr;
- RecTy *ArgType = nullptr;
+ const RecTy *Type = nullptr;
+ const RecTy *ArgType = nullptr;
switch (OpTok) {
default:
llvm_unreachable("Unhandled code!");
@@ -1600,7 +1596,7 @@ Init *TGParser::ParseOperation(Record *CurRec, RecTy *ItemType) {
InitList.back()->getAsString() + "'"));
return nullptr;
}
- RecTy *ListType = InitListBack->getType();
+ const RecTy *ListType = InitListBack->getType();
if (!ArgType) {
// Argument type must be determined from the argument itself.
@@ -1702,7 +1698,7 @@ Init *TGParser::ParseOperation(Record *CurRec, RecTy *ItemType) {
} else {
// Desired argument type is a known and in ArgType.
- RecTy *Resolved = resolveTypes(ArgType, ListType);
+ const RecTy *Resolved = resolveTypes(ArgType, ListType);
if (!Resolved) {
Error(InitLoc, Twine("expected value of type '") +
ArgType->getAsString() + "', got '" +
@@ -1812,7 +1808,7 @@ Init *TGParser::ParseOperation(Record *CurRec, RecTy *ItemType) {
return nullptr;
}
- RecTy *ArgBackType = ArgBack->getType();
+ const RecTy *ArgBackType = ArgBack->getType();
if (!FirstArgIsList || Args.size() == 1) {
if (Args.size() == 1 && isa<ListRecTy>(ArgBackType)) {
FirstArgIsList = true; // Detect error if 2nd arg were present.
@@ -1888,7 +1884,7 @@ Init *TGParser::ParseOperation(Record *CurRec, RecTy *ItemType) {
case tgtok::XIf:
case tgtok::XSubst: { // Value ::= !ternop '(' Value ',' Value ',' Value ')'
TernOpInit::TernaryOp Code;
- RecTy *Type = nullptr;
+ const RecTy *Type = nullptr;
tgtok::TokKind LexCode = Lex.getCode();
Lex.Lex(); // eat the operation
@@ -1982,8 +1978,8 @@ Init *TGParser::ParseOperation(Record *CurRec, RecTy *ItemType) {
break;
}
case tgtok::XIf: {
- RecTy *MHSTy = nullptr;
- RecTy *RHSTy = nullptr;
+ const RecTy *MHSTy = nullptr;
+ const RecTy *RHSTy = nullptr;
if (TypedInit *MHSt = dyn_cast<TypedInit>(MHS))
MHSTy = MHSt->getType();
@@ -2104,7 +2100,7 @@ Init *TGParser::ParseOperation(Record *CurRec, RecTy *ItemType) {
return nullptr;
}
- ListRecTy *ListType = dyn_cast<ListRecTy>(List->getType());
+ const ListRecTy *ListType = dyn_cast<ListRecTy>(List->getType());
if (!ListType) {
TokError(Twine("!foldl list must be a list, but is of type '") +
List->getType()->getAsString());
@@ -2202,8 +2198,8 @@ Init *TGParser::ParseOperation(Record *CurRec, RecTy *ItemType) {
///
/// OperatorType ::= '<' Type '>'
///
-RecTy *TGParser::ParseOperatorType() {
- RecTy *Type = nullptr;
+const RecTy *TGParser::ParseOperatorType() {
+ const RecTy *Type = nullptr;
if (!consume(tgtok::less)) {
TokError("expected type name for operator");
@@ -2231,9 +2227,9 @@ RecTy *TGParser::ParseOperatorType() {
/// Parse the !substr operation. Return null on error.
///
/// Substr ::= !substr(string, start-int [, length-int]) => string
-Init *TGParser::ParseOperationSubstr(Record *CurRec, RecTy *ItemType) {
+Init *TGParser::ParseOperationSubstr(Record *CurRec, const RecTy *ItemType) {
TernOpInit::TernaryOp Code = TernOpInit::SUBSTR;
- RecTy *Type = StringRecTy::get(Records);
+ const RecTy *Type = StringRecTy::get(Records);
Lex.Lex(); // eat the operation
@@ -2319,9 +2315,9 @@ Init *TGParser::ParseOperationSubstr(Record *CurRec, RecTy *ItemType) {
/// Parse the !find operation. Return null on error.
///
/// Substr ::= !find(string, string [, start-int]) => int
-Init *TGParser::ParseOperationFind(Record *CurRec, RecTy *ItemType) {
+Init *TGParser::ParseOperationFind(Record *CurRec, const RecTy *ItemType) {
TernOpInit::TernaryOp Code = TernOpInit::FIND;
- RecTy *Type = IntRecTy::get(Records);
+ const RecTy *Type = IntRecTy::get(Records);
Lex.Lex(); // eat the operation
@@ -2408,7 +2404,8 @@ Init *TGParser::ParseOperationFind(Record *CurRec, RecTy *ItemType) {
///
/// ForEach ::= !foreach(ID, list-or-dag, expr) => list<expr type>
/// Filter ::= !foreach(ID, list, predicate) ==> list<list type>
-Init *TGParser::ParseOperationForEachFilter(Record *CurRec, RecTy *ItemType) {
+Init *TGParser::ParseOperationForEachFilter(Record *CurRec,
+ const RecTy *ItemType) {
SMLoc OpLoc = Lex.getLoc();
tgtok::TokKind Operation = Lex.getCode();
Lex.Lex(); // eat the operation
@@ -2452,14 +2449,14 @@ Init *TGParser::ParseOperationForEachFilter(Record *CurRec, RecTy *ItemType) {
return nullptr;
}
- RecTy *InEltType = nullptr;
- RecTy *ExprEltType = nullptr;
+ const RecTy *InEltType = nullptr;
+ const RecTy *ExprEltType = nullptr;
bool IsDAG = false;
- if (ListRecTy *InListTy = dyn_cast<ListRecTy>(MHSt->getType())) {
+ if (const ListRecTy *InListTy = dyn_cast<ListRecTy>(MHSt->getType())) {
InEltType = InListTy->getElementType();
if (ItemType) {
- if (ListRecTy *OutListTy = dyn_cast<ListRecTy>(ItemType)) {
+ if (const ListRecTy *OutListTy = dyn_cast<ListRecTy>(ItemType)) {
ExprEltType = (Operation == tgtok::XForEach)
? OutListTy->getElementType()
: IntRecTy::get(Records);
@@ -2471,7 +2468,7 @@ Init *TGParser::ParseOperationForEachFilter(Record *CurRec, RecTy *ItemType) {
return nullptr;
}
}
- } else if (DagRecTy *InDagTy = dyn_cast<DagRecTy>(MHSt->getType())) {
+ } else if (const DagRecTy *InDagTy = dyn_cast<DagRecTy>(MHSt->getType())) {
if (Operation == tgtok::XFilter) {
TokError("!filter must have a list argument");
return nullptr;
@@ -2514,7 +2511,7 @@ Init *TGParser::ParseOperationForEachFilter(Record *CurRec, RecTy *ItemType) {
return nullptr;
}
- RecTy *OutType = InEltType;
+ const RecTy *OutType = InEltType;
if (Operation == tgtok::XForEach && !IsDAG) {
TypedInit *RHSt = dyn_cast<TypedInit>(RHS);
if (!RHSt) {
@@ -2532,7 +2529,7 @@ Init *TGParser::ParseOperationForEachFilter(Record *CurRec, RecTy *ItemType) {
->Fold(CurRec);
}
-Init *TGParser::ParseOperationCond(Record *CurRec, RecTy *ItemType) {
+Init *TGParser::ParseOperationCond(Record *CurRec, const RecTy *ItemType) {
Lex.Lex(); // eat the operation 'cond'
if (!consume(tgtok::l_paren)) {
@@ -2577,9 +2574,9 @@ Init *TGParser::ParseOperationCond(Record *CurRec, RecTy *ItemType) {
}
// resolve type
- RecTy *Type = nullptr;
+ const RecTy *Type = nullptr;
for (Init *V : Val) {
- RecTy *VTy = nullptr;
+ const RecTy *VTy = nullptr;
if (TypedInit *Vt = dyn_cast<TypedInit>(V))
VTy = Vt->getType();
if (BitsInit *Vbits = dyn_cast<BitsInit>(V))
@@ -2592,7 +2589,7 @@ Init *TGParser::ParseOperationCond(Record *CurRec, RecTy *ItemType) {
Type = VTy;
} else {
if (!isa<UnsetInit>(V)) {
- RecTy *RType = resolveTypes(Type, VTy);
+ const RecTy *RType = resolveTypes(Type, VTy);
if (!RType) {
TokError(Twine("inconsistent types '") + Type->getAsString() +
"' and '" + VTy->getAsString() + "' for !cond");
@@ -2637,7 +2634,7 @@ Init *TGParser::ParseOperationCond(Record *CurRec, RecTy *ItemType) {
/// SimpleValue ::= STRCONCATTOK '(' Value ',' Value ')'
/// SimpleValue ::= COND '(' [Value ':' Value,]+ ')'
///
-Init *TGParser::ParseSimpleValue(Record *CurRec, RecTy *ItemType,
+Init *TGParser::ParseSimpleValue(Record *CurRec, const RecTy *ItemType,
IDParseMode Mode) {
Init *R = nullptr;
tgtok::TokKind Code = Lex.getCode();
@@ -2756,7 +2753,7 @@ Init *TGParser::ParseSimpleValue(Record *CurRec, RecTy *ItemType,
}
// bits<n> can also come from variable initializers.
if (VarInit *VI = dyn_cast<VarInit>(Vals[i])) {
- if (BitsRecTy *BitsRec = dyn_cast<BitsRecTy>(VI->getType())) {
+ if (const BitsRecTy *BitsRec = dyn_cast<BitsRecTy>(VI->getType())) {
for (unsigned i = 0, e = BitsRec->getNumBits(); i != e; ++i)
NewBits.push_back(VI->getBit((e - i) - 1));
continue;
@@ -2779,11 +2776,11 @@ Init *TGParser::ParseSimpleValue(Record *CurRec, RecTy *ItemType,
Lex.Lex(); // eat the '['
SmallVector<Init*, 16> Vals;
- RecTy *DeducedEltTy = nullptr;
- ListRecTy *GivenListTy = nullptr;
+ const RecTy *DeducedEltTy = nullptr;
+ const ListRecTy *GivenListTy = nullptr;
if (ItemType) {
- ListRecTy *ListType = dyn_cast<ListRecTy>(ItemType);
+ const ListRecTy *ListType = dyn_cast<ListRecTy>(ItemType);
if (!ListType) {
TokError(Twine("Encountered a list when expecting a ") +
ItemType->getAsString());
@@ -2802,7 +2799,7 @@ Init *TGParser::ParseSimpleValue(Record *CurRec, RecTy *ItemType,
return nullptr;
}
- RecTy *GivenEltTy = nullptr;
+ const RecTy *GivenEltTy = nullptr;
if (consume(tgtok::less)) {
// Optional list element type
GivenEltTy = ParseType();
@@ -2818,7 +2815,7 @@ Init *TGParser::ParseSimpleValue(Record *CurRec, RecTy *ItemType,
}
// Check elements
- RecTy *EltTy = nullptr;
+ const RecTy *EltTy = nullptr;
for (Init *V : Vals) {
TypedInit *TArg = dyn_cast<TypedInit>(V);
if (TArg) {
@@ -2915,7 +2912,8 @@ Init *TGParser::ParseSimpleValue(Record *CurRec, RecTy *ItemType,
/// ValueSuffix ::= '[' SliceElements ']'
/// ValueSuffix ::= '.' ID
///
-Init *TGParser::ParseValue(Record *CurRec, RecTy *ItemType, IDParseMode Mode) {
+Init *TGParser::ParseValue(Record *CurRec, const RecTy *ItemType,
+ IDParseMode Mode) {
SMLoc LHSLoc = Lex.getLoc();
Init *Result = ParseSimpleValue(CurRec, ItemType, Mode);
if (!Result) return nullptr;
@@ -3159,8 +3157,7 @@ void TGParser::ParseDagArgList(
/// ValueList ::= Value (',' Value)
///
void TGParser::ParseValueList(SmallVectorImpl<Init *> &Result, Record *CurRec,
- RecTy *ItemType) {
-
+ const RecTy *ItemType) {
Result.push_back(ParseValue(CurRec, ItemType));
if (!Result.back()) {
Result.clear();
@@ -3269,7 +3266,7 @@ Init *TGParser::ParseDeclaration(Record *CurRec,
// Read the field prefix if present.
bool HasField = consume(tgtok::Field);
- RecTy *Type = ParseType();
+ const RecTy *Type = ParseType();
if (!Type) return nullptr;
if (Lex.getCode() != tgtok::Id) {
@@ -3353,7 +3350,7 @@ VarInit *TGParser::ParseForeachDeclaration(Init *&ForeachListValue) {
return nullptr;
}
- RecTy *IterType = nullptr;
+ const RecTy *IterType = nullptr;
SmallVector<unsigned, 16> Ranges;
switch (Lex.getCode()) {
@@ -3497,7 +3494,7 @@ bool TGParser::ParseBodyItem(Record *CurRec) {
if (!Field)
return TokError("Value '" + FieldName->getValue() + "' unknown!");
- RecTy *Type = Field->getType();
+ const RecTy *Type = Field->getType();
if (!BitList.empty() && isa<BitsRecTy>(Type)) {
// When assigning to a subset of a 'bits' object, expect the RHS to have
// the type of that subset instead of the type of the whole object.
@@ -3659,7 +3656,7 @@ bool TGParser::ParseDefset() {
DefsetRecord Defset;
Defset.Loc = Lex.getLoc();
- RecTy *Type = ParseType();
+ const RecTy *Type = ParseType();
if (!Type)
return true;
if (!isa<ListRecTy>(Type))
@@ -3715,7 +3712,7 @@ bool TGParser::ParseDeftype() {
return TokError("expected '='");
SMLoc Loc = Lex.getLoc();
- RecTy *Type = ParseType();
+ const RecTy *Type = ParseType();
if (!Type)
return true;
@@ -3859,7 +3856,7 @@ bool TGParser::ParseIf(MultiClass *CurMultiClass) {
ListInit *EmptyList = ListInit::get({}, BitRecTy::get(Records));
ListInit *SingletonList =
ListInit::get({BitInit::get(Records, true)}, BitRecTy::get(Records));
- RecTy *BitListTy = ListRecTy::get(BitRecTy::get(Records));
+ const RecTy *BitListTy = ListRecTy::get(BitRecTy::get(Records));
// The foreach containing the then-clause selects SingletonList if
// the condition is true.
@@ -4413,7 +4410,7 @@ bool TGParser::CheckTemplateArgValues(
ArgName = Value->getName();
RecordVal *Arg = ArgsRec->getValue(ArgName);
- RecTy *ArgType = Arg->getType();
+ const RecTy *ArgType = Arg->getType();
if (TypedInit *ArgValue = dyn_cast<TypedInit>(Value->getValue())) {
auto *CastValue = ArgValue->getCastTo(ArgType);
diff --git a/llvm/lib/TableGen/TGParser.h b/llvm/lib/TableGen/TGParser.h
index b08e250870901a..f33ae1ce2c8107 100644
--- a/llvm/lib/TableGen/TGParser.h
+++ b/llvm/lib/TableGen/TGParser.h
@@ -74,7 +74,7 @@ struct ForeachLoop {
struct DefsetRecord {
SMLoc Loc;
- RecTy *EltTy = nullptr;
+ const RecTy *EltTy = nullptr;
SmallVector<Init *, 16> Elements;
};
@@ -143,7 +143,7 @@ class TGParser {
TGLexer Lex;
std::vector<SmallVector<LetRecord, 4>> LetStack;
std::map<std::string, std::unique_ptr<MultiClass>> MultiClasses;
- std::map<std::string, RecTy *> TypeAliases;
+ std::map<std::string, const RecTy *> TypeAliases;
/// Loops - Keep track of any foreach loops we are within.
///
@@ -288,12 +288,12 @@ class TGParser {
Init *ParseIDValue(Record *CurRec, StringInit *Name, SMRange NameLoc,
IDParseMode Mode = ParseValueMode);
- Init *ParseSimpleValue(Record *CurRec, RecTy *ItemType = nullptr,
+ Init *ParseSimpleValue(Record *CurRec, const RecTy *ItemType = nullptr,
IDParseMode Mode = ParseValueMode);
- Init *ParseValue(Record *CurRec, RecTy *ItemType = nullptr,
+ Init *ParseValue(Record *CurRec, const RecTy *ItemType = nullptr,
IDParseMode Mode = ParseValueMode);
- void ParseValueList(SmallVectorImpl<llvm::Init*> &Result,
- Record *CurRec, RecTy *ItemType = nullptr);
+ void ParseValueList(SmallVectorImpl<llvm::Init *> &Result, Record *CurRec,
+ const RecTy *ItemType = nullptr);
bool ParseTemplateArgValueList(SmallVectorImpl<llvm::ArgumentInit *> &Result,
Record *CurRec, Record *ArgsRec);
void ParseDagArgList(
@@ -306,13 +306,13 @@ class TGParser {
void ParseRangeList(SmallVectorImpl<unsigned> &Result);
bool ParseRangePiece(SmallVectorImpl<unsigned> &Ranges,
TypedInit *FirstItem = nullptr);
- RecTy *ParseType();
- Init *ParseOperation(Record *CurRec, RecTy *ItemType);
- Init *ParseOperationSubstr(Record *CurRec, RecTy *ItemType);
- Init *ParseOperationFind(Record *CurRec, RecTy *ItemType);
- Init *ParseOperationForEachFilter(Record *CurRec, RecTy *ItemType);
- Init *ParseOperationCond(Record *CurRec, RecTy *ItemType);
- RecTy *ParseOperatorType();
+ const RecTy *ParseType();
+ Init *ParseOperation(Record *CurRec, const RecTy *ItemType);
+ Init *ParseOperationSubstr(Record *CurRec, const RecTy *ItemType);
+ Init *ParseOperationFind(Record *CurRec, const RecTy *ItemType);
+ Init *ParseOperationForEachFilter(Record *CurRec, const RecTy *ItemType);
+ Init *ParseOperationCond(Record *CurRec, const RecTy *ItemType);
+ const RecTy *ParseOperatorType();
Init *ParseObjectName(MultiClass *CurMultiClass);
Record *ParseClassID();
MultiClass *ParseMultiClassID();
diff --git a/llvm/utils/TableGen/Common/CodeGenRegisters.cpp b/llvm/utils/TableGen/Common/CodeGenRegisters.cpp
index d0f4a2fbf5b47b..81a15334d63dca 100644
--- a/llvm/utils/TableGen/Common/CodeGenRegisters.cpp
+++ b/llvm/utils/TableGen/Common/CodeGenRegisters.cpp
@@ -651,7 +651,7 @@ struct TupleExpander : SetTheory::Expander {
// Precompute some types.
Record *RegisterCl = Def->getRecords().getClass("Register");
- RecTy *RegisterRecTy = RecordRecTy::get(RegisterCl);
+ const RecTy *RegisterRecTy = RecordRecTy::get(RegisterCl);
std::vector<StringRef> RegNames =
Def->getValueAsListOfStrings("RegAsmNames");
diff --git a/llvm/utils/TableGen/SearchableTableEmitter.cpp b/llvm/utils/TableGen/SearchableTableEmitter.cpp
index 549929d7a33820..d6cb94cdff24f1 100644
--- a/llvm/utils/TableGen/SearchableTableEmitter.cpp
+++ b/llvm/utils/TableGen/SearchableTableEmitter.cpp
@@ -56,7 +56,7 @@ struct GenericEnum {
struct GenericField {
std::string Name;
- RecTy *RecType = nullptr;
+ const RecTy *RecType = nullptr;
bool IsCode = false;
bool IsIntrinsic = false;
bool IsInstruction = false;
@@ -675,7 +675,7 @@ void SearchableTableEmitter::collectTableEntries(
if (!Field.RecType) {
Field.RecType = TI->getType();
} else {
- RecTy *Ty = resolveTypes(Field.RecType, TI->getType());
+ const RecTy *Ty = resolveTypes(Field.RecType, TI->getType());
if (!Ty)
PrintFatalError(EntryRec->getValue(Field.Name),
Twine("Field '") + Field.Name + "' of table '" +
More information about the llvm-commits
mailing list