[llvm] [RISCV] Use 'riscv-isa' module flag to set ELF flags and attributes. (PR #85155)

Alex Bradbury via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 14 08:08:40 PDT 2024


================
@@ -385,8 +385,32 @@ void RISCVAsmPrinter::emitStartOfAsmFile(Module &M) {
   if (const MDString *ModuleTargetABI =
           dyn_cast_or_null<MDString>(M.getModuleFlag("target-abi")))
     RTS.setTargetABI(RISCVABI::getTargetABI(ModuleTargetABI->getString()));
+
+  MCSubtargetInfo SubtargetInfo = *TM.getMCSubtargetInfo();
+
+  // Use module flag to update feature bits.
+  if (auto *MD = dyn_cast_or_null<MDNode>(M.getModuleFlag("riscv-isa"))) {
+    for (auto &ISA : MD->operands()) {
+      if (auto *ISAString = dyn_cast_or_null<MDString>(ISA)) {
+        auto ParseResult = llvm::RISCVISAInfo::parseArchString(
+            ISAString->getString(), /*EnableExperimentalExtension=*/true,
+            /*ExperimentalExtensionVersionCheck=*/true);
+        if (!errorToBool(ParseResult.takeError())) {
+          auto &ISAInfo = *ParseResult;
+          for (const auto &Feature : RISCVFeatureKV) {
+            if (ISAInfo->hasExtension(Feature.Key) &&
----------------
asb wrote:

My personal view is that if we can stop the user from doing something that's _definitely_ nonsensical then it's nice to do so, but it needn't be blocking unless we think it's likely to be a common error. We have had issues in this general area of error checking being overzealous leading to compatibility issues, so I'd rather we fail to catch some silly things vs incorrectly erroring on reasonable things and leaving users stuck until a toolchain update.

https://github.com/llvm/llvm-project/pull/85155


More information about the llvm-commits mailing list