Ga1axy0 commented on code in PR #19877:
URL: https://github.com/apache/tvm/pull/19877#discussion_r3462287219


##########
src/target/llvm/llvm_instance.cc:
##########
@@ -199,13 +277,26 @@ LLVMTargetInfo::LLVMTargetInfo(LLVMInstance& instance,
   if (triple_.empty() || triple_ == "default") {
     triple_ = llvm::sys::getDefaultTargetTriple();
   }
+  bool has_explicit_mcpu = target.Get("mcpu").has_value();
   cpu_ = 
Downcast<ffi::String>(target.Get("mcpu").value_or(ffi::String(defaults::cpu)));
 
+  bool has_explicit_mattr = false;
   if (const auto& v = 
Downcast<ffi::Optional<ffi::Array<ffi::String>>>(target.Get("mattr"))) {
+    has_explicit_mattr = true;
     for (const ffi::String& s : v.value()) {
       attrs_.push_back(s);
     }
   }
+
+  auto arch = llvm::Triple(triple_).getArch();
+  if (!has_explicit_mattr && !has_explicit_mcpu &&
+      (arch == llvm::Triple::riscv32 || arch == llvm::Triple::riscv64)) {
+    std::vector<std::string> detected_attrs = DetectLocalRISCVAttrs();
+    for (const std::string& attr : detected_attrs) {
+      attrs_.push_back(attr);
+    }
+  }

Review Comment:
   I agree that applying host-detected features should only happen when the 
target is the host machine.
   
   I updated the logic to compare the target triple against LLVM's default host 
triple before using `riscv_hwprobe`. The detected RISC-V attributes are now 
only applied when `mcpu` and `mattr` are both unspecified, the target 
architecture matches the host architecture, and the target OS matches the host 
OS.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to