aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2008-06-20 00:53:00 +0000
committerDan Gohman <gohman@apple.com>2008-06-20 00:53:00 +0000
commitb23f4f1131c7009cbfe647e0c0be43da582d9a19 (patch)
tree0333b7a3f57f4cc4931b8adcafe97d1ff5be4c29 /lib
parent2d85b4bfe6b2725fcc0ad49bd81bd54a29240b84 (diff)
downloadexternal_llvm-b23f4f1131c7009cbfe647e0c0be43da582d9a19.zip
external_llvm-b23f4f1131c7009cbfe647e0c0be43da582d9a19.tar.gz
external_llvm-b23f4f1131c7009cbfe647e0c0be43da582d9a19.tar.bz2
Simplify the ComputeLinearIndex logic and fix a few bugs.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@52516 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp26
1 files changed, 10 insertions, 16 deletions
diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp b/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
index e55552f..85a42d4 100644
--- a/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
+++ b/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
@@ -100,37 +100,31 @@ static unsigned ComputeLinearIndex(const TargetLowering &TLI, const Type *Ty,
const unsigned *IndicesEnd,
unsigned CurIndex = 0) {
// Base case: We're done.
- if (Indices == IndicesEnd)
+ if (Indices && Indices == IndicesEnd)
return CurIndex;
- // Otherwise we need to recurse. A non-negative value is used to
- // indicate the final result value; a negative value carries the
- // complemented position to continue the search.
- CurIndex = ~CurIndex;
-
// Given a struct type, recursively traverse the elements.
if (const StructType *STy = dyn_cast<StructType>(Ty)) {
- for (StructType::element_iterator EI = STy->element_begin(),
+ for (StructType::element_iterator EB = STy->element_begin(),
+ EI = EB,
EE = STy->element_end();
EI != EE; ++EI) {
- CurIndex = ComputeLinearIndex(TLI, *EI, Indices+1, IndicesEnd,
- ~CurIndex);
- if ((int)CurIndex >= 0)
- return CurIndex;
+ if (Indices && *Indices == unsigned(EI - EB))
+ return ComputeLinearIndex(TLI, *EI, Indices+1, IndicesEnd, CurIndex);
+ CurIndex = ComputeLinearIndex(TLI, *EI, 0, 0, CurIndex);
}
}
// Given an array type, recursively traverse the elements.
else if (const ArrayType *ATy = dyn_cast<ArrayType>(Ty)) {
const Type *EltTy = ATy->getElementType();
for (unsigned i = 0, e = ATy->getNumElements(); i != e; ++i) {
- CurIndex = ComputeLinearIndex(TLI, EltTy, Indices+1, IndicesEnd,
- ~CurIndex);
- if ((int)CurIndex >= 0)
- return CurIndex;
+ if (Indices && *Indices == i)
+ return ComputeLinearIndex(TLI, EltTy, Indices+1, IndicesEnd, CurIndex);
+ CurIndex = ComputeLinearIndex(TLI, EltTy, 0, 0, CurIndex);
}
}
// We haven't found the type we're looking for, so keep searching.
- return CurIndex;
+ return CurIndex + 1;
}
/// ComputeValueVTs - Given an LLVM IR type, compute a sequence of