LLVM  14.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::x86_64: {
156  if (T.getOS() == Triple::OSType::Win32) {
158  return CCMgrT::Create(ES, ErrorHandlerAddress);
159  } else {
161  return CCMgrT::Create(ES, ErrorHandlerAddress);
162  }
163  }
164 
165  }
166 }
167 
168 std::function<std::unique_ptr<IndirectStubsManager>()>
170  switch (T.getArch()) {
171  default:
172  return [](){
173  return std::make_unique<
175  };
176 
177  case Triple::aarch64:
178  case Triple::aarch64_32:
179  return [](){
180  return std::make_unique<
182  };
183 
184  case Triple::x86:
185  return [](){
186  return std::make_unique<
188  };
189 
190  case Triple::mips:
191  return [](){
192  return std::make_unique<
194  };
195 
196  case Triple::mipsel:
197  return [](){
198  return std::make_unique<
200  };
201 
202  case Triple::mips64:
203  case Triple::mips64el:
204  return [](){
205  return std::make_unique<
207  };
208 
209  case Triple::x86_64:
210  if (T.getOS() == Triple::OSType::Win32) {
211  return [](){
212  return std::make_unique<
214  };
215  } else {
216  return [](){
217  return std::make_unique<
219  };
220  }
221 
222  }
223 }
224 
226  Constant *AddrIntVal =
228  Constant *AddrPtrVal =
229  ConstantExpr::getCast(Instruction::IntToPtr, AddrIntVal,
230  PointerType::get(&FT, 0));
231  return AddrPtrVal;
232 }
233 
235  const Twine &Name, Constant *Initializer) {
236  auto IP = new GlobalVariable(M, &PT, false, GlobalValue::ExternalLinkage,
237  Initializer, Name, nullptr,
238  GlobalValue::NotThreadLocal, 0, true);
239  IP->setVisibility(GlobalValue::HiddenVisibility);
240  return IP;
241 }
242 
243 void makeStub(Function &F, Value &ImplPointer) {
244  assert(F.isDeclaration() && "Can't turn a definition into a stub.");
245  assert(F.getParent() && "Function isn't in a module.");
246  Module &M = *F.getParent();
247  BasicBlock *EntryBlock = BasicBlock::Create(M.getContext(), "entry", &F);
248  IRBuilder<> Builder(EntryBlock);
249  LoadInst *ImplAddr = Builder.CreateLoad(F.getType(), &ImplPointer);
250  std::vector<Value*> CallArgs;
251  for (auto &A : F.args())
252  CallArgs.push_back(&A);
253  CallInst *Call = Builder.CreateCall(F.getFunctionType(), ImplAddr, CallArgs);
254  Call->setTailCall();
255  Call->setAttributes(F.getAttributes());
256  if (F.getReturnType()->isVoidTy())
257  Builder.CreateRetVoid();
258  else
259  Builder.CreateRet(Call);
260 }
261 
262 std::vector<GlobalValue *> SymbolLinkagePromoter::operator()(Module &M) {
263  std::vector<GlobalValue *> PromotedGlobals;
264 
265  for (auto &GV : M.global_values()) {
266  bool Promoted = true;
267 
268  // Rename if necessary.
269  if (!GV.hasName())
270  GV.setName("__orc_anon." + Twine(NextId++));
271  else if (GV.getName().startswith("\01L"))
272  GV.setName("__" + GV.getName().substr(1) + "." + Twine(NextId++));
273  else if (GV.hasLocalLinkage())
274  GV.setName("__orc_lcl." + GV.getName() + "." + Twine(NextId++));
275  else
276  Promoted = false;
277 
278  if (GV.hasLocalLinkage()) {
279  GV.setLinkage(GlobalValue::ExternalLinkage);
280  GV.setVisibility(GlobalValue::HiddenVisibility);
281  Promoted = true;
282  }
283  GV.setUnnamedAddr(GlobalValue::UnnamedAddr::None);
284 
285  if (Promoted)
286  PromotedGlobals.push_back(&GV);
287  }
288 
289  return PromotedGlobals;
290 }
291 
293  ValueToValueMapTy *VMap) {
294  Function *NewF =
295  Function::Create(cast<FunctionType>(F.getValueType()),
296  F.getLinkage(), F.getName(), &Dst);
297  NewF->copyAttributesFrom(&F);
298 
299  if (VMap) {
300  (*VMap)[&F] = NewF;
301  auto NewArgI = NewF->arg_begin();
302  for (auto ArgI = F.arg_begin(), ArgE = F.arg_end(); ArgI != ArgE;
303  ++ArgI, ++NewArgI)
304  (*VMap)[&*ArgI] = &*NewArgI;
305  }
306 
307  return NewF;
308 }
309 
311  ValueMaterializer *Materializer,
312  Function *NewF) {
313  assert(!OrigF.isDeclaration() && "Nothing to move");
314  if (!NewF)
315  NewF = cast<Function>(VMap[&OrigF]);
316  else
317  assert(VMap[&OrigF] == NewF && "Incorrect function mapping in VMap.");
318  assert(NewF && "Function mapping missing from VMap.");
319  assert(NewF->getParent() != OrigF.getParent() &&
320  "moveFunctionBody should only be used to move bodies between "
321  "modules.");
322 
323  SmallVector<ReturnInst *, 8> Returns; // Ignore returns cloned.
324  CloneFunctionInto(NewF, &OrigF, VMap,
326  nullptr, nullptr, Materializer);
327  OrigF.deleteBody();
328 }
329 
331  ValueToValueMapTy *VMap) {
332  GlobalVariable *NewGV = new GlobalVariable(
333  Dst, GV.getValueType(), GV.isConstant(),
334  GV.getLinkage(), nullptr, GV.getName(), nullptr,
336  NewGV->copyAttributesFrom(&GV);
337  if (VMap)
338  (*VMap)[&GV] = NewGV;
339  return NewGV;
340 }
341 
343  ValueToValueMapTy &VMap,
344  ValueMaterializer *Materializer,
345  GlobalVariable *NewGV) {
346  assert(OrigGV.hasInitializer() && "Nothing to move");
347  if (!NewGV)
348  NewGV = cast<GlobalVariable>(VMap[&OrigGV]);
349  else
350  assert(VMap[&OrigGV] == NewGV &&
351  "Incorrect global variable mapping in VMap.");
352  assert(NewGV->getParent() != OrigGV.getParent() &&
353  "moveGlobalVariableInitializer should only be used to move "
354  "initializers between modules");
355 
356  NewGV->setInitializer(MapValue(OrigGV.getInitializer(), VMap, RF_None,
357  nullptr, Materializer));
358 }
359 
361  ValueToValueMapTy &VMap) {
362  assert(OrigA.getAliasee() && "Original alias doesn't have an aliasee?");
363  auto *NewA = GlobalAlias::create(OrigA.getValueType(),
364  OrigA.getType()->getPointerAddressSpace(),
365  OrigA.getLinkage(), OrigA.getName(), &Dst);
366  NewA->copyAttributesFrom(&OrigA);
367  VMap[&OrigA] = NewA;
368  return NewA;
369 }
370 
371 void cloneModuleFlagsMetadata(Module &Dst, const Module &Src,
372  ValueToValueMapTy &VMap) {
373  auto *MFs = Src.getModuleFlagsMetadata();
374  if (!MFs)
375  return;
376  for (auto *MF : MFs->operands())
377  Dst.addModuleFlag(MapMetadata(MF, VMap));
378 }
379 
382  MCDisassembler &Disassembler,
383  MCInstrAnalysis &MIA) {
384  // AArch64 appears to already come with the necessary relocations. Among other
385  // architectures, only x86_64 is currently implemented here.
386  if (G.getTargetTriple().getArch() != Triple::x86_64)
387  return Error::success();
388 
389  raw_null_ostream CommentStream;
390  auto &STI = Disassembler.getSubtargetInfo();
391 
392  // Determine the function bounds
393  auto &B = Sym.getBlock();
394  assert(!B.isZeroFill() && "expected content block");
395  auto SymAddress = Sym.getAddress();
396  auto SymStartInBlock =
397  (const uint8_t *)B.getContent().data() + Sym.getOffset();
398  auto SymSize = Sym.getSize() ? Sym.getSize() : B.getSize() - Sym.getOffset();
399  auto Content = makeArrayRef(SymStartInBlock, SymSize);
400 
401  LLVM_DEBUG(dbgs() << "Adding self-relocations to " << Sym.getName() << "\n");
402 
403  SmallDenseSet<uintptr_t, 8> ExistingRelocations;
404  for (auto &E : B.edges()) {
405  if (E.isRelocation())
406  ExistingRelocations.insert(E.getOffset());
407  }
408 
409  size_t I = 0;
410  while (I < Content.size()) {
411  MCInst Instr;
412  uint64_t InstrSize = 0;
413  uint64_t InstrStart = SymAddress.getValue() + I;
414  auto DecodeStatus = Disassembler.getInstruction(
415  Instr, InstrSize, Content.drop_front(I), InstrStart, CommentStream);
417  LLVM_DEBUG(dbgs() << "Aborting due to disassembly failure at address "
418  << InstrStart);
419  return make_error<StringError>(
420  formatv("failed to disassemble at address {0:x16}", InstrStart),
422  }
423  // Advance to the next instruction.
424  I += InstrSize;
425 
426  // Check for a PC-relative address equal to the symbol itself.
427  auto PCRelAddr =
428  MIA.evaluateMemoryOperandAddress(Instr, &STI, InstrStart, InstrSize);
429  if (!PCRelAddr || *PCRelAddr != SymAddress.getValue())
430  continue;
431 
432  auto RelocOffInInstr =
433  MIA.getMemoryOperandRelocationOffset(Instr, InstrSize);
434  if (!RelocOffInInstr.hasValue() ||
435  InstrSize - RelocOffInInstr.getValue() != 4) {
436  LLVM_DEBUG(dbgs() << "Skipping unknown self-relocation at "
437  << InstrStart);
438  continue;
439  }
440 
441  auto RelocOffInBlock = orc::ExecutorAddr(InstrStart) + *RelocOffInInstr -
442  SymAddress + Sym.getOffset();
443  if (ExistingRelocations.contains(RelocOffInBlock))
444  continue;
445 
446  LLVM_DEBUG(dbgs() << "Adding delta32 self-relocation at " << InstrStart);
447  B.addEdge(jitlink::x86_64::Delta32, RelocOffInBlock, Sym, /*Addend=*/-4);
448  }
449  return Error::success();
450 }
451 
452 } // End namespace orc.
453 } // End namespace llvm.
llvm::orc::ExecutorAddr
Represents an address in the executor process.
Definition: ExecutorAddress.h:30
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: AllocatorList.h:23
llvm::orc::JITDylib
Represents a JIT'd dynamic library.
Definition: Core.h:947
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:457
llvm::GlobalValue::getLinkage
LinkageTypes getLinkage() const
Definition: GlobalValue.h:467
llvm::GlobalValue::HiddenVisibility
@ HiddenVisibility
The GV is hidden.
Definition: GlobalValue.h:64
T
llvm::Function
Definition: Function.h:62
llvm::Triple::x86
@ x86
Definition: Triple.h:82
llvm::raw_string_ostream
A raw_ostream that writes to an std::string.
Definition: raw_ostream.h:631
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:729
llvm::GlobalValue::NotThreadLocal
@ NotThreadLocal
Definition: GlobalValue.h:179
llvm::orc::cloneModuleFlagsMetadata
void cloneModuleFlagsMetadata(Module &Dst, const Module &Src, ValueToValueMapTy &VMap)
Clone module flags metadata into the destination module.
Definition: IndirectionUtils.cpp:371
llvm::SmallVector
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1175
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:39
llvm::orc::SymbolStringPtr
Pointer to a pooled string representing a symbol name.
Definition: SymbolStringPool.h:50
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:734
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:330
llvm::GlobalVariable
Definition: GlobalVariable.h:39
llvm::PointerType::getAddressSpace
unsigned getAddressSpace() const
Return the address space of the Pointer type.
Definition: DerivedTypes.h:687
Content
T Content
Definition: ELFObjHandler.cpp:89
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:83
llvm::Expected
Tagged union holding either a T or a Error.
Definition: APFloat.h:42
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:63
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: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:58
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:243
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:225
llvm::Triple::mips64el
@ mips64el
Definition: Triple.h:64
llvm::GlobalValue::getThreadLocalMode
ThreadLocalMode getThreadLocalMode() const
Definition: GlobalValue.h:252
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:262
llvm::MCDisassembler::Success
@ Success
Definition: MCDisassembler.h:103
IP
Definition: NVPTXLowerArgs.cpp:166
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:330
B
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
llvm::MCInstrAnalysis
Definition: MCInstrAnalysis.h:27
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:32
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:932
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:100
G
const DataFlowGraph & G
Definition: RDFGraph.cpp:202
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:578
Addr
uint64_t Addr
Definition: ELFObjHandler.cpp:79
llvm::orc::createLocalIndirectStubsManagerBuilder
std::function< std::unique_ptr< IndirectStubsManager >)> createLocalIndirectStubsManagerBuilder(const Triple &T)
Create a local indriect stubs manager builder.
Definition: IndirectionUtils.cpp:169
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:76
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:139
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:2015
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:650
llvm::raw_null_ostream
A raw_ostream that discards all output.
Definition: raw_ostream.h:694
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:234
llvm::orc::cloneGlobalAliasDecl
GlobalAlias * cloneGlobalAliasDecl(Module &Dst, const GlobalAlias &OrigA, ValueToValueMapTy &VMap)
Clone a global alias declaration into a new module.
Definition: IndirectionUtils.cpp:360
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:57
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:134
llvm::cantFail
void cantFail(Error Err, const char *Msg=nullptr)
Report a fatal error if Err is a failure value.
Definition: Error.h:746
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:100
llvm::orc::cloneFunctionDecl
Function * cloneFunctionDecl(Module &Dst, const Function &F, ValueToValueMapTy *VMap=nullptr)
Clone a function declaration into a new module.
Definition: IndirectionUtils.cpp:292
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:342
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:309
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:127
llvm::LoadInst
An instruction for reading from memory.
Definition: Instructions.h:180
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:243
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:242
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:482
llvm::Error
Lightweight error class with error context and mandatory checking.
Definition: Error.h:156
llvm::orc::ExecutionSession
An ExecutionSession represents a running JIT program.
Definition: Core.h:1359
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:380
llvm::Triple::mipsel
@ mipsel
Definition: Triple.h:62
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:738
llvm::MCDisassembler::getSubtargetInfo
const MCSubtargetInfo & getSubtargetInfo() const
Definition: MCDisassembler.h:188
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:474
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:87
IndirectionUtils.h
llvm::GlobalValue::getType
PointerType * getType() const
Global values are always pointers.
Definition: GlobalValue.h:271
llvm::GlobalValue::getValueType
Type * getValueType() const
Definition: GlobalValue.h:273
llvm::CallInst
This class represents a function call, abstracting a target machine's calling convention.
Definition: Instructions.h:1478
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:83
llvm::orc::TrampolinePool::~TrampolinePool
virtual ~TrampolinePool()
Definition: IndirectionUtils.cpp:62
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:310
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:61
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:434
llvm::JITSymbolFlags::Exported
@ Exported
Definition: JITSymbol.h:85
llvm::FunctionType
Class to represent function types.
Definition: DerivedTypes.h:103