[clang][PATCH][nfc] Refactor TargetInfo::adjust to pass DiagnosticsEngine to allow diagnostics on target-unsupported options

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D104729
This commit is contained in:
Melanie Blower 2021-06-08 16:55:54 -04:00
parent 931e95687d
commit 2c02b0c3f4
13 changed files with 18 additions and 17 deletions

View File

@ -1162,7 +1162,7 @@ public:
/// Apply changes to the target information with respect to certain /// Apply changes to the target information with respect to certain
/// language options which change the target configuration and adjust /// language options which change the target configuration and adjust
/// the language based on the target options where applicable. /// the language based on the target options where applicable.
virtual void adjust(LangOptions &Opts); virtual void adjust(DiagnosticsEngine &Diags, LangOptions &Opts);
/// Adjust target options based on codegen options. /// Adjust target options based on codegen options.
virtual void adjustTargetOptions(const CodeGenOptions &CGOpts, virtual void adjustTargetOptions(const CodeGenOptions &CGOpts,

View File

@ -346,7 +346,7 @@ bool TargetInfo::isTypeSigned(IntType T) {
/// Apply changes to the target information with respect to certain /// Apply changes to the target information with respect to certain
/// language options which change the target configuration and adjust /// language options which change the target configuration and adjust
/// the language based on the target options where applicable. /// the language based on the target options where applicable.
void TargetInfo::adjust(LangOptions &Opts) { void TargetInfo::adjust(DiagnosticsEngine &Diags, LangOptions &Opts) {
if (Opts.NoBitFieldTypeAlign) if (Opts.NoBitFieldTypeAlign)
UseBitFieldTypeAlignment = false; UseBitFieldTypeAlignment = false;

View File

@ -358,8 +358,8 @@ AMDGPUTargetInfo::AMDGPUTargetInfo(const llvm::Triple &Triple,
MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64; MaxAtomicPromoteWidth = MaxAtomicInlineWidth = 64;
} }
void AMDGPUTargetInfo::adjust(LangOptions &Opts) { void AMDGPUTargetInfo::adjust(DiagnosticsEngine &Diags, LangOptions &Opts) {
TargetInfo::adjust(Opts); TargetInfo::adjust(Diags, Opts);
// ToDo: There are still a few places using default address space as private // ToDo: There are still a few places using default address space as private
// address space in OpenCL, which needs to be cleaned up, then Opts.OpenCL // address space in OpenCL, which needs to be cleaned up, then Opts.OpenCL
// can be removed from the following line. // can be removed from the following line.

View File

@ -93,7 +93,7 @@ public:
void setAddressSpaceMap(bool DefaultIsPrivate); void setAddressSpaceMap(bool DefaultIsPrivate);
void adjust(LangOptions &Opts) override; void adjust(DiagnosticsEngine &Diags, LangOptions &Opts) override;
uint64_t getPointerWidthV(unsigned AddrSpace) const override { uint64_t getPointerWidthV(unsigned AddrSpace) const override {
if (isR600(getTriple())) if (isR600(getTriple()))

View File

@ -614,10 +614,10 @@ void PPCTargetInfo::fillValidCPUList(SmallVectorImpl<StringRef> &Values) const {
Values.append(std::begin(ValidCPUNames), std::end(ValidCPUNames)); Values.append(std::begin(ValidCPUNames), std::end(ValidCPUNames));
} }
void PPCTargetInfo::adjust(LangOptions &Opts) { void PPCTargetInfo::adjust(DiagnosticsEngine &Diags, LangOptions &Opts) {
if (HasAltivec) if (HasAltivec)
Opts.AltiVec = 1; Opts.AltiVec = 1;
TargetInfo::adjust(Opts); TargetInfo::adjust(Diags, Opts);
if (LongDoubleFormat != &llvm::APFloat::IEEEdouble()) if (LongDoubleFormat != &llvm::APFloat::IEEEdouble())
LongDoubleFormat = Opts.PPCIEEELongDouble LongDoubleFormat = Opts.PPCIEEELongDouble
? &llvm::APFloat::IEEEquad() ? &llvm::APFloat::IEEEquad()

View File

@ -89,7 +89,7 @@ public:
} }
// Set the language option for altivec based on our value. // Set the language option for altivec based on our value.
void adjust(LangOptions &Opts) override; void adjust(DiagnosticsEngine &Diags, LangOptions &Opts) override;
// Note: GCC recognizes the following additional cpus: // Note: GCC recognizes the following additional cpus:
// 401, 403, 405, 405fp, 440fp, 464, 464fp, 476, 476fp, 505, 740, 801, // 401, 403, 405, 405fp, 440fp, 464, 464fp, 476, 476fp, 505, 740, 801,

View File

@ -135,8 +135,8 @@ public:
AddrSpaceMap = DefaultIsGeneric ? &SPIRDefIsGenMap : &SPIRDefIsPrivMap; AddrSpaceMap = DefaultIsGeneric ? &SPIRDefIsGenMap : &SPIRDefIsPrivMap;
} }
void adjust(LangOptions &Opts) override { void adjust(DiagnosticsEngine &Diags, LangOptions &Opts) override {
TargetInfo::adjust(Opts); TargetInfo::adjust(Diags, Opts);
// FIXME: SYCL specification considers unannotated pointers and references // FIXME: SYCL specification considers unannotated pointers and references
// to be pointing to the generic address space. See section 5.9.3 of // to be pointing to the generic address space. See section 5.9.3 of
// SYCL 2020 specification. // SYCL 2020 specification.

View File

@ -234,7 +234,8 @@ ArrayRef<Builtin::Info> WebAssemblyTargetInfo::getTargetBuiltins() const {
Builtin::FirstTSBuiltin); Builtin::FirstTSBuiltin);
} }
void WebAssemblyTargetInfo::adjust(LangOptions &Opts) { void WebAssemblyTargetInfo::adjust(DiagnosticsEngine &Diags,
LangOptions &Opts) {
// If the Atomics feature isn't available, turn off POSIXThreads and // If the Atomics feature isn't available, turn off POSIXThreads and
// ThreadModel, so that we don't predefine _REENTRANT or __STDCPP_THREADS__. // ThreadModel, so that we don't predefine _REENTRANT or __STDCPP_THREADS__.
if (!HasAtomics) { if (!HasAtomics) {

View File

@ -138,7 +138,7 @@ private:
bool hasProtectedVisibility() const override { return false; } bool hasProtectedVisibility() const override { return false; }
void adjust(LangOptions &Opts) override; void adjust(DiagnosticsEngine &Diags, LangOptions &Opts) override;
}; };
class LLVM_LIBRARY_VISIBILITY WebAssembly32TargetInfo class LLVM_LIBRARY_VISIBILITY WebAssembly32TargetInfo

View File

@ -588,7 +588,7 @@ private:
// //
// FIXME: We shouldn't need to do this, the target should be immutable once // FIXME: We shouldn't need to do this, the target should be immutable once
// created. This complexity should be lifted elsewhere. // created. This complexity should be lifted elsewhere.
Target->adjust(LangOpt); Target->adjust(PP.getDiagnostics(), LangOpt);
// Initialize the preprocessor. // Initialize the preprocessor.
PP.Initialize(*Target); PP.Initialize(*Target);

View File

@ -142,7 +142,7 @@ bool CompilerInstance::createTarget() {
// Inform the target of the language options. // Inform the target of the language options.
// FIXME: We shouldn't need to do this, the target should be immutable once // FIXME: We shouldn't need to do this, the target should be immutable once
// created. This complexity should be lifted elsewhere. // created. This complexity should be lifted elsewhere.
getTarget().adjust(getLangOpts()); getTarget().adjust(getDiagnostics(), getLangOpts());
// Adjust target options based on codegen options. // Adjust target options based on codegen options.
getTarget().adjustTargetOptions(getCodeGenOpts(), getTargetOpts()); getTarget().adjustTargetOptions(getCodeGenOpts(), getTargetOpts());
@ -457,7 +457,7 @@ void CompilerInstance::createPreprocessor(TranslationUnitKind TUKind) {
getSourceManager(), *HeaderInfo, *this, getSourceManager(), *HeaderInfo, *this,
/*IdentifierInfoLookup=*/nullptr, /*IdentifierInfoLookup=*/nullptr,
/*OwnsHeaderSearch=*/true, TUKind); /*OwnsHeaderSearch=*/true, TUKind);
getTarget().adjust(getLangOpts()); getTarget().adjust(getDiagnostics(), getLangOpts());
PP->Initialize(getTarget(), getAuxTarget()); PP->Initialize(getTarget(), getAuxTarget());
if (PPOpts.DetailedRecord) if (PPOpts.DetailedRecord)

View File

@ -110,7 +110,7 @@ CreateCI(const llvm::opt::ArgStringList &Argv) {
"Initialization failed. " "Initialization failed. "
"Target is missing"); "Target is missing");
Clang->getTarget().adjust(Clang->getLangOpts()); Clang->getTarget().adjust(Clang->getDiagnostics(), Clang->getLangOpts());
return std::move(Clang); return std::move(Clang);
} }

View File

@ -208,7 +208,7 @@ std::unique_ptr<CompilerInstance> BuildCompilerInstance() {
TargetInfo *TI = TargetInfo::CreateTargetInfo( TargetInfo *TI = TargetInfo::CreateTargetInfo(
Ins->getDiagnostics(), Ins->getInvocation().TargetOpts); Ins->getDiagnostics(), Ins->getInvocation().TargetOpts);
Ins->setTarget(TI); Ins->setTarget(TI);
Ins->getTarget().adjust(Ins->getLangOpts()); Ins->getTarget().adjust(Ins->getDiagnostics(), Ins->getLangOpts());
Ins->createFileManager(); Ins->createFileManager();
Ins->createSourceManager(Ins->getFileManager()); Ins->createSourceManager(Ins->getFileManager());
Ins->createPreprocessor(TU_Complete); Ins->createPreprocessor(TU_Complete);