[Assignment Tracking][2/*] Add flags to enable Assignment Tracking
authorOCHyams <orlando.hyams@sony.com>
Wed, 2 Nov 2022 17:00:58 +0000 (17:00 +0000)
committerOCHyams <orlando.hyams@sony.com>
Wed, 2 Nov 2022 17:06:43 +0000 (17:06 +0000)
The Assignment Tracking debug-info feature is outlined in this RFC:

https://discourse.llvm.org/t/
rfc-assignment-tracking-a-better-way-of-specifying-variable-locations-in-ir

Enable in clang: -Xclang -fexperimental-assignment-tracking
Enable in llvm tools: -experimental-assignment-tracking

When assignment tracking is enabled in clang it will pass on the flag to enable
the feature in lllvm. It's undefined behaviour to read IR that contains
assignment tracking metadata without specifying the feature flags.

Tests will come with later patches that add assignment tracking features.

Reviewed By: jmorse

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

clang/include/clang/Basic/CodeGenOptions.def
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Clang.cpp
llvm/include/llvm/IR/DebugInfo.h
llvm/lib/IR/DebugInfo.cpp

index 258ba12..183cb0c 100644 (file)
@@ -331,6 +331,10 @@ VALUE_CODEGENOPT(StackProbeSize    , 32, 4096) ///< Overrides default stack
 VALUE_CODEGENOPT(WarnStackSize     , 32, UINT_MAX) ///< Set via -fwarn-stack-size.
 CODEGENOPT(NoStackArgProbe, 1, 0) ///< Set when -mno-stack-arg-probe is used
 CODEGENOPT(DebugStrictDwarf, 1, 1) ///< Whether or not to use strict DWARF info.
+
+CODEGENOPT(EnableAssignmentTracking, 1,0) ///< Enable the Assignment Tracking
+                                          ///< debug info feature feature.
+
 CODEGENOPT(DebugColumnInfo, 1, 0) ///< Whether or not to use column information
                                   ///< in debug info.
 
index d660a2b..b2f334f 100644 (file)
@@ -5638,6 +5638,11 @@ def fctor_dtor_return_this : Flag<["-"], "fctor-dtor-return-this">,
 
 } // let Flags = [CC1Option, NoDriverOption]
 
+def fexperimental_assignment_tracking :
+  Flag<["-"], "fexperimental-assignment-tracking">, Group<f_Group>,
+  HelpText<"Enable assignment tracking debug info">,
+  MarshallingInfoFlag<CodeGenOpts<"EnableAssignmentTracking">>;
+
 //===----------------------------------------------------------------------===//
 // Dependency Output Options
 //===----------------------------------------------------------------------===//
index 160eb1f..f873251 100644 (file)
@@ -6987,18 +6987,21 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
 
   // Forward -Xclang arguments to -cc1, and -mllvm arguments to the LLVM option
   // parser.
-  // -finclude-default-header flag is for preprocessor,
-  // do not pass it to other cc1 commands when save-temps is enabled
-  if (C.getDriver().isSaveTempsEnabled() &&
-      !isa<PreprocessJobAction>(JA)) {
-    for (auto *Arg : Args.filtered(options::OPT_Xclang)) {
-      Arg->claim();
-      if (StringRef(Arg->getValue()) != "-finclude-default-header")
-        CmdArgs.push_back(Arg->getValue());
+  for (auto Arg : Args.filtered(options::OPT_Xclang)) {
+    Arg->claim();
+    // -finclude-default-header flag is for preprocessor,
+    // do not pass it to other cc1 commands when save-temps is enabled
+    if (C.getDriver().isSaveTempsEnabled() &&
+        !isa<PreprocessJobAction>(JA)) {
+      if (StringRef(Arg->getValue()) == "-finclude-default-header")
+        continue;
     }
-  }
-  else {
-    Args.AddAllArgValues(CmdArgs, options::OPT_Xclang);
+    if (StringRef(Arg->getValue()) == "-fexperimental-assignment-tracking") {
+      // Add the llvm version of this flag too.
+      CmdArgs.push_back("-mllvm");
+      CmdArgs.push_back("-experimental-assignment-tracking");
+    }
+    CmdArgs.push_back(Arg->getValue());
   }
   for (const Arg *A : Args.filtered(options::OPT_mllvm)) {
     A->claim();
index 730c69d..b35d447 100644 (file)
@@ -159,6 +159,8 @@ private:
   SmallPtrSet<const MDNode *, 32> NodesSeen;
 };
 
+/// Return true if assignment tracking is enabled.
+bool getEnableAssignmentTracking();
 } // end namespace llvm
 
 #endif // LLVM_IR_DEBUGINFO_H
index be09d14..8f6d58c 100644 (file)
 using namespace llvm;
 using namespace llvm::dwarf;
 
+static cl::opt<bool>
+    ExperimentalAssignmentTracking("experimental-assignment-tracking",
+                                   cl::init(false));
+bool llvm::getEnableAssignmentTracking() {
+  return ExperimentalAssignmentTracking;
+}
+
 /// Finds all intrinsics declaring local variables as living in the memory that
 /// 'V' points to. This may include a mix of dbg.declare and
 /// dbg.addr intrinsics.