[clang] 52e79ed - [MC] MCAsmStreamer: use MCTargetOptions
Fangrui Song via cfe-commits
cfe-commits at lists.llvm.org
Sat Jul 20 22:57:06 PDT 2024
Author: Fangrui Song
Date: 2024-07-20T22:57:01-07:00
New Revision: 52e79ed1e078f69103dcd9234c2494e7dd64b5f7
URL: https://github.com/llvm/llvm-project/commit/52e79ed1e078f69103dcd9234c2494e7dd64b5f7
DIFF: https://github.com/llvm/llvm-project/commit/52e79ed1e078f69103dcd9234c2494e7dd64b5f7.diff
LOG: [MC] MCAsmStreamer: use MCTargetOptions
Some bool parameters duplicate MCTargetOptions and might cause
inconsistency/confusion.
Added:
Modified:
clang/tools/driver/cc1as_main.cpp
llvm/lib/CodeGen/LLVMTargetMachine.cpp
llvm/lib/DWARFLinker/Classic/DWARFStreamer.cpp
llvm/lib/DWARFLinker/Parallel/DWARFEmitterImpl.cpp
llvm/lib/MC/MCAsmStreamer.cpp
llvm/tools/llvm-mc/llvm-mc.cpp
llvm/tools/llvm-ml/llvm-ml.cpp
Removed:
################################################################################
diff --git a/clang/tools/driver/cc1as_main.cpp b/clang/tools/driver/cc1as_main.cpp
index 2d5acbecb123a..15d1e0c2f2f2d 100644
--- a/clang/tools/driver/cc1as_main.cpp
+++ b/clang/tools/driver/cc1as_main.cpp
@@ -531,6 +531,9 @@ static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts,
MCOptions.MCNoWarn = Opts.NoWarn;
MCOptions.MCFatalWarnings = Opts.FatalWarnings;
MCOptions.MCNoTypeCheck = Opts.NoTypeCheck;
+ MCOptions.ShowMCInst = Opts.ShowInst;
+ MCOptions.AsmVerbose = true;
+ MCOptions.MCUseDwarfDirectory = MCTargetOptions::EnableDwarfDirectory;
MCOptions.ABIName = Opts.TargetABI;
// FIXME: There is a bit of code duplication with addPassesToEmitFile.
diff --git a/llvm/lib/CodeGen/LLVMTargetMachine.cpp b/llvm/lib/CodeGen/LLVMTargetMachine.cpp
index 562821df06651..819187c129c3a 100644
--- a/llvm/lib/CodeGen/LLVMTargetMachine.cpp
+++ b/llvm/lib/CodeGen/LLVMTargetMachine.cpp
@@ -167,25 +167,12 @@ Expected<std::unique_ptr<MCStreamer>> LLVMTargetMachine::createMCStreamer(
if (Options.MCOptions.ShowMCEncoding)
MCE.reset(getTarget().createMCCodeEmitter(MII, Context));
- bool UseDwarfDirectory = false;
- switch (Options.MCOptions.MCUseDwarfDirectory) {
- case MCTargetOptions::DisableDwarfDirectory:
- UseDwarfDirectory = false;
- break;
- case MCTargetOptions::EnableDwarfDirectory:
- UseDwarfDirectory = true;
- break;
- case MCTargetOptions::DefaultDwarfDirectory:
- UseDwarfDirectory = MAI.enableDwarfFileDirectoryDefault();
- break;
- }
-
std::unique_ptr<MCAsmBackend> MAB(
getTarget().createMCAsmBackend(STI, MRI, Options.MCOptions));
auto FOut = std::make_unique<formatted_raw_ostream>(Out);
MCStreamer *S = getTarget().createAsmStreamer(
- Context, std::move(FOut), Options.MCOptions.AsmVerbose,
- UseDwarfDirectory, InstPrinter, std::move(MCE), std::move(MAB),
+ Context, std::move(FOut), Options.MCOptions.AsmVerbose, true,
+ InstPrinter, std::move(MCE), std::move(MAB),
Options.MCOptions.ShowMCInst);
AsmStreamer.reset(S);
break;
diff --git a/llvm/lib/DWARFLinker/Classic/DWARFStreamer.cpp b/llvm/lib/DWARFLinker/Classic/DWARFStreamer.cpp
index 55a0ee81ad4bc..45a62daffb033 100644
--- a/llvm/lib/DWARFLinker/Classic/DWARFStreamer.cpp
+++ b/llvm/lib/DWARFLinker/Classic/DWARFStreamer.cpp
@@ -62,6 +62,8 @@ Error DwarfStreamer::init(Triple TheTriple,
TripleName.c_str());
MCTargetOptions MCOptions = mc::InitMCTargetOptionsFromFlags();
+ MCOptions.AsmVerbose = true;
+ MCOptions.MCUseDwarfDirectory = MCTargetOptions::EnableDwarfDirectory;
MAI.reset(TheTarget->createMCAsmInfo(*MRI, TripleName, MCOptions));
if (!MAI)
return createStringError(std::errc::invalid_argument,
diff --git a/llvm/lib/DWARFLinker/Parallel/DWARFEmitterImpl.cpp b/llvm/lib/DWARFLinker/Parallel/DWARFEmitterImpl.cpp
index dd379de68e4c4..f790766348b53 100644
--- a/llvm/lib/DWARFLinker/Parallel/DWARFEmitterImpl.cpp
+++ b/llvm/lib/DWARFLinker/Parallel/DWARFEmitterImpl.cpp
@@ -41,6 +41,8 @@ Error DwarfEmitterImpl::init(Triple TheTriple,
TripleName.c_str());
MCTargetOptions MCOptions = mc::InitMCTargetOptionsFromFlags();
+ MCOptions.AsmVerbose = true;
+ MCOptions.MCUseDwarfDirectory = MCTargetOptions::EnableDwarfDirectory;
MAI.reset(TheTarget->createMCAsmInfo(*MRI, TripleName, MCOptions));
if (!MAI)
return createStringError(std::errc::invalid_argument,
diff --git a/llvm/lib/MC/MCAsmStreamer.cpp b/llvm/lib/MC/MCAsmStreamer.cpp
index 24209e456b5e2..b4122881bd45a 100644
--- a/llvm/lib/MC/MCAsmStreamer.cpp
+++ b/llvm/lib/MC/MCAsmStreamer.cpp
@@ -55,9 +55,9 @@ class MCAsmStreamer final : public MCStreamer {
raw_svector_ostream CommentStream;
raw_null_ostream NullStream;
- unsigned IsVerboseAsm : 1;
- unsigned ShowInst : 1;
- unsigned UseDwarfDirectory : 1;
+ bool IsVerboseAsm = false;
+ bool ShowInst = false;
+ bool UseDwarfDirectory = false;
void EmitRegisterName(int64_t Register);
void PrintQuotedString(StringRef Data, raw_ostream &OS) const;
@@ -72,24 +72,41 @@ class MCAsmStreamer final : public MCStreamer {
public:
MCAsmStreamer(MCContext &Context, std::unique_ptr<formatted_raw_ostream> os,
- bool isVerboseAsm, bool useDwarfDirectory,
- MCInstPrinter *printer, std::unique_ptr<MCCodeEmitter> emitter,
- std::unique_ptr<MCAsmBackend> asmbackend, bool showInst)
+ bool, bool, MCInstPrinter *printer,
+ std::unique_ptr<MCCodeEmitter> emitter,
+ std::unique_ptr<MCAsmBackend> asmbackend, bool)
: MCStreamer(Context), OSOwner(std::move(os)), OS(*OSOwner),
MAI(Context.getAsmInfo()), InstPrinter(printer),
Assembler(std::make_unique<MCAssembler>(
Context, std::move(asmbackend), std::move(emitter),
(asmbackend) ? asmbackend->createObjectWriter(NullStream)
: nullptr)),
- CommentStream(CommentToEmit), IsVerboseAsm(isVerboseAsm),
- ShowInst(showInst), UseDwarfDirectory(useDwarfDirectory) {
+ CommentStream(CommentToEmit) {
assert(InstPrinter);
- if (IsVerboseAsm)
- InstPrinter->setCommentStream(CommentStream);
if (Assembler->getBackendPtr())
setAllowAutoPadding(Assembler->getBackend().allowAutoPadding());
Context.setUseNamesOnTempLabels(true);
+
+ auto *TO = Context.getTargetOptions();
+ if (!TO)
+ return;
+ IsVerboseAsm = TO->AsmVerbose;
+ if (IsVerboseAsm)
+ InstPrinter->setCommentStream(CommentStream);
+ ShowInst = TO->ShowMCInst;
+ switch (TO->MCUseDwarfDirectory) {
+ case MCTargetOptions::DisableDwarfDirectory:
+ UseDwarfDirectory = false;
+ break;
+ case MCTargetOptions::EnableDwarfDirectory:
+ UseDwarfDirectory = true;
+ break;
+ case MCTargetOptions::DefaultDwarfDirectory:
+ UseDwarfDirectory =
+ Context.getAsmInfo()->enableDwarfFileDirectoryDefault();
+ break;
+ }
}
MCAssembler &getAssembler() { return *Assembler; }
diff --git a/llvm/tools/llvm-mc/llvm-mc.cpp b/llvm/tools/llvm-mc/llvm-mc.cpp
index c46e4f087d42b..0f1e330541441 100644
--- a/llvm/tools/llvm-mc/llvm-mc.cpp
+++ b/llvm/tools/llvm-mc/llvm-mc.cpp
@@ -356,6 +356,9 @@ int main(int argc, char **argv) {
cl::ParseCommandLineOptions(argc, argv, "llvm machine code playground\n");
MCTargetOptions MCOptions = mc::InitMCTargetOptionsFromFlags();
MCOptions.CompressDebugSections = CompressDebugSections.getValue();
+ MCOptions.ShowMCInst = ShowInst;
+ MCOptions.AsmVerbose = true;
+ MCOptions.MCUseDwarfDirectory = MCTargetOptions::EnableDwarfDirectory;
setDwarfDebugFlags(argc, argv);
setDwarfDebugProducer();
diff --git a/llvm/tools/llvm-ml/llvm-ml.cpp b/llvm/tools/llvm-ml/llvm-ml.cpp
index 829347dafee98..bcfec97019c1c 100644
--- a/llvm/tools/llvm-ml/llvm-ml.cpp
+++ b/llvm/tools/llvm-ml/llvm-ml.cpp
@@ -264,6 +264,7 @@ int llvm_ml_main(int Argc, char **Argv, const llvm::ToolContext &) {
MCOptions.AssemblyLanguage = "masm";
MCOptions.MCFatalWarnings = InputArgs.hasArg(OPT_fatal_warnings);
MCOptions.MCSaveTempLabels = InputArgs.hasArg(OPT_save_temp_labels);
+ MCOptions.AsmVerbose = true;
Triple TheTriple = GetTriple(ProgName, InputArgs);
std::string Error;
More information about the cfe-commits
mailing list