Index: examples/Kaleidoscope/MCJIT/cached/Makefile =================================================================== --- examples/Kaleidoscope/MCJIT/cached/Makefile +++ examples/Kaleidoscope/MCJIT/cached/Makefile @@ -1,11 +1,11 @@ all: toy-mcjit toy-jit toy-ir-gen toy-mcjit : toy.cpp - clang++ toy.cpp -g -O3 -rdynamic -fno-rtti `llvm-config --cppflags --ldflags --libs core mcjit native irreader` -o toy-mcjit + clang++ toy.cpp -g -O3 -rdynamic -fno-rtti `llvm-config --cxxflags --ldflags --libs core mcjit native irreader` -pthread -ldl -lcurses -lz -o toy-mcjit toy-jit : toy-jit.cpp - clang++ toy-jit.cpp -g -O3 -rdynamic -fno-rtti `llvm-config --cppflags --ldflags --libs core jit native irreader` -o toy-jit + clang++ toy-jit.cpp -g -O3 -rdynamic -fno-rtti `llvm-config --cxxflags --ldflags --libs core jit native irreader` -pthread -ldl -lcurses -lz -o toy-jit # This is a special build for the purpose of converting Kaleidoscope input to an IR file toy-ir-gen : toy-jit.cpp - clang++ toy-jit.cpp -g -O3 -rdynamic -fno-rtti -DDUMP_FINAL_MODULE `llvm-config --cppflags --ldflags --libs core jit native irreader` -o toy-ir-gen + clang++ toy-jit.cpp -g -O3 -rdynamic -fno-rtti -DDUMP_FINAL_MODULE `llvm-config --cxxflags --ldflags --libs core jit native irreader` -pthread -ldl -lcurses -lz -o toy-ir-gen Index: examples/Kaleidoscope/MCJIT/cached/genk-timing.py =================================================================== --- examples/Kaleidoscope/MCJIT/cached/genk-timing.py +++ examples/Kaleidoscope/MCJIT/cached/genk-timing.py @@ -20,7 +20,7 @@ self.shfile.write("echo \"With MCJIT\" >> %s\n" % self.timeFile) self.shfile.write("/usr/bin/time -f \"Command %C\\n\\tuser time: %U s\\n\\tsytem time: %S s\\n\\tmax set: %M kb\"") self.shfile.write(" -o %s -a " % self.timeFile) - self.shfile.write("./toy-mcjit < %s > %s-mcjit.out 2> %s-mcjit.err\n" % (filename, rootname, rootname)) + self.shfile.write("./toy-mcjit -use-object-cache < %s > %s-mcjit.out 2> %s-mcjit.err\n" % (filename, rootname, rootname)) self.shfile.write("echo \"\" >> %s\n" % self.timeFile) self.shfile.write("echo \"With JIT\" >> %s\n" % self.timeFile) self.shfile.write("/usr/bin/time -f \"Command %C\\n\\tuser time: %U s\\n\\tsytem time: %S s\\n\\tmax set: %M kb\"") Index: examples/Kaleidoscope/MCJIT/cached/toy-jit.cpp =================================================================== --- examples/Kaleidoscope/MCJIT/cached/toy-jit.cpp +++ examples/Kaleidoscope/MCJIT/cached/toy-jit.cpp @@ -1171,7 +1171,7 @@ // Set up the optimizer pipeline. Start with registering info about how the // target lays out data structures. - OurFPM.add(new DataLayout(*TheExecutionEngine->getDataLayout())); + OurFPM.add(new DataLayoutPass(TheModule)); // Provide basic AliasAnalysis support for GVN. OurFPM.add(createBasicAliasAnalysisPass()); // Promote allocas to registers. Index: examples/Kaleidoscope/MCJIT/cached/toy.cpp =================================================================== --- examples/Kaleidoscope/MCJIT/cached/toy.cpp +++ examples/Kaleidoscope/MCJIT/cached/toy.cpp @@ -694,7 +694,7 @@ return; } std::string ErrStr; - raw_fd_ostream IRObjectFile(IRCacheFile.c_str(), ErrStr, raw_fd_ostream::F_Binary); + raw_fd_ostream IRObjectFile(IRCacheFile.c_str(), ErrStr, sys::fs::F_None); IRObjectFile << Obj->getBuffer(); } } @@ -715,13 +715,19 @@ // This file isn't in our cache return NULL; } - std::unique_ptr IRObjectBuffer; - MemoryBuffer::getFile(IRCacheFile.c_str(), IRObjectBuffer, -1, false); + + ErrorOr> IRObjectBuffer = + MemoryBuffer::getFile(IRCacheFile.c_str(), -1, false); + if(IRObjectBuffer.getError()) { + fprintf(stderr, "Unable to read from cache\n"); + return NULL; + } + // MCJIT will want to write into this buffer, and we don't want that // because the file has probably just been mmapped. Instead we make // a copy. The filed-based buffer will be released when it goes // out of scope. - return MemoryBuffer::getMemBufferCopy(IRObjectBuffer->getBuffer()); + return MemoryBuffer::getMemBufferCopy(IRObjectBuffer.get()->getBuffer()); } return NULL; @@ -773,29 +779,23 @@ /// Our implementation will attempt to find functions in other /// modules associated with the MCJITHelper to cross link functions /// from one generated module to another. - /// - /// If \p AbortOnFailure is false and no function with the given name is - /// found, this function returns a null pointer. Otherwise, it prints a - /// message to stderr and aborts. - virtual void *getPointerToNamedFunction(const std::string &Name, - bool AbortOnFailure = true); + virtual uint64_t getSymbolAddress(const std::string &Name); private: MCJITHelper *MasterHelper; }; -void *HelpingMemoryManager::getPointerToNamedFunction(const std::string &Name, - bool AbortOnFailure) +uint64_t HelpingMemoryManager::getSymbolAddress(const std::string &Name) { // Try the standard symbol resolution first, but ask it not to abort. - void *pfn = SectionMemoryManager::getPointerToNamedFunction(Name, false); - if (pfn) - return pfn; + uint64_t faddr = SectionMemoryManager::getSymbolAddress(Name); + if (faddr) + return faddr; - pfn = MasterHelper->getPointerToNamedFunction(Name); - if (!pfn && AbortOnFailure) + faddr = (uint64_t)MasterHelper->getPointerToNamedFunction(Name); + if (!faddr) report_fatal_error("Program used external function '" + Name + "' which could not be resolved!"); - return pfn; + return faddr; } MCJITHelper::~MCJITHelper() @@ -854,7 +854,7 @@ return OpenModule; // Otherwise create a new Module. - std::string ModName = GenerateUniqueName("mcjit_module_"); + std::string ModName = GenerateUniqueName("IR:mcjit_module_"); Module *M = new Module(ModName, Context); Modules.push_back(M); OpenModule = M; @@ -918,7 +918,7 @@ // Set up the optimizer pipeline. Start with registering info about how the // target lays out data structures. - FPM->add(new DataLayout(*NewEngine->getDataLayout())); + FPM->add(new DataLayoutPass(M)); // Provide basic AliasAnalysis support for GVN. FPM->add(createBasicAliasAnalysisPass()); // Promote allocas to registers. Index: examples/Kaleidoscope/MCJIT/complete/Makefile =================================================================== --- examples/Kaleidoscope/MCJIT/complete/Makefile +++ examples/Kaleidoscope/MCJIT/complete/Makefile @@ -1,4 +1,4 @@ all: toy toy : toy.cpp - clang++ toy.cpp -g -O3 -rdynamic -fno-rtti `llvm-config --cppflags --ldflags --libs core jit mcjit native irreader` -o toy + clang++ toy.cpp -g -O3 -rdynamic -fno-rtti `llvm-config --cxxflags --ldflags --libs core jit mcjit native irreader` -pthread -ldl -lcurses -lz -o toy Index: examples/Kaleidoscope/MCJIT/complete/toy.cpp =================================================================== --- examples/Kaleidoscope/MCJIT/complete/toy.cpp +++ examples/Kaleidoscope/MCJIT/complete/toy.cpp @@ -718,7 +718,7 @@ return; } std::string ErrStr; - raw_fd_ostream IRObjectFile(IRCacheFile.c_str(), ErrStr, raw_fd_ostream::F_Binary); + raw_fd_ostream IRObjectFile(IRCacheFile.c_str(), ErrStr, sys::fs::F_None); IRObjectFile << Obj->getBuffer(); } } @@ -739,13 +739,18 @@ // This file isn't in our cache return NULL; } - std::unique_ptr IRObjectBuffer; - MemoryBuffer::getFile(IRCacheFile.c_str(), IRObjectBuffer, -1, false); + ErrorOr> IRObjectBuffer = + MemoryBuffer::getFile(IRCacheFile.c_str(), -1, false); + if(IRObjectBuffer.getError()) { + fprintf(stderr, "Unable to read from cache\n"); + return NULL; + } + // MCJIT will want to write into this buffer, and we don't want that // because the file has probably just been mmapped. Instead we make // a copy. The filed-based buffer will be released when it goes // out of scope. - return MemoryBuffer::getMemBufferCopy(IRObjectBuffer->getBuffer()); + return MemoryBuffer::getMemBufferCopy(IRObjectBuffer.get()->getBuffer()); } return NULL; @@ -818,7 +823,7 @@ // Set up the optimizer pipeline. Start with registering info about how the // target lays out data structures. - TheFPM->add(new DataLayout(*TheExecutionEngine->getDataLayout())); + TheFPM->add(new DataLayoutPass(TheModule)); // Provide basic AliasAnalysis support for GVN. TheFPM->add(createBasicAliasAnalysisPass()); // Promote allocas to registers. @@ -936,29 +941,23 @@ /// Our implementation will attempt to find functions in other /// modules associated with the MCJITHelper to cross link functions /// from one generated module to another. - /// - /// If \p AbortOnFailure is false and no function with the given name is - /// found, this function returns a null pointer. Otherwise, it prints a - /// message to stderr and aborts. - virtual void *getPointerToNamedFunction(const std::string &Name, - bool AbortOnFailure = true); + virtual uint64_t getSymbolAddress(const std::string &Name); private: MCJITHelper *MasterHelper; }; -void *HelpingMemoryManager::getPointerToNamedFunction(const std::string &Name, - bool AbortOnFailure) +uint64_t HelpingMemoryManager::getSymbolAddress(const std::string &Name) { // Try the standard symbol resolution first, but ask it not to abort. - void *pfn = RTDyldMemoryManager::getPointerToNamedFunction(Name, false); - if (pfn) - return pfn; + uint64_t faddr = SectionMemoryManager::getSymbolAddress(Name); + if (faddr) + return faddr; - pfn = MasterHelper->getPointerToNamedFunction(Name); - if (!pfn && AbortOnFailure) + faddr = (uint64_t)MasterHelper->getPointerToNamedFunction(Name); + if (!faddr) report_fatal_error("Program used external function '" + Name + "' which could not be resolved!"); - return pfn; + return faddr; } MCJITHelper::~MCJITHelper() @@ -1017,7 +1016,7 @@ return CurrentModule; // Otherwise create a new Module. - std::string ModName = GenerateUniqueName("mcjit_module_"); + std::string ModName = GenerateUniqueName("IR:mcjit_module_"); Module *M = new Module(ModName, Context); Modules.push_back(M); CurrentModule = M; @@ -1056,7 +1055,7 @@ // Set up the optimizer pipeline. Start with registering info about how the // target lays out data structures. - FPM->add(new DataLayout(*EE->getDataLayout())); + FPM->add(new DataLayoutPass(M)); // Provide basic AliasAnalysis support for GVN. FPM->add(createBasicAliasAnalysisPass()); // Promote allocas to registers. Index: examples/Kaleidoscope/MCJIT/initial/Makefile =================================================================== --- examples/Kaleidoscope/MCJIT/initial/Makefile +++ examples/Kaleidoscope/MCJIT/initial/Makefile @@ -1,4 +1,4 @@ all: toy-mcjit toy-mcjit : toy.cpp - clang++ toy.cpp -g -O3 -rdynamic -fno-rtti `llvm-config --cppflags --ldflags --libs core mcjit native` -o toy-mcjit + clang++ toy.cpp -g -O3 -rdynamic -fno-rtti `llvm-config --cxxflags --ldflags --libs core mcjit native` -pthread -ldl -lcurses -lz -o toy-mcjit Index: examples/Kaleidoscope/MCJIT/initial/toy.cpp =================================================================== --- examples/Kaleidoscope/MCJIT/initial/toy.cpp +++ examples/Kaleidoscope/MCJIT/initial/toy.cpp @@ -681,29 +681,23 @@ /// Our implementation will attempt to find functions in other /// modules associated with the MCJITHelper to cross link functions /// from one generated module to another. - /// - /// If \p AbortOnFailure is false and no function with the given name is - /// found, this function returns a null pointer. Otherwise, it prints a - /// message to stderr and aborts. - virtual void *getPointerToNamedFunction(const std::string &Name, - bool AbortOnFailure = true); + virtual uint64_t getSymbolAddress(const std::string &Name); private: MCJITHelper *MasterHelper; }; -void *HelpingMemoryManager::getPointerToNamedFunction(const std::string &Name, - bool AbortOnFailure) +uint64_t HelpingMemoryManager::getSymbolAddress(const std::string &Name) { // Try the standard symbol resolution first, but ask it not to abort. - void *pfn = SectionMemoryManager::getPointerToNamedFunction(Name, false); - if (pfn) - return pfn; + uint64_t faddr = SectionMemoryManager::getSymbolAddress(Name); + if (faddr) + return faddr; - pfn = MasterHelper->getPointerToNamedFunction(Name); - if (!pfn && AbortOnFailure) + faddr = (uint64_t)MasterHelper->getPointerToNamedFunction(Name); + if (!faddr) report_fatal_error("Program used external function '" + Name + "' which could not be resolved!"); - return pfn; + return faddr; } MCJITHelper::~MCJITHelper() @@ -791,7 +785,7 @@ // Set up the optimizer pipeline. Start with registering info about how the // target lays out data structures. - FPM->add(new DataLayout(*NewEngine->getDataLayout())); + FPM->add(new DataLayoutPass(OpenModule)); // Provide basic AliasAnalysis support for GVN. FPM->add(createBasicAliasAnalysisPass()); // Promote allocas to registers. Index: examples/Kaleidoscope/MCJIT/lazy/Makefile =================================================================== --- examples/Kaleidoscope/MCJIT/lazy/Makefile +++ examples/Kaleidoscope/MCJIT/lazy/Makefile @@ -1,7 +1,7 @@ all: toy-mcjit toy-jit toy-mcjit : toy.cpp - clang++ toy.cpp -g -O3 -rdynamic -fno-rtti `llvm-config --cppflags --ldflags --libs core mcjit native` -o toy-mcjit + clang++ toy.cpp -g -O3 -rdynamic -fno-rtti `llvm-config --cxxflags --ldflags --libs core mcjit native` -pthread -ldl -lcurses -lz -o toy-mcjit toy-jit : toy-jit.cpp - clang++ toy-jit.cpp -g -O3 -rdynamic `llvm-config --cppflags --ldflags --libs core jit native` -o toy-jit + clang++ toy-jit.cpp -g -O3 -rdynamic `llvm-config --cxxflags --ldflags --libs core jit native` -pthread -ldl -lcurses -lz -o toy-jit Index: examples/Kaleidoscope/MCJIT/lazy/toy-jit.cpp =================================================================== --- examples/Kaleidoscope/MCJIT/lazy/toy-jit.cpp +++ examples/Kaleidoscope/MCJIT/lazy/toy-jit.cpp @@ -1131,7 +1131,7 @@ // Set up the optimizer pipeline. Start with registering info about how the // target lays out data structures. - OurFPM.add(new DataLayout(*TheExecutionEngine->getDataLayout())); + OurFPM.add(new DataLayoutPass(TheModule)); // Provide basic AliasAnalysis support for GVN. OurFPM.add(createBasicAliasAnalysisPass()); // Promote allocas to registers. Index: examples/Kaleidoscope/MCJIT/lazy/toy.cpp =================================================================== --- examples/Kaleidoscope/MCJIT/lazy/toy.cpp +++ examples/Kaleidoscope/MCJIT/lazy/toy.cpp @@ -684,29 +684,23 @@ /// Our implementation will attempt to find functions in other /// modules associated with the MCJITHelper to cross link functions /// from one generated module to another. - /// - /// If \p AbortOnFailure is false and no function with the given name is - /// found, this function returns a null pointer. Otherwise, it prints a - /// message to stderr and aborts. - virtual void *getPointerToNamedFunction(const std::string &Name, - bool AbortOnFailure = true); + virtual uint64_t getSymbolAddress(const std::string &Name); private: MCJITHelper *MasterHelper; }; -void *HelpingMemoryManager::getPointerToNamedFunction(const std::string &Name, - bool AbortOnFailure) +uint64_t HelpingMemoryManager::getSymbolAddress(const std::string &Name) { // Try the standard symbol resolution first, but ask it not to abort. - void *pfn = SectionMemoryManager::getPointerToNamedFunction(Name, false); - if (pfn) - return pfn; + uint64_t faddr = SectionMemoryManager::getSymbolAddress(Name); + if (faddr) + return faddr; - pfn = MasterHelper->getPointerToNamedFunction(Name); - if (!pfn && AbortOnFailure) + faddr = (uint64_t)MasterHelper->getPointerToNamedFunction(Name); + if (!faddr) report_fatal_error("Program used external function '" + Name + "' which could not be resolved!"); - return pfn; + return faddr; } MCJITHelper::~MCJITHelper() @@ -821,7 +815,7 @@ // Set up the optimizer pipeline. Start with registering info about how the // target lays out data structures. - FPM->add(new DataLayout(*NewEngine->getDataLayout())); + FPM->add(new DataLayoutPass(M)); // Provide basic AliasAnalysis support for GVN. FPM->add(createBasicAliasAnalysisPass()); // Promote allocas to registers.