Hadrian: add --test-root-dirs, to only run specific directories of tests
[ghc.git] / includes / CodeGen.Platform.hs
1
2 import CmmExpr
3 #if !(defined(MACHREGS_i386) || defined(MACHREGS_x86_64) \
4 || defined(MACHREGS_sparc) || defined(MACHREGS_powerpc))
5 import Panic
6 #endif
7 import Reg
8
9 #include "ghcautoconf.h"
10 #include "stg/MachRegs.h"
11
12 #if defined(MACHREGS_i386) || defined(MACHREGS_x86_64)
13
14 # if defined(MACHREGS_i386)
15 # define eax 0
16 # define ebx 1
17 # define ecx 2
18 # define edx 3
19 # define esi 4
20 # define edi 5
21 # define ebp 6
22 # define esp 7
23 # endif
24
25 # if defined(MACHREGS_x86_64)
26 # define rax 0
27 # define rbx 1
28 # define rcx 2
29 # define rdx 3
30 # define rsi 4
31 # define rdi 5
32 # define rbp 6
33 # define rsp 7
34 # define r8 8
35 # define r9 9
36 # define r10 10
37 # define r11 11
38 # define r12 12
39 # define r13 13
40 # define r14 14
41 # define r15 15
42 # endif
43
44
45 -- N.B. XMM, YMM, and ZMM are all aliased to the same hardware registers hence
46 -- being assigned the same RegNos.
47 # define xmm0 16
48 # define xmm1 17
49 # define xmm2 18
50 # define xmm3 19
51 # define xmm4 20
52 # define xmm5 21
53 # define xmm6 22
54 # define xmm7 23
55 # define xmm8 24
56 # define xmm9 25
57 # define xmm10 26
58 # define xmm11 27
59 # define xmm12 28
60 # define xmm13 29
61 # define xmm14 30
62 # define xmm15 31
63
64 # define ymm0 16
65 # define ymm1 17
66 # define ymm2 18
67 # define ymm3 19
68 # define ymm4 20
69 # define ymm5 21
70 # define ymm6 22
71 # define ymm7 23
72 # define ymm8 24
73 # define ymm9 25
74 # define ymm10 26
75 # define ymm11 27
76 # define ymm12 28
77 # define ymm13 29
78 # define ymm14 30
79 # define ymm15 31
80
81 # define zmm0 16
82 # define zmm1 17
83 # define zmm2 18
84 # define zmm3 19
85 # define zmm4 20
86 # define zmm5 21
87 # define zmm6 22
88 # define zmm7 23
89 # define zmm8 24
90 # define zmm9 25
91 # define zmm10 26
92 # define zmm11 27
93 # define zmm12 28
94 # define zmm13 29
95 # define zmm14 30
96 # define zmm15 31
97
98 -- Note: these are only needed for ARM/ARM64 because globalRegMaybe is now used in CmmSink.hs.
99 -- Since it's only used to check 'isJust', the actual values don't matter, thus
100 -- I'm not sure if these are the correct numberings.
101 -- Normally, the register names are just stringified as part of the REG() macro
102
103 #elif defined(MACHREGS_powerpc) || defined(MACHREGS_arm) \
104 || defined(MACHREGS_aarch64)
105
106 # define r0 0
107 # define r1 1
108 # define r2 2
109 # define r3 3
110 # define r4 4
111 # define r5 5
112 # define r6 6
113 # define r7 7
114 # define r8 8
115 # define r9 9
116 # define r10 10
117 # define r11 11
118 # define r12 12
119 # define r13 13
120 # define r14 14
121 # define r15 15
122 # define r16 16
123 # define r17 17
124 # define r18 18
125 # define r19 19
126 # define r20 20
127 # define r21 21
128 # define r22 22
129 # define r23 23
130 # define r24 24
131 # define r25 25
132 # define r26 26
133 # define r27 27
134 # define r28 28
135 # define r29 29
136 # define r30 30
137 # define r31 31
138
139 -- See note above. These aren't actually used for anything except satisfying the compiler for globalRegMaybe
140 -- so I'm unsure if they're the correct numberings, should they ever be attempted to be used in the NCG.
141 #if defined(MACHREGS_aarch64) || defined(MACHREGS_arm)
142 # define s0 32
143 # define s1 33
144 # define s2 34
145 # define s3 35
146 # define s4 36
147 # define s5 37
148 # define s6 38
149 # define s7 39
150 # define s8 40
151 # define s9 41
152 # define s10 42
153 # define s11 43
154 # define s12 44
155 # define s13 45
156 # define s14 46
157 # define s15 47
158 # define s16 48
159 # define s17 49
160 # define s18 50
161 # define s19 51
162 # define s20 52
163 # define s21 53
164 # define s22 54
165 # define s23 55
166 # define s24 56
167 # define s25 57
168 # define s26 58
169 # define s27 59
170 # define s28 60
171 # define s29 61
172 # define s30 62
173 # define s31 63
174
175 # define d0 32
176 # define d1 33
177 # define d2 34
178 # define d3 35
179 # define d4 36
180 # define d5 37
181 # define d6 38
182 # define d7 39
183 # define d8 40
184 # define d9 41
185 # define d10 42
186 # define d11 43
187 # define d12 44
188 # define d13 45
189 # define d14 46
190 # define d15 47
191 # define d16 48
192 # define d17 49
193 # define d18 50
194 # define d19 51
195 # define d20 52
196 # define d21 53
197 # define d22 54
198 # define d23 55
199 # define d24 56
200 # define d25 57
201 # define d26 58
202 # define d27 59
203 # define d28 60
204 # define d29 61
205 # define d30 62
206 # define d31 63
207 #endif
208
209 # if defined(MACHREGS_darwin)
210 # define f0 32
211 # define f1 33
212 # define f2 34
213 # define f3 35
214 # define f4 36
215 # define f5 37
216 # define f6 38
217 # define f7 39
218 # define f8 40
219 # define f9 41
220 # define f10 42
221 # define f11 43
222 # define f12 44
223 # define f13 45
224 # define f14 46
225 # define f15 47
226 # define f16 48
227 # define f17 49
228 # define f18 50
229 # define f19 51
230 # define f20 52
231 # define f21 53
232 # define f22 54
233 # define f23 55
234 # define f24 56
235 # define f25 57
236 # define f26 58
237 # define f27 59
238 # define f28 60
239 # define f29 61
240 # define f30 62
241 # define f31 63
242 # else
243 # define fr0 32
244 # define fr1 33
245 # define fr2 34
246 # define fr3 35
247 # define fr4 36
248 # define fr5 37
249 # define fr6 38
250 # define fr7 39
251 # define fr8 40
252 # define fr9 41
253 # define fr10 42
254 # define fr11 43
255 # define fr12 44
256 # define fr13 45
257 # define fr14 46
258 # define fr15 47
259 # define fr16 48
260 # define fr17 49
261 # define fr18 50
262 # define fr19 51
263 # define fr20 52
264 # define fr21 53
265 # define fr22 54
266 # define fr23 55
267 # define fr24 56
268 # define fr25 57
269 # define fr26 58
270 # define fr27 59
271 # define fr28 60
272 # define fr29 61
273 # define fr30 62
274 # define fr31 63
275 # endif
276
277 #elif defined(MACHREGS_sparc)
278
279 # define g0 0
280 # define g1 1
281 # define g2 2
282 # define g3 3
283 # define g4 4
284 # define g5 5
285 # define g6 6
286 # define g7 7
287
288 # define o0 8
289 # define o1 9
290 # define o2 10
291 # define o3 11
292 # define o4 12
293 # define o5 13
294 # define o6 14
295 # define o7 15
296
297 # define l0 16
298 # define l1 17
299 # define l2 18
300 # define l3 19
301 # define l4 20
302 # define l5 21
303 # define l6 22
304 # define l7 23
305
306 # define i0 24
307 # define i1 25
308 # define i2 26
309 # define i3 27
310 # define i4 28
311 # define i5 29
312 # define i6 30
313 # define i7 31
314
315 # define f0 32
316 # define f1 33
317 # define f2 34
318 # define f3 35
319 # define f4 36
320 # define f5 37
321 # define f6 38
322 # define f7 39
323 # define f8 40
324 # define f9 41
325 # define f10 42
326 # define f11 43
327 # define f12 44
328 # define f13 45
329 # define f14 46
330 # define f15 47
331 # define f16 48
332 # define f17 49
333 # define f18 50
334 # define f19 51
335 # define f20 52
336 # define f21 53
337 # define f22 54
338 # define f23 55
339 # define f24 56
340 # define f25 57
341 # define f26 58
342 # define f27 59
343 # define f28 60
344 # define f29 61
345 # define f30 62
346 # define f31 63
347
348 #endif
349
350 callerSaves :: GlobalReg -> Bool
351 #if defined(CALLER_SAVES_Base)
352 callerSaves BaseReg = True
353 #endif
354 #if defined(CALLER_SAVES_R1)
355 callerSaves (VanillaReg 1 _) = True
356 #endif
357 #if defined(CALLER_SAVES_R2)
358 callerSaves (VanillaReg 2 _) = True
359 #endif
360 #if defined(CALLER_SAVES_R3)
361 callerSaves (VanillaReg 3 _) = True
362 #endif
363 #if defined(CALLER_SAVES_R4)
364 callerSaves (VanillaReg 4 _) = True
365 #endif
366 #if defined(CALLER_SAVES_R5)
367 callerSaves (VanillaReg 5 _) = True
368 #endif
369 #if defined(CALLER_SAVES_R6)
370 callerSaves (VanillaReg 6 _) = True
371 #endif
372 #if defined(CALLER_SAVES_R7)
373 callerSaves (VanillaReg 7 _) = True
374 #endif
375 #if defined(CALLER_SAVES_R8)
376 callerSaves (VanillaReg 8 _) = True
377 #endif
378 #if defined(CALLER_SAVES_R9)
379 callerSaves (VanillaReg 9 _) = True
380 #endif
381 #if defined(CALLER_SAVES_R10)
382 callerSaves (VanillaReg 10 _) = True
383 #endif
384 #if defined(CALLER_SAVES_F1)
385 callerSaves (FloatReg 1) = True
386 #endif
387 #if defined(CALLER_SAVES_F2)
388 callerSaves (FloatReg 2) = True
389 #endif
390 #if defined(CALLER_SAVES_F3)
391 callerSaves (FloatReg 3) = True
392 #endif
393 #if defined(CALLER_SAVES_F4)
394 callerSaves (FloatReg 4) = True
395 #endif
396 #if defined(CALLER_SAVES_F5)
397 callerSaves (FloatReg 5) = True
398 #endif
399 #if defined(CALLER_SAVES_F6)
400 callerSaves (FloatReg 6) = True
401 #endif
402 #if defined(CALLER_SAVES_D1)
403 callerSaves (DoubleReg 1) = True
404 #endif
405 #if defined(CALLER_SAVES_D2)
406 callerSaves (DoubleReg 2) = True
407 #endif
408 #if defined(CALLER_SAVES_D3)
409 callerSaves (DoubleReg 3) = True
410 #endif
411 #if defined(CALLER_SAVES_D4)
412 callerSaves (DoubleReg 4) = True
413 #endif
414 #if defined(CALLER_SAVES_D5)
415 callerSaves (DoubleReg 5) = True
416 #endif
417 #if defined(CALLER_SAVES_D6)
418 callerSaves (DoubleReg 6) = True
419 #endif
420 #if defined(CALLER_SAVES_L1)
421 callerSaves (LongReg 1) = True
422 #endif
423 #if defined(CALLER_SAVES_Sp)
424 callerSaves Sp = True
425 #endif
426 #if defined(CALLER_SAVES_SpLim)
427 callerSaves SpLim = True
428 #endif
429 #if defined(CALLER_SAVES_Hp)
430 callerSaves Hp = True
431 #endif
432 #if defined(CALLER_SAVES_HpLim)
433 callerSaves HpLim = True
434 #endif
435 #if defined(CALLER_SAVES_CCCS)
436 callerSaves CCCS = True
437 #endif
438 #if defined(CALLER_SAVES_CurrentTSO)
439 callerSaves CurrentTSO = True
440 #endif
441 #if defined(CALLER_SAVES_CurrentNursery)
442 callerSaves CurrentNursery = True
443 #endif
444 callerSaves _ = False
445
446 activeStgRegs :: [GlobalReg]
447 activeStgRegs = [
448 #if defined(REG_Base)
449 BaseReg
450 #endif
451 #if defined(REG_Sp)
452 ,Sp
453 #endif
454 #if defined(REG_Hp)
455 ,Hp
456 #endif
457 #if defined(REG_R1)
458 ,VanillaReg 1 VGcPtr
459 #endif
460 #if defined(REG_R2)
461 ,VanillaReg 2 VGcPtr
462 #endif
463 #if defined(REG_R3)
464 ,VanillaReg 3 VGcPtr
465 #endif
466 #if defined(REG_R4)
467 ,VanillaReg 4 VGcPtr
468 #endif
469 #if defined(REG_R5)
470 ,VanillaReg 5 VGcPtr
471 #endif
472 #if defined(REG_R6)
473 ,VanillaReg 6 VGcPtr
474 #endif
475 #if defined(REG_R7)
476 ,VanillaReg 7 VGcPtr
477 #endif
478 #if defined(REG_R8)
479 ,VanillaReg 8 VGcPtr
480 #endif
481 #if defined(REG_R9)
482 ,VanillaReg 9 VGcPtr
483 #endif
484 #if defined(REG_R10)
485 ,VanillaReg 10 VGcPtr
486 #endif
487 #if defined(REG_SpLim)
488 ,SpLim
489 #endif
490 #if MAX_REAL_XMM_REG != 0
491 #if defined(REG_F1)
492 ,FloatReg 1
493 #endif
494 #if defined(REG_D1)
495 ,DoubleReg 1
496 #endif
497 #if defined(REG_XMM1)
498 ,XmmReg 1
499 #endif
500 #if defined(REG_YMM1)
501 ,YmmReg 1
502 #endif
503 #if defined(REG_ZMM1)
504 ,ZmmReg 1
505 #endif
506 #if defined(REG_F2)
507 ,FloatReg 2
508 #endif
509 #if defined(REG_D2)
510 ,DoubleReg 2
511 #endif
512 #if defined(REG_XMM2)
513 ,XmmReg 2
514 #endif
515 #if defined(REG_YMM2)
516 ,YmmReg 2
517 #endif
518 #if defined(REG_ZMM2)
519 ,ZmmReg 2
520 #endif
521 #if defined(REG_F3)
522 ,FloatReg 3
523 #endif
524 #if defined(REG_D3)
525 ,DoubleReg 3
526 #endif
527 #if defined(REG_XMM3)
528 ,XmmReg 3
529 #endif
530 #if defined(REG_YMM3)
531 ,YmmReg 3
532 #endif
533 #if defined(REG_ZMM3)
534 ,ZmmReg 3
535 #endif
536 #if defined(REG_F4)
537 ,FloatReg 4
538 #endif
539 #if defined(REG_D4)
540 ,DoubleReg 4
541 #endif
542 #if defined(REG_XMM4)
543 ,XmmReg 4
544 #endif
545 #if defined(REG_YMM4)
546 ,YmmReg 4
547 #endif
548 #if defined(REG_ZMM4)
549 ,ZmmReg 4
550 #endif
551 #if defined(REG_F5)
552 ,FloatReg 5
553 #endif
554 #if defined(REG_D5)
555 ,DoubleReg 5
556 #endif
557 #if defined(REG_XMM5)
558 ,XmmReg 5
559 #endif
560 #if defined(REG_YMM5)
561 ,YmmReg 5
562 #endif
563 #if defined(REG_ZMM5)
564 ,ZmmReg 5
565 #endif
566 #if defined(REG_F6)
567 ,FloatReg 6
568 #endif
569 #if defined(REG_D6)
570 ,DoubleReg 6
571 #endif
572 #if defined(REG_XMM6)
573 ,XmmReg 6
574 #endif
575 #if defined(REG_YMM6)
576 ,YmmReg 6
577 #endif
578 #if defined(REG_ZMM6)
579 ,ZmmReg 6
580 #endif
581 #else /* MAX_REAL_XMM_REG == 0 */
582 #if defined(REG_F1)
583 ,FloatReg 1
584 #endif
585 #if defined(REG_F2)
586 ,FloatReg 2
587 #endif
588 #if defined(REG_F3)
589 ,FloatReg 3
590 #endif
591 #if defined(REG_F4)
592 ,FloatReg 4
593 #endif
594 #if defined(REG_F5)
595 ,FloatReg 5
596 #endif
597 #if defined(REG_F6)
598 ,FloatReg 6
599 #endif
600 #if defined(REG_D1)
601 ,DoubleReg 1
602 #endif
603 #if defined(REG_D2)
604 ,DoubleReg 2
605 #endif
606 #if defined(REG_D3)
607 ,DoubleReg 3
608 #endif
609 #if defined(REG_D4)
610 ,DoubleReg 4
611 #endif
612 #if defined(REG_D5)
613 ,DoubleReg 5
614 #endif
615 #if defined(REG_D6)
616 ,DoubleReg 6
617 #endif
618 #endif /* MAX_REAL_XMM_REG == 0 */
619 ]
620
621 haveRegBase :: Bool
622 #if defined(REG_Base)
623 haveRegBase = True
624 #else
625 haveRegBase = False
626 #endif
627
628 -- | Returns 'Nothing' if this global register is not stored
629 -- in a real machine register, otherwise returns @'Just' reg@, where
630 -- reg is the machine register it is stored in.
631 globalRegMaybe :: GlobalReg -> Maybe RealReg
632 #if defined(MACHREGS_i386) || defined(MACHREGS_x86_64) \
633 || defined(MACHREGS_sparc) || defined(MACHREGS_powerpc) \
634 || defined(MACHREGS_arm) || defined(MACHREGS_aarch64)
635 # if defined(REG_Base)
636 globalRegMaybe BaseReg = Just (RealRegSingle REG_Base)
637 # endif
638 # if defined(REG_R1)
639 globalRegMaybe (VanillaReg 1 _) = Just (RealRegSingle REG_R1)
640 # endif
641 # if defined(REG_R2)
642 globalRegMaybe (VanillaReg 2 _) = Just (RealRegSingle REG_R2)
643 # endif
644 # if defined(REG_R3)
645 globalRegMaybe (VanillaReg 3 _) = Just (RealRegSingle REG_R3)
646 # endif
647 # if defined(REG_R4)
648 globalRegMaybe (VanillaReg 4 _) = Just (RealRegSingle REG_R4)
649 # endif
650 # if defined(REG_R5)
651 globalRegMaybe (VanillaReg 5 _) = Just (RealRegSingle REG_R5)
652 # endif
653 # if defined(REG_R6)
654 globalRegMaybe (VanillaReg 6 _) = Just (RealRegSingle REG_R6)
655 # endif
656 # if defined(REG_R7)
657 globalRegMaybe (VanillaReg 7 _) = Just (RealRegSingle REG_R7)
658 # endif
659 # if defined(REG_R8)
660 globalRegMaybe (VanillaReg 8 _) = Just (RealRegSingle REG_R8)
661 # endif
662 # if defined(REG_R9)
663 globalRegMaybe (VanillaReg 9 _) = Just (RealRegSingle REG_R9)
664 # endif
665 # if defined(REG_R10)
666 globalRegMaybe (VanillaReg 10 _) = Just (RealRegSingle REG_R10)
667 # endif
668 # if defined(REG_F1)
669 globalRegMaybe (FloatReg 1) = Just (RealRegSingle REG_F1)
670 # endif
671 # if defined(REG_F2)
672 globalRegMaybe (FloatReg 2) = Just (RealRegSingle REG_F2)
673 # endif
674 # if defined(REG_F3)
675 globalRegMaybe (FloatReg 3) = Just (RealRegSingle REG_F3)
676 # endif
677 # if defined(REG_F4)
678 globalRegMaybe (FloatReg 4) = Just (RealRegSingle REG_F4)
679 # endif
680 # if defined(REG_F5)
681 globalRegMaybe (FloatReg 5) = Just (RealRegSingle REG_F5)
682 # endif
683 # if defined(REG_F6)
684 globalRegMaybe (FloatReg 6) = Just (RealRegSingle REG_F6)
685 # endif
686 # if defined(REG_D1)
687 globalRegMaybe (DoubleReg 1) =
688 # if defined(MACHREGS_sparc)
689 Just (RealRegPair REG_D1 (REG_D1 + 1))
690 # else
691 Just (RealRegSingle REG_D1)
692 # endif
693 # endif
694 # if defined(REG_D2)
695 globalRegMaybe (DoubleReg 2) =
696 # if defined(MACHREGS_sparc)
697 Just (RealRegPair REG_D2 (REG_D2 + 1))
698 # else
699 Just (RealRegSingle REG_D2)
700 # endif
701 # endif
702 # if defined(REG_D3)
703 globalRegMaybe (DoubleReg 3) =
704 # if defined(MACHREGS_sparc)
705 Just (RealRegPair REG_D3 (REG_D3 + 1))
706 # else
707 Just (RealRegSingle REG_D3)
708 # endif
709 # endif
710 # if defined(REG_D4)
711 globalRegMaybe (DoubleReg 4) =
712 # if defined(MACHREGS_sparc)
713 Just (RealRegPair REG_D4 (REG_D4 + 1))
714 # else
715 Just (RealRegSingle REG_D4)
716 # endif
717 # endif
718 # if defined(REG_D5)
719 globalRegMaybe (DoubleReg 5) =
720 # if defined(MACHREGS_sparc)
721 Just (RealRegPair REG_D5 (REG_D5 + 1))
722 # else
723 Just (RealRegSingle REG_D5)
724 # endif
725 # endif
726 # if defined(REG_D6)
727 globalRegMaybe (DoubleReg 6) =
728 # if defined(MACHREGS_sparc)
729 Just (RealRegPair REG_D6 (REG_D6 + 1))
730 # else
731 Just (RealRegSingle REG_D6)
732 # endif
733 # endif
734 # if MAX_REAL_XMM_REG != 0
735 # if defined(REG_XMM1)
736 globalRegMaybe (XmmReg 1) = Just (RealRegSingle REG_XMM1)
737 # endif
738 # if defined(REG_XMM2)
739 globalRegMaybe (XmmReg 2) = Just (RealRegSingle REG_XMM2)
740 # endif
741 # if defined(REG_XMM3)
742 globalRegMaybe (XmmReg 3) = Just (RealRegSingle REG_XMM3)
743 # endif
744 # if defined(REG_XMM4)
745 globalRegMaybe (XmmReg 4) = Just (RealRegSingle REG_XMM4)
746 # endif
747 # if defined(REG_XMM5)
748 globalRegMaybe (XmmReg 5) = Just (RealRegSingle REG_XMM5)
749 # endif
750 # if defined(REG_XMM6)
751 globalRegMaybe (XmmReg 6) = Just (RealRegSingle REG_XMM6)
752 # endif
753 # endif
754 # if defined(MAX_REAL_YMM_REG) && MAX_REAL_YMM_REG != 0
755 # if defined(REG_YMM1)
756 globalRegMaybe (YmmReg 1) = Just (RealRegSingle REG_YMM1)
757 # endif
758 # if defined(REG_YMM2)
759 globalRegMaybe (YmmReg 2) = Just (RealRegSingle REG_YMM2)
760 # endif
761 # if defined(REG_YMM3)
762 globalRegMaybe (YmmReg 3) = Just (RealRegSingle REG_YMM3)
763 # endif
764 # if defined(REG_YMM4)
765 globalRegMaybe (YmmReg 4) = Just (RealRegSingle REG_YMM4)
766 # endif
767 # if defined(REG_YMM5)
768 globalRegMaybe (YmmReg 5) = Just (RealRegSingle REG_YMM5)
769 # endif
770 # if defined(REG_YMM6)
771 globalRegMaybe (YmmReg 6) = Just (RealRegSingle REG_YMM6)
772 # endif
773 # endif
774 # if defined(MAX_REAL_ZMM_REG) && MAX_REAL_ZMM_REG != 0
775 # if defined(REG_ZMM1)
776 globalRegMaybe (ZmmReg 1) = Just (RealRegSingle REG_ZMM1)
777 # endif
778 # if defined(REG_ZMM2)
779 globalRegMaybe (ZmmReg 2) = Just (RealRegSingle REG_ZMM2)
780 # endif
781 # if defined(REG_ZMM3)
782 globalRegMaybe (ZmmReg 3) = Just (RealRegSingle REG_ZMM3)
783 # endif
784 # if defined(REG_ZMM4)
785 globalRegMaybe (ZmmReg 4) = Just (RealRegSingle REG_ZMM4)
786 # endif
787 # if defined(REG_ZMM5)
788 globalRegMaybe (ZmmReg 5) = Just (RealRegSingle REG_ZMM5)
789 # endif
790 # if defined(REG_ZMM6)
791 globalRegMaybe (ZmmReg 6) = Just (RealRegSingle REG_ZMM6)
792 # endif
793 # endif
794 # if defined(REG_Sp)
795 globalRegMaybe Sp = Just (RealRegSingle REG_Sp)
796 # endif
797 # if defined(REG_Lng1)
798 globalRegMaybe (LongReg 1) = Just (RealRegSingle REG_Lng1)
799 # endif
800 # if defined(REG_Lng2)
801 globalRegMaybe (LongReg 2) = Just (RealRegSingle REG_Lng2)
802 # endif
803 # if defined(REG_SpLim)
804 globalRegMaybe SpLim = Just (RealRegSingle REG_SpLim)
805 # endif
806 # if defined(REG_Hp)
807 globalRegMaybe Hp = Just (RealRegSingle REG_Hp)
808 # endif
809 # if defined(REG_HpLim)
810 globalRegMaybe HpLim = Just (RealRegSingle REG_HpLim)
811 # endif
812 # if defined(REG_CurrentTSO)
813 globalRegMaybe CurrentTSO = Just (RealRegSingle REG_CurrentTSO)
814 # endif
815 # if defined(REG_CurrentNursery)
816 globalRegMaybe CurrentNursery = Just (RealRegSingle REG_CurrentNursery)
817 # endif
818 # if defined(REG_MachSp)
819 globalRegMaybe MachSp = Just (RealRegSingle REG_MachSp)
820 # endif
821 globalRegMaybe _ = Nothing
822 #elif defined(MACHREGS_NO_REGS)
823 globalRegMaybe _ = Nothing
824 #else
825 globalRegMaybe = panic "globalRegMaybe not defined for this platform"
826 #endif
827
828 freeReg :: RegNo -> Bool
829
830 #if defined(MACHREGS_i386) || defined(MACHREGS_x86_64)
831
832 # if defined(MACHREGS_i386)
833 freeReg esp = False -- %esp is the C stack pointer
834 freeReg esi = False -- Note [esi/edi/ebp not allocatable]
835 freeReg edi = False
836 freeReg ebp = False
837 # endif
838 # if defined(MACHREGS_x86_64)
839 freeReg rsp = False -- %rsp is the C stack pointer
840 # endif
841
842 {-
843 Note [esi/edi/ebp not allocatable]
844
845 %esi is mapped to R1, so %esi would normally be allocatable while it
846 is not being used for R1. However, %esi has no 8-bit version on x86,
847 and the linear register allocator is not sophisticated enough to
848 handle this irregularity (we need more RegClasses). The
849 graph-colouring allocator also cannot handle this - it was designed
850 with more flexibility in mind, but the current implementation is
851 restricted to the same set of classes as the linear allocator.
852
853 Hence, on x86 esi, edi and ebp are treated as not allocatable.
854 -}
855
856 -- split patterns in two functions to prevent overlaps
857 freeReg r = freeRegBase r
858
859 freeRegBase :: RegNo -> Bool
860 # if defined(REG_Base)
861 freeRegBase REG_Base = False
862 # endif
863 # if defined(REG_Sp)
864 freeRegBase REG_Sp = False
865 # endif
866 # if defined(REG_SpLim)
867 freeRegBase REG_SpLim = False
868 # endif
869 # if defined(REG_Hp)
870 freeRegBase REG_Hp = False
871 # endif
872 # if defined(REG_HpLim)
873 freeRegBase REG_HpLim = False
874 # endif
875 -- All other regs are considered to be "free", because we can track
876 -- their liveness accurately.
877 freeRegBase _ = True
878
879 #elif defined(MACHREGS_powerpc)
880
881 freeReg 0 = False -- Used by code setting the back chain pointer
882 -- in stack reallocations on Linux.
883 -- Moreover r0 is not usable in all insns.
884 freeReg 1 = False -- The Stack Pointer
885 -- most ELF PowerPC OSes use r2 as a TOC pointer
886 freeReg 2 = False
887 freeReg 13 = False -- reserved for system thread ID on 64 bit
888 -- at least linux in -fPIC relies on r30 in PLT stubs
889 freeReg 30 = False
890 {- TODO: reserve r13 on 64 bit systems only and r30 on 32 bit respectively.
891 For now we use r30 on 64 bit and r13 on 32 bit as a temporary register
892 in stack handling code. See compiler/nativeGen/PPC/Instr.hs.
893
894 Later we might want to reserve r13 and r30 only where it is required.
895 Then use r12 as temporary register, which is also what the C ABI does.
896 -}
897
898 # if defined(REG_Base)
899 freeReg REG_Base = False
900 # endif
901 # if defined(REG_Sp)
902 freeReg REG_Sp = False
903 # endif
904 # if defined(REG_SpLim)
905 freeReg REG_SpLim = False
906 # endif
907 # if defined(REG_Hp)
908 freeReg REG_Hp = False
909 # endif
910 # if defined(REG_HpLim)
911 freeReg REG_HpLim = False
912 # endif
913 freeReg _ = True
914
915 #elif defined(MACHREGS_sparc)
916
917 -- SPARC regs used by the OS / ABI
918 -- %g0(r0) is always zero
919 freeReg g0 = False
920
921 -- %g5(r5) - %g7(r7)
922 -- are reserved for the OS
923 freeReg g5 = False
924 freeReg g6 = False
925 freeReg g7 = False
926
927 -- %o6(r14)
928 -- is the C stack pointer
929 freeReg o6 = False
930
931 -- %o7(r15)
932 -- holds the C return address
933 freeReg o7 = False
934
935 -- %i6(r30)
936 -- is the C frame pointer
937 freeReg i6 = False
938
939 -- %i7(r31)
940 -- is used for C return addresses
941 freeReg i7 = False
942
943 -- %f0(r32) - %f1(r32)
944 -- are C floating point return regs
945 freeReg f0 = False
946 freeReg f1 = False
947
948 {-
949 freeReg regNo
950 -- don't release high half of double regs
951 | regNo >= f0
952 , regNo < NCG_FirstFloatReg
953 , regNo `mod` 2 /= 0
954 = False
955 -}
956
957 # if defined(REG_Base)
958 freeReg REG_Base = False
959 # endif
960 # if defined(REG_R1)
961 freeReg REG_R1 = False
962 # endif
963 # if defined(REG_R2)
964 freeReg REG_R2 = False
965 # endif
966 # if defined(REG_R3)
967 freeReg REG_R3 = False
968 # endif
969 # if defined(REG_R4)
970 freeReg REG_R4 = False
971 # endif
972 # if defined(REG_R5)
973 freeReg REG_R5 = False
974 # endif
975 # if defined(REG_R6)
976 freeReg REG_R6 = False
977 # endif
978 # if defined(REG_R7)
979 freeReg REG_R7 = False
980 # endif
981 # if defined(REG_R8)
982 freeReg REG_R8 = False
983 # endif
984 # if defined(REG_R9)
985 freeReg REG_R9 = False
986 # endif
987 # if defined(REG_R10)
988 freeReg REG_R10 = False
989 # endif
990 # if defined(REG_F1)
991 freeReg REG_F1 = False
992 # endif
993 # if defined(REG_F2)
994 freeReg REG_F2 = False
995 # endif
996 # if defined(REG_F3)
997 freeReg REG_F3 = False
998 # endif
999 # if defined(REG_F4)
1000 freeReg REG_F4 = False
1001 # endif
1002 # if defined(REG_F5)
1003 freeReg REG_F5 = False
1004 # endif
1005 # if defined(REG_F6)
1006 freeReg REG_F6 = False
1007 # endif
1008 # if defined(REG_D1)
1009 freeReg REG_D1 = False
1010 # endif
1011 # if defined(REG_D1_2)
1012 freeReg REG_D1_2 = False
1013 # endif
1014 # if defined(REG_D2)
1015 freeReg REG_D2 = False
1016 # endif
1017 # if defined(REG_D2_2)
1018 freeReg REG_D2_2 = False
1019 # endif
1020 # if defined(REG_D3)
1021 freeReg REG_D3 = False
1022 # endif
1023 # if defined(REG_D3_2)
1024 freeReg REG_D3_2 = False
1025 # endif
1026 # if defined(REG_D4)
1027 freeReg REG_D4 = False
1028 # endif
1029 # if defined(REG_D4_2)
1030 freeReg REG_D4_2 = False
1031 # endif
1032 # if defined(REG_D5)
1033 freeReg REG_D5 = False
1034 # endif
1035 # if defined(REG_D5_2)
1036 freeReg REG_D5_2 = False
1037 # endif
1038 # if defined(REG_D6)
1039 freeReg REG_D6 = False
1040 # endif
1041 # if defined(REG_D6_2)
1042 freeReg REG_D6_2 = False
1043 # endif
1044 # if defined(REG_Sp)
1045 freeReg REG_Sp = False
1046 # endif
1047 # if defined(REG_SpLim)
1048 freeReg REG_SpLim = False
1049 # endif
1050 # if defined(REG_Hp)
1051 freeReg REG_Hp = False
1052 # endif
1053 # if defined(REG_HpLim)
1054 freeReg REG_HpLim = False
1055 # endif
1056 freeReg _ = True
1057
1058 #else
1059
1060 freeReg = panic "freeReg not defined for this platform"
1061
1062 #endif
1063