From 4ec82eb1de09451278bd69b12412822193f0a896 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Tue, 12 Oct 2004 04:20:25 +0000 Subject: [PATCH] Implement a new method git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@16927 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/VMCore/Function.cpp | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/lib/VMCore/Function.cpp b/lib/VMCore/Function.cpp index ede2ca20974..4d123b563a1 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(Ptr)) { + if (CE->getOpcode() == Instruction::Cast) { + if (isa(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(Ptr)) { + if (isa(CI->getOperand(0)->getType())) + return StripPointerCasts(CI->getOperand(0)); + } else if (GetElementPtrInst *GEP = dyn_cast(Ptr)) { + for (unsigned i = 1, e = CE->getNumOperands(); i != e; ++i) + if (!isa(CE->getOperand(i)) || + !cast(CE->getOperand(i))->isNullValue()) + return Ptr; + return StripPointerCasts(CE->getOperand(0)); + } + return Ptr; +} // vim: sw=2 ai