1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-02-01 05:01:59 +01:00

[TableGen] Don't leak Expanders and Operators in SetTheory.

llvm-svn: 235697
This commit is contained in:
Craig Topper 2015-04-24 06:49:44 +00:00
parent 450d5f5eed
commit 60d2b0d189
4 changed files with 28 additions and 27 deletions

View File

@ -95,17 +95,17 @@ private:
ExpandMap Expansions; ExpandMap Expansions;
// Known DAG operators by name. // Known DAG operators by name.
StringMap<Operator*> Operators; StringMap<std::unique_ptr<Operator>> Operators;
// Typed expanders by class name. // Typed expanders by class name.
StringMap<Expander*> Expanders; StringMap<std::unique_ptr<Expander>> Expanders;
public: public:
/// Create a SetTheory instance with only the standard operators. /// Create a SetTheory instance with only the standard operators.
SetTheory(); SetTheory();
/// addExpander - Add an expander for Records with the named super class. /// 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 /// addFieldExpander - Add an expander for ClassName that simply evaluates
/// FieldName in the Record to get the set elements. That is all that is /// 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); void addFieldExpander(StringRef ClassName, StringRef FieldName);
/// addOperator - Add a DAG operator. /// 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. /// evaluate - Evaluate Expr and append the resulting set to Elts.
void evaluate(Init *Expr, RecSet &Elts, ArrayRef<SMLoc> Loc); void evaluate(Init *Expr, RecSet &Elts, ArrayRef<SMLoc> Loc);

View File

@ -245,28 +245,28 @@ void SetTheory::Expander::anchor() {}
SetTheory::SetTheory() { SetTheory::SetTheory() {
addOperator("add", new AddOp); addOperator("add", llvm::make_unique<AddOp>());
addOperator("sub", new SubOp); addOperator("sub", llvm::make_unique<SubOp>());
addOperator("and", new AndOp); addOperator("and", llvm::make_unique<AndOp>());
addOperator("shl", new ShlOp); addOperator("shl", llvm::make_unique<ShlOp>());
addOperator("trunc", new TruncOp); addOperator("trunc", llvm::make_unique<TruncOp>());
addOperator("rotl", new RotOp(false)); addOperator("rotl", llvm::make_unique<RotOp>(false));
addOperator("rotr", new RotOp(true)); addOperator("rotr", llvm::make_unique<RotOp>(true));
addOperator("decimate", new DecimateOp); addOperator("decimate", llvm::make_unique<DecimateOp>());
addOperator("interleave", new InterleaveOp); addOperator("interleave", llvm::make_unique<InterleaveOp>());
addOperator("sequence", new SequenceOp); addOperator("sequence", llvm::make_unique<SequenceOp>());
} }
void SetTheory::addOperator(StringRef Name, Operator *Op) { void SetTheory::addOperator(StringRef Name, std::unique_ptr<Operator> Op) {
Operators[Name] = Op; Operators[Name] = std::move(Op);
} }
void SetTheory::addExpander(StringRef ClassName, Expander *E) { void SetTheory::addExpander(StringRef ClassName, std::unique_ptr<Expander> E) {
Expanders[ClassName] = E; Expanders[ClassName] = std::move(E);
} }
void SetTheory::addFieldExpander(StringRef ClassName, StringRef FieldName) { 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) { void SetTheory::evaluate(Init *Expr, RecSet &Elts, ArrayRef<SMLoc> Loc) {
@ -289,10 +289,10 @@ void SetTheory::evaluate(Init *Expr, RecSet &Elts, ArrayRef<SMLoc> Loc) {
DefInit *OpInit = dyn_cast<DefInit>(DagExpr->getOperator()); DefInit *OpInit = dyn_cast<DefInit>(DagExpr->getOperator());
if (!OpInit) if (!OpInit)
PrintFatalError(Loc, "Bad set expression: " + Expr->getAsString()); PrintFatalError(Loc, "Bad set expression: " + Expr->getAsString());
Operator *Op = Operators.lookup(OpInit->getDef()->getName()); auto I = Operators.find(OpInit->getDef()->getName());
if (!Op) if (I == Operators.end())
PrintFatalError(Loc, "Unknown set operator: " + Expr->getAsString()); 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) { const RecVec *SetTheory::expand(Record *Set) {
@ -307,11 +307,12 @@ const RecVec *SetTheory::expand(Record *Set) {
// Skip unnamed superclasses. // Skip unnamed superclasses.
if (!dyn_cast<StringInit>(SC[i]->getNameInit())) if (!dyn_cast<StringInit>(SC[i]->getNameInit()))
continue; continue;
if (Expander *Exp = Expanders.lookup(SC[i]->getName())) { auto I = Expanders.find(SC[i]->getName());
if (I != Expanders.end()) {
// This breaks recursive definitions. // This breaks recursive definitions.
RecVec &EltVec = Expansions[Set]; RecVec &EltVec = Expansions[Set];
RecSet Elts; RecSet Elts;
Exp->expand(*this, Set, Elts); I->second->expand(*this, Set, Elts);
EltVec.assign(Elts.begin(), Elts.end()); EltVec.assign(Elts.begin(), Elts.end());
return &EltVec; return &EltVec;
} }

View File

@ -924,7 +924,7 @@ CodeGenRegBank::CodeGenRegBank(RecordKeeper &Records) {
// Configure register Sets to understand register classes and tuples. // Configure register Sets to understand register classes and tuples.
Sets.addFieldExpander("RegisterClass", "MemberList"); Sets.addFieldExpander("RegisterClass", "MemberList");
Sets.addFieldExpander("CalleeSavedRegs", "SaveList"); 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. // Read in the user-defined (named) sub-register indices.
// More indices will be synthesized later. // More indices will be synthesized later.

View File

@ -93,8 +93,8 @@ CodeGenSchedModels::CodeGenSchedModels(RecordKeeper &RK,
// Allow Set evaluation to recognize the dags used in InstRW records: // Allow Set evaluation to recognize the dags used in InstRW records:
// (instrs Op1, Op1...) // (instrs Op1, Op1...)
Sets.addOperator("instrs", new InstrsOp); Sets.addOperator("instrs", llvm::make_unique<InstrsOp>());
Sets.addOperator("instregex", new InstRegexOp(Target)); Sets.addOperator("instregex", llvm::make_unique<InstRegexOp>(Target));
// Instantiate a CodeGenProcModel for each SchedMachineModel with the values // Instantiate a CodeGenProcModel for each SchedMachineModel with the values
// that are explicitly referenced in tablegen records. Resources associated // that are explicitly referenced in tablegen records. Resources associated