Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / llvm / lib / MC / MCTargetOptionsCommandFlags.cpp
blob8a4923e4792fb539ff689157738b7d59c0c9671c
1 //===-- MCTargetOptionsCommandFlags.cpp -----------------------*- C++ //-*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file contains machine code-specific flags that are shared between
10 // different command line tools.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/MC/MCTargetOptionsCommandFlags.h"
15 #include "llvm/MC/MCTargetOptions.h"
16 #include "llvm/Support/CommandLine.h"
18 using namespace llvm;
20 #define MCOPT(TY, NAME) \
21 static cl::opt<TY> *NAME##View; \
22 TY llvm::mc::get##NAME() { \
23 assert(NAME##View && "RegisterMCTargetOptionsFlags not created."); \
24 return *NAME##View; \
27 #define MCOPT_EXP(TY, NAME) \
28 MCOPT(TY, NAME) \
29 std::optional<TY> llvm::mc::getExplicit##NAME() { \
30 if (NAME##View->getNumOccurrences()) { \
31 TY res = *NAME##View; \
32 return res; \
33 } \
34 return std::nullopt; \
37 MCOPT_EXP(bool, RelaxAll)
38 MCOPT(bool, IncrementalLinkerCompatible)
39 MCOPT(int, DwarfVersion)
40 MCOPT(bool, Dwarf64)
41 MCOPT(EmitDwarfUnwindType, EmitDwarfUnwind)
42 MCOPT(bool, EmitCompactUnwindNonCanonical)
43 MCOPT(bool, ShowMCInst)
44 MCOPT(bool, FatalWarnings)
45 MCOPT(bool, NoWarn)
46 MCOPT(bool, NoDeprecatedWarn)
47 MCOPT(bool, NoTypeCheck)
48 MCOPT(std::string, ABIName)
49 MCOPT(std::string, AsSecureLogFile)
51 llvm::mc::RegisterMCTargetOptionsFlags::RegisterMCTargetOptionsFlags() {
52 #define MCBINDOPT(NAME) \
53 do { \
54 NAME##View = std::addressof(NAME); \
55 } while (0)
57 static cl::opt<bool> RelaxAll(
58 "mc-relax-all", cl::desc("When used with filetype=obj, relax all fixups "
59 "in the emitted object file"));
60 MCBINDOPT(RelaxAll);
62 static cl::opt<bool> IncrementalLinkerCompatible(
63 "incremental-linker-compatible",
64 cl::desc(
65 "When used with filetype=obj, "
66 "emit an object file which can be used with an incremental linker"));
67 MCBINDOPT(IncrementalLinkerCompatible);
69 static cl::opt<int> DwarfVersion("dwarf-version", cl::desc("Dwarf version"),
70 cl::init(0));
71 MCBINDOPT(DwarfVersion);
73 static cl::opt<bool> Dwarf64(
74 "dwarf64",
75 cl::desc("Generate debugging info in the 64-bit DWARF format"));
76 MCBINDOPT(Dwarf64);
78 static cl::opt<EmitDwarfUnwindType> EmitDwarfUnwind(
79 "emit-dwarf-unwind", cl::desc("Whether to emit DWARF EH frame entries."),
80 cl::init(EmitDwarfUnwindType::Default),
81 cl::values(clEnumValN(EmitDwarfUnwindType::Always, "always",
82 "Always emit EH frame entries"),
83 clEnumValN(EmitDwarfUnwindType::NoCompactUnwind,
84 "no-compact-unwind",
85 "Only emit EH frame entries when compact unwind is "
86 "not available"),
87 clEnumValN(EmitDwarfUnwindType::Default, "default",
88 "Use target platform default")));
89 MCBINDOPT(EmitDwarfUnwind);
91 static cl::opt<bool> EmitCompactUnwindNonCanonical(
92 "emit-compact-unwind-non-canonical",
93 cl::desc(
94 "Whether to try to emit Compact Unwind for non canonical entries."),
95 cl::init(
96 false)); // By default, use DWARF for non-canonical personalities.
97 MCBINDOPT(EmitCompactUnwindNonCanonical);
99 static cl::opt<bool> ShowMCInst(
100 "asm-show-inst",
101 cl::desc("Emit internal instruction representation to assembly file"));
102 MCBINDOPT(ShowMCInst);
104 static cl::opt<bool> FatalWarnings("fatal-warnings",
105 cl::desc("Treat warnings as errors"));
106 MCBINDOPT(FatalWarnings);
108 static cl::opt<bool> NoWarn("no-warn", cl::desc("Suppress all warnings"));
109 static cl::alias NoWarnW("W", cl::desc("Alias for --no-warn"),
110 cl::aliasopt(NoWarn));
111 MCBINDOPT(NoWarn);
113 static cl::opt<bool> NoDeprecatedWarn(
114 "no-deprecated-warn", cl::desc("Suppress all deprecated warnings"));
115 MCBINDOPT(NoDeprecatedWarn);
117 static cl::opt<bool> NoTypeCheck(
118 "no-type-check", cl::desc("Suppress type errors (Wasm)"));
119 MCBINDOPT(NoTypeCheck);
121 static cl::opt<std::string> ABIName(
122 "target-abi", cl::Hidden,
123 cl::desc("The name of the ABI to be targeted from the backend."),
124 cl::init(""));
125 MCBINDOPT(ABIName);
127 static cl::opt<std::string> AsSecureLogFile(
128 "as-secure-log-file", cl::desc("As secure log file name"), cl::Hidden);
129 MCBINDOPT(AsSecureLogFile);
131 #undef MCBINDOPT
134 MCTargetOptions llvm::mc::InitMCTargetOptionsFromFlags() {
135 MCTargetOptions Options;
136 Options.MCRelaxAll = getRelaxAll();
137 Options.MCIncrementalLinkerCompatible = getIncrementalLinkerCompatible();
138 Options.Dwarf64 = getDwarf64();
139 Options.DwarfVersion = getDwarfVersion();
140 Options.ShowMCInst = getShowMCInst();
141 Options.ABIName = getABIName();
142 Options.MCFatalWarnings = getFatalWarnings();
143 Options.MCNoWarn = getNoWarn();
144 Options.MCNoDeprecatedWarn = getNoDeprecatedWarn();
145 Options.MCNoTypeCheck = getNoTypeCheck();
146 Options.EmitDwarfUnwind = getEmitDwarfUnwind();
147 Options.EmitCompactUnwindNonCanonical = getEmitCompactUnwindNonCanonical();
148 Options.AsSecureLogFile = getAsSecureLogFile();
150 return Options;