[llvm] [AIX] Support per global code model. (PR #79202)

zhijian lin via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 11 11:13:20 PDT 2024


================
@@ -474,6 +474,55 @@ static void collectTOCStats(PPCAsmPrinter::TOCEntryType Type) {
   }
 }
 
+static CodeModel::Model getCodeModel(const PPCSubtarget &S,
+                                     const TargetMachine &TM,
+                                     const MachineOperand &MO) {
+  CodeModel::Model ModuleModel = TM.getCodeModel();
+  // Per global code model is only supported on AIX.
+  if (!S.isAIXABI())
+    return ModuleModel;
+
+  // If the operand is not a global address then there is no
+  // global variable to carry an attribute.
+  if (!(MO.getType() == MachineOperand::MO_GlobalAddress))
+    return ModuleModel;
+
+  const GlobalValue *GV = MO.getGlobal();
+  assert(GV && "expected global for MO_GlobalAddress");
+
+  if (!isa<GlobalVariable>(GV))
+    return ModuleModel;
+
+  std::optional<CodeModel::Model> MaybeCodeModel =
+      cast<GlobalVariable>(GV)->getCodeModel();
+  if (MaybeCodeModel)
+    return *MaybeCodeModel;
+
+  return ModuleModel;
+}
+
+static std::optional<CodeModel::Model>
+getPerGlobalCodeModel(const GlobalValue *GV) {
+  // Symbols that aren't global variables cannot have the attribute.
+  if (!isa<GlobalVariable>(GV))
+    return std::nullopt;
+
+  return cast<GlobalVariable>(GV)->getCodeModel();
+}
----------------
diggerlin wrote:

nit: the function is small function and only be used in function `doInitialization` , suggest to lambda function.

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


More information about the llvm-commits mailing list