summaryrefslogtreecommitdiff
path: root/include/llvm/IR/Value.h
diff options
context:
space:
mode:
authorChandler Carruth <chandlerc@gmail.com>2013-08-22 11:25:11 +0000
committerChandler Carruth <chandlerc@gmail.com>2013-08-22 11:25:11 +0000
commitf73826bef09fcc38d2db7b69baf0b8a45c9788f8 (patch)
treee753a61c30eb9246f6cdd6a467573e35e628120f /include/llvm/IR/Value.h
parent4efbeb2700506fa1cbbca5e487b57eaad05c60ed (diff)
downloadllvm-f73826bef09fcc38d2db7b69baf0b8a45c9788f8.tar.gz
llvm-f73826bef09fcc38d2db7b69baf0b8a45c9788f8.tar.bz2
llvm-f73826bef09fcc38d2db7b69baf0b8a45c9788f8.tar.xz
Add a new helper method to Value to strip in-bounds constant offsets of
pointers, but accumulate the offset into an APInt in the process of stripping it. This is a pretty handy thing to have, such as when trying to determine if two pointers are at some constant relative offset. I'll be committing a patch shortly to use it for exactly that purpose. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@189000 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/IR/Value.h')
-rw-r--r--include/llvm/IR/Value.h43
1 files changed, 31 insertions, 12 deletions
diff --git a/include/llvm/IR/Value.h b/include/llvm/IR/Value.h
index e667b87f03..e1361fef35 100644
--- a/include/llvm/IR/Value.h
+++ b/include/llvm/IR/Value.h
@@ -22,26 +22,29 @@
namespace llvm {
-class Constant;
+class APInt;
class Argument;
-class Instruction;
+class AssemblyAnnotationWriter;
class BasicBlock;
-class GlobalValue;
+class Constant;
+class DataLayout;
class Function;
-class GlobalVariable;
class GlobalAlias;
+class GlobalValue;
+class GlobalVariable;
class InlineAsm;
-class ValueSymbolTable;
-template<typename ValueTy> class StringMapEntry;
-typedef StringMapEntry<Value*> ValueName;
-class raw_ostream;
-class AssemblyAnnotationWriter;
-class ValueHandleBase;
+class Instruction;
class LLVMContext;
-class Twine;
class MDNode;
-class Type;
class StringRef;
+class Twine;
+class Type;
+class ValueHandleBase;
+class ValueSymbolTable;
+class raw_ostream;
+
+template<typename ValueTy> class StringMapEntry;
+typedef StringMapEntry<Value*> ValueName;
//===----------------------------------------------------------------------===//
// Value Class
@@ -287,6 +290,22 @@ public:
return const_cast<Value*>(this)->stripInBoundsConstantOffsets();
}
+ /// \brief Strips like \c stripInBoundsConstantOffsets but also accumulates
+ /// the constant offset stripped.
+ ///
+ /// Stores the resulting constant offset stripped into the APInt provided.
+ /// The provided APInt will be extended or truncated as needed to be the
+ /// correct bitwidth for an offset of this pointer type.
+ ///
+ /// If this is called on a non-pointer value, it returns 'this'.
+ Value *stripAndAccumulateInBoundsConstantOffsets(const DataLayout &DL,
+ APInt &Offset);
+ const Value *stripAndAccumulateInBoundsConstantOffsets(const DataLayout &DL,
+ APInt &Offset) const {
+ return const_cast<Value *>(this)
+ ->stripAndAccumulateInBoundsConstantOffsets(DL, Offset);
+ }
+
/// \brief Strips off unneeded pointer casts and any in-bounds offsets from
/// the specified value, returning the original pointer value.
///