LLVM: include/llvm/ExecutionEngine/Orc/LLJIT.h Source File (original) (raw)

1

2

3

4

5

6

7

8

9

10

11

12

13#ifndef LLVM_EXECUTIONENGINE_ORC_LLJIT_H

14#define LLVM_EXECUTIONENGINE_ORC_LLJIT_H

15

29#include

30

31namespace llvm {

32namespace orc {

33

38

39

40

41

44

46

47public:

48

50 public:

52

54

56

57 protected:

60 };

61

62

63

65

66

68

69

71

72

74

75

77

78

79

80

81

82

83 JITDylibSP getProcessSymbolsJITDylib();

84

85

86

87

88

89

91

92

93

95 return ES->getJITDylibByName(Name);

96 }

97

98

99

100

101

102

103

104

106

107

108

109

110

111

112

114 std::unique_ptr LibBuffer);

115

116

117

118

119

120

121

122 Error linkStaticLibraryInto(JITDylib &JD, const char *Path);

123

124

125

126

127

128

129

131

132

133

134

136

137

139

140

142

143

147

148

150

151

152 Error addObjectFile(JITDylib &JD, std::unique_ptr Obj);

153

154

158

159

160

163

164

165

170

171

172

173

177

178

182

183

187

188

190 this->PS = std::move(PS);

191 }

192

193

195

196

199 dbgs() << "LLJIT running initializers for JITDylib \"" << JD.getName()

200 << "\"\n";

201 });

202 assert(PS && "PlatformSupport must be set to run initializers.");

203 return PS->initialize(JD);

204 }

205

206

209 dbgs() << "LLJIT running deinitializers for JITDylib \"" << JD.getName()

210 << "\"\n";

211 });

212 assert(PS && "PlatformSupport must be set to run initializers.");

213 return PS->deinitialize(JD);

214 }

215

216

218

219

221

222

224

225

227

228

229 std::string mangle(StringRef UnmangledName) const;

230

231

233 return ES->intern(mangle(UnmangledName));

234 }

235

236protected:

239

242

243

245

247

248 std::unique_ptr ES;

249 std::unique_ptr PS;

250

254

256

259

265};

266

267

268

269class LLLazyJIT : public LLJIT {

271

272public:

273

274

276 IPLayer->setPartitionFunction(std::move(Partition));

277 }

278

279

281

282

284

285

289

290private:

291

292

294

295 std::unique_ptr LCTMgr;

296 std::unique_ptr IPLayer;

297 std::unique_ptr CODLayer;

298};

299

301public:

303 std::function<Expected<std::unique_ptr>(ExecutionSession &)>;

304

306 std::function<Expected<std::unique_ptrIRCompileLayer::IRCompiler>(

308

311

313

315

316 std::unique_ptr EPC;

317 std::unique_ptr ES;

318 std::optional JTMB;

319 std::optional DL;

329

330

332};

333

334template <typename JITType, typename SetterImpl, typename State>

336public:

337

338

339 SetterImpl &

342 impl().ES &&

343 "setExecutorProcessControl should not be called if an ExecutionSession "

344 "has already been set");

345 impl().EPC = std::move(EPC);

346 return impl();

347 }

348

349

352 impl().EPC &&

353 "setExecutionSession should not be called if an ExecutorProcessControl "

354 "object has already been set");

355 impl().ES = std::move(ES);

356 return impl();

357 }

358

359

360

361

362

364 impl().JTMB = std::move(JTMB);

365 return impl();

366 }

367

368

369

371 return impl().JTMB;

372 }

373

374

375

377 impl().DL = std::move(DL);

378 return impl();

379 }

380

381

382

383

384

385

386

388 impl().LinkProcessSymbolsByDefault = LinkProcessSymbolsByDefault;

389 return impl();

390 }

391

392

393

394

395

398 SetupProcessSymbolsJITDylib) {

399 impl().SetupProcessSymbolsJITDylib = std::move(SetupProcessSymbolsJITDylib);

400 return impl();

401 }

402

403

404

405

406

409 impl().CreateObjectLinkingLayer = std::move(CreateObjectLinkingLayer);

410 return impl();

411 }

412

413

414

415

416

417

418

421 impl().CreateCompileFunction = std::move(CreateCompileFunction);

422 return impl();

423 }

424

425

426

427

428

429

430

431

432 SetterImpl &

434 impl().PrePlatformSetup = std::move(PrePlatformSetup);

435 return impl();

436 }

437

438

439

440

441

442 SetterImpl &

444 impl().SetUpPlatform = std::move(SetUpPlatform);

445 return impl();

446 }

447

448

449

450

451

452 SetterImpl &

454 impl().NotifyCreated = std::move(Callback);

455 return impl();

456 }

457

458

459

460

461

462

463

464

465

466

467

468

469

471 impl().NumCompileThreads = NumCompileThreads;

472 return impl();

473 }

474

475

476

477

478

479

480

481

482

484 std::optional SupportConcurrentCompilation) {

485 impl().SupportConcurrentCompilation = SupportConcurrentCompilation;

486 return impl();

487 }

488

489

491 if (auto Err = impl().prepareForConstruction())

492 return std::move(Err);

493

495 std::unique_ptr J(new JITType(impl(), Err));

496 if (Err)

497 return std::move(Err);

498

499 if (impl().NotifyCreated)

500 if (Error Err = impl().NotifyCreated(*J))

501 return std::move(Err);

502

503 return std::move(J);

504 }

505

506protected:

507 SetterImpl &impl() { return static_cast<SetterImpl &>(*this); }

508};

509

510

514

517

518public:

520 std::function<std::unique_ptr()>;

521

524 std::unique_ptr LCTMgr;

526

528};

529

530template <typename JITType, typename SetterImpl, typename State>

533public:

534

535

536

538 this->impl().LazyCompileFailureAddr = Addr;

539 return this->impl();

540 }

541

542

543

544

545

546 SetterImpl &

548 this->impl().LCTMgr = std::move(LCTMgr);

549 return this->impl();

550 }

551

552

553

554

555

558 this->impl().ISMBuilder = std::move(ISMBuilder);

559 return this->impl();

560 }

561};

562

563

567 LLLazyJITBuilderState> {};

568

569

570

572

573

574

576public:

577

579 : OrcRuntime(std::move(OrcRuntimePath)) {}

580

581

583 : OrcRuntime(std::move(OrcRuntimeMB)) {}

584

585

586

587

589 bool StaticVCRuntime) {

590 VCRuntime = {std::move(VCRuntimePath), StaticVCRuntime};

591 return *this;

592 }

593

595

596private:

597 std::variant<std::string, std::unique_ptr> OrcRuntime;

598 std::optional<std::pair<std::string, bool>> VCRuntime;

599};

600

601

602

603

604

606

607

608

609

610

612

613

614

616public:

620

621private:

625};

626

627}

628}

629

630#endif

assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")

MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL

static bool lookup(const GsymReader &GR, DataExtractor &Data, uint64_t &Offset, uint64_t BaseAddr, uint64_t Addr, SourceLocations &SrcLocs, llvm::Error &Err)

A Lookup helper functions.

This file defines the SmallSet class.

#define DEBUG_WITH_TYPE(TYPE,...)

DEBUG_WITH_TYPE macro - This macro should be used by passes to emit debug information.

static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T, const llvm::StringTable &StandardNames, VectorLibrary VecLib)

Initialize the set of available library functions based on the specified target triple.

A parsed version of the target data layout string in and methods for querying it.

Lightweight error class with error context and mandatory checking.

static ErrorSuccess success()

Create a success value.

Tagged union holding either a T or a Error.

A Module instance is used to store all the information related to an LLVM module.

SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.

StringRef - Represent a constant reference to a string, i.e.

Triple - Helper class for working with autoconf configuration names.

const std::string & getName() const

Get the name for this JITLinkDylib.

An ExecutionSession represents a running JIT program.

Represents an address in the executor process.

ExecutorNativePlatform & addVCRuntime(std::string VCRuntimePath, bool StaticVCRuntime)

Add a path to the VC runtime.

Definition LLJIT.h:588

ExecutorNativePlatform(std::unique_ptr< MemoryBuffer > OrcRuntimeMB)

Set up using the given memory buffer.

Definition LLJIT.h:582

ExecutorNativePlatform(std::string OrcRuntimePath)

Set up using path to Orc runtime.

Definition LLJIT.h:578

LLVM_ABI Expected< JITDylibSP > operator()(LLJIT &J)

ExecutorProcessControl supports interaction with a JIT target process.

std::function< std::optional< GlobalValueSet >(GlobalValueSet Requested)> PartitionFunction

Partitioning function.

A layer that applies a transform to emitted modules.

unique_function< Expected< ThreadSafeModule >( ThreadSafeModule, MaterializationResponsibility &R)> TransformFunction

Represents a JIT'd dynamic library.

A utility class for building TargetMachines for JITs.

SetterImpl & setLinkProcessSymbolsByDefault(bool LinkProcessSymbolsByDefault)

The LinkProcessSymbolsDyDefault flag determines whether the "Process" JITDylib will be added to the d...

Definition LLJIT.h:387

SetterImpl & setNotifyCreatedCallback(LLJITBuilderState::NotifyCreatedFunction Callback)

Set up a callback after successful construction of the JIT.

Definition LLJIT.h:453

std::optional< JITTargetMachineBuilder > & getJITTargetMachineBuilder()

Return a reference to the JITTargetMachineBuilder.

Definition LLJIT.h:370

SetterImpl & setPrePlatformSetup(unique_function< Error(LLJIT &)> PrePlatformSetup)

Set a setup function to be run just before the PlatformSetupFunction is run.

Definition LLJIT.h:433

SetterImpl & setCompileFunctionCreator(LLJITBuilderState::CompileFunctionCreator CreateCompileFunction)

Set a CompileFunctionCreator.

Definition LLJIT.h:419

SetterImpl & setNumCompileThreads(unsigned NumCompileThreads)

Set the number of compile threads to use.

Definition LLJIT.h:470

SetterImpl & setDataLayout(std::optional< DataLayout > DL)

Set a DataLayout for this instance.

Definition LLJIT.h:376

SetterImpl & setJITTargetMachineBuilder(JITTargetMachineBuilder JTMB)

Set the JITTargetMachineBuilder for this instance.

Definition LLJIT.h:363

SetterImpl & setExecutorProcessControl(std::unique_ptr< ExecutorProcessControl > EPC)

Set an ExecutorProcessControl for this instance.

Definition LLJIT.h:340

SetterImpl & setObjectLinkingLayerCreator(LLJITBuilderState::ObjectLinkingLayerCreator CreateObjectLinkingLayer)

Set an ObjectLinkingLayer creation function.

Definition LLJIT.h:407

SetterImpl & setPlatformSetUp(LLJITBuilderState::PlatformSetupFunction SetUpPlatform)

Set up an PlatformSetupFunction.

Definition LLJIT.h:443

Expected< std::unique_ptr< JITType > > create()

Create an instance of the JIT.

Definition LLJIT.h:490

SetterImpl & setExecutionSession(std::unique_ptr< ExecutionSession > ES)

Set an ExecutionSession for this instance.

Definition LLJIT.h:350

SetterImpl & setSupportConcurrentCompilation(std::optional< bool > SupportConcurrentCompilation)

If set, this forces LLJIT concurrent compilation support to be either on or off.

Definition LLJIT.h:483

SetterImpl & setProcessSymbolsJITDylibSetup(LLJITBuilderState::ProcessSymbolsJITDylibSetupFunction SetupProcessSymbolsJITDylib)

Set a setup function for the process symbols dylib.

Definition LLJIT.h:396

SetterImpl & impl()

Definition LLJIT.h:507

LLVM_ABI Error prepareForConstruction()

Called prior to JIT class construcion to fix up defaults.

ProcessSymbolsJITDylibSetupFunction SetupProcessSymbolsJITDylib

Definition LLJIT.h:321

ObjectLinkingLayerCreator CreateObjectLinkingLayer

Definition LLJIT.h:322

unsigned NumCompileThreads

Definition LLJIT.h:327

std::function< Error(LLJIT &)> NotifyCreatedFunction

Definition LLJIT.h:314

std::unique_ptr< ExecutionSession > ES

Definition LLJIT.h:317

unique_function< Error(LLJIT &)> PrePlatformSetup

Definition LLJIT.h:324

CompileFunctionCreator CreateCompileFunction

Definition LLJIT.h:323

std::optional< bool > SupportConcurrentCompilation

Definition LLJIT.h:328

bool LinkProcessSymbolsByDefault

Definition LLJIT.h:320

std::unique_ptr< ExecutorProcessControl > EPC

Definition LLJIT.h:316

std::optional< DataLayout > DL

Definition LLJIT.h:319

std::optional< JITTargetMachineBuilder > JTMB

Definition LLJIT.h:318

unique_function< Expected< JITDylibSP >(LLJIT &J)> PlatformSetupFunction

Definition LLJIT.h:312

std::function< Expected< std::unique_ptr< ObjectLayer > >(ExecutionSession &)> ObjectLinkingLayerCreator

Definition LLJIT.h:302

PlatformSetupFunction SetUpPlatform

Definition LLJIT.h:325

NotifyCreatedFunction NotifyCreated

Definition LLJIT.h:326

unique_function< Expected< JITDylibSP >(LLJIT &J)> ProcessSymbolsJITDylibSetupFunction

Definition LLJIT.h:309

std::function< Expected< std::unique_ptr< IRCompileLayer::IRCompiler > >( JITTargetMachineBuilder JTMB)> CompileFunctionCreator

Definition LLJIT.h:305

Constructs LLJIT instances.

Definition LLJIT.h:513

Initializer support for LLJIT.

Definition LLJIT.h:49

virtual Error deinitialize(JITDylib &JD)=0

virtual ~PlatformSupport()

virtual Error initialize(JITDylib &JD)=0

static void setInitTransform(LLJIT &J, IRTransformLayer::TransformFunction T)

A pre-fabricated ORC JIT stack that can serve as an alternative to MCJIT.

Definition LLJIT.h:42

void setPlatformSupport(std::unique_ptr< PlatformSupport > PS)

Set the PlatformSupport instance.

Definition LLJIT.h:189

std::unique_ptr< ExecutionSession > ES

Definition LLJIT.h:248

LLJIT(LLJITBuilderState &S, Error &Err)

Create an LLJIT instance with a single compile thread.

Error addObjectFile(ResourceTrackerSP RT, std::unique_ptr< MemoryBuffer > Obj)

Adds an object file to the given JITDylib.

JITDylib & getMainJITDylib()

Returns a reference to the JITDylib representing the JIT'd main program.

Definition LLJIT.h:76

JITDylibSearchOrder DefaultLinks

Definition LLJIT.h:255

const DataLayout & getDataLayout() const

Returns a reference to the DataLayout for this instance.

Definition LLJIT.h:73

Error initialize(JITDylib &JD)

Run the initializers for the given JITDylib.

Definition LLJIT.h:197

Error addIRModule(ThreadSafeModule TSM)

Adds an IR module to the Main JITDylib.

Definition LLJIT.h:144

ObjectLayer & getObjLinkingLayer()

Returns a reference to the ObjLinkingLayer.

Definition LLJIT.h:217

Expected< ExecutorAddr > lookupLinkerMangled(JITDylib &JD, StringRef Name)

Look up a symbol in JITDylib JD by the symbol's linker-mangled name (to look up symbols based on thei...

Definition LLJIT.h:166

IRCompileLayer & getIRCompileLayer()

Returns a reference to the IR compile layer.

Definition LLJIT.h:226

std::unique_ptr< ObjectTransformLayer > ObjTransformLayer

Definition LLJIT.h:261

IRTransformLayer & getIRTransformLayer()

Returns a reference to the IR transform layer.

Definition LLJIT.h:223

std::string mangle(StringRef UnmangledName) const

Returns a linker-mangled version of UnmangledName.

JITDylib * Main

Definition LLJIT.h:253

Expected< ExecutorAddr > lookup(JITDylib &JD, StringRef UnmangledName)

Look up a symbol in JITDylib JD based on its IR symbol name.

Definition LLJIT.h:179

std::unique_ptr< IRTransformLayer > InitHelperTransformLayer

Definition LLJIT.h:264

Error deinitialize(JITDylib &JD)

Run the deinitializers for the given JITDylib.

Definition LLJIT.h:207

std::unique_ptr< IRCompileLayer > CompileLayer

Definition LLJIT.h:262

Expected< ExecutorAddr > lookup(StringRef UnmangledName)

Look up a symbol in the main JITDylib based on its IR symbol name.

Definition LLJIT.h:184

const Triple & getTargetTriple() const

Returns a reference to the triple for this instance.

Definition LLJIT.h:70

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...

PlatformSupport * getPlatformSupport()

Get the PlatformSupport instance.

Definition LLJIT.h:194

JITDylib * ProcessSymbols

Definition LLJIT.h:251

JITDylib * Platform

Definition LLJIT.h:252

ExecutionSession & getExecutionSession()

Returns the ExecutionSession for this instance.

Definition LLJIT.h:67

std::unique_ptr< IRTransformLayer > TransformLayer

Definition LLJIT.h:263

SymbolStringPtr mangleAndIntern(StringRef UnmangledName) const

Returns an interned, linker-mangled version of UnmangledName.

Definition LLJIT.h:232

DataLayout DL

Definition LLJIT.h:257

Error addObjectFile(std::unique_ptr< MemoryBuffer > Obj)

Adds an object file to the given JITDylib.

Definition LLJIT.h:155

std::unique_ptr< ObjectLayer > ObjLinkingLayer

Definition LLJIT.h:260

std::unique_ptr< PlatformSupport > PS

Definition LLJIT.h:249

JITDylibSearchOrder defaultLinkOrder()

Returns the default link order for this LLJIT instance.

Definition LLJIT.h:135

LLVM_ABI friend Expected< JITDylibSP > setUpGenericLLVMIRPlatform(LLJIT &J)

Configure the LLJIT instance to scrape modules for llvm.global_ctors and llvm.global_dtors variables ...

JITDylib * getJITDylibByName(StringRef Name)

Returns the JITDylib with the given name, or nullptr if no JITDylib with that name exists.

Definition LLJIT.h:94

ObjectTransformLayer & getObjTransformLayer()

Returns a reference to the object transform layer.

Definition LLJIT.h:220

Triple TT

Definition LLJIT.h:258

Error addIRModule(ResourceTrackerSP RT, ThreadSafeModule TSM)

Adds an IR module with the given ResourceTracker.

friend class LLJITBuilderSetters

Definition LLJIT.h:43

Expected< ExecutorAddr > lookupLinkerMangled(StringRef Name)

Look up a symbol in the main JITDylib by the symbol's linker-mangled name (to look up symbols based o...

Definition LLJIT.h:174

SetterImpl & setLazyCompileFailureAddr(ExecutorAddr Addr)

Set the address in the target address to call if a lazy compile fails.

Definition LLJIT.h:537

SetterImpl & setLazyCallthroughManager(std::unique_ptr< LazyCallThroughManager > LCTMgr)

Set the lazy-callthrough manager.

Definition LLJIT.h:547

SetterImpl & setIndirectStubsManagerBuilder(LLLazyJITBuilderState::IndirectStubsManagerBuilderFunction ISMBuilder)

Set the IndirectStubsManager builder function.

Definition LLJIT.h:556

ExecutorAddr LazyCompileFailureAddr

Definition LLJIT.h:523

std::function< std::unique_ptr< IndirectStubsManager >()> IndirectStubsManagerBuilderFunction

Definition LLJIT.h:519

std::unique_ptr< LazyCallThroughManager > LCTMgr

Definition LLJIT.h:524

Triple TT

Definition LLJIT.h:522

LLVM_ABI Error prepareForConstruction()

IndirectStubsManagerBuilderFunction ISMBuilder

Definition LLJIT.h:525

friend class LLLazyJIT

Definition LLJIT.h:516

Constructs LLLazyJIT instances.

Definition LLJIT.h:567

An extended version of LLJIT that supports lazy function-at-a-time compilation of LLVM IR.

Definition LLJIT.h:269

void setPartitionFunction(IRPartitionLayer::PartitionFunction Partition)

Sets the partition function.

Definition LLJIT.h:275

Error addLazyIRModule(ThreadSafeModule M)

Add a module to be lazily compiled to the main JITDylib.

Definition LLJIT.h:286

CompileOnDemandLayer & getCompileOnDemandLayer()

Returns a reference to the on-demand layer.

Definition LLJIT.h:280

friend class LLJITBuilderSetters

Definition LLJIT.h:270

LLVM_ABI Error addLazyIRModule(JITDylib &JD, ThreadSafeModule M)

Add a module to be lazily compiled to JITDylib JD.

ORCPlatformSupport(orc::LLJIT &J)

Definition LLJIT.h:617

Interface for Layers that accept object files.

Pointer to a pooled string representing a symbol name.

An LLVM Module together with a shared ThreadSafeContext.

unique_function is a type-erasing functor similar to std::function.

std::vector< std::pair< JITDylib *, JITDylibLookupFlags > > JITDylibSearchOrder

A list of (JITDylib*, JITDylibLookupFlags) pairs to be used as a search order during symbol lookup.

IntrusiveRefCntPtr< JITDylib > JITDylibSP

IntrusiveRefCntPtr< ResourceTracker > ResourceTrackerSP

LLVM_ABI Expected< JITDylibSP > setUpInactivePlatform(LLJIT &J)

Configure the LLJIT instance to disable platform support explicitly.

LLVM_ABI Expected< JITDylibSP > setUpGenericLLVMIRPlatform(LLJIT &J)

Configure the LLJIT instance to scrape modules for llvm.global_ctors and llvm.global_dtors variables ...

LLVM_ABI Error setUpOrcPlatformManually(LLJIT &J)

Configure the LLJIT instance to use orc runtime support.

This is an optimization pass for GlobalISel generic memory operations.

LLVM_ABI raw_ostream & dbgs()

dbgs() - This returns a reference to a raw_ostream for debugging messages.

OutputIt move(R &&Range, OutputIt Out)

Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.

Implement std::hash so that hash_code can be used in STL containers.