Skip to content

Commit c10a847

Browse files
committed
[Assignment Tracking][2/*] Add flags to enable Assignment Tracking
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
1 parent 1ca1197 commit c10a847

File tree

5 files changed

+32
-11
lines changed

5 files changed

+32
-11
lines changed

clang/include/clang/Basic/CodeGenOptions.def

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,10 @@ VALUE_CODEGENOPT(StackProbeSize , 32, 4096) ///< Overrides default stack
331331
VALUE_CODEGENOPT(WarnStackSize , 32, UINT_MAX) ///< Set via -fwarn-stack-size.
332332
CODEGENOPT(NoStackArgProbe, 1, 0) ///< Set when -mno-stack-arg-probe is used
333333
CODEGENOPT(DebugStrictDwarf, 1, 1) ///< Whether or not to use strict DWARF info.
334+
335+
CODEGENOPT(EnableAssignmentTracking, 1,0) ///< Enable the Assignment Tracking
336+
///< debug info feature feature.
337+
334338
CODEGENOPT(DebugColumnInfo, 1, 0) ///< Whether or not to use column information
335339
///< in debug info.
336340

clang/include/clang/Driver/Options.td

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5638,6 +5638,11 @@ def fctor_dtor_return_this : Flag<["-"], "fctor-dtor-return-this">,
56385638

56395639
} // let Flags = [CC1Option, NoDriverOption]
56405640

5641+
def fexperimental_assignment_tracking :
5642+
Flag<["-"], "fexperimental-assignment-tracking">, Group<f_Group>,
5643+
HelpText<"Enable assignment tracking debug info">,
5644+
MarshallingInfoFlag<CodeGenOpts<"EnableAssignmentTracking">>;
5645+
56415646
//===----------------------------------------------------------------------===//
56425647
// Dependency Output Options
56435648
//===----------------------------------------------------------------------===//

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6987,18 +6987,21 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
69876987

69886988
// Forward -Xclang arguments to -cc1, and -mllvm arguments to the LLVM option
69896989
// parser.
6990-
// -finclude-default-header flag is for preprocessor,
6991-
// do not pass it to other cc1 commands when save-temps is enabled
6992-
if (C.getDriver().isSaveTempsEnabled() &&
6993-
!isa<PreprocessJobAction>(JA)) {
6994-
for (auto *Arg : Args.filtered(options::OPT_Xclang)) {
6995-
Arg->claim();
6996-
if (StringRef(Arg->getValue()) != "-finclude-default-header")
6997-
CmdArgs.push_back(Arg->getValue());
6990+
for (auto Arg : Args.filtered(options::OPT_Xclang)) {
6991+
Arg->claim();
6992+
// -finclude-default-header flag is for preprocessor,
6993+
// do not pass it to other cc1 commands when save-temps is enabled
6994+
if (C.getDriver().isSaveTempsEnabled() &&
6995+
!isa<PreprocessJobAction>(JA)) {
6996+
if (StringRef(Arg->getValue()) == "-finclude-default-header")
6997+
continue;
69986998
}
6999-
}
7000-
else {
7001-
Args.AddAllArgValues(CmdArgs, options::OPT_Xclang);
6999+
if (StringRef(Arg->getValue()) == "-fexperimental-assignment-tracking") {
7000+
// Add the llvm version of this flag too.
7001+
CmdArgs.push_back("-mllvm");
7002+
CmdArgs.push_back("-experimental-assignment-tracking");
7003+
}
7004+
CmdArgs.push_back(Arg->getValue());
70027005
}
70037006
for (const Arg *A : Args.filtered(options::OPT_mllvm)) {
70047007
A->claim();

llvm/include/llvm/IR/DebugInfo.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ class DebugInfoFinder {
159159
SmallPtrSet<const MDNode *, 32> NodesSeen;
160160
};
161161

162+
/// Return true if assignment tracking is enabled.
163+
bool getEnableAssignmentTracking();
162164
} // end namespace llvm
163165

164166
#endif // LLVM_IR_DEBUGINFO_H

llvm/lib/IR/DebugInfo.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,13 @@
3939
using namespace llvm;
4040
using namespace llvm::dwarf;
4141

42+
static cl::opt<bool>
43+
ExperimentalAssignmentTracking("experimental-assignment-tracking",
44+
cl::init(false));
45+
bool llvm::getEnableAssignmentTracking() {
46+
return ExperimentalAssignmentTracking;
47+
}
48+
4249
/// Finds all intrinsics declaring local variables as living in the memory that
4350
/// 'V' points to. This may include a mix of dbg.declare and
4451
/// dbg.addr intrinsics.

0 commit comments

Comments
 (0)