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