From 430b8a22e2717d3dfb6b4f096bc23c9538fd7959 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Tue, 5 Aug 2008 14:45:15 +0000 Subject: [PATCH] Fix several const-correctness issues, resolving some -Wcast-qual warnings. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@54349 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../SelectionDAG/ScheduleDAGRRList.cpp | 22 +++++++++---------- lib/Support/SmallPtrSet.cpp | 4 ++-- lib/VMCore/Constants.cpp | 3 ++- lib/VMCore/Type.cpp | 4 ++-- 4 files changed, 17 insertions(+), 16 deletions(-) diff --git a/lib/CodeGen/SelectionDAG/ScheduleDAGRRList.cpp b/lib/CodeGen/SelectionDAG/ScheduleDAGRRList.cpp index bd46f8e5505..2665dc8f61f 100644 --- a/lib/CodeGen/SelectionDAG/ScheduleDAGRRList.cpp +++ b/lib/CodeGen/SelectionDAG/ScheduleDAGRRList.cpp @@ -88,7 +88,7 @@ public: void Schedule(); /// IsReachable - Checks if SU is reachable from TargetSU. - bool IsReachable(SUnit *SU, SUnit *TargetSU); + bool IsReachable(const SUnit *SU, const SUnit *TargetSU); /// willCreateCycle - Returns true if adding an edge from SU to TargetSU will /// create a cycle. @@ -155,7 +155,7 @@ private: /// DFS - make a DFS traversal and mark all nodes affected by the /// edge insertion. These nodes will later get new topological indexes /// by means of the Shift method. - void DFS(SUnit *SU, int UpperBound, bool& HasLoop); + void DFS(const SUnit *SU, int UpperBound, bool& HasLoop); /// Shift - reassign topological indexes for the nodes in the DAG /// to preserve the topological ordering. @@ -395,7 +395,7 @@ void ScheduleDAGRRList::UnscheduleNodeBottomUp(SUnit *SU) { } /// IsReachable - Checks if SU is reachable from TargetSU. -bool ScheduleDAGRRList::IsReachable(SUnit *SU, SUnit *TargetSU) { +bool ScheduleDAGRRList::IsReachable(const SUnit *SU, const SUnit *TargetSU) { // If insertion of the edge SU->TargetSU would create a cycle // then there is a path from TargetSU to SU. int UpperBound, LowerBound; @@ -543,8 +543,8 @@ bool ScheduleDAGRRList::RemovePred(SUnit *M, SUnit *N, /// DFS - Make a DFS traversal to mark all nodes reachable from SU and mark /// all nodes affected by the edge insertion. These nodes will later get new /// topological indexes by means of the Shift method. -void ScheduleDAGRRList::DFS(SUnit *SU, int UpperBound, bool& HasLoop) { - std::vector WorkList; +void ScheduleDAGRRList::DFS(const SUnit *SU, int UpperBound, bool& HasLoop) { + std::vector WorkList; WorkList.reserve(SUnits.size()); WorkList.push_back(SU); @@ -1403,7 +1403,7 @@ namespace { class VISIBILITY_HIDDEN BURegReductionPriorityQueue : public RegReductionPriorityQueue { // SUnits - The SUnits for the current graph. - const std::vector *SUnits; + std::vector *SUnits; // SethiUllmanNumbers - The SethiUllman number for each node. std::vector SethiUllmanNumbers; @@ -1692,11 +1692,11 @@ BURegReductionPriorityQueue::canClobber(const SUnit *SU, const SUnit *Op) { /// hasCopyToRegUse - Return true if SU has a value successor that is a /// CopyToReg node. -static bool hasCopyToRegUse(SUnit *SU) { +static bool hasCopyToRegUse(const SUnit *SU) { for (SUnit::const_succ_iterator I = SU->Succs.begin(), E = SU->Succs.end(); I != E; ++I) { if (I->isCtrl) continue; - SUnit *SuccSU = I->Dep; + const SUnit *SuccSU = I->Dep; if (SuccSU->Node && SuccSU->Node->getOpcode() == ISD::CopyToReg) return true; } @@ -1705,7 +1705,7 @@ static bool hasCopyToRegUse(SUnit *SU) { /// canClobberPhysRegDefs - True if SU would clobber one of SuccSU's /// physical register defs. -static bool canClobberPhysRegDefs(SUnit *SuccSU, SUnit *SU, +static bool canClobberPhysRegDefs(const SUnit *SuccSU, const SUnit *SU, const TargetInstrInfo *TII, const TargetRegisterInfo *TRI) { SDNode *N = SuccSU->Node; @@ -1739,7 +1739,7 @@ static bool canClobberPhysRegDefs(SUnit *SuccSU, SUnit *SU, /// commutable, favor the one that's not commutable. void BURegReductionPriorityQueue::AddPseudoTwoAddrDeps() { for (unsigned i = 0, e = SUnits->size(); i != e; ++i) { - SUnit *SU = (SUnit *)&((*SUnits)[i]); + SUnit *SU = &(*SUnits)[i]; if (!SU->isTwoAddress) continue; @@ -1819,7 +1819,7 @@ static unsigned LimitedSumOfUnscheduledPredsOfSuccs(const SUnit *SU, unsigned Sum = 0; for (SUnit::const_succ_iterator I = SU->Succs.begin(), E = SU->Succs.end(); I != E; ++I) { - SUnit *SuccSU = I->Dep; + const SUnit *SuccSU = I->Dep; for (SUnit::const_pred_iterator II = SuccSU->Preds.begin(), EE = SuccSU->Preds.end(); II != EE; ++II) { SUnit *PredSU = II->Dep; diff --git a/lib/Support/SmallPtrSet.cpp b/lib/Support/SmallPtrSet.cpp index 4cbf2cd9e2f..68938fa5a57 100644 --- a/lib/Support/SmallPtrSet.cpp +++ b/lib/Support/SmallPtrSet.cpp @@ -58,13 +58,13 @@ bool SmallPtrSetImpl::insert_imp(const void * Ptr) { Grow(); // Okay, we know we have space. Find a hash bucket. - void **Bucket = const_cast(FindBucketFor((void*)Ptr)); + const void **Bucket = const_cast(FindBucketFor(Ptr)); if (*Bucket == Ptr) return false; // Already inserted, good. // Otherwise, insert it! if (*Bucket == getTombstoneMarker()) --NumTombstones; - *Bucket = (void*)Ptr; + *Bucket = Ptr; ++NumElements; // Track density. return true; } diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp index 8f62a71bbd1..bb8fa655565 100644 --- a/lib/VMCore/Constants.cpp +++ b/lib/VMCore/Constants.cpp @@ -1070,7 +1070,8 @@ private: } typename MapTy::iterator I = - Map.find(MapKey((TypeClass*)CP->getRawType(), getValType(CP))); + Map.find(MapKey(static_cast(CP->getRawType()), + getValType(CP))); if (I == Map.end() || I->second != CP) { // FIXME: This should not use a linear scan. If this gets to be a // performance problem, someone should look at this. diff --git a/lib/VMCore/Type.cpp b/lib/VMCore/Type.cpp index a05f911e83f..b7bf339ab8d 100644 --- a/lib/VMCore/Type.cpp +++ b/lib/VMCore/Type.cpp @@ -84,9 +84,9 @@ void Type::destroy() const { // Now call the destructor for the subclass directly because we're going // to delete this as an array of char. if (isa(this)) - ((FunctionType*)this)->FunctionType::~FunctionType(); + static_cast(this)->FunctionType::~FunctionType(); else - ((StructType*)this)->StructType::~StructType(); + static_cast(this)->StructType::~StructType(); // Finally, remove the memory as an array deallocation of the chars it was // constructed from.