LLVM  15.0.0git
IndirectionUtils.cpp
Go to the documentation of this file.
1 //===---- IndirectionUtils.cpp - Utilities for call indirection in Orc ----===//
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 
10 #include "llvm/ADT/STLExtras.h"
11 #include "llvm/ADT/Triple.h"
14 #include "llvm/IR/IRBuilder.h"
17 #include "llvm/Support/Format.h"
19 #include <sstream>
20 
21 #define DEBUG_TYPE "orc"
22 
23 using namespace llvm;
24 using namespace llvm::orc;
25 
26 namespace {
27 
28 class CompileCallbackMaterializationUnit : public orc::MaterializationUnit {
29 public:
30  using CompileFunction = JITCompileCallbackManager::CompileFunction;
31 
32  CompileCallbackMaterializationUnit(SymbolStringPtr Name,
33  CompileFunction Compile)
34  : MaterializationUnit(Interface(
36  Name(std::move(Name)), Compile(std::move(Compile)) {}
37 
38  StringRef getName() const override { return "<Compile Callbacks>"; }
39 
40 private:
41  void materialize(std::unique_ptr<MaterializationResponsibility> R) override {
42  SymbolMap Result;
43  Result[Name] = JITEvaluatedSymbol(Compile(), JITSymbolFlags::Exported);
44  // No dependencies, so these calls cannot fail.
45  cantFail(R->notifyResolved(Result));
46  cantFail(R->notifyEmitted());
47  }
48 
49  void discard(const JITDylib &JD, const SymbolStringPtr &Name) override {
50  llvm_unreachable("Discard should never occur on a LMU?");
51  }
52 
54  CompileFunction Compile;
55 };
56 
57 } // namespace
58 
59 namespace llvm {
60 namespace orc {
61 
63 void IndirectStubsManager::anchor() {}
64 
67  if (auto TrampolineAddr = TP->getTrampoline()) {
68  auto CallbackName =
69  ES.intern(std::string("cc") + std::to_string(++NextCallbackId));
70 
71  std::lock_guard<std::mutex> Lock(CCMgrMutex);
72  AddrToSymbol[*TrampolineAddr] = CallbackName;
73  cantFail(
74  CallbacksJD.define(std::make_unique<CompileCallbackMaterializationUnit>(
75  std::move(CallbackName), std::move(Compile))));
76  return *TrampolineAddr;
77  } else
78  return TrampolineAddr.takeError();
79 }
80 
82  JITTargetAddress TrampolineAddr) {
84 
85  {
86  std::unique_lock<std::mutex> Lock(CCMgrMutex);
87  auto I = AddrToSymbol.find(TrampolineAddr);
88 
89  // If this address is not associated with a compile callback then report an
90  // error to the execution session and return ErrorHandlerAddress to the
91  // callee.
92  if (I == AddrToSymbol.end()) {
93  Lock.unlock();
94  std::string ErrMsg;
95  {
96  raw_string_ostream ErrMsgStream(ErrMsg);
97  ErrMsgStream << "No compile callback for trampoline at "
98  << format("0x%016" PRIx64, TrampolineAddr);
99  }
100  ES.reportError(
101  make_error<StringError>(std::move(ErrMsg), inconvertibleErrorCode()));
102  return ErrorHandlerAddress;
103  } else
104  Name = I->second;
105  }
106 
107  if (auto Sym =
108  ES.lookup(makeJITDylibSearchOrder(
110  Name))
111  return Sym->getAddress();
112  else {
113  llvm::dbgs() << "Didn't find callback.\n";
114  // If anything goes wrong materializing Sym then report it to the session
115  // and return the ErrorHandlerAddress;
116  ES.reportError(Sym.takeError());
117  return ErrorHandlerAddress;
118  }
119 }
120 
123  JITTargetAddress ErrorHandlerAddress) {
124  switch (T.getArch()) {
125  default:
126  return make_error<StringError>(
127  std::string("No callback manager available for ") + T.str(),
129  case Triple::aarch64:
130  case Triple::aarch64_32: {
132  return CCMgrT::Create(ES, ErrorHandlerAddress);
133  }
134 
135  case Triple::x86: {
137  return CCMgrT::Create(ES, ErrorHandlerAddress);
138  }
139 
140  case Triple::mips: {
142  return CCMgrT::Create(ES, ErrorHandlerAddress);
143  }
144  case Triple::mipsel: {
146  return CCMgrT::Create(ES, ErrorHandlerAddress);
147  }
148 
149  case Triple::mips64:
150  case Triple::mips64el: {
152  return CCMgrT::Create(ES, ErrorHandlerAddress);
153  }
154 
155  case Triple::riscv64: {
157  return CCMgrT::Create(ES, ErrorHandlerAddress);
158  }
159 
160  case Triple::x86_64: {
161  if (T.getOS() == Triple::OSType::Win32) {
163  return CCMgrT::Create(ES, ErrorHandlerAddress);
164  } else {
166  return CCMgrT::Create(ES, ErrorHandlerAddress);
167  }
168  }
169 
170  }
171 }
172 
173 std::function<std::unique_ptr<IndirectStubsManager>()>
175  switch (T.getArch()) {
176  default:
177  return [](){
178  return std::make_unique<
180  };
181 
182  case Triple::aarch64:
183  case Triple::aarch64_32:
184  return [](){
185  return std::make_unique<
187  };
188 
189  case Triple::x86:
190  return [](){
191  return std::make_unique<
193  };
194 
195  case Triple::mips:
196  return [](){
197  return std::make_unique<
199  };
200 
201  case Triple::mipsel:
202  return [](){
203  return std::make_unique<
205  };
206 
207  case Triple::mips64:
208  case Triple::mips64el:
209  return [](){
210  return std::make_unique<
212  };
213 
214  case Triple::riscv64:
215  return []() {
216  return std::make_unique<
218  };
219 
220  case Triple::x86_64:
221  if (T.getOS() == Triple::OSType::Win32) {
222  return [](){
223  return std::make_unique<
225  };
226  } else {
227  return [](){
228  return std::make_unique<
230  };
231  }
232 
233  }
234 }
235 
237  Constant *AddrIntVal =
239  Constant *AddrPtrVal =
240  ConstantExpr::getCast(Instruction::IntToPtr, AddrIntVal,
241  PointerType::get(&FT, 0));
242  return AddrPtrVal;
243 }
244 
246  const Twine &Name, Constant *Initializer) {
247  auto IP = new GlobalVariable(M, &PT, false, GlobalValue::ExternalLinkage,
248  Initializer, Name, nullptr,
249  GlobalValue::NotThreadLocal, 0, true);
250  IP->setVisibility(GlobalValue::HiddenVisibility);
251  return IP;
252 }
253 
254 void makeStub(Function &F, Value &ImplPointer) {
255  assert(F.isDeclaration() && "Can't turn a definition into a stub.");
256  assert(F.getParent() && "Function isn't in a module.");
257  Module &M = *F.getParent();
258  BasicBlock *EntryBlock = BasicBlock::Create(M.getContext(), "entry", &F);
259  IRBuilder<> Builder(EntryBlock);
260  LoadInst *ImplAddr = Builder.CreateLoad(F.getType(), &ImplPointer);
261  std::vector<Value*> CallArgs;
262  for (auto &A : F.args())
263  CallArgs.push_back(&A);
264  CallInst *Call = Builder.CreateCall(F.getFunctionType(), ImplAddr, CallArgs);
265  Call->setTailCall();
266  Call->setAttributes(F.getAttributes());
267  if (F.getReturnType()->isVoidTy())
268  Builder.CreateRetVoid();
269  else
270  Builder.CreateRet(Call);
271 }
272 
273 std::vector<GlobalValue *> SymbolLinkagePromoter::operator()(Module &M) {
274  std::vector<GlobalValue *> PromotedGlobals;
275 
276  for (auto &GV : M.global_values()) {
277  bool Promoted = true;
278 
279  // Rename if necessary.
280  if (!GV.hasName())
281  GV.setName("__orc_anon." + Twine(NextId++));
282  else if (GV.getName().startswith("\01L"))
283  GV.setName("__" + GV.getName().substr(1) + "." + Twine(NextId++));
284  else if (GV.hasLocalLinkage())
285  GV.setName("__orc_lcl." + GV.getName() + "." + Twine(NextId++));
286  else
287  Promoted = false;
288 
289  if (GV.hasLocalLinkage()) {
290  GV.setLinkage(GlobalValue::ExternalLinkage);
291  GV.setVisibility(GlobalValue::HiddenVisibility);
292  Promoted = true;
293  }
294  GV.setUnnamedAddr(GlobalValue::UnnamedAddr::None);
295 
296  if (Promoted)
297  PromotedGlobals.push_back(&GV);
298  }
299 
300  return PromotedGlobals;
301 }
302 
304  ValueToValueMapTy *VMap) {
305  Function *NewF =
306  Function::Create(cast<FunctionType>(F.getValueType()),
307  F.getLinkage(), F.getName(), &Dst);
308  NewF->copyAttributesFrom(&F);
309 
310  if (VMap) {
311  (*VMap)[&F] = NewF;
312  auto NewArgI = NewF->arg_begin();
313  for (auto ArgI = F.arg_begin(), ArgE = F.arg_end(); ArgI != ArgE;
314  ++ArgI, ++NewArgI)
315  (*VMap)[&*ArgI] = &*NewArgI;
316  }
317 
318  return NewF;
319 }
320 
322  ValueMaterializer *Materializer,
323  Function *NewF) {
324  assert(!OrigF.isDeclaration() && "Nothing to move");
325  if (!NewF)
326  NewF = cast<Function>(VMap[&OrigF]);
327  else
328  assert(VMap[&OrigF] == NewF && "Incorrect function mapping in VMap.");
329  assert(NewF && "Function mapping missing from VMap.");
330  assert(NewF->getParent() != OrigF.getParent() &&
331  "moveFunctionBody should only be used to move bodies between "
332  "modules.");
333 
334  SmallVector<ReturnInst *, 8> Returns; // Ignore returns cloned.
335  CloneFunctionInto(NewF, &OrigF, VMap,
337  nullptr, nullptr, Materializer);
338  OrigF.deleteBody();
339 }
340 
342  ValueToValueMapTy *VMap) {
343  GlobalVariable *NewGV = new GlobalVariable(
344  Dst, GV.getValueType(), GV.isConstant(),
345  GV.getLinkage(), nullptr, GV.getName(), nullptr,
347  NewGV->copyAttributesFrom(&GV);
348  if (VMap)
349  (*VMap)[&GV] = NewGV;
350  return NewGV;
351 }
352 
354  ValueToValueMapTy &VMap,
355  ValueMaterializer *Materializer,
356  GlobalVariable *NewGV) {
357  assert(OrigGV.hasInitializer() && "Nothing to move");
358  if (!NewGV)
359  NewGV = cast<GlobalVariable>(VMap[&OrigGV]);
360  else
361  assert(VMap[&OrigGV] == NewGV &&
362  "Incorrect global variable mapping in VMap.");
363  assert(NewGV->getParent() != OrigGV.getParent() &&
364  "moveGlobalVariableInitializer should only be used to move "
365  "initializers between modules");
366 
367  NewGV->setInitializer(MapValue(OrigGV.getInitializer(), VMap, RF_None,
368  nullptr, Materializer));
369 }
370 
372  ValueToValueMapTy &VMap) {
373  assert(OrigA.getAliasee() && "Original alias doesn't have an aliasee?");
374  auto *NewA = GlobalAlias::create(OrigA.getValueType(),
375  OrigA.getType()->getPointerAddressSpace(),
376  OrigA.getLinkage(), OrigA.getName(), &Dst);
377  NewA->copyAttributesFrom(&OrigA);
378  VMap[&OrigA] = NewA;
379  return NewA;
380 }
381 
382 void cloneModuleFlagsMetadata(Module &Dst, const Module &Src,
383  ValueToValueMapTy &VMap) {
384  auto *MFs = Src.getModuleFlagsMetadata();
385  if (!MFs)
386  return;
387  for (auto *MF : MFs->operands())
388  Dst.addModuleFlag(MapMetadata(MF, VMap));
389 }
390 
393  MCDisassembler &Disassembler,
394  MCInstrAnalysis &MIA) {
395  // AArch64 appears to already come with the necessary relocations. Among other
396  // architectures, only x86_64 is currently implemented here.
397  if (G.getTargetTriple().getArch() != Triple::x86_64)
398  return Error::success();
399 
400  raw_null_ostream CommentStream;
401  auto &STI = Disassembler.getSubtargetInfo();
402 
403  // Determine the function bounds
404  auto &B = Sym.getBlock();
405  assert(!B.isZeroFill() && "expected content block");
406  auto SymAddress = Sym.getAddress();
407  auto SymStartInBlock =
408  (const uint8_t *)B.getContent().data() + Sym.getOffset();
409  auto SymSize = Sym.getSize() ? Sym.getSize() : B.getSize() - Sym.getOffset();
410  auto Content = makeArrayRef(SymStartInBlock, SymSize);
411 
412  LLVM_DEBUG(dbgs() << "Adding self-relocations to " << Sym.getName() << "\n");
413 
414  SmallDenseSet<uintptr_t, 8> ExistingRelocations;
415  for (auto &E : B.edges()) {
416  if (E.isRelocation())
417  ExistingRelocations.insert(E.getOffset());
418  }
419 
420  size_t I = 0;
421  while (I < Content.size()) {
422  MCInst Instr;
423  uint64_t InstrSize = 0;
424  uint64_t InstrStart = SymAddress.getValue() + I;
425  auto DecodeStatus = Disassembler.getInstruction(
426  Instr, InstrSize, Content.drop_front(I), InstrStart, CommentStream);
428  LLVM_DEBUG(dbgs() << "Aborting due to disassembly failure at address "
429  << InstrStart);
430  return make_error<StringError>(
431  formatv("failed to disassemble at address {0:x16}", InstrStart),
433  }
434  // Advance to the next instruction.
435  I += InstrSize;
436 
437  // Check for a PC-relative address equal to the symbol itself.
438  auto PCRelAddr =
439  MIA.evaluateMemoryOperandAddress(Instr, &STI, InstrStart, InstrSize);
440  if (!PCRelAddr || *PCRelAddr != SymAddress.getValue())
441  continue;
442 
443  auto RelocOffInInstr =
444  MIA.getMemoryOperandRelocationOffset(Instr, InstrSize);
445  if (!RelocOffInInstr || InstrSize - *RelocOffInInstr != 4) {
446  LLVM_DEBUG(dbgs() << "Skipping unknown self-relocation at "
447  << InstrStart);
448  continue;
449  }
450 
451  auto RelocOffInBlock = orc::ExecutorAddr(InstrStart) + *RelocOffInInstr -
452  SymAddress + Sym.getOffset();
453  if (ExistingRelocations.contains(RelocOffInBlock))
454  continue;
455 
456  LLVM_DEBUG(dbgs() << "Adding delta32 self-relocation at " << InstrStart);
457  B.addEdge(jitlink::x86_64::Delta32, RelocOffInBlock, Sym, /*Addend=*/-4);
458  }
459  return Error::success();
460 }
461 
462 } // End namespace orc.
463 } // End namespace llvm.
llvm::orc::ExecutorAddr
Represents an address in the executor process.
Definition: ExecutorAddress.h:30
llvm::Triple::riscv64
@ riscv64
Definition: Triple.h:76
llvm::RF_None
@ RF_None
Definition: ValueMapper.h:66
getName
static StringRef getName(Value *V)
Definition: ProvenanceAnalysisEvaluator.cpp:42
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:946
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::MapMetadata
Metadata * MapMetadata(const Metadata *MD, ValueToValueMapTy &VM, RemapFlags Flags=RF_None, ValueMapTypeRemapper *TypeMapper=nullptr, ValueMaterializer *Materializer=nullptr)
Lookup or compute a mapping for a piece of metadata.
Definition: ValueMapper.h:231
llvm::orc::LocalJITCompileCallbackManager
Manage compile callbacks for in-process JITs.
Definition: IndirectionUtils.h:241
MCDisassembler.h
llvm::GlobalVariable::copyAttributesFrom
void copyAttributesFrom(const GlobalVariable *Src)
copyAttributesFrom - copy all additional attributes (those not needed to create a GlobalVariable) fro...
Definition: Globals.cpp:478
llvm::GlobalValue::getLinkage
LinkageTypes getLinkage() const
Definition: GlobalValue.h:509
llvm::GlobalValue::HiddenVisibility
@ HiddenVisibility
The GV is hidden.
Definition: GlobalValue.h:64
T
llvm::Function
Definition: Function.h:60
llvm::Triple::x86
@ x86
Definition: Triple.h:85
llvm::raw_string_ostream
A raw_ostream that writes to an std::string.
Definition: raw_ostream.h:632
llvm::PointerType::get
static PointerType * get(Type *ElementType, unsigned AddressSpace)
This constructs a pointer to an object of the specified type in a numbered address space.
Definition: Type.cpp:727
llvm::GlobalValue::NotThreadLocal
@ NotThreadLocal
Definition: GlobalValue.h:184
llvm::orc::cloneModuleFlagsMetadata
void cloneModuleFlagsMetadata(Module &Dst, const Module &Src, ValueToValueMapTy &VMap)
Clone module flags metadata into the destination module.
Definition: IndirectionUtils.cpp:382
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1185
llvm::MCInstrAnalysis::getMemoryOperandRelocationOffset
virtual Optional< uint64_t > getMemoryOperandRelocationOffset(const MCInst &Inst, uint64_t Size) const
Given an instruction with a memory operand that could require relocation, returns the offset within t...
Definition: MCInstrAnalysis.cpp:40
llvm::orc::SymbolStringPtr
Pointer to a pooled string representing a symbol name.
Definition: SymbolStringPool.h:57
llvm::GlobalValue::UnnamedAddr::None
@ None
llvm::Type::getPointerAddressSpace
unsigned getPointerAddressSpace() const
Get the address space of this pointer or pointer vector type.
Definition: DerivedTypes.h:729
llvm::SmallDenseSet
Implements a dense probed hash-table based set with some number of buckets stored inline.
Definition: DenseSet.h:286
llvm::IRBuilder<>
llvm::Error::success
static ErrorSuccess success()
Create a success value.
Definition: Error.h:329
llvm::GlobalVariable
Definition: GlobalVariable.h:39
llvm::PointerType::getAddressSpace
unsigned getAddressSpace() const
Return the address space of the Pointer type.
Definition: DerivedTypes.h:682
Content
T Content
Definition: ELFObjHandler.cpp:88
llvm::GlobalAlias
Definition: GlobalAlias.h:28
llvm::Triple
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
llvm::MapValue
Value * MapValue(const Value *V, ValueToValueMapTy &VM, RemapFlags Flags=RF_None, ValueMapTypeRemapper *TypeMapper=nullptr, ValueMaterializer *Materializer=nullptr)
Look up or compute a value in the value map.
Definition: ValueMapper.h:209
llvm::CloneFunctionChangeType::DifferentModule
@ DifferentModule
llvm::Triple::x86_64
@ x86_64
Definition: Triple.h:86
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:41
STLExtras.h
llvm::MCInst
Instances of this class represent a single low-level machine instruction.
Definition: MCInst.h:184
llvm::Triple::aarch64_32
@ aarch64_32
Definition: Triple.h:53
Format.h
OrcABISupport.h
llvm::detail::DenseSetImpl< ValueT, SmallDenseMap< ValueT, detail::DenseSetEmpty, 4, DenseMapInfo< ValueT >, detail::DenseSetPair< ValueT > >, DenseMapInfo< ValueT > >::insert
std::pair< iterator, bool > insert(const ValueT &V)
Definition: DenseSet.h:206
llvm::Triple::mips64
@ mips64
Definition: Triple.h:66
llvm::orc::MaterializationUnit
A MaterializationUnit represents a set of symbol definitions that can be materialized as a group,...
Definition: Core.h:665
LLVM_DEBUG
#define LLVM_DEBUG(X)
Definition: Debug.h:101
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::GlobalVariable::hasInitializer
bool hasInitializer() const
Definitions have initializers, declarations don't.
Definition: GlobalVariable.h:91
llvm::BasicBlock
LLVM Basic Block Representation.
Definition: BasicBlock.h:55
llvm::dbgs
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Definition: Debug.cpp:163
llvm::Lock
static sys::Mutex Lock
Definition: NVPTXUtilities.cpp:39
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::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:264
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
llvm::orc::createIRTypedAddress
Constant * createIRTypedAddress(FunctionType &FT, JITTargetAddress Addr)
Build a function pointer of FunctionType with the given constant address.
Definition: IndirectionUtils.cpp:236
llvm::Triple::mips64el
@ mips64el
Definition: Triple.h:67
llvm::GlobalValue::getThreadLocalMode
ThreadLocalMode getThreadLocalMode() const
Definition: GlobalValue.h:257
llvm::orc
Definition: CompileOnDemandLayer.h:54
llvm::orc::SymbolLinkagePromoter::operator()
std::vector< GlobalValue * > operator()(Module &M)
Promote symbols in the given module.
Definition: IndirectionUtils.cpp:273
llvm::MCDisassembler::Success
@ Success
Definition: MCDisassembler.h:112
IP
Definition: NVPTXLowerArgs.cpp:167
llvm::orc::cloneGlobalVariableDecl
GlobalVariable * cloneGlobalVariableDecl(Module &Dst, const GlobalVariable &GV, ValueToValueMapTy *VMap=nullptr)
Clone a global variable declaration into a new module.
Definition: IndirectionUtils.cpp:341
B
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
llvm::MCInstrAnalysis
Definition: MCInstrAnalysis.h:30
llvm::MCInstrAnalysis::evaluateMemoryOperandAddress
virtual Optional< uint64_t > evaluateMemoryOperandAddress(const MCInst &Inst, const MCSubtargetInfo *STI, uint64_t Addr, uint64_t Size) const
Given an instruction tries to get the address of a memory operand.
Definition: MCInstrAnalysis.cpp:33
llvm::Function::copyAttributesFrom
void copyAttributesFrom(const Function *Src)
copyAttributesFrom - copy all additional attributes (those not needed to create a Function) from the ...
Definition: Function.cpp:712
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:926
llvm::MCDisassembler::getInstruction
virtual DecodeStatus getInstruction(MCInst &Instr, uint64_t &Size, ArrayRef< uint8_t > Bytes, uint64_t Address, raw_ostream &CStream) const =0
Returns the disassembly of a single instruction.
llvm::MCDisassembler::DecodeStatus
DecodeStatus
Ternary decode status.
Definition: MCDisassembler.h:109
G
const DataFlowGraph & G
Definition: RDFGraph.cpp:200
llvm::orc::createLocalCompileCallbackManager
Expected< std::unique_ptr< JITCompileCallbackManager > > createLocalCompileCallbackManager(const Triple &T, ExecutionSession &ES, JITTargetAddress ErrorHandlerAddress)
Create a local compile callback manager.
Definition: IndirectionUtils.cpp:122
llvm::Constant
This is an important base class in LLVM.
Definition: Constant.h:41
uint64_t
llvm::GlobalValue::getParent
Module * getParent()
Get the module that this global value is contained inside of...
Definition: GlobalValue.h:620
Addr
uint64_t Addr
Definition: ELFObjHandler.cpp:78
llvm::orc::createLocalIndirectStubsManagerBuilder
std::function< std::unique_ptr< IndirectStubsManager >)> createLocalIndirectStubsManagerBuilder(const Triple &T)
Create a local indriect stubs manager builder.
Definition: IndirectionUtils.cpp:174
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::MCDisassembler
Superclass for all disassemblers.
Definition: MCDisassembler.h:85
llvm::DenseMap< SymbolStringPtr, JITEvaluatedSymbol >
I
#define I(x, y, z)
Definition: MD5.cpp:58
Cloning.h
llvm::PointerType
Class to represent pointers.
Definition: DerivedTypes.h:632
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::sys::SmartMutex::unlock
bool unlock()
Definition: Mutex.h:46
llvm::ConstantExpr::getCast
static Constant * getCast(unsigned ops, Constant *C, Type *Ty, bool OnlyIfReduced=false)
Convenience function for getting a Cast operation.
Definition: Constants.cpp:2001
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
Builder
assume Assume Builder
Definition: AssumeBundleBuilder.cpp:651
llvm::raw_null_ostream
A raw_ostream that discards all output.
Definition: raw_ostream.h:695
Triple.h
MCInstrAnalysis.h
llvm::orc::createImplPointer
GlobalVariable * createImplPointer(PointerType &PT, Module &M, const Twine &Name, Constant *Initializer)
Create a function pointer with the given type, name, and initializer in the given Module.
Definition: IndirectionUtils.cpp:245
llvm::orc::cloneGlobalAliasDecl
GlobalAlias * cloneGlobalAliasDecl(Module &Dst, const GlobalAlias &OrigA, ValueToValueMapTy &VMap)
Clone a global alias declaration into a new module.
Definition: IndirectionUtils.cpp:371
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:143
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::detail::DenseSetImpl< ValueT, SmallDenseMap< ValueT, detail::DenseSetEmpty, 4, DenseMapInfo< ValueT >, detail::DenseSetPair< ValueT > >, DenseMapInfo< ValueT > >::contains
bool contains(const_arg_type_t< ValueT > V) const
Check if the set contains the given element.
Definition: DenseSet.h:185
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::cloneFunctionDecl
Function * cloneFunctionDecl(Module &Dst, const Function &F, ValueToValueMapTy *VMap=nullptr)
Clone a function declaration into a new module.
Definition: IndirectionUtils.cpp:303
llvm::orc::moveGlobalVariableInitializer
void moveGlobalVariableInitializer(GlobalVariable &OrigGV, ValueToValueMapTy &VMap, ValueMaterializer *Materializer=nullptr, GlobalVariable *NewGV=nullptr)
Move global variable GV from its parent module to cloned global declaration in a different module.
Definition: IndirectionUtils.cpp:353
llvm::format
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
Definition: Format.h:124
llvm::GlobalAlias::getAliasee
const Constant * getAliasee() const
Definition: GlobalAlias.h:84
llvm::Value::getName
StringRef getName() const
Return a constant reference to the value's name.
Definition: Value.cpp:305
llvm::ValueMap
See the file comment.
Definition: ValueMap.h:85
llvm::Type::getContext
LLVMContext & getContext() const
Return the LLVMContext in which this type was uniqued.
Definition: Type.h:128
llvm::LoadInst
An instruction for reading from memory.
Definition: Instructions.h:173
x86_64.h
llvm::orc::SymbolFlagsMap
DenseMap< SymbolStringPtr, JITSymbolFlags > SymbolFlagsMap
A map from symbol names (as SymbolStringPtrs) to JITSymbolFlags.
Definition: Core.h:116
llvm::orc::makeStub
void makeStub(Function &F, Value &ImplPointer)
Turn a function declaration into a stub function that makes an indirect call using the given function...
Definition: IndirectionUtils.cpp:254
llvm::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:83
llvm::Type::getInt64Ty
static IntegerType * getInt64Ty(LLVMContext &C)
Definition: Type.cpp:240
llvm::orc::JITCompileCallbackManager::CompileFunction
std::function< JITTargetAddress()> CompileFunction
Definition: IndirectionUtils.h:205
llvm::GraphProgram::Name
Name
Definition: GraphWriter.h:50
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::GlobalAlias::create
static GlobalAlias * create(Type *Ty, unsigned AddressSpace, LinkageTypes Linkage, const Twine &Name, Constant *Aliasee, Module *Parent)
If a parent module is specified, the alias is automatically inserted into the end of the specified mo...
Definition: Globals.cpp:503
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:155
llvm::orc::ExecutionSession
An ExecutionSession represents a running JIT program.
Definition: Core.h:1358
llvm::orc::addFunctionPointerRelocationsToCurrentSymbol
Error addFunctionPointerRelocationsToCurrentSymbol(jitlink::Symbol &Sym, jitlink::LinkGraph &G, MCDisassembler &Disassembler, MCInstrAnalysis &MIA)
Introduce relocations to Sym in its own definition if there are any pointers formed via PC-relative a...
Definition: IndirectionUtils.cpp:391
llvm::Triple::mipsel
@ mipsel
Definition: Triple.h:65
llvm::JITTargetAddress
uint64_t JITTargetAddress
Represents an address in the target process's address space.
Definition: JITSymbol.h:42
llvm::Function::arg_begin
arg_iterator arg_begin()
Definition: Function.h:741
llvm::MCDisassembler::getSubtargetInfo
const MCSubtargetInfo & getSubtargetInfo() const
Definition: MCDisassembler.h:196
llvm::orc::LocalIndirectStubsManager
IndirectStubsManager implementation for the host architecture, e.g.
Definition: IndirectionUtils.h:370
llvm::makeArrayRef
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
Definition: ArrayRef.h:475
llvm::GlobalValue::ExternalLinkage
@ ExternalLinkage
Externally visible function.
Definition: GlobalValue.h:48
llvm::GlobalVariable::isConstant
bool isConstant() const
If the value is a global constant, its value is immutable throughout the runtime execution of the pro...
Definition: GlobalVariable.h:152
llvm::orc::JITCompileCallbackManager::executeCompileCallback
JITTargetAddress executeCompileCallback(JITTargetAddress TrampolineAddr)
Execute the callback for the given trampoline id.
Definition: IndirectionUtils.cpp:81
llvm::to_string
std::string to_string(const T &Value)
Definition: ScopedPrinter.h:85
IndirectionUtils.h
llvm::GlobalValue::getType
PointerType * getType() const
Global values are always pointers.
Definition: GlobalValue.h:276
llvm::GlobalValue::getValueType
Type * getValueType() const
Definition: GlobalValue.h:278
llvm::CallInst
This class represents a function call, abstracting a target machine's calling convention.
Definition: Instructions.h:1461
llvm::CloneFunctionInto
void CloneFunctionInto(Function *NewFunc, const Function *OldFunc, ValueToValueMapTy &VMap, CloneFunctionChangeType Changes, SmallVectorImpl< ReturnInst * > &Returns, const char *NameSuffix="", ClonedCodeInfo *CodeInfo=nullptr, ValueMapTypeRemapper *TypeMapper=nullptr, ValueMaterializer *Materializer=nullptr)
Clone OldFunc into NewFunc, transforming the old arguments into references to VMap values.
Definition: CloneFunction.cpp:81
llvm::orc::TrampolinePool::~TrampolinePool
virtual ~TrampolinePool()
llvm::orc::JITCompileCallbackManager::getCompileCallback
Expected< JITTargetAddress > getCompileCallback(CompileFunction Compile)
Reserve a compile callback.
Definition: IndirectionUtils.cpp:66
llvm::orc::JITDylibLookupFlags::MatchAllSymbols
@ MatchAllSymbols
llvm::orc::moveFunctionBody
void moveFunctionBody(Function &OrigF, ValueToValueMapTy &VMap, ValueMaterializer *Materializer=nullptr, Function *NewF=nullptr)
Move the body of function 'F' to a cloned function declaration in a different module (See related clo...
Definition: IndirectionUtils.cpp:321
llvm::ValueMaterializer
This is a class that can be implemented by clients to materialize Values on demand.
Definition: ValueMapper.h:49
llvm::Value
LLVM Value Representation.
Definition: Value.h:74
llvm::Triple::mips
@ mips
Definition: Triple.h:64
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::GlobalVariable::setInitializer
void setInitializer(Constant *InitVal)
setInitializer - Sets the initializer for this global variable, removing any existing initializer if ...
Definition: Globals.cpp:455
llvm::JITSymbolFlags::Exported
@ Exported
Definition: JITSymbol.h:85
llvm::FunctionType
Class to represent function types.
Definition: DerivedTypes.h:103