26 const llvm::Triple &Triple = TC.
getTriple();
27 if (!Args.hasFlag(options::OPT_fxray_instrument,
28 options::OPT_fno_xray_instrument,
false))
30 XRayInstrument = Args.getLastArg(options::OPT_fxray_instrument);
31 if (Triple.isMacOSX()) {
32 switch (Triple.getArch()) {
33 case llvm::Triple::aarch64:
34 case llvm::Triple::x86_64:
37 D.
Diag(diag::err_drv_unsupported_opt_for_target)
38 << XRayInstrument->getSpelling() << Triple.str();
41 }
else if (Triple.isOSBinFormatELF()) {
42 switch (Triple.getArch()) {
43 case llvm::Triple::x86_64:
44 case llvm::Triple::arm:
45 case llvm::Triple::aarch64:
46 case llvm::Triple::hexagon:
47 case llvm::Triple::ppc64le:
48 case llvm::Triple::loongarch64:
49 case llvm::Triple::mips:
50 case llvm::Triple::mipsel:
51 case llvm::Triple::mips64:
52 case llvm::Triple::mips64el:
53 case llvm::Triple::systemz:
54 case llvm::Triple::riscv32:
55 case llvm::Triple::riscv64:
58 D.
Diag(diag::err_drv_unsupported_opt_for_target)
59 << XRayInstrument->getSpelling() << Triple.str();
62 D.
Diag(diag::err_drv_unsupported_opt_for_target)
63 << XRayInstrument->getSpelling() << Triple.str();
66 if (Args.hasFlag(options::OPT_fxray_shared, options::OPT_fno_xray_shared,
71 switch (Triple.getArch()) {
72 case llvm::Triple::aarch64:
73 case llvm::Triple::x86_64:
76 D.
Diag(diag::err_drv_unsupported_opt_for_target)
77 <<
"-fxray-shared" << Triple.str();
82 D.
Diag(diag::err_opt_not_valid_without_opt) <<
"-fxray-shared"
89 if (Arg *A = Args.getLastArg(options::OPT_fpatchable_function_entry_EQ))
90 D.
Diag(diag::err_drv_argument_not_allowed_with)
91 << XRayInstrument->getSpelling() << A->getSpelling();
93 if (!Args.hasFlag(options::OPT_fxray_link_deps,
94 options::OPT_fno_xray_link_deps,
true))
98 Args.getAllArgValues(options::OPT_fxray_instrumentation_bundle);
102 for (
const auto &B : Bundles) {
104 llvm::SplitString(B, BundleParts,
",");
105 for (
const auto &P : BundleParts) {
107 auto Valid = llvm::StringSwitch<bool>(P)
108 .Cases({
"none",
"all",
"function",
"function-entry",
109 "function-exit",
"custom"},
114 D.
Diag(clang::diag::err_drv_invalid_value)
115 <<
"-fxray-instrumentation-bundle=" << P;
121 InstrumentationBundle.clear();
125 InstrumentationBundle.Mask |= Mask;
131 for (
const auto &Filename :
132 Args.getAllArgValues(options::OPT_fxray_always_instrument)) {
133 if (D.
getVFS().exists(Filename)) {
134 AlwaysInstrumentFiles.push_back(Filename);
135 ExtraDeps.push_back(Filename);
137 D.
Diag(clang::diag::err_drv_no_such_file) << Filename;
140 for (
const auto &Filename :
141 Args.getAllArgValues(options::OPT_fxray_never_instrument)) {
142 if (D.
getVFS().exists(Filename)) {
143 NeverInstrumentFiles.push_back(Filename);
144 ExtraDeps.push_back(Filename);
146 D.
Diag(clang::diag::err_drv_no_such_file) << Filename;
149 for (
const auto &Filename :
150 Args.getAllArgValues(options::OPT_fxray_attr_list)) {
151 if (D.
getVFS().exists(Filename)) {
152 AttrListFiles.push_back(Filename);
153 ExtraDeps.push_back(Filename);
155 D.
Diag(clang::diag::err_drv_no_such_file) << Filename;
159 auto SpecifiedModes = Args.getAllArgValues(options::OPT_fxray_modes);
160 if (SpecifiedModes.empty())
163 for (
const auto &Arg : SpecifiedModes) {
166 llvm::SplitString(Arg, ModeParts,
",");
167 for (
const auto &M : ModeParts)
173 Modes.push_back(std::string(M));
178 Modes.erase(llvm::unique(Modes), Modes.end());
182 ArgStringList &CmdArgs,
types::ID InputType)
const {
186 XRayInstrument->render(Args, CmdArgs);
192 Args.addOptInFlag(CmdArgs, options::OPT_fxray_always_emit_customevents,
193 options::OPT_fno_xray_always_emit_customevents);
195 Args.addOptInFlag(CmdArgs, options::OPT_fxray_always_emit_typedevents,
196 options::OPT_fno_xray_always_emit_typedevents);
197 Args.addOptInFlag(CmdArgs, options::OPT_fxray_ignore_loops,
198 options::OPT_fno_xray_ignore_loops);
199 Args.addOptOutFlag(CmdArgs, options::OPT_fxray_function_index,
200 options::OPT_fno_xray_function_index);
203 Args.addOptInFlag(CmdArgs, options::OPT_fxray_shared,
204 options::OPT_fno_xray_shared);
207 Args.getLastArg(options::OPT_fxray_instruction_threshold_EQ)) {
209 StringRef S = A->getValue();
211 D.
Diag(clang::diag::err_drv_invalid_value) << A->getAsString(Args) << S;
213 A->render(Args, CmdArgs);
216 int XRayFunctionGroups = 1;
217 int XRaySelectedFunctionGroup = 0;
218 if (
const Arg *A = Args.getLastArg(options::OPT_fxray_function_groups)) {
219 StringRef S = A->getValue();
220 if (S.getAsInteger(0, XRayFunctionGroups) || XRayFunctionGroups < 1)
221 D.
Diag(clang::diag::err_drv_invalid_value) << A->getAsString(Args) << S;
222 if (XRayFunctionGroups > 1)
223 A->render(Args, CmdArgs);
226 Args.getLastArg(options::OPT_fxray_selected_function_group)) {
227 StringRef S = A->getValue();
228 if (S.getAsInteger(0, XRaySelectedFunctionGroup) ||
229 XRaySelectedFunctionGroup < 0 ||
230 XRaySelectedFunctionGroup >= XRayFunctionGroups)
231 D.
Diag(clang::diag::err_drv_invalid_value) << A->getAsString(Args) << S;
232 if (XRaySelectedFunctionGroup != 0)
233 A->render(Args, CmdArgs);
236 for (
const auto &
Always : AlwaysInstrumentFiles) {
238 AlwaysInstrumentOpt +=
Always;
239 CmdArgs.push_back(Args.MakeArgString(AlwaysInstrumentOpt));
242 for (
const auto &
Never : NeverInstrumentFiles) {
244 NeverInstrumentOpt +=
Never;
245 CmdArgs.push_back(Args.MakeArgString(NeverInstrumentOpt));
248 for (
const auto &AttrFile : AttrListFiles) {
250 AttrListFileOpt += AttrFile;
251 CmdArgs.push_back(Args.MakeArgString(AttrListFileOpt));
254 for (
const auto &Dep : ExtraDeps) {
257 CmdArgs.push_back(Args.MakeArgString(ExtraDepOpt));
260 for (
const auto &Mode : Modes) {
263 CmdArgs.push_back(Args.MakeArgString(ModeOpt));
267 if (InstrumentationBundle.full()) {
269 }
else if (InstrumentationBundle.empty()) {
274 Bundle +=
"function";
276 Bundle +=
"function-entry";
278 Bundle +=
"function-exit";
285 CmdArgs.push_back(Args.MakeArgString(Bundle));