Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore registers appropriately in early returns #48

Open
hikalium opened this issue Oct 24, 2020 · 1 comment
Open

Restore registers appropriately in early returns #48

hikalium opened this issue Oct 24, 2020 · 1 comment

Comments

@hikalium
Copy link
Owner

$ ./compilium
int main() {
  int a = 1;
  return a + 2;
}
Preprocess begin
Parse begin
[
 FuncDef <main> : function<returns: int, args: []>{
  [
   (op=<> R=(op= R=(op=<a>))),
   (op=<return> R=(op=<+> L=(op=<a>) R=(op=<2>)))
  ]
 }
]

Analyze begin
`a` has a type: int
[
 FuncDef <main> : function<returns: int, args: []>{
  [
   (op=<> R=(op= R=(op=<a>))),
   (op=<return> R=(op=<+>:int reg: 1 L=(op=<a>:lvalue<int> reg: 1) R=(op=<2>:int reg: 2)))
  ]
 }
]

.intel_syntax noprefix
.text
.global _main
_main:
push rbp
mov rbp, rsp
push r12
push r13
push r14
push r15
lea rdi, [rbp - 4]
mov rsi, 1
mov [rdi], esi # 4 byte store
lea rdi, [rbp - 4]
movsxd rdi, dword ptr[rdi]
mov rsi, 2
add rdi, rsi
mov rax, rdi
mov rsp, rbp
pop rbp
ret
pop r15
pop r14
pop r13
pop r12
mov rsp, rbp
pop rbp
ret
.data
@hikalium
Copy link
Owner Author

pop r15
pop r14
pop r13
pop r12

should also be done in early returns.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant