15 #include "llvm/ADT/StringExtras.h" 16 #include "llvm/ADT/StringSwitch.h" 17 #include "llvm/Support/FileSystem.h" 18 #include "llvm/Support/Path.h" 19 #include "llvm/Support/ScopedPrinter.h" 20 #include "llvm/Support/SpecialCaseList.h" 22 using namespace clang;
27 constexpr
char XRayInstrumentOption[] =
"-fxray-instrument";
28 constexpr
char XRayInstructionThresholdOption[] =
29 "-fxray-instruction-threshold=";
34 const llvm::Triple &Triple = TC.
getTriple();
35 if (Args.hasFlag(options::OPT_fxray_instrument,
36 options::OPT_fnoxray_instrument,
false)) {
37 if (Triple.getOS() == llvm::Triple::Linux)
38 switch (Triple.getArch()) {
39 case llvm::Triple::x86_64:
40 case llvm::Triple::arm:
41 case llvm::Triple::aarch64:
42 case llvm::Triple::ppc64le:
43 case llvm::Triple::mips:
44 case llvm::Triple::mipsel:
45 case llvm::Triple::mips64:
46 case llvm::Triple::mips64el:
49 D.
Diag(diag::err_drv_clang_unsupported)
50 << (std::string(XRayInstrumentOption) +
" on " + Triple.str());
53 D.
Diag(diag::err_drv_clang_unsupported)
54 << (std::string(XRayInstrumentOption) +
" on non-Linux target OS");
55 XRayInstrument =
true;
57 Args.getLastArg(options::OPT_fxray_instruction_threshold_,
58 options::OPT_fxray_instruction_threshold_EQ)) {
59 StringRef S = A->getValue();
60 if (S.getAsInteger(0, InstructionThreshold) || InstructionThreshold < 0)
61 D.
Diag(clang::diag::err_drv_invalid_value) << A->getAsString(Args) << S;
68 if (Args.hasFlag(options::OPT_fxray_always_emit_customevents,
69 options::OPT_fnoxray_always_emit_customevents,
false))
70 XRayAlwaysEmitCustomEvents =
true;
75 Args.getAllArgValues(options::OPT_fxray_always_instrument)) {
76 if (llvm::sys::fs::exists(
Filename)) {
77 AlwaysInstrumentFiles.push_back(
Filename);
84 Args.getAllArgValues(options::OPT_fxray_never_instrument)) {
85 if (llvm::sys::fs::exists(
Filename)) {
86 NeverInstrumentFiles.push_back(
Filename);
95 ArgStringList &CmdArgs,
types::ID InputType)
const {
99 CmdArgs.push_back(XRayInstrumentOption);
101 if (XRayAlwaysEmitCustomEvents)
102 CmdArgs.push_back(
"-fxray-always-emit-customevents");
104 CmdArgs.push_back(Args.MakeArgString(Twine(XRayInstructionThresholdOption) +
105 Twine(InstructionThreshold)));
107 for (
const auto &Always : AlwaysInstrumentFiles) {
109 AlwaysInstrumentOpt += Always;
110 CmdArgs.push_back(Args.MakeArgString(AlwaysInstrumentOpt));
113 for (
const auto &Never : NeverInstrumentFiles) {
115 NeverInstrumentOpt += Never;
116 CmdArgs.push_back(Args.MakeArgString(NeverInstrumentOpt));
119 for (
const auto &Dep : ExtraDeps) {
122 CmdArgs.push_back(Args.MakeArgString(ExtraDepOpt));
DiagnosticBuilder Diag(unsigned DiagID) const
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
void addArgs(const ToolChain &TC, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs, types::ID InputType) const
Dataflow Directional Tag Classes.
XRayArgs(const ToolChain &TC, const llvm::opt::ArgList &Args)
Parses the XRay arguments from an argument list.