Skip to content

Commit

Permalink
aotcompile: add missing codegen support for OC
Browse files Browse the repository at this point in the history
  • Loading branch information
vtjnash committed Nov 12, 2024
1 parent b0e7fed commit 7ed179b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
32 changes: 19 additions & 13 deletions src/aotcompile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,9 @@ void *jl_create_native_impl(jl_array_t *methods, LLVMOrcThreadSafeModuleRef llvm
else if (func == "jl_fptr_sparam") {
func_id = -2;
}
else if (decls.functionObject != "jl_f_opaque_closure_call") {
func_id = -3;
}
else {
//Safe b/c context is locked by params
data->jl_sysimg_fvars.push_back(cast<Function>(clone.getModuleUnlocked()->getNamedValue(func)));
Expand Down Expand Up @@ -904,11 +907,13 @@ static bool canPartition(const GlobalValue &G) {
return true;
}

static inline bool verify_partitioning(const SmallVectorImpl<Partition> &partitions, const Module &M, size_t fvars_size, size_t gvars_size) {
static inline bool verify_partitioning(const SmallVectorImpl<Partition> &partitions, const Module &M, DenseMap<GlobalValue *, unsigned> &fvars, DenseMap<GlobalValue *, unsigned> &gvars) {
size_t fvars_size = fvars.size();
size_t gvars_size = gvars.size();
bool bad = false;
#ifndef JL_NDEBUG
SmallVector<uint32_t, 0> fvars(fvars_size);
SmallVector<uint32_t, 0> gvars(gvars_size);
SmallVector<uint32_t, 0> fvars_partition(fvars_size);
SmallVector<uint32_t, 0> gvars_partition(gvars_size);
StringMap<uint32_t> GVNames;
for (uint32_t i = 0; i < partitions.size(); i++) {
for (auto &name : partitions[i].globals) {
Expand All @@ -919,18 +924,18 @@ static inline bool verify_partitioning(const SmallVectorImpl<Partition> &partiti
GVNames[name.getKey()] = i;
}
for (auto &fvar : partitions[i].fvars) {
if (fvars[fvar.second] != 0) {
if (fvars_partition[fvar.second] != 0) {
bad = true;
dbgs() << "Duplicate fvar " << fvar.first() << " in partitions " << i << " and " << fvars[fvar.second] - 1 << "\n";
dbgs() << "Duplicate fvar " << fvar.first() << " in partitions " << i << " and " << fvars_partition[fvar.second] - 1 << "\n";
}
fvars[fvar.second] = i+1;
fvars_partition[fvar.second] = i+1;
}
for (auto &gvar : partitions[i].gvars) {
if (gvars[gvar.second] != 0) {
if (gvars_partition[gvar.second] != 0) {
bad = true;
dbgs() << "Duplicate gvar " << gvar.first() << " in partitions " << i << " and " << gvars[gvar.second] - 1 << "\n";
dbgs() << "Duplicate gvar " << gvar.first() << " in partitions " << i << " and " << gvars_partition[gvar.second] - 1 << "\n";
}
gvars[gvar.second] = i+1;
gvars_partition[gvar.second] = i+1;
}
}
for (auto &GV : M.global_values()) {
Expand Down Expand Up @@ -967,13 +972,14 @@ static inline bool verify_partitioning(const SmallVectorImpl<Partition> &partiti
}
}
for (uint32_t i = 0; i < fvars_size; i++) {
if (fvars[i] == 0) {
if (fvars_partition[i] == 0) {
auto gv = find_if(fvars.begin(), fvars.end(), [i](auto var) { return var.second == i; });
bad = true;
dbgs() << "fvar " << i << " not in any partition\n";
dbgs() << "fvar " << gv->first->getName() << " at " << i << " not in any partition\n";
}
}
for (uint32_t i = 0; i < gvars_size; i++) {
if (gvars[i] == 0) {
if (gvars_partition[i] == 0) {
bad = true;
dbgs() << "gvar " << i << " not in any partition\n";
}
Expand Down Expand Up @@ -1117,7 +1123,7 @@ static SmallVector<Partition, 32> partitionModule(Module &M, unsigned threads) {
}
}

bool verified = verify_partitioning(partitions, M, fvars.size(), gvars.size());
bool verified = verify_partitioning(partitions, M, fvars, gvars);
assert(verified && "Partitioning failed to partition globals correctly");
(void) verified;

Expand Down
8 changes: 8 additions & 0 deletions src/staticdata.c
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,7 @@ typedef enum {
JL_API_BOXED,
JL_API_CONST,
JL_API_WITH_PARAMETERS,
JL_API_OC_CALL,
JL_API_INTERPRETED,
JL_API_BUILTIN,
JL_API_MAX
Expand Down Expand Up @@ -1797,6 +1798,9 @@ static void jl_write_values(jl_serializer_state *s) JL_GC_DISABLED
else if (invokeptr_id == -2) {
fptr_id = JL_API_WITH_PARAMETERS;
}
else if (invokeptr_id == -3) {
fptr_id = JL_API_OC_CALL;
}
else {
assert(invokeptr_id > 0);
ios_ensureroom(s->fptr_record, invokeptr_id * sizeof(void*));
Expand Down Expand Up @@ -2038,6 +2042,10 @@ static inline uintptr_t get_item_for_reloc(jl_serializer_state *s, uintptr_t bas
if (s->image->fptrs.nptrs)
return (uintptr_t)jl_fptr_sparam;
return (uintptr_t)NULL;
case JL_API_OC_CALL:
if (s->image->fptrs.nptrs)
return (uintptr_t)jl_f_opaque_closure_call;
return (uintptr_t)NULL;
case JL_API_CONST:
return (uintptr_t)jl_fptr_const_return;
case JL_API_INTERPRETED:
Expand Down

0 comments on commit 7ed179b

Please sign in to comment.