llvm.org GIT mirror llvm / 0b12ecf
Turn StripPointerCast() into a method git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@50836 91177308-0d34-0410-b5e6-96231b3b80d8 Anton Korobeynikov 11 years ago
9 changed file(s) with 42 addition(s) and 45 deletion(s). Raw diff Collapse all Expand all
182182 /// getDest - This is just like getRawDest, but it strips off any cast
183183 /// instructions that feed it, giving the original input. The returned
184184 /// value is guaranteed to be a pointer.
185 Value *getDest() const { return StripPointerCasts(getRawDest()); }
185 Value *getDest() const { return getRawDest()->stripPointerCasts(); }
186186
187187 /// set* - Set the specified arguments of the instruction.
188188 ///
233233 /// getSource - This is just like getRawSource, but it strips off any cast
234234 /// instructions that feed it, giving the original input. The returned
235235 /// value is guaranteed to be a pointer.
236 Value *getSource() const { return StripPointerCasts(getRawSource()); }
236 Value *getSource() const { return getRawSource()->stripPointerCasts(); }
237237
238238
239239 void setSource(Value *Ptr) {
263263 /// getSource - This is just like getRawSource, but it strips off any cast
264264 /// instructions that feed it, giving the original input. The returned
265265 /// value is guaranteed to be a pointer.
266 Value *getSource() const { return StripPointerCasts(getRawSource()); }
266 Value *getSource() const { return getRawSource()->stripPointerCasts(); }
267267
268268 void setSource(Value *Ptr) {
269269 assert(getRawSource()->getType() == Ptr->getType() &&
219219 /// getRawType - This should only be used to implement the vmcore library.
220220 ///
221221 const Type *getRawType() const { return Ty.getRawType(); }
222
223 /// stripPointerCasts - This method strips off any unneeded pointer
224 /// casts from the specified value, returning the original uncasted value.
225 /// Note that the returned value is guaranteed to have pointer type.
226 Value *stripPointerCasts();
222227 };
223228
224229 inline std::ostream &operator<<(std::ostream &OS, const Value &V) {
271276 return isa(Val) || isa(Val) || isa(Val);
272277 }
273278
274 /// StripPointerCasts - This function strips off any unneeded pointer
275 /// casts from the specified value, returning the original uncasted value.
276 /// Note that the returned value is guaranteed to have pointer type.
277 Value *StripPointerCasts(Value *Ptr);
278
279279 } // End llvm namespace
280280
281281 #endif
178178 for (; !CouldBecomeSafePoint(IP); ++IP)
179179 if (StoreInst *SI = dyn_cast(IP))
180180 if (AllocaInst *AI =
181 dyn_cast(StripPointerCasts(SI->getOperand(1))))
181 dyn_cast(SI->getOperand(1)->stripPointerCasts()))
182182 InitedRoots.insert(AI);
183183
184184 // Add root initializers.
293293 // Initialize the GC root, but do not delete the intrinsic. The
294294 // backend needs the intrinsic to flag the stack slot.
295295 Roots.push_back(cast(
296 StripPointerCasts(CI->getOperand(1))));
296 CI->getOperand(1)->stripPointerCasts()));
297297 }
298298 break;
299299 default:
27112711
27122712 /// ExtractTypeInfo - Returns the type info, possibly bitcast, encoded in V.
27132713 static GlobalVariable *ExtractTypeInfo (Value *V) {
2714 V = StripPointerCasts(V);
2714 V = V->stripPointerCasts();
27152715 GlobalVariable *GV = dyn_cast(V);
27162716 assert ((GV || isa(V)) &&
27172717 "TypeInfo must be a global variable or NULL");
31493149 return 0;
31503150
31513151 case Intrinsic::init_trampoline: {
3152 const Function *F = cast(StripPointerCasts(I.getOperand(2)));
3152 const Function *F = cast(I.getOperand(2)->stripPointerCasts());
31533153
31543154 SDOperand Ops[6];
31553155 Ops[0] = getRoot();
324324 if (Function *F = CI->getCalledFunction())
325325 if (F->getIntrinsicID() == Intrinsic::gcroot) {
326326 std::pair Pair = std::make_pair(
327 CI, cast(StripPointerCasts(CI->getOperand(1))));
327 CI, cast(CI->getOperand(1)->stripPointerCasts()));
328328 if (IsNullValue(CI->getOperand(2)))
329329 Roots.push_back(Pair);
330330 else
757757 Constant *SInit =
758758 cast(RemapOperand(SGV->getInitializer(), ValueMap));
759759
760 GlobalVariable *DGV = cast(StripPointerCasts(ValueMap[SGV]));
760 GlobalVariable *DGV =
761 cast(ValueMap[SGV]->stripPointerCasts());
761762 if (DGV->hasInitializer()) {
762763 if (SGV->hasExternalLinkage()) {
763764 if (DGV->getInitializer() != SInit)
91309130 IntrinsicInst *Tramp =
91319131 cast(cast(Callee)->getOperand(0));
91329132
9133 Function *NestF = cast(StripPointerCasts(Tramp->getOperand(2)));
9133 Function *NestF = cast(Tramp->getOperand(2)->stripPointerCasts());
91349134 const PointerType *NestFPTy = cast(NestF->getType());
91359135 const FunctionType *NestFTy = cast(NestFPTy->getElementType());
91369136
309309 uncheckedReplaceAllUsesWith(New);
310310 }
311311
312 Value *Value::stripPointerCasts() {
313 if (ConstantExpr *CE = dyn_cast(this)) {
314 if (CE->getOpcode() == Instruction::BitCast) {
315 if (isa(CE->getOperand(0)->getType()))
316 return CE->getOperand(0)->stripPointerCasts();
317 } else if (CE->getOpcode() == Instruction::GetElementPtr) {
318 for (unsigned i = 1, e = CE->getNumOperands(); i != e; ++i)
319 if (!CE->getOperand(i)->isNullValue())
320 return this;
321 return CE->getOperand(0)->stripPointerCasts();
322 }
323 return this;
324 }
325
326 if (BitCastInst *CI = dyn_cast(this)) {
327 if (isa(CI->getOperand(0)->getType()))
328 return CI->getOperand(0)->stripPointerCasts();
329 } else if (GetElementPtrInst *GEP = dyn_cast(this)) {
330 if (GEP->hasAllZeroIndices())
331 return GEP->getOperand(0)->stripPointerCasts();
332 }
333 return this;
334 }
335
312336 //===----------------------------------------------------------------------===//
313337 // User Class
314338 //===----------------------------------------------------------------------===//
330354 setOperand(i, To); // Fix it now...
331355 }
332356 }
333
334 //===----------------------------------------------------------------------===//
335 // Utility functions
336 //===----------------------------------------------------------------------===//
337
338 Value *llvm::StripPointerCasts(Value *Ptr) {
339 if (ConstantExpr *CE = dyn_cast(Ptr)) {
340 if (CE->getOpcode() == Instruction::BitCast) {
341 if (isa(CE->getOperand(0)->getType()))
342 return StripPointerCasts(CE->getOperand(0));
343 } else if (CE->getOpcode() == Instruction::GetElementPtr) {
344 for (unsigned i = 1, e = CE->getNumOperands(); i != e; ++i)
345 if (!CE->getOperand(i)->isNullValue())
346 return Ptr;
347 return StripPointerCasts(CE->getOperand(0));
348 }
349 return Ptr;
350 }
351
352 if (BitCastInst *CI = dyn_cast(Ptr)) {
353 if (isa(CI->getOperand(0)->getType()))
354 return StripPointerCasts(CI->getOperand(0));
355 } else if (GetElementPtrInst *GEP = dyn_cast(Ptr)) {
356 if (GEP->hasAllZeroIndices())
357 return StripPointerCasts(GEP->getOperand(0));
358 }
359 return Ptr;
360 }
12701270 "Intrinsic parameter #1 is not i8**.", &CI);
12711271 Assert1(CI.getOperand(2)->getType() == PtrTy,
12721272 "Intrinsic parameter #2 is not i8*.", &CI);
1273 Assert1(isa(StripPointerCasts(CI.getOperand(1))),
1273 Assert1(isa(CI.getOperand(1)->stripPointerCasts()),
12741274 "llvm.gcroot parameter #1 must be an alloca.", &CI);
12751275 Assert1(isa(CI.getOperand(2)),
12761276 "llvm.gcroot parameter #2 must be a constant.", &CI);
12961296 &CI);
12971297 } break;
12981298 case Intrinsic::init_trampoline:
1299 Assert1(isa(StripPointerCasts(CI.getOperand(2))),
1299 Assert1(isa(CI.getOperand(2)->stripPointerCasts()),
13001300 "llvm.init_trampoline parameter #2 must resolve to a function.",
13011301 &CI);
13021302 break;