Skip to content

Commit

Permalink
Factor a loop out of LateLowerGCFrame::runOnFunction and into GCLower…
Browse files Browse the repository at this point in the history
…ingRefs
  • Loading branch information
jonathanvdc committed Feb 17, 2019
1 parent 262875a commit 5457a5c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
14 changes: 14 additions & 0 deletions src/llvm-late-gc-helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@ void GCLoweringRefs::initFunctions(Module &M) {
}

void GCLoweringRefs::initAll(Module &M) {
// First initialize the functions.
initFunctions(M);

// Then initialize types and metadata nodes.
auto &ctx = M.getContext();
T_size = M.getDataLayout().getIntPtrType(ctx);
T_int8 = Type::getInt8Ty(ctx);
Expand Down Expand Up @@ -56,3 +58,15 @@ void GCLoweringRefs::initAll(Module &M) {
T_ppjlvalue_der = nullptr;
}
}

llvm::CallInst *GCLoweringRefs::getPtls(llvm::Function &F) {
for (auto I = F.getEntryBlock().begin(), E = F.getEntryBlock().end();
ptls_getter && I != E; ++I) {
if (CallInst *callInst = dyn_cast<CallInst>(&*I)) {
if (callInst->getCalledValue() == ptls_getter) {
return callInst;
}
}
}
return nullptr;
}
10 changes: 7 additions & 3 deletions src/llvm-late-gc-helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
#define LLVM_LATE_GC_HELPERS_H

#include <llvm/IR/Function.h>
#include <llvm/IR/Instructions.h>
#include <llvm/IR/Metadata.h>
#include <llvm/IR/Module.h>
#include <llvm/IR/Type.h>

// A data structure that contains references to platform-agnostic GC lowering
// types, metadata and functions.
// types and functions.
struct GCLoweringRefs {
llvm::Type *T_prjlvalue;
llvm::Type *T_ppjlvalue;
Expand All @@ -20,8 +21,6 @@ struct GCLoweringRefs {
llvm::Type *T_pjlvalue;
llvm::Type *T_pjlvalue_der;
llvm::Type *T_ppjlvalue_der;
llvm::MDNode *tbaa_gcframe;
llvm::MDNode *tbaa_tag;
llvm::Function *ptls_getter;
llvm::Function *gc_flush_func;
llvm::Function *gc_preserve_begin_func;
Expand All @@ -36,6 +35,11 @@ struct GCLoweringRefs {

// Initializes a GC lowering refs structure's functions only.
void initFunctions(llvm::Module &M);

// Gets a call to the `julia.ptls_states` intrinisc in the entry
// point of the given function, if there exists such as call.
// Otherwise, `nullptr` is returned.
llvm::CallInst *getPtls(llvm::Function &F);
};

#endif
14 changes: 4 additions & 10 deletions src/llvm-late-gc-lowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,8 @@ struct LateLowerGCFrame: public FunctionPass, private GCLoweringRefs {
}

private:
llvm::MDNode *tbaa_gcframe;
llvm::MDNode *tbaa_tag;
Function *queueroot_func;
Function *pool_alloc_func;
Function *big_alloc_func;
Expand Down Expand Up @@ -2100,16 +2102,8 @@ bool LateLowerGCFrame::runOnFunction(Function &F) {
initFunctions(*F.getParent());
if (!ptls_getter)
return CleanupIR(F);
ptlsStates = nullptr;
for (auto I = F.getEntryBlock().begin(), E = F.getEntryBlock().end();
ptls_getter && I != E; ++I) {
if (CallInst *callInst = dyn_cast<CallInst>(&*I)) {
if (callInst->getCalledValue() == ptls_getter) {
ptlsStates = callInst;
break;
}
}
}

ptlsStates = getPtls(F);
if (!ptlsStates)
return CleanupIR(F);
State S = LocalScan(F);
Expand Down

0 comments on commit 5457a5c

Please sign in to comment.