[llvm] r235697 - [TableGen] Don't leak Expanders and Operators in SetTheory.
Craig Topper
craig.topper at gmail.com
Thu Apr 23 23:49:45 PDT 2015
Author: ctopper
Date: Fri Apr 24 01:49:44 2015
New Revision: 235697
URL: http://llvm.org/viewvc/llvm-project?rev=235697&view=rev
Log:
[TableGen] Don't leak Expanders and Operators in SetTheory.
Modified:
llvm/trunk/include/llvm/TableGen/SetTheory.h
llvm/trunk/lib/TableGen/SetTheory.cpp
llvm/trunk/utils/TableGen/CodeGenRegisters.cpp
llvm/trunk/utils/TableGen/CodeGenSchedule.cpp
Modified: llvm/trunk/include/llvm/TableGen/SetTheory.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/TableGen/SetTheory.h?rev=235697&r1=235696&r2=235697&view=diff
==============================================================================
--- llvm/trunk/include/llvm/TableGen/SetTheory.h (original)
+++ llvm/trunk/include/llvm/TableGen/SetTheory.h Fri Apr 24 01:49:44 2015
@@ -95,17 +95,17 @@ private:
ExpandMap Expansions;
// Known DAG operators by name.
- StringMap<Operator*> Operators;
+ StringMap<std::unique_ptr<Operator>> Operators;
// Typed expanders by class name.
- StringMap<Expander*> Expanders;
+ StringMap<std::unique_ptr<Expander>> Expanders;
public:
/// Create a SetTheory instance with only the standard operators.
SetTheory();
/// addExpander - Add an expander for Records with the named super class.
- void addExpander(StringRef ClassName, Expander*);
+ void addExpander(StringRef ClassName, std::unique_ptr<Expander>);
/// addFieldExpander - Add an expander for ClassName that simply evaluates
/// FieldName in the Record to get the set elements. That is all that is
@@ -118,7 +118,7 @@ public:
void addFieldExpander(StringRef ClassName, StringRef FieldName);
/// addOperator - Add a DAG operator.
- void addOperator(StringRef Name, Operator*);
+ void addOperator(StringRef Name, std::unique_ptr<Operator>);
/// evaluate - Evaluate Expr and append the resulting set to Elts.
void evaluate(Init *Expr, RecSet &Elts, ArrayRef<SMLoc> Loc);
Modified: llvm/trunk/lib/TableGen/SetTheory.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/TableGen/SetTheory.cpp?rev=235697&r1=235696&r2=235697&view=diff
==============================================================================
--- llvm/trunk/lib/TableGen/SetTheory.cpp (original)
+++ llvm/trunk/lib/TableGen/SetTheory.cpp Fri Apr 24 01:49:44 2015
@@ -245,28 +245,28 @@ void SetTheory::Expander::anchor() {}
SetTheory::SetTheory() {
- addOperator("add", new AddOp);
- addOperator("sub", new SubOp);
- addOperator("and", new AndOp);
- addOperator("shl", new ShlOp);
- addOperator("trunc", new TruncOp);
- addOperator("rotl", new RotOp(false));
- addOperator("rotr", new RotOp(true));
- addOperator("decimate", new DecimateOp);
- addOperator("interleave", new InterleaveOp);
- addOperator("sequence", new SequenceOp);
+ addOperator("add", llvm::make_unique<AddOp>());
+ addOperator("sub", llvm::make_unique<SubOp>());
+ addOperator("and", llvm::make_unique<AndOp>());
+ addOperator("shl", llvm::make_unique<ShlOp>());
+ addOperator("trunc", llvm::make_unique<TruncOp>());
+ addOperator("rotl", llvm::make_unique<RotOp>(false));
+ addOperator("rotr", llvm::make_unique<RotOp>(true));
+ addOperator("decimate", llvm::make_unique<DecimateOp>());
+ addOperator("interleave", llvm::make_unique<InterleaveOp>());
+ addOperator("sequence", llvm::make_unique<SequenceOp>());
}
-void SetTheory::addOperator(StringRef Name, Operator *Op) {
- Operators[Name] = Op;
+void SetTheory::addOperator(StringRef Name, std::unique_ptr<Operator> Op) {
+ Operators[Name] = std::move(Op);
}
-void SetTheory::addExpander(StringRef ClassName, Expander *E) {
- Expanders[ClassName] = E;
+void SetTheory::addExpander(StringRef ClassName, std::unique_ptr<Expander> E) {
+ Expanders[ClassName] = std::move(E);
}
void SetTheory::addFieldExpander(StringRef ClassName, StringRef FieldName) {
- addExpander(ClassName, new FieldExpander(FieldName));
+ addExpander(ClassName, llvm::make_unique<FieldExpander>(FieldName));
}
void SetTheory::evaluate(Init *Expr, RecSet &Elts, ArrayRef<SMLoc> Loc) {
@@ -289,10 +289,10 @@ void SetTheory::evaluate(Init *Expr, Rec
DefInit *OpInit = dyn_cast<DefInit>(DagExpr->getOperator());
if (!OpInit)
PrintFatalError(Loc, "Bad set expression: " + Expr->getAsString());
- Operator *Op = Operators.lookup(OpInit->getDef()->getName());
- if (!Op)
+ auto I = Operators.find(OpInit->getDef()->getName());
+ if (I == Operators.end())
PrintFatalError(Loc, "Unknown set operator: " + Expr->getAsString());
- Op->apply(*this, DagExpr, Elts, Loc);
+ I->second->apply(*this, DagExpr, Elts, Loc);
}
const RecVec *SetTheory::expand(Record *Set) {
@@ -307,11 +307,12 @@ const RecVec *SetTheory::expand(Record *
// Skip unnamed superclasses.
if (!dyn_cast<StringInit>(SC[i]->getNameInit()))
continue;
- if (Expander *Exp = Expanders.lookup(SC[i]->getName())) {
+ auto I = Expanders.find(SC[i]->getName());
+ if (I != Expanders.end()) {
// This breaks recursive definitions.
RecVec &EltVec = Expansions[Set];
RecSet Elts;
- Exp->expand(*this, Set, Elts);
+ I->second->expand(*this, Set, Elts);
EltVec.assign(Elts.begin(), Elts.end());
return &EltVec;
}
Modified: llvm/trunk/utils/TableGen/CodeGenRegisters.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/CodeGenRegisters.cpp?rev=235697&r1=235696&r2=235697&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/CodeGenRegisters.cpp (original)
+++ llvm/trunk/utils/TableGen/CodeGenRegisters.cpp Fri Apr 24 01:49:44 2015
@@ -924,7 +924,7 @@ CodeGenRegBank::CodeGenRegBank(RecordKee
// Configure register Sets to understand register classes and tuples.
Sets.addFieldExpander("RegisterClass", "MemberList");
Sets.addFieldExpander("CalleeSavedRegs", "SaveList");
- Sets.addExpander("RegisterTuples", new TupleExpander());
+ Sets.addExpander("RegisterTuples", llvm::make_unique<TupleExpander>());
// Read in the user-defined (named) sub-register indices.
// More indices will be synthesized later.
Modified: llvm/trunk/utils/TableGen/CodeGenSchedule.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/CodeGenSchedule.cpp?rev=235697&r1=235696&r2=235697&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/CodeGenSchedule.cpp (original)
+++ llvm/trunk/utils/TableGen/CodeGenSchedule.cpp Fri Apr 24 01:49:44 2015
@@ -93,8 +93,8 @@ CodeGenSchedModels::CodeGenSchedModels(R
// Allow Set evaluation to recognize the dags used in InstRW records:
// (instrs Op1, Op1...)
- Sets.addOperator("instrs", new InstrsOp);
- Sets.addOperator("instregex", new InstRegexOp(Target));
+ Sets.addOperator("instrs", llvm::make_unique<InstrsOp>());
+ Sets.addOperator("instregex", llvm::make_unique<InstRegexOp>(Target));
// Instantiate a CodeGenProcModel for each SchedMachineModel with the values
// that are explicitly referenced in tablegen records. Resources associated
More information about the llvm-commits
mailing list