LLVM  15.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 
19 #include "llvm/IR/GlobalVariable.h"
20 #include "llvm/IR/IRBuilder.h"
21 #include "llvm/IR/Mangler.h"
22 #include "llvm/IR/Module.h"
24 
25 #include <map>
26 
27 #define DEBUG_TYPE "orc"
28 
29 using namespace llvm;
30 using namespace llvm::orc;
31 
32 namespace {
33 
34 /// Adds helper function decls and wrapper functions that call the helper with
35 /// some additional prefix arguments.
36 ///
37 /// E.g. For wrapper "foo" with type i8(i8, i64), helper "bar", and prefix
38 /// args i32 4 and i16 12345, this function will add:
39 ///
40 /// declare i8 @bar(i32, i16, i8, i64)
41 ///
42 /// define i8 @foo(i8, i64) {
43 /// entry:
44 /// %2 = call i8 @bar(i32 4, i16 12345, i8 %0, i64 %1)
45 /// ret i8 %2
46 /// }
47 ///
48 Function *addHelperAndWrapper(Module &M, StringRef WrapperName,
49  FunctionType *WrapperFnType,
50  GlobalValue::VisibilityTypes WrapperVisibility,
51  StringRef HelperName,
52  ArrayRef<Value *> HelperPrefixArgs) {
53  std::vector<Type *> HelperArgTypes;
54  for (auto *Arg : HelperPrefixArgs)
55  HelperArgTypes.push_back(Arg->getType());
56  for (auto *T : WrapperFnType->params())
57  HelperArgTypes.push_back(T);
58  auto *HelperFnType =
59  FunctionType::get(WrapperFnType->getReturnType(), HelperArgTypes, false);
60  auto *HelperFn = Function::Create(HelperFnType, GlobalValue::ExternalLinkage,
61  HelperName, M);
62 
63  auto *WrapperFn = Function::Create(
64  WrapperFnType, GlobalValue::ExternalLinkage, WrapperName, M);
65  WrapperFn->setVisibility(WrapperVisibility);
66 
67  auto *EntryBlock = BasicBlock::Create(M.getContext(), "entry", WrapperFn);
68  IRBuilder<> IB(EntryBlock);
69 
70  std::vector<Value *> HelperArgs;
71  for (auto *Arg : HelperPrefixArgs)
72  HelperArgs.push_back(Arg);
73  for (auto &Arg : WrapperFn->args())
74  HelperArgs.push_back(&Arg);
75  auto *HelperResult = IB.CreateCall(HelperFn, HelperArgs);
76  if (HelperFn->getReturnType()->isVoidTy())
77  IB.CreateRetVoid();
78  else
79  IB.CreateRet(HelperResult);
80 
81  return WrapperFn;
82 }
83 
84 class GenericLLVMIRPlatformSupport;
85 
86 /// orc::Platform component of Generic LLVM IR Platform support.
87 /// Just forwards calls to the GenericLLVMIRPlatformSupport class below.
88 class GenericLLVMIRPlatform : public Platform {
89 public:
90  GenericLLVMIRPlatform(GenericLLVMIRPlatformSupport &S) : S(S) {}
91  Error setupJITDylib(JITDylib &JD) override;
92  Error teardownJITDylib(JITDylib &JD) override;
93  Error notifyAdding(ResourceTracker &RT,
94  const MaterializationUnit &MU) override;
95  Error notifyRemoving(ResourceTracker &RT) override {
96  // Noop -- Nothing to do (yet).
97  return Error::success();
98  }
99 
100 private:
101  GenericLLVMIRPlatformSupport &S;
102 };
103 
104 /// This transform parses llvm.global_ctors to produce a single initialization
105 /// function for the module, records the function, then deletes
106 /// llvm.global_ctors.
107 class GlobalCtorDtorScraper {
108 public:
109  GlobalCtorDtorScraper(GenericLLVMIRPlatformSupport &PS,
110  StringRef InitFunctionPrefix,
111  StringRef DeInitFunctionPrefix)
112  : PS(PS), InitFunctionPrefix(InitFunctionPrefix),
113  DeInitFunctionPrefix(DeInitFunctionPrefix) {}
116 
117 private:
118  GenericLLVMIRPlatformSupport &PS;
119  StringRef InitFunctionPrefix;
120  StringRef DeInitFunctionPrefix;
121 };
122 
123 /// Generic IR Platform Support
124 ///
125 /// Scrapes llvm.global_ctors and llvm.global_dtors and replaces them with
126 /// specially named 'init' and 'deinit'. Injects definitions / interposes for
127 /// some runtime API, including __cxa_atexit, dlopen, and dlclose.
128 class GenericLLVMIRPlatformSupport : public LLJIT::PlatformSupport {
129 public:
130  GenericLLVMIRPlatformSupport(LLJIT &J)
131  : J(J), InitFunctionPrefix(J.mangle("__orc_init_func.")),
132  DeInitFunctionPrefix(J.mangle("__orc_deinit_func.")) {
133 
134  getExecutionSession().setPlatform(
135  std::make_unique<GenericLLVMIRPlatform>(*this));
136 
137  setInitTransform(J, GlobalCtorDtorScraper(*this, InitFunctionPrefix,
138  DeInitFunctionPrefix));
139 
140  SymbolMap StdInterposes;
141 
142  StdInterposes[J.mangleAndIntern("__lljit.platform_support_instance")] =
145  StdInterposes[J.mangleAndIntern("__lljit.cxa_atexit_helper")] =
146  JITEvaluatedSymbol(pointerToJITTargetAddress(registerAtExitHelper),
147  JITSymbolFlags());
148 
149  cantFail(
150  J.getMainJITDylib().define(absoluteSymbols(std::move(StdInterposes))));
151  cantFail(setupJITDylib(J.getMainJITDylib()));
152  cantFail(J.addIRModule(J.getMainJITDylib(), createPlatformRuntimeModule()));
153  }
154 
155  ExecutionSession &getExecutionSession() { return J.getExecutionSession(); }
156 
157  /// Adds a module that defines the __dso_handle global.
158  Error setupJITDylib(JITDylib &JD) {
159 
160  // Add per-jitdylib standard interposes.
161  SymbolMap PerJDInterposes;
162  PerJDInterposes[J.mangleAndIntern("__lljit.run_atexits_helper")] =
164  JITSymbolFlags());
165  cantFail(JD.define(absoluteSymbols(std::move(PerJDInterposes))));
166 
167  auto Ctx = std::make_unique<LLVMContext>();
168  auto M = std::make_unique<Module>("__standard_lib", *Ctx);
169  M->setDataLayout(J.getDataLayout());
170 
171  auto *Int64Ty = Type::getInt64Ty(*Ctx);
172  auto *DSOHandle = new GlobalVariable(
173  *M, Int64Ty, true, GlobalValue::ExternalLinkage,
174  ConstantInt::get(Int64Ty, reinterpret_cast<uintptr_t>(&JD)),
175  "__dso_handle");
176  DSOHandle->setVisibility(GlobalValue::DefaultVisibility);
177  DSOHandle->setInitializer(
179 
180  auto *GenericIRPlatformSupportTy =
181  StructType::create(*Ctx, "lljit.GenericLLJITIRPlatformSupport");
182 
183  auto *PlatformInstanceDecl = new GlobalVariable(
184  *M, GenericIRPlatformSupportTy, true, GlobalValue::ExternalLinkage,
185  nullptr, "__lljit.platform_support_instance");
186 
187  auto *VoidTy = Type::getVoidTy(*Ctx);
188  addHelperAndWrapper(
189  *M, "__lljit_run_atexits", FunctionType::get(VoidTy, {}, false),
190  GlobalValue::HiddenVisibility, "__lljit.run_atexits_helper",
191  {PlatformInstanceDecl, DSOHandle});
192 
193  return J.addIRModule(JD, ThreadSafeModule(std::move(M), std::move(Ctx)));
194  }
195 
196  Error notifyAdding(ResourceTracker &RT, const MaterializationUnit &MU) {
197  auto &JD = RT.getJITDylib();
198  if (auto &InitSym = MU.getInitializerSymbol())
199  InitSymbols[&JD].add(InitSym, SymbolLookupFlags::WeaklyReferencedSymbol);
200  else {
201  // If there's no identified init symbol attached, but there is a symbol
202  // with the GenericIRPlatform::InitFunctionPrefix, then treat that as
203  // an init function. Add the symbol to both the InitSymbols map (which
204  // will trigger a lookup to materialize the module) and the InitFunctions
205  // map (which holds the names of the symbols to execute).
206  for (auto &KV : MU.getSymbols())
207  if ((*KV.first).startswith(InitFunctionPrefix)) {
208  InitSymbols[&JD].add(KV.first,
210  InitFunctions[&JD].add(KV.first);
211  } else if ((*KV.first).startswith(DeInitFunctionPrefix)) {
212  DeInitFunctions[&JD].add(KV.first);
213  }
214  }
215  return Error::success();
216  }
217 
218  Error initialize(JITDylib &JD) override {
219  LLVM_DEBUG({
220  dbgs() << "GenericLLVMIRPlatformSupport getting initializers to run\n";
221  });
222  if (auto Initializers = getInitializers(JD)) {
223  LLVM_DEBUG(
224  { dbgs() << "GenericLLVMIRPlatformSupport running initializers\n"; });
225  for (auto InitFnAddr : *Initializers) {
226  LLVM_DEBUG({
227  dbgs() << " Running init " << formatv("{0:x16}", InitFnAddr)
228  << "...\n";
229  });
230  auto *InitFn = jitTargetAddressToFunction<void (*)()>(InitFnAddr);
231  InitFn();
232  }
233  } else
234  return Initializers.takeError();
235  return Error::success();
236  }
237 
238  Error deinitialize(JITDylib &JD) override {
239  LLVM_DEBUG({
240  dbgs() << "GenericLLVMIRPlatformSupport getting deinitializers to run\n";
241  });
242  if (auto Deinitializers = getDeinitializers(JD)) {
243  LLVM_DEBUG({
244  dbgs() << "GenericLLVMIRPlatformSupport running deinitializers\n";
245  });
246  for (auto DeinitFnAddr : *Deinitializers) {
247  LLVM_DEBUG({
248  dbgs() << " Running deinit " << formatv("{0:x16}", DeinitFnAddr)
249  << "...\n";
250  });
251  auto *DeinitFn = jitTargetAddressToFunction<void (*)()>(DeinitFnAddr);
252  DeinitFn();
253  }
254  } else
255  return Deinitializers.takeError();
256 
257  return Error::success();
258  }
259 
260  void registerInitFunc(JITDylib &JD, SymbolStringPtr InitName) {
261  getExecutionSession().runSessionLocked([&]() {
262  InitFunctions[&JD].add(InitName);
263  });
264  }
265 
266  void registerDeInitFunc(JITDylib &JD, SymbolStringPtr DeInitName) {
267  getExecutionSession().runSessionLocked(
268  [&]() { DeInitFunctions[&JD].add(DeInitName); });
269  }
270 
271 private:
272 
273  Expected<std::vector<JITTargetAddress>> getInitializers(JITDylib &JD) {
274  if (auto Err = issueInitLookups(JD))
275  return std::move(Err);
276 
278  std::vector<JITDylibSP> DFSLinkOrder;
279 
280  if (auto Err = getExecutionSession().runSessionLocked([&]() -> Error {
281  if (auto DFSLinkOrderOrErr = JD.getDFSLinkOrder())
282  DFSLinkOrder = std::move(*DFSLinkOrderOrErr);
283  else
284  return DFSLinkOrderOrErr.takeError();
285 
286  for (auto &NextJD : DFSLinkOrder) {
287  auto IFItr = InitFunctions.find(NextJD.get());
288  if (IFItr != InitFunctions.end()) {
289  LookupSymbols[NextJD.get()] = std::move(IFItr->second);
290  InitFunctions.erase(IFItr);
291  }
292  }
293  return Error::success();
294  }))
295  return std::move(Err);
296 
297  LLVM_DEBUG({
298  dbgs() << "JITDylib init order is [ ";
299  for (auto &JD : llvm::reverse(DFSLinkOrder))
300  dbgs() << "\"" << JD->getName() << "\" ";
301  dbgs() << "]\n";
302  dbgs() << "Looking up init functions:\n";
303  for (auto &KV : LookupSymbols)
304  dbgs() << " \"" << KV.first->getName() << "\": " << KV.second << "\n";
305  });
306 
307  auto &ES = getExecutionSession();
308  auto LookupResult = Platform::lookupInitSymbols(ES, LookupSymbols);
309 
310  if (!LookupResult)
311  return LookupResult.takeError();
312 
313  std::vector<JITTargetAddress> Initializers;
314  while (!DFSLinkOrder.empty()) {
315  auto &NextJD = *DFSLinkOrder.back();
316  DFSLinkOrder.pop_back();
317  auto InitsItr = LookupResult->find(&NextJD);
318  if (InitsItr == LookupResult->end())
319  continue;
320  for (auto &KV : InitsItr->second)
321  Initializers.push_back(KV.second.getAddress());
322  }
323 
324  return Initializers;
325  }
326 
327  Expected<std::vector<JITTargetAddress>> getDeinitializers(JITDylib &JD) {
328  auto &ES = getExecutionSession();
329 
330  auto LLJITRunAtExits = J.mangleAndIntern("__lljit_run_atexits");
331 
333  std::vector<JITDylibSP> DFSLinkOrder;
334 
335  if (auto Err = ES.runSessionLocked([&]() -> Error {
336  if (auto DFSLinkOrderOrErr = JD.getDFSLinkOrder())
337  DFSLinkOrder = std::move(*DFSLinkOrderOrErr);
338  else
339  return DFSLinkOrderOrErr.takeError();
340 
341  for (auto &NextJD : DFSLinkOrder) {
342  auto &JDLookupSymbols = LookupSymbols[NextJD.get()];
343  auto DIFItr = DeInitFunctions.find(NextJD.get());
344  if (DIFItr != DeInitFunctions.end()) {
345  LookupSymbols[NextJD.get()] = std::move(DIFItr->second);
346  DeInitFunctions.erase(DIFItr);
347  }
348  JDLookupSymbols.add(LLJITRunAtExits,
349  SymbolLookupFlags::WeaklyReferencedSymbol);
350  }
351  return Error::success();
352  }))
353  return std::move(Err);
354 
355  LLVM_DEBUG({
356  dbgs() << "JITDylib deinit order is [ ";
357  for (auto &JD : DFSLinkOrder)
358  dbgs() << "\"" << JD->getName() << "\" ";
359  dbgs() << "]\n";
360  dbgs() << "Looking up deinit functions:\n";
361  for (auto &KV : LookupSymbols)
362  dbgs() << " \"" << KV.first->getName() << "\": " << KV.second << "\n";
363  });
364 
365  auto LookupResult = Platform::lookupInitSymbols(ES, LookupSymbols);
366 
367  if (!LookupResult)
368  return LookupResult.takeError();
369 
370  std::vector<JITTargetAddress> DeInitializers;
371  for (auto &NextJD : DFSLinkOrder) {
372  auto DeInitsItr = LookupResult->find(NextJD.get());
373  assert(DeInitsItr != LookupResult->end() &&
374  "Every JD should have at least __lljit_run_atexits");
375 
376  auto RunAtExitsItr = DeInitsItr->second.find(LLJITRunAtExits);
377  if (RunAtExitsItr != DeInitsItr->second.end())
378  DeInitializers.push_back(RunAtExitsItr->second.getAddress());
379 
380  for (auto &KV : DeInitsItr->second)
381  if (KV.first != LLJITRunAtExits)
382  DeInitializers.push_back(KV.second.getAddress());
383  }
384 
385  return DeInitializers;
386  }
387 
388  /// Issue lookups for all init symbols required to initialize JD (and any
389  /// JITDylibs that it depends on).
390  Error issueInitLookups(JITDylib &JD) {
391  DenseMap<JITDylib *, SymbolLookupSet> RequiredInitSymbols;
392  std::vector<JITDylibSP> DFSLinkOrder;
393 
394  if (auto Err = getExecutionSession().runSessionLocked([&]() -> Error {
395  if (auto DFSLinkOrderOrErr = JD.getDFSLinkOrder())
396  DFSLinkOrder = std::move(*DFSLinkOrderOrErr);
397  else
398  return DFSLinkOrderOrErr.takeError();
399 
400  for (auto &NextJD : DFSLinkOrder) {
401  auto ISItr = InitSymbols.find(NextJD.get());
402  if (ISItr != InitSymbols.end()) {
403  RequiredInitSymbols[NextJD.get()] = std::move(ISItr->second);
404  InitSymbols.erase(ISItr);
405  }
406  }
407  return Error::success();
408  }))
409  return Err;
410 
411  return Platform::lookupInitSymbols(getExecutionSession(),
412  RequiredInitSymbols)
413  .takeError();
414  }
415 
416  static void registerAtExitHelper(void *Self, void (*F)(void *), void *Ctx,
417  void *DSOHandle) {
418  LLVM_DEBUG({
419  dbgs() << "Registering atexit function " << (void *)F << " for JD "
420  << (*static_cast<JITDylib **>(DSOHandle))->getName() << "\n";
421  });
422  static_cast<GenericLLVMIRPlatformSupport *>(Self)->AtExitMgr.registerAtExit(
423  F, Ctx, DSOHandle);
424  }
425 
426  static void runAtExitsHelper(void *Self, void *DSOHandle) {
427  LLVM_DEBUG({
428  dbgs() << "Running atexit functions for JD "
429  << (*static_cast<JITDylib **>(DSOHandle))->getName() << "\n";
430  });
431  static_cast<GenericLLVMIRPlatformSupport *>(Self)->AtExitMgr.runAtExits(
432  DSOHandle);
433  }
434 
435  // Constructs an LLVM IR module containing platform runtime globals,
436  // functions, and interposes.
437  ThreadSafeModule createPlatformRuntimeModule() {
438  auto Ctx = std::make_unique<LLVMContext>();
439  auto M = std::make_unique<Module>("__standard_lib", *Ctx);
440  M->setDataLayout(J.getDataLayout());
441 
442  auto *GenericIRPlatformSupportTy =
443  StructType::create(*Ctx, "lljit.GenericLLJITIRPlatformSupport");
444 
445  auto *PlatformInstanceDecl = new GlobalVariable(
446  *M, GenericIRPlatformSupportTy, true, GlobalValue::ExternalLinkage,
447  nullptr, "__lljit.platform_support_instance");
448 
449  auto *Int8Ty = Type::getInt8Ty(*Ctx);
450  auto *IntTy = Type::getIntNTy(*Ctx, sizeof(int) * CHAR_BIT);
451  auto *VoidTy = Type::getVoidTy(*Ctx);
452  auto *BytePtrTy = PointerType::getUnqual(Int8Ty);
453  auto *AtExitCallbackTy = FunctionType::get(VoidTy, {BytePtrTy}, false);
454  auto *AtExitCallbackPtrTy = PointerType::getUnqual(AtExitCallbackTy);
455 
456  addHelperAndWrapper(
457  *M, "__cxa_atexit",
458  FunctionType::get(IntTy, {AtExitCallbackPtrTy, BytePtrTy, BytePtrTy},
459  false),
460  GlobalValue::DefaultVisibility, "__lljit.cxa_atexit_helper",
461  {PlatformInstanceDecl});
462 
463  return ThreadSafeModule(std::move(M), std::move(Ctx));
464  }
465 
466  LLJIT &J;
467  std::string InitFunctionPrefix;
468  std::string DeInitFunctionPrefix;
472  ItaniumCXAAtExitSupport AtExitMgr;
473 };
474 
475 Error GenericLLVMIRPlatform::setupJITDylib(JITDylib &JD) {
476  return S.setupJITDylib(JD);
477 }
478 
479 Error GenericLLVMIRPlatform::teardownJITDylib(JITDylib &JD) {
480  return Error::success();
481 }
482 
483 Error GenericLLVMIRPlatform::notifyAdding(ResourceTracker &RT,
484  const MaterializationUnit &MU) {
485  return S.notifyAdding(RT, MU);
486 }
487 
489 GlobalCtorDtorScraper::operator()(ThreadSafeModule TSM,
491  auto Err = TSM.withModuleDo([&](Module &M) -> Error {
492  auto &Ctx = M.getContext();
493  auto *GlobalCtors = M.getNamedGlobal("llvm.global_ctors");
494  auto *GlobalDtors = M.getNamedGlobal("llvm.global_dtors");
495 
496  auto RegisterCOrDtors = [&](GlobalVariable *GlobalCOrDtors,
497  bool isCtor) -> Error {
498  // If there's no llvm.global_c/dtor or it's just a decl then skip.
499  if (!GlobalCOrDtors || GlobalCOrDtors->isDeclaration())
500  return Error::success();
501  std::string InitOrDeInitFunctionName;
502  if (isCtor)
503  raw_string_ostream(InitOrDeInitFunctionName)
504  << InitFunctionPrefix << M.getModuleIdentifier();
505  else
506  raw_string_ostream(InitOrDeInitFunctionName)
507  << DeInitFunctionPrefix << M.getModuleIdentifier();
508 
509  MangleAndInterner Mangle(PS.getExecutionSession(), M.getDataLayout());
510  auto InternedInitOrDeInitName = Mangle(InitOrDeInitFunctionName);
511  if (auto Err = R.defineMaterializing(
512  {{InternedInitOrDeInitName, JITSymbolFlags::Callable}}))
513  return Err;
514 
515  auto *InitOrDeInitFunc = Function::Create(
516  FunctionType::get(Type::getVoidTy(Ctx), {}, false),
517  GlobalValue::ExternalLinkage, InitOrDeInitFunctionName, &M);
518  InitOrDeInitFunc->setVisibility(GlobalValue::HiddenVisibility);
519  std::vector<std::pair<Function *, unsigned>> InitsOrDeInits;
520  auto COrDtors = isCtor ? getConstructors(M) : getDestructors(M);
521 
522  for (auto E : COrDtors)
523  InitsOrDeInits.push_back(std::make_pair(E.Func, E.Priority));
524  llvm::sort(InitsOrDeInits,
525  [](const std::pair<Function *, unsigned> &LHS,
526  const std::pair<Function *, unsigned> &RHS) {
527  return LHS.second < RHS.second;
528  });
529 
530  auto *InitOrDeInitFuncEntryBlock =
531  BasicBlock::Create(Ctx, "entry", InitOrDeInitFunc);
532  IRBuilder<> IB(InitOrDeInitFuncEntryBlock);
533  for (auto &KV : InitsOrDeInits)
534  IB.CreateCall(KV.first);
535  IB.CreateRetVoid();
536 
537  if (isCtor)
538  PS.registerInitFunc(R.getTargetJITDylib(), InternedInitOrDeInitName);
539  else
540  PS.registerDeInitFunc(R.getTargetJITDylib(), InternedInitOrDeInitName);
541 
542  GlobalCOrDtors->eraseFromParent();
543  return Error::success();
544  };
545 
546  if (auto Err = RegisterCOrDtors(GlobalCtors, true))
547  return Err;
548  if (auto Err = RegisterCOrDtors(GlobalDtors, false))
549  return Err;
550 
551  return Error::success();
552  });
553 
554  if (Err)
555  return std::move(Err);
556 
557  return std::move(TSM);
558 }
559 
560 /// Inactive Platform Support
561 ///
562 /// Explicitly disables platform support. JITDylibs are not scanned for special
563 /// init/deinit symbols. No runtime API interposes are injected.
564 class InactivePlatformSupport : public LLJIT::PlatformSupport {
565 public:
566  InactivePlatformSupport() = default;
567 
568  Error initialize(JITDylib &JD) override {
569  LLVM_DEBUG(dbgs() << "InactivePlatformSupport: no initializers running for "
570  << JD.getName() << "\n");
571  return Error::success();
572  }
573 
574  Error deinitialize(JITDylib &JD) override {
575  LLVM_DEBUG(
576  dbgs() << "InactivePlatformSupport: no deinitializers running for "
577  << JD.getName() << "\n");
578  return Error::success();
579  }
580 };
581 
582 } // end anonymous namespace
583 
584 namespace llvm {
585 namespace orc {
586 
589  J.InitHelperTransformLayer->setTransform(std::move(T));
590 }
591 
593 
595 
596  LLVM_DEBUG(dbgs() << "Preparing to create LLJIT instance...\n");
597 
598  if (!JTMB) {
599  LLVM_DEBUG({
600  dbgs() << " No explicitly set JITTargetMachineBuilder. "
601  "Detecting host...\n";
602  });
603  if (auto JTMBOrErr = JITTargetMachineBuilder::detectHost())
604  JTMB = std::move(*JTMBOrErr);
605  else
606  return JTMBOrErr.takeError();
607  }
608 
609  LLVM_DEBUG({
610  dbgs() << " JITTargetMachineBuilder is "
611  << JITTargetMachineBuilderPrinter(*JTMB, " ")
612  << " Pre-constructed ExecutionSession: " << (ES ? "Yes" : "No")
613  << "\n"
614  << " DataLayout: ";
615  if (DL)
616  dbgs() << DL->getStringRepresentation() << "\n";
617  else
618  dbgs() << "None (will be created by JITTargetMachineBuilder)\n";
619 
620  dbgs() << " Custom object-linking-layer creator: "
621  << (CreateObjectLinkingLayer ? "Yes" : "No") << "\n"
622  << " Custom compile-function creator: "
623  << (CreateCompileFunction ? "Yes" : "No") << "\n"
624  << " Custom platform-setup function: "
625  << (SetUpPlatform ? "Yes" : "No") << "\n"
626  << " Number of compile threads: " << NumCompileThreads;
627  if (!NumCompileThreads)
628  dbgs() << " (code will be compiled on the execution thread)\n";
629  else
630  dbgs() << "\n";
631  });
632 
633  // If neither ES nor EPC has been set then create an EPC instance.
634  if (!ES && !EPC) {
635  LLVM_DEBUG({
636  dbgs() << "ExecutorProcessControl not specified, "
637  "Creating SelfExecutorProcessControl instance\n";
638  });
639  if (auto EPCOrErr = SelfExecutorProcessControl::Create())
640  EPC = std::move(*EPCOrErr);
641  else
642  return EPCOrErr.takeError();
643  } else
644  LLVM_DEBUG({
645  dbgs() << "Using explicitly specified ExecutorProcessControl instance "
646  << EPC.get() << "\n";
647  });
648 
649  // If the client didn't configure any linker options then auto-configure the
650  // JIT linker.
651  if (!CreateObjectLinkingLayer) {
652  auto &TT = JTMB->getTargetTriple();
653  if (TT.isOSBinFormatMachO() &&
655 
656  JTMB->setRelocationModel(Reloc::PIC_);
657  JTMB->setCodeModel(CodeModel::Small);
658  CreateObjectLinkingLayer =
659  [](ExecutionSession &ES,
660  const Triple &) -> Expected<std::unique_ptr<ObjectLayer>> {
661  auto ObjLinkingLayer = std::make_unique<ObjectLinkingLayer>(ES);
662  ObjLinkingLayer->addPlugin(std::make_unique<EHFrameRegistrationPlugin>(
663  ES, std::make_unique<jitlink::InProcessEHFrameRegistrar>()));
664  return std::move(ObjLinkingLayer);
665  };
666  }
667  }
668 
669  return Error::success();
670 }
671 
673  if (CompileThreads)
674  CompileThreads->wait();
675  if (auto Err = ES->endSession())
676  ES->reportError(std::move(Err));
677 }
678 
680  assert(TSM && "Can not add null module");
681 
682  if (auto Err =
683  TSM.withModuleDo([&](Module &M) { return applyDataLayout(M); }))
684  return Err;
685 
686  return InitHelperTransformLayer->add(std::move(RT), std::move(TSM));
687 }
688 
691 }
692 
694  std::unique_ptr<MemoryBuffer> Obj) {
695  assert(Obj && "Can not add null object");
696 
697  return ObjTransformLayer->add(std::move(RT), std::move(Obj));
698 }
699 
700 Error LLJIT::addObjectFile(JITDylib &JD, std::unique_ptr<MemoryBuffer> Obj) {
702 }
703 
706  if (auto Sym = ES->lookup(
708  Name))
709  return ExecutorAddr(Sym->getAddress());
710  else
711  return Sym.takeError();
712 }
713 
716 
717  // If the config state provided an ObjectLinkingLayer factory then use it.
718  if (S.CreateObjectLinkingLayer)
719  return S.CreateObjectLinkingLayer(ES, S.JTMB->getTargetTriple());
720 
721  // Otherwise default to creating an RTDyldObjectLinkingLayer that constructs
722  // a new SectionMemoryManager for each object.
723  auto GetMemMgr = []() { return std::make_unique<SectionMemoryManager>(); };
724  auto Layer =
725  std::make_unique<RTDyldObjectLinkingLayer>(ES, std::move(GetMemMgr));
726 
727  if (S.JTMB->getTargetTriple().isOSBinFormatCOFF()) {
728  Layer->setOverrideObjectFlagsWithResponsibilityFlags(true);
729  Layer->setAutoClaimResponsibilityForObjectSymbols(true);
730  }
731 
732  // FIXME: Explicit conversion to std::unique_ptr<ObjectLayer> added to silence
733  // errors from some GCC / libstdc++ bots. Remove this conversion (i.e.
734  // just return ObjLinkingLayer) once those bots are upgraded.
735  return std::unique_ptr<ObjectLayer>(std::move(Layer));
736 }
737 
741 
742  /// If there is a custom compile function creator set then use it.
743  if (S.CreateCompileFunction)
744  return S.CreateCompileFunction(std::move(JTMB));
745 
746  // Otherwise default to creating a SimpleCompiler, or ConcurrentIRCompiler,
747  // depending on the number of threads requested.
748  if (S.NumCompileThreads > 0)
749  return std::make_unique<ConcurrentIRCompiler>(std::move(JTMB));
750 
751  auto TM = JTMB.createTargetMachine();
752  if (!TM)
753  return TM.takeError();
754 
755  return std::make_unique<TMOwningSimpleCompiler>(std::move(*TM));
756 }
757 
759  : DL(""), TT(S.JTMB->getTargetTriple()) {
760 
761  ErrorAsOutParameter _(&Err);
762 
763  assert(!(S.EPC && S.ES) && "EPC and ES should not both be set");
764 
765  if (S.EPC) {
766  ES = std::make_unique<ExecutionSession>(std::move(S.EPC));
767  } else if (S.ES)
768  ES = std::move(S.ES);
769  else {
770  if (auto EPC = SelfExecutorProcessControl::Create()) {
771  ES = std::make_unique<ExecutionSession>(std::move(*EPC));
772  } else {
773  Err = EPC.takeError();
774  return;
775  }
776  }
777 
778  if (auto MainOrErr = this->ES->createJITDylib("main"))
779  Main = &*MainOrErr;
780  else {
781  Err = MainOrErr.takeError();
782  return;
783  }
784 
785  if (S.DL)
786  DL = std::move(*S.DL);
787  else if (auto DLOrErr = S.JTMB->getDefaultDataLayoutForTarget())
788  DL = std::move(*DLOrErr);
789  else {
790  Err = DLOrErr.takeError();
791  return;
792  }
793 
794  auto ObjLayer = createObjectLinkingLayer(S, *ES);
795  if (!ObjLayer) {
796  Err = ObjLayer.takeError();
797  return;
798  }
799  ObjLinkingLayer = std::move(*ObjLayer);
801  std::make_unique<ObjectTransformLayer>(*ES, *ObjLinkingLayer);
802 
803  {
804  auto CompileFunction = createCompileFunction(S, std::move(*S.JTMB));
805  if (!CompileFunction) {
806  Err = CompileFunction.takeError();
807  return;
808  }
809  CompileLayer = std::make_unique<IRCompileLayer>(
810  *ES, *ObjTransformLayer, std::move(*CompileFunction));
811  TransformLayer = std::make_unique<IRTransformLayer>(*ES, *CompileLayer);
813  std::make_unique<IRTransformLayer>(*ES, *TransformLayer);
814  }
815 
816  if (S.NumCompileThreads > 0) {
817  InitHelperTransformLayer->setCloneToNewContextOnEmit(true);
819  std::make_unique<ThreadPool>(hardware_concurrency(S.NumCompileThreads));
820  ES->setDispatchTask([this](std::unique_ptr<Task> T) {
821  // FIXME: We should be able to use move-capture here, but ThreadPool's
822  // AsyncTaskTys are std::functions rather than unique_functions
823  // (because MSVC's std::packaged_tasks don't support move-only types).
824  // Fix this when all the above gets sorted out.
825  CompileThreads->async([UnownedT = T.release()]() mutable {
826  std::unique_ptr<Task> T(UnownedT);
827  T->run();
828  });
829  });
830  }
831 
832  if (S.SetUpPlatform)
833  Err = S.SetUpPlatform(*this);
834  else
836 }
837 
838 std::string LLJIT::mangle(StringRef UnmangledName) const {
839  std::string MangledName;
840  {
841  raw_string_ostream MangledNameStream(MangledName);
842  Mangler::getNameWithPrefix(MangledNameStream, UnmangledName, DL);
843  }
844  return MangledName;
845 }
846 
848  if (M.getDataLayout().isDefault())
849  M.setDataLayout(DL);
850 
851  if (M.getDataLayout() != DL)
852  return make_error<StringError>(
853  "Added modules have incompatible data layouts: " +
854  M.getDataLayout().getStringRepresentation() + " (module) vs " +
855  DL.getStringRepresentation() + " (jit)",
857 
858  return Error::success();
859 }
860 
862  LLVM_DEBUG(
863  { dbgs() << "Setting up GenericLLVMIRPlatform support for LLJIT\n"; });
864  J.setPlatformSupport(std::make_unique<GenericLLVMIRPlatformSupport>(J));
865 }
866 
868  LLVM_DEBUG(
869  { dbgs() << "Explicitly deactivated platform support for LLJIT\n"; });
870  J.setPlatformSupport(std::make_unique<InactivePlatformSupport>());
871  return Error::success();
872 }
873 
876  return Err;
877  TT = JTMB->getTargetTriple();
878  return Error::success();
879 }
880 
882  assert(TSM && "Can not add null module");
883 
884  if (auto Err = TSM.withModuleDo(
885  [&](Module &M) -> Error { return applyDataLayout(M); }))
886  return Err;
887 
888  return CODLayer->add(JD, std::move(TSM));
889 }
890 
891 LLLazyJIT::LLLazyJIT(LLLazyJITBuilderState &S, Error &Err) : LLJIT(S, Err) {
892 
893  // If LLJIT construction failed then bail out.
894  if (Err)
895  return;
896 
897  ErrorAsOutParameter _(&Err);
898 
899  /// Take/Create the lazy-compile callthrough manager.
900  if (S.LCTMgr)
901  LCTMgr = std::move(S.LCTMgr);
902  else {
903  if (auto LCTMgrOrErr = createLocalLazyCallThroughManager(
904  S.TT, *ES, S.LazyCompileFailureAddr.getValue()))
905  LCTMgr = std::move(*LCTMgrOrErr);
906  else {
907  Err = LCTMgrOrErr.takeError();
908  return;
909  }
910  }
911 
912  // Take/Create the indirect stubs manager builder.
913  auto ISMBuilder = std::move(S.ISMBuilder);
914 
915  // If none was provided, try to build one.
916  if (!ISMBuilder)
917  ISMBuilder = createLocalIndirectStubsManagerBuilder(S.TT);
918 
919  // No luck. Bail out.
920  if (!ISMBuilder) {
921  Err = make_error<StringError>("Could not construct "
922  "IndirectStubsManagerBuilder for target " +
923  S.TT.str(),
925  return;
926  }
927 
928  // Create the COD layer.
929  CODLayer = std::make_unique<CompileOnDemandLayer>(
930  *ES, *InitHelperTransformLayer, *LCTMgr, std::move(ISMBuilder));
931 
932  if (S.NumCompileThreads > 0)
933  CODLayer->setCloneToNewContextOnEmit(true);
934 }
935 
936 } // End namespace orc.
937 } // End namespace llvm.
llvm::orc::ExecutorAddr
Represents an address in the executor process.
Definition: ExecutorAddress.h:30
llvm::GlobalVariable::eraseFromParent
void eraseFromParent()
eraseFromParent - This method unlinks 'this' from the containing module and deletes it.
Definition: Globals.cpp:428
llvm::orc::MaterializationResponsibility
Tracks responsibility for materialization, and mediates interactions between MaterializationUnits and...
Definition: Core.h:523
getName
static StringRef getName(Value *V)
Definition: ProvenanceAnalysisEvaluator.cpp:42
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:17
llvm::orc::JITDylib
Represents a JIT'd dynamic library.
Definition: Core.h:950
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:43
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::getConstructors
iterator_range< CtorDtorIterator > getConstructors(const Module &M)
Create an iterator range over the entries of the llvm.global_ctors array.
Definition: ExecutionUtils.cpp:81
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:874
llvm::orc::LLJIT::PlatformSupport::setInitTransform
static void setInitTransform(LLJIT &J, IRTransformLayer::TransformFunction T)
Definition: LLJIT.cpp:587
llvm::raw_string_ostream
A raw_ostream that writes to an std::string.
Definition: raw_ostream.h:632
llvm::orc::JITDylib::getDefaultResourceTracker
ResourceTrackerSP getDefaultResourceTracker()
Get the default resource tracker for this JITDylib.
Definition: Core.cpp:660
llvm::orc::LLJIT::LLJIT
LLJIT(LLJITBuilderState &S, Error &Err)
Create an LLJIT instance with a single compile thread.
Definition: LLJIT.cpp:758
llvm::orc::SymbolStringPtr
Pointer to a pooled string representing a symbol name.
Definition: SymbolStringPool.h:50
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:361
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:693
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:861
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:881
llvm::reverse
auto reverse(ContainerTy &&C, std::enable_if_t< has_rbegin< ContainerTy >::value > *=nullptr)
Definition: STLExtras.h:380
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
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:116
RHS
Value * RHS
Definition: X86PartialReduction.cpp:76
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:513
llvm::Type::getInt8Ty
static IntegerType * getInt8Ty(LLVMContext &C)
Definition: Type.cpp:237
llvm::orc::LLJIT::createCompileFunction
static Expected< std::unique_ptr< IRCompileLayer::IRCompiler > > createCompileFunction(LLJITBuilderState &S, JITTargetMachineBuilder JTMB)
Definition: LLJIT.cpp:739
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:669
LLVM_DEBUG
#define LLVM_DEBUG(X)
Definition: Debug.h:101
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:240
EHFrameSupport.h
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:704
Arg
amdgpu Simplify well known AMD library false FunctionCallee Value * Arg
Definition: AMDGPULibCalls.cpp:186
llvm::orc::ResourceTracker::getJITDylib
JITDylib & getJITDylib() const
Return the JITDylib targeted by this tracker.
Definition: Core.h:68
LHS
Value * LHS
Definition: X86PartialReduction.cpp:75
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::tpctypes::LookupResult
std::vector< JITTargetAddress > LookupResult
Definition: TargetProcessControlTypes.h:119
llvm::orc::LLJIT::addIRModule
Error addIRModule(ResourceTrackerSP RT, ThreadSafeModule TSM)
Adds an IR module with the given ResourceTracker.
Definition: LLJIT.cpp:679
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:241
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:838
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::LLJIT::mangleAndIntern
SymbolStringPtr mangleAndIntern(StringRef UnmangledName) const
Returns an interned, linker-mangled version of UnmangledName.
Definition: LLJIT.h:184
llvm::orc
Definition: CompileOnDemandLayer.h:54
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:669
llvm::ErrorAsOutParameter
Helper for Errors used as out-parameters.
Definition: Error.h:1097
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:919
llvm::orc::ItaniumCXAAtExitSupport
An interface for Itanium __cxa_atexit interposer implementations.
Definition: ExecutionUtils.h:196
llvm::FunctionType::params
ArrayRef< Type * > params() const
Definition: DerivedTypes.h:130
llvm::orc::JITTargetMachineBuilder::detectHost
static Expected< JITTargetMachineBuilder > detectHost()
Create a JITTargetMachineBuilder for the host system.
Definition: JITTargetMachineBuilder.cpp:24
llvm::orc::LLJIT::createObjectLinkingLayer
static Expected< std::unique_ptr< ObjectLayer > > createObjectLinkingLayer(LLJITBuilderState &S, ExecutionSession &ES)
Definition: LLJIT.cpp:715
llvm::Triple::getArch
ArchType getArch() const
Get the parsed architecture type of this triple.
Definition: Triple.h:345
llvm::IRBuilderBase::CreateRet
ReturnInst * CreateRet(Value *V)
Create a 'ret <val>' instruction.
Definition: IRBuilder.h:959
llvm::orc::SymbolLookupFlags::WeaklyReferencedSymbol
@ WeaklyReferencedSymbol
RTDyldObjectLinkingLayer.h
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:87
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:702
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< SymbolStringPtr, JITEvaluatedSymbol >
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:861
llvm::orc::MaterializationUnit::getSymbols
const SymbolFlagsMap & getSymbols() const
Return the set of symbols that this source provides.
Definition: Core.h:699
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::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:672
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:58
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:1306
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:745
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
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::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:594
llvm::orc::LLJIT::TransformLayer
std::unique_ptr< IRTransformLayer > TransformLayer
Definition: LLJIT.h:214
llvm::Type::getInt64Ty
static IntegerType * getInt64Ty(LLVMContext &C)
Definition: Type.cpp:240
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:50
llvm::Type::getIntNTy
static IntegerType * getIntNTy(LLVMContext &C, unsigned N)
Definition: Type.cpp:243
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:77
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:1362
llvm::sort
void sort(IteratorTy Start, IteratorTy End)
Definition: STLExtras.h:1552
llvm::orc::absoluteSymbols
std::unique_ptr< AbsoluteSymbolsMaterializationUnit > absoluteSymbols(SymbolMap Symbols)
Create an AbsoluteSymbolsMaterializationUnit with the given symbols.
Definition: Core.h:760
llvm::GlobalValue::ExternalLinkage
@ ExternalLinkage
Externally visible function.
Definition: GlobalValue.h:48
llvm::Type::getVoidTy
static Type * getVoidTy(LLVMContext &C)
Definition: Type.cpp:222
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:1803
SectionMemoryManager.h
llvm::IRBuilderBase::CreateRetVoid
ReturnInst * CreateRetVoid()
Create a 'ret void' instruction.
Definition: IRBuilder.h:954
ExecutorProcessControl.h
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:847
llvm::orc::setUpInactivePlatform
Error setUpInactivePlatform(LLJIT &J)
Configure the LLJIT instance to disable platform support explicitly.
Definition: LLJIT.cpp:867
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::IRBuilderBase::CreateCall
CallInst * CreateCall(FunctionType *FTy, Value *Callee, ArrayRef< Value * > Args=None, const Twine &Name="", MDNode *FPMathTag=nullptr)
Definition: IRBuilder.h:2229
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