| OLD | NEW |
| (Empty) |
| 1 //===- NoExitRuntime.cpp - Expand i64 and wider integer types -------------===// | |
| 2 // | |
| 3 // The LLVM Compiler Infrastructure | |
| 4 // | |
| 5 // This file is distributed under the University of Illinois Open Source | |
| 6 // License. See LICENSE.TXT for details. | |
| 7 // | |
| 8 //===------------------------------------------------------------------===// | |
| 9 // | |
| 10 //===------------------------------------------------------------------===// | |
| 11 | |
| 12 #include "llvm/ADT/PostOrderIterator.h" | |
| 13 #include "llvm/ADT/SmallVector.h" | |
| 14 #include "llvm/ADT/SmallString.h" | |
| 15 #include "llvm/ADT/StringExtras.h" | |
| 16 #include "llvm/Analysis/ConstantFolding.h" | |
| 17 #include "llvm/Analysis/InstructionSimplify.h" | |
| 18 #include "llvm/IR/DataLayout.h" | |
| 19 #include "llvm/IR/Function.h" | |
| 20 #include "llvm/IR/IRBuilder.h" | |
| 21 #include "llvm/IR/Instructions.h" | |
| 22 #include "llvm/IR/IntrinsicInst.h" | |
| 23 #include "llvm/IR/Module.h" | |
| 24 #include "llvm/Pass.h" | |
| 25 #include "llvm/IR/CFG.h" | |
| 26 #include "llvm/Analysis/TargetLibraryInfo.h" | |
| 27 #include "llvm/Transforms/NaCl.h" | |
| 28 #include "llvm/Transforms/Utils/Local.h" | |
| 29 #include <map> | |
| 30 | |
| 31 #include "llvm/Support/raw_ostream.h" | |
| 32 | |
| 33 #ifdef NDEBUG | |
| 34 #undef assert | |
| 35 #define assert(x) { if (!(x)) report_fatal_error(#x); } | |
| 36 #endif | |
| 37 | |
| 38 using namespace llvm; | |
| 39 | |
| 40 namespace { | |
| 41 class NoExitRuntime : public ModulePass { | |
| 42 Module *TheModule; | |
| 43 | |
| 44 public: | |
| 45 static char ID; | |
| 46 NoExitRuntime() : ModulePass(ID) { | |
| 47 initializeNoExitRuntimePass(*PassRegistry::getPassRegistry()); | |
| 48 } | |
| 49 | |
| 50 virtual bool runOnModule(Module &M); | |
| 51 }; | |
| 52 } | |
| 53 | |
| 54 char NoExitRuntime::ID = 0; | |
| 55 INITIALIZE_PASS(NoExitRuntime, "emscripten-no-exit-runtime", | |
| 56 "Generate code which assumes the runtime is never exited (so ate
xit etc. is unneeded; see emscripten NO_EXIT_RUNTIME setting)", | |
| 57 false, false) | |
| 58 | |
| 59 | |
| 60 // Implementation of NoExitRuntime | |
| 61 | |
| 62 bool NoExitRuntime::runOnModule(Module &M) { | |
| 63 TheModule = &M; | |
| 64 | |
| 65 Function *AtExit = TheModule->getFunction("__cxa_atexit"); | |
| 66 if (!AtExit || !AtExit->isDeclaration() || AtExit->getNumUses() == 0) return f
alse; | |
| 67 | |
| 68 // The system atexit is used - let's remove calls to it | |
| 69 | |
| 70 Type *i32 = Type::getInt32Ty(TheModule->getContext()); | |
| 71 Value *Zero = Constant::getNullValue(i32); | |
| 72 | |
| 73 std::vector<Instruction*> ToErase; | |
| 74 | |
| 75 for (Instruction::user_iterator UI = AtExit->user_begin(), UE = AtExit->user_e
nd(); UI != UE; ++UI) { | |
| 76 if (CallInst *CI = dyn_cast<CallInst>(*UI)) { | |
| 77 if (CI->getCalledValue() == AtExit) { | |
| 78 // calls to atexit can just be removed | |
| 79 CI->replaceAllUsesWith(Zero); | |
| 80 ToErase.push_back(CI); | |
| 81 continue; | |
| 82 } | |
| 83 } | |
| 84 // Possibly other uses of atexit are done - ptrtoint, etc. - but we leave th
ose alone | |
| 85 } | |
| 86 | |
| 87 for (unsigned i = 0; i < ToErase.size(); i++) { | |
| 88 ToErase[i]->eraseFromParent(); | |
| 89 } | |
| 90 | |
| 91 return true; | |
| 92 } | |
| 93 | |
| 94 ModulePass *llvm::createNoExitRuntimePass() { | |
| 95 return new NoExitRuntime(); | |
| 96 } | |
| OLD | NEW |