merge s6 and sp in variable naming pass

This commit is contained in:
water111 2021-12-28 20:45:45 -05:00
parent 696a6d87be
commit 33829b8dd3
9 changed files with 52 additions and 50 deletions

View file

@ -86,6 +86,14 @@ void VarMapSSA::merge(const VarSSA& var_a, const VarSSA& var_b) {
}
}
void VarMapSSA::merge_reg(Register reg) {
for (auto& entry : m_entries) {
if (entry.reg == reg) {
entry.var_id = 0;
}
}
}
/*!
* Make all Bs A.
*/
@ -491,6 +499,13 @@ std::string SSA::print() const {
return result;
}
/*!
* Merge all variables in the same register to the given register.
*/
void SSA::merge_reg_to_single_variable(Register reg) {
map.merge_reg(reg);
}
/*!
* Simplify the SSA while still keeping it in SSA form.
* This does only a single pass of simplifications and returns true if it made changes.
@ -1070,6 +1085,10 @@ std::optional<VariableNames> run_variable_renaming(const Function& function,
fmt::print("Simplified SSA\n{}-------------------------------\n", ssa.print());
}
// merge special registers
ssa.merge_reg_to_single_variable(Register(Reg::GPR, Reg::SP));
ssa.merge_reg_to_single_variable(Register(Reg::GPR, Reg::S6));
// remember what the SSA mapping was:
auto ssa_mapping = ssa.get_ssa_mapping();

View file

@ -77,6 +77,7 @@ class VarMapSSA {
bool same(const VarSSA& var_a, const VarSSA& var_b) const;
int var_id(const VarSSA& var) const;
void remap_reg(Register reg, const std::unordered_map<int, int>& remap);
void merge_reg(Register reg);
void debug_print_map() const;
private:
@ -143,6 +144,7 @@ struct SSA {
RegAccessMap<int> get_ssa_mapping();
bool simplify();
void merge_reg_to_single_variable(Register reg);
void merge_all_phis();
void remap(int nargs);
void make_vars(const Function& function, const DecompilerTypeSystem& dts);

View file

@ -741,22 +741,15 @@ battlecontroller-default-event-handler
(defmethod deactivate battlecontroller ((obj battlecontroller))
(with-pp
(let ((gp-0 pp))
(let ((s6-1 obj))
)
(battlecontroller-off)
(let ((s6-2 gp-0))
)
(let ((gp-0 pp))
(set! pp obj)
(battlecontroller-off)
(set! pp gp-0)
)
((the-as (function process-drawable none) (find-parent-method battlecontroller 10)) obj)
0
(none)
)
((the-as
(function process-drawable none)
(find-parent-method battlecontroller 10)
)
obj
)
0
(none)
)
)
(defmethod TODO-RENAME-27 battlecontroller ((obj battlecontroller))

View file

@ -912,11 +912,9 @@
((type-type? (-> gp-0 type) process-drawable)
(when (zero? (logand (-> (the-as process-drawable gp-0) skel status) 4))
(let ((s5-0 pp))
(let ((s6-1 gp-0))
)
(set! pp gp-0)
(let ((v0-1 (the-as object (ja-done? 0))))
(let ((s6-2 s5-0))
)
(set! pp s5-0)
v0-1
)
)

View file

@ -223,8 +223,7 @@
(when (and (and *display-vol-marks* (logtest? (-> a0-1 flags) 1)) (logtest? (-> obj flags) 2))
(when (zero? (-> obj debug-point))
(let ((s5-0 pp))
(let ((s6-1 (-> obj process)))
)
(set! pp (-> obj process))
(let ((s4-0 0))
(dotimes (v1-8 (-> obj pos-vol-count))
(+! s4-0 (-> obj pos-vol v1-8 num-planes))
@ -235,8 +234,7 @@
(set! (-> obj debug-point) (new 'debug 'vector-array (* 10 s4-0)))
(set! (-> obj debug-normal) (new 'debug 'vector-array (* 10 s4-0)))
)
(let ((s6-2 s5-0))
)
(set! pp s5-0)
)
(set! (-> obj debug-point length) 0)
(set! (-> obj debug-normal length) 0)
@ -273,7 +271,3 @@
)
#f
)

View file

@ -103,12 +103,12 @@
;; definition for function drawable-load
(defun drawable-load ((arg0 drawable) (arg1 kheap))
(local-vars (sp-0 none))
(local-vars (sp-0 pointer))
(cond
((type-type? (-> arg0 type) string)
sp-0
(the-as none sp-0)
(if (< (the-as uint sp-0) (the-as uint *stack-top*))
(&+ *kernel-sp* -1024)
(set! sp-0 (&+ *kernel-sp* -1024))
)
(let ((s5-1 (the-as drawable (loado (the-as string arg0) arg1))))
(if (and s5-1 (type-type? (-> s5-1 type) drawable))
@ -124,10 +124,10 @@
;; definition for function art-load
(defun art-load ((arg0 string) (arg1 kheap))
(local-vars (sp-0 none))
sp-0
(local-vars (sp-0 pointer))
(the-as none sp-0)
(if (< (the-as uint sp-0) (the-as uint *stack-top*))
(&+ *kernel-sp* -1024)
(set! sp-0 (&+ *kernel-sp* -1024))
)
(let ((s5-0 (loado arg0 arg1)))
(if (type-type? (-> (the-as art s5-0) type) art)
@ -139,11 +139,11 @@
;; definition for function art-group-load-check
(defun art-group-load-check ((arg0 string) (arg1 kheap) (arg2 int))
(local-vars (sp-0 none))
(local-vars (sp-0 pointer))
(when *debug-segment*
sp-0
(the-as none sp-0)
(if (< (the-as uint sp-0) (the-as uint *stack-top*))
(&+ *kernel-sp* -1024)
(set! sp-0 (&+ *kernel-sp* -1024))
)
(let ((s3-1 (the-as art-group (loado (make-file-name (file-kind art-group) arg0 arg2 #f) arg1))))
(cond

View file

@ -1383,7 +1383,8 @@
(entity-deactivate-handler obj (-> obj entity))
)
(let ((s5-0 pp))
(let ((s4-0 (-> obj stack-frame-top)))
(set! pp obj)
(let ((s4-0 (-> pp stack-frame-top)))
(while (the-as protect-frame s4-0)
(case (-> s4-0 type)
((protect-frame state)
@ -1393,8 +1394,7 @@
(set! s4-0 (-> (the-as protect-frame s4-0) next))
)
)
(let ((s6-2 s5-0))
)
(set! pp s5-0)
)
(process-disconnect obj)
(let ((v1-11 (-> obj child)))

View file

@ -47,7 +47,7 @@
;; WARN: Unsupported inline assembly instruction kind - [jr t9]
;; WARN: Unsupported inline assembly instruction kind - [sw v0, 0(sp)]
(defun enter-state ((arg0 object) (arg1 object) (arg2 object) (arg3 object) (arg4 object) (arg5 object))
(local-vars (s7-0 none) (sp-0 none) (sp-1 int) (ra-0 int) (sv-0 none))
(local-vars (s7-0 none) (sp-0 int) (ra-0 int) (sv-0 none))
(with-pp
(logclear! (-> pp mask) (process-mask sleep sleep-code))
(logior! (-> pp mask) (process-mask going))
@ -99,7 +99,7 @@
)
)
(let ((v1-28 (-> pp main-thread)))
(.lwu sp-1 28 v1-28)
(.lwu sp-0 28 v1-28)
)
(let ((t9-6 (-> s0-2 code)))
(.lw ra-0 return-from-thread-dead s7-0)
@ -113,7 +113,7 @@
(set-to-run (-> pp main-thread) enter-state arg0 arg1 arg2 arg3 arg4 arg5)
(when (!= (-> pp top-thread name) 'post)
(let ((v0-2 (the-as object return-from-thread)))
(.sw (the-as (function none) v0-2) 0 sp-0)
(.sw (the-as (function none) v0-2) 0 (the-as none sp-0))
v0-2
)
)
@ -127,11 +127,9 @@
(with-pp
(when (and arg0 (!= (-> arg0 type) process-tree) (-> (the-as process arg0) event-hook))
(let ((gp-0 pp))
(let ((s6-1 (the-as process arg0)))
)
(set! pp (the-as process arg0))
(let ((v0-0 ((-> (the-as process arg0) event-hook) (-> arg1 from) (-> arg1 num-params) (-> arg1 message) arg1)))
(let ((s6-2 gp-0))
)
(set! pp gp-0)
v0-0
)
)

View file

@ -711,11 +711,9 @@ battlecontroller-default-event-handler
(defmethod deactivate battlecontroller ((obj battlecontroller))
(with-pp
(let ((gp-0 pp))
(let ((s6-1 obj))
)
(set! pp obj)
(battlecontroller-off)
(let ((s6-2 gp-0))
)
(set! pp gp-0)
)
((the-as (function process-drawable none) (find-parent-method battlecontroller 10)) obj)
0