diff options
| author | Dan Gohman <gohman@apple.com> | 2010-02-01 16:37:38 +0000 |
|---|---|---|
| committer | Dan Gohman <gohman@apple.com> | 2010-02-01 16:37:38 +0000 |
| commit | ede94e68501ead5d92fb04e9d9fa5c2ec9c3e55c (patch) | |
| tree | 8067c2eeaa078e3d5d7f7087a57f891b0144908a /llvm/lib | |
| parent | aa8c429a5307c729f0c094087f84f42d58f42987 (diff) | |
| download | bcm5719-llvm-ede94e68501ead5d92fb04e9d9fa5c2ec9c3e55c.tar.gz bcm5719-llvm-ede94e68501ead5d92fb04e9d9fa5c2ec9c3e55c.zip | |
Add a generalized form of ConstantExpr::getOffsetOf which works for
array types as well as struct types, and which accepts arbitrary
Constant indicies.
llvm-svn: 94981
Diffstat (limited to 'llvm/lib')
| -rw-r--r-- | llvm/lib/VMCore/Constants.cpp | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/llvm/lib/VMCore/Constants.cpp b/llvm/lib/VMCore/Constants.cpp index 1415944885b..b1c942c214f 100644 --- a/llvm/lib/VMCore/Constants.cpp +++ b/llvm/lib/VMCore/Constants.cpp @@ -1493,16 +1493,21 @@ Constant* ConstantExpr::getAlignOf(const Type* Ty) { } Constant* ConstantExpr::getOffsetOf(const StructType* STy, unsigned FieldNo) { + return getOffsetOf(STy, ConstantInt::get(Type::getInt32Ty(STy->getContext()), + FieldNo)); +} + +Constant* ConstantExpr::getOffsetOf(const Type* Ty, Constant *FieldNo) { // offsetof is implemented as: (i64) gep (Ty*)null, 0, FieldNo // Note that a non-inbounds gep is used, as null isn't within any object. Constant *GEPIdx[] = { - ConstantInt::get(Type::getInt64Ty(STy->getContext()), 0), - ConstantInt::get(Type::getInt32Ty(STy->getContext()), FieldNo) + ConstantInt::get(Type::getInt64Ty(Ty->getContext()), 0), + FieldNo }; Constant *GEP = getGetElementPtr( - Constant::getNullValue(PointerType::getUnqual(STy)), GEPIdx, 2); + Constant::getNullValue(PointerType::getUnqual(Ty)), GEPIdx, 2); return getCast(Instruction::PtrToInt, GEP, - Type::getInt64Ty(STy->getContext())); + Type::getInt64Ty(Ty->getContext())); } Constant *ConstantExpr::getCompare(unsigned short pred, |

