diff options
Diffstat (limited to 'contrib/llvm-project/clang/lib/Basic/Targets/RISCV.cpp')
| -rw-r--r-- | contrib/llvm-project/clang/lib/Basic/Targets/RISCV.cpp | 93 |
1 files changed, 40 insertions, 53 deletions
diff --git a/contrib/llvm-project/clang/lib/Basic/Targets/RISCV.cpp b/contrib/llvm-project/clang/lib/Basic/Targets/RISCV.cpp index fb312b6cf26e..c71b2e9eeb6c 100644 --- a/contrib/llvm-project/clang/lib/Basic/Targets/RISCV.cpp +++ b/contrib/llvm-project/clang/lib/Basic/Targets/RISCV.cpp @@ -154,7 +154,7 @@ void RISCVTargetInfo::getTargetDefines(const LangOptions &Opts, else Builder.defineMacro("__riscv_float_abi_soft"); - if (ABIName == "ilp32e") + if (ABIName == "ilp32e" || ABIName == "lp64e") Builder.defineMacro("__riscv_abi_rve"); Builder.defineMacro("__riscv_arch_test"); @@ -214,6 +214,13 @@ void RISCVTargetInfo::getTargetDefines(const LangOptions &Opts, Builder.defineMacro("__riscv_misaligned_fast"); else Builder.defineMacro("__riscv_misaligned_avoid"); + + if (ISAInfo->hasExtension("e")) { + if (Is64Bit) + Builder.defineMacro("__riscv_64e"); + else + Builder.defineMacro("__riscv_32e"); + } } static constexpr Builtin::Info BuiltinInfo[] = { @@ -234,39 +241,6 @@ ArrayRef<Builtin::Info> RISCVTargetInfo::getTargetBuiltins() const { clang::RISCV::LastTSBuiltin - Builtin::FirstTSBuiltin); } -static std::vector<std::string> -collectNonISAExtFeature(ArrayRef<std::string> FeaturesNeedOverride, int XLen) { - std::vector<std::string> NonISAExtFeatureVec; - - auto IsNonISAExtFeature = [](const std::string &Feature) { - assert(Feature.size() > 1 && (Feature[0] == '+' || Feature[0] == '-')); - StringRef Ext = StringRef(Feature).drop_front(); // drop the +/- - return !llvm::RISCVISAInfo::isSupportedExtensionFeature(Ext); - }; - llvm::copy_if(FeaturesNeedOverride, std::back_inserter(NonISAExtFeatureVec), - IsNonISAExtFeature); - - return NonISAExtFeatureVec; -} - -static std::vector<std::string> -resolveTargetAttrOverride(const std::vector<std::string> &FeaturesVec, - int XLen) { - auto I = llvm::find(FeaturesVec, "__RISCV_TargetAttrNeedOverride"); - if (I == FeaturesVec.end()) - return FeaturesVec; - - ArrayRef<std::string> FeaturesNeedOverride(&*FeaturesVec.begin(), &*I); - std::vector<std::string> NonISAExtFeature = - collectNonISAExtFeature(FeaturesNeedOverride, XLen); - - std::vector<std::string> ResolvedFeature(++I, FeaturesVec.end()); - ResolvedFeature.insert(ResolvedFeature.end(), NonISAExtFeature.begin(), - NonISAExtFeature.end()); - - return ResolvedFeature; -} - bool RISCVTargetInfo::initFeatureMap( llvm::StringMap<bool> &Features, DiagnosticsEngine &Diags, StringRef CPU, const std::vector<std::string> &FeaturesVec) const { @@ -280,10 +254,27 @@ bool RISCVTargetInfo::initFeatureMap( Features["32bit"] = true; } - std::vector<std::string> NewFeaturesVec = - resolveTargetAttrOverride(FeaturesVec, XLen); + // If a target attribute specified a full arch string, override all the ISA + // extension target features. + const auto I = llvm::find(FeaturesVec, "__RISCV_TargetAttrNeedOverride"); + if (I != FeaturesVec.end()) { + std::vector<std::string> OverrideFeatures(std::next(I), FeaturesVec.end()); + + // Add back any non ISA extension features, e.g. +relax. + auto IsNonISAExtFeature = [](StringRef Feature) { + assert(Feature.size() > 1 && (Feature[0] == '+' || Feature[0] == '-')); + StringRef Ext = Feature.substr(1); // drop the +/- + return !llvm::RISCVISAInfo::isSupportedExtensionFeature(Ext); + }; + llvm::copy_if(llvm::make_range(FeaturesVec.begin(), I), + std::back_inserter(OverrideFeatures), IsNonISAExtFeature); - auto ParseResult = llvm::RISCVISAInfo::parseFeatures(XLen, NewFeaturesVec); + return TargetInfo::initFeatureMap(Features, Diags, CPU, OverrideFeatures); + } + + // Otherwise, parse the features and add any implied extensions. + std::vector<std::string> AllFeatures = FeaturesVec; + auto ParseResult = llvm::RISCVISAInfo::parseFeatures(XLen, FeaturesVec); if (!ParseResult) { std::string Buffer; llvm::raw_string_ostream OutputErrMsg(Buffer); @@ -294,21 +285,9 @@ bool RISCVTargetInfo::initFeatureMap( return false; } - // RISCVISAInfo makes implications for ISA features - std::vector<std::string> ImpliedFeatures = (*ParseResult)->toFeatures(); - - // parseFeatures normalizes the feature set by dropping any explicit - // negatives, and non-extension features. We need to preserve the later - // for correctness and want to preserve the former for consistency. - for (auto &Feature : NewFeaturesVec) { - StringRef ExtName = Feature; - assert(ExtName.size() > 1 && (ExtName[0] == '+' || ExtName[0] == '-')); - ExtName = ExtName.drop_front(1); // Drop '+' or '-' - if (!llvm::is_contained(ImpliedFeatures, ("+" + ExtName).str()) && - !llvm::is_contained(ImpliedFeatures, ("-" + ExtName).str())) - ImpliedFeatures.push_back(Feature); - } - return TargetInfo::initFeatureMap(Features, Diags, CPU, ImpliedFeatures); + // Append all features, not just new ones, so we override any negatives. + llvm::append_range(AllFeatures, (*ParseResult)->toFeatures()); + return TargetInfo::initFeatureMap(Features, Diags, CPU, AllFeatures); } std::optional<std::pair<unsigned, unsigned>> @@ -378,6 +357,11 @@ bool RISCVTargetInfo::handleTargetFeatures(std::vector<std::string> &Features, if (llvm::is_contained(Features, "+experimental")) HasExperimental = true; + if (ABI == "ilp32e" && ISAInfo->hasExtension("d")) { + Diags.Report(diag::err_invalid_feature_combination) + << "ILP32E cannot be used with the D ISA extension"; + return false; + } return true; } @@ -412,7 +396,10 @@ static void handleFullArchString(StringRef FullArchStr, // Forward the invalid FullArchStr. Features.push_back("+" + FullArchStr.str()); } else { - std::vector<std::string> FeatStrings = (*RII)->toFeatures(); + // Append a full list of features, including any negative extensions so that + // we override the CPU's features. + std::vector<std::string> FeatStrings = + (*RII)->toFeatures(/* AddAllExtensions */ true); Features.insert(Features.end(), FeatStrings.begin(), FeatStrings.end()); } } |
