Index: include/llvm/Target/TargetRegisterInfo.h
===================================================================
--- include/llvm/Target/TargetRegisterInfo.h	(revision 131942)
+++ include/llvm/Target/TargetRegisterInfo.h	(working copy)
@@ -566,6 +566,15 @@
     return b;
   }
 
+  /// getNativeRegIndex - Return the native register index corresponding to an
+  /// LLVM register index.
+  ///
+  /// On x86, for example, passing X86::ESP returns 4 (the native index of
+  /// the ESP physical register).
+  virtual unsigned getNativeRegIndex(unsigned i) const {
+    return i;
+  }
+
   //===--------------------------------------------------------------------===//
   // Register Class Information
   //
Index: lib/Target/X86/X86RegisterInfo.cpp
===================================================================
--- lib/Target/X86/X86RegisterInfo.cpp	(revision 131942)
+++ lib/Target/X86/X86RegisterInfo.cpp	(working copy)
@@ -188,6 +188,25 @@
   }
 }
 
+unsigned
+X86RegisterInfo::getNativeRegIndex(unsigned i) const {
+  unsigned reg = getX86RegNum(i);
+  switch (i) {
+  case X86::R8:  case X86::R8D:  case X86::R8W:  case X86::R8B:
+  case X86::R9:  case X86::R9D:  case X86::R9W:  case X86::R9B:
+  case X86::R10: case X86::R10D: case X86::R10W: case X86::R10B:
+  case X86::R11: case X86::R11D: case X86::R11W: case X86::R11B:
+  case X86::R12: case X86::R12D: case X86::R12W: case X86::R12B:
+  case X86::R13: case X86::R13D: case X86::R13W: case X86::R13B:
+  case X86::R14: case X86::R14D: case X86::R14W: case X86::R14B:
+  case X86::R15: case X86::R15D: case X86::R15W: case X86::R15B:
+  case X86::XMM8: case X86::XMM9: case X86::XMM10: case X86::XMM11:
+  case X86::XMM12: case X86::XMM13: case X86::XMM14: case X86::XMM15:
+    reg += 8;
+  }
+  return reg;
+}
+
 const TargetRegisterClass *
 X86RegisterInfo::getMatchingSuperRegClass(const TargetRegisterClass *A,
                                           const TargetRegisterClass *B,
Index: lib/Target/X86/X86RegisterInfo.h
===================================================================
--- lib/Target/X86/X86RegisterInfo.h	(revision 131942)
+++ lib/Target/X86/X86RegisterInfo.h	(working copy)
@@ -138,6 +138,8 @@
   // FIXME: Move to FrameInfok
   unsigned getSlotSize() const { return SlotSize; }
 
+  unsigned getNativeRegIndex(unsigned i) const;
+
   // Exception handling queries.
   unsigned getEHExceptionRegister() const;
   unsigned getEHHandlerRegister() const;
