Skip to content

Commit

Permalink
aotcompile: reimplement canPartition correctly
Browse files Browse the repository at this point in the history
This could previously cause any use of llvmcall to crash during ji
generate or generate bad code. Now it uses the llvm attribute to specify
this correctly.
  • Loading branch information
vtjnash committed Nov 12, 2024
1 parent 7a78467 commit b026ab6
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions src/aotcompile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -900,12 +900,9 @@ struct Partition {
size_t weight;
};

static bool canPartition(const GlobalValue &G) {
if (auto F = dyn_cast<Function>(&G)) {
if (F->hasFnAttribute(Attribute::AlwaysInline))
return false;
}
return true;
static bool canPartition(const Function &F)
{
return !F.hasFnAttribute(Attribute::AlwaysInline);
}

static inline bool verify_partitioning(const SmallVectorImpl<Partition> &partitions, const Module &M, DenseMap<GlobalValue *, unsigned> &fvars, DenseMap<GlobalValue *, unsigned> &gvars) {
Expand Down Expand Up @@ -947,13 +944,6 @@ static inline bool verify_partitioning(const SmallVectorImpl<Partition> &partiti
}
} else {
// Local global values are not partitioned
if (!canPartition(GV)) {
if (GVNames.count(GV.getName())) {
bad = true;
dbgs() << "Shouldn't have partitioned " << GV.getName() << ", but is in partition " << GVNames[GV.getName()] << "\n";
}
continue;
}
if (!GVNames.count(GV.getName())) {
bad = true;
dbgs() << "Global " << GV << " not in any partition\n";
Expand Down Expand Up @@ -1042,8 +1032,6 @@ static SmallVector<Partition, 32> partitionModule(Module &M, unsigned threads) {
for (auto &G : M.global_values()) {
if (G.isDeclaration())
continue;
if (!canPartition(G))
continue;
// Currently ccallable global aliases have extern linkage, we only want to make the
// internally linked functions/global variables extern+hidden
if (G.hasLocalLinkage()) {
Expand All @@ -1052,7 +1040,8 @@ static SmallVector<Partition, 32> partitionModule(Module &M, unsigned threads) {
}
if (auto F = dyn_cast<Function>(&G)) {
partitioner.make(&G, getFunctionWeight(*F).weight);
} else {
}
else {
partitioner.make(&G, 1);
}
}
Expand Down Expand Up @@ -1380,6 +1369,12 @@ static void materializePreserved(Module &M, Partition &partition) {
continue;
if (Preserve.contains(&F))
continue;
if (!canPartition(F)) {
F.setLinkage(GlobalValue::AvailableExternallyLinkage);
F.setVisibility(GlobalValue::HiddenVisibility);
F.setDSOLocal(true);
continue;
}
F.deleteBody();
F.setLinkage(GlobalValue::ExternalLinkage);
F.setVisibility(GlobalValue::HiddenVisibility);
Expand Down

0 comments on commit b026ab6

Please sign in to comment.