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 473 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
484 unsigned Alignment = Alloca->getAlignment(); | 484 unsigned Alignment = Alloca->getAlignment(); |
485 if (Alignment == 0) | 485 if (Alignment == 0) |
486 Alignment = DL->getPrefTypeAlignment(ElementTy); | 486 Alignment = DL->getPrefTypeAlignment(ElementTy); |
487 Value *Tmp = CopyDebug(new AllocaInst(Type::getInt8Ty(Inst->getContext()), | 487 Value *Tmp = CopyDebug(new AllocaInst(Type::getInt8Ty(Inst->getContext()), |
488 MulSize, Alignment, "", Inst), | 488 MulSize, Alignment, "", Inst), |
489 Inst); | 489 Inst); |
490 Tmp->takeName(Alloca); | 490 Tmp->takeName(Alloca); |
491 Value *Alloca2 = new PtrToIntInst(Tmp, IntPtrType, | 491 Value *Alloca2 = new PtrToIntInst(Tmp, IntPtrType, |
492 Tmp->getName() + ".asint", Inst); | 492 Tmp->getName() + ".asint", Inst); |
493 FC->recordConvertedAndErase(Alloca, Alloca2); | 493 FC->recordConvertedAndErase(Alloca, Alloca2); |
494 } else if (// These atomics only operate on integer pointers, not | 494 } else if (// Handle these instructions as a convenience to allow |
495 // other pointers, so we don't need to recreate the | |
496 // instruction. | |
497 isa<AtomicCmpXchgInst>(Inst) || | |
498 isa<AtomicRMWInst>(Inst) || | |
499 // Handle these instructions as a convenience to allow | |
500 // the pass to be used in more situations, even though we | 495 // the pass to be used in more situations, even though we |
501 // don't expect them in PNaCl's stable ABI. | 496 // don't expect them in PNaCl's stable ABI. |
502 isa<GetElementPtrInst>(Inst) || | 497 isa<GetElementPtrInst>(Inst) || |
503 isa<VAArgInst>(Inst) || | 498 isa<VAArgInst>(Inst) || |
504 isa<IndirectBrInst>(Inst) || | 499 isa<IndirectBrInst>(Inst) || |
505 isa<ExtractValueInst>(Inst) || | 500 isa<ExtractValueInst>(Inst) || |
506 isa<InsertValueInst>(Inst)) { | 501 isa<InsertValueInst>(Inst) || |
502 // These atomics only operate on integer pointers, not | |
Mark Seaborn
2013/06/26 14:33:41
Please undo this part of the change -- it's just a
JF
2013/06/26 15:52:29
Not quite: the top comment now applies to the atom
| |
503 // other pointers, so we don't need to recreate the | |
504 // instruction. | |
505 isa<AtomicCmpXchgInst>(Inst) || | |
506 isa<AtomicRMWInst>(Inst)) { | |
507 FC->convertInPlace(Inst); | 507 FC->convertInPlace(Inst); |
508 } | 508 } |
509 } | 509 } |
510 | 510 |
511 // Convert ptrtoint+inttoptr to a bitcast because it's shorter and | 511 // Convert ptrtoint+inttoptr to a bitcast because it's shorter and |
512 // because some intrinsics work on bitcasts but not on | 512 // because some intrinsics work on bitcasts but not on |
513 // ptrtoint+inttoptr, in particular: | 513 // ptrtoint+inttoptr, in particular: |
514 // * llvm.lifetime.start/end (although we strip these out) | 514 // * llvm.lifetime.start/end (although we strip these out) |
515 // * llvm.eh.typeid.for | 515 // * llvm.eh.typeid.for |
516 static void SimplifyCasts(Instruction *Inst, Type *IntPtrType) { | 516 static void SimplifyCasts(Instruction *Inst, Type *IntPtrType) { |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
618 // various casts. | 618 // various casts. |
619 for (Module::iterator Func = M.begin(), E = M.end(); Func != E; ++Func) { | 619 for (Module::iterator Func = M.begin(), E = M.end(); Func != E; ++Func) { |
620 CleanUpFunction(Func, IntPtrType); | 620 CleanUpFunction(Func, IntPtrType); |
621 } | 621 } |
622 return true; | 622 return true; |
623 } | 623 } |
624 | 624 |
625 ModulePass *llvm::createReplacePtrsWithIntsPass() { | 625 ModulePass *llvm::createReplacePtrsWithIntsPass() { |
626 return new ReplacePtrsWithInts(); | 626 return new ReplacePtrsWithInts(); |
627 } | 627 } |
OLD | NEW |