[llvm] r222187 - Revert "Improve memory ownership/management in TableGen by unique_ptrifying TreePattern's Tree member."
David Blaikie
dblaikie at gmail.com
Mon Nov 17 14:55:41 PST 2014
Author: dblaikie
Date: Mon Nov 17 16:55:41 2014
New Revision: 222187
URL: http://llvm.org/viewvc/llvm-project?rev=222187&view=rev
Log:
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.
Modified:
llvm/trunk/utils/TableGen/CodeGenDAGPatterns.cpp
llvm/trunk/utils/TableGen/CodeGenDAGPatterns.h
Modified: llvm/trunk/utils/TableGen/CodeGenDAGPatterns.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/CodeGenDAGPatterns.cpp?rev=222187&r1=222186&r2=222187&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/CodeGenDAGPatterns.cpp (original)
+++ llvm/trunk/utils/TableGen/CodeGenDAGPatterns.cpp Mon Nov 17 16:55:41 2014
@@ -1902,10 +1902,10 @@ TreePattern::TreePattern(Record *TheRec,
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),
isInputPattern(isInput), HasError(false) {
- Trees.push_back(std::move(Pat));
+ Trees.push_back(Pat);
}
void TreePattern::error(const Twine &Msg) {
@@ -1918,7 +1918,7 @@ void TreePattern::error(const Twine &Msg
void TreePattern::ComputeNamedNodes() {
for (unsigned i = 0, e = Trees.size(); i != e; ++i)
- ComputeNamedNodes(Trees[i].get());
+ ComputeNamedNodes(Trees[i]);
}
void TreePattern::ComputeNamedNodes(TreePatternNode *N) {
@@ -1929,8 +1929,8 @@ void TreePattern::ComputeNamedNodes(Tree
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)) {
Record *R = DI->getDef();
@@ -1944,7 +1944,7 @@ TreePattern::ParseTreePattern(Init *TheI
OpName);
// Input argument?
- auto Res = llvm::make_unique<TreePatternNode>(DI, 1);
+ TreePatternNode *Res = new TreePatternNode(DI, 1);
if (R->getName() == "node" && !OpName.empty()) {
if (OpName.empty())
error("'node' argument requires a name to match with operand list");
@@ -1959,7 +1959,7 @@ TreePattern::ParseTreePattern(Init *TheI
if (TheInit == UnsetInit::get()) {
if (OpName.empty())
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);
Res->setName(OpName);
return Res;
@@ -1968,7 +1968,7 @@ TreePattern::ParseTreePattern(Init *TheI
if (IntInit *II = dyn_cast<IntInit>(TheInit)) {
if (!OpName.empty())
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)) {
@@ -1994,7 +1994,7 @@ TreePattern::ParseTreePattern(Init *TheI
if (Dag->getNumArgs() != 1)
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.
assert(New->getNumTypes() == 1 && "FIXME: Unhandled");
@@ -2044,8 +2044,7 @@ TreePattern::ParseTreePattern(Init *TheI
// Parse all the operands.
for (unsigned i = 0, e = Dag->getNumArgs(); i != e; ++i)
- Children.push_back(
- ParseTreePattern(Dag->getArg(i), Dag->getArgName(i)).release());
+ Children.push_back(ParseTreePattern(Dag->getArg(i), Dag->getArgName(i)));
// If the operator is an intrinsic, then this is just syntactic sugar for for
// (intrinsic_* <number>, ..children..). Pick the right intrinsic node, and
@@ -2090,7 +2089,7 @@ TreePattern::ParseTreePattern(Init *TheI
}
unsigned NumResults = GetNumNodeResults(Operator, CDP);
- auto Result = llvm::make_unique<TreePatternNode>(Operator, Children, NumResults);
+ TreePatternNode *Result = new TreePatternNode(Operator, Children, NumResults);
Result->setName(OpName);
if (!Dag->getName().empty()) {
@@ -2106,7 +2105,7 @@ TreePattern::ParseTreePattern(Init *TheI
/// more type generic things and have useless type casts fold away.
///
/// This returns true if any change is made.
-static bool SimplifyTree(std::unique_ptr<TreePatternNode> &N) {
+static bool SimplifyTree(TreePatternNode *&N) {
if (N->isLeaf())
return false;
@@ -2116,7 +2115,7 @@ static bool SimplifyTree(std::unique_ptr
N->getExtType(0).isConcrete() &&
N->getExtType(0) == N->getChild(0)->getExtType(0) &&
N->getName().empty()) {
- N.reset(N->getChild(0));
+ N = N->getChild(0);
SimplifyTree(N);
return true;
}
@@ -2124,9 +2123,9 @@ static bool SimplifyTree(std::unique_ptr
// Walk all children.
bool MadeChange = false;
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);
- N->setChild(i, Child.release());
+ N->setChild(i, Child);
}
return MadeChange;
}
@@ -2173,7 +2172,7 @@ InferAllTypes(const StringMap<SmallVecto
// changing the type of the input register in this case. This allows
// us to match things like:
// 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());
if (DI && (DI->getDef()->isSubClassOf("RegisterClass") ||
DI->getDef()->isSubClassOf("RegisterOperand")))
@@ -2925,27 +2924,26 @@ const DAGInstruction &CodeGenDAGPatterns
I->error("Input operand $" + InstInputsCheck.begin()->first +
" occurs in pattern but not in operands list!");
- auto ResultPattern = llvm::make_unique<TreePatternNode>(
- I->getRecord(), ResultNodeOperands,
- GetNumNodeResults(I->getRecord(), *this));
-
+ TreePatternNode *ResultPattern =
+ new TreePatternNode(I->getRecord(), ResultNodeOperands,
+ GetNumNodeResults(I->getRecord(), *this));
// Copy fully inferred output node type to instruction result pattern.
for (unsigned i = 0; i != NumResults; ++i)
ResultPattern->setType(i, Res0Node->getExtType(i));
// Create and insert the instruction.
// FIXME: InstImpResults should not be part of DAGInstruction.
- DAGInsts.insert(std::make_pair(
- I->getRecord(), DAGInstruction(I, Results, Operands, InstImpResults)));
+ DAGInstruction TheInst(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
// constructed result is correct. This depends on the instruction already
// 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());
DAGInstruction &TheInsertedInst = DAGInsts.find(I->getRecord())->second;
- TheInsertedInst.setResultPattern(std::move(Temp.getOnlyTree()));
+ TheInsertedInst.setResultPattern(Temp.getOnlyTree());
return TheInsertedInst;
}
@@ -3377,7 +3375,7 @@ void CodeGenDAGPatterns::ParsePatterns()
InstImpResults);
// 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;
for (unsigned ii = 0, ee = DstPattern->getNumChildren(); ii != ee; ++ii) {
TreePatternNode *OpNode = DstPattern->getChild(ii);
@@ -3389,16 +3387,16 @@ void CodeGenDAGPatterns::ParsePatterns()
}
ResultNodeOperands.push_back(OpNode);
}
- if (!DstPattern->isLeaf()) {
- auto NewPattern = llvm::make_unique<TreePatternNode>(
- DstPattern->getOperator(), ResultNodeOperands,
- DstPattern->getNumTypes());
- for (unsigned i = 0, e = DstPattern->getNumTypes(); i != e; ++i)
- NewPattern->setType(i, DstPattern->getExtType(i));
- DstPattern = std::move(NewPattern);
- }
+ DstPattern = Result.getOnlyTree();
+ if (!DstPattern->isLeaf())
+ DstPattern = new TreePatternNode(DstPattern->getOperator(),
+ ResultNodeOperands,
+ DstPattern->getNumTypes());
+
+ for (unsigned i = 0, e = Result.getOnlyTree()->getNumTypes(); i != e; ++i)
+ DstPattern->setType(i, Result.getOnlyTree()->getExtType(i));
- TreePattern Temp(Result.getRecord(), std::move(DstPattern), false, *this);
+ TreePattern Temp(Result.getRecord(), DstPattern, false, *this);
Temp.InferAllTypes();
@@ -3406,7 +3404,7 @@ void CodeGenDAGPatterns::ParsePatterns()
PatternToMatch(CurPattern,
CurPattern->getValueAsListInit("Predicates"),
Pattern->getTree(0),
- Temp.getOnlyTree().release(), InstImpResults,
+ Temp.getOnlyTree(), InstImpResults,
CurPattern->getValueAsInt("AddedComplexity"),
CurPattern->getID()));
}
Modified: llvm/trunk/utils/TableGen/CodeGenDAGPatterns.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/TableGen/CodeGenDAGPatterns.h?rev=222187&r1=222186&r2=222187&view=diff
==============================================================================
--- llvm/trunk/utils/TableGen/CodeGenDAGPatterns.h (original)
+++ llvm/trunk/utils/TableGen/CodeGenDAGPatterns.h Mon Nov 17 16:55:41 2014
@@ -294,7 +294,7 @@ private:
std::string getPredCode() const;
std::string getImmCode() const;
};
-
+
/// 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
@@ -508,7 +508,7 @@ class TreePattern {
/// Trees - The list of pattern trees which corresponds to this pattern.
/// 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
/// pattern.
@@ -548,17 +548,15 @@ public:
CodeGenDAGPatterns &ise);
TreePattern(Record *TheRec, DagInit *Pat, bool isInput,
CodeGenDAGPatterns &ise);
- TreePattern(Record *TheRec, std::unique_ptr<TreePatternNode> Pat,
- bool isInput, CodeGenDAGPatterns &ise);
+ TreePattern(Record *TheRec, TreePatternNode *Pat, bool isInput,
+ CodeGenDAGPatterns &ise);
/// getTrees - Return the tree patterns which corresponds to this pattern.
///
- const std::vector<std::unique_ptr<TreePatternNode>> &getTrees() const {
- return Trees;
- }
+ const std::vector<TreePatternNode*> &getTrees() const { return Trees; }
unsigned getNumTrees() const { return Trees.size(); }
- TreePatternNode *getTree(unsigned i) const { return Trees[i].get(); }
- std::unique_ptr<TreePatternNode> &getOnlyTree() {
+ TreePatternNode *getTree(unsigned i) const { return Trees[i]; }
+ TreePatternNode *getOnlyTree() const {
assert(Trees.size() == 1 && "Doesn't have exactly one pattern!");
return Trees[0];
}
@@ -588,8 +586,7 @@ public:
/// PatFrag references.
void InlinePatternFragments() {
for (unsigned i = 0, e = Trees.size(); i != e; ++i)
- // Can leak, if InlinePatternFragments doesn't return 'this'
- Trees[i].reset(Trees[i].release()->InlinePatternFragments(*this));
+ Trees[i] = Trees[i]->InlinePatternFragments(*this);
}
/// InferAllTypes - Infer/propagate as many types throughout the expression
@@ -612,7 +609,7 @@ public:
void dump() const;
private:
- std::unique_ptr<TreePatternNode> ParseTreePattern(Init *DI, StringRef OpName);
+ TreePatternNode *ParseTreePattern(Init *DI, StringRef OpName);
void ComputeNamedNodes();
void ComputeNamedNodes(TreePatternNode *N);
};
@@ -628,15 +625,14 @@ class DAGInstruction {
std::vector<Record*> Results;
std::vector<Record*> Operands;
std::vector<Record*> ImpResults;
- std::unique_ptr<TreePatternNode> ResultPattern;
-
+ TreePatternNode *ResultPattern;
public:
DAGInstruction(TreePattern *TP,
const std::vector<Record*> &results,
const std::vector<Record*> &operands,
const std::vector<Record*> &impresults)
: Pattern(TP), Results(results), Operands(operands),
- ImpResults(impresults) {}
+ ImpResults(impresults), ResultPattern(nullptr) {}
TreePattern *getPattern() const { return Pattern; }
unsigned getNumResults() const { return Results.size(); }
@@ -644,9 +640,7 @@ public:
unsigned getNumImpResults() const { return ImpResults.size(); }
const std::vector<Record*>& getImpResults() const { return ImpResults; }
- void setResultPattern(std::unique_ptr<TreePatternNode> R) {
- ResultPattern = std::move(R);
- }
+ void setResultPattern(TreePatternNode *R) { ResultPattern = R; }
Record *getResult(unsigned RN) const {
assert(RN < Results.size());
@@ -663,7 +657,7 @@ public:
return ImpResults[RN];
}
- TreePatternNode *getResultPattern() const { return ResultPattern.get(); }
+ TreePatternNode *getResultPattern() const { return ResultPattern; }
};
/// PatternToMatch - Used by CodeGenDAGPatterns to keep tab of patterns
More information about the llvm-commits
mailing list