[clang] [llvm] [PowerPC] Support local-dynamic TLS relocation on AIX (PR #66316)

Amy Kwan via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 1 21:01:16 PST 2024


================
@@ -145,9 +164,89 @@ namespace {
                                                               .addImm(0);
 
         if (IsAIX) {
-          // The variable offset and region handle are copied in r4 and r3. The
-          // copies are followed by GETtlsADDR32AIX/GETtlsADDR64AIX.
-          if (!IsTLSTPRelMI) {
+          if (IsTLSLDAIXMI) {
+            // The relative order between the LoadOffset at toc node, and the
+            // .__tls_get_mod node is being tuned here. It is better to put the
+            // LoadOffset at toc node after the call, since the LoadOffset at toc node
+            // can use clobbers r4/r5. Search for the pattern of two Load at toc
+            // nodes, and then move the LoadOffset at toc node right before the
+            // node that uses the OutReg of the .__tls_get_mod node.
+            unsigned LDTocOp =
+                Is64Bit ? (IsLargeModel ? PPC::LDtocL : PPC::LDtoc)
+                        : (IsLargeModel ? PPC::LWZtocL : PPC::LWZtoc);
+            if (!RegInfo.use_empty(OutReg)) {
+              std::set<MachineInstr *> Uses;
+              // Collect all instructions that use the OutReg.
+              for (MachineOperand &MO : RegInfo.use_operands(OutReg))
+                Uses.insert(MO.getParent());
+              // Find the first user (e.g.: lwax/stfdx) within the current BB.
+              MachineBasicBlock::iterator UseIter = MBB.begin();
+              for (MachineBasicBlock::iterator IE = MBB.end(); UseIter != IE;
+                   ++UseIter)
+                if (Uses.count(&*UseIter))
+                  break;
+
+              // Got some work to do when UseIter pointing to valid node. Check
+              // the pattern and do the movement if match.
----------------
amy-kwan wrote:

Maybe we can say this? If this is accurate.
```suggestion
              // Additional handling is required when UserIter (the first user of OutReg) is pointing to a valid node. Check
              // the pattern and do the movement if the pattern matches.
```

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


More information about the llvm-commits mailing list