LLVM  16.0.0git
LLJIT.cpp
Go to the documentation of this file.
1 //===--------- LLJIT.cpp - An ORC-based JIT for compiling LLVM IR ---------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
21 #include "llvm/IR/GlobalVariable.h"
22 #include "llvm/IR/IRBuilder.h"
23 #include "llvm/IR/Mangler.h"
24 #include "llvm/IR/Module.h"
26 
27 #include <map>
28 
29 #define DEBUG_TYPE "orc"
30 
31 using namespace llvm;
32 using namespace llvm::orc;
33 
34 namespace {
35 
36 /// Adds helper function decls and wrapper functions that call the helper with
37 /// some additional prefix arguments.
38 ///
39 /// E.g. For wrapper "foo" with type i8(i8, i64), helper "bar", and prefix
40 /// args i32 4 and i16 12345, this function will add:
41 ///
42 /// declare i8 @bar(i32, i16, i8, i64)
43 ///
44 /// define i8 @foo(i8, i64) {
45 /// entry:
46 /// %2 = call i8 @bar(i32 4, i16 12345, i8 %0, i64 %1)
47 /// ret i8 %2
48 /// }
49 ///
50 Function *addHelperAndWrapper(Module &M, StringRef WrapperName,
51  FunctionType *WrapperFnType,
52  GlobalValue::VisibilityTypes WrapperVisibility,
53  StringRef HelperName,
54  ArrayRef<Value *> HelperPrefixArgs) {
55  std::vector<Type *> HelperArgTypes;
56  for (auto *Arg : HelperPrefixArgs)
57  HelperArgTypes.push_back(Arg->getType());
58  for (auto *T : WrapperFnType->params())
59  HelperArgTypes.push_back(T);
60  auto *HelperFnType =
61  FunctionType::get(WrapperFnType->getReturnType(), HelperArgTypes, false);
62  auto *HelperFn = Function::Create(HelperFnType, GlobalValue::ExternalLinkage,
63  HelperName, M);
64 
65  auto *WrapperFn = Function::Create(
66  WrapperFnType, GlobalValue::ExternalLinkage, WrapperName, M);
67  WrapperFn->setVisibility(WrapperVisibility);
68 
69  auto *EntryBlock = BasicBlock::Create(M.getContext(), "entry", WrapperFn);
70  IRBuilder<> IB(EntryBlock);
71 
72  std::vector<Value *> HelperArgs;
73  for (auto *Arg : HelperPrefixArgs)
74  HelperArgs.push_back(Arg);
75  for (auto &Arg : WrapperFn->args())
76  HelperArgs.push_back(&Arg);
77  auto *HelperResult = IB.CreateCall(HelperFn, HelperArgs);
78  if (HelperFn->getReturnType()->isVoidTy())
79  IB.CreateRetVoid();
80  else
81  IB.CreateRet(HelperResult);
82 
83  return WrapperFn;
84 }
85 
86 class ORCPlatformSupport : public LLJIT::PlatformSupport {
87 public:
88  ORCPlatformSupport(orc::LLJIT &J) : J(J) {}
89 
90  Error initialize(orc::JITDylib &JD) override {
93  using SPSDLOpenSig = SPSExecutorAddr(SPSString, int32_t);
94  enum dlopen_mode : int32_t {
95  ORC_RT_RTLD_LAZY = 0x1,
96  ORC_RT_RTLD_NOW = 0x2,
97  ORC_RT_RTLD_LOCAL = 0x4,
98  ORC_RT_RTLD_GLOBAL = 0x8
99  };
100 
101  if (auto WrapperAddr = J.lookup("__orc_rt_jit_dlopen_wrapper")) {
102  return J.getExecutionSession().callSPSWrapper<SPSDLOpenSig>(
103  *WrapperAddr, DSOHandles[&JD], JD.getName(),
104  int32_t(ORC_RT_RTLD_LAZY));
105  } else
106  return WrapperAddr.takeError();
107  }
108 
109  Error deinitialize(orc::JITDylib &JD) override {
111  using SPSDLCloseSig = int32_t(SPSExecutorAddr);
112 
113  if (auto WrapperAddr = J.lookup("__orc_rt_jit_dlclose_wrapper")) {
114  int32_t result;
115  auto E = J.getExecutionSession().callSPSWrapper<SPSDLCloseSig>(
116  *WrapperAddr, result, DSOHandles[&JD]);
117  if (E)
118  return E;
119  else if (result)
120  return make_error<StringError>("dlclose failed",
122  DSOHandles.erase(&JD);
123  } else
124  return WrapperAddr.takeError();
125  return Error::success();
126  }
127 
128 private:
129  orc::LLJIT &J;
131 };
132 
133 class GenericLLVMIRPlatformSupport;
134 
135 /// orc::Platform component of Generic LLVM IR Platform support.
136 /// Just forwards calls to the GenericLLVMIRPlatformSupport class below.
137 class GenericLLVMIRPlatform : public Platform {
138 public:
139  GenericLLVMIRPlatform(GenericLLVMIRPlatformSupport &S) : S(S) {}
140  Error setupJITDylib(JITDylib &JD) override;
141  Error teardownJITDylib(JITDylib &JD) override;
142  Error notifyAdding(ResourceTracker &RT,
143  const MaterializationUnit &MU) override;
144  Error notifyRemoving(ResourceTracker &RT) override {
145  // Noop -- Nothing to do (yet).
146  return Error::success();
147  }
148 
149 private:
150  GenericLLVMIRPlatformSupport &S;
151 };
152 
153 /// This transform parses llvm.global_ctors to produce a single initialization
154 /// function for the module, records the function, then deletes
155 /// llvm.global_ctors.
156 class GlobalCtorDtorScraper {
157 public:
158  GlobalCtorDtorScraper(GenericLLVMIRPlatformSupport &PS,
159  StringRef InitFunctionPrefix,
160  StringRef DeInitFunctionPrefix)
161  : PS(PS), InitFunctionPrefix(InitFunctionPrefix),
162  DeInitFunctionPrefix(DeInitFunctionPrefix) {}
165 
166 private:
167  GenericLLVMIRPlatformSupport &PS;
168  StringRef InitFunctionPrefix;
169  StringRef DeInitFunctionPrefix;
170 };
171 
172 /// Generic IR Platform Support
173 ///
174 /// Scrapes llvm.global_ctors and llvm.global_dtors and replaces them with
175 /// specially named 'init' and 'deinit'. Injects definitions / interposes for
176 /// some runtime API, including __cxa_atexit, dlopen, and dlclose.
177 class GenericLLVMIRPlatformSupport : public LLJIT::PlatformSupport {
178 public:
179  GenericLLVMIRPlatformSupport(LLJIT &J)
180  : J(J), InitFunctionPrefix(J.mangle("__orc_init_func.")),
181  DeInitFunctionPrefix(J.mangle("__orc_deinit_func.")) {
182 
183  getExecutionSession().setPlatform(
184  std::make_unique<GenericLLVMIRPlatform>(*this));
185 
186  setInitTransform(J, GlobalCtorDtorScraper(*this, InitFunctionPrefix,
187  DeInitFunctionPrefix));
188 
189  SymbolMap StdInterposes;
190 
191  StdInterposes[J.mangleAndIntern("__lljit.platform_support_instance")] =
194  StdInterposes[J.mangleAndIntern("__lljit.cxa_atexit_helper")] =
195  JITEvaluatedSymbol(pointerToJITTargetAddress(registerCxaAtExitHelper),
196  JITSymbolFlags());
197 
198  cantFail(
199  J.getMainJITDylib().define(absoluteSymbols(std::move(StdInterposes))));
200  cantFail(setupJITDylib(J.getMainJITDylib()));
201  cantFail(J.addIRModule(J.getMainJITDylib(), createPlatformRuntimeModule()));
202  }
203 
204  ExecutionSession &getExecutionSession() { return J.getExecutionSession(); }
205 
206  /// Adds a module that defines the __dso_handle global.
207  Error setupJITDylib(JITDylib &JD) {
208 
209  // Add per-jitdylib standard interposes.
210  SymbolMap PerJDInterposes;
211  PerJDInterposes[J.mangleAndIntern("__lljit.run_atexits_helper")] =
213  JITSymbolFlags());
214  PerJDInterposes[J.mangleAndIntern("__lljit.atexit_helper")] =
215  JITEvaluatedSymbol(pointerToJITTargetAddress(registerAtExitHelper),
216  JITSymbolFlags());
217  cantFail(JD.define(absoluteSymbols(std::move(PerJDInterposes))));
218 
219  auto Ctx = std::make_unique<LLVMContext>();
220  auto M = std::make_unique<Module>("__standard_lib", *Ctx);
221  M->setDataLayout(J.getDataLayout());
222 
223  auto *Int64Ty = Type::getInt64Ty(*Ctx);
224  auto *DSOHandle = new GlobalVariable(
225  *M, Int64Ty, true, GlobalValue::ExternalLinkage,
226  ConstantInt::get(Int64Ty, reinterpret_cast<uintptr_t>(&JD)),
227  "__dso_handle");
228  DSOHandle->setVisibility(GlobalValue::DefaultVisibility);
229  DSOHandle->setInitializer(
231 
232  auto *GenericIRPlatformSupportTy =
233  StructType::create(*Ctx, "lljit.GenericLLJITIRPlatformSupport");
234 
235  auto *PlatformInstanceDecl = new GlobalVariable(
236  *M, GenericIRPlatformSupportTy, true, GlobalValue::ExternalLinkage,
237  nullptr, "__lljit.platform_support_instance");
238 
239  auto *VoidTy = Type::getVoidTy(*Ctx);
240  addHelperAndWrapper(
241  *M, "__lljit_run_atexits", FunctionType::get(VoidTy, {}, false),
242  GlobalValue::HiddenVisibility, "__lljit.run_atexits_helper",
243  {PlatformInstanceDecl, DSOHandle});
244 
245  auto *IntTy = Type::getIntNTy(*Ctx, sizeof(int) * CHAR_BIT);
246  auto *AtExitCallbackTy = FunctionType::get(VoidTy, {}, false);
247  auto *AtExitCallbackPtrTy = PointerType::getUnqual(AtExitCallbackTy);
248  addHelperAndWrapper(*M, "atexit",
249  FunctionType::get(IntTy, {AtExitCallbackPtrTy}, false),
250  GlobalValue::HiddenVisibility, "__lljit.atexit_helper",
251  {PlatformInstanceDecl, DSOHandle});
252 
253  return J.addIRModule(JD, ThreadSafeModule(std::move(M), std::move(Ctx)));
254  }
255 
256  Error notifyAdding(ResourceTracker &RT, const MaterializationUnit &MU) {
257  auto &JD = RT.getJITDylib();
258  if (auto &InitSym = MU.getInitializerSymbol())
259  InitSymbols[&JD].add(InitSym, SymbolLookupFlags::WeaklyReferencedSymbol);
260  else {
261  // If there's no identified init symbol attached, but there is a symbol
262  // with the GenericIRPlatform::InitFunctionPrefix, then treat that as
263  // an init function. Add the symbol to both the InitSymbols map (which
264  // will trigger a lookup to materialize the module) and the InitFunctions
265  // map (which holds the names of the symbols to execute).
266  for (auto &KV : MU.getSymbols())
267  if ((*KV.first).startswith(InitFunctionPrefix)) {
268  InitSymbols[&JD].add(KV.first,
270  InitFunctions[&JD].add(KV.first);
271  } else if ((*KV.first).startswith(DeInitFunctionPrefix)) {
272  DeInitFunctions[&JD].add(KV.first);
273  }
274  }
275  return Error::success();
276  }
277 
278  Error initialize(JITDylib &JD) override {
279  LLVM_DEBUG({
280  dbgs() << "GenericLLVMIRPlatformSupport getting initializers to run\n";
281  });
282  if (auto Initializers = getInitializers(JD)) {
283  LLVM_DEBUG(
284  { dbgs() << "GenericLLVMIRPlatformSupport running initializers\n"; });
285  for (auto InitFnAddr : *Initializers) {
286  LLVM_DEBUG({
287  dbgs() << " Running init " << formatv("{0:x16}", InitFnAddr)
288  << "...\n";
289  });
290  auto *InitFn = jitTargetAddressToFunction<void (*)()>(InitFnAddr);
291  InitFn();
292  }
293  } else
294  return Initializers.takeError();
295  return Error::success();
296  }
297 
298  Error deinitialize(JITDylib &JD) override {
299  LLVM_DEBUG({
300  dbgs() << "GenericLLVMIRPlatformSupport getting deinitializers to run\n";
301  });
302  if (auto Deinitializers = getDeinitializers(JD)) {
303  LLVM_DEBUG({
304  dbgs() << "GenericLLVMIRPlatformSupport running deinitializers\n";
305  });
306  for (auto DeinitFnAddr : *Deinitializers) {
307  LLVM_DEBUG({
308  dbgs() << " Running deinit " << formatv("{0:x16}", DeinitFnAddr)
309  << "...\n";
310  });
311  auto *DeinitFn = jitTargetAddressToFunction<void (*)()>(DeinitFnAddr);
312  DeinitFn();
313  }
314  } else
315  return Deinitializers.takeError();
316 
317  return Error::success();
318  }
319 
320  void registerInitFunc(JITDylib &JD, SymbolStringPtr InitName) {
321  getExecutionSession().runSessionLocked([&]() {
322  InitFunctions[&JD].add(InitName);
323  });
324  }
325 
326  void registerDeInitFunc(JITDylib &JD, SymbolStringPtr DeInitName) {
327  getExecutionSession().runSessionLocked(
328  [&]() { DeInitFunctions[&JD].add(DeInitName); });
329  }
330 
331 private:
332 
333  Expected<std::vector<JITTargetAddress>> getInitializers(JITDylib &JD) {
334  if (auto Err = issueInitLookups(JD))
335  return std::move(Err);
336 
338  std::vector<JITDylibSP> DFSLinkOrder;
339 
340  if (auto Err = getExecutionSession().runSessionLocked([&]() -> Error {
341  if (auto DFSLinkOrderOrErr = JD.getDFSLinkOrder())
342  DFSLinkOrder = std::move(*DFSLinkOrderOrErr);
343  else
344  return DFSLinkOrderOrErr.takeError();
345 
346  for (auto &NextJD : DFSLinkOrder) {
347  auto IFItr = InitFunctions.find(NextJD.get());
348  if (IFItr != InitFunctions.end()) {
349  LookupSymbols[NextJD.get()] = std::move(IFItr->second);
350  InitFunctions.erase(IFItr);
351  }
352  }
353  return Error::success();
354  }))
355  return std::move(Err);
356 
357  LLVM_DEBUG({
358  dbgs() << "JITDylib init order is [ ";
359  for (auto &JD : llvm::reverse(DFSLinkOrder))
360  dbgs() << "\"" << JD->getName() << "\" ";
361  dbgs() << "]\n";
362  dbgs() << "Looking up init functions:\n";
363  for (auto &KV : LookupSymbols)
364  dbgs() << " \"" << KV.first->getName() << "\": " << KV.second << "\n";
365  });
366 
367  auto &ES = getExecutionSession();
368  auto LookupResult = Platform::lookupInitSymbols(ES, LookupSymbols);
369 
370  if (!LookupResult)
371  return LookupResult.takeError();
372 
373  std::vector<JITTargetAddress> Initializers;
374  while (!DFSLinkOrder.empty()) {
375  auto &NextJD = *DFSLinkOrder.back();
376  DFSLinkOrder.pop_back();
377  auto InitsItr = LookupResult->find(&NextJD);
378  if (InitsItr == LookupResult->end())
379  continue;
380  for (auto &KV : InitsItr->second)
381  Initializers.push_back(KV.second.getAddress());
382  }
383 
384  return Initializers;
385  }
386 
387  Expected<std::vector<JITTargetAddress>> getDeinitializers(JITDylib &JD) {
388  auto &ES = getExecutionSession();
389 
390  auto LLJITRunAtExits = J.mangleAndIntern("__lljit_run_atexits");
391 
393  std::vector<JITDylibSP> DFSLinkOrder;
394 
395  if (auto Err = ES.runSessionLocked([&]() -> Error {
396  if (auto DFSLinkOrderOrErr = JD.getDFSLinkOrder())
397  DFSLinkOrder = std::move(*DFSLinkOrderOrErr);
398  else
399  return DFSLinkOrderOrErr.takeError();
400 
401  for (auto &NextJD : DFSLinkOrder) {
402  auto &JDLookupSymbols = LookupSymbols[NextJD.get()];
403  auto DIFItr = DeInitFunctions.find(NextJD.get());
404  if (DIFItr != DeInitFunctions.end()) {
405  LookupSymbols[NextJD.get()] = std::move(DIFItr->second);
406  DeInitFunctions.erase(DIFItr);
407  }
408  JDLookupSymbols.add(LLJITRunAtExits,
409  SymbolLookupFlags::WeaklyReferencedSymbol);
410  }
411  return Error::success();
412  }))
413  return std::move(Err);
414 
415  LLVM_DEBUG({
416  dbgs() << "JITDylib deinit order is [ ";
417  for (auto &JD : DFSLinkOrder)
418  dbgs() << "\"" << JD->getName() << "\" ";
419  dbgs() << "]\n";
420  dbgs() << "Looking up deinit functions:\n";
421  for (auto &KV : LookupSymbols)
422  dbgs() << " \"" << KV.first->getName() << "\": " << KV.second << "\n";
423  });
424 
425  auto LookupResult = Platform::lookupInitSymbols(ES, LookupSymbols);
426 
427  if (!LookupResult)
428  return LookupResult.takeError();
429 
430  std::vector<JITTargetAddress> DeInitializers;
431  for (auto &NextJD : DFSLinkOrder) {
432  auto DeInitsItr = LookupResult->find(NextJD.get());
433  assert(DeInitsItr != LookupResult->end() &&
434  "Every JD should have at least __lljit_run_atexits");
435 
436  auto RunAtExitsItr = DeInitsItr->second.find(LLJITRunAtExits);
437  if (RunAtExitsItr != DeInitsItr->second.end())
438  DeInitializers.push_back(RunAtExitsItr->second.getAddress());
439 
440  for (auto &KV : DeInitsItr->second)
441  if (KV.first != LLJITRunAtExits)
442  DeInitializers.push_back(KV.second.getAddress());
443  }
444 
445  return DeInitializers;
446  }
447 
448  /// Issue lookups for all init symbols required to initialize JD (and any
449  /// JITDylibs that it depends on).
450  Error issueInitLookups(JITDylib &JD) {
451  DenseMap<JITDylib *, SymbolLookupSet> RequiredInitSymbols;
452  std::vector<JITDylibSP> DFSLinkOrder;
453 
454  if (auto Err = getExecutionSession().runSessionLocked([&]() -> Error {
455  if (auto DFSLinkOrderOrErr = JD.getDFSLinkOrder())
456  DFSLinkOrder = std::move(*DFSLinkOrderOrErr);
457  else
458  return DFSLinkOrderOrErr.takeError();
459 
460  for (auto &NextJD : DFSLinkOrder) {
461  auto ISItr = InitSymbols.find(NextJD.get());
462  if (ISItr != InitSymbols.end()) {
463  RequiredInitSymbols[NextJD.get()] = std::move(ISItr->second);
464  InitSymbols.erase(ISItr);
465  }
466  }
467  return Error::success();
468  }))
469  return Err;
470 
471  return Platform::lookupInitSymbols(getExecutionSession(),
472  RequiredInitSymbols)
473  .takeError();
474  }
475 
476  static void registerCxaAtExitHelper(void *Self, void (*F)(void *), void *Ctx,
477  void *DSOHandle) {
478  LLVM_DEBUG({
479  dbgs() << "Registering cxa atexit function " << (void *)F << " for JD "
480  << (*static_cast<JITDylib **>(DSOHandle))->getName() << "\n";
481  });
482  static_cast<GenericLLVMIRPlatformSupport *>(Self)->AtExitMgr.registerAtExit(
483  F, Ctx, DSOHandle);
484  }
485 
486  static void registerAtExitHelper(void *Self, void *DSOHandle, void (*F)()) {
487  LLVM_DEBUG({
488  dbgs() << "Registering atexit function " << (void *)F << " for JD "
489  << (*static_cast<JITDylib **>(DSOHandle))->getName() << "\n";
490  });
491  static_cast<GenericLLVMIRPlatformSupport *>(Self)->AtExitMgr.registerAtExit(
492  reinterpret_cast<void (*)(void *)>(F), nullptr, DSOHandle);
493  }
494 
495  static void runAtExitsHelper(void *Self, void *DSOHandle) {
496  LLVM_DEBUG({
497  dbgs() << "Running atexit functions for JD "
498  << (*static_cast<JITDylib **>(DSOHandle))->getName() << "\n";
499  });
500  static_cast<GenericLLVMIRPlatformSupport *>(Self)->AtExitMgr.runAtExits(
501  DSOHandle);
502  }
503 
504  // Constructs an LLVM IR module containing platform runtime globals,
505  // functions, and interposes.
506  ThreadSafeModule createPlatformRuntimeModule() {
507  auto Ctx = std::make_unique<LLVMContext>();
508  auto M = std::make_unique<Module>("__standard_lib", *Ctx);
509  M->setDataLayout(J.getDataLayout());
510 
511  auto *GenericIRPlatformSupportTy =
512  StructType::create(*Ctx, "lljit.GenericLLJITIRPlatformSupport");
513 
514  auto *PlatformInstanceDecl = new GlobalVariable(
515  *M, GenericIRPlatformSupportTy, true, GlobalValue::ExternalLinkage,
516  nullptr, "__lljit.platform_support_instance");
517 
518  auto *Int8Ty = Type::getInt8Ty(*Ctx);
519  auto *IntTy = Type::getIntNTy(*Ctx, sizeof(int) * CHAR_BIT);
520  auto *VoidTy = Type::getVoidTy(*Ctx);
521  auto *BytePtrTy = PointerType::getUnqual(Int8Ty);
522  auto *CxaAtExitCallbackTy = FunctionType::get(VoidTy, {BytePtrTy}, false);
523  auto *CxaAtExitCallbackPtrTy = PointerType::getUnqual(CxaAtExitCallbackTy);
524 
525  addHelperAndWrapper(
526  *M, "__cxa_atexit",
527  FunctionType::get(IntTy, {CxaAtExitCallbackPtrTy, BytePtrTy, BytePtrTy},
528  false),
529  GlobalValue::DefaultVisibility, "__lljit.cxa_atexit_helper",
530  {PlatformInstanceDecl});
531 
532  return ThreadSafeModule(std::move(M), std::move(Ctx));
533  }
534 
535  LLJIT &J;
536  std::string InitFunctionPrefix;
537  std::string DeInitFunctionPrefix;
541  ItaniumCXAAtExitSupport AtExitMgr;
542 };
543 
544 Error GenericLLVMIRPlatform::setupJITDylib(JITDylib &JD) {
545  return S.setupJITDylib(JD);
546 }
547 
548 Error GenericLLVMIRPlatform::teardownJITDylib(JITDylib &JD) {
549  return Error::success();
550 }
551 
552 Error GenericLLVMIRPlatform::notifyAdding(ResourceTracker &RT,
553  const MaterializationUnit &MU) {
554  return S.notifyAdding(RT, MU);
555 }
556 
558 GlobalCtorDtorScraper::operator()(ThreadSafeModule TSM,
560  auto Err = TSM.withModuleDo([&](Module &M) -> Error {
561  auto &Ctx = M.getContext();
562  auto *GlobalCtors = M.getNamedGlobal("llvm.global_ctors");
563  auto *GlobalDtors = M.getNamedGlobal("llvm.global_dtors");
564 
565  auto RegisterCOrDtors = [&](GlobalVariable *GlobalCOrDtors,
566  bool isCtor) -> Error {
567  // If there's no llvm.global_c/dtor or it's just a decl then skip.
568  if (!GlobalCOrDtors || GlobalCOrDtors->isDeclaration())
569  return Error::success();
570  std::string InitOrDeInitFunctionName;
571  if (isCtor)
572  raw_string_ostream(InitOrDeInitFunctionName)
573  << InitFunctionPrefix << M.getModuleIdentifier();
574  else
575  raw_string_ostream(InitOrDeInitFunctionName)
576  << DeInitFunctionPrefix << M.getModuleIdentifier();
577 
578  MangleAndInterner Mangle(PS.getExecutionSession(), M.getDataLayout());
579  auto InternedInitOrDeInitName = Mangle(InitOrDeInitFunctionName);
580  if (auto Err = R.defineMaterializing(
581  {{InternedInitOrDeInitName, JITSymbolFlags::Callable}}))
582  return Err;
583 
584  auto *InitOrDeInitFunc = Function::Create(
585  FunctionType::get(Type::getVoidTy(Ctx), {}, false),
586  GlobalValue::ExternalLinkage, InitOrDeInitFunctionName, &M);
587  InitOrDeInitFunc->setVisibility(GlobalValue::HiddenVisibility);
588  std::vector<std::pair<Function *, unsigned>> InitsOrDeInits;
589  auto COrDtors = isCtor ? getConstructors(M) : getDestructors(M);
590 
591  for (auto E : COrDtors)
592  InitsOrDeInits.push_back(std::make_pair(E.Func, E.Priority));
593  llvm::sort(InitsOrDeInits, llvm::less_second());
594 
595  auto *InitOrDeInitFuncEntryBlock =
596  BasicBlock::Create(Ctx, "entry", InitOrDeInitFunc);
597  IRBuilder<> IB(InitOrDeInitFuncEntryBlock);
598  for (auto &KV : InitsOrDeInits)
599  IB.CreateCall(KV.first);
600  IB.CreateRetVoid();
601 
602  if (isCtor)
603  PS.registerInitFunc(R.getTargetJITDylib(), InternedInitOrDeInitName);
604  else
605  PS.registerDeInitFunc(R.getTargetJITDylib(), InternedInitOrDeInitName);
606 
607  GlobalCOrDtors->eraseFromParent();
608  return Error::success();
609  };
610 
611  if (auto Err = RegisterCOrDtors(GlobalCtors, true))
612  return Err;
613  if (auto Err = RegisterCOrDtors(GlobalDtors, false))
614  return Err;
615 
616  return Error::success();
617  });
618 
619  if (Err)
620  return std::move(Err);
621 
622  return std::move(TSM);
623 }
624 
625 /// Inactive Platform Support
626 ///
627 /// Explicitly disables platform support. JITDylibs are not scanned for special
628 /// init/deinit symbols. No runtime API interposes are injected.
629 class InactivePlatformSupport : public LLJIT::PlatformSupport {
630 public:
631  InactivePlatformSupport() = default;
632 
633  Error initialize(JITDylib &JD) override {
634  LLVM_DEBUG(dbgs() << "InactivePlatformSupport: no initializers running for "
635  << JD.getName() << "\n");
636  return Error::success();
637  }
638 
639  Error deinitialize(JITDylib &JD) override {
640  LLVM_DEBUG(
641  dbgs() << "InactivePlatformSupport: no deinitializers running for "
642  << JD.getName() << "\n");
643  return Error::success();
644  }
645 };
646 
647 } // end anonymous namespace
648 
649 namespace llvm {
650 namespace orc {
651 
654  J.InitHelperTransformLayer->setTransform(std::move(T));
655 }
656 
658 
660 
661  LLVM_DEBUG(dbgs() << "Preparing to create LLJIT instance...\n");
662 
663  if (!JTMB) {
664  LLVM_DEBUG({
665  dbgs() << " No explicitly set JITTargetMachineBuilder. "
666  "Detecting host...\n";
667  });
668  if (auto JTMBOrErr = JITTargetMachineBuilder::detectHost())
669  JTMB = std::move(*JTMBOrErr);
670  else
671  return JTMBOrErr.takeError();
672  }
673 
674  LLVM_DEBUG({
675  dbgs() << " JITTargetMachineBuilder is "
676  << JITTargetMachineBuilderPrinter(*JTMB, " ")
677  << " Pre-constructed ExecutionSession: " << (ES ? "Yes" : "No")
678  << "\n"
679  << " DataLayout: ";
680  if (DL)
681  dbgs() << DL->getStringRepresentation() << "\n";
682  else
683  dbgs() << "None (will be created by JITTargetMachineBuilder)\n";
684 
685  dbgs() << " Custom object-linking-layer creator: "
686  << (CreateObjectLinkingLayer ? "Yes" : "No") << "\n"
687  << " Custom compile-function creator: "
688  << (CreateCompileFunction ? "Yes" : "No") << "\n"
689  << " Custom platform-setup function: "
690  << (SetUpPlatform ? "Yes" : "No") << "\n"
691  << " Number of compile threads: " << NumCompileThreads;
692  if (!NumCompileThreads)
693  dbgs() << " (code will be compiled on the execution thread)\n";
694  else
695  dbgs() << "\n";
696  });
697 
698  // If neither ES nor EPC has been set then create an EPC instance.
699  if (!ES && !EPC) {
700  LLVM_DEBUG({
701  dbgs() << "ExecutorProcessControl not specified, "
702  "Creating SelfExecutorProcessControl instance\n";
703  });
704  if (auto EPCOrErr = SelfExecutorProcessControl::Create())
705  EPC = std::move(*EPCOrErr);
706  else
707  return EPCOrErr.takeError();
708  } else
709  LLVM_DEBUG({
710  dbgs() << "Using explicitly specified ExecutorProcessControl instance "
711  << EPC.get() << "\n";
712  });
713 
714  // If the client didn't configure any linker options then auto-configure the
715  // JIT linker.
716  if (!CreateObjectLinkingLayer) {
717  auto &TT = JTMB->getTargetTriple();
718  if (TT.getArch() == Triple::riscv64 ||
719  (TT.isOSBinFormatMachO() &&
721 
722  JTMB->setRelocationModel(Reloc::PIC_);
723  JTMB->setCodeModel(CodeModel::Small);
724  CreateObjectLinkingLayer =
725  [](ExecutionSession &ES,
726  const Triple &) -> Expected<std::unique_ptr<ObjectLayer>> {
727  auto ObjLinkingLayer = std::make_unique<ObjectLinkingLayer>(ES);
728  if (auto EHFrameRegistrar = EPCEHFrameRegistrar::Create(ES))
729  ObjLinkingLayer->addPlugin(
730  std::make_unique<EHFrameRegistrationPlugin>(
731  ES, std::move(*EHFrameRegistrar)));
732  else
733  return EHFrameRegistrar.takeError();
734  return std::move(ObjLinkingLayer);
735  };
736  }
737  }
738 
739  return Error::success();
740 }
741 
743  if (CompileThreads)
744  CompileThreads->wait();
745  if (auto Err = ES->endSession())
746  ES->reportError(std::move(Err));
747 }
748 
750  assert(TSM && "Can not add null module");
751 
752  if (auto Err =
753  TSM.withModuleDo([&](Module &M) { return applyDataLayout(M); }))
754  return Err;
755 
756  return InitHelperTransformLayer->add(std::move(RT), std::move(TSM));
757 }
758 
761 }
762 
764  std::unique_ptr<MemoryBuffer> Obj) {
765  assert(Obj && "Can not add null object");
766 
767  return ObjTransformLayer->add(std::move(RT), std::move(Obj));
768 }
769 
770 Error LLJIT::addObjectFile(JITDylib &JD, std::unique_ptr<MemoryBuffer> Obj) {
772 }
773 
775  SymbolStringPtr Name) {
776  if (auto Sym = ES->lookup(
778  Name))
779  return ExecutorAddr(Sym->getAddress());
780  else
781  return Sym.takeError();
782 }
783 
786 
787  // If the config state provided an ObjectLinkingLayer factory then use it.
788  if (S.CreateObjectLinkingLayer)
789  return S.CreateObjectLinkingLayer(ES, S.JTMB->getTargetTriple());
790 
791  // Otherwise default to creating an RTDyldObjectLinkingLayer that constructs
792  // a new SectionMemoryManager for each object.
793  auto GetMemMgr = []() { return std::make_unique<SectionMemoryManager>(); };
794  auto Layer =
795  std::make_unique<RTDyldObjectLinkingLayer>(ES, std::move(GetMemMgr));
796 
797  if (S.JTMB->getTargetTriple().isOSBinFormatCOFF()) {
798  Layer->setOverrideObjectFlagsWithResponsibilityFlags(true);
799  Layer->setAutoClaimResponsibilityForObjectSymbols(true);
800  }
801 
802  if (S.JTMB->getTargetTriple().isOSBinFormatELF() &&
803  (S.JTMB->getTargetTriple().getArch() == Triple::ArchType::ppc64 ||
804  S.JTMB->getTargetTriple().getArch() == Triple::ArchType::ppc64le))
805  Layer->setAutoClaimResponsibilityForObjectSymbols(true);
806 
807  // FIXME: Explicit conversion to std::unique_ptr<ObjectLayer> added to silence
808  // errors from some GCC / libstdc++ bots. Remove this conversion (i.e.
809  // just return ObjLinkingLayer) once those bots are upgraded.
810  return std::unique_ptr<ObjectLayer>(std::move(Layer));
811 }
812 
816 
817  /// If there is a custom compile function creator set then use it.
818  if (S.CreateCompileFunction)
819  return S.CreateCompileFunction(std::move(JTMB));
820 
821  // Otherwise default to creating a SimpleCompiler, or ConcurrentIRCompiler,
822  // depending on the number of threads requested.
823  if (S.NumCompileThreads > 0)
824  return std::make_unique<ConcurrentIRCompiler>(std::move(JTMB));
825 
826  auto TM = JTMB.createTargetMachine();
827  if (!TM)
828  return TM.takeError();
829 
830  return std::make_unique<TMOwningSimpleCompiler>(std::move(*TM));
831 }
832 
834  : DL(""), TT(S.JTMB->getTargetTriple()) {
835 
836  ErrorAsOutParameter _(&Err);
837 
838  assert(!(S.EPC && S.ES) && "EPC and ES should not both be set");
839 
840  if (S.EPC) {
841  ES = std::make_unique<ExecutionSession>(std::move(S.EPC));
842  } else if (S.ES)
843  ES = std::move(S.ES);
844  else {
845  if (auto EPC = SelfExecutorProcessControl::Create()) {
846  ES = std::make_unique<ExecutionSession>(std::move(*EPC));
847  } else {
848  Err = EPC.takeError();
849  return;
850  }
851  }
852 
853  if (auto MainOrErr = this->ES->createJITDylib("main"))
854  Main = &*MainOrErr;
855  else {
856  Err = MainOrErr.takeError();
857  return;
858  }
859 
860  if (S.DL)
861  DL = std::move(*S.DL);
862  else if (auto DLOrErr = S.JTMB->getDefaultDataLayoutForTarget())
863  DL = std::move(*DLOrErr);
864  else {
865  Err = DLOrErr.takeError();
866  return;
867  }
868 
869  auto ObjLayer = createObjectLinkingLayer(S, *ES);
870  if (!ObjLayer) {
871  Err = ObjLayer.takeError();
872  return;
873  }
874  ObjLinkingLayer = std::move(*ObjLayer);
876  std::make_unique<ObjectTransformLayer>(*ES, *ObjLinkingLayer);
877 
878  {
879  auto CompileFunction = createCompileFunction(S, std::move(*S.JTMB));
880  if (!CompileFunction) {
881  Err = CompileFunction.takeError();
882  return;
883  }
884  CompileLayer = std::make_unique<IRCompileLayer>(
885  *ES, *ObjTransformLayer, std::move(*CompileFunction));
886  TransformLayer = std::make_unique<IRTransformLayer>(*ES, *CompileLayer);
888  std::make_unique<IRTransformLayer>(*ES, *TransformLayer);
889  }
890 
891  if (S.NumCompileThreads > 0) {
892  InitHelperTransformLayer->setCloneToNewContextOnEmit(true);
894  std::make_unique<ThreadPool>(hardware_concurrency(S.NumCompileThreads));
895  ES->setDispatchTask([this](std::unique_ptr<Task> T) {
896  // FIXME: We should be able to use move-capture here, but ThreadPool's
897  // AsyncTaskTys are std::functions rather than unique_functions
898  // (because MSVC's std::packaged_tasks don't support move-only types).
899  // Fix this when all the above gets sorted out.
900  CompileThreads->async([UnownedT = T.release()]() mutable {
901  std::unique_ptr<Task> T(UnownedT);
902  T->run();
903  });
904  });
905  }
906 
907  if (S.SetUpPlatform)
908  Err = S.SetUpPlatform(*this);
909  else
911 }
912 
913 std::string LLJIT::mangle(StringRef UnmangledName) const {
914  std::string MangledName;
915  {
916  raw_string_ostream MangledNameStream(MangledName);
917  Mangler::getNameWithPrefix(MangledNameStream, UnmangledName, DL);
918  }
919  return MangledName;
920 }
921 
923  if (M.getDataLayout().isDefault())
924  M.setDataLayout(DL);
925 
926  if (M.getDataLayout() != DL)
927  return make_error<StringError>(
928  "Added modules have incompatible data layouts: " +
929  M.getDataLayout().getStringRepresentation() + " (module) vs " +
930  DL.getStringRepresentation() + " (jit)",
932 
933  return Error::success();
934 }
935 
937  LLVM_DEBUG(
938  { dbgs() << "Setting up orc platform support for LLJIT\n"; });
939  J.setPlatformSupport(std::make_unique<ORCPlatformSupport>(J));
940  return Error::success();
941 }
942 
944  LLVM_DEBUG(
945  { dbgs() << "Setting up GenericLLVMIRPlatform support for LLJIT\n"; });
946  J.setPlatformSupport(std::make_unique<GenericLLVMIRPlatformSupport>(J));
947 }
948 
950  LLVM_DEBUG(
951  { dbgs() << "Explicitly deactivated platform support for LLJIT\n"; });
952  J.setPlatformSupport(std::make_unique<InactivePlatformSupport>());
953  return Error::success();
954 }
955 
958  return Err;
959  TT = JTMB->getTargetTriple();
960  return Error::success();
961 }
962 
964  assert(TSM && "Can not add null module");
965 
966  if (auto Err = TSM.withModuleDo(
967  [&](Module &M) -> Error { return applyDataLayout(M); }))
968  return Err;
969 
970  return CODLayer->add(JD, std::move(TSM));
971 }
972 
973 LLLazyJIT::LLLazyJIT(LLLazyJITBuilderState &S, Error &Err) : LLJIT(S, Err) {
974 
975  // If LLJIT construction failed then bail out.
976  if (Err)
977  return;
978 
979  ErrorAsOutParameter _(&Err);
980 
981  /// Take/Create the lazy-compile callthrough manager.
982  if (S.LCTMgr)
983  LCTMgr = std::move(S.LCTMgr);
984  else {
985  if (auto LCTMgrOrErr = createLocalLazyCallThroughManager(
986  S.TT, *ES, S.LazyCompileFailureAddr.getValue()))
987  LCTMgr = std::move(*LCTMgrOrErr);
988  else {
989  Err = LCTMgrOrErr.takeError();
990  return;
991  }
992  }
993 
994  // Take/Create the indirect stubs manager builder.
995  auto ISMBuilder = std::move(S.ISMBuilder);
996 
997  // If none was provided, try to build one.
998  if (!ISMBuilder)
999  ISMBuilder = createLocalIndirectStubsManagerBuilder(S.TT);
1000 
1001  // No luck. Bail out.
1002  if (!ISMBuilder) {
1003  Err = make_error<StringError>("Could not construct "
1004  "IndirectStubsManagerBuilder for target " +
1005  S.TT.str(),
1007  return;
1008  }
1009 
1010  // Create the COD layer.
1011  CODLayer = std::make_unique<CompileOnDemandLayer>(
1012  *ES, *InitHelperTransformLayer, *LCTMgr, std::move(ISMBuilder));
1013 
1014  if (S.NumCompileThreads > 0)
1015  CODLayer->setCloneToNewContextOnEmit(true);
1016 }
1017 
1018 // In-process LLJIT uses eh-frame section wrappers via EPC, so we need to force
1019 // them to be linked in.
1023 }
1024 
1025 } // End namespace orc.
1026 } // End namespace llvm.
llvm::orc::ExecutorAddr
Represents an address in the executor process.
Definition: ExecutorAddress.h:31
llvm::Triple::riscv64
@ riscv64
Definition: Triple.h:76
llvm::GlobalVariable::eraseFromParent
void eraseFromParent()
eraseFromParent - This method unlinks 'this' from the containing module and deletes it.
Definition: Globals.cpp:459
LLVM_ATTRIBUTE_USED
#define LLVM_ATTRIBUTE_USED
Definition: Compiler.h:139
llvm::orc::MaterializationResponsibility
Tracks responsibility for materialization, and mediates interactions between MaterializationUnits and...
Definition: Core.h:519
llvm::less_second
Function object to check whether the second component of a std::pair compares less than the second co...
Definition: STLExtras.h:1484
getName
static StringRef getName(Value *V)
Definition: ProvenanceAnalysisEvaluator.cpp:20
llvm::hardware_concurrency
ThreadPoolStrategy hardware_concurrency(unsigned ThreadCount=0)
Returns a default thread strategy where all available hardware resources are to be used,...
Definition: Threading.h:185
llvm::orc::LLJITBuilderState
Definition: LLJIT.h:251
llvm::orc::JITTargetMachineBuilder
A utility class for building TargetMachines for JITs.
Definition: JITTargetMachineBuilder.h:34
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
llvm::orc::JITDylib
Represents a JIT'd dynamic library.
Definition: Core.h:953
M
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
Definition: README.txt:252
llvm::orc::JITTargetMachineBuilder::createTargetMachine
Expected< std::unique_ptr< TargetMachine > > createTargetMachine()
Create a TargetMachine.
Definition: JITTargetMachineBuilder.cpp:44
llvm::orc::LLJIT::getMainJITDylib
JITDylib & getMainJITDylib()
Returns a reference to the JITDylib representing the JIT'd main program.
Definition: LLJIT.h:71
llvm::unique_function< Expected< ThreadSafeModule >(ThreadSafeModule, MaterializationResponsibility &R)>
llvm::orc::LLJITBuilderState::JTMB
Optional< JITTargetMachineBuilder > JTMB
Definition: LLJIT.h:265
llvm_orc_registerEHFrameSectionWrapper
llvm::orc::shared::CWrapperFunctionResult llvm_orc_registerEHFrameSectionWrapper(const char *Data, uint64_t Size)
Definition: RegisterEHFrames.cpp:172
llvm::orc::getConstructors
iterator_range< CtorDtorIterator > getConstructors(const Module &M)
Create an iterator range over the entries of the llvm.global_ctors array.
Definition: ExecutionUtils.cpp:82
llvm::GlobalValue::HiddenVisibility
@ HiddenVisibility
The GV is hidden.
Definition: GlobalValue.h:64
T
llvm::Function
Definition: Function.h:60
llvm::orc::LLLazyJITBuilderState::prepareForConstruction
Error prepareForConstruction()
Definition: LLJIT.cpp:956
llvm::orc::LLJIT::PlatformSupport::setInitTransform
static void setInitTransform(LLJIT &J, IRTransformLayer::TransformFunction T)
Definition: LLJIT.cpp:652
llvm::raw_string_ostream
A raw_ostream that writes to an std::string.
Definition: raw_ostream.h:629
llvm::orc::JITDylib::getDefaultResourceTracker
ResourceTrackerSP getDefaultResourceTracker()
Get the default resource tracker for this JITDylib.
Definition: Core.cpp:661
llvm::orc::LLJIT::LLJIT
LLJIT(LLJITBuilderState &S, Error &Err)
Create an LLJIT instance with a single compile thread.
Definition: LLJIT.cpp:833
llvm::orc::SymbolStringPtr
Pointer to a pooled string representing a symbol name.
Definition: SymbolStringPool.h:57
llvm::IRBuilder<>
llvm::Error::success
static ErrorSuccess success()
Create a success value.
Definition: Error.h:329
llvm::GlobalVariable
Definition: GlobalVariable.h:39
llvm::orc::LLJIT::InitHelperTransformLayer
std::unique_ptr< IRTransformLayer > InitHelperTransformLayer
Definition: LLJIT.h:215
llvm::FunctionType::get
static FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)
This static method is the primary way of constructing a FunctionType.
Definition: Type.cpp:360
llvm::orc::LLJIT::getTargetTriple
const Triple & getTargetTriple() const
Returns a reference to the triple for this instance.
Definition: LLJIT.h:65
llvm::orc::LLJIT::addObjectFile
Error addObjectFile(ResourceTrackerSP RT, std::unique_ptr< MemoryBuffer > Obj)
Adds an object file to the given JITDylib.
Definition: LLJIT.cpp:763
llvm::Triple
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
LLJIT.h
llvm::orc::LLJIT::setUpGenericLLVMIRPlatform
friend void setUpGenericLLVMIRPlatform(LLJIT &J)
Configure the LLJIT instance to scrape modules for llvm.global_ctors and llvm.global_dtors variables ...
Definition: LLJIT.cpp:943
llvm::orc::LLLazyJITBuilderState
Definition: LLJIT.h:396
DynamicLibrary.h
Module.h
llvm::Triple::x86_64
@ x86_64
Definition: Triple.h:86
llvm::orc::LLLazyJIT::addLazyIRModule
Error addLazyIRModule(JITDylib &JD, ThreadSafeModule M)
Add a module to be lazily compiled to JITDylib JD.
Definition: LLJIT.cpp:963
llvm::orc::ResourceTracker
API to remove / transfer ownership of JIT resources.
Definition: Core.h:53
llvm::orc::LLJIT
A pre-fabricated ORC JIT stack that can serve as an alternative to MCJIT.
Definition: LLJIT.h:37
llvm::orc::LLJIT::setPlatformSupport
void setPlatformSupport(std::unique_ptr< PlatformSupport > PS)
Set the PlatformSupport instance.
Definition: LLJIT.h:141
llvm::GlobalValue::DefaultVisibility
@ DefaultVisibility
The GV is visible.
Definition: GlobalValue.h:63
llvm::errs
raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
Definition: raw_ostream.cpp:891
ObjectTransformLayer.h
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:41
initialize
static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T, ArrayRef< StringLiteral > StandardNames)
Initialize the set of available library functions based on the specified target triple.
Definition: TargetLibraryInfo.cpp:150
llvm::DataLayout::getStringRepresentation
const std::string & getStringRepresentation() const
Returns the string representation of the DataLayout.
Definition: DataLayout.h:252
llvm::StructType::create
static StructType * create(LLVMContext &Context, StringRef Name)
This creates an identified struct.
Definition: Type.cpp:512
llvm::Type::getInt8Ty
static IntegerType * getInt8Ty(LLVMContext &C)
Definition: Type.cpp:236
llvm::orc::LLJIT::createCompileFunction
static Expected< std::unique_ptr< IRCompileLayer::IRCompiler > > createCompileFunction(LLJITBuilderState &S, JITTargetMachineBuilder JTMB)
Definition: LLJIT.cpp:814
llvm::JITSymbolFlags
Flags for symbols in the JIT.
Definition: JITSymbol.h:74
llvm::orc::MaterializationUnit
A MaterializationUnit represents a set of symbol definitions that can be materialized as a group,...
Definition: Core.h:665
LLVM_DEBUG
#define LLVM_DEBUG(X)
Definition: Debug.h:101
EPCEHFrameRegistrar.h
llvm::JITEvaluatedSymbol
Represents a symbol that has been evaluated to an address already.
Definition: JITSymbol.h:229
F
#define F(x, y, z)
Definition: MD5.cpp:55
llvm::RISCVFenceField::R
@ R
Definition: RISCVBaseInfo.h:265
EHFrameSupport.h
result
It looks like we only need to define PPCfmarto for these because according to these instructions perform RTO on fma s result
Definition: README_P9.txt:256
llvm::dbgs
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163
llvm::orc::LLJIT::lookupLinkerMangled
Expected< ExecutorAddr > lookupLinkerMangled(JITDylib &JD, SymbolStringPtr Name)
Look up a symbol in JITDylib JD by the symbol's linker-mangled name (to look up symbols based on thei...
Definition: LLJIT.cpp:774
Arg
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
Definition: AMDGPULibCalls.cpp:187
llvm::orc::ResourceTracker::getJITDylib
JITDylib & getJITDylib() const
Return the JITDylib targeted by this tracker.
Definition: Core.h:68
llvm::formatv
auto formatv(const char *Fmt, Ts &&... Vals) -> formatv_object< decltype(std::make_tuple(detail::build_format_adapter(std::forward< Ts >(Vals))...))>
Definition: FormatVariadic.h:251
llvm::orc::LLJIT::addIRModule
Error addIRModule(ResourceTrackerSP RT, ThreadSafeModule TSM)
Adds an IR module with the given ResourceTracker.
Definition: LLJIT.cpp:749
llvm::GlobalValue::isDeclaration
bool isDeclaration() const
Return true if the primary definition of this global value is outside of the current translation unit...
Definition: Globals.cpp:266
llvm::GlobalValue::VisibilityTypes
VisibilityTypes
An enumeration for the kinds of visibility of global values.
Definition: GlobalValue.h:62
llvm::orc::LLJIT::mangle
std::string mangle(StringRef UnmangledName) const
Returns a linker-mangled version of UnmangledName.
Definition: LLJIT.cpp:913
llvm::orc::LLJIT::lookup
Expected< ExecutorAddr > lookup(JITDylib &JD, StringRef UnmangledName)
Look up a symbol in JITDylib JD based on its IR symbol name.
Definition: LLJIT.h:131
llvm::orc::JITDylib::getDFSLinkOrder
static Expected< std::vector< JITDylibSP > > getDFSLinkOrder(ArrayRef< JITDylibSP > JDs)
Returns the given JITDylibs and all of their transitive dependencies in DFS order (based on linkage r...
Definition: Core.cpp:1996
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
llvm::orc::Platform::lookupInitSymbols
static Expected< DenseMap< JITDylib *, SymbolMap > > lookupInitSymbols(ExecutionSession &ES, const DenseMap< JITDylib *, SymbolLookupSet > &InitSyms)
A utility function for looking up initializer symbols.
Definition: Core.cpp:1784
llvm::orc::EPCEHFrameRegistrar::Create
static Expected< std::unique_ptr< EPCEHFrameRegistrar > > Create(ExecutionSession &ES, Optional< ExecutorAddr > RegistrationFunctionsDylib=std::nullopt)
Create from a ExecutorProcessControl instance alone.
Definition: EPCEHFrameRegistrar.cpp:20
llvm::orc::LLJIT::mangleAndIntern
SymbolStringPtr mangleAndIntern(StringRef UnmangledName) const
Returns an interned, linker-mangled version of UnmangledName.
Definition: LLJIT.h:184
llvm::orc
Definition: COFFPlatform.h:30
llvm::orc::LLLazyJITBuilderState::TT
Triple TT
Definition: LLJIT.h:403
llvm::Mangler::getNameWithPrefix
void getNameWithPrefix(raw_ostream &OS, const GlobalValue *GV, bool CannotUsePrivateLabel) const
Print the appropriate prefix and the specified global variable's name.
Definition: Mangler.cpp:119
llvm::CodeModel::Small
@ Small
Definition: CodeGen.h:28
llvm::Triple::isOSBinFormatMachO
bool isOSBinFormatMachO() const
Tests whether the environment is MachO.
Definition: Triple.h:686
llvm::orc::shared::SPSExecutorAddr
Definition: ExecutorAddress.h:228
llvm::ErrorAsOutParameter
Helper for Errors used as out-parameters.
Definition: Error.h:1096
llvm::ConstantInt::get
static Constant * get(Type *Ty, uint64_t V, bool IsSigned=false)
If Ty is a vector type, return a Constant with a splat of the given value.
Definition: Constants.cpp:879
llvm::orc::ItaniumCXAAtExitSupport
An interface for Itanium __cxa_atexit interposer implementations.
Definition: ExecutionUtils.h:197
llvm::FunctionType::params
ArrayRef< Type * > params() const
Definition: DerivedTypes.h:130
RegisterEHFrames.h
llvm::orc::JITTargetMachineBuilder::detectHost
static Expected< JITTargetMachineBuilder > detectHost()
Create a JITTargetMachineBuilder for the host system.
Definition: JITTargetMachineBuilder.cpp:25
llvm::orc::LLJIT::createObjectLinkingLayer
static Expected< std::unique_ptr< ObjectLayer > > createObjectLinkingLayer(LLJITBuilderState &S, ExecutionSession &ES)
Definition: LLJIT.cpp:785
llvm::Triple::getArch
ArchType getArch() const
Get the parsed architecture type of this triple.
Definition: Triple.h:354
llvm::orc::tpctypes::LookupResult
std::vector< ExecutorAddr > LookupResult
Definition: TargetProcessControlTypes.h:90
llvm::orc::SymbolLookupFlags::WeaklyReferencedSymbol
@ WeaklyReferencedSymbol
RTDyldObjectLinkingLayer.h
llvm::sort
void sort(IteratorTy Start, IteratorTy End)
Definition: STLExtras.h:1682
llvm::orc::getDestructors
iterator_range< CtorDtorIterator > getDestructors(const Module &M)
Create an iterator range over the entries of the llvm.global_ctors array.
Definition: ExecutionUtils.cpp:88
llvm::orc::LLJIT::ObjTransformLayer
std::unique_ptr< ObjectTransformLayer > ObjTransformLayer
Definition: LLJIT.h:212
llvm::PointerType::getUnqual
static PointerType * getUnqual(Type *ElementType)
This constructs a pointer to an object of the specified type in the default address space (address sp...
Definition: DerivedTypes.h:651
llvm::orc::MaterializationUnit::getInitializerSymbol
const SymbolStringPtr & getInitializerSymbol() const
Returns the initialization symbol for this MaterializationUnit (if any).
Definition: Core.h:698
llvm::orc::LLJIT::ES
std::unique_ptr< ExecutionSession > ES
Definition: LLJIT.h:202
llvm::orc::LLJIT::CompileThreads
std::unique_ptr< ThreadPool > CompileThreads
Definition: LLJIT.h:209
llvm::orc::createLocalIndirectStubsManagerBuilder
std::function< std::unique_ptr< IndirectStubsManager >)> createLocalIndirectStubsManagerBuilder(const Triple &T)
Create a local indriect stubs manager builder.
Definition: IndirectionUtils.cpp:174
llvm::orc::LLJIT::PlatformSupport::~PlatformSupport
virtual ~PlatformSupport()
move
compiles ldr LCPI1_0 ldr ldr mov lsr tst moveq r1 ldr LCPI1_1 and r0 bx lr It would be better to do something like to fold the shift into the conditional move
Definition: README.txt:546
llvm::DenseMap
Definition: DenseMap.h:714
llvm::orc::setUpGenericLLVMIRPlatform
void setUpGenericLLVMIRPlatform(LLJIT &J)
Configure the LLJIT instance to scrape modules for llvm.global_ctors and llvm.global_dtors variables ...
Definition: LLJIT.cpp:943
llvm::AArch64PACKey::IB
@ IB
Definition: AArch64BaseInfo.h:820
llvm::orc::MaterializationUnit::getSymbols
const SymbolFlagsMap & getSymbols() const
Return the set of symbols that this source provides.
Definition: Core.h:695
llvm::orc::LLJIT::CompileLayer
std::unique_ptr< IRCompileLayer > CompileLayer
Definition: LLJIT.h:213
llvm::orc::ResourceTrackerSP
uint8_t IntrusiveRefCntPtr< ResourceTracker > ResourceTrackerSP
Definition: Core.h:47
llvm::Function::Create
static Function * Create(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)
Definition: Function.h:137
IRBuilder.h
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
llvm::orc::ExecutionSession::callSPSWrapper
Error callSPSWrapper(ExecutorAddr WrapperFnAddr, WrapperCallArgTs &&...WrapperCallArgs)
Run a wrapper function using SPS to serialize the arguments and deserialize the results.
Definition: Core.h:1610
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
llvm::orc::JITTargetMachineBuilderPrinter
Definition: JITTargetMachineBuilder.h:159
_
#define _
Definition: HexagonMCCodeEmitter.cpp:47
Mangler.h
llvm::orc::ThreadSafeModule::withModuleDo
decltype(auto) withModuleDo(Func &&F)
Locks the associated ThreadSafeContext and calls the given function on the contained Module.
Definition: ThreadSafeModule.h:133
llvm::orc::LLJIT::~LLJIT
virtual ~LLJIT()
Destruct this instance.
Definition: LLJIT.cpp:742
llvm::ArrayRef
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: APInt.h:32
llvm::orc::LLJIT::TT
Triple TT
Definition: LLJIT.h:208
llvm::Reloc::PIC_
@ PIC_
Definition: CodeGen.h:22
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
llvm::orc::setUpOrcPlatform
Error setUpOrcPlatform(LLJIT &J)
Configure the LLJIT instance to use orc runtime support.
Definition: LLJIT.cpp:936
llvm::orc::LLJIT::DL
DataLayout DL
Definition: LLJIT.h:207
llvm::orc::Platform
Platforms set up standard symbols and mediate interactions between dynamic initializers (e....
Definition: Core.h:1309
if
if(llvm_vc STREQUAL "") set(fake_version_inc "$
Definition: CMakeLists.txt:14
llvm::orc::LLJIT::PlatformSupport
Initializer support for LLJIT.
Definition: LLJIT.h:44
MachOPlatform.h
llvm::cantFail
void cantFail(Error Err, const char *Msg=nullptr)
Report a fatal error if Err is a failure value.
Definition: Error.h:744
llvm::BasicBlock::Create
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
Definition: BasicBlock.h:97
llvm::orc::createLocalLazyCallThroughManager
Expected< std::unique_ptr< LazyCallThroughManager > > createLocalLazyCallThroughManager(const Triple &T, ExecutionSession &ES, JITTargetAddress ErrorHandlerAddr)
Create a LocalLazyCallThroughManager from the given triple and execution session.
Definition: LazyReexports.cpp:106
JITLinkMemoryManager.h
S
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Definition: README.txt:210
llvm_orc_deregisterEHFrameSectionWrapper
llvm::orc::shared::CWrapperFunctionResult llvm_orc_deregisterEHFrameSectionWrapper(const char *Data, uint64_t Size)
Definition: RegisterEHFrames.cpp:179
for
this could be done in SelectionDAGISel along with other special for
Definition: README.txt:104
llvm::pointerToJITTargetAddress
JITTargetAddress pointerToJITTargetAddress(T *Ptr)
Convert a pointer to a JITTargetAddress.
Definition: JITSymbol.h:69
llvm::orc::linkComponents
LLVM_ATTRIBUTE_USED void linkComponents()
Definition: LLJIT.cpp:1020
llvm::orc::MangleAndInterner
Mangles symbol names then uniques them in the context of an ExecutionSession.
Definition: Mangling.h:26
llvm::orc::SelfExecutorProcessControl::Create
static Expected< std::unique_ptr< SelfExecutorProcessControl > > Create(std::shared_ptr< SymbolStringPool > SSP=nullptr, std::unique_ptr< TaskDispatcher > D=nullptr, std::unique_ptr< jitlink::JITLinkMemoryManager > MemMgr=nullptr)
Create a SelfExecutorProcessControl with the given symbol string pool and memory manager.
Definition: ExecutorProcessControl.cpp:48
llvm::orc::LLJITBuilderState::prepareForConstruction
Error prepareForConstruction()
Called prior to JIT class construcion to fix up defaults.
Definition: LLJIT.cpp:659
llvm::orc::LLJIT::TransformLayer
std::unique_ptr< IRTransformLayer > TransformLayer
Definition: LLJIT.h:214
llvm::Type::getInt64Ty
static IntegerType * getInt64Ty(LLVMContext &C)
Definition: Type.cpp:239
llvm::Type::getIntNTy
static IntegerType * getIntNTy(LLVMContext &C, unsigned N)
Definition: Type.cpp:242
llvm::inconvertibleErrorCode
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
Definition: Error.cpp:79
llvm::ms_demangle::QualifierMangleMode::Mangle
@ Mangle
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:155
GlobalVariable.h
llvm::orc::ExecutionSession
An ExecutionSession represents a running JIT program.
Definition: Core.h:1365
llvm::orc::absoluteSymbols
std::unique_ptr< AbsoluteSymbolsMaterializationUnit > absoluteSymbols(SymbolMap Symbols)
Create an AbsoluteSymbolsMaterializationUnit with the given symbols.
Definition: Core.h:763
llvm::GlobalValue::ExternalLinkage
@ ExternalLinkage
Externally visible function.
Definition: GlobalValue.h:48
llvm::Type::getVoidTy
static Type * getVoidTy(LLVMContext &C)
Definition: Type.cpp:221
llvm::orc::LLJIT::Main
JITDylib * Main
Definition: LLJIT.h:205
llvm::orc::JITDylib::define
Error define(std::unique_ptr< MaterializationUnitType > &&MU, ResourceTrackerSP RT=nullptr)
Define all symbols provided by the materialization unit to be part of this JITDylib.
Definition: Core.h:1806
SectionMemoryManager.h
ExecutorProcessControl.h
llvm::reverse
auto reverse(ContainerTy &&C)
Definition: STLExtras.h:485
ObjectLinkingLayer.h
llvm::orc::ThreadSafeModule
An LLVM Module together with a shared ThreadSafeContext.
Definition: ThreadSafeModule.h:77
TM
const char LLVMTargetMachineRef TM
Definition: PassBuilderBindings.cpp:47
llvm::orc::LLJIT::applyDataLayout
Error applyDataLayout(Module &M)
Definition: LLJIT.cpp:922
llvm::orc::setUpInactivePlatform
Error setUpInactivePlatform(LLJIT &J)
Configure the LLJIT instance to disable platform support explicitly.
Definition: LLJIT.cpp:949
llvm::orc::shared::SPSString
SPSSequence< char > SPSString
SPS tag type for strings, which are equivalent to sequences of chars.
Definition: SimplePackedSerialization.h:208
llvm::orc::JITDylibLookupFlags::MatchAllSymbols
@ MatchAllSymbols
llvm::FunctionType::getReturnType
Type * getReturnType() const
Definition: DerivedTypes.h:124
OrcError.h
llvm::orc::LLJIT::ObjLinkingLayer
std::unique_ptr< ObjectLayer > ObjLinkingLayer
Definition: LLJIT.h:211
llvm::orc::makeJITDylibSearchOrder
JITDylibSearchOrder makeJITDylibSearchOrder(ArrayRef< JITDylib * > JDs, JITDylibLookupFlags Flags=JITDylibLookupFlags::MatchExportedSymbolsOnly)
Convenience function for creating a search order from an ArrayRef of JITDylib*, all with the same fla...
Definition: Core.h:158
llvm::Triple::aarch64
@ aarch64
Definition: Triple.h:51
llvm::orc::LLJIT::getExecutionSession
ExecutionSession & getExecutionSession()
Returns the ExecutionSession for this instance.
Definition: LLJIT.h:62
llvm::JITSymbolFlags::Exported
@ Exported
Definition: JITSymbol.h:85
llvm::FunctionType
Class to represent function types.
Definition: DerivedTypes.h:103
llvm::orc::LLJIT::getDataLayout
const DataLayout & getDataLayout() const
Returns a reference to the DataLayout for this instance.
Definition: LLJIT.h:68