[PATCH] D40478: Added Instrument Control Flow Flag

Oren Ben Simhon via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 13 05:49:16 PST 2017


oren_ben_simhon updated this revision to Diff 126745.
oren_ben_simhon added a comment.

Implemented some of the comments posted until 12/12 (Thanks Peter)


Repository:
  rL LLVM

https://reviews.llvm.org/D40478

Files:
  include/clang/Driver/Options.td
  include/clang/Frontend/CodeGenOptions.def
  lib/CodeGen/CGCall.cpp
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/CodeGen/instrument-control-flow.c
  test/Driver/clang_f_opts.c


Index: test/Driver/clang_f_opts.c
===================================================================
--- test/Driver/clang_f_opts.c
+++ test/Driver/clang_f_opts.c
@@ -502,4 +502,7 @@
 // RUN: %clang -### -target x86_64-unknown-windows-msvc -fno-short-wchar %s 2>&1 | FileCheck -check-prefix CHECK-WINDOWS-ISO10646 %s
 // CHECK-WINDOWS-ISO10646: "-fwchar-type=int"
 // CHECK-WINDOWS-ISO10646: "-fsigned-wchar"
-
+// RUN: %clang -### -S -finstrument-control-flow %s 2>&1 | FileCheck -check-prefix=CHECK-INSTRUMENT-CONTROL-FLOW %s
+// RUN: %clang -### -S %s 2>&1 | FileCheck -check-prefix=CHECK-NO-INSTRUMENT-CONTROL-FLOW %s
+// CHECK-INSTRUMENT-CONTROL-FLOW: -finstrument-control-flow
+// CHECK-NO-INSTRUMENT-CONTROL-FLOW-NOT: -finstrument-control-flow
Index: test/CodeGen/instrument-control-flow.c
===================================================================
--- /dev/null
+++ test/CodeGen/instrument-control-flow.c
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -S -emit-llvm -finstrument-control-flow -o - %s  | FileCheck %s
+
+// CHECK: define void @foo() [[NUW:#[0-9]+]]
+void foo(void) {
+}
+
+// CHECK: attributes [[NUW]] = { {{.*}} "instrument-control-flow"="true" {{.*}} }
Index: lib/Frontend/CompilerInvocation.cpp
===================================================================
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -784,6 +784,7 @@
       Args.hasArg(OPT_finstrument_functions_after_inlining);
   Opts.InstrumentFunctionEntryBare =
       Args.hasArg(OPT_finstrument_function_entry_bare);
+  Opts.InstrumentControlFlow = Args.hasArg(OPT_finstrument_control_flow);
   Opts.XRayInstrumentFunctions = Args.hasArg(OPT_fxray_instrument);
   Opts.XRayInstructionThreshold =
       getLastArgIntValue(Args, OPT_fxray_instruction_threshold_EQ, 200, Diags);
Index: lib/Driver/ToolChains/Clang.cpp
===================================================================
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -3977,6 +3977,10 @@
   // Forward -cl options to -cc1
   RenderOpenCLOptions(Args, CmdArgs);
 
+  if (Args.getLastArg(options::OPT_finstrument_control_flow)) {
+    CmdArgs.push_back("-finstrument-control-flow");
+  }
+
   // Forward -f options with positive and negative forms; we translate
   // these by hand.
   if (Arg *A = getLastProfileSampleUseArg(Args)) {
Index: lib/CodeGen/CGCall.cpp
===================================================================
--- lib/CodeGen/CGCall.cpp
+++ lib/CodeGen/CGCall.cpp
@@ -1735,6 +1735,9 @@
     FuncAttrs.addAttribute("no-signed-zeros-fp-math",
                            llvm::toStringRef(CodeGenOpts.NoSignedZeros));
     FuncAttrs.addAttribute(
+        "instrument-control-flow",
+        llvm::toStringRef(CodeGenOpts.InstrumentControlFlow));
+    FuncAttrs.addAttribute(
         "correctly-rounded-divide-sqrt-fp-math",
         llvm::toStringRef(CodeGenOpts.CorrectlyRoundedDivSqrt));
 
Index: include/clang/Frontend/CodeGenOptions.def
===================================================================
--- include/clang/Frontend/CodeGenOptions.def
+++ include/clang/Frontend/CodeGenOptions.def
@@ -80,7 +80,8 @@
                           ///< -finstrument-functions-after-inlining is enabled.
 CODEGENOPT(InstrumentFunctionEntryBare , 1, 0) ///< Set when
                                ///< -finstrument-function-entry-bare is enabled.
-
+CODEGENOPT(InstrumentControlFlow , 1, 0) ///< if -finstrument-control-flow is
+                                         ///< enabled, set the option.
 CODEGENOPT(XRayInstrumentFunctions , 1, 0) ///< Set when -fxray-instrument is
                                            ///< enabled.
 
Index: include/clang/Driver/Options.td
===================================================================
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -1032,7 +1032,9 @@
   HelpText<"Like -finstrument-functions, but insert the calls after inlining">;
 def finstrument_function_entry_bare : Flag<["-"], "finstrument-function-entry-bare">, Group<f_Group>, Flags<[CC1Option]>,
   HelpText<"Instrument function entry only, after inlining, without arguments to the instrumentation call">;
-
+def finstrument_control_flow : Flag<["-"], "finstrument-control-flow">,
+  Group<f_Group>, Flags<[CC1Option]>,
+  HelpText<"Instrument control flow instructions for indirect branch tracking">;
 def fxray_instrument : Flag<["-"], "fxray-instrument">, Group<f_Group>,
   Flags<[CC1Option]>,
   HelpText<"Generate XRay instrumentation sleds on function entry and exit">;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D40478.126745.patch
Type: text/x-patch
Size: 4563 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171213/ddd5d1f8/attachment.bin>


More information about the llvm-commits mailing list