forked from OSchip/llvm-project
[clang][nfc] Split getOrCheckAMDGPUCodeObjectVersion
[clang][nfc] Split getOrCheckAMDGPUCodeObjectVersion Separates detection of deprecated or invalid code object version from returning the version. Written to avoid any behaviour change. Precursor to a revision of D98746. Reviewed By: yaxunl Differential Revision: https://reviews.llvm.org/D101077
This commit is contained in:
parent
484b6648fd
commit
2cdb9873b2
|
@ -568,7 +568,7 @@ AMDGPUToolChain::AMDGPUToolChain(const Driver &D, const llvm::Triple &Triple,
|
|||
// and errors for the last invalid code object version options.
|
||||
// It is done here to avoid repeated warning or error messages for
|
||||
// each tool invocation.
|
||||
(void)getOrCheckAMDGPUCodeObjectVersion(D, Args, /*Diagnose=*/true);
|
||||
checkAMDGPUCodeObjectVersion(D, Args);
|
||||
}
|
||||
|
||||
Tool *AMDGPUToolChain::buildLinker() const {
|
||||
|
|
|
@ -1114,7 +1114,7 @@ static const char *RelocationModelName(llvm::Reloc::Model Model) {
|
|||
static void handleAMDGPUCodeObjectVersionOptions(const Driver &D,
|
||||
const ArgList &Args,
|
||||
ArgStringList &CmdArgs) {
|
||||
unsigned CodeObjVer = getOrCheckAMDGPUCodeObjectVersion(D, Args);
|
||||
unsigned CodeObjVer = getAMDGPUCodeObjectVersion(D, Args);
|
||||
CmdArgs.insert(CmdArgs.begin() + 1,
|
||||
Args.MakeArgString(Twine("--amdhsa-code-object-version=") +
|
||||
Twine(CodeObjVer)));
|
||||
|
|
|
@ -1573,29 +1573,46 @@ void tools::addX86AlignBranchArgs(const Driver &D, const ArgList &Args,
|
|||
}
|
||||
}
|
||||
|
||||
unsigned tools::getOrCheckAMDGPUCodeObjectVersion(
|
||||
const Driver &D, const llvm::opt::ArgList &Args, bool Diagnose) {
|
||||
const unsigned MinCodeObjVer = 2;
|
||||
const unsigned MaxCodeObjVer = 4;
|
||||
unsigned CodeObjVer = 4;
|
||||
|
||||
// Emit warnings for legacy options even if they are overridden.
|
||||
if (Diagnose) {
|
||||
if (Args.hasArg(options::OPT_mno_code_object_v3_legacy))
|
||||
D.Diag(diag::warn_drv_deprecated_arg) << "-mno-code-object-v3"
|
||||
<< "-mcode-object-version=2";
|
||||
|
||||
if (Args.hasArg(options::OPT_mcode_object_v3_legacy))
|
||||
D.Diag(diag::warn_drv_deprecated_arg) << "-mcode-object-v3"
|
||||
<< "-mcode-object-version=3";
|
||||
}
|
||||
|
||||
static llvm::opt::Arg *
|
||||
getAMDGPUCodeObjectArgument(const Driver &D, const llvm::opt::ArgList &Args) {
|
||||
// The last of -mcode-object-v3, -mno-code-object-v3 and
|
||||
// -mcode-object-version=<version> wins.
|
||||
if (auto *CodeObjArg =
|
||||
Args.getLastArg(options::OPT_mcode_object_v3_legacy,
|
||||
options::OPT_mno_code_object_v3_legacy,
|
||||
options::OPT_mcode_object_version_EQ)) {
|
||||
return Args.getLastArg(options::OPT_mcode_object_v3_legacy,
|
||||
options::OPT_mno_code_object_v3_legacy,
|
||||
options::OPT_mcode_object_version_EQ);
|
||||
}
|
||||
|
||||
void tools::checkAMDGPUCodeObjectVersion(const Driver &D,
|
||||
const llvm::opt::ArgList &Args) {
|
||||
const unsigned MinCodeObjVer = 2;
|
||||
const unsigned MaxCodeObjVer = 4;
|
||||
|
||||
// Emit warnings for legacy options even if they are overridden.
|
||||
if (Args.hasArg(options::OPT_mno_code_object_v3_legacy))
|
||||
D.Diag(diag::warn_drv_deprecated_arg) << "-mno-code-object-v3"
|
||||
<< "-mcode-object-version=2";
|
||||
|
||||
if (Args.hasArg(options::OPT_mcode_object_v3_legacy))
|
||||
D.Diag(diag::warn_drv_deprecated_arg) << "-mcode-object-v3"
|
||||
<< "-mcode-object-version=3";
|
||||
|
||||
if (auto *CodeObjArg = getAMDGPUCodeObjectArgument(D, Args)) {
|
||||
if (CodeObjArg->getOption().getID() ==
|
||||
options::OPT_mcode_object_version_EQ) {
|
||||
unsigned CodeObjVer = MaxCodeObjVer;
|
||||
auto Remnant =
|
||||
StringRef(CodeObjArg->getValue()).getAsInteger(0, CodeObjVer);
|
||||
if (Remnant || CodeObjVer < MinCodeObjVer || CodeObjVer > MaxCodeObjVer)
|
||||
D.Diag(diag::err_drv_invalid_int_value)
|
||||
<< CodeObjArg->getAsString(Args) << CodeObjArg->getValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unsigned tools::getAMDGPUCodeObjectVersion(const Driver &D,
|
||||
const llvm::opt::ArgList &Args) {
|
||||
unsigned CodeObjVer = 4; // default
|
||||
if (auto *CodeObjArg = getAMDGPUCodeObjectArgument(D, Args)) {
|
||||
if (CodeObjArg->getOption().getID() ==
|
||||
options::OPT_mno_code_object_v3_legacy) {
|
||||
CodeObjVer = 2;
|
||||
|
@ -1603,12 +1620,7 @@ unsigned tools::getOrCheckAMDGPUCodeObjectVersion(
|
|||
options::OPT_mcode_object_v3_legacy) {
|
||||
CodeObjVer = 3;
|
||||
} else {
|
||||
auto Remnant =
|
||||
StringRef(CodeObjArg->getValue()).getAsInteger(0, CodeObjVer);
|
||||
if (Diagnose &&
|
||||
(Remnant || CodeObjVer < MinCodeObjVer || CodeObjVer > MaxCodeObjVer))
|
||||
D.Diag(diag::err_drv_invalid_int_value)
|
||||
<< CodeObjArg->getAsString(Args) << CodeObjArg->getValue();
|
||||
StringRef(CodeObjArg->getValue()).getAsInteger(0, CodeObjVer);
|
||||
}
|
||||
}
|
||||
return CodeObjVer;
|
||||
|
|
|
@ -138,9 +138,11 @@ void addMultilibFlag(bool Enabled, const char *const Flag,
|
|||
void addX86AlignBranchArgs(const Driver &D, const llvm::opt::ArgList &Args,
|
||||
llvm::opt::ArgStringList &CmdArgs, bool IsLTO);
|
||||
|
||||
unsigned getOrCheckAMDGPUCodeObjectVersion(const Driver &D,
|
||||
const llvm::opt::ArgList &Args,
|
||||
bool Diagnose = false);
|
||||
void checkAMDGPUCodeObjectVersion(const Driver &D,
|
||||
const llvm::opt::ArgList &Args);
|
||||
|
||||
unsigned getAMDGPUCodeObjectVersion(const Driver &D,
|
||||
const llvm::opt::ArgList &Args);
|
||||
|
||||
void addMachineOutlinerArgs(const Driver &D, const llvm::opt::ArgList &Args,
|
||||
llvm::opt::ArgStringList &CmdArgs,
|
||||
|
|
|
@ -112,7 +112,7 @@ void AMDGCN::constructHIPFatbinCommand(Compilation &C, const JobAction &JA,
|
|||
// for backward compatibility. For code object version 4 and greater, the
|
||||
// offload kind in bundle ID is 'hipv4'.
|
||||
std::string OffloadKind = "hip";
|
||||
if (getOrCheckAMDGPUCodeObjectVersion(C.getDriver(), Args) >= 4)
|
||||
if (getAMDGPUCodeObjectVersion(C.getDriver(), Args) >= 4)
|
||||
OffloadKind = OffloadKind + "v4";
|
||||
for (const auto &II : Inputs) {
|
||||
const auto* A = II.getAction();
|
||||
|
|
Loading…
Reference in New Issue