[clang] 14f8703 - [xray][clang] Always add xray-skip-entry/exit and xray-ignore-loops attrs

Shoaib Meenai via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 11 14:01:10 PST 2020


Author: Ian Levesque
Date: 2020-02-11T14:00:41-08:00
New Revision: 14f870366a93ba0c6311883d900e24339681ba76

URL: https://github.com/llvm/llvm-project/commit/14f870366a93ba0c6311883d900e24339681ba76
DIFF: https://github.com/llvm/llvm-project/commit/14f870366a93ba0c6311883d900e24339681ba76.diff

LOG: [xray][clang] Always add xray-skip-entry/exit and xray-ignore-loops attrs

The function attributes xray-skip-entry, xray-skip-exit, and
xray-ignore-loops were only being applied if a function had an
xray-instrument attribute, but they should apply if xray is enabled
globally too.

Differential Revision: https://reviews.llvm.org/D73842

Added: 
    clang/test/CodeGen/xray-attributes-skip-entry-exit.cpp
    clang/test/Driver/XRay/xray-ignore-loops-flags.cpp

Modified: 
    clang/include/clang/Driver/XRayArgs.h
    clang/lib/CodeGen/CodeGenFunction.cpp
    clang/lib/Driver/XRayArgs.cpp
    clang/lib/Frontend/CompilerInvocation.cpp
    clang/test/CodeGen/xray-ignore-loops.cpp

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/Driver/XRayArgs.h b/clang/include/clang/Driver/XRayArgs.h
index fa2583f4b966..96098bf629cd 100644
--- a/clang/include/clang/Driver/XRayArgs.h
+++ b/clang/include/clang/Driver/XRayArgs.h
@@ -30,6 +30,7 @@ class XRayArgs {
   bool XRayAlwaysEmitCustomEvents = false;
   bool XRayAlwaysEmitTypedEvents = false;
   bool XRayRT = true;
+  bool XRayIgnoreLoops = false;
 
 public:
   /// Parses the XRay arguments from an argument list.

diff  --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp
index af0adc213580..b7506b53030d 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -814,23 +814,25 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, QualType RetTy,
           if (ShouldXRayInstrumentFunction())
             Fn->addFnAttr("xray-log-args",
                           llvm::utostr(LogArgs->getArgumentCount()));
-        if (!CGM.getCodeGenOpts().XRayInstrumentationBundle.has(
-                XRayInstrKind::FunctionExit)) {
-          Fn->addFnAttr("xray-skip-exit");
-        }
-        if (!CGM.getCodeGenOpts().XRayInstrumentationBundle.has(
-                XRayInstrKind::FunctionEntry)) {
-          Fn->addFnAttr("xray-skip-entry");
-        }
       }
     } else {
       if (ShouldXRayInstrumentFunction() && !CGM.imbueXRayAttrs(Fn, Loc))
         Fn->addFnAttr(
             "xray-instruction-threshold",
             llvm::itostr(CGM.getCodeGenOpts().XRayInstructionThreshold));
-      if (CGM.getCodeGenOpts().XRayIgnoreLoops) {
+    }
+
+    if (ShouldXRayInstrumentFunction()) {
+      if (CGM.getCodeGenOpts().XRayIgnoreLoops)
         Fn->addFnAttr("xray-ignore-loops");
-      }
+
+      if (!CGM.getCodeGenOpts().XRayInstrumentationBundle.has(
+              XRayInstrKind::FunctionExit))
+        Fn->addFnAttr("xray-skip-exit");
+
+      if (!CGM.getCodeGenOpts().XRayInstrumentationBundle.has(
+              XRayInstrKind::FunctionEntry))
+        Fn->addFnAttr("xray-skip-entry");
     }
 
     unsigned Count, Offset;

diff  --git a/clang/lib/Driver/XRayArgs.cpp b/clang/lib/Driver/XRayArgs.cpp
index 66c3959648ac..54c15685d389 100644
--- a/clang/lib/Driver/XRayArgs.cpp
+++ b/clang/lib/Driver/XRayArgs.cpp
@@ -101,6 +101,10 @@ XRayArgs::XRayArgs(const ToolChain &TC, const ArgList &Args) {
                     options::OPT_fnoxray_link_deps, true))
     XRayRT = false;
 
+  if (Args.hasFlag(options::OPT_fxray_ignore_loops,
+                   options::OPT_fno_xray_ignore_loops, false))
+    XRayIgnoreLoops = true;
+
   auto Bundles =
       Args.getAllArgValues(options::OPT_fxray_instrumentation_bundle);
   if (Bundles.empty())
@@ -197,6 +201,9 @@ void XRayArgs::addArgs(const ToolChain &TC, const ArgList &Args,
   if (XRayAlwaysEmitTypedEvents)
     CmdArgs.push_back("-fxray-always-emit-typedevents");
 
+  if (XRayIgnoreLoops)
+    CmdArgs.push_back("-fxray-ignore-loops");
+
   CmdArgs.push_back(Args.MakeArgString(Twine(XRayInstructionThresholdOption) +
                                        Twine(InstructionThreshold)));
 

diff  --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp
index e57c7ef55bb5..ae39066edd4c 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -1099,8 +1099,7 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK,
       Args.hasArg(OPT_fxray_always_emit_typedevents);
   Opts.XRayInstructionThreshold =
       getLastArgIntValue(Args, OPT_fxray_instruction_threshold_EQ, 200, Diags);
-  Opts.XRayIgnoreLoops =
-      Args.hasArg(OPT_fxray_ignore_loops, OPT_fno_xray_ignore_loops, false);
+  Opts.XRayIgnoreLoops = Args.hasArg(OPT_fxray_ignore_loops);
 
   auto XRayInstrBundles =
       Args.getAllArgValues(OPT_fxray_instrumentation_bundle);

diff  --git a/clang/test/CodeGen/xray-attributes-skip-entry-exit.cpp b/clang/test/CodeGen/xray-attributes-skip-entry-exit.cpp
new file mode 100644
index 000000000000..e23262fd5dbc
--- /dev/null
+++ b/clang/test/CodeGen/xray-attributes-skip-entry-exit.cpp
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -fxray-instrument \
+// RUN:     -fxray-instrumentation-bundle=function-entry -x c++ \
+// RUN:     -std=c++11 -triple x86_64-unknown-unknown -emit-llvm -o - %s \
+// RUN:     | FileCheck --check-prefixes CHECK,SKIPEXIT %s
+// RUN: %clang_cc1 -fxray-instrument \
+// RUN:     -fxray-instrumentation-bundle=function-exit -x c++ \
+// RUN:     -std=c++11 -triple x86_64-unknown-unknown -emit-llvm -o - %s \
+// RUN:     | FileCheck --check-prefixes CHECK,SKIPENTRY %s
+// RUN: %clang_cc1 -fxray-instrument \
+// RUN:     -fxray-instrumentation-bundle=function-entry,function-exit -x c++ \
+// RUN:     -std=c++11 -triple x86_64-unknown-unknown -emit-llvm -o - %s \
+// RUN:     | FileCheck --check-prefixes CHECK,NOSKIPENTRY,NOSKIPEXIT %s
+
+// CHECK: define void @_Z13justAFunctionv() #[[ATTR:[0-9]+]] {
+void justAFunction() {
+}
+
+// SKIPENTRY: attributes #[[ATTR]] = {{.*}} "xray-skip-entry" {{.*}}
+// SKIPEXIT: attributes #[[ATTR]] = {{.*}} "xray-skip-exit" {{.*}}
+
+// NOSKIPENTRY-NOT: attributes #[[ATTR]] = {{.*}} "xray-skip-entry" {{.*}}
+// NOSKIPEXIT-NOT: attributes #[[ATTR]] = {{.*}} "xray-skip-exit" {{.*}}

diff  --git a/clang/test/CodeGen/xray-ignore-loops.cpp b/clang/test/CodeGen/xray-ignore-loops.cpp
index 17ea2afbeece..ed918b8f9b31 100644
--- a/clang/test/CodeGen/xray-ignore-loops.cpp
+++ b/clang/test/CodeGen/xray-ignore-loops.cpp
@@ -4,5 +4,5 @@ int foo() {
   return 1;
 }
 
-// CHECK: define i32 @_Z3foov() #[[ATTRS:[0-9]+]] {
+// CHECK: define{{.*}} i32 @_Z3foov() #[[ATTRS:[0-9]+]] {
 // CHECK-DAG: attributes #[[ATTRS]] = {{.*}} "xray-ignore-loops" {{.*}}

diff  --git a/clang/test/Driver/XRay/xray-ignore-loops-flags.cpp b/clang/test/Driver/XRay/xray-ignore-loops-flags.cpp
new file mode 100644
index 000000000000..476786fc639a
--- /dev/null
+++ b/clang/test/Driver/XRay/xray-ignore-loops-flags.cpp
@@ -0,0 +1,10 @@
+// This test ensures that when we invoke the clang compiler, that the -cc1
+// options include the -fxray-ignore-loops flag we provide in the
+// invocation.
+//
+// RUN: %clang -fxray-instrument -fxray-ignore-loops -target x86_64-linux- -### \
+// RUN:     -x c++ -std=c++11 -emit-llvm -c -o - %s 2>&1 \
+// RUN:     | FileCheck %s
+// CHECK:  -fxray-ignore-loops
+//
+// REQUIRES: x86_64 || x86_64h


        


More information about the cfe-commits mailing list