summaryrefslogtreecommitdiffstats
path: root/llvm/lib/TableGen/TGParser.h
diff options
context:
space:
mode:
authorNicolai Haehnle <nhaehnle@gmail.com>2018-06-21 13:35:44 +0000
committerNicolai Haehnle <nhaehnle@gmail.com>2018-06-21 13:35:44 +0000
commit7d69e0f37d2829e720662d6398a956c6b2e6048d (patch)
treea6cc45c53f9bd4963a17aed929bb71db274c9bbc /llvm/lib/TableGen/TGParser.h
parent42e31cbe7c9896ec06b7e9938405b6d3f9fc56c1 (diff)
downloadbcm5719-llvm-7d69e0f37d2829e720662d6398a956c6b2e6048d.tar.gz
bcm5719-llvm-7d69e0f37d2829e720662d6398a956c6b2e6048d.zip
TableGen: Allow foreach in multiclass to depend on template args
Summary: This also allows inner foreach loops to have a list that depends on the iteration variable of an outer foreach loop. The test cases show some very simple examples of how this can be used. This was perhaps the last remaining major non-orthogonality in the TableGen frontend. Change-Id: I79b92d41a5c0e7c03cc8af4000c5e1bda5ef464d Reviewers: tra, simon_tatham, craig.topper, MartinO, arsenm Subscribers: wdng, llvm-commits Differential Revision: https://reviews.llvm.org/D47431 llvm-svn: 335221
Diffstat (limited to 'llvm/lib/TableGen/TGParser.h')
-rw-r--r--llvm/lib/TableGen/TGParser.h62
1 files changed, 43 insertions, 19 deletions
diff --git a/llvm/lib/TableGen/TGParser.h b/llvm/lib/TableGen/TGParser.h
index a457aab3ff6..0a28b3a03aa 100644
--- a/llvm/lib/TableGen/TGParser.h
+++ b/llvm/lib/TableGen/TGParser.h
@@ -27,6 +27,7 @@ namespace llvm {
class RecordKeeper;
class RecTy;
class Init;
+ struct ForeachLoop;
struct MultiClass;
struct SubClassReference;
struct SubMultiClassReference;
@@ -41,14 +42,31 @@ namespace llvm {
}
};
+ /// RecordsEntry - Can be either a record or a foreach loop.
+ struct RecordsEntry {
+ std::unique_ptr<Record> Rec;
+ std::unique_ptr<ForeachLoop> Loop;
+
+ void dump() const;
+
+ RecordsEntry() {}
+ RecordsEntry(std::unique_ptr<Record> Rec) : Rec(std::move(Rec)) {}
+ RecordsEntry(std::unique_ptr<ForeachLoop> Loop)
+ : Loop(std::move(Loop)) {}
+ };
+
/// ForeachLoop - Record the iteration state associated with a for loop.
/// This is used to instantiate items in the loop body.
struct ForeachLoop {
+ SMLoc Loc;
VarInit *IterVar;
- ListInit *ListValue;
+ Init *ListValue;
+ std::vector<RecordsEntry> Entries;
+
+ void dump() const;
- ForeachLoop(VarInit *IVar, ListInit *LValue)
- : IterVar(IVar), ListValue(LValue) {}
+ ForeachLoop(SMLoc Loc, VarInit *IVar, Init *LValue)
+ : Loc(Loc), IterVar(IVar), ListValue(LValue) {}
};
struct DefsetRecord {
@@ -57,6 +75,16 @@ namespace llvm {
SmallVector<Init *, 16> Elements;
};
+struct MultiClass {
+ Record Rec; // Placeholder for template args and Name.
+ std::vector<RecordsEntry> Entries;
+
+ void dump() const;
+
+ MultiClass(StringRef Name, SMLoc Loc, RecordKeeper &Records) :
+ Rec(Name, Loc, Records) {}
+};
+
class TGParser {
TGLexer Lex;
std::vector<SmallVector<LetRecord, 4>> LetStack;
@@ -64,8 +92,7 @@ class TGParser {
/// Loops - Keep track of any foreach loops we are within.
///
- typedef std::vector<ForeachLoop> LoopVector;
- LoopVector Loops;
+ std::vector<std::unique_ptr<ForeachLoop>> Loops;
SmallVector<DefsetRecord *, 2> Defsets;
@@ -112,23 +139,19 @@ private: // Semantic analysis methods.
ArrayRef<unsigned> BitList, Init *V,
bool AllowSelfAssignment = false);
bool AddSubClass(Record *Rec, SubClassReference &SubClass);
+ bool AddSubClass(RecordsEntry &Entry, SubClassReference &SubClass);
bool AddSubMultiClass(MultiClass *CurMC,
SubMultiClassReference &SubMultiClass);
- // IterRecord: Map an iterator name to a value.
- struct IterRecord {
- VarInit *IterVar;
- Init *IterValue;
- IterRecord(VarInit *Var, Init *Val) : IterVar(Var), IterValue(Val) {}
- };
-
- // IterSet: The set of all iterator values at some point in the
- // iteration space.
- typedef std::vector<IterRecord> IterSet;
+ using SubstStack = SmallVector<std::pair<Init *, Init *>, 8>;
- bool addDefOne(std::unique_ptr<Record> Rec, IterSet &IterVals);
- bool addDefForeach(Record *Rec, IterSet &IterVals);
- bool addDef(std::unique_ptr<Record> Rec);
+ bool addEntry(RecordsEntry E);
+ bool resolve(const ForeachLoop &Loop, SubstStack &Stack, bool Final,
+ std::vector<RecordsEntry> *Dest, SMLoc *Loc = nullptr);
+ bool resolve(const std::vector<RecordsEntry> &Source, SubstStack &Substs,
+ bool Final, std::vector<RecordsEntry> *Dest,
+ SMLoc *Loc = nullptr);
+ bool addDefOne(std::unique_ptr<Record> Rec);
private: // Parser methods.
bool ParseObjectList(MultiClass *MC = nullptr);
@@ -148,7 +171,7 @@ private: // Parser methods.
bool ParseTemplateArgList(Record *CurRec);
Init *ParseDeclaration(Record *CurRec, bool ParsingTemplateArgs);
- VarInit *ParseForeachDeclaration(ListInit *&ForeachListValue);
+ VarInit *ParseForeachDeclaration(Init *&ForeachListValue);
SubClassReference ParseSubClassReference(Record *CurRec, bool isDefm);
SubMultiClassReference ParseSubMultiClassReference(MultiClass *CurMC);
@@ -175,6 +198,7 @@ private: // Parser methods.
Record *ParseClassID();
MultiClass *ParseMultiClassID();
bool ApplyLetStack(Record *CurRec);
+ bool ApplyLetStack(RecordsEntry &Entry);
};
} // end namespace llvm
OpenPOWER on IntegriCloud