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