Skip to content

Commit 338652e

Browse files
committed
CHB:don't record save/restores of temporary registers
1 parent d8e20c7 commit 338652e

File tree

2 files changed

+97
-94
lines changed

2 files changed

+97
-94
lines changed

CodeHawk/CHB/bchlib/bCHFunctionInfo.ml

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1825,36 +1825,33 @@ object (self)
18251825

18261826
method save_register
18271827
(vmem: variable_t) (iaddr: ctxt_iaddress_t) (reg: register_t) =
1828-
if BCHCPURegisters.is_temporary_register reg then
1829-
()
1828+
if self#env#is_stack_variable vmem then
1829+
TR.tfold
1830+
~ok:(fun offset ->
1831+
match offset with
1832+
| ConstantOffset (n, NoOffset) ->
1833+
self#stackframe#add_register_spill ~offset:n#toInt reg iaddr
1834+
| _ ->
1835+
log_error_result
1836+
~msg:"save_register:not a constant offset"
1837+
__FILE__ __LINE__
1838+
["(" ^ (p2s self#get_address#toPretty) ^ "," ^ iaddr ^ "): ";
1839+
(p2s vmem#toPretty) ^ " with " ^ (register_to_string reg)
1840+
^ " and offset " ^ (memory_offset_to_string offset)])
1841+
~error:(fun e ->
1842+
log_error_result
1843+
~msg:"save_register"
1844+
__FILE__ __LINE__
1845+
(["(" ^ (p2s self#get_address#toPretty) ^ "," ^ iaddr ^ "): ";
1846+
(p2s vmem#toPretty) ^ " with " ^ (register_to_string reg)] @ e))
1847+
(self#env#get_memvar_offset vmem)
18301848
else
1831-
if self#env#is_stack_variable vmem then
1832-
TR.tfold
1833-
~ok:(fun offset ->
1834-
match offset with
1835-
| ConstantOffset (n, NoOffset) ->
1836-
self#stackframe#add_register_spill ~offset:n#toInt reg iaddr
1837-
| _ ->
1838-
log_error_result
1839-
~msg:"save_register:not a constant offset"
1840-
__FILE__ __LINE__
1841-
["(" ^ (p2s self#get_address#toPretty) ^ "," ^ iaddr ^ "): ";
1842-
(p2s vmem#toPretty) ^ " with " ^ (register_to_string reg)
1843-
^ " and offset " ^ (memory_offset_to_string offset)])
1844-
~error:(fun e ->
1845-
log_error_result
1846-
~msg:"save_register"
1847-
__FILE__ __LINE__
1848-
(["(" ^ (p2s self#get_address#toPretty) ^ "," ^ iaddr ^ "): ";
1849-
(p2s vmem#toPretty) ^ " with " ^ (register_to_string reg)] @ e))
1850-
(self#env#get_memvar_offset vmem)
1851-
else
1852-
log_error_result
1853-
~msg:"save register:not a stack variable"
1854-
__FILE__ __LINE__
1855-
["(" ^ (p2s self#get_address#toPretty) ^ "," ^ iaddr ^ "): ";
1856-
"not a stack variable: "
1857-
^ (p2s vmem#toPretty) ^ " with " ^ (register_to_string reg)]
1849+
log_error_result
1850+
~msg:"save register:not a stack variable"
1851+
__FILE__ __LINE__
1852+
["(" ^ (p2s self#get_address#toPretty) ^ "," ^ iaddr ^ "): ";
1853+
"not a stack variable: "
1854+
^ (p2s vmem#toPretty) ^ " with " ^ (register_to_string reg)]
18581855

18591856
method restore_register
18601857
(memaddr: xpr_t) (iaddr:ctxt_iaddress_t) (reg:register_t) =

CodeHawk/CHB/bchlib/bCHFunctionStackframe.ml

Lines changed: 71 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -465,75 +465,81 @@ object (self)
465465

466466
method add_register_spill
467467
~(offset: int) (reg: register_t) (iaddr:ctxt_iaddress_t) =
468-
let spill = RegisterSpill (offset, reg) in
469-
begin
470-
(if H.mem stackslots offset then
471-
if (H.find stackslots offset)#is_spill then
472-
()
473-
else
474-
let sslot = H.find stackslots offset in
475-
raise
476-
(BCH_failure
477-
(LBLOCK [
478-
STR "Add register spill at address ";
479-
STR iaddr;
480-
STR " for register ";
481-
STR (register_to_string reg);
482-
STR " at offset ";
483-
INT offset;
484-
STR " cannot be completed, because another stackslot ";
485-
STR "at this offset, with name: ";
486-
STR sslot#name;
487-
STR " already exists"]))
488-
else
489-
let ssrec = {
490-
sslot_name = (register_to_string reg) ^ "_spill";
491-
sslot_offset = offset;
492-
sslot_btype = t_unknown;
493-
sslot_spill = Some reg;
494-
sslot_size = Some 4;
495-
sslot_desc = Some "register spill"
496-
} in
497-
let sslot = new stackslot_t ssrec in
498-
H.add stackslots offset sslot);
468+
if BCHCPURegisters.is_temporary_register reg then
469+
()
470+
else
471+
let spill = RegisterSpill (offset, reg) in
472+
begin
473+
(if H.mem stackslots offset then
474+
if (H.find stackslots offset)#is_spill then
475+
()
476+
else
477+
let sslot = H.find stackslots offset in
478+
raise
479+
(BCH_failure
480+
(LBLOCK [
481+
STR "Add register spill at address ";
482+
STR iaddr;
483+
STR " for register ";
484+
STR (register_to_string reg);
485+
STR " at offset ";
486+
INT offset;
487+
STR " cannot be completed, because another stackslot ";
488+
STR "at this offset, with name: ";
489+
STR sslot#name;
490+
STR " already exists"]))
491+
else
492+
let ssrec = {
493+
sslot_name = (register_to_string reg) ^ "_spill";
494+
sslot_offset = offset;
495+
sslot_btype = t_unknown;
496+
sslot_spill = Some reg;
497+
sslot_size = Some 4;
498+
sslot_desc = Some "register spill"
499+
} in
500+
let sslot = new stackslot_t ssrec in
501+
H.add stackslots offset sslot);
499502
self#add_access offset iaddr spill
500-
end
503+
end
501504

502505
method add_register_restore
503506
~(offset: int) (reg: register_t) (iaddr: ctxt_iaddress_t) =
504-
let restore = RegisterRestore (offset, reg) in
505-
begin
506-
(if H.mem stackslots offset then
507-
if (H.find stackslots offset)#is_spill then
508-
()
509-
else
510-
let sslot = H.find stackslots offset in
511-
raise
512-
(BCH_failure
513-
(LBLOCK [
514-
STR "Add register restore at address ";
515-
STR iaddr;
516-
STR " for register ";
517-
STR (register_to_string reg);
518-
STR " at offset ";
519-
INT offset;
520-
STR " cannot be completed, because another stackslot ";
521-
STR "at this offset, with name: ";
522-
STR sslot#name;
523-
STR " already exists"]))
524-
else
525-
let ssrec = {
526-
sslot_name = (register_to_string reg) ^ "_spill";
527-
sslot_offset = offset;
528-
sslot_btype = t_unknown;
529-
sslot_spill = Some reg;
530-
sslot_size = Some 4;
531-
sslot_desc = Some "register_spill"
532-
} in
533-
let sslot = new stackslot_t ssrec in
534-
H.add stackslots offset sslot);
535-
self#add_access offset iaddr restore
536-
end
507+
if BCHCPURegisters.is_temporary_register reg then
508+
()
509+
else
510+
let restore = RegisterRestore (offset, reg) in
511+
begin
512+
(if H.mem stackslots offset then
513+
if (H.find stackslots offset)#is_spill then
514+
()
515+
else
516+
let sslot = H.find stackslots offset in
517+
raise
518+
(BCH_failure
519+
(LBLOCK [
520+
STR "Add register restore at address ";
521+
STR iaddr;
522+
STR " for register ";
523+
STR (register_to_string reg);
524+
STR " at offset ";
525+
INT offset;
526+
STR " cannot be completed, because another stackslot ";
527+
STR "at this offset, with name: ";
528+
STR sslot#name;
529+
STR " already exists"]))
530+
else
531+
let ssrec = {
532+
sslot_name = (register_to_string reg) ^ "_spill";
533+
sslot_offset = offset;
534+
sslot_btype = t_unknown;
535+
sslot_spill = Some reg;
536+
sslot_size = Some 4;
537+
sslot_desc = Some "register_spill"
538+
} in
539+
let sslot = new stackslot_t ssrec in
540+
H.add stackslots offset sslot);
541+
self#add_access offset iaddr restore
542+
end
537543

538544
method add_load
539545
~(baseoffset:int)

0 commit comments

Comments
 (0)