Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve remarks of the alloc opt pass slightly. #55995

Merged
merged 3 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions src/llvm-alloc-helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,16 @@ JL_USED_FUNC void AllocUseInfo::dump(llvm::raw_ostream &OS)
OS << " zeroed";
OS << '\n';
OS << "Uses: " << uses.size() << '\n';
for (auto inst: uses)
for (auto inst: uses) {
inst->print(OS);
OS << '\n';
}
if (!preserves.empty()) {
OS << "Preserves: " << preserves.size() << '\n';
for (auto inst: preserves)
for (auto inst: preserves) {
inst->print(OS);
OS << '\n';
}
}
OS << "MemOps: " << memops.size() << '\n';
for (auto &field: memops) {
Expand Down Expand Up @@ -268,9 +272,12 @@ void jl_alloc::runEscapeAnalysis(llvm::CallInst *I, EscapeAnalysisRequiredArgs r
}
LLVM_DEBUG(dbgs() << "Unknown call, marking escape\n");
REMARK([&]() {
std::string str;
llvm::raw_string_ostream rso(str);
inst->print(rso);
return OptimizationRemarkMissed(DEBUG_TYPE, "UnknownCall",
inst)
<< "Unknown call, marking escape (" << ore::NV("Call", inst) << ")";
<< "Unknown call, marking escape (" << ore::NV("Call", StringRef(str)) << ")";
});
required.use_info.escaped = true;
return false;
Expand All @@ -284,9 +291,12 @@ void jl_alloc::runEscapeAnalysis(llvm::CallInst *I, EscapeAnalysisRequiredArgs r
if (use->getOperandNo() != StoreInst::getPointerOperandIndex()) {
LLVM_DEBUG(dbgs() << "Object address is stored somewhere, marking escape\n");
REMARK([&]() {
std::string str;
llvm::raw_string_ostream rso(str);
inst->print(rso);
return OptimizationRemarkMissed(DEBUG_TYPE, "StoreObjAddr",
inst)
<< "Object address is stored somewhere, marking escape (" << ore::NV("Store", inst) << ")";
<< "Object address is stored somewhere, marking escape (" << ore::NV("Store", StringRef(str)) << ")";
});
required.use_info.escaped = true;
return false;
Expand All @@ -310,9 +320,12 @@ void jl_alloc::runEscapeAnalysis(llvm::CallInst *I, EscapeAnalysisRequiredArgs r
if (use->getOperandNo() != isa<AtomicCmpXchgInst>(inst) ? AtomicCmpXchgInst::getPointerOperandIndex() : AtomicRMWInst::getPointerOperandIndex()) {
LLVM_DEBUG(dbgs() << "Object address is cmpxchg/rmw-ed somewhere, marking escape\n");
REMARK([&]() {
std::string str;
llvm::raw_string_ostream rso(str);
inst->print(rso);
return OptimizationRemarkMissed(DEBUG_TYPE, "StoreObjAddr",
inst)
<< "Object address is cmpxchg/rmw-ed somewhere, marking escape (" << ore::NV("Store", inst) << ")";
<< "Object address is cmpxchg/rmw-ed somewhere, marking escape (" << ore::NV("Store", StringRef(str)) << ")";
});
required.use_info.escaped = true;
return false;
Expand Down Expand Up @@ -363,9 +376,12 @@ void jl_alloc::runEscapeAnalysis(llvm::CallInst *I, EscapeAnalysisRequiredArgs r
}
LLVM_DEBUG(dbgs() << "Unknown instruction, marking escape\n");
REMARK([&]() {
std::string str;
llvm::raw_string_ostream rso(str);
inst->print(rso);
return OptimizationRemarkMissed(DEBUG_TYPE, "UnknownInst",
inst)
<< "Unknown instruction, marking escape (" << ore::NV("Inst", inst) << ")";
<< "Unknown instruction, marking escape (" << ore::NV("Inst", StringRef(str)) << ")";
});
required.use_info.escaped = true;
return false;
Expand Down
46 changes: 37 additions & 9 deletions src/llvm-alloc-opt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,21 +220,28 @@ void Optimizer::optimizeAll()
while (!worklist.empty()) {
auto item = worklist.pop_back_val();
auto orig = item.first;
orig->print(dbgs());
size_t sz = item.second;
checkInst(orig);
if (use_info.escaped) {
REMARK([&]() {
std::string str;
llvm::raw_string_ostream rso(str);
orig->print(rso);
return OptimizationRemarkMissed(DEBUG_TYPE, "Escaped", orig)
<< "GC allocation escaped " << ore::NV("GC Allocation", orig);
<< "GC allocation escaped " << ore::NV("GC Allocation", StringRef(str));
});
if (use_info.hastypeof)
optimizeTag(orig);
continue;
}
if (use_info.haserror || use_info.returned) {
REMARK([&]() {
std::string str;
llvm::raw_string_ostream rso(str);
orig->print(rso);
return OptimizationRemarkMissed(DEBUG_TYPE, "Escaped", orig)
<< "GC allocation has error or was returned " << ore::NV("GC Allocation", orig);
<< "GC allocation has error or was returned " << ore::NV("GC Allocation", StringRef(str));
});
if (use_info.hastypeof)
optimizeTag(orig);
Expand All @@ -243,8 +250,11 @@ void Optimizer::optimizeAll()
if (!use_info.addrescaped && !use_info.hasload && (!use_info.haspreserve ||
!use_info.refstore)) {
REMARK([&]() {
std::string str;
llvm::raw_string_ostream rso(str);
orig->print(rso);
return OptimizationRemark(DEBUG_TYPE, "Dead Allocation", orig)
<< "GC allocation removed " << ore::NV("GC Allocation", orig);
<< "GC allocation removed " << ore::NV("GC Allocation", StringRef(str));
});
// No one took the address, no one reads anything and there's no meaningful
// preserve of fields (either no preserve/ccall or no object reference fields)
Expand All @@ -270,17 +280,23 @@ void Optimizer::optimizeAll()
}
if (has_refaggr) {
REMARK([&]() {
std::string str;
llvm::raw_string_ostream rso(str);
orig->print(rso);
return OptimizationRemarkMissed(DEBUG_TYPE, "Escaped", orig)
<< "GC allocation has unusual object reference, unable to move to stack " << ore::NV("GC Allocation", orig);
<< "GC allocation has unusual object reference, unable to move to stack " << ore::NV("GC Allocation", StringRef(str));
});
if (use_info.hastypeof)
optimizeTag(orig);
continue;
}
if (!use_info.hasunknownmem && !use_info.addrescaped) {
REMARK([&](){
std::string str;
llvm::raw_string_ostream rso(str);
orig->print(rso);
return OptimizationRemark(DEBUG_TYPE, "Stack Split Allocation", orig)
<< "GC allocation split on stack " << ore::NV("GC Allocation", orig);
<< "GC allocation split on stack " << ore::NV("GC Allocation", StringRef(str));
});
// No one actually care about the memory layout of this object, split it.
splitOnStack(orig);
Expand All @@ -292,16 +308,22 @@ void Optimizer::optimizeAll()
// This later causes the GC rooting pass, to miss-characterize the float as a pointer to a GC value
if (has_unboxed && has_ref) {
REMARK([&]() {
std::string str;
llvm::raw_string_ostream rso(str);
orig->print(rso);
return OptimizationRemarkMissed(DEBUG_TYPE, "Escaped", orig)
<< "GC allocation could not be split since it contains both boxed and unboxed values, unable to move to stack " << ore::NV("GC Allocation", orig);
<< "GC allocation could not be split since it contains both boxed and unboxed values, unable to move to stack " << ore::NV("GC Allocation", StringRef(str));
});
if (use_info.hastypeof)
optimizeTag(orig);
continue;
}
REMARK([&](){
std::string str;
llvm::raw_string_ostream rso(str);
orig->print(rso);
return OptimizationRemark(DEBUG_TYPE, "Stack Move Allocation", orig)
<< "GC allocation moved to stack " << ore::NV("GC Allocation", orig);
<< "GC allocation moved to stack " << ore::NV("GC Allocation", StringRef(str));
});
// The object has no fields with mix reference access
moveToStack(orig, sz, has_ref, use_info.allockind);
Expand Down Expand Up @@ -380,7 +402,10 @@ void Optimizer::checkInst(CallInst *I)
std::string suse_info;
llvm::raw_string_ostream osuse_info(suse_info);
use_info.dump(osuse_info);
return OptimizationRemarkAnalysis(DEBUG_TYPE, "EscapeAnalysis", I) << "escape analysis for " << ore::NV("GC Allocation", I) << "\n" << ore::NV("UseInfo", osuse_info.str());
std::string str;
llvm::raw_string_ostream rso(str);
I->print(rso);
return OptimizationRemarkAnalysis(DEBUG_TYPE, "EscapeAnalysis", I) << "escape analysis for " << ore::NV("GC Allocation", StringRef(str)) << "\n" << ore::NV("UseInfo", osuse_info.str());
});
}

Expand Down Expand Up @@ -905,8 +930,11 @@ void Optimizer::optimizeTag(CallInst *orig_inst)
if (pass.typeof_func == callee) {
++RemovedTypeofs;
REMARK([&](){
std::string str;
llvm::raw_string_ostream rso(str);
orig_inst->print(rso);
return OptimizationRemark(DEBUG_TYPE, "typeof", call)
<< "removed typeof call for GC allocation " << ore::NV("Alloc", orig_inst);
<< "removed typeof call for GC allocation " << ore::NV("Alloc", StringRef(str));
});
call->replaceAllUsesWith(tag);
// Push to the removed instructions to trigger `finalize` to
Expand Down