Skip to content

Commit 159adbf

Browse files
Improve remarks of the alloc opt pass slightly. (#55995)
The Value printer LLVM uses just prints the kind of instruction so it just shows call. --------- Co-authored-by: Oscar Smith <[email protected]>
1 parent a19569d commit 159adbf

File tree

2 files changed

+58
-15
lines changed

2 files changed

+58
-15
lines changed

src/llvm-alloc-helpers.cpp

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,12 +134,16 @@ JL_USED_FUNC void AllocUseInfo::dump(llvm::raw_ostream &OS)
134134
OS << " zeroed";
135135
OS << '\n';
136136
OS << "Uses: " << uses.size() << '\n';
137-
for (auto inst: uses)
137+
for (auto inst: uses) {
138138
inst->print(OS);
139+
OS << '\n';
140+
}
139141
if (!preserves.empty()) {
140142
OS << "Preserves: " << preserves.size() << '\n';
141-
for (auto inst: preserves)
143+
for (auto inst: preserves) {
142144
inst->print(OS);
145+
OS << '\n';
146+
}
143147
}
144148
OS << "MemOps: " << memops.size() << '\n';
145149
for (auto &field: memops) {
@@ -268,9 +272,12 @@ void jl_alloc::runEscapeAnalysis(llvm::CallInst *I, EscapeAnalysisRequiredArgs r
268272
}
269273
LLVM_DEBUG(dbgs() << "Unknown call, marking escape\n");
270274
REMARK([&]() {
275+
std::string str;
276+
llvm::raw_string_ostream rso(str);
277+
inst->print(rso);
271278
return OptimizationRemarkMissed(DEBUG_TYPE, "UnknownCall",
272279
inst)
273-
<< "Unknown call, marking escape (" << ore::NV("Call", inst) << ")";
280+
<< "Unknown call, marking escape (" << ore::NV("Call", StringRef(str)) << ")";
274281
});
275282
required.use_info.escaped = true;
276283
return false;
@@ -284,9 +291,12 @@ void jl_alloc::runEscapeAnalysis(llvm::CallInst *I, EscapeAnalysisRequiredArgs r
284291
if (use->getOperandNo() != StoreInst::getPointerOperandIndex()) {
285292
LLVM_DEBUG(dbgs() << "Object address is stored somewhere, marking escape\n");
286293
REMARK([&]() {
294+
std::string str;
295+
llvm::raw_string_ostream rso(str);
296+
inst->print(rso);
287297
return OptimizationRemarkMissed(DEBUG_TYPE, "StoreObjAddr",
288298
inst)
289-
<< "Object address is stored somewhere, marking escape (" << ore::NV("Store", inst) << ")";
299+
<< "Object address is stored somewhere, marking escape (" << ore::NV("Store", StringRef(str)) << ")";
290300
});
291301
required.use_info.escaped = true;
292302
return false;
@@ -310,9 +320,12 @@ void jl_alloc::runEscapeAnalysis(llvm::CallInst *I, EscapeAnalysisRequiredArgs r
310320
if (use->getOperandNo() != isa<AtomicCmpXchgInst>(inst) ? AtomicCmpXchgInst::getPointerOperandIndex() : AtomicRMWInst::getPointerOperandIndex()) {
311321
LLVM_DEBUG(dbgs() << "Object address is cmpxchg/rmw-ed somewhere, marking escape\n");
312322
REMARK([&]() {
323+
std::string str;
324+
llvm::raw_string_ostream rso(str);
325+
inst->print(rso);
313326
return OptimizationRemarkMissed(DEBUG_TYPE, "StoreObjAddr",
314327
inst)
315-
<< "Object address is cmpxchg/rmw-ed somewhere, marking escape (" << ore::NV("Store", inst) << ")";
328+
<< "Object address is cmpxchg/rmw-ed somewhere, marking escape (" << ore::NV("Store", StringRef(str)) << ")";
316329
});
317330
required.use_info.escaped = true;
318331
return false;
@@ -363,9 +376,12 @@ void jl_alloc::runEscapeAnalysis(llvm::CallInst *I, EscapeAnalysisRequiredArgs r
363376
}
364377
LLVM_DEBUG(dbgs() << "Unknown instruction, marking escape\n");
365378
REMARK([&]() {
379+
std::string str;
380+
llvm::raw_string_ostream rso(str);
381+
inst->print(rso);
366382
return OptimizationRemarkMissed(DEBUG_TYPE, "UnknownInst",
367383
inst)
368-
<< "Unknown instruction, marking escape (" << ore::NV("Inst", inst) << ")";
384+
<< "Unknown instruction, marking escape (" << ore::NV("Inst", StringRef(str)) << ")";
369385
});
370386
required.use_info.escaped = true;
371387
return false;

src/llvm-alloc-opt.cpp

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -224,17 +224,23 @@ void Optimizer::optimizeAll()
224224
checkInst(orig);
225225
if (use_info.escaped) {
226226
REMARK([&]() {
227+
std::string str;
228+
llvm::raw_string_ostream rso(str);
229+
orig->print(rso);
227230
return OptimizationRemarkMissed(DEBUG_TYPE, "Escaped", orig)
228-
<< "GC allocation escaped " << ore::NV("GC Allocation", orig);
231+
<< "GC allocation escaped " << ore::NV("GC Allocation", StringRef(str));
229232
});
230233
if (use_info.hastypeof)
231234
optimizeTag(orig);
232235
continue;
233236
}
234237
if (use_info.haserror || use_info.returned) {
235238
REMARK([&]() {
239+
std::string str;
240+
llvm::raw_string_ostream rso(str);
241+
orig->print(rso);
236242
return OptimizationRemarkMissed(DEBUG_TYPE, "Escaped", orig)
237-
<< "GC allocation has error or was returned " << ore::NV("GC Allocation", orig);
243+
<< "GC allocation has error or was returned " << ore::NV("GC Allocation", StringRef(str));
238244
});
239245
if (use_info.hastypeof)
240246
optimizeTag(orig);
@@ -243,8 +249,11 @@ void Optimizer::optimizeAll()
243249
if (!use_info.addrescaped && !use_info.hasload && (!use_info.haspreserve ||
244250
!use_info.refstore)) {
245251
REMARK([&]() {
252+
std::string str;
253+
llvm::raw_string_ostream rso(str);
254+
orig->print(rso);
246255
return OptimizationRemark(DEBUG_TYPE, "Dead Allocation", orig)
247-
<< "GC allocation removed " << ore::NV("GC Allocation", orig);
256+
<< "GC allocation removed " << ore::NV("GC Allocation", StringRef(str));
248257
});
249258
// No one took the address, no one reads anything and there's no meaningful
250259
// preserve of fields (either no preserve/ccall or no object reference fields)
@@ -270,17 +279,23 @@ void Optimizer::optimizeAll()
270279
}
271280
if (has_refaggr) {
272281
REMARK([&]() {
282+
std::string str;
283+
llvm::raw_string_ostream rso(str);
284+
orig->print(rso);
273285
return OptimizationRemarkMissed(DEBUG_TYPE, "Escaped", orig)
274-
<< "GC allocation has unusual object reference, unable to move to stack " << ore::NV("GC Allocation", orig);
286+
<< "GC allocation has unusual object reference, unable to move to stack " << ore::NV("GC Allocation", StringRef(str));
275287
});
276288
if (use_info.hastypeof)
277289
optimizeTag(orig);
278290
continue;
279291
}
280292
if (!use_info.hasunknownmem && !use_info.addrescaped) {
281293
REMARK([&](){
294+
std::string str;
295+
llvm::raw_string_ostream rso(str);
296+
orig->print(rso);
282297
return OptimizationRemark(DEBUG_TYPE, "Stack Split Allocation", orig)
283-
<< "GC allocation split on stack " << ore::NV("GC Allocation", orig);
298+
<< "GC allocation split on stack " << ore::NV("GC Allocation", StringRef(str));
284299
});
285300
// No one actually care about the memory layout of this object, split it.
286301
splitOnStack(orig);
@@ -292,16 +307,22 @@ void Optimizer::optimizeAll()
292307
// This later causes the GC rooting pass, to miss-characterize the float as a pointer to a GC value
293308
if (has_unboxed && has_ref) {
294309
REMARK([&]() {
310+
std::string str;
311+
llvm::raw_string_ostream rso(str);
312+
orig->print(rso);
295313
return OptimizationRemarkMissed(DEBUG_TYPE, "Escaped", orig)
296-
<< "GC allocation could not be split since it contains both boxed and unboxed values, unable to move to stack " << ore::NV("GC Allocation", orig);
314+
<< "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));
297315
});
298316
if (use_info.hastypeof)
299317
optimizeTag(orig);
300318
continue;
301319
}
302320
REMARK([&](){
321+
std::string str;
322+
llvm::raw_string_ostream rso(str);
323+
orig->print(rso);
303324
return OptimizationRemark(DEBUG_TYPE, "Stack Move Allocation", orig)
304-
<< "GC allocation moved to stack " << ore::NV("GC Allocation", orig);
325+
<< "GC allocation moved to stack " << ore::NV("GC Allocation", StringRef(str));
305326
});
306327
// The object has no fields with mix reference access
307328
moveToStack(orig, sz, has_ref, use_info.allockind);
@@ -380,7 +401,10 @@ void Optimizer::checkInst(CallInst *I)
380401
std::string suse_info;
381402
llvm::raw_string_ostream osuse_info(suse_info);
382403
use_info.dump(osuse_info);
383-
return OptimizationRemarkAnalysis(DEBUG_TYPE, "EscapeAnalysis", I) << "escape analysis for " << ore::NV("GC Allocation", I) << "\n" << ore::NV("UseInfo", osuse_info.str());
404+
std::string str;
405+
llvm::raw_string_ostream rso(str);
406+
I->print(rso);
407+
return OptimizationRemarkAnalysis(DEBUG_TYPE, "EscapeAnalysis", I) << "escape analysis for " << ore::NV("GC Allocation", StringRef(str)) << "\n" << ore::NV("UseInfo", osuse_info.str());
384408
});
385409
}
386410

@@ -905,8 +929,11 @@ void Optimizer::optimizeTag(CallInst *orig_inst)
905929
if (pass.typeof_func == callee) {
906930
++RemovedTypeofs;
907931
REMARK([&](){
932+
std::string str;
933+
llvm::raw_string_ostream rso(str);
934+
orig_inst->print(rso);
908935
return OptimizationRemark(DEBUG_TYPE, "typeof", call)
909-
<< "removed typeof call for GC allocation " << ore::NV("Alloc", orig_inst);
936+
<< "removed typeof call for GC allocation " << ore::NV("Alloc", StringRef(str));
910937
});
911938
call->replaceAllUsesWith(tag);
912939
// Push to the removed instructions to trigger `finalize` to

0 commit comments

Comments
 (0)