[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:21 PDT 2024


================
@@ -558,6 +558,39 @@ static bool hasTocDataAttr(SDValue Val, unsigned PointerSize) {
   return true;
 }
 
+static CodeModel::Model getCodeModel(const PPCSubtarget &Subtarget,
+                                     const TargetMachine &TM,
+                                     const SDNode *Node) {
+  // If there isn't an attribute to override the module code model
+  // this will be the effective code model.
+  CodeModel::Model ModuleModel = TM.getCodeModel();
+
+  // Initially support per global code model for AIX only.
+  if (!Subtarget.isAIXABI())
+    return ModuleModel;
+
+  // If the operand is not a global address there is no
+  // GlobalVariable to query for an attribute.
+  SDValue Operand = Node->getOperand(0);
+  if (!isa<GlobalAddressSDNode>(Operand))
+    return ModuleModel;
+
+  const GlobalValue *GV = cast<GlobalAddressSDNode>(Operand)->getGlobal();
+  if (!GV || !isa<GlobalVariable>(GV))
+    return ModuleModel;
+
+  std::optional<CodeModel::Model> MaybeCodeModel =
+      dyn_cast<GlobalVariable>(GV)->getCodeModel();
+  if (MaybeCodeModel) {
+    CodeModel::Model CM = *MaybeCodeModel;
+    assert((CM == CodeModel::Small || CM == CodeModel::Large) &&
+           "invalid code model for AIX");
+    return CM;
+  }
+
+  return ModuleModel;
----------------
diggerlin wrote:

nit : we can change the code from line 574 ~591 to 
```
if (auto *GValue = dyn_cast<GlobalAddressSDNode>(Node->getOperand(0)){
  if(auto *GVar = dyn_cast<GlobalVariable>(GV)){
      std::optional<CodeModel::Model> MaybeCodeModel =GV->getCodeModel();
  if (MaybeCodeModel) {
    CodeModel::Model CM = *MaybeCodeModel;
    assert((CM == CodeModel::Small || CM == CodeModel::Large) &&
           "invalid code model for AIX");
    return CM;
    } 
 }
 }
return ModuleModel;
```

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


More information about the llvm-commits mailing list