From 91c18ff3482abdf90239e9b482797403f6e7e9bc Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Wed, 6 Mar 2024 23:19:59 -0800 Subject: [PATCH] [MC] Move CompressDebugSections/RelaxELFRelocations from TargetOptions/MCAsmInfo to MCTargetOptions The convention is for such MC-specific options to reside in MCTargetOptions. However, CompressDebugSections/RelaxELFRelocations do not follow the convention: `CompressDebugSections` is defined in both TargetOptions and MCAsmInfo and there is forwarding complexity. Move the option to MCTargetOptions and hereby simplify the code. Rename the misleading RelaxELFRelocations to X86RelaxRelocations. llvm-mc -relax-relocations and llc -x86-relax-relocations can now be unified. Also updated Comgr to reflect this change. Change-Id: Id87f6ab3aa2371c08c5504a85a493d7a7984f7f3 --- amd/comgr/src/comgr-compiler.cpp | 6 +++--- llvm/include/llvm/MC/MCAsmInfo.h | 16 ---------------- 2 files changed, 3 insertions(+), 19 deletions(-) diff --git a/amd/comgr/src/comgr-compiler.cpp b/amd/comgr/src/comgr-compiler.cpp index 8ac16d46aa6d5e..0d8ee3ad433310 100644 --- a/amd/comgr/src/comgr-compiler.cpp +++ b/amd/comgr/src/comgr-compiler.cpp @@ -349,6 +349,7 @@ getOutputStream(AssemblerInvocation &Opts, DiagnosticsEngine &Diags, return Out; } +// clang/tools/driver/cc1as_main.cpp, ExecuteAssemblerImpl() static bool executeAssemblerImpl(AssemblerInvocation &Opts, DiagnosticsEngine &Diags, raw_ostream &LogS) { // Get the target specific parser. @@ -384,15 +385,14 @@ static bool executeAssemblerImpl(AssemblerInvocation &Opts, assert(MRI && "Unable to create target register info!"); llvm::MCTargetOptions MCOptions; + MCOptions.X86RelaxRelocations = Opts.RelaxELFRelocations; + MCOptions.CompressDebugSections = Opts.CompressDebugSections; std::unique_ptr MAI( TheTarget->createMCAsmInfo(*MRI, Opts.Triple, MCOptions)); assert(MAI && "Unable to create target asm info!"); // Ensure MCAsmInfo initialization occurs before any use, otherwise sections // may be created with a combination of default and explicit settings. - MAI->setCompressDebugSections(Opts.CompressDebugSections); - - MAI->setRelaxELFRelocations(Opts.RelaxELFRelocations); bool IsBinary = Opts.OutputType == AssemblerInvocation::FT_Obj; std::unique_ptr FDOS = getOutputStream(Opts, Diags, IsBinary); diff --git a/llvm/include/llvm/MC/MCAsmInfo.h b/llvm/include/llvm/MC/MCAsmInfo.h index c92c3fcc9757fb..0f898f4fd17ce0 100644 --- a/llvm/include/llvm/MC/MCAsmInfo.h +++ b/llvm/include/llvm/MC/MCAsmInfo.h @@ -529,17 +529,10 @@ class MCAsmInfo { /// Preserve Comments in assembly bool PreserveAsmComments; - /// Compress DWARF debug sections. Defaults to no compression. - DebugCompressionType CompressDebugSections = DebugCompressionType::None; - /// True if the integrated assembler should interpret 'a >> b' constant /// expressions as logical rather than arithmetic. bool UseLogicalShr = true; - // If true, emit GOTPCRELX/REX_GOTPCRELX instead of GOTPCREL, on - // X86_64 ELF. - bool RelaxELFRelocations = true; - // If true, then the lexer and expression parser will support %neg(), // %hi(), and similar unary operators. bool HasMipsExpressions = false; @@ -887,18 +880,9 @@ class MCAsmInfo { PreserveAsmComments = Value; } - DebugCompressionType compressDebugSections() const { - return CompressDebugSections; - } - - void setCompressDebugSections(DebugCompressionType CompressDebugSections) { - this->CompressDebugSections = CompressDebugSections; - } bool shouldUseLogicalShr() const { return UseLogicalShr; } - bool canRelaxRelocations() const { return RelaxELFRelocations; } - void setRelaxELFRelocations(bool V) { RelaxELFRelocations = V; } bool hasMipsExpressions() const { return HasMipsExpressions; } bool needsFunctionDescriptors() const { return NeedsFunctionDescriptors; } bool shouldUseMotorolaIntegers() const { return UseMotorolaIntegers; }