| OLD | NEW |
| 1 //===- ReplacePtrsWithInts.cpp - Convert pointer values to integer values--===// | 1 //===- ReplacePtrsWithInts.cpp - Convert pointer values to integer values--===// |
| 2 // | 2 // |
| 3 // The LLVM Compiler Infrastructure | 3 // The LLVM Compiler Infrastructure |
| 4 // | 4 // |
| 5 // This file is distributed under the University of Illinois Open Source | 5 // This file is distributed under the University of Illinois Open Source |
| 6 // License. See LICENSE.TXT for details. | 6 // License. See LICENSE.TXT for details. |
| 7 // | 7 // |
| 8 //===----------------------------------------------------------------------===// | 8 //===----------------------------------------------------------------------===// |
| 9 // | 9 // |
| 10 // This pass strips out aggregate pointer types and replaces them with | 10 // This pass strips out aggregate pointer types and replaces them with |
| (...skipping 495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 506 // Convert ptrtoint+inttoptr to a bitcast because it's shorter and | 506 // Convert ptrtoint+inttoptr to a bitcast because it's shorter and |
| 507 // because some intrinsics work on bitcasts but not on | 507 // because some intrinsics work on bitcasts but not on |
| 508 // ptrtoint+inttoptr, in particular: | 508 // ptrtoint+inttoptr, in particular: |
| 509 // * llvm.lifetime.start/end (although we strip these out) | 509 // * llvm.lifetime.start/end (although we strip these out) |
| 510 // * llvm.eh.typeid.for | 510 // * llvm.eh.typeid.for |
| 511 static void SimplifyCasts(Instruction *Inst, Type *IntPtrType) { | 511 static void SimplifyCasts(Instruction *Inst, Type *IntPtrType) { |
| 512 if (IntToPtrInst *Cast1 = dyn_cast<IntToPtrInst>(Inst)) { | 512 if (IntToPtrInst *Cast1 = dyn_cast<IntToPtrInst>(Inst)) { |
| 513 if (PtrToIntInst *Cast2 = dyn_cast<PtrToIntInst>(Cast1->getOperand(0))) { | 513 if (PtrToIntInst *Cast2 = dyn_cast<PtrToIntInst>(Cast1->getOperand(0))) { |
| 514 assert(Cast2->getType() == IntPtrType); | 514 assert(Cast2->getType() == IntPtrType); |
| 515 Value *V = Cast2->getPointerOperand(); | 515 Value *V = Cast2->getPointerOperand(); |
| 516 if (V->getType() != Cast1->getType()) | 516 if (V->getType() != Cast1->getType()) { |
| 517 // Hack: don't convert to bitcast. |
| 518 return; |
| 517 V = new BitCastInst(V, Cast1->getType(), V->getName() + ".bc", Cast1); | 519 V = new BitCastInst(V, Cast1->getType(), V->getName() + ".bc", Cast1); |
| 520 } |
| 518 Cast1->replaceAllUsesWith(V); | 521 Cast1->replaceAllUsesWith(V); |
| 519 if (Cast1->use_empty()) | 522 if (Cast1->use_empty()) |
| 520 Cast1->eraseFromParent(); | 523 Cast1->eraseFromParent(); |
| 521 if (Cast2->use_empty()) | 524 if (Cast2->use_empty()) |
| 522 Cast2->eraseFromParent(); | 525 Cast2->eraseFromParent(); |
| 523 } | 526 } |
| 524 } | 527 } |
| 525 } | 528 } |
| 526 | 529 |
| 527 static void CleanUpFunction(Function *Func, Type *IntPtrType) { | 530 static void CleanUpFunction(Function *Func, Type *IntPtrType) { |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 629 // Delete the now-unused bitcast ConstantExprs that we created so | 632 // Delete the now-unused bitcast ConstantExprs that we created so |
| 630 // that they don't interfere with StripDeadPrototypes. | 633 // that they don't interfere with StripDeadPrototypes. |
| 631 Func->removeDeadConstantUsers(); | 634 Func->removeDeadConstantUsers(); |
| 632 } | 635 } |
| 633 return true; | 636 return true; |
| 634 } | 637 } |
| 635 | 638 |
| 636 ModulePass *llvm::createReplacePtrsWithIntsPass() { | 639 ModulePass *llvm::createReplacePtrsWithIntsPass() { |
| 637 return new ReplacePtrsWithInts(); | 640 return new ReplacePtrsWithInts(); |
| 638 } | 641 } |
| OLD | NEW |