aasmllvm.pas 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  1. {
  2. Copyright (c) 1999-2002 by Jonas Maebe
  3. Contains the assembler object for the PowerPC
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit aasmllvm;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. globtype,verbose,
  22. aasmbase,aasmtai,aasmdata,
  23. cpubase,cgbase,cgutils,
  24. symdef,
  25. llvmbase;
  26. type
  27. taillvm = class(tai_cpu_abstract)
  28. // switch_end (= ']'), unreachable
  29. constructor create_llvm(op: tllvmop);
  30. constructor op_none(op : tllvmop);
  31. constructor op_const_reg(op:tllvmop;_size1,_size2:tasmsymbol;_op1: aint; _op2:tregister);
  32. constructor load_ref_reg_align(_type1:tasmsymbol; const ref: treference; reg: tregister; align: aint);
  33. constructor store_reg_ref_align(_type1,_type2:tasmsymbol; reg: tregister; const ref: treference; align: aint);
  34. constructor opcnv_reg_reg_type(op:tllvmop; reg1: tregister; fromtyp: tasmsymbol; reg2: tregister; totyp: tasmsymbol);
  35. constructor op_ressym_string(op: tllvmop; restyp: tasmsymbol; const str: ansistring);
  36. procedure loadstring(opidx:longint;_str: pchar);
  37. llvmopcode: tllvmop;
  38. end;
  39. (*
  40. procedure InitLlvmAsm;
  41. procedure DoneLlvmAsm;
  42. *)
  43. implementation
  44. uses
  45. cutils, cclasses, strings, aasmcpu;
  46. {*****************************************************************************
  47. taicpu Constructors
  48. *****************************************************************************}
  49. constructor taillvm.create_llvm(op: tllvmop);
  50. begin
  51. create(a_none);
  52. llvmopcode:=op;
  53. typ:=ait_llvmins;
  54. end;
  55. procedure taillvm.loadstring(opidx:longint;_str: pchar);
  56. begin
  57. allocate_oper(opidx+1);
  58. with oper[opidx]^ do
  59. begin
  60. if typ<>top_reg then
  61. clearop(opidx);
  62. str:=strnew(_str);
  63. typ:=top_string;
  64. end;
  65. end;
  66. constructor taillvm.op_ressym_string(op: tllvmop; restyp: tasmsymbol; const str: ansistring);
  67. begin
  68. create_llvm(op);
  69. ops:=2;
  70. loadsymbol(0,restyp,0);
  71. loadstring(1,pchar(str));
  72. end;
  73. constructor taillvm.op_none(op : tllvmop);
  74. begin
  75. create_llvm(op);
  76. end;
  77. (*
  78. constructor taicpu.op_reg(op : tllvmop;_op1 : tregister);
  79. begin
  80. inherited create(op);
  81. ops:=1;
  82. loadreg(0,_op1);
  83. end;
  84. constructor taicpu.op_const(op : tllvmop;_op1 : aint);
  85. begin
  86. inherited create(op);
  87. ops:=1;
  88. loadconst(0,_op1);
  89. end;
  90. constructor taicpu.op_reg_reg(op : tllvmop;_op1,_op2 : tregister);
  91. begin
  92. inherited create(op);
  93. ops:=2;
  94. loadreg(0,_op1);
  95. loadreg(1,_op2);
  96. end;
  97. constructor taicpu.op_reg_const(op:tllvmop; _op1: tregister; _op2: aint);
  98. begin
  99. inherited create(op);
  100. ops:=2;
  101. loadreg(0,_op1);
  102. loadconst(1,_op2);
  103. end;
  104. *)
  105. constructor taillvm.op_const_reg(op:tllvmop; _size1, _size2: tasmsymbol; _op1: aint; _op2: tregister);
  106. begin
  107. create_llvm(op);
  108. ops:=4;
  109. loadsymbol(0,_size1,0);
  110. loadconst(1,_op1);
  111. loadsymbol(2,_size2,0);
  112. loadreg(3,_op2);
  113. end;
  114. constructor taillvm.load_ref_reg_align(_type1:tasmsymbol; const ref: treference; reg: tregister; align: aint);
  115. begin
  116. create_llvm(la_load);
  117. ops:=4;
  118. loadreg(0,reg);
  119. loadsymbol(1,_type1,0);
  120. loadref(2,ref);
  121. loadconst(3,align);
  122. end;
  123. constructor taillvm.store_reg_ref_align(_type1,_type2:tasmsymbol; reg: tregister; const ref: treference; align: aint);
  124. begin
  125. create_llvm(la_store);
  126. ops:=5;
  127. loadsymbol(0,_type1,0);
  128. loadreg(1,reg);
  129. loadsymbol(2,_type2,0);
  130. loadref(3,ref);
  131. loadconst(4,align);
  132. end;
  133. constructor taillvm.opcnv_reg_reg_type(op:tllvmop; reg1: tregister; fromtyp: tasmsymbol; reg2: tregister; totyp: tasmsymbol);
  134. begin
  135. create_llvm(op);
  136. ops:=4;
  137. loadreg(0,reg1);
  138. loadsymbol(1,fromtyp,0);
  139. loadreg(2,reg2);
  140. loadsymbol(3,totyp,0);
  141. end;
  142. (*
  143. constructor taicpu.op_reg_ref(op : tllvmop;_op1 : tregister;const _op2 : treference);
  144. begin
  145. inherited create(op);
  146. ops:=2;
  147. loadreg(0,_op1);
  148. loadref(1,_op2);
  149. end;
  150. constructor taicpu.op_const_const(op : tllvmop;_op1,_op2 : aint);
  151. begin
  152. inherited create(op);
  153. ops:=2;
  154. loadconst(0,_op1);
  155. loadconst(1,_op2);
  156. end;
  157. constructor taicpu.op_reg_reg_reg(op : tllvmop;_op1,_op2,_op3 : tregister);
  158. begin
  159. inherited create(op);
  160. ops:=3;
  161. loadreg(0,_op1);
  162. loadreg(1,_op2);
  163. loadreg(2,_op3);
  164. end;
  165. constructor taicpu.op_reg_reg_const(op : tllvmop;_op1,_op2 : tregister; _op3: aint);
  166. begin
  167. inherited create(op);
  168. ops:=3;
  169. loadreg(0,_op1);
  170. loadreg(1,_op2);
  171. loadconst(2,_op3);
  172. end;
  173. constructor taicpu.op_reg_reg_sym_ofs(op : tllvmop;_op1,_op2 : tregister; _op3: tasmsymbol;_op3ofs: aint);
  174. begin
  175. inherited create(op);
  176. ops:=3;
  177. loadreg(0,_op1);
  178. loadreg(1,_op2);
  179. loadsymbol(0,_op3,_op3ofs);
  180. end;
  181. constructor taicpu.op_reg_reg_ref(op : tllvmop;_op1,_op2 : tregister; const _op3: treference);
  182. begin
  183. inherited create(op);
  184. ops:=3;
  185. loadreg(0,_op1);
  186. loadreg(1,_op2);
  187. loadref(2,_op3);
  188. end;
  189. constructor taicpu.op_const_reg_reg(op : tllvmop;_op1 : aint;_op2, _op3 : tregister);
  190. begin
  191. inherited create(op);
  192. ops:=3;
  193. loadconst(0,_op1);
  194. loadreg(1,_op2);
  195. loadreg(2,_op3);
  196. end;
  197. constructor taicpu.op_const_reg_const(op : tllvmop;_op1 : aint;_op2 : tregister;_op3 : aint);
  198. begin
  199. inherited create(op);
  200. ops:=3;
  201. loadconst(0,_op1);
  202. loadreg(1,_op2);
  203. loadconst(2,_op3);
  204. end;
  205. constructor taicpu.op_const_const_const(op : tllvmop;_op1 : aint;_op2 : aint;_op3 : aint);
  206. begin
  207. inherited create(op);
  208. ops:=3;
  209. loadconst(0,_op1);
  210. loadconst(1,_op2);
  211. loadconst(2,_op3);
  212. end;
  213. constructor taicpu.op_reg_reg_reg_reg(op : tllvmop;_op1,_op2,_op3,_op4 : tregister);
  214. begin
  215. inherited create(op);
  216. ops:=4;
  217. loadreg(0,_op1);
  218. loadreg(1,_op2);
  219. loadreg(2,_op3);
  220. loadreg(3,_op4);
  221. end;
  222. constructor taicpu.op_reg_bool_reg_reg(op : tllvmop;_op1: tregister;_op2:boolean;_op3,_op4:tregister);
  223. begin
  224. inherited create(op);
  225. ops:=4;
  226. loadreg(0,_op1);
  227. loadbool(1,_op2);
  228. loadreg(2,_op3);
  229. loadreg(3,_op4);
  230. end;
  231. constructor taicpu.op_reg_bool_reg_const(op : tllvmop;_op1: tregister;_op2:boolean;_op3:tregister;_op4: aint);
  232. begin
  233. inherited create(op);
  234. ops:=4;
  235. loadreg(0,_op1);
  236. loadbool(0,_op2);
  237. loadreg(0,_op3);
  238. loadconst(0,cardinal(_op4));
  239. end;
  240. constructor taicpu.op_reg_reg_reg_const_const(op : tllvmop;_op1,_op2,_op3 : tregister;_op4,_op5 : aint);
  241. begin
  242. inherited create(op);
  243. ops:=5;
  244. loadreg(0,_op1);
  245. loadreg(1,_op2);
  246. loadreg(2,_op3);
  247. loadconst(3,cardinal(_op4));
  248. loadconst(4,cardinal(_op5));
  249. end;
  250. constructor taicpu.op_reg_reg_const_const_const(op : tllvmop;_op1,_op2 : tregister;_op3,_op4,_op5 : aint);
  251. begin
  252. inherited create(op);
  253. ops:=5;
  254. loadreg(0,_op1);
  255. loadreg(1,_op2);
  256. loadconst(2,_op3);
  257. loadconst(3,_op4);
  258. loadconst(4,_op5);
  259. end;
  260. constructor taicpu.op_cond_sym(op : tasmop;cond:TAsmCond;_op1 : tasmsymbol);
  261. begin
  262. inherited create(op);
  263. condition:=cond;
  264. ops:=1;
  265. loadsymbol(0,_op1,0);
  266. end;
  267. constructor taicpu.op_const_const_sym(op : tasmop;_op1,_op2 : aint; _op3: tasmsymbol);
  268. begin
  269. inherited create(op);
  270. ops:=3;
  271. loadconst(0,_op1);
  272. loadconst(1,_op2);
  273. loadsymbol(2,_op3,0);
  274. end;
  275. constructor taicpu.op_sym(op : tasmop;_op1 : tasmsymbol);
  276. begin
  277. inherited create(op);
  278. ops:=1;
  279. loadsymbol(0,_op1,0);
  280. end;
  281. constructor taicpu.op_sym_ofs(op : tasmop;_op1 : tasmsymbol;_op1ofs:aint);
  282. begin
  283. inherited create(op);
  284. ops:=1;
  285. loadsymbol(0,_op1,_op1ofs);
  286. end;
  287. constructor taicpu.op_reg_sym_ofs(op : tasmop;_op1 : tregister;_op2:tasmsymbol;_op2ofs : aint);
  288. begin
  289. inherited create(op);
  290. ops:=2;
  291. loadreg(0,_op1);
  292. loadsymbol(1,_op2,_op2ofs);
  293. end;
  294. constructor taicpu.op_sym_ofs_ref(op : tasmop;_op1 : tasmsymbol;_op1ofs:aint;const _op2 : treference);
  295. begin
  296. inherited create(op);
  297. ops:=2;
  298. loadsymbol(0,_op1,_op1ofs);
  299. loadref(1,_op2);
  300. end;
  301. { ****************************** newra stuff *************************** }
  302. function taicpu.is_same_reg_move(regtype: Tregistertype):boolean;
  303. begin
  304. result :=
  305. (((opcode=A_MR) and
  306. (regtype = R_INTREGISTER)) or
  307. ((opcode = A_FMR) and
  308. (regtype = R_FPUREGISTER))) and
  309. { these opcodes can only have registers as operands }
  310. (oper[0]^.reg=oper[1]^.reg);
  311. end;
  312. function taicpu.spilling_get_operation_type(opnr: aint): topertype;
  313. begin
  314. result := operand_read;
  315. case opcode of
  316. A_STMW,A_LMW:
  317. internalerror(2005021805);
  318. A_STBU, A_STBUX, A_STHU, A_STHUX, A_STWU, A_STWUX, A_STFSU, A_STFSUX, A_STFDU, A_STFDUX, A_STB, A_STBX, A_STH, A_STHX, A_STW, A_STWX, A_STFS, A_STFSX, A_STFD, A_STFDX, A_STFIWX, A_STHBRX, A_STWBRX, A_STWCX_, A_CMP, A_CMPI, A_CMPL, A_CMPLI, A_DCBA, A_DCBI, A_DCBST, A_DCBT, A_DCBTST, A_DCBZ, A_ECOWX, A_FCMPO, A_FCMPU, A_MTMSR, A_TLBIE, A_TW, A_TWI, A_CMPWI, A_CMPW, A_CMPLWI, A_CMPLW, A_MT, A_MTLR, A_MTCTR:;
  319. A_RLWIMI:
  320. if opnr = 0 then
  321. result := operand_readwrite;
  322. else
  323. if opnr = 0 then
  324. result := operand_write;
  325. end;
  326. end;
  327. function taicpu.spilling_get_operation_type_ref(opnr: aint; reg: tregister): topertype;
  328. begin
  329. result := operand_read;
  330. case opcode of
  331. A_STBU, A_STBUX, A_STHU, A_STHUX, A_STWU, A_STWUX, A_STFSU, A_STFSUX, A_STFDU, A_STFDUX:
  332. if (oper[opnr]^.ref^.base = reg) then
  333. result := operand_readwrite;
  334. end;
  335. end;
  336. function spilling_create_load(const ref:treference;r:tregister): tai;
  337. begin
  338. case getregtype(r) of
  339. R_INTREGISTER:
  340. result:=taicpu.op_reg_ref(A_LWZ,r,ref);
  341. R_FPUREGISTER:
  342. result:=taicpu.op_reg_ref(A_LFD,r,ref);
  343. else
  344. internalerror(2005123101);
  345. end;
  346. end;
  347. function spilling_create_store(r:tregister; const ref:treference): tai;
  348. begin
  349. case getregtype(r) of
  350. R_INTREGISTER:
  351. result:=taicpu.op_reg_ref(A_STW,r,ref);
  352. R_FPUREGISTER:
  353. result:=taicpu.op_reg_ref(A_STFD,r,ref);
  354. else
  355. internalerror(2005123102);
  356. end;
  357. end;
  358. procedure InitAsm;
  359. begin
  360. end;
  361. procedure DoneAsm;
  362. begin
  363. end;
  364. *)
  365. end.