shenhan updated this revision to Diff 550137.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D157750/new/
https://reviews.llvm.org/D157750
Files:
clang/include/clang/Basic/DiagnosticDriverKinds.td
clang/lib/Driver/ToolChains/Clang.cpp
clang/test/Driver/fsplit-machine-functions.c
llvm/include/llvm/IR/DiagnosticInfo.h
llvm/lib/CodeGen/MachineFunctionSplitter.cpp
llvm/lib/IR/DiagnosticInfo.cpp
Index: llvm/lib/IR/DiagnosticInfo.cpp
===================================================================
--- llvm/lib/IR/DiagnosticInfo.cpp
+++ llvm/lib/IR/DiagnosticInfo.cpp
@@ -449,3 +449,7 @@
if (!getNote().empty())
DP << ": " << getNote();
}
+
+void DiagnosticInfoMachineFunctionSplit::print(DiagnosticPrinter &DP) const {
+ DP << "-fsplit-machine-functions is not valid for " << TargetTriple;
+}
Index: llvm/lib/CodeGen/MachineFunctionSplitter.cpp
===================================================================
--- llvm/lib/CodeGen/MachineFunctionSplitter.cpp
+++ llvm/lib/CodeGen/MachineFunctionSplitter.cpp
@@ -35,9 +35,11 @@
#include "llvm/CodeGen/MachineFunctionPass.h"
#include "llvm/CodeGen/MachineModuleInfo.h"
#include "llvm/CodeGen/Passes.h"
+#include "llvm/IR/DiagnosticInfo.h"
#include "llvm/IR/Function.h"
#include "llvm/InitializePasses.h"
#include "llvm/Support/CommandLine.h"
+#include "llvm/TargetParser/Triple.h"
#include <optional>
using namespace llvm;
@@ -82,6 +84,11 @@
void getAnalysisUsage(AnalysisUsage &AU) const override;
bool runOnMachineFunction(MachineFunction &F) override;
+
+ bool doInitialization(Module &) override;
+
+private:
+ bool UnsupportedTriple = false;
};
} // end anonymous namespace
@@ -127,7 +134,20 @@
return (*Count < ColdCountThreshold);
}
+bool MachineFunctionSplitter::doInitialization(Module &M) {
+ StringRef TripleStr = M.getTargetTriple();
+ if (!Triple(TripleStr).isX86()) {
+ UnsupportedTriple = true;
+ M.getContext().diagnose(
+ DiagnosticInfoMachineFunctionSplit(TripleStr, DS_Warning));
+ return false;
+ }
+ return MachineFunctionPass::doInitialization(M);
+}
+
bool MachineFunctionSplitter::runOnMachineFunction(MachineFunction &MF) {
+ if (UnsupportedTriple)
+ return false;
// We target functions with profile data. Static information in the form
// of exception handling code may be split to cold if user passes the
// mfs-split-ehcode flag.
Index: llvm/include/llvm/IR/DiagnosticInfo.h
===================================================================
--- llvm/include/llvm/IR/DiagnosticInfo.h
+++ llvm/include/llvm/IR/DiagnosticInfo.h
@@ -86,6 +86,7 @@
DK_SrcMgr,
DK_DontCall,
DK_MisExpect,
+ DK_MachineFunctionSplit,
DK_FirstPluginKind // Must be last value to work with
// getNextAvailablePluginDiagnosticKind
};
@@ -1117,6 +1118,20 @@
}
};
+class DiagnosticInfoMachineFunctionSplit : public DiagnosticInfo {
+ StringRef TargetTriple;
+
+public:
+ DiagnosticInfoMachineFunctionSplit(StringRef TargetTriple,
+ DiagnosticSeverity DS)
+ : DiagnosticInfo(DK_MachineFunctionSplit, DS),
+ TargetTriple(TargetTriple) {}
+ void print(DiagnosticPrinter &DP) const override;
+ static bool classof(const DiagnosticInfo *DI) {
+ return DI->getKind() == DK_MachineFunctionSplit;
+ }
+};
+
} // end namespace llvm
#endif // LLVM_IR_DIAGNOSTICINFO_H
Index: clang/test/Driver/fsplit-machine-functions.c
===================================================================
--- clang/test/Driver/fsplit-machine-functions.c
+++ clang/test/Driver/fsplit-machine-functions.c
@@ -1,8 +1,8 @@
// RUN: %clang -### -target x86_64 -fprofile-use=default.profdata -fsplit-machine-functions %s -c 2>&1 | FileCheck -check-prefix=CHECK-OPT %s
// RUN: %clang -### -target x86_64 -fsplit-machine-functions %s -c 2>&1 | FileCheck -check-prefix=CHECK-OPT %s
// RUN: %clang -### -target x86_64 -fprofile-use=default.profdata -fsplit-machine-functions -fno-split-machine-functions %s -c 2>&1 | FileCheck -check-prefix=CHECK-NOOPT %s
-// RUN: not %clang -c -target arm-unknown-linux -fsplit-machine-functions %s 2>&1 | FileCheck -check-prefix=CHECK-TRIPLE %s
+// RUN: %clang -c -target arm-unknown-linux -fsplit-machine-functions %s 2>&1 | FileCheck -check-prefix=CHECK-TRIPLE %s
// CHECK-OPT: "-fsplit-machine-functions"
// CHECK-NOOPT-NOT: "-fsplit-machine-functions"
-// CHECK-TRIPLE: error: unsupported option '-fsplit-machine-functions' for target
+// CHECK-TRIPLE: warning: -fsplit-machine-functions is only valid for X86.
Index: clang/lib/Driver/ToolChains/Clang.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Clang.cpp
+++ clang/lib/Driver/ToolChains/Clang.cpp
@@ -5859,14 +5859,15 @@
if (Arg *A = Args.getLastArg(options::OPT_fsplit_machine_functions,
options::OPT_fno_split_machine_functions)) {
- // This codegen pass is only available on x86-elf targets.
- if (Triple.isX86() && Triple.isOSBinFormatELF()) {
- if (A->getOption().matches(options::OPT_fsplit_machine_functions))
+ if (A->getOption().matches(options::OPT_fsplit_machine_functions)) {
+ // This codegen pass is only available on elf targets.
+ if (Triple.isOSBinFormatELF())
A->render(Args, CmdArgs);
- } else {
- D.Diag(diag::err_drv_unsupported_opt_for_target)
- << A->getAsString(Args) << TripleStr;
+ else
+ D.Diag(diag::warn_drv_for_elf_only) << A->getAsString(Args);
}
+ // Do not issue warnings for -fno-split-machine-functions even it is not
+ // on ELF.
}
Args.AddLastArg(CmdArgs, options::OPT_finstrument_functions,
Index: clang/include/clang/Basic/DiagnosticDriverKinds.td
===================================================================
--- clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -693,6 +693,10 @@
"-fjmc works only for ELF; option ignored">,
InGroup<OptionIgnored>;
+def warn_drv_for_elf_only : Warning<
+ "'%0' works only for ELF; option ignored">,
+ InGroup<OptionIgnored>;
+
def warn_target_override_arm64ec : Warning<
"/arm64EC has been overridden by specified target: %0; option ignored">,
InGroup<OptionIgnored>;
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits