[llvm] [MC] Add support for -mcpu=native. (PR #159414)

Cameron McInally via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 19 07:13:08 PDT 2025


================
@@ -459,14 +459,26 @@ int main(int argc, char **argv) {
   MAI->setCommentColumn(CommentColumn);
 
   // Package up features to be passed to target/subtarget
+  SubtargetFeatures Features;
   std::string FeaturesStr;
+
+  // Replace -mcpu=native with Host CPU and features.
+  if (MCPU == "native") {
+    MCPU = std::string(llvm::sys::getHostCPUName());
+
+    llvm::StringMap<bool> TargetFeatures = llvm::sys::getHostCPUFeatures();
+    for (auto const &[FeatureName, IsSupported] : TargetFeatures)
+      Features.AddFeature(FeatureName, IsSupported);
+  }
+
+  // Handle features passed to target/subtarget.
   if (MAttrs.size()) {
----------------
mcinally wrote:

Good catch! Addressed now.

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


More information about the llvm-commits mailing list