[llvm] [llvm-objdump] Add the --visualize-jumps option (PR #74858)
James Henderson via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 14 01:01:43 PST 2023
================
@@ -503,5 +506,188 @@ SourcePrinter::SourcePrinter(const object::ObjectFile *Obj,
Symbolizer.reset(new symbolize::LLVMSymbolizer(SymbolizerOpts));
}
+// TODO Light/dark shades? 256-color terminals?
+const raw_ostream::Colors LineColors[] = {
+ raw_ostream::RED, raw_ostream::GREEN, raw_ostream::YELLOW,
+ raw_ostream::BLUE, raw_ostream::MAGENTA, raw_ostream::CYAN,
+};
+
+raw_ostream::Colors ControlFlowPrinter::PickColor() {
+ if (!OutputMode.color_enabled())
+ return raw_ostream::RESET;
+ auto Ret = LineColors[NextColorIdx];
+ NextColorIdx =
+ (NextColorIdx + 1) % (sizeof(LineColors) / sizeof(LineColors[0]));
+ return Ret;
+}
+
+void ControlFlowPrinter::addEdge(uint64_t From, uint64_t To) {
+ auto It = Targets.find(To);
+ if (It == Targets.end())
+ It = Targets.insert(std::make_pair(To, ControlFlowTarget(To, PickColor())))
+ .first;
+ It->second.addSource(From);
+}
+
+void ControlFlowPrinter::finalise() {
+ if (!OutputMode.enabled()) {
+ setControlFlowColumnWidth(0);
+ return;
+ }
+
+ SmallVector<ControlFlowTarget *> SortedTargets;
+ for (auto &[Addr, Info] : Targets) {
+ SortedTargets.push_back(&Info);
+ }
+ std::sort(SortedTargets.begin(), SortedTargets.end(),
+ [](ControlFlowTarget *LHS, ControlFlowTarget *RHS) {
+ return LHS->Length() < RHS->Length();
+ });
+
+ // FIXME This is O(n^3) in the worst case, can we do better?
----------------
jh7370 wrote:
I'm concerned about introducing this kind of FIXME. If this PR is intended to be landed, then we should really have it addressed prior to landing, unless the behaviour is acceptable. If it is acceptable, but should be improved, filing a GitHub issue and including the link to that issue might be preferable.
https://github.com/llvm/llvm-project/pull/74858
More information about the llvm-commits
mailing list