Add some convenience utility accessor methods to MacroAssembler::CPUState.
authormark.lam@apple.com <mark.lam@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 14 Aug 2017 22:55:31 +0000 (22:55 +0000)
committermark.lam@apple.com <mark.lam@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 14 Aug 2017 22:55:31 +0000 (22:55 +0000)
https://bugs.webkit.org/show_bug.cgi?id=175549
<rdar://problem/33884868>

Reviewed by Saam Barati.

Previously, in order to read ProbeContext CPUState registers, we used to need to
do it this way:

    ExecState* exec = reinterpret_cast<ExecState*>(cpu.fp());
    uint32_t i32 = static_cast<uint32_t>(cpu.gpr(GPRInfo::regT0));
    void* p = reinterpret_cast<void*>(cpu.gpr(GPRInfo::regT1));
    uint64_t u64 = bitwise_cast<uint64_t>(cpu.fpr(FPRInfo::fpRegT0));

With this patch, we can now read them this way instead:

    ExecState* exec = cpu.fp<ExecState*>();
    uint32_t i32 = cpu.gpr<uint32_t>(GPRInfo::regT0);
    void* p = cpu.gpr<void*>(GPRInfo::regT1);
    uint64_t u64 = cpu.fpr<uint64_t>(FPRInfo::fpRegT0);

* assembler/MacroAssembler.h:
(JSC:: const):
(JSC::MacroAssembler::CPUState::fpr const):
(JSC::MacroAssembler::CPUState::pc const):
(JSC::MacroAssembler::CPUState::fp const):
(JSC::MacroAssembler::CPUState::sp const):
(JSC::ProbeContext::pc):
(JSC::ProbeContext::fp):
(JSC::ProbeContext::sp):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@220720 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/assembler/MacroAssembler.h

index 1f6f514..9792e42 100644 (file)
@@ -1,3 +1,36 @@
+2017-08-14  Mark Lam  <mark.lam@apple.com>
+
+        Add some convenience utility accessor methods to MacroAssembler::CPUState.
+        https://bugs.webkit.org/show_bug.cgi?id=175549
+        <rdar://problem/33884868>
+
+        Reviewed by Saam Barati.
+
+        Previously, in order to read ProbeContext CPUState registers, we used to need to
+        do it this way:
+
+            ExecState* exec = reinterpret_cast<ExecState*>(cpu.fp());
+            uint32_t i32 = static_cast<uint32_t>(cpu.gpr(GPRInfo::regT0));
+            void* p = reinterpret_cast<void*>(cpu.gpr(GPRInfo::regT1));
+            uint64_t u64 = bitwise_cast<uint64_t>(cpu.fpr(FPRInfo::fpRegT0));
+
+        With this patch, we can now read them this way instead:
+        
+            ExecState* exec = cpu.fp<ExecState*>();
+            uint32_t i32 = cpu.gpr<uint32_t>(GPRInfo::regT0);
+            void* p = cpu.gpr<void*>(GPRInfo::regT1);
+            uint64_t u64 = cpu.fpr<uint64_t>(FPRInfo::fpRegT0);
+
+        * assembler/MacroAssembler.h:
+        (JSC:: const):
+        (JSC::MacroAssembler::CPUState::fpr const):
+        (JSC::MacroAssembler::CPUState::pc const):
+        (JSC::MacroAssembler::CPUState::fp const):
+        (JSC::MacroAssembler::CPUState::sp const):
+        (JSC::ProbeContext::pc):
+        (JSC::ProbeContext::fp):
+        (JSC::ProbeContext::sp):
+
 2017-08-12  Filip Pizlo  <fpizlo@apple.com>
 
         Put the ScopedArgumentsTable's ScopeOffset array in some gigacage
index f8b2958..65977f0 100644 (file)
@@ -1863,11 +1863,20 @@ struct MacroAssembler::CPUState {
     inline uintptr_t& gpr(RegisterID);
     inline uintptr_t& spr(SPRegisterID);
     inline double& fpr(FPRegisterID);
-    
-    inline void*& pc();
-    inline void*& fp();
-    inline void*& sp();
-    
+
+    template<typename T, typename std::enable_if<std::is_integral<T>::value>::type* = nullptr>
+    T gpr(RegisterID) const;
+    template<typename T, typename std::enable_if<std::is_pointer<T>::value>::type* = nullptr>
+    T gpr(RegisterID) const;
+    template<typename T> T fpr(FPRegisterID) const;
+
+    void*& pc();
+    void*& fp();
+    void*& sp();
+    template<typename T> T pc() const;
+    template<typename T> T fp() const;
+    template<typename T> T sp() const;
+
     uintptr_t gprs[MacroAssembler::numberOfRegisters()];
     uintptr_t sprs[MacroAssembler::numberOfSPRegisters()];
     double fprs[MacroAssembler::numberOfFPRegisters()];
@@ -1891,6 +1900,27 @@ inline double& MacroAssembler::CPUState::fpr(FPRegisterID id)
     return fprs[id];
 }
 
+template<typename T, typename std::enable_if<std::is_integral<T>::value>::type*>
+T MacroAssembler::CPUState::gpr(RegisterID id) const
+{
+    CPUState* cpu = const_cast<CPUState*>(this);
+    return static_cast<T>(cpu->gpr(id));
+}
+
+template<typename T, typename std::enable_if<std::is_pointer<T>::value>::type*>
+T MacroAssembler::CPUState::gpr(RegisterID id) const
+{
+    CPUState* cpu = const_cast<CPUState*>(this);
+    return reinterpret_cast<T>(cpu->gpr(id));
+}
+
+template<typename T>
+T MacroAssembler::CPUState::fpr(FPRegisterID id) const
+{
+    CPUState* cpu = const_cast<CPUState*>(this);
+    return bitwise_cast<T>(cpu->fpr(id));
+}
+
 inline void*& MacroAssembler::CPUState::pc()
 {
 #if CPU(X86) || CPU(X86_64)
@@ -1936,6 +1966,27 @@ inline void*& MacroAssembler::CPUState::sp()
 #endif
 }
 
+template<typename T>
+T MacroAssembler::CPUState::pc() const
+{
+    CPUState* cpu = const_cast<CPUState*>(this);
+    return reinterpret_cast<T>(cpu->pc());
+}
+
+template<typename T>
+T MacroAssembler::CPUState::fp() const
+{
+    CPUState* cpu = const_cast<CPUState*>(this);
+    return reinterpret_cast<T>(cpu->fp());
+}
+
+template<typename T>
+T MacroAssembler::CPUState::sp() const
+{
+    CPUState* cpu = const_cast<CPUState*>(this);
+    return reinterpret_cast<T>(cpu->sp());
+}
+
 struct ProbeContext {
     using CPUState = MacroAssembler::CPUState;
     using RegisterID = MacroAssembler::RegisterID;
@@ -1957,6 +2008,10 @@ struct ProbeContext {
     void*& pc() { return cpu.pc(); }
     void*& fp() { return cpu.fp(); }
     void*& sp() { return cpu.sp(); }
+
+    template<typename T> T pc() { return cpu.pc<T>(); }
+    template<typename T> T fp() { return cpu.fp<T>(); }
+    template<typename T> T sp() { return cpu.sp<T>(); }
 };
     
 } // namespace JSC