mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-12 17:32:19 +00:00
[Orc] Tidy up IndirectionUtils API a little, add some comments. NFC.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@234669 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
3e68e2879f
commit
c6665c6b72
@ -261,7 +261,8 @@ private:
|
||||
auto CallbackInfo =
|
||||
CompileCallbackMgr.getCompileCallback(Proto->getContext());
|
||||
GlobalVariable *FunctionBodyPointer =
|
||||
createImplPointer(*Proto, Name + AddrSuffix,
|
||||
createImplPointer(*Proto->getType(), *Proto->getParent(),
|
||||
Name + AddrSuffix,
|
||||
createIRTypedAddress(*Proto->getFunctionType(),
|
||||
CallbackInfo.getAddress()));
|
||||
makeStub(*Proto, *FunctionBodyPointer);
|
||||
|
@ -203,16 +203,7 @@ private:
|
||||
TargetAddress ResolverBlockAddr;
|
||||
};
|
||||
|
||||
inline Constant* createIRTypedAddress(FunctionType &FT, TargetAddress Addr) {
|
||||
Constant *AddrIntVal =
|
||||
ConstantInt::get(Type::getInt64Ty(FT.getContext()), Addr);
|
||||
Constant *AddrPtrVal =
|
||||
ConstantExpr::getCast(Instruction::IntToPtr, AddrIntVal,
|
||||
PointerType::get(&FT, 0));
|
||||
return AddrPtrVal;
|
||||
}
|
||||
|
||||
/// @brief Get an update functor for updating the value of a named function
|
||||
/// @brief Get an update functor that updates the value of a named function
|
||||
/// pointer.
|
||||
template <typename JITLayerT>
|
||||
JITCompileCallbackManagerBase::UpdateFtor
|
||||
@ -228,13 +219,26 @@ getLocalFPUpdater(JITLayerT &JIT, typename JITLayerT::ModuleSetHandleT H,
|
||||
};
|
||||
}
|
||||
|
||||
GlobalVariable* createImplPointer(Function &F, const Twine &Name,
|
||||
Constant *Initializer);
|
||||
/// @brief Build a function pointer of FunctionType with the given constant
|
||||
/// address.
|
||||
///
|
||||
/// Usage example: Turn a trampoline address into a function pointer constant
|
||||
/// for use in a stub.
|
||||
Constant* createIRTypedAddress(FunctionType &FT, TargetAddress Addr);
|
||||
|
||||
/// @brief Create a function pointer with the given type, name, and initializer
|
||||
/// in the given Module.
|
||||
GlobalVariable* createImplPointer(PointerType &PT, Module &M,
|
||||
const Twine &Name, Constant *Initializer);
|
||||
|
||||
/// @brief Turn a function declaration into a stub function that makes an
|
||||
/// indirect call using the given function pointer.
|
||||
void makeStub(Function &F, GlobalVariable &ImplPointer);
|
||||
|
||||
typedef std::map<Module*, DenseSet<const GlobalValue*>> ModulePartitionMap;
|
||||
|
||||
/// @brief Extract subsections of a Module into the given Module according to
|
||||
/// the given ModulePartitionMap.
|
||||
void partition(Module &M, const ModulePartitionMap &PMap);
|
||||
|
||||
/// @brief Struct for trivial "complete" partitioning of a module.
|
||||
@ -250,6 +254,7 @@ public:
|
||||
Functions(std::move(S.Functions)) {}
|
||||
};
|
||||
|
||||
/// @brief Extract every function in M into a separate module.
|
||||
FullyPartitionedModule fullyPartition(Module &M);
|
||||
|
||||
} // End namespace orc.
|
||||
|
@ -18,13 +18,20 @@
|
||||
namespace llvm {
|
||||
namespace orc {
|
||||
|
||||
GlobalVariable* createImplPointer(Function &F, const Twine &Name,
|
||||
Constant *Initializer) {
|
||||
assert(F.getParent() && "Function isn't in a module.");
|
||||
Constant* createIRTypedAddress(FunctionType &FT, TargetAddress Addr) {
|
||||
Constant *AddrIntVal =
|
||||
ConstantInt::get(Type::getInt64Ty(FT.getContext()), Addr);
|
||||
Constant *AddrPtrVal =
|
||||
ConstantExpr::getCast(Instruction::IntToPtr, AddrIntVal,
|
||||
PointerType::get(&FT, 0));
|
||||
return AddrPtrVal;
|
||||
}
|
||||
|
||||
GlobalVariable* createImplPointer(PointerType &PT, Module &M,
|
||||
const Twine &Name, Constant *Initializer) {
|
||||
if (!Initializer)
|
||||
Initializer = Constant::getNullValue(F.getType());
|
||||
Module &M = *F.getParent();
|
||||
return new GlobalVariable(M, F.getType(), false, GlobalValue::ExternalLinkage,
|
||||
Initializer = Constant::getNullValue(&PT);
|
||||
return new GlobalVariable(M, &PT, false, GlobalValue::ExternalLinkage,
|
||||
Initializer, Name, nullptr,
|
||||
GlobalValue::NotThreadLocal, 0, true);
|
||||
}
|
||||
@ -51,6 +58,7 @@ void partition(Module &M, const ModulePartitionMap &PMap) {
|
||||
auto ExtractGlobalVars =
|
||||
[&](GlobalVariable &New, const GlobalVariable &Orig,
|
||||
ValueToValueMapTy &VMap) {
|
||||
assert(Orig.hasName() && "Extracted globals must have names.");
|
||||
if (KVPair.second.count(&Orig)) {
|
||||
copyGVInitializer(New, Orig, VMap);
|
||||
}
|
||||
@ -62,6 +70,7 @@ void partition(Module &M, const ModulePartitionMap &PMap) {
|
||||
|
||||
auto ExtractFunctions =
|
||||
[&](Function &New, const Function &Orig, ValueToValueMapTy &VMap) {
|
||||
assert(Orig.hasName() && "Extracted functions must have names.");
|
||||
if (KVPair.second.count(&Orig))
|
||||
copyFunctionBody(New, Orig, VMap);
|
||||
if (New.hasLocalLinkage()) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user