[PATCH] D24112: [SelectionDAGBuilder] Add const to relevant places
Aditya Kumar via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 31 17:24:18 PDT 2016
hiraditya created this revision.
hiraditya added reviewers: hans, evandro, sebpop.
hiraditya added a subscriber: llvm-commits.
https://reviews.llvm.org/D24112
Files:
lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h
Index: lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h
===================================================================
--- lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h
+++ lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h
@@ -305,12 +305,13 @@
};
/// Check whether a range of clusters is dense enough for a jump table.
- bool isDense(const CaseClusterVector &Clusters, unsigned *TotalCases,
- unsigned First, unsigned Last, unsigned MinDensity);
+ bool isDense(const CaseClusterVector &Clusters,
+ const SmallVectorImpl<unsigned> &TotalCases,
+ unsigned First, unsigned Last, unsigned MinDensity) const;
/// Build a jump table cluster from Clusters[First..Last]. Returns false if it
/// decides it's not a good idea.
- bool buildJumpTable(CaseClusterVector &Clusters, unsigned First,
+ bool buildJumpTable(const CaseClusterVector &Clusters, unsigned First,
unsigned Last, const SwitchInst *SI,
MachineBasicBlock *DefaultMBB, CaseCluster &JTCluster);
Index: lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
===================================================================
--- lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
+++ lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
@@ -8318,14 +8318,14 @@
}
bool SelectionDAGBuilder::isDense(const CaseClusterVector &Clusters,
- unsigned *TotalCases, unsigned First,
- unsigned Last,
- unsigned Density) {
+ const SmallVectorImpl<unsigned> &TotalCases,
+ unsigned First, unsigned Last,
+ unsigned Density) const {
assert(Last >= First);
assert(TotalCases[Last] >= TotalCases[First]);
- APInt LowCase = Clusters[First].Low->getValue();
- APInt HighCase = Clusters[Last].High->getValue();
+ const APInt &LowCase = Clusters[First].Low->getValue();
+ const APInt &HighCase = Clusters[Last].High->getValue();
assert(LowCase.getBitWidth() == HighCase.getBitWidth());
// FIXME: A range of consecutive cases has 100% density, but only requires one
@@ -8354,7 +8354,7 @@
TLI.isOperationLegalOrCustom(ISD::BRIND, MVT::Other);
}
-bool SelectionDAGBuilder::buildJumpTable(CaseClusterVector &Clusters,
+bool SelectionDAGBuilder::buildJumpTable(const CaseClusterVector &Clusters,
unsigned First, unsigned Last,
const SwitchInst *SI,
MachineBasicBlock *DefaultMBB,
@@ -8373,12 +8373,12 @@
for (unsigned I = First; I <= Last; ++I) {
assert(Clusters[I].Kind == CC_Range);
Prob += Clusters[I].Prob;
- APInt Low = Clusters[I].Low->getValue();
- APInt High = Clusters[I].High->getValue();
+ const APInt &Low = Clusters[I].Low->getValue();
+ const APInt &High = Clusters[I].High->getValue();
NumCmps += (Low == High) ? 1 : 2;
if (I != First) {
// Fill the gap between this and the previous cluster.
- APInt PreviousHigh = Clusters[I - 1].High->getValue();
+ const APInt &PreviousHigh = Clusters[I - 1].High->getValue();
assert(PreviousHigh.slt(Low));
uint64_t Gap = (Low - PreviousHigh).getLimitedValue() - 1;
for (uint64_t J = 0; J < Gap; J++)
@@ -8453,8 +8453,8 @@
SmallVector<unsigned, 8> TotalCases(N);
for (unsigned i = 0; i < N; ++i) {
- APInt Hi = Clusters[i].High->getValue();
- APInt Lo = Clusters[i].Low->getValue();
+ const APInt &Hi = Clusters[i].High->getValue();
+ const APInt &Lo = Clusters[i].Low->getValue();
TotalCases[i] = (Hi - Lo).getLimitedValue() + 1;
if (i != 0)
TotalCases[i] += TotalCases[i - 1];
@@ -8464,7 +8464,7 @@
if (DefaultMBB->getParent()->getFunction()->optForSize())
MinDensity = OptsizeJumpTableDensity;
if (N >= MinJumpTableSize
- && isDense(Clusters, &TotalCases[0], 0, N - 1, MinDensity)) {
+ && isDense(Clusters, TotalCases, 0, N - 1, MinDensity)) {
// Cheap case: the whole range might be suitable for jump table.
CaseCluster JTCluster;
if (buildJumpTable(Clusters, 0, N - 1, SI, DefaultMBB, JTCluster)) {
@@ -8509,7 +8509,7 @@
// Search for a solution that results in fewer partitions.
for (int64_t j = N - 1; j > i; j--) {
// Try building a partition from Clusters[i..j].
- if (isDense(Clusters, &TotalCases[0], i, j, MinDensity)) {
+ if (isDense(Clusters, TotalCases, i, j, MinDensity)) {
unsigned NumPartitions = 1 + (j == N - 1 ? 0 : MinPartitions[j + 1]);
bool IsTable = j - i + 1 >= MinJumpTableSize;
unsigned Tables = IsTable + (j == N - 1 ? 0 : NumTables[j + 1]);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D24112.69931.patch
Type: text/x-patch
Size: 4815 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160901/5bf2e013/attachment.bin>
More information about the llvm-commits
mailing list