Skip to content

[clang][modules] Reset codegen options. #74006

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 3 additions & 85 deletions clang/include/clang/Basic/CodeGenOptions.def
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,8 @@ CODEGENOPT(Name, Bits, Default)
#endif

CODEGENOPT(DisableIntegratedAS, 1, 0) ///< -no-integrated-as
ENUM_CODEGENOPT(CompressDebugSections, llvm::DebugCompressionType, 2,
llvm::DebugCompressionType::None)
CODEGENOPT(RelaxELFRelocations, 1, 1) ///< -Wa,-mrelax-relocations={yes,no}
CODEGENOPT(AsmVerbose , 1, 0) ///< -dA, -fverbose-asm.
CODEGENOPT(Dwarf64 , 1, 0) ///< -gdwarf64.
CODEGENOPT(Dwarf32 , 1, 1) ///< -gdwarf32.
CODEGENOPT(PreserveAsmComments, 1, 1) ///< -dA, -fno-preserve-as-comments.
CODEGENOPT(AssumeSaneOperatorNew , 1, 1) ///< implicit __attribute__((malloc)) operator new
CODEGENOPT(AssumeUniqueVTables , 1, 1) ///< Assume a class has only one vtable.
Expand Down Expand Up @@ -73,10 +69,6 @@ CODEGENOPT(DebugPassManager, 1, 0) ///< Prints debug information for the new
CODEGENOPT(DisableRedZone , 1, 0) ///< Set when -mno-red-zone is enabled.
CODEGENOPT(EmitCallSiteInfo, 1, 0) ///< Emit call site info only in the case of
///< '-g' + 'O>0' level.
CODEGENOPT(EnableDIPreservationVerify, 1, 0) ///< Enable di preservation verify
///< each (it means check
///< the original debug info
///< metadata preservation).
CODEGENOPT(IndirectTlsSegRefs, 1, 0) ///< Set when -mno-tls-direct-seg-refs
///< is specified.
CODEGENOPT(DisableTailCalls , 1, 0) ///< Do not emit tail calls.
Expand Down Expand Up @@ -113,16 +105,10 @@ CODEGENOPT(IndirectBranchCSPrefix, 1, 0) ///< if -mindirect-branch-cs-prefix
CODEGENOPT(XRayInstrumentFunctions , 1, 0) ///< Set when -fxray-instrument is
///< enabled.
CODEGENOPT(StackSizeSection , 1, 0) ///< Set when -fstack-size-section is enabled.
CODEGENOPT(ForceDwarfFrameSection , 1, 0) ///< Set when -fforce-dwarf-frame is
///< enabled.

///< Set when -femit-compact-unwind-non-canonical is enabled.
CODEGENOPT(EmitCompactUnwindNonCanonical, 1, 0)

///< Set when -femit-dwarf-unwind is passed.
ENUM_CODEGENOPT(EmitDwarfUnwind, llvm::EmitDwarfUnwindType, 2,
llvm::EmitDwarfUnwindType::Default)

///< Set when -fxray-always-emit-customevents is enabled.
CODEGENOPT(XRayAlwaysEmitCustomEvents , 1, 0)

Expand Down Expand Up @@ -178,17 +164,13 @@ CODEGENOPT(IncrementalLinkerCompatible, 1, 0) ///< Emit an object file which can
CODEGENOPT(MergeAllConstants , 1, 1) ///< Merge identical constants.
CODEGENOPT(MergeFunctions , 1, 0) ///< Set when -fmerge-functions is enabled.
CODEGENOPT(NoCommon , 1, 0) ///< Set when -fno-common or C++ is enabled.
CODEGENOPT(NoDwarfDirectoryAsm , 1, 0) ///< Set when -fno-dwarf-directory-asm is
///< enabled.
CODEGENOPT(NoExecStack , 1, 0) ///< Set when -Wa,--noexecstack is enabled.
CODEGENOPT(FatalWarnings , 1, 0) ///< Set when -Wa,--fatal-warnings is
///< enabled.
CODEGENOPT(NoWarn , 1, 0) ///< Set when -Wa,--no-warn is enabled.
CODEGENOPT(NoTypeCheck , 1, 0) ///< Set when -Wa,--no-type-check is enabled.
CODEGENOPT(MisExpect , 1, 0) ///< Set when -Wmisexpect is enabled
CODEGENOPT(EnableSegmentedStacks , 1, 0) ///< Set when -fsplit-stack is enabled.
CODEGENOPT(NoInlineLineTables, 1, 0) ///< Whether debug info should contain
///< inline line tables.
CODEGENOPT(StackClashProtector, 1, 0) ///< Set when -fstack-clash-protection is enabled.
CODEGENOPT(NoImplicitFloat , 1, 0) ///< Set when -mno-implicit-float is enabled.
CODEGENOPT(NullPointerIsValid , 1, 0) ///< Assume Null pointer deference is defined.
Expand Down Expand Up @@ -341,37 +323,6 @@ VALUE_CODEGENOPT(StackProbeSize , 32, 4096) ///< Overrides default stack
///< probe size, even if 0.
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.

/// Control the Assignment Tracking debug info feature.
ENUM_CODEGENOPT(AssignmentTrackingMode, AssignmentTrackingOpts, 2, AssignmentTrackingOpts::Disabled)

CODEGENOPT(DebugColumnInfo, 1, 0) ///< Whether or not to use column information
///< in debug info.

CODEGENOPT(DebugTypeExtRefs, 1, 0) ///< Whether or not debug info should contain
///< external references to a PCH or module.

CODEGENOPT(DebugExplicitImport, 1, 0) ///< Whether or not debug info should
///< contain explicit imports for
///< anonymous namespaces

/// Set debug info source file hashing algorithm.
ENUM_CODEGENOPT(DebugSrcHash, DebugSrcHashKind, 2, DSH_MD5)

CODEGENOPT(SplitDwarfInlining, 1, 1) ///< Whether to include inlining info in the
///< skeleton CU to allow for symbolication
///< of inline stack frames without .dwo files.
CODEGENOPT(DebugFwdTemplateParams, 1, 0) ///< Whether to emit complete
///< template parameter descriptions in
///< forward declarations (versus just
///< including them in the name).
ENUM_CODEGENOPT(DebugSimpleTemplateNames, llvm::codegenoptions::DebugTemplateNamesKind, 2, llvm::codegenoptions::DebugTemplateNamesKind::Full) ///< Whether to emit template parameters
///< in the textual names of template
///< specializations.
///< Implies DebugFwdTemplateNames to
///< allow decorated names to be
///< reconstructed when needed.
CODEGENOPT(EmitLLVMUseLists, 1, 0) ///< Control whether to serialize use-lists.

CODEGENOPT(WholeProgramVTables, 1, 0) ///< Whether to apply whole-program
Expand All @@ -395,30 +346,6 @@ VALUE_CODEGENOPT(SmallDataLimit, 32, 0)
/// The lower bound for a buffer to be considered for stack protection.
VALUE_CODEGENOPT(SSPBufferSize, 32, 0)

/// The kind of generated debug info.
ENUM_CODEGENOPT(DebugInfo, llvm::codegenoptions::DebugInfoKind, 4, llvm::codegenoptions::NoDebugInfo)

/// Whether to generate macro debug info.
CODEGENOPT(MacroDebugInfo, 1, 0)

/// Tune the debug info for this debugger.
ENUM_CODEGENOPT(DebuggerTuning, llvm::DebuggerKind, 3,
llvm::DebuggerKind::Default)

/// Dwarf version. Version zero indicates to LLVM that no DWARF should be
/// emitted.
VALUE_CODEGENOPT(DwarfVersion, 3, 0)

/// Whether we should emit CodeView debug information. It's possible to emit
/// CodeView and DWARF into the same object.
CODEGENOPT(EmitCodeView, 1, 0)

/// Whether to emit the .debug$H section containing hashes of CodeView types.
CODEGENOPT(CodeViewGHash, 1, 0)

/// Whether to emit the compiler path and command line into the CodeView debug information.
CODEGENOPT(CodeViewCommandLine, 1, 0)

/// The kind of inlining to perform.
ENUM_CODEGENOPT(Inlining, InliningMethod, 2, NormalInlining)

Expand Down Expand Up @@ -451,26 +378,14 @@ CODEGENOPT(DirectAccessExternalData, 1, 0)
/// paths that reach the end of a function without executing a required return.
CODEGENOPT(StrictReturn, 1, 1)

/// Whether emit extra debug info for sample pgo profile collection.
CODEGENOPT(DebugInfoForProfiling, 1, 0)

/// Whether emit pseudo probes for sample pgo profile collection.
CODEGENOPT(PseudoProbeForProfiling, 1, 0)

/// Whether 3-component vector type is preserved.
CODEGENOPT(PreserveVec3Type, 1, 0)

/// Whether to emit .debug_gnu_pubnames section instead of .debug_pubnames.
CODEGENOPT(DebugNameTable, 2, 0)

/// Whether to use DWARF base address specifiers in .debug_ranges.
CODEGENOPT(DebugRangesBaseAddress, 1, 0)

CODEGENOPT(NoPLT, 1, 0)

/// Whether to embed source in DWARF debug line section.
CODEGENOPT(EmbedSource, 1, 0)

/// Whether to emit all vtables
CODEGENOPT(ForceEmitVTables, 1, 0)

Expand Down Expand Up @@ -515,6 +430,9 @@ ENUM_CODEGENOPT(ZeroCallUsedRegs, llvm::ZeroCallUsedRegs::ZeroCallUsedRegsKind,
/// non-deleting destructors. (No effect on Microsoft ABI.)
CODEGENOPT(CtorDtorReturnThis, 1, 0)

/// FIXME: Make DebugOptions its own top-level .def file.
#include "DebugOptions.def"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think it would make sense to eventually treat these as separate top-level .def files?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was my initial idea, but it ballooned into a lot of code changes. Turns out the debug options are used in a lot of places. It could be done, but it would be a lot of churn.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. In that case I suggest leaving a FIXME behind.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the FIXME.


#undef CODEGENOPT
#undef ENUM_CODEGENOPT
#undef VALUE_CODEGENOPT
4 changes: 4 additions & 0 deletions clang/include/clang/Basic/CodeGenOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,10 @@ class CodeGenOptions : public CodeGenOptionsBase {
return SanitizeBinaryMetadataCovered || SanitizeBinaryMetadataAtomics ||
SanitizeBinaryMetadataUAR;
}

/// Reset all of the options that are not considered when building a
/// module.
void resetNonModularOptions(StringRef ModuleFormat);
};

} // end namespace clang
Expand Down
146 changes: 146 additions & 0 deletions clang/include/clang/Basic/DebugOptions.def
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
//===--- DebugOptions.def - Debug option database ----------------- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file defines debug-specific codegen options. Users of this file
// must define the CODEGENOPT macro to make use of this information.
// Optionally, the user may also define DEBUGOPT (for flags), ENUM_DEBUGOPT (for
// options that have enumeration type), and VALUE_DEBUGOPT (is a debug option
// that describes a value rather than a flag).
//
// BENIGN_ variants of the macros are used to describe options that do not
// affect the generated PCM.
//
//===----------------------------------------------------------------------===//
#ifndef DEBUGOPT
#define DEBUGOPT(Name, Bits, Default) \
CODEGENOPT(Name, Bits, Default)
#endif

#ifndef VALUE_DEBUGOPT
# define VALUE_DEBUGOPT(Name, Bits, Default) \
VALUE_CODEGENOPT(Name, Bits, Default)
#endif

#ifndef ENUM_DEBUGOPT
# define ENUM_DEBUGOPT(Name, Type, Bits, Default) \
ENUM_CODEGENOPT(Name, Type, Bits, Default)
#endif

#ifndef BENIGN_DEBUGOPT
#define BENIGN_DEBUGOPT(Name, Bits, Default) \
DEBUGOPT(Name, Bits, Default)
#endif

#ifndef BENIGN_VALUE_DEBUGOPT
# define BENIGN_VALUE_DEBUGOPT(Name, Bits, Default) \
VALUE_DEBUGOPT(Name, Bits, Default)
#endif

#ifndef BENIGN_ENUM_DEBUGOPT
# define BENIGN_ENUM_DEBUGOPT(Name, Type, Bits, Default) \
ENUM_DEBUGOPT(Name, Type, Bits, Default)
#endif

BENIGN_ENUM_DEBUGOPT(CompressDebugSections, llvm::DebugCompressionType, 2,
llvm::DebugCompressionType::None)
DEBUGOPT(Dwarf64, 1, 0) ///< -gdwarf64.
BENIGN_DEBUGOPT(EnableDIPreservationVerify, 1, 0) ///< Enable di preservation
///< verify each (it means
///< check the original debug
///< info metadata
///< preservation).
BENIGN_DEBUGOPT(ForceDwarfFrameSection , 1, 0) ///< Set when -fforce-dwarf-frame
///< is enabled.

///< Set when -femit-dwarf-unwind is passed.
BENIGN_ENUM_DEBUGOPT(EmitDwarfUnwind, llvm::EmitDwarfUnwindType, 2,
llvm::EmitDwarfUnwindType::Default)

BENIGN_DEBUGOPT(NoDwarfDirectoryAsm , 1, 0) ///< Set when -fno-dwarf-directory-asm
///< is enabled.

BENIGN_DEBUGOPT(NoInlineLineTables, 1, 0) ///< Whether debug info should contain
///< inline line tables.

DEBUGOPT(DebugStrictDwarf, 1, 1) ///< Whether or not to use strict DWARF info.

/// Control the Assignment Tracking debug info feature.
BENIGN_ENUM_DEBUGOPT(AssignmentTrackingMode, AssignmentTrackingOpts, 2,
AssignmentTrackingOpts::Disabled)

DEBUGOPT(DebugColumnInfo, 1, 0) ///< Whether or not to use column information
///< in debug info.

DEBUGOPT(DebugTypeExtRefs, 1, 0) ///< Whether or not debug info should contain
///< external references to a PCH or module.

DEBUGOPT(DebugExplicitImport, 1, 0) ///< Whether or not debug info should
///< contain explicit imports for
///< anonymous namespaces

/// Set debug info source file hashing algorithm.
ENUM_DEBUGOPT(DebugSrcHash, DebugSrcHashKind, 2, DSH_MD5)

DEBUGOPT(SplitDwarfInlining, 1, 1) ///< Whether to include inlining info in the
///< skeleton CU to allow for symbolication
///< of inline stack frames without .dwo files.
DEBUGOPT(DebugFwdTemplateParams, 1, 0) ///< Whether to emit complete
///< template parameter descriptions in
///< forward declarations (versus just
///< including them in the name).
ENUM_DEBUGOPT(DebugSimpleTemplateNames,
llvm::codegenoptions::DebugTemplateNamesKind, 2,
llvm::codegenoptions::DebugTemplateNamesKind::Full)
///< Whether to emit template parameters in the textual names of
///< template specializations.
///< Implies DebugFwdTemplateNames to allow decorated names to be
///< reconstructed when needed.

/// The kind of generated debug info.
ENUM_DEBUGOPT(DebugInfo, llvm::codegenoptions::DebugInfoKind, 4,
llvm::codegenoptions::NoDebugInfo)

/// Whether to generate macro debug info.
DEBUGOPT(MacroDebugInfo, 1, 0)

/// Tune the debug info for this debugger.
ENUM_DEBUGOPT(DebuggerTuning, llvm::DebuggerKind, 3,
llvm::DebuggerKind::Default)

/// Dwarf version. Version zero indicates to LLVM that no DWARF should be
/// emitted.
VALUE_DEBUGOPT(DwarfVersion, 3, 0)

/// Whether we should emit CodeView debug information. It's possible to emit
/// CodeView and DWARF into the same object.
DEBUGOPT(EmitCodeView, 1, 0)

/// Whether to emit the .debug$H section containing hashes of CodeView types.
DEBUGOPT(CodeViewGHash, 1, 0)

/// Whether to emit the compiler path and command line into the CodeView debug information.
DEBUGOPT(CodeViewCommandLine, 1, 0)

/// Whether emit extra debug info for sample pgo profile collection.
DEBUGOPT(DebugInfoForProfiling, 1, 0)

/// Whether to emit .debug_gnu_pubnames section instead of .debug_pubnames.
DEBUGOPT(DebugNameTable, 2, 0)

/// Whether to use DWARF base address specifiers in .debug_ranges.
DEBUGOPT(DebugRangesBaseAddress, 1, 0)

/// Whether to embed source in DWARF debug line section.
DEBUGOPT(EmbedSource, 1, 0)

#undef DEBUGOPT
#undef ENUM_DEBUGOPT
#undef VALUE_DEBUGOPT
#undef BENIGN_DEBUGOPT
#undef BENIGN_ENUM_DEBUGOPT
#undef BENIGN_VALUE_DEBUGOPT
1 change: 1 addition & 0 deletions clang/include/module.modulemap
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ module Clang_Basic {
textual header "clang/Basic/BuiltinsX86_64.def"
textual header "clang/Basic/BuiltinsXCore.def"
textual header "clang/Basic/CodeGenOptions.def"
textual header "clang/Basic/DebugOptions.def"
textual header "clang/Basic/DiagnosticOptions.def"
textual header "clang/Basic/Features.def"
textual header "clang/Basic/FPOptions.def"
Expand Down
35 changes: 35 additions & 0 deletions clang/lib/Basic/CodeGenOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,39 @@ CodeGenOptions::CodeGenOptions() {
memcpy(CoverageVersion, "408*", 4);
}

void CodeGenOptions::resetNonModularOptions(StringRef ModuleFormat) {
// First reset all CodeGen options only. The Debug options are handled later.
#define DEBUGOPT(Name, Bits, Default)
#define VALUE_DEBUGOPT(Name, Bits, Default)
#define ENUM_DEBUGOPT(Name, Type, Bits, Default)
#define CODEGENOPT(Name, Bits, Default) Name = Default;
#define ENUM_CODEGENOPT(Name, Type, Bits, Default) set##Name(Default);
#include "clang/Basic/CodeGenOptions.def"

// Next reset all debug options that can always be reset, because they never
// affect the PCM.
#define DEBUGOPT(Name, Bits, Default)
#define VALUE_DEBUGOPT(Name, Bits, Default)
#define ENUM_DEBUGOPT(Name, Type, Bits, Default)
#define BENIGN_DEBUGOPT(Name, Bits, Default) Name = Default;
#define BENIGN_VALUE_DEBUGOPT(Name, Bits, Default) Name = Default;
#define BENIGN_ENUM_DEBUGOPT(Name, Type, Bits, Default) set##Name(Default);
#include "clang/Basic/DebugOptions.def"

// Conditionally reset debug options that only matter when the debug info is
// emitted into the PCM (-gmodules).
if (ModuleFormat == "raw") {
#define DEBUGOPT(Name, Bits, Default) Name = Default;
#define VALUE_DEBUGOPT(Name, Bits, Default) Name = Default;
#define ENUM_DEBUGOPT(Name, Type, Bits, Default) set##Name(Default);
#define BENIGN_DEBUGOPT(Name, Bits, Default)
#define BENIGN_VALUE_DEBUGOPT(Name, Bits, Default)
#define BENIGN_ENUM_DEBUGOPT(Name, Type, Bits, Default)
#include "clang/Basic/DebugOptions.def"
}

RelocationModel = llvm::Reloc::PIC_;
memcpy(CoverageVersion, "408*", 4);
}

} // end namespace clang
13 changes: 13 additions & 0 deletions clang/lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4773,6 +4773,18 @@ std::string CompilerInvocation::getModuleHash() const {
if (getCodeGenOpts().DebugTypeExtRefs)
HBuilder.addRange(getCodeGenOpts().DebugPrefixMap);

// Extend the signature with the affecting debug options.
if (getHeaderSearchOpts().ModuleFormat == "obj") {
#define DEBUGOPT(Name, Bits, Default) HBuilder.add(CodeGenOpts->Name);
#define VALUE_DEBUGOPT(Name, Bits, Default) HBuilder.add(CodeGenOpts->Name);
#define ENUM_DEBUGOPT(Name, Type, Bits, Default) \
HBuilder.add(static_cast<unsigned>(CodeGenOpts->get##Name()));
#define BENIGN_DEBUGOPT(Name, Bits, Default)
#define BENIGN_VALUE_DEBUGOPT(Name, Bits, Default)
#define BENIGN_ENUM_DEBUGOPT(Name, Type, Bits, Default)
#include "clang/Basic/DebugOptions.def"
}

// Extend the signature with the enabled sanitizers, if at least one is
// enabled. Sanitizers which cannot affect AST generation aren't hashed.
SanitizerSet SanHash = getLangOpts().Sanitize;
Expand Down Expand Up @@ -4819,6 +4831,7 @@ std::vector<std::string> CompilerInvocationBase::getCC1CommandLine() const {
void CompilerInvocation::resetNonModularOptions() {
getLangOpts().resetNonModularOptions();
getPreprocessorOpts().resetNonModularOptions();
getCodeGenOpts().resetNonModularOptions(getHeaderSearchOpts().ModuleFormat);
}

void CompilerInvocation::clearImplicitModuleBuildOptions() {
Expand Down
Loading