[llvm-commits] [llvm] r50836 - in /llvm/trunk: include/llvm/IntrinsicInst.h include/llvm/Value.h lib/CodeGen/Collector.cpp lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp lib/CodeGen/ShadowStackCollector.cpp lib/Linker/LinkModules.cpp lib/Transforms/Scalar/InstructionCombining.cpp lib/VMCore/Value.cpp lib/VMCore/Verifier.cpp
Anton Korobeynikov
asl at math.spbu.ru
Wed May 7 15:54:15 PDT 2008
Author: asl
Date: Wed May 7 17:54:15 2008
New Revision: 50836
URL: http://llvm.org/viewvc/llvm-project?rev=50836&view=rev
Log:
Turn StripPointerCast() into a method
Modified:
llvm/trunk/include/llvm/IntrinsicInst.h
llvm/trunk/include/llvm/Value.h
llvm/trunk/lib/CodeGen/Collector.cpp
llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
llvm/trunk/lib/CodeGen/ShadowStackCollector.cpp
llvm/trunk/lib/Linker/LinkModules.cpp
llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp
llvm/trunk/lib/VMCore/Value.cpp
llvm/trunk/lib/VMCore/Verifier.cpp
Modified: llvm/trunk/include/llvm/IntrinsicInst.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IntrinsicInst.h?rev=50836&r1=50835&r2=50836&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IntrinsicInst.h (original)
+++ llvm/trunk/include/llvm/IntrinsicInst.h Wed May 7 17:54:15 2008
@@ -183,7 +183,7 @@
/// getDest - This is just like getRawDest, but it strips off any cast
/// instructions that feed it, giving the original input. The returned
/// value is guaranteed to be a pointer.
- Value *getDest() const { return StripPointerCasts(getRawDest()); }
+ Value *getDest() const { return getRawDest()->stripPointerCasts(); }
/// set* - Set the specified arguments of the instruction.
///
@@ -234,7 +234,7 @@
/// getSource - This is just like getRawSource, but it strips off any cast
/// instructions that feed it, giving the original input. The returned
/// value is guaranteed to be a pointer.
- Value *getSource() const { return StripPointerCasts(getRawSource()); }
+ Value *getSource() const { return getRawSource()->stripPointerCasts(); }
void setSource(Value *Ptr) {
@@ -264,7 +264,7 @@
/// getSource - This is just like getRawSource, but it strips off any cast
/// instructions that feed it, giving the original input. The returned
/// value is guaranteed to be a pointer.
- Value *getSource() const { return StripPointerCasts(getRawSource()); }
+ Value *getSource() const { return getRawSource()->stripPointerCasts(); }
void setSource(Value *Ptr) {
assert(getRawSource()->getType() == Ptr->getType() &&
Modified: llvm/trunk/include/llvm/Value.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Value.h?rev=50836&r1=50835&r2=50836&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Value.h (original)
+++ llvm/trunk/include/llvm/Value.h Wed May 7 17:54:15 2008
@@ -220,6 +220,11 @@
/// getRawType - This should only be used to implement the vmcore library.
///
const Type *getRawType() const { return Ty.getRawType(); }
+
+ /// stripPointerCasts - This 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.
+ Value *stripPointerCasts();
};
inline std::ostream &operator<<(std::ostream &OS, const Value &V) {
@@ -272,11 +277,6 @@
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
Modified: llvm/trunk/lib/CodeGen/Collector.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/Collector.cpp?rev=50836&r1=50835&r2=50836&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/Collector.cpp (original)
+++ llvm/trunk/lib/CodeGen/Collector.cpp Wed May 7 17:54:15 2008
@@ -179,7 +179,7 @@
for (; !CouldBecomeSafePoint(IP); ++IP)
if (StoreInst *SI = dyn_cast<StoreInst>(IP))
if (AllocaInst *AI =
- dyn_cast<AllocaInst>(StripPointerCasts(SI->getOperand(1))))
+ dyn_cast<AllocaInst>(SI->getOperand(1)->stripPointerCasts()))
InitedRoots.insert(AI);
// Add root initializers.
@@ -294,7 +294,7 @@
// 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>(
- StripPointerCasts(CI->getOperand(1))));
+ CI->getOperand(1)->stripPointerCasts()));
}
break;
default:
Modified: llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp?rev=50836&r1=50835&r2=50836&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp Wed May 7 17:54:15 2008
@@ -2712,7 +2712,7 @@
/// ExtractTypeInfo - Returns the type info, possibly bitcast, encoded in V.
static GlobalVariable *ExtractTypeInfo (Value *V) {
- V = StripPointerCasts(V);
+ V = V->stripPointerCasts();
GlobalVariable *GV = dyn_cast<GlobalVariable>(V);
assert ((GV || isa<ConstantPointerNull>(V)) &&
"TypeInfo must be a global variable or NULL");
@@ -3150,7 +3150,7 @@
return 0;
case Intrinsic::init_trampoline: {
- const Function *F = cast<Function>(StripPointerCasts(I.getOperand(2)));
+ const Function *F = cast<Function>(I.getOperand(2)->stripPointerCasts());
SDOperand Ops[6];
Ops[0] = getRoot();
Modified: llvm/trunk/lib/CodeGen/ShadowStackCollector.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/ShadowStackCollector.cpp?rev=50836&r1=50835&r2=50836&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/ShadowStackCollector.cpp (original)
+++ llvm/trunk/lib/CodeGen/ShadowStackCollector.cpp Wed May 7 17:54:15 2008
@@ -325,7 +325,7 @@
if (Function *F = CI->getCalledFunction())
if (F->getIntrinsicID() == Intrinsic::gcroot) {
std::pair<CallInst*,AllocaInst*> Pair = std::make_pair(
- CI, cast<AllocaInst>(StripPointerCasts(CI->getOperand(1))));
+ CI, cast<AllocaInst>(CI->getOperand(1)->stripPointerCasts()));
if (IsNullValue(CI->getOperand(2)))
Roots.push_back(Pair);
else
Modified: llvm/trunk/lib/Linker/LinkModules.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Linker/LinkModules.cpp?rev=50836&r1=50835&r2=50836&view=diff
==============================================================================
--- llvm/trunk/lib/Linker/LinkModules.cpp (original)
+++ llvm/trunk/lib/Linker/LinkModules.cpp Wed May 7 17:54:15 2008
@@ -758,7 +758,8 @@
Constant *SInit =
cast<Constant>(RemapOperand(SGV->getInitializer(), ValueMap));
- GlobalVariable *DGV = cast<GlobalVariable>(StripPointerCasts(ValueMap[SGV]));
+ GlobalVariable *DGV =
+ cast<GlobalVariable>(ValueMap[SGV]->stripPointerCasts());
if (DGV->hasInitializer()) {
if (SGV->hasExternalLinkage()) {
if (DGV->getInitializer() != SInit)
Modified: llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp?rev=50836&r1=50835&r2=50836&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp Wed May 7 17:54:15 2008
@@ -9131,7 +9131,7 @@
IntrinsicInst *Tramp =
cast<IntrinsicInst>(cast<BitCastInst>(Callee)->getOperand(0));
- Function *NestF = cast<Function>(StripPointerCasts(Tramp->getOperand(2)));
+ Function *NestF = cast<Function>(Tramp->getOperand(2)->stripPointerCasts());
const PointerType *NestFPTy = cast<PointerType>(NestF->getType());
const FunctionType *NestFTy = cast<FunctionType>(NestFPTy->getElementType());
Modified: llvm/trunk/lib/VMCore/Value.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Value.cpp?rev=50836&r1=50835&r2=50836&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/Value.cpp (original)
+++ llvm/trunk/lib/VMCore/Value.cpp Wed May 7 17:54:15 2008
@@ -310,6 +310,30 @@
uncheckedReplaceAllUsesWith(New);
}
+Value *Value::stripPointerCasts() {
+ if (ConstantExpr *CE = dyn_cast<ConstantExpr>(this)) {
+ if (CE->getOpcode() == Instruction::BitCast) {
+ if (isa<PointerType>(CE->getOperand(0)->getType()))
+ return CE->getOperand(0)->stripPointerCasts();
+ } else if (CE->getOpcode() == Instruction::GetElementPtr) {
+ for (unsigned i = 1, e = CE->getNumOperands(); i != e; ++i)
+ if (!CE->getOperand(i)->isNullValue())
+ return this;
+ return CE->getOperand(0)->stripPointerCasts();
+ }
+ return this;
+ }
+
+ if (BitCastInst *CI = dyn_cast<BitCastInst>(this)) {
+ if (isa<PointerType>(CI->getOperand(0)->getType()))
+ return CI->getOperand(0)->stripPointerCasts();
+ } else if (GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(this)) {
+ if (GEP->hasAllZeroIndices())
+ return GEP->getOperand(0)->stripPointerCasts();
+ }
+ return this;
+}
+
//===----------------------------------------------------------------------===//
// User Class
//===----------------------------------------------------------------------===//
@@ -331,31 +355,3 @@
setOperand(i, To); // Fix it now...
}
}
-
-//===----------------------------------------------------------------------===//
-// 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;
-}
Modified: llvm/trunk/lib/VMCore/Verifier.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Verifier.cpp?rev=50836&r1=50835&r2=50836&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/Verifier.cpp (original)
+++ llvm/trunk/lib/VMCore/Verifier.cpp Wed May 7 17:54:15 2008
@@ -1271,7 +1271,7 @@
"Intrinsic parameter #1 is not i8**.", &CI);
Assert1(CI.getOperand(2)->getType() == PtrTy,
"Intrinsic parameter #2 is not i8*.", &CI);
- Assert1(isa<AllocaInst>(StripPointerCasts(CI.getOperand(1))),
+ Assert1(isa<AllocaInst>(CI.getOperand(1)->stripPointerCasts()),
"llvm.gcroot parameter #1 must be an alloca.", &CI);
Assert1(isa<Constant>(CI.getOperand(2)),
"llvm.gcroot parameter #2 must be a constant.", &CI);
@@ -1297,7 +1297,7 @@
&CI);
} break;
case Intrinsic::init_trampoline:
- Assert1(isa<Function>(StripPointerCasts(CI.getOperand(2))),
+ Assert1(isa<Function>(CI.getOperand(2)->stripPointerCasts()),
"llvm.init_trampoline parameter #2 must resolve to a function.",
&CI);
break;
More information about the llvm-commits
mailing list