Commit e8d9c75
committed
New "reverse C" calling convention in LLVM and Clang.
Test case:
#define PARAMS \
const char *ptr, long p2, \
long p3, long p4, long p5, long p6
#define ARGS ptr, p2, p3, p4, p5, p6
#define UNLIKELY(x) \
__builtin_expect(x, 0)
#if __has_attribute(reverse_call)
#define CC __attribute__((reverse_call))
#else
#define CC
#endif
CC const char *Next(PARAMS);
const char *Fallback(PARAMS);
CC const char *Parse(PARAMS) {
if (UNLIKELY(!ptr)) {
// This ruins everything.
ptr = Fallback(ARGS);
}
ptr++;
__attribute__((musttail)) return Next(ARGS);
}
Before (existing calling convention):
0000000000000000 <Parse>:
0: 41 57 push r15
2: 41 56 push r14
4: 41 55 push r13
6: 41 54 push r12
8: 53 push rbx
9: 4d 89 ce mov r14,r9
c: 4d 89 c7 mov r15,r8
f: 49 89 cc mov r12,rcx
12: 49 89 d5 mov r13,rdx
15: 48 89 f3 mov rbx,rsi
18: 48 85 ff test rdi,rdi
1b: 74 21 je 3e <Parse+0x3e>
1d: 48 83 c7 01 add rdi,0x1
21: 48 89 de mov rsi,rbx
24: 4c 89 ea mov rdx,r13
27: 4c 89 e1 mov rcx,r12
2a: 4d 89 f8 mov r8,r15
2d: 4d 89 f1 mov r9,r14
30: 5b pop rbx
31: 41 5c pop r12
33: 41 5d pop r13
35: 41 5e pop r14
37: 41 5f pop r15
39: e9 00 00 00 00 jmp 3e <Parse+0x3e>
3a: R_X86_64_PLT32 Next-0x4
3e: 31 ff xor edi,edi
40: 48 89 de mov rsi,rbx
43: 4c 89 ea mov rdx,r13
46: 4c 89 e1 mov rcx,r12
49: 4d 89 f8 mov r8,r15
4c: 4d 89 f1 mov r9,r14
4f: e8 00 00 00 00 call 54 <Parse+0x54>
50: R_X86_64_PLT32 Fallback-0x4
54: 48 89 c7 mov rdi,rax
57: eb c4 jmp 1d <Parse+0x1d>
After (new reverse_call calling convention):
0000000000000000 <Parse>:
0: 48 85 db test rbx,rbx
3: 74 09 je e <Parse+0xe>
5: 48 83 c3 01 add rbx,0x1
9: e9 00 00 00 00 jmp e <Parse+0xe>
a: R_X86_64_PLT32 Next-0x4
e: 50 push rax
f: 31 ff xor edi,edi
11: 48 89 ee mov rsi,rbp
14: 4c 89 e2 mov rdx,r12
17: 4c 89 e9 mov rcx,r13
1a: 4d 89 f0 mov r8,r14
1d: 4d 89 f9 mov r9,r15
20: e8 00 00 00 00 call 25 <Parse+0x25>
21: R_X86_64_PLT32 Fallback-0x4
25: 48 89 c3 mov rbx,rax
28: 48 83 c4 08 add rsp,0x8
2c: 48 83 c3 01 add rbx,0x1
30: e9 00 00 00 00 jmp 35 <Parse+0x35>
The fast path has gone from 24 instructions (including 5 spills) to
4 instructions (0 spills).1 parent 0a2708d commit e8d9c75
20 files changed
Lines changed: 102 additions & 1 deletion
File tree
- clang
- include
- clang-c
- clang/Basic
- lib
- AST
- Basic/Targets
- CodeGen
- Sema
- tools/libclang
- llvm
- docs
- include/llvm
- AsmParser
- IR
- lib
- AsmParser
- IR
- Target/X86
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3424 | 3424 | | |
3425 | 3425 | | |
3426 | 3426 | | |
| 3427 | + | |
3427 | 3428 | | |
3428 | 3429 | | |
3429 | 3430 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2567 | 2567 | | |
2568 | 2568 | | |
2569 | 2569 | | |
| 2570 | + | |
| 2571 | + | |
| 2572 | + | |
| 2573 | + | |
| 2574 | + | |
2570 | 2575 | | |
2571 | 2576 | | |
2572 | 2577 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4864 | 4864 | | |
4865 | 4865 | | |
4866 | 4866 | | |
| 4867 | + | |
| 4868 | + | |
| 4869 | + | |
| 4870 | + | |
| 4871 | + | |
| 4872 | + | |
| 4873 | + | |
| 4874 | + | |
| 4875 | + | |
| 4876 | + | |
| 4877 | + | |
| 4878 | + | |
| 4879 | + | |
| 4880 | + | |
4867 | 4881 | | |
4868 | 4882 | | |
4869 | 4883 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
280 | 280 | | |
281 | 281 | | |
282 | 282 | | |
| 283 | + | |
283 | 284 | | |
284 | 285 | | |
285 | 286 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3098 | 3098 | | |
3099 | 3099 | | |
3100 | 3100 | | |
| 3101 | + | |
3101 | 3102 | | |
3102 | 3103 | | |
3103 | 3104 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3156 | 3156 | | |
3157 | 3157 | | |
3158 | 3158 | | |
| 3159 | + | |
3159 | 3160 | | |
3160 | 3161 | | |
3161 | 3162 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
983 | 983 | | |
984 | 984 | | |
985 | 985 | | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
986 | 989 | | |
987 | 990 | | |
988 | 991 | | |
| |||
1718 | 1721 | | |
1719 | 1722 | | |
1720 | 1723 | | |
| 1724 | + | |
1721 | 1725 | | |
1722 | 1726 | | |
1723 | 1727 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
358 | 358 | | |
359 | 359 | | |
360 | 360 | | |
| 361 | + | |
361 | 362 | | |
362 | 363 | | |
363 | 364 | | |
| |||
729 | 730 | | |
730 | 731 | | |
731 | 732 | | |
| 733 | + | |
732 | 734 | | |
733 | 735 | | |
734 | 736 | | |
| |||
806 | 808 | | |
807 | 809 | | |
808 | 810 | | |
| 811 | + | |
809 | 812 | | |
810 | 813 | | |
811 | 814 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
| 70 | + | |
70 | 71 | | |
71 | 72 | | |
72 | 73 | | |
| |||
242 | 243 | | |
243 | 244 | | |
244 | 245 | | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
245 | 249 | | |
246 | 250 | | |
247 | 251 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4742 | 4742 | | |
4743 | 4743 | | |
4744 | 4744 | | |
| 4745 | + | |
| 4746 | + | |
| 4747 | + | |
4745 | 4748 | | |
4746 | 4749 | | |
4747 | 4750 | | |
| |||
4913 | 4916 | | |
4914 | 4917 | | |
4915 | 4918 | | |
| 4919 | + | |
| 4920 | + | |
| 4921 | + | |
4916 | 4922 | | |
4917 | 4923 | | |
4918 | 4924 | | |
| |||
8290 | 8296 | | |
8291 | 8297 | | |
8292 | 8298 | | |
| 8299 | + | |
8293 | 8300 | | |
8294 | 8301 | | |
8295 | 8302 | | |
| |||
0 commit comments