| 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 28 matching lines...) Expand all Loading... |
| 39 // | 39 // |
| 40 // This pass currently strips out lifetime markers (that is, calls to | 40 // This pass currently strips out lifetime markers (that is, calls to |
| 41 // the llvm.lifetime.start/end intrinsics) and invariant markers | 41 // the llvm.lifetime.start/end intrinsics) and invariant markers |
| 42 // (calls to llvm.invariant.start/end). | 42 // (calls to llvm.invariant.start/end). |
| 43 // | 43 // |
| 44 //===----------------------------------------------------------------------===// | 44 //===----------------------------------------------------------------------===// |
| 45 | 45 |
| 46 #include "llvm/ADT/DenseMap.h" | 46 #include "llvm/ADT/DenseMap.h" |
| 47 #include "llvm/ADT/SmallPtrSet.h" | 47 #include "llvm/ADT/SmallPtrSet.h" |
| 48 #include "llvm/IR/DataLayout.h" | 48 #include "llvm/IR/DataLayout.h" |
| 49 #include "llvm/IR/DebugInfo.h" |
| 49 #include "llvm/IR/DerivedTypes.h" | 50 #include "llvm/IR/DerivedTypes.h" |
| 50 #include "llvm/IR/Function.h" | 51 #include "llvm/IR/Function.h" |
| 51 #include "llvm/IR/Instructions.h" | 52 #include "llvm/IR/Instructions.h" |
| 52 #include "llvm/IR/IntrinsicInst.h" | 53 #include "llvm/IR/IntrinsicInst.h" |
| 53 #include "llvm/IR/Module.h" | 54 #include "llvm/IR/Module.h" |
| 54 #include "llvm/IR/Type.h" | 55 #include "llvm/IR/Type.h" |
| 55 #include "llvm/Pass.h" | 56 #include "llvm/Pass.h" |
| 56 #include "llvm/Support/raw_ostream.h" | 57 #include "llvm/Support/raw_ostream.h" |
| 57 #include "llvm/Transforms/NaCl.h" | 58 #include "llvm/Transforms/NaCl.h" |
| 58 | 59 |
| (...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 560 } | 561 } |
| 561 } | 562 } |
| 562 | 563 |
| 563 char ReplacePtrsWithInts::ID = 0; | 564 char ReplacePtrsWithInts::ID = 0; |
| 564 INITIALIZE_PASS(ReplacePtrsWithInts, "replace-ptrs-with-ints", | 565 INITIALIZE_PASS(ReplacePtrsWithInts, "replace-ptrs-with-ints", |
| 565 "Convert pointer values to integer values", | 566 "Convert pointer values to integer values", |
| 566 false, false) | 567 false, false) |
| 567 | 568 |
| 568 bool ReplacePtrsWithInts::runOnModule(Module &M) { | 569 bool ReplacePtrsWithInts::runOnModule(Module &M) { |
| 569 DataLayout DL(&M); | 570 DataLayout DL(&M); |
| 571 DenseMap<const Function *, DISubprogram> FunctionDIs = makeSubprogramMap(M); |
| 570 Type *IntPtrType = DL.getIntPtrType(M.getContext()); | 572 Type *IntPtrType = DL.getIntPtrType(M.getContext()); |
| 571 | 573 |
| 572 for (Module::iterator Iter = M.begin(), E = M.end(); Iter != E; ) { | 574 for (Module::iterator Iter = M.begin(), E = M.end(); Iter != E; ) { |
| 573 Function *OldFunc = Iter++; | 575 Function *OldFunc = Iter++; |
| 574 // Intrinsics' types must be left alone. | 576 // Intrinsics' types must be left alone. |
| 575 if (OldFunc->isIntrinsic()) | 577 if (OldFunc->isIntrinsic()) |
| 576 continue; | 578 continue; |
| 577 | 579 |
| 578 FunctionConverter FC(IntPtrType); | 580 FunctionConverter FC(IntPtrType); |
| 579 FunctionType *NFTy = FC.convertFuncType(OldFunc->getFunctionType()); | 581 FunctionType *NFTy = FC.convertFuncType(OldFunc->getFunctionType()); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 617 for (BasicBlock::iterator Inst = BB->begin(), E = BB->end(); | 619 for (BasicBlock::iterator Inst = BB->begin(), E = BB->end(); |
| 618 Inst != E; ++Inst) { | 620 Inst != E; ++Inst) { |
| 619 if (IntrinsicInst *Call = dyn_cast<IntrinsicInst>(Inst)) { | 621 if (IntrinsicInst *Call = dyn_cast<IntrinsicInst>(Inst)) { |
| 620 if (Call->getIntrinsicID() == Intrinsic::dbg_declare) { | 622 if (Call->getIntrinsicID() == Intrinsic::dbg_declare) { |
| 621 ConvertMetadataOperand(&FC, Call, 0); | 623 ConvertMetadataOperand(&FC, Call, 0); |
| 622 } | 624 } |
| 623 } | 625 } |
| 624 } | 626 } |
| 625 } | 627 } |
| 626 FC.eraseReplacedInstructions(); | 628 FC.eraseReplacedInstructions(); |
| 629 |
| 630 // Patch the pointer to LLVM function in debug info descriptor. |
| 631 auto DI = FunctionDIs.find(OldFunc); |
| 632 if (DI != FunctionDIs.end()) |
| 633 DI->second.replaceFunction(NewFunc); |
| 634 |
| 627 OldFunc->eraseFromParent(); | 635 OldFunc->eraseFromParent(); |
| 628 } | 636 } |
| 629 // Now that all functions have their normalized types, we can remove | 637 // Now that all functions have their normalized types, we can remove |
| 630 // various casts. | 638 // various casts. |
| 631 for (Module::iterator Func = M.begin(), E = M.end(); Func != E; ++Func) { | 639 for (Module::iterator Func = M.begin(), E = M.end(); Func != E; ++Func) { |
| 632 CleanUpFunction(Func, IntPtrType); | 640 CleanUpFunction(Func, IntPtrType); |
| 633 // Delete the now-unused bitcast ConstantExprs that we created so | 641 // Delete the now-unused bitcast ConstantExprs that we created so |
| 634 // that they don't interfere with StripDeadPrototypes. | 642 // that they don't interfere with StripDeadPrototypes. |
| 635 Func->removeDeadConstantUsers(); | 643 Func->removeDeadConstantUsers(); |
| 636 } | 644 } |
| 637 return true; | 645 return true; |
| 638 } | 646 } |
| 639 | 647 |
| 640 ModulePass *llvm::createReplacePtrsWithIntsPass() { | 648 ModulePass *llvm::createReplacePtrsWithIntsPass() { |
| 641 return new ReplacePtrsWithInts(); | 649 return new ReplacePtrsWithInts(); |
| 642 } | 650 } |
| OLD | NEW |