diff options
author | Jakob Stoklund Olesen <stoklund@2pi.dk> | 2012-01-24 18:06:05 +0000 |
---|---|---|
committer | Jakob Stoklund Olesen <stoklund@2pi.dk> | 2012-01-24 18:06:05 +0000 |
commit | 60e70e8fcf2828f77828945fbd9cc54c28b5945d (patch) | |
tree | 7b9050adc4aaf303b8f75d69e52571f6fe5f4150 /llvm/utils/TableGen/SetTheory.cpp | |
parent | 3c4225a8581f0b865fd0de3125d5f1a195febe72 (diff) | |
download | bcm5719-llvm-60e70e8fcf2828f77828945fbd9cc54c28b5945d.tar.gz bcm5719-llvm-60e70e8fcf2828f77828945fbd9cc54c28b5945d.zip |
Add an (interleave A, B, ...) SetTheory operator.
This will interleave the elements from two or more lists.
llvm-svn: 148824
Diffstat (limited to 'llvm/utils/TableGen/SetTheory.cpp')
-rw-r--r-- | llvm/utils/TableGen/SetTheory.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/llvm/utils/TableGen/SetTheory.cpp b/llvm/utils/TableGen/SetTheory.cpp index 838b9246aad..0649fd1cfaf 100644 --- a/llvm/utils/TableGen/SetTheory.cpp +++ b/llvm/utils/TableGen/SetTheory.cpp @@ -139,6 +139,24 @@ struct DecimateOp : public SetIntBinOp { } }; +// (interleave S1, S2, ...) Interleave elements of the arguments. +struct InterleaveOp : public SetTheory::Operator { + void apply(SetTheory &ST, DagInit *Expr, RecSet &Elts) { + // Evaluate the arguments individually. + SmallVector<RecSet, 4> Args(Expr->getNumArgs()); + unsigned MaxSize = 0; + for (unsigned i = 0, e = Expr->getNumArgs(); i != e; ++i) { + ST.evaluate(Expr->getArg(i), Args[i]); + MaxSize = std::max(MaxSize, unsigned(Args[i].size())); + } + // Interleave arguments into Elts. + for (unsigned n = 0; n != MaxSize; ++n) + for (unsigned i = 0, e = Expr->getNumArgs(); i != e; ++i) + if (n < Args[i].size()) + Elts.insert(Args[i][n]); + } +}; + // (sequence "Format", From, To) Generate a sequence of records by name. struct SequenceOp : public SetTheory::Operator { void apply(SetTheory &ST, DagInit *Expr, RecSet &Elts) { @@ -211,6 +229,7 @@ SetTheory::SetTheory() { addOperator("rotl", new RotOp(false)); addOperator("rotr", new RotOp(true)); addOperator("decimate", new DecimateOp); + addOperator("interleave", new InterleaveOp); addOperator("sequence", new SequenceOp); } |