diff options
author | Chris Lattner <sabre@nondot.org> | 2004-10-12 04:20:25 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2004-10-12 04:20:25 +0000 |
commit | 4ec82eb1de09451278bd69b12412822193f0a896 (patch) | |
tree | 78f61d978fb940d5f231cd8a3ba88cfc909ca10f /lib/VMCore | |
parent | 673e02b0c37e7a7fa6ffc67bc5e4813a3ce2806d (diff) | |
download | external_llvm-4ec82eb1de09451278bd69b12412822193f0a896.zip external_llvm-4ec82eb1de09451278bd69b12412822193f0a896.tar.gz external_llvm-4ec82eb1de09451278bd69b12412822193f0a896.tar.bz2 |
Implement a new method
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@16927 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore')
-rw-r--r-- | lib/VMCore/Function.cpp | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/lib/VMCore/Function.cpp b/lib/VMCore/Function.cpp index ede2ca2..4d123b5 100644 --- a/lib/VMCore/Function.cpp +++ b/lib/VMCore/Function.cpp @@ -13,10 +13,8 @@ //===----------------------------------------------------------------------===// #include "llvm/Module.h" -#include "llvm/Constant.h" #include "llvm/DerivedTypes.h" -#include "llvm/Instructions.h" -#include "llvm/Intrinsics.h" +#include "llvm/IntrinsicInst.h" #include "llvm/Support/LeakDetector.h" #include "SymbolTableListTraitsImpl.h" using namespace llvm; @@ -265,5 +263,31 @@ unsigned Function::getIntrinsicID() const { return 0; } +Value *MemIntrinsic::StripPointerCasts(Value *Ptr) { + if (ConstantExpr *CE = dyn_cast<ConstantExpr>(Ptr)) { + if (CE->getOpcode() == Instruction::Cast) { + if (isa<PointerType>(CE->getOperand(0)->getType())) + return StripPointerCasts(CE->getOperand(0)); + } else if (CE->getOpcode() == Instruction::GetElementPtr) { + for (unsigned i = 1, e = CE->getNumOperands(); i != e; ++i) + if (!CE->getOperand(i)->isNullValue()) + return Ptr; + return StripPointerCasts(CE->getOperand(0)); + } + return Ptr; + } + + if (CastInst *CI = dyn_cast<CastInst>(Ptr)) { + if (isa<PointerType>(CI->getOperand(0)->getType())) + return StripPointerCasts(CI->getOperand(0)); + } else if (GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(Ptr)) { + for (unsigned i = 1, e = CE->getNumOperands(); i != e; ++i) + if (!isa<Constant>(CE->getOperand(i)) || + !cast<Constant>(CE->getOperand(i))->isNullValue()) + return Ptr; + return StripPointerCasts(CE->getOperand(0)); + } + return Ptr; +} // vim: sw=2 ai |