xref: /freebsd/contrib/llvm-project/llvm/lib/ExecutionEngine/JITLink/ppc64.cpp (revision 5f757f3ff9144b609b3c433dfd370cc6bdc191ad)
1 //===----- ppc64.cpp - Generic JITLink ppc64 edge kinds, utilities ------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // Generic utilities for graphs representing 64-bit PowerPC objects.
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #include "llvm/ExecutionEngine/JITLink/ppc64.h"
14 
15 #define DEBUG_TYPE "jitlink"
16 
17 namespace llvm::jitlink::ppc64 {
18 
19 const char NullPointerContent[8] = {0x00, 0x00, 0x00, 0x00,
20                                     0x00, 0x00, 0x00, 0x00};
21 
22 const char PointerJumpStubContent_little[20] = {
23     0x18,       0x00, 0x41,       (char)0xf8, // std r2, 24(r1)
24     0x00,       0x00, (char)0x82, 0x3d,       // addis r12, r2, OffHa
25     0x00,       0x00, (char)0x8c, (char)0xe9, // ld r12, OffLo(r12)
26     (char)0xa6, 0x03, (char)0x89, 0x7d,       // mtctr r12
27     0x20,       0x04, (char)0x80, 0x4e,       // bctr
28 };
29 
30 const char PointerJumpStubContent_big[20] = {
31     (char)0xf8, 0x41,       0x00, 0x18,       // std r2, 24(r1)
32     0x3d,       (char)0x82, 0x00, 0x00,       // addis r12, r2, OffHa
33     (char)0xe9, (char)0x8c, 0x00, 0x00,       // ld r12, OffLo(r12)
34     0x7d,       (char)0x89, 0x03, (char)0xa6, // mtctr r12
35     0x4e,       (char)0x80, 0x04, 0x20,       // bctr
36 };
37 
38 // TODO: We can use prefixed instructions if LLJIT is running on power10.
39 const char PointerJumpStubNoTOCContent_little[32] = {
40     (char)0xa6, 0x02,       (char)0x88, 0x7d,       // mflr 12
41     0x05,       (char)0x00, (char)0x9f, 0x42,       // bcl 20,31,.+4
42     (char)0xa6, 0x02,       0x68,       0x7d,       // mflr 11
43     (char)0xa6, 0x03,       (char)0x88, 0x7d,       // mtlr 12
44     0x00,       0x00,       (char)0x8b, 0x3d,       // addis 12,11,OffHa
45     0x00,       0x00,       (char)0x8c, (char)0xe9, // ld 12, OffLo(12)
46     (char)0xa6, 0x03,       (char)0x89, 0x7d,       // mtctr 12
47     0x20,       0x04,       (char)0x80, 0x4e,       // bctr
48 };
49 
50 const char PointerJumpStubNoTOCContent_big[32] = {
51     0x7d,       (char)0x88, 0x02, (char)0xa6, // mflr 12
52     0x42,       (char)0x9f, 0x00, 0x05,       // bcl 20,31,.+4
53     0x7d,       0x68,       0x02, (char)0xa6, // mflr 11
54     0x7d,       (char)0x88, 0x03, (char)0xa6, // mtlr 12
55     0x3d,       (char)0x8b, 0x00, 0x00,       // addis 12,11,OffHa
56     (char)0xe9, (char)0x8c, 0x00, 0x00,       // ld 12, OffLo(12)
57     0x7d,       (char)0x89, 0x03, (char)0xa6, // mtctr 12
58     0x4e,       (char)0x80, 0x04, 0x20,       // bctr
59 };
60 
61 const char *getEdgeKindName(Edge::Kind K) {
62   switch (K) {
63   case Pointer64:
64     return "Pointer64";
65   case Pointer32:
66     return "Pointer32";
67   case Pointer16:
68     return "Pointer16";
69   case Pointer16DS:
70     return "Pointer16DS";
71   case Pointer16HA:
72     return "Pointer16HA";
73   case Pointer16HI:
74     return "Pointer16HI";
75   case Pointer16HIGH:
76     return "Pointer16HIGH";
77   case Pointer16HIGHA:
78     return "Pointer16HIGHA";
79   case Pointer16HIGHER:
80     return "Pointer16HIGHER";
81   case Pointer16HIGHERA:
82     return "Pointer16HIGHERA";
83   case Pointer16HIGHEST:
84     return "Pointer16HIGHEST";
85   case Pointer16HIGHESTA:
86     return "Pointer16HIGHESTA";
87   case Pointer16LO:
88     return "Pointer16LO";
89   case Pointer16LODS:
90     return "Pointer16LODS";
91   case Pointer14:
92     return "Pointer14";
93   case Delta64:
94     return "Delta64";
95   case Delta34:
96     return "Delta34";
97   case Delta32:
98     return "Delta32";
99   case NegDelta32:
100     return "NegDelta32";
101   case Delta16:
102     return "Delta16";
103   case Delta16HA:
104     return "Delta16HA";
105   case Delta16HI:
106     return "Delta16HI";
107   case Delta16LO:
108     return "Delta16LO";
109   case TOC:
110     return "TOC";
111   case TOCDelta16:
112     return "TOCDelta16";
113   case TOCDelta16DS:
114     return "TOCDelta16DS";
115   case TOCDelta16HA:
116     return "TOCDelta16HA";
117   case TOCDelta16HI:
118     return "TOCDelta16HI";
119   case TOCDelta16LO:
120     return "TOCDelta16LO";
121   case TOCDelta16LODS:
122     return "TOCDelta16LODS";
123   case RequestGOTAndTransformToDelta34:
124     return "RequestGOTAndTransformToDelta34";
125   case CallBranchDelta:
126     return "CallBranchDelta";
127   case CallBranchDeltaRestoreTOC:
128     return "CallBranchDeltaRestoreTOC";
129   case RequestCall:
130     return "RequestCall";
131   case RequestCallNoTOC:
132     return "RequestCallNoTOC";
133   case RequestTLSDescInGOTAndTransformToTOCDelta16HA:
134     return "RequestTLSDescInGOTAndTransformToTOCDelta16HA";
135   case RequestTLSDescInGOTAndTransformToTOCDelta16LO:
136     return "RequestTLSDescInGOTAndTransformToTOCDelta16LO";
137   case RequestTLSDescInGOTAndTransformToDelta34:
138     return "RequestTLSDescInGOTAndTransformToDelta34";
139   default:
140     return getGenericEdgeKindName(static_cast<Edge::Kind>(K));
141   }
142 }
143 
144 } // end namespace llvm::jitlink::ppc64
145