[llvm] [PowerPC][AIX] Emit PowerPC version for XCOFF (PR #95510)

Qiu Chaofan via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 21 03:13:31 PDT 2024


================
@@ -514,9 +514,27 @@ bool AsmPrinter::doInitialization(Module &M) {
     }
   }
 
-  // On AIX, emit bytes for llvm.commandline metadata after .file so that the
-  // C_INFO symbol is preserved if any csect is kept by the linker.
   if (TM.getTargetTriple().isOSBinFormatXCOFF()) {
+    // Emit .machine directive on AIX.
+    StringRef TargetCPU;
+    // Walk through the target-cpu attribute of functions and use the newest
+    // level as the CPU of the module.
+    for (auto &F : M) {
+      StringRef FunCPU = TM.getSubtargetImpl(F)->getCPU();
+      if (XCOFF::getCpuID(FunCPU) > XCOFF::getCpuID(TargetCPU))
+        TargetCPU = FunCPU;
+    }
+    // If there is no "target-cpu" attr in functions, take the "-mcpu" value.
+    if (TargetCPU.empty()) {
+      if (!TM.getTargetCPU().empty())
+        TargetCPU = TM.getTargetCPU();
+      else
+        TargetCPU = "any";
+    }
+    OutStreamer->emitMachineDirective(TargetCPU);
----------------
ecnelises wrote:

AIX system `as` does not recognize `power*` names, can we assume here the target CPU is only supported form?

> Valid values are:COM PWR PWR2 PPC 601 603 604 PPC64 620 A35 PWR4 PWR5 PWR5X 970 PPC970 PWR6 PWR6E PWR7 PWR8 PWR9 PWR10 ANY

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


More information about the llvm-commits mailing list