LLVM: lib/ExecutionEngine/Orc/Speculation.cpp Source File (original) (raw)

1

2

3

4

5

6

7

8

10

21

22namespace llvm {

23

24namespace orc {

25

26

28 assert(SrcJD && "Tracking on Null Source .impl dylib");

29 std::lock_guardstd::mutex Lockit(ConcurrentAccess);

30 for (auto &I : ImplMaps) {

31 auto It = Maps.insert({I.first, {I.second.Aliasee, SrcJD}});

32

33 assert(It.second && "ImplSymbols are already tracked for this Symbol?");

34 (void)(It);

35 }

36}

37

38

39void Speculator::speculateForEntryPoint(Speculator *Ptr, uint64_t StubId) {

40 assert(Ptr && " Null Address Received in orc_speculate_for ");

42}

43

51 {Mangle("__orc_speculator"), ThisPtr},

52 {Mangle("__orc_speculate_for"), SpeculateForEntryPtr}

53 }));

54}

55

56

57

58

61

62 assert(TSM && "Speculation Layer received Null Module ?");

63

64

66 auto &MContext = M.getContext();

67 auto SpeculatorVTy = StructType::create(MContext, "Class.Speculator");

71 auto RuntimeCall =

73 "__orc_speculate_for", &M);

76 nullptr, "__orc_speculator");

77

79

80

81

82 for (auto &Fn : M.getFunctionList()) {

83 if (!Fn.isDeclaration()) {

84

85 auto IRNames = QueryAnalysis(Fn);

86

87 if (IRNames) {

88

89

93 ConstantInt::get(LoadValueTy, 0),

94 "__orc_speculate.guard.for." + Fn.getName());

95 SpeculatorGuard->setAlignment(Align(1));

97

98 BasicBlock &ProgramEntry = Fn.getEntryBlock();

99

101 MContext, "__orc_speculate.block", &Fn, &ProgramEntry);

103 MContext, "__orc_speculate.decision.block", &Fn, SpeculateBlock);

104

105 assert(SpeculateDecisionBlock == &Fn.getEntryBlock() &&

106 "SpeculateDecisionBlock not updated?");

108

109 auto LoadGuard =

110 Mutator.CreateLoad(LoadValueTy, SpeculatorGuard, "guard.value");

111

112 auto CanSpeculate =

113 Mutator.CreateICmpEQ(LoadGuard, ConstantInt::get(LoadValueTy, 0),

114 "compare.to.speculate");

115 Mutator.CreateCondBr(CanSpeculate, SpeculateBlock, &ProgramEntry);

116

118 auto ImplAddrToUint =

120 Mutator.CreateCall(RuntimeCallTy, RuntimeCall,

121 {SpeclAddr, ImplAddrToUint});

122 Mutator.CreateStore(ConstantInt::get(LoadValueTy, 1),

123 SpeculatorGuard);

124 Mutator.CreateBr(&ProgramEntry);

125

127 "IR builder association mismatch?");

128 S.registerSymbols(internToJITSymbols(*IRNames),

129 &R->getTargetJITDylib());

130 }

131 }

132 }

133 });

134

136 "Speculation Instrumentation breaks IR?");

137

138 NextLayer.emit(std::move(R), std::move(TSM));

139}

140

141}

142}

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

Module.h This file contains the declarations for the Module class.

LLVM Basic Block Representation.

const Function * getParent() const

Return the enclosing method, or null if none.

static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)

Creates a new BasicBlock.

Lightweight error class with error context and mandatory checking.

static LLVM_ABI FunctionType * get(Type *Result, ArrayRef< Type * > Params, bool isVarArg)

This static method is the primary way of constructing a FunctionType.

static Function * Create(FunctionType *Ty, LinkageTypes Linkage, unsigned AddrSpace, const Twine &N="", Module *M=nullptr)

@ InternalLinkage

Rename collisions when linking (static functions).

@ ExternalLinkage

Externally visible function.

BasicBlock * GetInsertBlock() const

Value * CreateICmpEQ(Value *LHS, Value *RHS, const Twine &Name="")

BranchInst * CreateCondBr(Value *Cond, BasicBlock *True, BasicBlock *False, MDNode *BranchWeights=nullptr, MDNode *Unpredictable=nullptr)

Create a conditional 'br Cond, TrueDest, FalseDest' instruction.

LoadInst * CreateLoad(Type *Ty, Value *Ptr, const char *Name)

Provided to resolve 'CreateLoad(Ty, Ptr, "...")' correctly, instead of converting the string to 'bool...

StoreInst * CreateStore(Value *Val, Value *Ptr, bool isVolatile=false)

Value * CreatePtrToInt(Value *V, Type *DestTy, const Twine &Name="")

CallInst * CreateCall(FunctionType *FTy, Value *Callee, ArrayRef< Value * > Args={}, const Twine &Name="", MDNode *FPMathTag=nullptr)

BranchInst * CreateBr(BasicBlock *Dest)

Create an unconditional 'br label X' instruction.

void SetInsertPoint(BasicBlock *TheBB)

This specifies that created instructions should be appended to the end of the specified block.

This provides a uniform API for creating instructions and inserting them into a basic block: either a...

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

static PointerType * getUnqual(Type *ElementType)

This constructs a pointer to an object of the specified type in the default address space (address sp...

static LLVM_ABI StructType * create(LLVMContext &Context, StringRef Name)

This creates an identified struct.

static LLVM_ABI IntegerType * getInt64Ty(LLVMContext &C)

static LLVM_ABI Type * getVoidTy(LLVMContext &C)

static LLVM_ABI IntegerType * getInt8Ty(LLVMContext &C)

Represents an address in the executor process.

static ExecutorAddr fromPtr(T *Ptr, UnwrapFn &&Unwrap=UnwrapFn())

Create an ExecutorAddr from the given pointer.

Represents a defining location for a JIT symbol.

void emit(std::unique_ptr< MaterializationResponsibility > R, ThreadSafeModule TSM) override

Emit should materialize the given IR.

Definition Speculation.cpp:59

LLVM_ABI void trackImpls(SymbolAliasMap ImplMaps, JITDylib *SrcJD)

Definition Speculation.cpp:27

Represents a JIT'd dynamic library.

Error define(std::unique_ptr< MaterializationUnitType > &&MU, ResourceTrackerSP RT=nullptr)

Define all symbols provided by the materialization unit to be part of this JITDylib.

Mangles symbol names then uniques them in the context of an ExecutionSession.

LLVM_ABI Error addSpeculationRuntime(JITDylib &JD, MangleAndInterner &Mangle)

Define symbols for this Speculator object (__orc_speculator) and the speculation runtime entry point ...

Definition Speculation.cpp:44

void speculateFor(TargetFAddr StubAddr)

An LLVM Module together with a shared ThreadSafeContext.

decltype(auto) withModuleDo(Func &&F)

Locks the associated ThreadSafeContext and calls the given function on the contained Module.

std::unique_ptr< AbsoluteSymbolsMaterializationUnit > absoluteSymbols(SymbolMap Symbols)

Create an AbsoluteSymbolsMaterializationUnit with the given symbols.

DenseMap< SymbolStringPtr, SymbolAliasMapEntry > SymbolAliasMap

A map of Symbols to (Symbol, Flags) pairs.

This is an optimization pass for GlobalISel generic memory operations.

This struct is a compact representation of a valid (non-zero power of two) alignment.