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

Wang Pengcheng via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 13 21:34:45 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) &&
----------------
wangpc-pp wrote:

Yes, I think we will check that (in `RISCVISAInfo::checkDependency()`).
```shell
~/workspace# clang -march=rv64imafdc_zdinx -### -
clang: error: -E or -x required when input is from standard input
clang: error: invalid arch name 'rv64imafdc_zdinx', 'f' and 'zfinx' extensions are incompatible
```

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


More information about the llvm-commits mailing list