[llvm-commits] CVS: llvm/lib/Target/TargetData.cpp
Chris Lattner
lattner at cs.uiuc.edu
Sun Mar 13 11:04:54 PST 2005
Changes in directory llvm/lib/Target:
TargetData.cpp updated: 1.54 -> 1.55
---
Log message:
add a StructLayout::getElementContainingOffset method.
---
Diffs of the changes: (+17 -0)
TargetData.cpp | 17 +++++++++++++++++
1 files changed, 17 insertions(+)
Index: llvm/lib/Target/TargetData.cpp
diff -u llvm/lib/Target/TargetData.cpp:1.54 llvm/lib/Target/TargetData.cpp:1.55
--- llvm/lib/Target/TargetData.cpp:1.54 Wed Dec 1 11:14:28 2004
+++ llvm/lib/Target/TargetData.cpp Sun Mar 13 13:04:41 2005
@@ -22,6 +22,7 @@
#include "llvm/Constants.h"
#include "llvm/Support/GetElementPtrTypeIterator.h"
#include "llvm/Support/MathExtras.h"
+#include <algorithm>
using namespace llvm;
// Handle the Pass registration stuff necessary to use TargetData's.
@@ -71,6 +72,22 @@
StructSize = (StructSize/StructAlignment + 1) * StructAlignment;
}
+
+/// getElementContainingOffset - Given a valid offset into the structure,
+/// return the structure index that contains it.
+unsigned StructLayout::getElementContainingOffset(uint64_t Offset) const {
+ std::vector<uint64_t>::const_iterator SI =
+ std::upper_bound(MemberOffsets.begin(), MemberOffsets.end(),
+ Offset);
+ assert(SI != MemberOffsets.begin() && "Offset not in structure type!");
+ --SI;
+ assert(*SI <= Offset && "upper_bound didn't work");
+ assert((SI == MemberOffsets.begin() || *(SI-1) < Offset) &&
+ (SI+1 == MemberOffsets.end() || *(SI+1) > Offset) &&
+ "Upper bound didn't work!");
+ return SI-MemberOffsets.begin();
+}
+
//===----------------------------------------------------------------------===//
// TargetData Class Implementation
//===----------------------------------------------------------------------===//
More information about the llvm-commits
mailing list