Lines Matching +full:string +full:- +full:support

1 //===- lli.cpp - LLVM Interpreter / Dynamic compiler ----------------------===//
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
10 // which allow the direct execution of LLVM programs through a Just-In-Time
13 //===----------------------------------------------------------------------===//
20 #include "llvm/Config/llvm-config.h"
51 #include "llvm/Support/CommandLine.h"
52 #include "llvm/Support/Debug.h"
53 #include "llvm/Support/DynamicLibrary.h"
54 #include "llvm/Support/Format.h"
55 #include "llvm/Support/InitLLVM.h"
56 #include "llvm/Support/MathExtras.h"
57 #include "llvm/Support/Memory.h"
58 #include "llvm/Support/MemoryBuffer.h"
59 #include "llvm/Support/Path.h"
60 #include "llvm/Support/PluginLoader.h"
61 #include "llvm/Support/Process.h"
62 #include "llvm/Support/Program.h"
63 #include "llvm/Support/SourceMgr.h"
64 #include "llvm/Support/TargetSelect.h"
65 #include "llvm/Support/ToolOutputFile.h"
66 #include "llvm/Support/WithColor.h"
67 #include "llvm/Support/raw_ostream.h"
97 cl::opt<std::string>
98 InputFile(cl::desc("<input bitcode>"), cl::Positional, cl::init("-"));
100 cl::list<std::string>
103 cl::opt<bool> ForceInterpreter("force-interpreter",
108 "jit-kind", cl::desc("Choose underlying JIT kind."),
112 clEnumValN(JITKind::OrcLazy, "orc-lazy",
113 "Orc-based lazy JIT.")));
116 JITLinker("jit-linker", cl::desc("Choose the dynamic linker/loader."),
119 "Default for platform and JIT-kind"),
123 "Orc-specific linker")));
124 cl::opt<std::string> OrcRuntime("orc-runtime",
129 LazyJITCompileThreads("compile-threads",
131 "(jit-kind=orc-lazy only)"),
134 cl::list<std::string>
135 ThreadEntryPoints("thread-entry",
136 cl::desc("calls the given entry-point on a new thread "
137 "(jit-kind=orc-lazy only)"));
140 "per-module-lazy",
145 cl::list<std::string>
148 "-extra-module arguments."));
150 cl::list<std::string>
156 cl::opt<bool> RemoteMCJIT("remote-mcjit",
164 cl::opt<std::string>
165 ChildExecPath("mcjit-remote-process",
168 "\n\tremote execution will be simulated in-process."),
173 cl::desc("Optimization level. [-O0, -O1, -O2, or -O3] "
174 "(default = '-O2')"),
177 cl::opt<std::string>
180 cl::opt<std::string>
181 EntryFunc("entry-function",
187 cl::list<std::string>
188 ExtraModules("extra-module",
192 cl::list<std::string>
193 ExtraObjects("extra-object",
197 cl::list<std::string>
198 ExtraArchives("extra-archive",
203 EnableCacheManager("enable-cache-manager",
207 cl::opt<std::string>
208 ObjectCacheDir("object-cache-dir",
213 cl::opt<std::string>
214 FakeArgv0("fake-argv0",
219 DisableCoreFiles("disable-core-files", cl::Hidden,
223 NoLazyCompilation("disable-lazy-compilation",
228 GenerateSoftFloatCalls("soft-float",
233 "no-process-syms",
240 "lljit-platform", cl::desc("Platform to use with LLJIT"),
247 "Requires -orc-runtime"),
251 "Disable platform support explicitly")),
264 "orc-lazy-debug", cl::desc("Debug dumping for the orc-lazy JIT."),
267 clEnumValN(DumpKind::NoDump, "no-dump", "Don't dump anything."),
268 clEnumValN(DumpKind::DumpFuncsToStdOut, "funcs-to-stdout",
270 clEnumValN(DumpKind::DumpModsToStdOut, "mods-to-stdout",
272 clEnumValN(DumpKind::DumpModsToDisk, "mods-to-disk",
276 clEnumValN(DumpKind::DumpDebugDescriptor, "jit-debug-descriptor",
278 clEnumValN(DumpKind::DumpDebugObjects, "jit-debug-objects",
279 "Dump __jit_debug_descriptor in-memory debug "
293 //===----------------------------------------------------------------------===//
304 LLIObjectCache(const std::string& CacheDir) : CacheDir(CacheDir) { in LLIObjectCache()
306 if (!this->CacheDir.empty() && in LLIObjectCache()
307 this->CacheDir[this->CacheDir.size() - 1] != '/') in LLIObjectCache()
308 this->CacheDir += '/'; in LLIObjectCache()
313 const std::string &ModuleID = M->getModuleIdentifier(); in notifyObjectCompiled()
314 std::string CacheName; in notifyObjectCompiled()
317 if (!CacheDir.empty()) { // Create user-defined cache dir. in notifyObjectCompiled()
329 const std::string &ModuleID = M->getModuleIdentifier(); in getObject()
330 std::string CacheName; in getObject()
342 // a copy. The filed-based buffer will be released when it goes in getObject()
344 return MemoryBuffer::getMemBufferCopy(IRObjectBuffer.get()->getBuffer()); in getObject()
348 std::string CacheDir;
350 bool getCacheFilename(StringRef ModID, std::string &CacheName) { in getCacheFilename()
354 std::string CacheSubdir = std::string(ModID); in getCacheFilename()
364 CacheName.replace(pos, CacheName.length() - pos, ".o"); in getCacheFilename()
371 // problems with remote targets (because lli's remote target support does not
381 M->setTargetTriple(TargetTripleStr); in addCygMingExtraModule()
419 //===----------------------------------------------------------------------===//
426 ExitOnErr.setBanner(std::string(argv[0]) + ": "); in main()
445 << "--entry-function name cannot be empty\n"; in main()
465 std::string CacheName("file:"); in main()
467 Mod->setModuleIdentifier(CacheName); in main()
473 ExitOnError ExitOnErr(std::string(*argv) + in main()
475 ExitOnErr(Mod->materializeAll()); in main()
478 std::string ErrorMsg; in main()
494 Mod->setTargetTriple(Triple::normalize(TargetTriple)); in main()
536 EE->setObjectCache(CacheManager.get()); in main()
545 std::string CacheName("file:"); in main()
547 XMod->setModuleIdentifier(CacheName); in main()
549 EE->addModule(std::move(XMod)); in main()
561 EE->addObjectFile(std::move(O)); in main()
572 object::Archive::create(ArBuf->getMemBufferRef()); in main()
574 std::string Buf; in main()
585 EE->addArchive(std::move(OB)); in main()
590 if (RemoteMCJIT && Triple(Mod->getTargetTriple()).isOSCygMing()) { in main()
591 addCygMingExtraModule(*EE, Context, Mod->getTargetTriple()); in main()
595 // support wasn't enabled in the build configuration. in main()
596 EE->RegisterJITEventListener( in main()
598 EE->RegisterJITEventListener( in main()
601 EE->RegisterJITEventListener( in main()
606 << "remote mcjit does not support lazy compilation\n"; in main()
609 EE->DisableLazyCompilation(NoLazyCompilation); in main()
614 InputFile = static_cast<std::string>(FakeArgv0); in main()
619 InputFile.erase(InputFile.length() - 3); in main()
630 Function *EntryFn = Mod->getFunction(EntryFunc); in main()
634 return -1; in main()
640 int Result = -1; in main()
642 // Sanity check use of remote-jit: LLI currently only supports use of the in main()
647 << "host does not support external remote targets.\n"; in main()
649 return -1; in main()
653 << "-remote-mcjit requires -mcjit-remote-process.\n"; in main()
659 return -1; in main()
667 FunctionCallee Exit = Mod->getOrInsertFunction( in main()
673 EE->finalizeObject(); in main()
675 EE->runStaticConstructorsDestructors(false); in main()
679 (void)EE->getPointerToFunction(EntryFn); in main()
682 static_cast<SectionMemoryManager*>(RTDyldMM)->invalidateInstructionCache(); in main()
685 Result = EE->runFunctionAsMain(EntryFn, InputArgv, envp); in main()
688 EE->runStaticConstructorsDestructors(true); in main()
693 dyn_cast<Function>(Exit.getCallee()->stripPointerCasts())) { in main()
694 if (ExitF->getFunctionType() == Exit.getFunctionType()) { in main()
699 EE->runFunction(ExitF, Args); in main()
711 // Remote target MCJIT doesn't (yet) support static constructors. No reason in main()
721 static_cast<ForwardingMemoryManager*>(RTDyldMM)->setMemMgr( in main()
725 static_cast<ForwardingMemoryManager *>(RTDyldMM)->setResolver( in main()
731 orc::ExecutorAddr(EE->getFunctionAddress(EntryFn->getName().str())); in main()
732 EE->finalizeObject(); in main()
733 LLVM_DEBUG(dbgs() << "Executing '" << EntryFn->getName() << "' at 0x" in main()
735 Result = ExitOnErr(EPC->runAsMain(Entry, {})); in main()
737 // Like static constructors, the remote target MCJIT support doesn't handle in main()
740 // Delete the EE - we need to tear it down *before* we terminate the session in main()
746 ExitOnErr(EPC->disconnect()); in main()
752 // JITLink debug support plugins put information about JITed code in this GDB
760 if (Latest->next_entry) in findNextDebugDescriptorEntry()
761 return Latest->next_entry; in findNextDebugDescriptorEntry()
773 ToolOutput = std::make_unique<ToolOutputFile>("-", EC, sys::fs::OF_None); in claimToolOutput()
798 std::string Name(std::string(F.getName())); in createIRDebugDumper()
809 outs() << "----- Module Start -----\n" << M << "----- Module End -----\n"; in createIRDebugDumper()
856 ToolOutput.os().write(NewEntry->symfile_addr, NewEntry->symfile_size); in createObjDebugDumper()
867 std::string ErrMsg; in loadDylibs()
882 std::string ErrMsg; in loadModule()
891 M->setModuleIdentifier("file:" + M->getModuleIdentifier()); in loadModule()
900 // when running under lli: the executor process will have run non-JIT ctors, in mingw_noop_main()
902 // error we just implement __main as a no-op. in mingw_noop_main()
904 // FIXME: Move this to ORC-RT (and the ORC-RT substitution library once it in mingw_noop_main()
905 // exists). That will allow it to work out-of-process, and for all in mingw_noop_main()
910 // Try to enable debugger support for the given instance.
912 // debugger support.
915 [[maybe_unused]] std::string ErrMsg = toString(std::move(Err)); in tryEnableDebugSupport()
945 TT = Builder.getJITTargetMachineBuilder()->getTargetTriple(); in runOrcJIT()
950 Builder.getJITTargetMachineBuilder()->getTargetTriple().setArchName( in runOrcJIT()
954 ->setCPU(codegen::getCPUStr()) in runOrcJIT()
962 // FIXME: Setting a dummy call-through manager in non-lazy mode prevents the in runOrcJIT()
987 -> Expected<std::unique_ptr<orc::IRCompileLayer::IRCompiler>> { in runOrcJIT()
1031 ->setRelocationModel(Reloc::PIC_) in runOrcJIT()
1037 L->addPlugin(std::make_unique<orc::EHFrameRegistrationPlugin>( in runOrcJIT()
1045 auto *ObjLayer = &J->getObjLinkingLayer(); in runOrcJIT()
1047 RTDyldObjLayer->registerJITEventListener( in runOrcJIT()
1050 RTDyldObjLayer->registerJITEventListener( in runOrcJIT()
1054 RTDyldObjLayer->registerJITEventListener( in runOrcJIT()
1058 RTDyldObjLayer->registerJITEventListener( in runOrcJIT()
1064 J->setPartitionFunction(orc::CompileOnDemandLayer::compileWholeModule); in runOrcJIT()
1067 J->getIRTransformLayer().setTransform( in runOrcJIT()
1081 J->getObjTransformLayer().setTransform( in runOrcJIT()
1083 -> Expected<std::unique_ptr<MemoryBuffer>> { in runOrcJIT()
1090 if (J->getTargetTriple().isOSCygMing()) in runOrcJIT()
1091 ExitOnErr(J->getProcessSymbolsJITDylib()->define( in runOrcJIT()
1092 orc::absoluteSymbols({{J->mangleAndIntern("__main"), in runOrcJIT()
1099 // that resolve on call-through. in runOrcJIT()
1101 return UseJITKind == JITKind::OrcLazy ? J->addLazyIRModule(JD, std::move(M)) in runOrcJIT()
1102 : J->addIRModule(JD, std::move(M)); in runOrcJIT()
1106 ExitOnErr(AddModule(J->getMainJITDylib(), std::move(MainModule))); in runOrcJIT()
1111 // -extra-module argument indexes to determine what dylib to use for each in runOrcJIT()
1112 // -extra-module. in runOrcJIT()
1114 IdxToDylib[0] = &J->getMainJITDylib(); in runOrcJIT()
1117 orc::JITDylib *JD = J->getJITDylibByName(*JDItr); in runOrcJIT()
1119 JD = &ExitOnErr(J->createJITDylib(*JDItr)); in runOrcJIT()
1120 J->getMainJITDylib().addToLinkOrder(*JD); in runOrcJIT()
1121 JD->addToLinkOrder(J->getMainJITDylib()); in runOrcJIT()
1123 IdxToDylib[JITDylibs.getPosition(JDItr - JITDylibs.begin())] = JD; in runOrcJIT()
1130 auto EMIdx = ExtraModules.getPosition(EMItr - ExtraModules.begin()); in runOrcJIT()
1133 auto &JD = *JDItr->second; in runOrcJIT()
1139 auto EAIdx = ExtraArchives.getPosition(EAItr - ExtraArchives.begin()); in runOrcJIT()
1142 auto &JD = *JDItr->second; in runOrcJIT()
1143 ExitOnErr(J->linkStaticLibraryInto(JD, EAItr->c_str())); in runOrcJIT()
1150 ExitOnErr(J->addObjectFile(std::move(Obj))); in runOrcJIT()
1154 ExitOnErr(J->initialize(J->getMainJITDylib())); in runOrcJIT()
1156 // Run any -thread-entry points. in runOrcJIT()
1159 auto EntryPointSym = ExitOnErr(J->lookup(ThreadEntryPoint)); in runOrcJIT()
1166 auto MainAddr = ExitOnErr(J->lookup(EntryFunc)); in runOrcJIT()
1170 // ExecutorProcessControl-based execution with JITLink. in runOrcJIT()
1171 Result = ExitOnErr(EPC->runAsMain(MainAddr, InputArgv)); in runOrcJIT()
1173 // Manual in-process execution with RuntimeDyld. in runOrcJIT()
1179 // Wait for -entry-point threads. in runOrcJIT()
1184 ExitOnErr(J->deinitialize(J->getMainJITDylib())); in runOrcJIT()
1190 // Make sure nobody used an orc-lazy specific option accidentally. in disallowOrcOptions()
1193 errs() << "-compile-threads requires -jit-kind=orc-lazy\n"; in disallowOrcOptions()
1198 errs() << "-thread-entry requires -jit-kind=orc-lazy\n"; in disallowOrcOptions()
1203 errs() << "-per-module-lazy requires -jit-kind=orc-lazy\n"; in disallowOrcOptions()
1210 llvm_unreachable("launchRemote not supported on non-Unix platforms"); in launchRemote()
1235 std::string ChildInStr = utostr(PipeFD[0][0]); in launchRemote()
1239 std::string ChildOutStr = utostr(PipeFD[1][1]); in launchRemote()
1267 // Normally, this function is provided by compiler-rt builtins or libgcc.
1276 // from a compiler support library).
1282 // For real JIT uses, the real compiler support libraries should be linked
1293 // https://github.com/llvm/llvm-project/issues/56603.
1296 // require compiling with -fms-extensions.
1302 "-export:_alloca";
1307 "-export:___chkstk_ms";
1312 "-export:__chkstk";