[PATCH] D24144: [CFGPrinter] Display branch weight on the edges
Adam Nemet via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 1 17:36:52 PDT 2016
This revision was automatically updated to reflect the committed changes.
Closed by commit rL280442: [CFGPrinter] Display branch weight on the edges (authored by anemet).
Changed prior to commit:
https://reviews.llvm.org/D24144?vs=70110&id=70115#toc
Repository:
rL LLVM
https://reviews.llvm.org/D24144
Files:
llvm/trunk/include/llvm/Analysis/CFGPrinter.h
Index: llvm/trunk/include/llvm/Analysis/CFGPrinter.h
===================================================================
--- llvm/trunk/include/llvm/Analysis/CFGPrinter.h
+++ llvm/trunk/include/llvm/Analysis/CFGPrinter.h
@@ -118,6 +118,36 @@
}
return "";
}
+
+ /// Display the raw branch weights from PGO.
+ std::string getEdgeAttributes(const BasicBlock *Node, succ_const_iterator I,
+ const Function *F) {
+ const TerminatorInst *TI = Node->getTerminator();
+ if (TI->getNumSuccessors() == 1)
+ return "";
+
+ MDNode *WeightsNode = TI->getMetadata(LLVMContext::MD_prof);
+ if (!WeightsNode)
+ return "";
+
+ MDString *MDName = cast<MDString>(WeightsNode->getOperand(0));
+ if (MDName->getString() != "branch_weights")
+ return "";
+
+ unsigned OpNo = I.getSuccessorIndex() + 1;
+ if (OpNo >= WeightsNode->getNumOperands())
+ return "";
+ ConstantInt *Weight =
+ mdconst::dyn_extract<ConstantInt>(WeightsNode->getOperand(OpNo));
+ if (!Weight)
+ return "";
+
+ // Append a 'W' to indicate that these are weights rather than actual
+ // profile
+ // count (due to scaling).
+ Twine Attrs = "label=\"W:" + Twine(Weight->getZExtValue()) + "\"";
+ return Attrs.str();
+ }
};
} // End llvm namespace
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D24144.70115.patch
Type: text/x-patch
Size: 1324 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160902/cd7ff40f/attachment.bin>
More information about the llvm-commits
mailing list