[llvm] 2829d50 - TableGen: Prune convertInitListSlice and VarListElementInit
NAKAMURA Takumi via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 26 07:50:34 PDT 2023
Author: NAKAMURA Takumi
Date: 2023-04-26T23:47:16+09:00
New Revision: 2829d509289eecde369738f49efb4b652a09074c
URL: https://github.com/llvm/llvm-project/commit/2829d509289eecde369738f49efb4b652a09074c
DIFF: https://github.com/llvm/llvm-project/commit/2829d509289eecde369738f49efb4b652a09074c.diff
LOG: TableGen: Prune convertInitListSlice and VarListElementInit
They were dedicated to constant version of list slice.
Depends on D147401
Differential Revision: https://reviews.llvm.org/D145872
Added:
Modified:
llvm/include/llvm/TableGen/Record.h
llvm/lib/TableGen/Record.cpp
llvm/lib/TableGen/TGParser.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/TableGen/Record.h b/llvm/include/llvm/TableGen/Record.h
index e44bb751ab20c..adb8e8cae64bb 100644
--- a/llvm/include/llvm/TableGen/Record.h
+++ b/llvm/include/llvm/TableGen/Record.h
@@ -314,7 +314,6 @@ class Init {
IK_AnonymousNameInit,
IK_StringInit,
IK_VarInit,
- IK_VarListElementInit,
IK_VarBitInit,
IK_VarDefInit,
IK_LastTypedInit,
@@ -384,14 +383,6 @@ class Init {
return nullptr;
}
- /// This function is used to implement the list slice
- /// selection operator. Given a value, it selects the specified list
- /// elements, returning them as a new \p Init of type \p list. If it
- /// is not legal to use the slice operator, null is returned.
- virtual Init *convertInitListSlice(ArrayRef<unsigned> Elements) 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.
@@ -443,7 +434,6 @@ class TypedInit : public Init {
Init *convertInitializerTo(RecTy *Ty) const override;
Init *convertInitializerBitRange(ArrayRef<unsigned> Bits) const override;
- Init *convertInitListSlice(ArrayRef<unsigned> Elements) const override;
/// This method is used to implement the FieldInit class.
/// Implementors of this method should return the type of the named field if
@@ -724,8 +714,6 @@ class ListInit final : public TypedInit, public FoldingSetNode,
Record *getElementAsRecord(unsigned i) const;
- Init *convertInitListSlice(ArrayRef<unsigned> Elements) const override;
-
Init *convertInitializerTo(RecTy *Ty) const override;
/// This method is used by classes that refer to other
@@ -1242,39 +1230,6 @@ class VarBitInit final : public TypedInit {
}
};
-/// List[4] - Represent access to one element of a var or
-/// field.
-class VarListElementInit : public TypedInit {
- TypedInit *TI;
- unsigned Element;
-
- VarListElementInit(TypedInit *T, unsigned E)
- : TypedInit(IK_VarListElementInit,
- cast<ListRecTy>(T->getType())->getElementType()),
- TI(T), Element(E) {
- assert(T->getType() && isa<ListRecTy>(T->getType()) &&
- "Illegal VarBitInit expression!");
- }
-
-public:
- VarListElementInit(const VarListElementInit &) = delete;
- VarListElementInit &operator=(const VarListElementInit &) = delete;
-
- static bool classof(const Init *I) {
- return I->getKind() == IK_VarListElementInit;
- }
-
- static VarListElementInit *get(TypedInit *T, unsigned E);
-
- TypedInit *getVariable() const { return TI; }
- unsigned getElementNum() const { return Element; }
-
- std::string getAsString() const override;
- Init *resolveReferences(Resolver &R) const override;
-
- Init *getBit(unsigned Bit) const override;
-};
-
/// AL - Represent a reference to a 'def' in the description
class DefInit : public TypedInit {
friend class Record;
diff --git a/llvm/lib/TableGen/Record.cpp b/llvm/lib/TableGen/Record.cpp
index 64fc006b97575..da64d685a97f6 100644
--- a/llvm/lib/TableGen/Record.cpp
+++ b/llvm/lib/TableGen/Record.cpp
@@ -83,8 +83,6 @@ struct RecordKeeperImpl {
FoldingSet<ExistsOpInit> TheExistsOpInitPool;
DenseMap<std::pair<RecTy *, Init *>, VarInit *> TheVarInitPool;
DenseMap<std::pair<TypedInit *, unsigned>, VarBitInit *> TheVarBitInitPool;
- DenseMap<std::pair<TypedInit *, unsigned>, VarListElementInit *>
- TheVarListElementInitPool;
FoldingSet<VarDefInit> TheVarDefInitPool;
DenseMap<std::pair<Init *, StringInit *>, FieldInit *> TheFieldInitPool;
FoldingSet<CondOpInit> TheCondOpInitPool;
@@ -670,23 +668,6 @@ Init *ListInit::convertInitializerTo(RecTy *Ty) const {
return nullptr;
}
-Init *ListInit::convertInitListSlice(ArrayRef<unsigned> Elements) const {
- if (Elements.size() == 1) {
- if (Elements[0] >= size())
- return nullptr;
- return getElement(Elements[0]);
- }
-
- SmallVector<Init *, 8> Vals;
- Vals.reserve(Elements.size());
- for (unsigned Element : Elements) {
- if (Element >= size())
- return nullptr;
- Vals.push_back(getElement(Element));
- }
- return ListInit::get(Vals, getElementType());
-}
-
Record *ListInit::getElementAsRecord(unsigned i) const {
assert(i < NumValues && "List element index out of range!");
DefInit *DI = dyn_cast<DefInit>(getElement(i));
@@ -1956,22 +1937,6 @@ Init *TypedInit::getCastTo(RecTy *Ty) const {
->Fold(nullptr);
}
-Init *TypedInit::convertInitListSlice(ArrayRef<unsigned> Elements) const {
- ListRecTy *T = dyn_cast<ListRecTy>(getType());
- if (!T)
- return nullptr; // Cannot subscript a non-list variable.
-
- if (Elements.size() == 1)
- return VarListElementInit::get(const_cast<TypedInit *>(this), Elements[0]);
-
- SmallVector<Init *, 8> ListInits;
- ListInits.reserve(Elements.size());
- for (unsigned Element : Elements)
- ListInits.push_back(
- VarListElementInit::get(const_cast<TypedInit *>(this), Element));
- return ListInit::get(ListInits, T->getElementType());
-}
-
VarInit *VarInit::get(StringRef VN, RecTy *T) {
Init *Value = StringInit::get(T->getRecordKeeper(), VN);
return VarInit::get(Value, T);
@@ -2022,38 +1987,8 @@ Init *VarBitInit::resolveReferences(Resolver &R) const {
return const_cast<VarBitInit*>(this);
}
-VarListElementInit *VarListElementInit::get(TypedInit *T, unsigned E) {
- detail::RecordKeeperImpl &RK = T->getRecordKeeper().getImpl();
- VarListElementInit *&I = RK.TheVarListElementInitPool[std::make_pair(T, E)];
- if (!I)
- I = new (RK.Allocator) VarListElementInit(T, E);
- return I;
-}
-
-std::string VarListElementInit::getAsString() const {
- return TI->getAsString() + "[" + utostr(Element) + "]";
-}
-
-Init *VarListElementInit::resolveReferences(Resolver &R) const {
- Init *NewTI = TI->resolveReferences(R);
- if (ListInit *List = dyn_cast<ListInit>(NewTI)) {
- // Leave out-of-bounds array references as-is. This can happen without
- // being an error, e.g. in the untaken "branch" of an !if expression.
- if (getElementNum() < List->size())
- return List->getElement(getElementNum());
- }
- if (NewTI != TI && isa<TypedInit>(NewTI))
- return VarListElementInit::get(cast<TypedInit>(NewTI), getElementNum());
- return const_cast<VarListElementInit *>(this);
-}
-
-Init *VarListElementInit::getBit(unsigned Bit) const {
- if (getType() == BitRecTy::get(getRecordKeeper()))
- return const_cast<VarListElementInit *>(this);
- return VarBitInit::get(const_cast<VarListElementInit *>(this), Bit);
-}
-
-DefInit::DefInit(Record *D) : TypedInit(IK_DefInit, D->getType()), Def(D) {}
+DefInit::DefInit(Record *D)
+ : TypedInit(IK_DefInit, D->getType()), Def(D) {}
DefInit *DefInit::get(Record *R) {
return R->getDefInit();
diff --git a/llvm/lib/TableGen/TGParser.cpp b/llvm/lib/TableGen/TGParser.cpp
index a67066b56d64a..ecd19b98e1b27 100644
--- a/llvm/lib/TableGen/TGParser.cpp
+++ b/llvm/lib/TableGen/TGParser.cpp
@@ -744,12 +744,12 @@ TypedInit *TGParser::ParseSliceElement(Record *CurRec) {
break;
}
case tgtok::IntVal: { // Deprecated "-num"
- auto *RHSi = IntInit::get(Records, -Lex.getCurIntVal());
- if (RHSi->getValue() < 0) {
+ auto i = -Lex.getCurIntVal();
+ if (i < 0) {
TokError("invalid range, cannot be negative");
return nullptr;
}
- RHS = RHSi;
+ RHS = IntInit::get(Records, i);
Lex.Lex(); // eat IntVal
break;
}
More information about the llvm-commits
mailing list