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");
+      }
     }
   }
 


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");
+      }
     }
   }
 
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
  • [PATCH] D89441: RFC: P... Ian Levesque via Phabricator via cfe-commits

Reply via email to