[PATCH] D89441: RFC: Potential fixes to function-instrument=xray-never
Ian Levesque via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 14 19:24:52 PDT 2020
ianlevesque created this revision.
ianlevesque added reviewers: dberris, MaskRay.
Herald added subscribers: llvm-commits, cfe-commits, hiraditya.
Herald added projects: clang, LLVM.
ianlevesque requested review of this revision.
When using https://reviews.llvm.org/D87953 I discovered that the function-instrument="xray-never" attribute doesn't actually do anything. The only reason [[clang::xray_never_instrument]] ever worked was that the code path that parses it coincidentally doesn't set the xray-instruction-threshold attribute on annotated functions. Do you think we should fix this by handling the xray-never attribute in XRayInstrumentation, or having CodeGenFunction remove the threshold if xray-never is set? Or something else? I included both possible fixes in this diff. I can code up either one with tests if we agree on an approach.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D89441
Files:
clang/lib/CodeGen/CodeGenFunction.cpp
llvm/lib/CodeGen/XRayInstrumentation.cpp
Index: llvm/lib/CodeGen/XRayInstrumentation.cpp
===================================================================
--- llvm/lib/CodeGen/XRayInstrumentation.cpp
+++ llvm/lib/CodeGen/XRayInstrumentation.cpp
@@ -145,6 +145,10 @@
bool XRayInstrumentation::runOnMachineFunction(MachineFunction &MF) {
auto &F = MF.getFunction();
auto InstrAttr = F.getFnAttribute("function-instrument");
+ bool NeverInstrument = InstrAttr.isStringAttribute() &&
+ InstrAttr.getValueAsString() == "xray-never";
+ if (NeverInstrument)
+ return false;
bool AlwaysInstrument = InstrAttr.isStringAttribute() &&
InstrAttr.getValueAsString() == "xray-always";
auto ThresholdAttr = F.getFnAttribute("xray-instruction-threshold");
Index: clang/lib/CodeGen/CodeGenFunction.cpp
===================================================================
--- clang/lib/CodeGen/CodeGenFunction.cpp
+++ clang/lib/CodeGen/CodeGenFunction.cpp
@@ -817,8 +817,10 @@
CurFn->getName().bytes_begin(), CurFn->getName().bytes_end());
auto Group = crc32(FuncName) % FuncGroups;
if (Group != CGM.getCodeGenOpts().XRaySelectedFunctionGroup &&
- !AlwaysXRayAttr)
+ !AlwaysXRayAttr) {
+ Fn->removeFnAttr("xray-instruction-threshold");
Fn->addFnAttr("function-instrument", "xray-never");
+ }
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D89441.298279.patch
Type: text/x-patch
Size: 1381 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201015/2c1280ab/attachment.bin>
More information about the llvm-commits
mailing list