From ba6057de7198f57738550fccb5b43d30f83757bb Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Fri, 24 Apr 2015 06:49:44 +0000 Subject: [PATCH] [TableGen] Don't leak Expanders and Operators in SetTheory. llvm-svn: 235697 --- llvm/include/llvm/TableGen/SetTheory.h | 8 +++---- llvm/lib/TableGen/SetTheory.cpp | 41 ++++++++++++++++---------------- llvm/utils/TableGen/CodeGenRegisters.cpp | 2 +- llvm/utils/TableGen/CodeGenSchedule.cpp | 4 ++-- 4 files changed, 28 insertions(+), 27 deletions(-) diff --git a/llvm/include/llvm/TableGen/SetTheory.h b/llvm/include/llvm/TableGen/SetTheory.h index 76e56ec..595c29f 100644 --- a/llvm/include/llvm/TableGen/SetTheory.h +++ b/llvm/include/llvm/TableGen/SetTheory.h @@ -95,17 +95,17 @@ private: ExpandMap Expansions; // Known DAG operators by name. - StringMap Operators; + StringMap> Operators; // Typed expanders by class name. - StringMap Expanders; + StringMap> 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); /// 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); /// evaluate - Evaluate Expr and append the resulting set to Elts. void evaluate(Init *Expr, RecSet &Elts, ArrayRef Loc); diff --git a/llvm/lib/TableGen/SetTheory.cpp b/llvm/lib/TableGen/SetTheory.cpp index c99c2ba..a8816c8 100644 --- a/llvm/lib/TableGen/SetTheory.cpp +++ b/llvm/lib/TableGen/SetTheory.cpp @@ -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()); + addOperator("sub", llvm::make_unique()); + addOperator("and", llvm::make_unique()); + addOperator("shl", llvm::make_unique()); + addOperator("trunc", llvm::make_unique()); + addOperator("rotl", llvm::make_unique(false)); + addOperator("rotr", llvm::make_unique(true)); + addOperator("decimate", llvm::make_unique()); + addOperator("interleave", llvm::make_unique()); + addOperator("sequence", llvm::make_unique()); } -void SetTheory::addOperator(StringRef Name, Operator *Op) { - Operators[Name] = Op; +void SetTheory::addOperator(StringRef Name, std::unique_ptr Op) { + Operators[Name] = std::move(Op); } -void SetTheory::addExpander(StringRef ClassName, Expander *E) { - Expanders[ClassName] = E; +void SetTheory::addExpander(StringRef ClassName, std::unique_ptr E) { + Expanders[ClassName] = std::move(E); } void SetTheory::addFieldExpander(StringRef ClassName, StringRef FieldName) { - addExpander(ClassName, new FieldExpander(FieldName)); + addExpander(ClassName, llvm::make_unique(FieldName)); } void SetTheory::evaluate(Init *Expr, RecSet &Elts, ArrayRef Loc) { @@ -289,10 +289,10 @@ void SetTheory::evaluate(Init *Expr, RecSet &Elts, ArrayRef Loc) { DefInit *OpInit = dyn_cast(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 *Set) { // Skip unnamed superclasses. if (!dyn_cast(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; } diff --git a/llvm/utils/TableGen/CodeGenRegisters.cpp b/llvm/utils/TableGen/CodeGenRegisters.cpp index 4dd7681..8d6d3d1 100644 --- a/llvm/utils/TableGen/CodeGenRegisters.cpp +++ b/llvm/utils/TableGen/CodeGenRegisters.cpp @@ -924,7 +924,7 @@ CodeGenRegBank::CodeGenRegBank(RecordKeeper &Records) { // 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()); // Read in the user-defined (named) sub-register indices. // More indices will be synthesized later. diff --git a/llvm/utils/TableGen/CodeGenSchedule.cpp b/llvm/utils/TableGen/CodeGenSchedule.cpp index bfdf8dc..58363e8 100644 --- a/llvm/utils/TableGen/CodeGenSchedule.cpp +++ b/llvm/utils/TableGen/CodeGenSchedule.cpp @@ -93,8 +93,8 @@ CodeGenSchedModels::CodeGenSchedModels(RecordKeeper &RK, // 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()); + Sets.addOperator("instregex", llvm::make_unique(Target)); // Instantiate a CodeGenProcModel for each SchedMachineModel with the values // that are explicitly referenced in tablegen records. Resources associated -- 2.7.4