Make StripPointerCast a common function (should we mak it method of Value instead?)
authorAnton Korobeynikov <asl@math.spbu.ru>
Tue, 6 May 2008 22:52:30 +0000 (22:52 +0000)
committerAnton Korobeynikov <asl@math.spbu.ru>
Tue, 6 May 2008 22:52:30 +0000 (22:52 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@50775 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/IntrinsicInst.h
include/llvm/Value.h
lib/CodeGen/Collector.cpp
lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
lib/CodeGen/ShadowStackCollector.cpp
lib/Transforms/Scalar/InstructionCombining.cpp
lib/VMCore/Function.cpp
lib/VMCore/Value.cpp
lib/VMCore/Verifier.cpp

index d3a53168f1930e880f992b67b8f001f7a05b9025..494eaaec4de99cca2eeca36d767b9ab6ce0d539f 100644 (file)
@@ -38,12 +38,6 @@ namespace llvm {
     IntrinsicInst(const IntrinsicInst&);  // DO NOT IMPLEMENT
     void operator=(const IntrinsicInst&); // DO NOT IMPLEMENT
   public:
-
-    /// StripPointerCasts - This static method strips off any unneeded pointer
-    /// casts from the specified value, returning the original uncasted value.
-    /// Note that the returned value is guaranteed to have pointer type.
-    static Value *StripPointerCasts(Value *Ptr);
-    
     /// getIntrinsicID - Return the intrinsic ID of this intrinsic.
     ///
     Intrinsic::ID getIntrinsicID() const {
index c1c728270e4c53de1d12590ee95ee1298ba8eff1..e3e64749598d64baafabfcb46093f4318eb456f3 100644 (file)
@@ -272,6 +272,11 @@ template <> inline bool isa_impl<GlobalValue, Value>(const Value &Val) {
   return isa<GlobalVariable>(Val) || isa<Function>(Val) || isa<GlobalAlias>(Val);
 }
 
+/// StripPointerCasts - This function strips off any unneeded pointer
+/// casts from the specified value, returning the original uncasted value.
+/// Note that the returned value is guaranteed to have pointer type.
+Value *StripPointerCasts(Value *Ptr);
+
 } // End llvm namespace
 
 #endif
index fe5119ea2db6ba1db0c7318aa339b3292f5d0873..07869a0ff553ed962b82cf56973bdff55300e6f7 100644 (file)
@@ -178,8 +178,8 @@ bool LowerIntrinsics::InsertRootInitializers(Function &F, AllocaInst **Roots,
   SmallPtrSet<AllocaInst*,16> InitedRoots;
   for (; !CouldBecomeSafePoint(IP); ++IP)
     if (StoreInst *SI = dyn_cast<StoreInst>(IP))
-      if (AllocaInst *AI = dyn_cast<AllocaInst>(
-            IntrinsicInst::StripPointerCasts(SI->getOperand(1))))
+      if (AllocaInst *AI =
+          dyn_cast<AllocaInst>(StripPointerCasts(SI->getOperand(1))))
         InitedRoots.insert(AI);
   
   // Add root initializers.
@@ -294,7 +294,7 @@ bool LowerIntrinsics::PerformDefaultLowering(Function &F, Collector &Coll) {
             // Initialize the GC root, but do not delete the intrinsic. The
             // backend needs the intrinsic to flag the stack slot.
             Roots.push_back(cast<AllocaInst>(
-              IntrinsicInst::StripPointerCasts(CI->getOperand(1))));
+                              StripPointerCasts(CI->getOperand(1))));
           }
           break;
         default:
index 8c606b886b687c4498102320639ec364862f5efe..ea047e683f5b1ab8962643cb0d4d9dd74a6a07af 100644 (file)
@@ -2712,7 +2712,7 @@ void SelectionDAGLowering::visitTargetIntrinsic(CallInst &I,
 
 /// ExtractTypeInfo - Returns the type info, possibly bitcast, encoded in V.
 static GlobalVariable *ExtractTypeInfo (Value *V) {
-  V = IntrinsicInst::StripPointerCasts(V);
+  V = StripPointerCasts(V);
   GlobalVariable *GV = dyn_cast<GlobalVariable>(V);
   assert ((GV || isa<ConstantPointerNull>(V)) &&
           "TypeInfo must be a global variable or NULL");
@@ -3150,8 +3150,7 @@ SelectionDAGLowering::visitIntrinsicCall(CallInst &I, unsigned Intrinsic) {
     return 0;
 
   case Intrinsic::init_trampoline: {
-    const Function *F =
-      cast<Function>(IntrinsicInst::StripPointerCasts(I.getOperand(2)));
+    const Function *F = cast<Function>(StripPointerCasts(I.getOperand(2)));
 
     SDOperand Ops[6];
     Ops[0] = getRoot();
index d41e83c712de7f6ad47f69dbc0f44f4501d7518e..121dfc24077301d894d53eda2ee7a66f50a58601 100644 (file)
@@ -325,8 +325,7 @@ void ShadowStackCollector::CollectRoots(Function &F) {
         if (Function *F = CI->getCalledFunction())
           if (F->getIntrinsicID() == Intrinsic::gcroot) {
             std::pair<CallInst*,AllocaInst*> Pair = std::make_pair(
-              CI, cast<AllocaInst>(
-                    IntrinsicInst::StripPointerCasts(CI->getOperand(1))));
+              CI, cast<AllocaInst>(StripPointerCasts(CI->getOperand(1))));
             if (IsNullValue(CI->getOperand(2)))
               Roots.push_back(Pair);
             else
index de29efa497d23789c544d69c718f1dd3446ec230..2afa6c51622c236f383a3eaa574138933a085654 100644 (file)
@@ -9131,8 +9131,7 @@ Instruction *InstCombiner::transformCallThroughTrampoline(CallSite CS) {
   IntrinsicInst *Tramp =
     cast<IntrinsicInst>(cast<BitCastInst>(Callee)->getOperand(0));
 
-  Function *NestF =
-    cast<Function>(IntrinsicInst::StripPointerCasts(Tramp->getOperand(2)));
+  Function *NestF = cast<Function>(StripPointerCasts(Tramp->getOperand(2)));
   const PointerType *NestFPTy = cast<PointerType>(NestF->getType());
   const FunctionType *NestFTy = cast<FunctionType>(NestFPTy->getElementType());
 
index f14c455bce02b081d0e6cc2722eaa45038f92f1f..546cadb0f3b1abcac744acb8ca3872f8ef11d4ae 100644 (file)
@@ -357,28 +357,4 @@ Function *Intrinsic::getDeclaration(Module *M, ID id, const Type **Tys,
                                           getType(id, Tys, numTys)));
 }
 
-Value *IntrinsicInst::StripPointerCasts(Value *Ptr) {
-  if (ConstantExpr *CE = dyn_cast<ConstantExpr>(Ptr)) {
-    if (CE->getOpcode() == Instruction::BitCast) {
-      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 (BitCastInst *CI = dyn_cast<BitCastInst>(Ptr)) {
-    if (isa<PointerType>(CI->getOperand(0)->getType()))
-      return StripPointerCasts(CI->getOperand(0));
-  } else if (GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(Ptr)) {
-    if (GEP->hasAllZeroIndices())
-      return StripPointerCasts(GEP->getOperand(0));
-  }
-  return Ptr;
-}
-
 // vim: sw=2 ai
index e55e558e0f99bc70e71ff084e50eeb2af7b1b905..93a71518eb1bc493334ea452f062edaa3c120279 100644 (file)
@@ -12,6 +12,7 @@
 //===----------------------------------------------------------------------===//
 
 #include "llvm/Constant.h"
+#include "llvm/Constants.h"
 #include "llvm/DerivedTypes.h"
 #include "llvm/InstrTypes.h"
 #include "llvm/Instructions.h"
@@ -331,3 +332,30 @@ void User::replaceUsesOfWith(Value *From, Value *To) {
     }
 }
 
+//===----------------------------------------------------------------------===//
+//                            Utility functions
+//===----------------------------------------------------------------------===//
+
+Value *llvm::StripPointerCasts(Value *Ptr) {
+  if (ConstantExpr *CE = dyn_cast<ConstantExpr>(Ptr)) {
+    if (CE->getOpcode() == Instruction::BitCast) {
+      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 (BitCastInst *CI = dyn_cast<BitCastInst>(Ptr)) {
+    if (isa<PointerType>(CI->getOperand(0)->getType()))
+      return StripPointerCasts(CI->getOperand(0));
+  } else if (GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(Ptr)) {
+    if (GEP->hasAllZeroIndices())
+      return StripPointerCasts(GEP->getOperand(0));
+  }
+  return Ptr;
+}
index 7449fe7ed6fbf037ed6a30610c15566cf72e0887..be546738699af0a450a71b0df99899b1f662f3a0 100644 (file)
@@ -1271,8 +1271,7 @@ void Verifier::visitIntrinsicFunctionCall(Intrinsic::ID ID, CallInst &CI) {
                 "Intrinsic parameter #1 is not i8**.", &CI);
         Assert1(CI.getOperand(2)->getType() == PtrTy,
                 "Intrinsic parameter #2 is not i8*.", &CI);
-        Assert1(isa<AllocaInst>(
-                  IntrinsicInst::StripPointerCasts(CI.getOperand(1))),
+        Assert1(isa<AllocaInst>(StripPointerCasts(CI.getOperand(1))),
                 "llvm.gcroot parameter #1 must be an alloca.", &CI);
         Assert1(isa<Constant>(CI.getOperand(2)),
                 "llvm.gcroot parameter #2 must be a constant.", &CI);
@@ -1298,7 +1297,7 @@ void Verifier::visitIntrinsicFunctionCall(Intrinsic::ID ID, CallInst &CI) {
               &CI);
     } break;
   case Intrinsic::init_trampoline:
-    Assert1(isa<Function>(IntrinsicInst::StripPointerCasts(CI.getOperand(2))),
+    Assert1(isa<Function>(StripPointerCasts(CI.getOperand(2))),
             "llvm.init_trampoline parameter #2 must resolve to a function.",
             &CI);
     break;