[PATCH] R600/SI: Implement getLdStBaseRegImmOfs for LDS

Matt Arsenault Matthew.Arsenault at amd.com
Mon Jul 28 16:59:01 PDT 2014


Use getNamedOperandIdx, implement for other address spaces

http://reviews.llvm.org/D4686

Files:
  lib/Target/R600/SIInstrInfo.cpp
  lib/Target/R600/SIInstrInfo.h

Index: lib/Target/R600/SIInstrInfo.cpp
===================================================================
--- lib/Target/R600/SIInstrInfo.cpp
+++ lib/Target/R600/SIInstrInfo.cpp
@@ -32,6 +32,56 @@
 // TargetInstrInfo callbacks
 //===----------------------------------------------------------------------===//
 
+bool SIInstrInfo::getLdStBaseRegImmOfs(MachineInstr *LdSt,
+                                       unsigned &BaseReg, unsigned &Offset,
+                                       const TargetRegisterInfo *TRI) const {
+  unsigned Opc = LdSt->getOpcode();
+  if (isDS(Opc)) {
+    int OffsetIdx = AMDGPU::getNamedOperandIdx(Opc, AMDGPU::OpName::offset);
+    if (OffsetIdx == -1) {
+      // The 2 offset instructions use offset0 and offset1 instead. This
+      // function only handles simple instructions with only a single offset, so
+      // we ignore them.
+      return false;
+    }
+
+    int AddrIdx = AMDGPU::getNamedOperandIdx(Opc, AMDGPU::OpName::addr);
+
+    BaseReg = LdSt->getOperand(AddrIdx).getReg();
+    Offset = LdSt->getOperand(OffsetIdx).getImm();
+    return true;
+  }
+
+  if (isMUBUF(Opc) || isMTBUF(Opc)) {
+    if (AMDGPU::getNamedOperandIdx(Opc, AMDGPU::OpName::soffset) != -1)
+      return false;
+
+    int VaddrIdx = AMDGPU::getNamedOperandIdx(Opc, AMDGPU::OpName::vaddr);
+    if (VaddrIdx == -1)
+      return false;
+
+    int OffsetIdx = AMDGPU::getNamedOperandIdx(Opc, AMDGPU::OpName::offset);
+
+    BaseReg = LdSt->getOperand(VaddrIdx).getReg();
+    Offset = LdSt->getOperand(OffsetIdx).getImm();
+    return true;
+  }
+
+  if (isSMRD(Opc)) {
+    int OffsetIdx = AMDGPU::getNamedOperandIdx(Opc, AMDGPU::OpName::offset);
+    if (OffsetIdx == -1)
+      return false;
+
+    int SBaseIdx = AMDGPU::getNamedOperandIdx(Opc, AMDGPU::OpName::sbase);
+
+    BaseReg = LdSt->getOperand(SBaseIdx).getReg();
+    Offset = LdSt->getOperand(OffsetIdx).getImm();
+    return true;
+  }
+
+  return false;
+}
+
 void
 SIInstrInfo::copyPhysReg(MachineBasicBlock &MBB,
                          MachineBasicBlock::iterator MI, DebugLoc DL,
Index: lib/Target/R600/SIInstrInfo.h
===================================================================
--- lib/Target/R600/SIInstrInfo.h
+++ lib/Target/R600/SIInstrInfo.h
@@ -62,6 +62,10 @@
     return RI;
   }
 
+  bool getLdStBaseRegImmOfs(MachineInstr *LdSt,
+                            unsigned &BaseReg, unsigned &Offset,
+                            const TargetRegisterInfo *TRI) const final;
+
   void copyPhysReg(MachineBasicBlock &MBB,
                    MachineBasicBlock::iterator MI, DebugLoc DL,
                    unsigned DestReg, unsigned SrcReg,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D4686.11965.patch
Type: text/x-patch
Size: 2649 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140728/cdf94230/attachment.bin>


More information about the llvm-commits mailing list