Revert "Improve memory ownership/management in TableGen by unique_ptrifying TreePattern's Tree member."

This reverts commit r222183.

Broke on the MSVC buildbots due to MSVC not producing default move
operations - I'd fix it immediately but just broke my build system a
bit, so backing out until I have a chance to get everything going again.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@222187 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
David Blaikie 2014-11-17 22:55:41 +00:00
parent 3941c30371
commit 9e092ac163
2 changed files with 47 additions and 55 deletions

View File

@ -1902,10 +1902,10 @@ TreePattern::TreePattern(Record *TheRec, DagInit *Pat, bool isInput,
Trees.push_back(ParseTreePattern(Pat, "")); Trees.push_back(ParseTreePattern(Pat, ""));
} }
TreePattern::TreePattern(Record *TheRec, std::unique_ptr<TreePatternNode> Pat, bool isInput, TreePattern::TreePattern(Record *TheRec, TreePatternNode *Pat, bool isInput,
CodeGenDAGPatterns &cdp) : TheRecord(TheRec), CDP(cdp), CodeGenDAGPatterns &cdp) : TheRecord(TheRec), CDP(cdp),
isInputPattern(isInput), HasError(false) { isInputPattern(isInput), HasError(false) {
Trees.push_back(std::move(Pat)); Trees.push_back(Pat);
} }
void TreePattern::error(const Twine &Msg) { void TreePattern::error(const Twine &Msg) {
@ -1918,7 +1918,7 @@ void TreePattern::error(const Twine &Msg) {
void TreePattern::ComputeNamedNodes() { void TreePattern::ComputeNamedNodes() {
for (unsigned i = 0, e = Trees.size(); i != e; ++i) for (unsigned i = 0, e = Trees.size(); i != e; ++i)
ComputeNamedNodes(Trees[i].get()); ComputeNamedNodes(Trees[i]);
} }
void TreePattern::ComputeNamedNodes(TreePatternNode *N) { void TreePattern::ComputeNamedNodes(TreePatternNode *N) {
@ -1929,8 +1929,8 @@ void TreePattern::ComputeNamedNodes(TreePatternNode *N) {
ComputeNamedNodes(N->getChild(i)); ComputeNamedNodes(N->getChild(i));
} }
std::unique_ptr<TreePatternNode>
TreePattern::ParseTreePattern(Init *TheInit, StringRef OpName) { TreePatternNode *TreePattern::ParseTreePattern(Init *TheInit, StringRef OpName){
if (DefInit *DI = dyn_cast<DefInit>(TheInit)) { if (DefInit *DI = dyn_cast<DefInit>(TheInit)) {
Record *R = DI->getDef(); Record *R = DI->getDef();
@ -1944,7 +1944,7 @@ TreePattern::ParseTreePattern(Init *TheInit, StringRef OpName) {
OpName); OpName);
// Input argument? // Input argument?
auto Res = llvm::make_unique<TreePatternNode>(DI, 1); TreePatternNode *Res = new TreePatternNode(DI, 1);
if (R->getName() == "node" && !OpName.empty()) { if (R->getName() == "node" && !OpName.empty()) {
if (OpName.empty()) if (OpName.empty())
error("'node' argument requires a name to match with operand list"); error("'node' argument requires a name to match with operand list");
@ -1959,7 +1959,7 @@ TreePattern::ParseTreePattern(Init *TheInit, StringRef OpName) {
if (TheInit == UnsetInit::get()) { if (TheInit == UnsetInit::get()) {
if (OpName.empty()) if (OpName.empty())
error("'?' argument requires a name to match with operand list"); error("'?' argument requires a name to match with operand list");
auto Res = llvm::make_unique<TreePatternNode>(TheInit, 1); TreePatternNode *Res = new TreePatternNode(TheInit, 1);
Args.push_back(OpName); Args.push_back(OpName);
Res->setName(OpName); Res->setName(OpName);
return Res; return Res;
@ -1968,7 +1968,7 @@ TreePattern::ParseTreePattern(Init *TheInit, StringRef OpName) {
if (IntInit *II = dyn_cast<IntInit>(TheInit)) { if (IntInit *II = dyn_cast<IntInit>(TheInit)) {
if (!OpName.empty()) if (!OpName.empty())
error("Constant int argument should not have a name!"); error("Constant int argument should not have a name!");
return llvm::make_unique<TreePatternNode>(II, 1); return new TreePatternNode(II, 1);
} }
if (BitsInit *BI = dyn_cast<BitsInit>(TheInit)) { if (BitsInit *BI = dyn_cast<BitsInit>(TheInit)) {
@ -1994,7 +1994,7 @@ TreePattern::ParseTreePattern(Init *TheInit, StringRef OpName) {
if (Dag->getNumArgs() != 1) if (Dag->getNumArgs() != 1)
error("Type cast only takes one operand!"); error("Type cast only takes one operand!");
auto New = ParseTreePattern(Dag->getArg(0), Dag->getArgName(0)); TreePatternNode *New = ParseTreePattern(Dag->getArg(0), Dag->getArgName(0));
// Apply the type cast. // Apply the type cast.
assert(New->getNumTypes() == 1 && "FIXME: Unhandled"); assert(New->getNumTypes() == 1 && "FIXME: Unhandled");
@ -2044,8 +2044,7 @@ TreePattern::ParseTreePattern(Init *TheInit, StringRef OpName) {
// Parse all the operands. // Parse all the operands.
for (unsigned i = 0, e = Dag->getNumArgs(); i != e; ++i) for (unsigned i = 0, e = Dag->getNumArgs(); i != e; ++i)
Children.push_back( Children.push_back(ParseTreePattern(Dag->getArg(i), Dag->getArgName(i)));
ParseTreePattern(Dag->getArg(i), Dag->getArgName(i)).release());
// If the operator is an intrinsic, then this is just syntactic sugar for for // If the operator is an intrinsic, then this is just syntactic sugar for for
// (intrinsic_* <number>, ..children..). Pick the right intrinsic node, and // (intrinsic_* <number>, ..children..). Pick the right intrinsic node, and
@ -2090,7 +2089,7 @@ TreePattern::ParseTreePattern(Init *TheInit, StringRef OpName) {
} }
unsigned NumResults = GetNumNodeResults(Operator, CDP); unsigned NumResults = GetNumNodeResults(Operator, CDP);
auto Result = llvm::make_unique<TreePatternNode>(Operator, Children, NumResults); TreePatternNode *Result = new TreePatternNode(Operator, Children, NumResults);
Result->setName(OpName); Result->setName(OpName);
if (!Dag->getName().empty()) { if (!Dag->getName().empty()) {
@ -2106,7 +2105,7 @@ TreePattern::ParseTreePattern(Init *TheInit, StringRef OpName) {
/// more type generic things and have useless type casts fold away. /// more type generic things and have useless type casts fold away.
/// ///
/// This returns true if any change is made. /// This returns true if any change is made.
static bool SimplifyTree(std::unique_ptr<TreePatternNode> &N) { static bool SimplifyTree(TreePatternNode *&N) {
if (N->isLeaf()) if (N->isLeaf())
return false; return false;
@ -2116,7 +2115,7 @@ static bool SimplifyTree(std::unique_ptr<TreePatternNode> &N) {
N->getExtType(0).isConcrete() && N->getExtType(0).isConcrete() &&
N->getExtType(0) == N->getChild(0)->getExtType(0) && N->getExtType(0) == N->getChild(0)->getExtType(0) &&
N->getName().empty()) { N->getName().empty()) {
N.reset(N->getChild(0)); N = N->getChild(0);
SimplifyTree(N); SimplifyTree(N);
return true; return true;
} }
@ -2124,9 +2123,9 @@ static bool SimplifyTree(std::unique_ptr<TreePatternNode> &N) {
// Walk all children. // Walk all children.
bool MadeChange = false; bool MadeChange = false;
for (unsigned i = 0, e = N->getNumChildren(); i != e; ++i) { for (unsigned i = 0, e = N->getNumChildren(); i != e; ++i) {
std::unique_ptr<TreePatternNode> Child(N->getChild(i)); TreePatternNode *Child = N->getChild(i);
MadeChange |= SimplifyTree(Child); MadeChange |= SimplifyTree(Child);
N->setChild(i, Child.release()); N->setChild(i, Child);
} }
return MadeChange; return MadeChange;
} }
@ -2173,7 +2172,7 @@ InferAllTypes(const StringMap<SmallVector<TreePatternNode*,1> > *InNamedTypes) {
// changing the type of the input register in this case. This allows // changing the type of the input register in this case. This allows
// us to match things like: // us to match things like:
// def : Pat<(v1i64 (bitconvert(v2i32 DPR:$src))), (v1i64 DPR:$src)>; // def : Pat<(v1i64 (bitconvert(v2i32 DPR:$src))), (v1i64 DPR:$src)>;
if (Nodes[i] == Trees[0].get() && Nodes[i]->isLeaf()) { if (Nodes[i] == Trees[0] && Nodes[i]->isLeaf()) {
DefInit *DI = dyn_cast<DefInit>(Nodes[i]->getLeafValue()); DefInit *DI = dyn_cast<DefInit>(Nodes[i]->getLeafValue());
if (DI && (DI->getDef()->isSubClassOf("RegisterClass") || if (DI && (DI->getDef()->isSubClassOf("RegisterClass") ||
DI->getDef()->isSubClassOf("RegisterOperand"))) DI->getDef()->isSubClassOf("RegisterOperand")))
@ -2925,27 +2924,26 @@ const DAGInstruction &CodeGenDAGPatterns::parseInstructionPattern(
I->error("Input operand $" + InstInputsCheck.begin()->first + I->error("Input operand $" + InstInputsCheck.begin()->first +
" occurs in pattern but not in operands list!"); " occurs in pattern but not in operands list!");
auto ResultPattern = llvm::make_unique<TreePatternNode>( TreePatternNode *ResultPattern =
I->getRecord(), ResultNodeOperands, new TreePatternNode(I->getRecord(), ResultNodeOperands,
GetNumNodeResults(I->getRecord(), *this)); GetNumNodeResults(I->getRecord(), *this));
// Copy fully inferred output node type to instruction result pattern. // Copy fully inferred output node type to instruction result pattern.
for (unsigned i = 0; i != NumResults; ++i) for (unsigned i = 0; i != NumResults; ++i)
ResultPattern->setType(i, Res0Node->getExtType(i)); ResultPattern->setType(i, Res0Node->getExtType(i));
// Create and insert the instruction. // Create and insert the instruction.
// FIXME: InstImpResults should not be part of DAGInstruction. // FIXME: InstImpResults should not be part of DAGInstruction.
DAGInsts.insert(std::make_pair( DAGInstruction TheInst(I, Results, Operands, InstImpResults);
I->getRecord(), DAGInstruction(I, Results, Operands, InstImpResults))); DAGInsts.insert(std::make_pair(I->getRecord(), TheInst));
// Use a temporary tree pattern to infer all types and make sure that the // Use a temporary tree pattern to infer all types and make sure that the
// constructed result is correct. This depends on the instruction already // constructed result is correct. This depends on the instruction already
// being inserted into the DAGInsts map. // being inserted into the DAGInsts map.
TreePattern Temp(I->getRecord(), std::move(ResultPattern), false, *this); TreePattern Temp(I->getRecord(), ResultPattern, false, *this);
Temp.InferAllTypes(&I->getNamedNodesMap()); Temp.InferAllTypes(&I->getNamedNodesMap());
DAGInstruction &TheInsertedInst = DAGInsts.find(I->getRecord())->second; DAGInstruction &TheInsertedInst = DAGInsts.find(I->getRecord())->second;
TheInsertedInst.setResultPattern(std::move(Temp.getOnlyTree())); TheInsertedInst.setResultPattern(Temp.getOnlyTree());
return TheInsertedInst; return TheInsertedInst;
} }
@ -3377,7 +3375,7 @@ void CodeGenDAGPatterns::ParsePatterns() {
InstImpResults); InstImpResults);
// Promote the xform function to be an explicit node if set. // Promote the xform function to be an explicit node if set.
auto DstPattern = std::move(Result.getOnlyTree()); TreePatternNode *DstPattern = Result.getOnlyTree();
std::vector<TreePatternNode*> ResultNodeOperands; std::vector<TreePatternNode*> ResultNodeOperands;
for (unsigned ii = 0, ee = DstPattern->getNumChildren(); ii != ee; ++ii) { for (unsigned ii = 0, ee = DstPattern->getNumChildren(); ii != ee; ++ii) {
TreePatternNode *OpNode = DstPattern->getChild(ii); TreePatternNode *OpNode = DstPattern->getChild(ii);
@ -3389,16 +3387,16 @@ void CodeGenDAGPatterns::ParsePatterns() {
} }
ResultNodeOperands.push_back(OpNode); ResultNodeOperands.push_back(OpNode);
} }
if (!DstPattern->isLeaf()) { DstPattern = Result.getOnlyTree();
auto NewPattern = llvm::make_unique<TreePatternNode>( if (!DstPattern->isLeaf())
DstPattern->getOperator(), ResultNodeOperands, DstPattern = new TreePatternNode(DstPattern->getOperator(),
DstPattern->getNumTypes()); ResultNodeOperands,
for (unsigned i = 0, e = DstPattern->getNumTypes(); i != e; ++i) DstPattern->getNumTypes());
NewPattern->setType(i, DstPattern->getExtType(i));
DstPattern = std::move(NewPattern);
}
TreePattern Temp(Result.getRecord(), std::move(DstPattern), false, *this); for (unsigned i = 0, e = Result.getOnlyTree()->getNumTypes(); i != e; ++i)
DstPattern->setType(i, Result.getOnlyTree()->getExtType(i));
TreePattern Temp(Result.getRecord(), DstPattern, false, *this);
Temp.InferAllTypes(); Temp.InferAllTypes();
@ -3406,7 +3404,7 @@ void CodeGenDAGPatterns::ParsePatterns() {
PatternToMatch(CurPattern, PatternToMatch(CurPattern,
CurPattern->getValueAsListInit("Predicates"), CurPattern->getValueAsListInit("Predicates"),
Pattern->getTree(0), Pattern->getTree(0),
Temp.getOnlyTree().release(), InstImpResults, Temp.getOnlyTree(), InstImpResults,
CurPattern->getValueAsInt("AddedComplexity"), CurPattern->getValueAsInt("AddedComplexity"),
CurPattern->getID())); CurPattern->getID()));
} }

View File

@ -294,7 +294,7 @@ private:
std::string getPredCode() const; std::string getPredCode() const;
std::string getImmCode() const; std::string getImmCode() const;
}; };
/// FIXME: TreePatternNode's can be shared in some cases (due to dag-shaped /// FIXME: TreePatternNode's can be shared in some cases (due to dag-shaped
/// patterns), and as such should be ref counted. We currently just leak all /// patterns), and as such should be ref counted. We currently just leak all
@ -508,7 +508,7 @@ class TreePattern {
/// Trees - The list of pattern trees which corresponds to this pattern. /// Trees - The list of pattern trees which corresponds to this pattern.
/// Note that PatFrag's only have a single tree. /// Note that PatFrag's only have a single tree.
/// ///
std::vector<std::unique_ptr<TreePatternNode>> Trees; std::vector<TreePatternNode*> Trees;
/// NamedNodes - This is all of the nodes that have names in the trees in this /// NamedNodes - This is all of the nodes that have names in the trees in this
/// pattern. /// pattern.
@ -548,17 +548,15 @@ public:
CodeGenDAGPatterns &ise); CodeGenDAGPatterns &ise);
TreePattern(Record *TheRec, DagInit *Pat, bool isInput, TreePattern(Record *TheRec, DagInit *Pat, bool isInput,
CodeGenDAGPatterns &ise); CodeGenDAGPatterns &ise);
TreePattern(Record *TheRec, std::unique_ptr<TreePatternNode> Pat, TreePattern(Record *TheRec, TreePatternNode *Pat, bool isInput,
bool isInput, CodeGenDAGPatterns &ise); CodeGenDAGPatterns &ise);
/// getTrees - Return the tree patterns which corresponds to this pattern. /// getTrees - Return the tree patterns which corresponds to this pattern.
/// ///
const std::vector<std::unique_ptr<TreePatternNode>> &getTrees() const { const std::vector<TreePatternNode*> &getTrees() const { return Trees; }
return Trees;
}
unsigned getNumTrees() const { return Trees.size(); } unsigned getNumTrees() const { return Trees.size(); }
TreePatternNode *getTree(unsigned i) const { return Trees[i].get(); } TreePatternNode *getTree(unsigned i) const { return Trees[i]; }
std::unique_ptr<TreePatternNode> &getOnlyTree() { TreePatternNode *getOnlyTree() const {
assert(Trees.size() == 1 && "Doesn't have exactly one pattern!"); assert(Trees.size() == 1 && "Doesn't have exactly one pattern!");
return Trees[0]; return Trees[0];
} }
@ -588,8 +586,7 @@ public:
/// PatFrag references. /// PatFrag references.
void InlinePatternFragments() { void InlinePatternFragments() {
for (unsigned i = 0, e = Trees.size(); i != e; ++i) for (unsigned i = 0, e = Trees.size(); i != e; ++i)
// Can leak, if InlinePatternFragments doesn't return 'this' Trees[i] = Trees[i]->InlinePatternFragments(*this);
Trees[i].reset(Trees[i].release()->InlinePatternFragments(*this));
} }
/// InferAllTypes - Infer/propagate as many types throughout the expression /// InferAllTypes - Infer/propagate as many types throughout the expression
@ -612,7 +609,7 @@ public:
void dump() const; void dump() const;
private: private:
std::unique_ptr<TreePatternNode> ParseTreePattern(Init *DI, StringRef OpName); TreePatternNode *ParseTreePattern(Init *DI, StringRef OpName);
void ComputeNamedNodes(); void ComputeNamedNodes();
void ComputeNamedNodes(TreePatternNode *N); void ComputeNamedNodes(TreePatternNode *N);
}; };
@ -628,15 +625,14 @@ class DAGInstruction {
std::vector<Record*> Results; std::vector<Record*> Results;
std::vector<Record*> Operands; std::vector<Record*> Operands;
std::vector<Record*> ImpResults; std::vector<Record*> ImpResults;
std::unique_ptr<TreePatternNode> ResultPattern; TreePatternNode *ResultPattern;
public: public:
DAGInstruction(TreePattern *TP, DAGInstruction(TreePattern *TP,
const std::vector<Record*> &results, const std::vector<Record*> &results,
const std::vector<Record*> &operands, const std::vector<Record*> &operands,
const std::vector<Record*> &impresults) const std::vector<Record*> &impresults)
: Pattern(TP), Results(results), Operands(operands), : Pattern(TP), Results(results), Operands(operands),
ImpResults(impresults) {} ImpResults(impresults), ResultPattern(nullptr) {}
TreePattern *getPattern() const { return Pattern; } TreePattern *getPattern() const { return Pattern; }
unsigned getNumResults() const { return Results.size(); } unsigned getNumResults() const { return Results.size(); }
@ -644,9 +640,7 @@ public:
unsigned getNumImpResults() const { return ImpResults.size(); } unsigned getNumImpResults() const { return ImpResults.size(); }
const std::vector<Record*>& getImpResults() const { return ImpResults; } const std::vector<Record*>& getImpResults() const { return ImpResults; }
void setResultPattern(std::unique_ptr<TreePatternNode> R) { void setResultPattern(TreePatternNode *R) { ResultPattern = R; }
ResultPattern = std::move(R);
}
Record *getResult(unsigned RN) const { Record *getResult(unsigned RN) const {
assert(RN < Results.size()); assert(RN < Results.size());
@ -663,7 +657,7 @@ public:
return ImpResults[RN]; return ImpResults[RN];
} }
TreePatternNode *getResultPattern() const { return ResultPattern.get(); } TreePatternNode *getResultPattern() const { return ResultPattern; }
}; };
/// PatternToMatch - Used by CodeGenDAGPatterns to keep tab of patterns /// PatternToMatch - Used by CodeGenDAGPatterns to keep tab of patterns