Skip to content

Commit

Permalink
[pbqp] Delete some dead code, NFC.
Browse files Browse the repository at this point in the history
I took the opportunity to replace some copy|move constructors|assignment
operators with default implementations.

As a follow-up, I plan on threading unique_ptr<T []> through a few areas
per David Blaikie's advice.

Differential Revision: https://reviews.llvm.org/D24424

llvm-svn: 285018
  • Loading branch information
vedantk committed Oct 24, 2016
1 parent 5d3391f commit 06ca6ea
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 262 deletions.
16 changes: 0 additions & 16 deletions llvm/include/llvm/CodeGen/PBQP/Graph.h
Expand Up @@ -110,29 +110,13 @@ namespace PBQP {
ThisEdgeAdjIdxs[1] = NodeEntry::getInvalidAdjEdgeIdx();
}

void invalidate() {
NIds[0] = NIds[1] = Graph::invalidNodeId();
ThisEdgeAdjIdxs[0] = ThisEdgeAdjIdxs[1] =
NodeEntry::getInvalidAdjEdgeIdx();
Costs = nullptr;
}

void connectToN(Graph &G, EdgeId ThisEdgeId, unsigned NIdx) {
assert(ThisEdgeAdjIdxs[NIdx] == NodeEntry::getInvalidAdjEdgeIdx() &&
"Edge already connected to NIds[NIdx].");
NodeEntry &N = G.getNode(NIds[NIdx]);
ThisEdgeAdjIdxs[NIdx] = N.addAdjEdgeId(ThisEdgeId);
}

void connectTo(Graph &G, EdgeId ThisEdgeId, NodeId NId) {
if (NId == NIds[0])
connectToN(G, ThisEdgeId, 0);
else {
assert(NId == NIds[1] && "Edge does not connect NId.");
connectToN(G, ThisEdgeId, 1);
}
}

void connect(Graph &G, EdgeId ThisEdgeId) {
connectToN(G, ThisEdgeId, 0);
connectToN(G, ThisEdgeId, 1);
Expand Down
143 changes: 2 additions & 141 deletions llvm/include/llvm/CodeGen/PBQP/Math.h
Expand Up @@ -27,25 +27,17 @@ class Vector {

/// \brief Construct a PBQP vector of the given size.
explicit Vector(unsigned Length)
: Length(Length), Data(new PBQPNum[Length]) {
// llvm::dbgs() << "Constructing PBQP::Vector "
// << this << " (length " << Length << ")\n";
}
: Length(Length), Data(new PBQPNum[Length]) {}

/// \brief Construct a PBQP vector with initializer.
Vector(unsigned Length, PBQPNum InitVal)
: Length(Length), Data(new PBQPNum[Length]) {
// llvm::dbgs() << "Constructing PBQP::Vector "
// << this << " (length " << Length << ", fill "
// << InitVal << ")\n";
std::fill(Data, Data + Length, InitVal);
}

/// \brief Copy construct a PBQP vector.
Vector(const Vector &V)
: Length(V.Length), Data(new PBQPNum[Length]) {
// llvm::dbgs() << "Copy-constructing PBQP::Vector " << this
// << " from PBQP::Vector " << &V << "\n";
std::copy(V.Data, V.Data + Length, Data);
}

Expand All @@ -57,31 +49,7 @@ class Vector {
}

/// \brief Destroy this vector, return its memory.
~Vector() {
// llvm::dbgs() << "Deleting PBQP::Vector " << this << "\n";
delete[] Data;
}

/// \brief Copy-assignment operator.
Vector& operator=(const Vector &V) {
// llvm::dbgs() << "Assigning to PBQP::Vector " << this
// << " from PBQP::Vector " << &V << "\n";
delete[] Data;
Length = V.Length;
Data = new PBQPNum[Length];
std::copy(V.Data, V.Data + Length, Data);
return *this;
}

/// \brief Move-assignment operator.
Vector& operator=(Vector &&V) {
delete[] Data;
Length = V.Length;
Data = V.Data;
V.Length = 0;
V.Data = nullptr;
return *this;
}
~Vector() { delete[] Data; }

/// \brief Comparison operator.
bool operator==(const Vector &V) const {
Expand Down Expand Up @@ -119,14 +87,6 @@ class Vector {
return *this;
}

/// \brief Subtract another vector from this one.
Vector& operator-=(const Vector &V) {
assert(Length != 0 && Data != nullptr && "Invalid vector");
assert(Length == V.Length && "Vector length mismatch.");
std::transform(Data, Data + Length, V.Data, Data, std::minus<PBQPNum>());
return *this;
}

/// \brief Returns the index of the minimum value in this vector
unsigned minIndex() const {
assert(Length != 0 && Data != nullptr && "Invalid vector");
Expand Down Expand Up @@ -193,26 +153,6 @@ class Matrix {
/// \brief Destroy this matrix, return its memory.
~Matrix() { delete[] Data; }

/// \brief Copy-assignment operator.
Matrix& operator=(const Matrix &M) {
delete[] Data;
Rows = M.Rows; Cols = M.Cols;
Data = new PBQPNum[Rows * Cols];
std::copy(M.Data, M.Data + (Rows * Cols), Data);
return *this;
}

/// \brief Move-assignment operator.
Matrix& operator=(Matrix &&M) {
delete[] Data;
Rows = M.Rows;
Cols = M.Cols;
Data = M.Data;
M.Rows = M.Cols = 0;
M.Data = nullptr;
return *this;
}

/// \brief Comparison operator.
bool operator==(const Matrix &M) const {
assert(Rows != 0 && Cols != 0 && Data != nullptr && "Invalid matrix");
Expand Down Expand Up @@ -265,30 +205,6 @@ class Matrix {
return V;
}

/// \brief Reset the matrix to the given value.
Matrix& reset(PBQPNum Val = 0) {
assert(Rows != 0 && Cols != 0 && Data != nullptr && "Invalid matrix");
std::fill(Data, Data + (Rows * Cols), Val);
return *this;
}

/// \brief Set a single row of this matrix to the given value.
Matrix& setRow(unsigned R, PBQPNum Val) {
assert(Rows != 0 && Cols != 0 && Data != nullptr && "Invalid matrix");
assert(R < Rows && "Row out of bounds.");
std::fill(Data + (R * Cols), Data + ((R + 1) * Cols), Val);
return *this;
}

/// \brief Set a single column of this matrix to the given value.
Matrix& setCol(unsigned C, PBQPNum Val) {
assert(Rows != 0 && Cols != 0 && Data != nullptr && "Invalid matrix");
assert(C < Cols && "Column out of bounds.");
for (unsigned R = 0; R < Rows; ++R)
(*this)[R][C] = Val;
return *this;
}

/// \brief Matrix transpose.
Matrix transpose() const {
assert(Rows != 0 && Cols != 0 && Data != nullptr && "Invalid matrix");
Expand All @@ -299,18 +215,6 @@ class Matrix {
return M;
}

/// \brief Returns the diagonal of the matrix as a vector.
///
/// Matrix must be square.
Vector diagonalize() const {
assert(Rows != 0 && Cols != 0 && Data != nullptr && "Invalid matrix");
assert(Rows == Cols && "Attempt to diagonalize non-square matrix.");
Vector V(Rows);
for (unsigned r = 0; r < Rows; ++r)
V[r] = (*this)[r][r];
return V;
}

/// \brief Add the given matrix to this one.
Matrix& operator+=(const Matrix &M) {
assert(Rows != 0 && Cols != 0 && Data != nullptr && "Invalid matrix");
Expand All @@ -328,49 +232,6 @@ class Matrix {
return Tmp;
}

/// \brief Returns the minimum of the given row
PBQPNum getRowMin(unsigned R) const {
assert(Rows != 0 && Cols != 0 && Data != nullptr && "Invalid matrix");
assert(R < Rows && "Row out of bounds");
return *std::min_element(Data + (R * Cols), Data + ((R + 1) * Cols));
}

/// \brief Returns the minimum of the given column
PBQPNum getColMin(unsigned C) const {
assert(Rows != 0 && Cols != 0 && Data != nullptr && "Invalid matrix");
PBQPNum MinElem = (*this)[0][C];
for (unsigned R = 1; R < Rows; ++R)
if ((*this)[R][C] < MinElem)
MinElem = (*this)[R][C];
return MinElem;
}

/// \brief Subtracts the given scalar from the elements of the given row.
Matrix& subFromRow(unsigned R, PBQPNum Val) {
assert(Rows != 0 && Cols != 0 && Data != nullptr && "Invalid matrix");
assert(R < Rows && "Row out of bounds");
std::transform(Data + (R * Cols), Data + ((R + 1) * Cols),
Data + (R * Cols),
std::bind2nd(std::minus<PBQPNum>(), Val));
return *this;
}

/// \brief Subtracts the given scalar from the elements of the given column.
Matrix& subFromCol(unsigned C, PBQPNum Val) {
assert(Rows != 0 && Cols != 0 && Data != nullptr && "Invalid matrix");
for (unsigned R = 0; R < Rows; ++R)
(*this)[R][C] -= Val;
return *this;
}

/// \brief Returns true if this is a zero matrix.
bool isZero() const {
assert(Rows != 0 && Cols != 0 && Data != nullptr && "Invalid matrix");
return find_if(Data, Data + (Rows * Cols),
std::bind2nd(std::not_equal_to<PBQPNum>(), 0)) ==
Data + (Rows * Cols);
}

private:
unsigned Rows, Cols;
PBQPNum *Data;
Expand Down
32 changes: 0 additions & 32 deletions llvm/include/llvm/CodeGen/PBQP/Solution.h
Expand Up @@ -38,38 +38,6 @@ namespace PBQP {
Solution()
: r0Reductions(0), r1Reductions(0), r2Reductions(0), rNReductions(0) {}

/// \brief Number of nodes for which selections have been made.
/// @return Number of nodes for which selections have been made.
unsigned numNodes() const { return selections.size(); }

/// \brief Records a reduction via the R0 rule. Should be called from the
/// solver only.
void recordR0() { ++r0Reductions; }

/// \brief Returns the number of R0 reductions applied to solve the problem.
unsigned numR0Reductions() const { return r0Reductions; }

/// \brief Records a reduction via the R1 rule. Should be called from the
/// solver only.
void recordR1() { ++r1Reductions; }

/// \brief Returns the number of R1 reductions applied to solve the problem.
unsigned numR1Reductions() const { return r1Reductions; }

/// \brief Records a reduction via the R2 rule. Should be called from the
/// solver only.
void recordR2() { ++r2Reductions; }

/// \brief Returns the number of R2 reductions applied to solve the problem.
unsigned numR2Reductions() const { return r2Reductions; }

/// \brief Records a reduction via the RN rule. Should be called from the
/// solver only.
void recordRN() { ++ rNReductions; }

/// \brief Returns the number of RN reductions applied to solve the problem.
unsigned numRNReductions() const { return rNReductions; }

/// \brief Set the selection for a given node.
/// @param nodeId Node id.
/// @param selection Selection for nodeId.
Expand Down
76 changes: 3 additions & 73 deletions llvm/include/llvm/CodeGen/RegAllocPBQP.h
Expand Up @@ -89,26 +89,7 @@ class AllowedRegVector {
std::copy(OptVec.begin(), OptVec.end(), Opts.get());
}

AllowedRegVector(const AllowedRegVector &Other)
: NumOpts(Other.NumOpts), Opts(new unsigned[NumOpts]) {
std::copy(Other.Opts.get(), Other.Opts.get() + NumOpts, Opts.get());
}

AllowedRegVector(AllowedRegVector &&Other)
: NumOpts(std::move(Other.NumOpts)), Opts(std::move(Other.Opts)) {}

AllowedRegVector& operator=(const AllowedRegVector &Other) {
NumOpts = Other.NumOpts;
Opts.reset(new unsigned[NumOpts]);
std::copy(Other.Opts.get(), Other.Opts.get() + NumOpts, Opts.get());
return *this;
}

AllowedRegVector& operator=(AllowedRegVector &&Other) {
NumOpts = std::move(Other.NumOpts);
Opts = std::move(Other.Opts);
return *this;
}
AllowedRegVector(AllowedRegVector &&) = default;

unsigned size() const { return NumOpts; }
unsigned operator[](size_t I) const { return Opts[I]; }
Expand Down Expand Up @@ -163,10 +144,6 @@ class GraphMetadata {
return VRegItr->second;
}

void eraseNodeIdForVReg(unsigned VReg) {
VRegToNodeId.erase(VReg);
}

AllowedRegVecRef getAllowedRegs(AllowedRegVector Allowed) {
return AllowedRegVecs.getValue(std::move(Allowed));
}
Expand Down Expand Up @@ -199,8 +176,6 @@ class NodeMetadata {
#endif
{}

// FIXME: Re-implementing default behavior to work around MSVC. Remove once
// MSVC synthesizes move constructors properly.
NodeMetadata(const NodeMetadata &Other)
: RS(Other.RS), NumOpts(Other.NumOpts), DeniedOpts(Other.DeniedOpts),
OptUnsafeEdges(new unsigned[NumOpts]), VReg(Other.VReg),
Expand All @@ -215,48 +190,9 @@ class NodeMetadata {
}
}

// FIXME: Re-implementing default behavior to work around MSVC. Remove once
// MSVC synthesizes move constructors properly.
NodeMetadata(NodeMetadata &&Other)
: RS(Other.RS), NumOpts(Other.NumOpts), DeniedOpts(Other.DeniedOpts),
OptUnsafeEdges(std::move(Other.OptUnsafeEdges)), VReg(Other.VReg),
AllowedRegs(std::move(Other.AllowedRegs))
#ifndef NDEBUG
, everConservativelyAllocatable(Other.everConservativelyAllocatable)
#endif
{}

// FIXME: Re-implementing default behavior to work around MSVC. Remove once
// MSVC synthesizes move constructors properly.
NodeMetadata& operator=(const NodeMetadata &Other) {
RS = Other.RS;
NumOpts = Other.NumOpts;
DeniedOpts = Other.DeniedOpts;
OptUnsafeEdges.reset(new unsigned[NumOpts]);
std::copy(Other.OptUnsafeEdges.get(), Other.OptUnsafeEdges.get() + NumOpts,
OptUnsafeEdges.get());
VReg = Other.VReg;
AllowedRegs = Other.AllowedRegs;
#ifndef NDEBUG
everConservativelyAllocatable = Other.everConservativelyAllocatable;
#endif
return *this;
}
NodeMetadata(NodeMetadata &&Other) = default;

// FIXME: Re-implementing default behavior to work around MSVC. Remove once
// MSVC synthesizes move constructors properly.
NodeMetadata& operator=(NodeMetadata &&Other) {
RS = Other.RS;
NumOpts = Other.NumOpts;
DeniedOpts = Other.DeniedOpts;
OptUnsafeEdges = std::move(Other.OptUnsafeEdges);
VReg = Other.VReg;
AllowedRegs = std::move(Other.AllowedRegs);
#ifndef NDEBUG
everConservativelyAllocatable = Other.everConservativelyAllocatable;
#endif
return *this;
}
NodeMetadata& operator=(NodeMetadata &&Other) = default;

void setVReg(unsigned VReg) { this->VReg = VReg; }
unsigned getVReg() const { return VReg; }
Expand Down Expand Up @@ -284,7 +220,6 @@ class NodeMetadata {
#endif
}


void handleAddEdge(const MatrixMetadata& MD, bool Transpose) {
DeniedOpts += Transpose ? MD.getWorstRow() : MD.getWorstCol();
const bool* UnsafeOpts =
Expand Down Expand Up @@ -369,11 +304,6 @@ class RegAllocSolverImpl {
handleReconnectEdge(EId, G.getEdgeNode2Id(EId));
}

void handleRemoveEdge(EdgeId EId) {
handleDisconnectEdge(EId, G.getEdgeNode1Id(EId));
handleDisconnectEdge(EId, G.getEdgeNode2Id(EId));
}

void handleDisconnectEdge(EdgeId EId, NodeId NId) {
NodeMetadata& NMd = G.getNodeMetadata(NId);
const MatrixMetadata& MMd = G.getEdgeCosts(EId).getMetadata();
Expand Down

0 comments on commit 06ca6ea

Please sign in to comment.