Skip to content

Commit

Permalink
[Driver] Simplify -fxray-instrument handling
Browse files Browse the repository at this point in the history
  • Loading branch information
MaskRay committed Jun 11, 2023
1 parent 2670680 commit d25992e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
2 changes: 1 addition & 1 deletion clang/include/clang/Driver/XRayArgs.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class XRayArgs {
std::vector<std::string> ExtraDeps;
std::vector<std::string> Modes;
XRayInstrSet InstrumentationBundle;
bool XRayInstrument = false;
llvm::opt::Arg *XRayInstrument = nullptr;
int InstructionThreshold = 200;
bool XRayAlwaysEmitCustomEvents = false;
bool XRayAlwaysEmitTypedEvents = false;
Expand Down
23 changes: 11 additions & 12 deletions clang/lib/Driver/XRayArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ using namespace clang::driver;
using namespace llvm::opt;

namespace {
constexpr char XRayInstrumentOption[] = "-fxray-instrument";
constexpr char XRayInstructionThresholdOption[] =
"-fxray-instruction-threshold=";
constexpr const char *const XRaySupportedModes[] = {"xray-fdr", "xray-basic"};
Expand All @@ -35,6 +34,7 @@ XRayArgs::XRayArgs(const ToolChain &TC, const ArgList &Args) {
if (!Args.hasFlag(options::OPT_fxray_instrument,
options::OPT_fno_xray_instrument, false))
return;
XRayInstrument = Args.getLastArg(options::OPT_fxray_instrument);
if (Triple.getOS() == llvm::Triple::Linux) {
switch (Triple.getArch()) {
case llvm::Triple::x86_64:
Expand All @@ -48,36 +48,35 @@ XRayArgs::XRayArgs(const ToolChain &TC, const ArgList &Args) {
case llvm::Triple::mips64el:
break;
default:
D.Diag(diag::err_drv_clang_unsupported)
<< (std::string(XRayInstrumentOption) + " on " + Triple.str());
D.Diag(diag::err_drv_unsupported_opt_for_target)
<< XRayInstrument->getSpelling() << Triple.str();
}
} else if (Triple.isOSFreeBSD() || Triple.isOSOpenBSD() ||
Triple.isOSNetBSD() || Triple.isMacOSX()) {
if (Triple.getArch() != llvm::Triple::x86_64) {
D.Diag(diag::err_drv_clang_unsupported)
<< (std::string(XRayInstrumentOption) + " on " + Triple.str());
D.Diag(diag::err_drv_unsupported_opt_for_target)
<< XRayInstrument->getSpelling() << Triple.str();
}
} else if (Triple.getOS() == llvm::Triple::Fuchsia) {
switch (Triple.getArch()) {
case llvm::Triple::x86_64:
case llvm::Triple::aarch64:
break;
default:
D.Diag(diag::err_drv_clang_unsupported)
<< (std::string(XRayInstrumentOption) + " on " + Triple.str());
D.Diag(diag::err_drv_unsupported_opt_for_target)
<< XRayInstrument->getSpelling() << Triple.str();
}
} else {
D.Diag(diag::err_drv_clang_unsupported)
<< (std::string(XRayInstrumentOption) + " on " + Triple.str());
D.Diag(diag::err_drv_unsupported_opt_for_target)
<< XRayInstrument->getSpelling() << Triple.str();
}

// Both XRay and -fpatchable-function-entry use
// TargetOpcode::PATCHABLE_FUNCTION_ENTER.
if (Arg *A = Args.getLastArg(options::OPT_fpatchable_function_entry_EQ))
D.Diag(diag::err_drv_argument_not_allowed_with)
<< "-fxray-instrument" << A->getSpelling();
<< XRayInstrument->getSpelling() << A->getSpelling();

XRayInstrument = true;
if (const Arg *A =
Args.getLastArg(options::OPT_fxray_instruction_threshold_EQ)) {
StringRef S = A->getValue();
Expand Down Expand Up @@ -211,7 +210,7 @@ void XRayArgs::addArgs(const ToolChain &TC, const ArgList &Args,
if (!XRayInstrument)
return;

CmdArgs.push_back(XRayInstrumentOption);
XRayInstrument->render(Args, CmdArgs);

if (XRayAlwaysEmitCustomEvents)
CmdArgs.push_back("-fxray-always-emit-customevents");
Expand Down

0 comments on commit d25992e

Please sign in to comment.