Skip to content

Commit 7ed179b

Browse files
committed
aotcompile: add missing codegen support for OC
1 parent b0e7fed commit 7ed179b

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

src/aotcompile.cpp

+19-13
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,9 @@ void *jl_create_native_impl(jl_array_t *methods, LLVMOrcThreadSafeModuleRef llvm
609609
else if (func == "jl_fptr_sparam") {
610610
func_id = -2;
611611
}
612+
else if (decls.functionObject != "jl_f_opaque_closure_call") {
613+
func_id = -3;
614+
}
612615
else {
613616
//Safe b/c context is locked by params
614617
data->jl_sysimg_fvars.push_back(cast<Function>(clone.getModuleUnlocked()->getNamedValue(func)));
@@ -904,11 +907,13 @@ static bool canPartition(const GlobalValue &G) {
904907
return true;
905908
}
906909

907-
static inline bool verify_partitioning(const SmallVectorImpl<Partition> &partitions, const Module &M, size_t fvars_size, size_t gvars_size) {
910+
static inline bool verify_partitioning(const SmallVectorImpl<Partition> &partitions, const Module &M, DenseMap<GlobalValue *, unsigned> &fvars, DenseMap<GlobalValue *, unsigned> &gvars) {
911+
size_t fvars_size = fvars.size();
912+
size_t gvars_size = gvars.size();
908913
bool bad = false;
909914
#ifndef JL_NDEBUG
910-
SmallVector<uint32_t, 0> fvars(fvars_size);
911-
SmallVector<uint32_t, 0> gvars(gvars_size);
915+
SmallVector<uint32_t, 0> fvars_partition(fvars_size);
916+
SmallVector<uint32_t, 0> gvars_partition(gvars_size);
912917
StringMap<uint32_t> GVNames;
913918
for (uint32_t i = 0; i < partitions.size(); i++) {
914919
for (auto &name : partitions[i].globals) {
@@ -919,18 +924,18 @@ static inline bool verify_partitioning(const SmallVectorImpl<Partition> &partiti
919924
GVNames[name.getKey()] = i;
920925
}
921926
for (auto &fvar : partitions[i].fvars) {
922-
if (fvars[fvar.second] != 0) {
927+
if (fvars_partition[fvar.second] != 0) {
923928
bad = true;
924-
dbgs() << "Duplicate fvar " << fvar.first() << " in partitions " << i << " and " << fvars[fvar.second] - 1 << "\n";
929+
dbgs() << "Duplicate fvar " << fvar.first() << " in partitions " << i << " and " << fvars_partition[fvar.second] - 1 << "\n";
925930
}
926-
fvars[fvar.second] = i+1;
931+
fvars_partition[fvar.second] = i+1;
927932
}
928933
for (auto &gvar : partitions[i].gvars) {
929-
if (gvars[gvar.second] != 0) {
934+
if (gvars_partition[gvar.second] != 0) {
930935
bad = true;
931-
dbgs() << "Duplicate gvar " << gvar.first() << " in partitions " << i << " and " << gvars[gvar.second] - 1 << "\n";
936+
dbgs() << "Duplicate gvar " << gvar.first() << " in partitions " << i << " and " << gvars_partition[gvar.second] - 1 << "\n";
932937
}
933-
gvars[gvar.second] = i+1;
938+
gvars_partition[gvar.second] = i+1;
934939
}
935940
}
936941
for (auto &GV : M.global_values()) {
@@ -967,13 +972,14 @@ static inline bool verify_partitioning(const SmallVectorImpl<Partition> &partiti
967972
}
968973
}
969974
for (uint32_t i = 0; i < fvars_size; i++) {
970-
if (fvars[i] == 0) {
975+
if (fvars_partition[i] == 0) {
976+
auto gv = find_if(fvars.begin(), fvars.end(), [i](auto var) { return var.second == i; });
971977
bad = true;
972-
dbgs() << "fvar " << i << " not in any partition\n";
978+
dbgs() << "fvar " << gv->first->getName() << " at " << i << " not in any partition\n";
973979
}
974980
}
975981
for (uint32_t i = 0; i < gvars_size; i++) {
976-
if (gvars[i] == 0) {
982+
if (gvars_partition[i] == 0) {
977983
bad = true;
978984
dbgs() << "gvar " << i << " not in any partition\n";
979985
}
@@ -1117,7 +1123,7 @@ static SmallVector<Partition, 32> partitionModule(Module &M, unsigned threads) {
11171123
}
11181124
}
11191125

1120-
bool verified = verify_partitioning(partitions, M, fvars.size(), gvars.size());
1126+
bool verified = verify_partitioning(partitions, M, fvars, gvars);
11211127
assert(verified && "Partitioning failed to partition globals correctly");
11221128
(void) verified;
11231129

src/staticdata.c

+8
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,7 @@ typedef enum {
587587
JL_API_BOXED,
588588
JL_API_CONST,
589589
JL_API_WITH_PARAMETERS,
590+
JL_API_OC_CALL,
590591
JL_API_INTERPRETED,
591592
JL_API_BUILTIN,
592593
JL_API_MAX
@@ -1797,6 +1798,9 @@ static void jl_write_values(jl_serializer_state *s) JL_GC_DISABLED
17971798
else if (invokeptr_id == -2) {
17981799
fptr_id = JL_API_WITH_PARAMETERS;
17991800
}
1801+
else if (invokeptr_id == -3) {
1802+
fptr_id = JL_API_OC_CALL;
1803+
}
18001804
else {
18011805
assert(invokeptr_id > 0);
18021806
ios_ensureroom(s->fptr_record, invokeptr_id * sizeof(void*));
@@ -2038,6 +2042,10 @@ static inline uintptr_t get_item_for_reloc(jl_serializer_state *s, uintptr_t bas
20382042
if (s->image->fptrs.nptrs)
20392043
return (uintptr_t)jl_fptr_sparam;
20402044
return (uintptr_t)NULL;
2045+
case JL_API_OC_CALL:
2046+
if (s->image->fptrs.nptrs)
2047+
return (uintptr_t)jl_f_opaque_closure_call;
2048+
return (uintptr_t)NULL;
20412049
case JL_API_CONST:
20422050
return (uintptr_t)jl_fptr_const_return;
20432051
case JL_API_INTERPRETED:

0 commit comments

Comments
 (0)