summaryrefslogtreecommitdiff
path: root/utils/TableGen/TGParser.cpp
diff options
context:
space:
mode:
authorJakob Stoklund Olesen <stoklund@2pi.dk>2011-07-18 17:02:57 +0000
committerJakob Stoklund Olesen <stoklund@2pi.dk>2011-07-18 17:02:57 +0000
commit77f8274c7d4bfb5e2a449eb49dc78dcae37e5457 (patch)
tree49292d4e5c83d913536a8d3021e83d965a6e5c4b /utils/TableGen/TGParser.cpp
parent22e522e08640be459f237796009cf7666d6d75e7 (diff)
downloadllvm-77f8274c7d4bfb5e2a449eb49dc78dcae37e5457.tar.gz
llvm-77f8274c7d4bfb5e2a449eb49dc78dcae37e5457.tar.bz2
llvm-77f8274c7d4bfb5e2a449eb49dc78dcae37e5457.tar.xz
Intern all RecTy subclass instances to avoid duplicates.
Make all of the RecTy constructors private, and use get() factory methods instead. Return singleton instances when it makes sense. ListTy instance pointers are stored in the element RecTy instance. BitsRecTy instance pointers, one per length, are stored in a static vector. Also unique DefInit instances. A Record has a unique DefInit which has a unique RecordRecTy instance. This saves some 200k-300k RecTy allocations when parsing ARM.td. It reduces TableGen's heap usage by almost 50%. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@135399 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils/TableGen/TGParser.cpp')
-rw-r--r--utils/TableGen/TGParser.cpp46
1 files changed, 23 insertions, 23 deletions
diff --git a/utils/TableGen/TGParser.cpp b/utils/TableGen/TGParser.cpp
index 59097f986f..1b916b44c7 100644
--- a/utils/TableGen/TGParser.cpp
+++ b/utils/TableGen/TGParser.cpp
@@ -106,9 +106,9 @@ bool TGParser::SetValue(Record *CurRec, SMLoc Loc, const std::string &ValName,
return Error(Loc, "Value '" + ValName + "' is not a bits type");
// Convert the incoming value to a bits type of the appropriate size...
- Init *BI = V->convertInitializerTo(new BitsRecTy(BitList.size()));
+ Init *BI = V->convertInitializerTo(BitsRecTy::get(BitList.size()));
if (BI == 0) {
- V->convertInitializerTo(new BitsRecTy(BitList.size()));
+ V->convertInitializerTo(BitsRecTy::get(BitList.size()));
return Error(Loc, "Initializer is not compatible with bit range");
}
@@ -581,13 +581,13 @@ bool TGParser::ParseOptionalBitList(std::vector<unsigned> &Ranges) {
RecTy *TGParser::ParseType() {
switch (Lex.getCode()) {
default: TokError("Unknown token when expecting a type"); return 0;
- case tgtok::String: Lex.Lex(); return new StringRecTy();
- case tgtok::Bit: Lex.Lex(); return new BitRecTy();
- case tgtok::Int: Lex.Lex(); return new IntRecTy();
- case tgtok::Code: Lex.Lex(); return new CodeRecTy();
- case tgtok::Dag: Lex.Lex(); return new DagRecTy();
+ case tgtok::String: Lex.Lex(); return StringRecTy::get();
+ case tgtok::Bit: Lex.Lex(); return BitRecTy::get();
+ case tgtok::Int: Lex.Lex(); return IntRecTy::get();
+ case tgtok::Code: Lex.Lex(); return CodeRecTy::get();
+ case tgtok::Dag: Lex.Lex(); return DagRecTy::get();
case tgtok::Id:
- if (Record *R = ParseClassID()) return new RecordRecTy(R);
+ if (Record *R = ParseClassID()) return RecordRecTy::get(R);
return 0;
case tgtok::Bits: {
if (Lex.Lex() != tgtok::less) { // Eat 'bits'
@@ -604,7 +604,7 @@ RecTy *TGParser::ParseType() {
return 0;
}
Lex.Lex(); // Eat '>'
- return new BitsRecTy(Val);
+ return BitsRecTy::get(Val);
}
case tgtok::List: {
if (Lex.Lex() != tgtok::less) { // Eat 'bits'
@@ -620,7 +620,7 @@ RecTy *TGParser::ParseType() {
return 0;
}
Lex.Lex(); // Eat '>'
- return new ListRecTy(SubType);
+ return ListRecTy::get(SubType);
}
}
}
@@ -667,7 +667,7 @@ Init *TGParser::ParseIDValue(Record *CurRec,
}
if (Record *D = Records.getDef(Name))
- return new DefInit(D);
+ return DefInit::get(D);
Error(NameLoc, "Variable not defined: '" + Name + "'");
return 0;
@@ -715,7 +715,7 @@ Init *TGParser::ParseOperation(Record *CurRec) {
case tgtok::XEmpty:
Lex.Lex(); // eat the operation
Code = UnOpInit::EMPTY;
- Type = new IntRecTy;
+ Type = IntRecTy::get();
break;
}
if (Lex.getCode() != tgtok::l_paren) {
@@ -767,7 +767,7 @@ Init *TGParser::ParseOperation(Record *CurRec) {
if (Code == UnOpInit::HEAD) {
Type = Itemt->getType();
} else {
- Type = new ListRecTy(Itemt->getType());
+ Type = ListRecTy::get(Itemt->getType());
}
} else {
assert(LHSt && "expected list type argument in unary operator");
@@ -808,14 +808,14 @@ Init *TGParser::ParseOperation(Record *CurRec) {
switch (OpTok) {
default: assert(0 && "Unhandled code!");
- case tgtok::XConcat: Code = BinOpInit::CONCAT; Type = new DagRecTy(); break;
- case tgtok::XSRA: Code = BinOpInit::SRA; Type = new IntRecTy(); break;
- case tgtok::XSRL: Code = BinOpInit::SRL; Type = new IntRecTy(); break;
- case tgtok::XSHL: Code = BinOpInit::SHL; Type = new IntRecTy(); break;
- case tgtok::XEq: Code = BinOpInit::EQ; Type = new BitRecTy(); break;
+ case tgtok::XConcat: Code = BinOpInit::CONCAT;Type = DagRecTy::get(); break;
+ case tgtok::XSRA: Code = BinOpInit::SRA; Type = IntRecTy::get(); break;
+ case tgtok::XSRL: Code = BinOpInit::SRL; Type = IntRecTy::get(); break;
+ case tgtok::XSHL: Code = BinOpInit::SHL; Type = IntRecTy::get(); break;
+ case tgtok::XEq: Code = BinOpInit::EQ; Type = BitRecTy::get(); break;
case tgtok::XStrConcat:
Code = BinOpInit::STRCONCAT;
- Type = new StringRecTy();
+ Type = StringRecTy::get();
break;
}
@@ -932,14 +932,14 @@ Init *TGParser::ParseOperation(Record *CurRec) {
if (MHSbits && RHSbits &&
MHSbits->getNumBits() == RHSbits->getNumBits()) {
- Type = new BitRecTy();
+ Type = BitRecTy::get();
break;
} else {
BitInit *MHSbit = dynamic_cast<BitInit*>(MHS);
BitInit *RHSbit = dynamic_cast<BitInit*>(RHS);
if (MHSbit && RHSbit) {
- Type = new BitRecTy();
+ Type = BitRecTy::get();
break;
}
}
@@ -1110,7 +1110,7 @@ Init *TGParser::ParseSimpleValue(Record *CurRec, RecTy *ItemType) {
Records.addDef(NewRec);
// The result of the expression is a reference to the new record.
- return new DefInit(NewRec);
+ return DefInit::get(NewRec);
}
case tgtok::l_brace: { // Value ::= '{' ValueList '}'
SMLoc BraceLoc = Lex.getLoc();
@@ -1129,7 +1129,7 @@ Init *TGParser::ParseSimpleValue(Record *CurRec, RecTy *ItemType) {
BitsInit *Result = new BitsInit(Vals.size());
for (unsigned i = 0, e = Vals.size(); i != e; ++i) {
- Init *Bit = Vals[i]->convertInitializerTo(new BitRecTy());
+ Init *Bit = Vals[i]->convertInitializerTo(BitRecTy::get());
if (Bit == 0) {
Error(BraceLoc, "Element #" + utostr(i) + " (" + Vals[i]->getAsString()+
") is not convertable to a bit");