summaryrefslogtreecommitdiffstats
path: root/llvm/utils/TableGen/TableGen.cpp
diff options
context:
space:
mode:
authorJakob Stoklund Olesen <stoklund@2pi.dk>2011-06-04 04:11:37 +0000
committerJakob Stoklund Olesen <stoklund@2pi.dk>2011-06-04 04:11:37 +0000
commitfc205a5694fd530ac921a56bd44e7ac71661e85c (patch)
treee703a34602a100e0b0401e201fdec1dd619b6f59 /llvm/utils/TableGen/TableGen.cpp
parent75b205386388c751921b8321e20a30cf0e4cc916 (diff)
downloadbcm5719-llvm-fc205a5694fd530ac921a56bd44e7ac71661e85c.tar.gz
bcm5719-llvm-fc205a5694fd530ac921a56bd44e7ac71661e85c.zip
Teach TableGen to evaluate DAG expressions as set operations.
A TableGen backend can define how certain classes can be expanded into ordered sets of defs, typically by evaluating a specific field in the record. The SetTheory class can then evaluate DAG expressions that refer to these named sets. A number of standard set and list operations are predefined, and the backend can add more specialized operators if needed. The -print-sets backend is used by SetTheory.td to provide examples. This is intended to simplify how register classes are defined: def GR32_NOSP : RegisterClass<"X86", [i32], 32, (sub GR32, ESP)>; llvm-svn: 132621
Diffstat (limited to 'llvm/utils/TableGen/TableGen.cpp')
-rw-r--r--llvm/utils/TableGen/TableGen.cpp21
1 files changed, 20 insertions, 1 deletions
diff --git a/llvm/utils/TableGen/TableGen.cpp b/llvm/utils/TableGen/TableGen.cpp
index fb941c44dcf..925b134ca4f 100644
--- a/llvm/utils/TableGen/TableGen.cpp
+++ b/llvm/utils/TableGen/TableGen.cpp
@@ -37,6 +37,7 @@
#include "RegisterInfoEmitter.h"
#include "ARMDecoderEmitter.h"
#include "SubtargetEmitter.h"
+#include "SetTheory.h"
#include "TGParser.h"
#include "llvm/ADT/OwningPtr.h"
#include "llvm/Support/CommandLine.h"
@@ -80,7 +81,8 @@ enum ActionType {
GenArmNeon,
GenArmNeonSema,
GenArmNeonTest,
- PrintEnums
+ PrintEnums,
+ PrintSets
};
namespace {
@@ -162,6 +164,8 @@ namespace {
"Generate ARM NEON tests for clang"),
clEnumValN(PrintEnums, "print-enums",
"Print enum values for a class"),
+ clEnumValN(PrintSets, "print-sets",
+ "Print expanded sets for testing DAG exprs"),
clEnumValEnd));
cl::opt<std::string>
@@ -374,6 +378,21 @@ int main(int argc, char **argv) {
Out.os() << "\n";
break;
}
+ case PrintSets:
+ {
+ SetTheory Sets(&Records);
+ Sets.addFieldExpander("Set", "Elements");
+ std::vector<Record*> Recs = Records.getAllDerivedDefinitions("Set");
+ for (unsigned i = 0, e = Recs.size(); i != e; ++i) {
+ Out.os() << Recs[i]->getName() << " = [";
+ const std::vector<Record*> *Elts = Sets.expand(Recs[i]);
+ assert(Elts && "Couldn't expand Set instance");
+ for (unsigned ei = 0, ee = Elts->size(); ei != ee; ++ei)
+ Out.os() << ' ' << (*Elts)[ei]->getName();
+ Out.os() << " ]\n";
+ }
+ break;
+ }
default:
assert(1 && "Invalid Action");
return 1;
OpenPOWER on IntegriCloud