TargetLoweringBase.cpp 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309
  1. //===-- TargetLoweringBase.cpp - Implement the TargetLoweringBase class ---===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This implements the TargetLoweringBase class.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #include "llvm/Target/TargetLowering.h"
  14. #include "llvm/ADT/BitVector.h"
  15. #include "llvm/ADT/STLExtras.h"
  16. #include "llvm/ADT/Triple.h"
  17. #include "llvm/CodeGen/Analysis.h"
  18. #include "llvm/CodeGen/MachineFrameInfo.h"
  19. #include "llvm/CodeGen/MachineFunction.h"
  20. #include "llvm/CodeGen/MachineJumpTableInfo.h"
  21. #include "llvm/IR/DataLayout.h"
  22. #include "llvm/IR/DerivedTypes.h"
  23. #include "llvm/IR/GlobalVariable.h"
  24. #include "llvm/MC/MCAsmInfo.h"
  25. #include "llvm/MC/MCExpr.h"
  26. #include "llvm/Support/CommandLine.h"
  27. #include "llvm/Support/ErrorHandling.h"
  28. #include "llvm/Support/MathExtras.h"
  29. #include "llvm/Target/TargetLoweringObjectFile.h"
  30. #include "llvm/Target/TargetMachine.h"
  31. #include "llvm/Target/TargetRegisterInfo.h"
  32. #include <cctype>
  33. using namespace llvm;
  34. /// InitLibcallNames - Set default libcall names.
  35. ///
  36. static void InitLibcallNames(const char **Names, const TargetMachine &TM) {
  37. Names[RTLIB::SHL_I16] = "__ashlhi3";
  38. Names[RTLIB::SHL_I32] = "__ashlsi3";
  39. Names[RTLIB::SHL_I64] = "__ashldi3";
  40. Names[RTLIB::SHL_I128] = "__ashlti3";
  41. Names[RTLIB::SRL_I16] = "__lshrhi3";
  42. Names[RTLIB::SRL_I32] = "__lshrsi3";
  43. Names[RTLIB::SRL_I64] = "__lshrdi3";
  44. Names[RTLIB::SRL_I128] = "__lshrti3";
  45. Names[RTLIB::SRA_I16] = "__ashrhi3";
  46. Names[RTLIB::SRA_I32] = "__ashrsi3";
  47. Names[RTLIB::SRA_I64] = "__ashrdi3";
  48. Names[RTLIB::SRA_I128] = "__ashrti3";
  49. Names[RTLIB::MUL_I8] = "__mulqi3";
  50. Names[RTLIB::MUL_I16] = "__mulhi3";
  51. Names[RTLIB::MUL_I32] = "__mulsi3";
  52. Names[RTLIB::MUL_I64] = "__muldi3";
  53. Names[RTLIB::MUL_I128] = "__multi3";
  54. Names[RTLIB::MULO_I32] = "__mulosi4";
  55. Names[RTLIB::MULO_I64] = "__mulodi4";
  56. Names[RTLIB::MULO_I128] = "__muloti4";
  57. Names[RTLIB::SDIV_I8] = "__divqi3";
  58. Names[RTLIB::SDIV_I16] = "__divhi3";
  59. Names[RTLIB::SDIV_I32] = "__divsi3";
  60. Names[RTLIB::SDIV_I64] = "__divdi3";
  61. Names[RTLIB::SDIV_I128] = "__divti3";
  62. Names[RTLIB::UDIV_I8] = "__udivqi3";
  63. Names[RTLIB::UDIV_I16] = "__udivhi3";
  64. Names[RTLIB::UDIV_I32] = "__udivsi3";
  65. Names[RTLIB::UDIV_I64] = "__udivdi3";
  66. Names[RTLIB::UDIV_I128] = "__udivti3";
  67. Names[RTLIB::SREM_I8] = "__modqi3";
  68. Names[RTLIB::SREM_I16] = "__modhi3";
  69. Names[RTLIB::SREM_I32] = "__modsi3";
  70. Names[RTLIB::SREM_I64] = "__moddi3";
  71. Names[RTLIB::SREM_I128] = "__modti3";
  72. Names[RTLIB::UREM_I8] = "__umodqi3";
  73. Names[RTLIB::UREM_I16] = "__umodhi3";
  74. Names[RTLIB::UREM_I32] = "__umodsi3";
  75. Names[RTLIB::UREM_I64] = "__umoddi3";
  76. Names[RTLIB::UREM_I128] = "__umodti3";
  77. // These are generally not available.
  78. Names[RTLIB::SDIVREM_I8] = 0;
  79. Names[RTLIB::SDIVREM_I16] = 0;
  80. Names[RTLIB::SDIVREM_I32] = 0;
  81. Names[RTLIB::SDIVREM_I64] = 0;
  82. Names[RTLIB::SDIVREM_I128] = 0;
  83. Names[RTLIB::UDIVREM_I8] = 0;
  84. Names[RTLIB::UDIVREM_I16] = 0;
  85. Names[RTLIB::UDIVREM_I32] = 0;
  86. Names[RTLIB::UDIVREM_I64] = 0;
  87. Names[RTLIB::UDIVREM_I128] = 0;
  88. Names[RTLIB::NEG_I32] = "__negsi2";
  89. Names[RTLIB::NEG_I64] = "__negdi2";
  90. Names[RTLIB::ADD_F32] = "__addsf3";
  91. Names[RTLIB::ADD_F64] = "__adddf3";
  92. Names[RTLIB::ADD_F80] = "__addxf3";
  93. Names[RTLIB::ADD_F128] = "__addtf3";
  94. Names[RTLIB::ADD_PPCF128] = "__gcc_qadd";
  95. Names[RTLIB::SUB_F32] = "__subsf3";
  96. Names[RTLIB::SUB_F64] = "__subdf3";
  97. Names[RTLIB::SUB_F80] = "__subxf3";
  98. Names[RTLIB::SUB_F128] = "__subtf3";
  99. Names[RTLIB::SUB_PPCF128] = "__gcc_qsub";
  100. Names[RTLIB::MUL_F32] = "__mulsf3";
  101. Names[RTLIB::MUL_F64] = "__muldf3";
  102. Names[RTLIB::MUL_F80] = "__mulxf3";
  103. Names[RTLIB::MUL_F128] = "__multf3";
  104. Names[RTLIB::MUL_PPCF128] = "__gcc_qmul";
  105. Names[RTLIB::DIV_F32] = "__divsf3";
  106. Names[RTLIB::DIV_F64] = "__divdf3";
  107. Names[RTLIB::DIV_F80] = "__divxf3";
  108. Names[RTLIB::DIV_F128] = "__divtf3";
  109. Names[RTLIB::DIV_PPCF128] = "__gcc_qdiv";
  110. Names[RTLIB::REM_F32] = "fmodf";
  111. Names[RTLIB::REM_F64] = "fmod";
  112. Names[RTLIB::REM_F80] = "fmodl";
  113. Names[RTLIB::REM_F128] = "fmodl";
  114. Names[RTLIB::REM_PPCF128] = "fmodl";
  115. Names[RTLIB::FMA_F32] = "fmaf";
  116. Names[RTLIB::FMA_F64] = "fma";
  117. Names[RTLIB::FMA_F80] = "fmal";
  118. Names[RTLIB::FMA_F128] = "fmal";
  119. Names[RTLIB::FMA_PPCF128] = "fmal";
  120. Names[RTLIB::POWI_F32] = "__powisf2";
  121. Names[RTLIB::POWI_F64] = "__powidf2";
  122. Names[RTLIB::POWI_F80] = "__powixf2";
  123. Names[RTLIB::POWI_F128] = "__powitf2";
  124. Names[RTLIB::POWI_PPCF128] = "__powitf2";
  125. Names[RTLIB::SQRT_F32] = "sqrtf";
  126. Names[RTLIB::SQRT_F64] = "sqrt";
  127. Names[RTLIB::SQRT_F80] = "sqrtl";
  128. Names[RTLIB::SQRT_F128] = "sqrtl";
  129. Names[RTLIB::SQRT_PPCF128] = "sqrtl";
  130. Names[RTLIB::LOG_F32] = "logf";
  131. Names[RTLIB::LOG_F64] = "log";
  132. Names[RTLIB::LOG_F80] = "logl";
  133. Names[RTLIB::LOG_F128] = "logl";
  134. Names[RTLIB::LOG_PPCF128] = "logl";
  135. Names[RTLIB::LOG2_F32] = "log2f";
  136. Names[RTLIB::LOG2_F64] = "log2";
  137. Names[RTLIB::LOG2_F80] = "log2l";
  138. Names[RTLIB::LOG2_F128] = "log2l";
  139. Names[RTLIB::LOG2_PPCF128] = "log2l";
  140. Names[RTLIB::LOG10_F32] = "log10f";
  141. Names[RTLIB::LOG10_F64] = "log10";
  142. Names[RTLIB::LOG10_F80] = "log10l";
  143. Names[RTLIB::LOG10_F128] = "log10l";
  144. Names[RTLIB::LOG10_PPCF128] = "log10l";
  145. Names[RTLIB::EXP_F32] = "expf";
  146. Names[RTLIB::EXP_F64] = "exp";
  147. Names[RTLIB::EXP_F80] = "expl";
  148. Names[RTLIB::EXP_F128] = "expl";
  149. Names[RTLIB::EXP_PPCF128] = "expl";
  150. Names[RTLIB::EXP2_F32] = "exp2f";
  151. Names[RTLIB::EXP2_F64] = "exp2";
  152. Names[RTLIB::EXP2_F80] = "exp2l";
  153. Names[RTLIB::EXP2_F128] = "exp2l";
  154. Names[RTLIB::EXP2_PPCF128] = "exp2l";
  155. Names[RTLIB::SIN_F32] = "sinf";
  156. Names[RTLIB::SIN_F64] = "sin";
  157. Names[RTLIB::SIN_F80] = "sinl";
  158. Names[RTLIB::SIN_F128] = "sinl";
  159. Names[RTLIB::SIN_PPCF128] = "sinl";
  160. Names[RTLIB::COS_F32] = "cosf";
  161. Names[RTLIB::COS_F64] = "cos";
  162. Names[RTLIB::COS_F80] = "cosl";
  163. Names[RTLIB::COS_F128] = "cosl";
  164. Names[RTLIB::COS_PPCF128] = "cosl";
  165. Names[RTLIB::POW_F32] = "powf";
  166. Names[RTLIB::POW_F64] = "pow";
  167. Names[RTLIB::POW_F80] = "powl";
  168. Names[RTLIB::POW_F128] = "powl";
  169. Names[RTLIB::POW_PPCF128] = "powl";
  170. Names[RTLIB::CEIL_F32] = "ceilf";
  171. Names[RTLIB::CEIL_F64] = "ceil";
  172. Names[RTLIB::CEIL_F80] = "ceill";
  173. Names[RTLIB::CEIL_F128] = "ceill";
  174. Names[RTLIB::CEIL_PPCF128] = "ceill";
  175. Names[RTLIB::TRUNC_F32] = "truncf";
  176. Names[RTLIB::TRUNC_F64] = "trunc";
  177. Names[RTLIB::TRUNC_F80] = "truncl";
  178. Names[RTLIB::TRUNC_F128] = "truncl";
  179. Names[RTLIB::TRUNC_PPCF128] = "truncl";
  180. Names[RTLIB::RINT_F32] = "rintf";
  181. Names[RTLIB::RINT_F64] = "rint";
  182. Names[RTLIB::RINT_F80] = "rintl";
  183. Names[RTLIB::RINT_F128] = "rintl";
  184. Names[RTLIB::RINT_PPCF128] = "rintl";
  185. Names[RTLIB::NEARBYINT_F32] = "nearbyintf";
  186. Names[RTLIB::NEARBYINT_F64] = "nearbyint";
  187. Names[RTLIB::NEARBYINT_F80] = "nearbyintl";
  188. Names[RTLIB::NEARBYINT_F128] = "nearbyintl";
  189. Names[RTLIB::NEARBYINT_PPCF128] = "nearbyintl";
  190. Names[RTLIB::FLOOR_F32] = "floorf";
  191. Names[RTLIB::FLOOR_F64] = "floor";
  192. Names[RTLIB::FLOOR_F80] = "floorl";
  193. Names[RTLIB::FLOOR_F128] = "floorl";
  194. Names[RTLIB::FLOOR_PPCF128] = "floorl";
  195. Names[RTLIB::COPYSIGN_F32] = "copysignf";
  196. Names[RTLIB::COPYSIGN_F64] = "copysign";
  197. Names[RTLIB::COPYSIGN_F80] = "copysignl";
  198. Names[RTLIB::COPYSIGN_F128] = "copysignl";
  199. Names[RTLIB::COPYSIGN_PPCF128] = "copysignl";
  200. Names[RTLIB::FPEXT_F64_F128] = "__extenddftf2";
  201. Names[RTLIB::FPEXT_F32_F128] = "__extendsftf2";
  202. Names[RTLIB::FPEXT_F32_F64] = "__extendsfdf2";
  203. Names[RTLIB::FPEXT_F16_F32] = "__gnu_h2f_ieee";
  204. Names[RTLIB::FPROUND_F32_F16] = "__gnu_f2h_ieee";
  205. Names[RTLIB::FPROUND_F64_F32] = "__truncdfsf2";
  206. Names[RTLIB::FPROUND_F80_F32] = "__truncxfsf2";
  207. Names[RTLIB::FPROUND_F128_F32] = "__trunctfsf2";
  208. Names[RTLIB::FPROUND_PPCF128_F32] = "__trunctfsf2";
  209. Names[RTLIB::FPROUND_F80_F64] = "__truncxfdf2";
  210. Names[RTLIB::FPROUND_F128_F64] = "__trunctfdf2";
  211. Names[RTLIB::FPROUND_PPCF128_F64] = "__trunctfdf2";
  212. Names[RTLIB::FPTOSINT_F32_I8] = "__fixsfqi";
  213. Names[RTLIB::FPTOSINT_F32_I16] = "__fixsfhi";
  214. Names[RTLIB::FPTOSINT_F32_I32] = "__fixsfsi";
  215. Names[RTLIB::FPTOSINT_F32_I64] = "__fixsfdi";
  216. Names[RTLIB::FPTOSINT_F32_I128] = "__fixsfti";
  217. Names[RTLIB::FPTOSINT_F64_I8] = "__fixdfqi";
  218. Names[RTLIB::FPTOSINT_F64_I16] = "__fixdfhi";
  219. Names[RTLIB::FPTOSINT_F64_I32] = "__fixdfsi";
  220. Names[RTLIB::FPTOSINT_F64_I64] = "__fixdfdi";
  221. Names[RTLIB::FPTOSINT_F64_I128] = "__fixdfti";
  222. Names[RTLIB::FPTOSINT_F80_I32] = "__fixxfsi";
  223. Names[RTLIB::FPTOSINT_F80_I64] = "__fixxfdi";
  224. Names[RTLIB::FPTOSINT_F80_I128] = "__fixxfti";
  225. Names[RTLIB::FPTOSINT_F128_I32] = "__fixtfsi";
  226. Names[RTLIB::FPTOSINT_F128_I64] = "__fixtfdi";
  227. Names[RTLIB::FPTOSINT_F128_I128] = "__fixtfti";
  228. Names[RTLIB::FPTOSINT_PPCF128_I32] = "__fixtfsi";
  229. Names[RTLIB::FPTOSINT_PPCF128_I64] = "__fixtfdi";
  230. Names[RTLIB::FPTOSINT_PPCF128_I128] = "__fixtfti";
  231. Names[RTLIB::FPTOUINT_F32_I8] = "__fixunssfqi";
  232. Names[RTLIB::FPTOUINT_F32_I16] = "__fixunssfhi";
  233. Names[RTLIB::FPTOUINT_F32_I32] = "__fixunssfsi";
  234. Names[RTLIB::FPTOUINT_F32_I64] = "__fixunssfdi";
  235. Names[RTLIB::FPTOUINT_F32_I128] = "__fixunssfti";
  236. Names[RTLIB::FPTOUINT_F64_I8] = "__fixunsdfqi";
  237. Names[RTLIB::FPTOUINT_F64_I16] = "__fixunsdfhi";
  238. Names[RTLIB::FPTOUINT_F64_I32] = "__fixunsdfsi";
  239. Names[RTLIB::FPTOUINT_F64_I64] = "__fixunsdfdi";
  240. Names[RTLIB::FPTOUINT_F64_I128] = "__fixunsdfti";
  241. Names[RTLIB::FPTOUINT_F80_I32] = "__fixunsxfsi";
  242. Names[RTLIB::FPTOUINT_F80_I64] = "__fixunsxfdi";
  243. Names[RTLIB::FPTOUINT_F80_I128] = "__fixunsxfti";
  244. Names[RTLIB::FPTOUINT_F128_I32] = "__fixunstfsi";
  245. Names[RTLIB::FPTOUINT_F128_I64] = "__fixunstfdi";
  246. Names[RTLIB::FPTOUINT_F128_I128] = "__fixunstfti";
  247. Names[RTLIB::FPTOUINT_PPCF128_I32] = "__fixunstfsi";
  248. Names[RTLIB::FPTOUINT_PPCF128_I64] = "__fixunstfdi";
  249. Names[RTLIB::FPTOUINT_PPCF128_I128] = "__fixunstfti";
  250. Names[RTLIB::SINTTOFP_I32_F32] = "__floatsisf";
  251. Names[RTLIB::SINTTOFP_I32_F64] = "__floatsidf";
  252. Names[RTLIB::SINTTOFP_I32_F80] = "__floatsixf";
  253. Names[RTLIB::SINTTOFP_I32_F128] = "__floatsitf";
  254. Names[RTLIB::SINTTOFP_I32_PPCF128] = "__floatsitf";
  255. Names[RTLIB::SINTTOFP_I64_F32] = "__floatdisf";
  256. Names[RTLIB::SINTTOFP_I64_F64] = "__floatdidf";
  257. Names[RTLIB::SINTTOFP_I64_F80] = "__floatdixf";
  258. Names[RTLIB::SINTTOFP_I64_F128] = "__floatditf";
  259. Names[RTLIB::SINTTOFP_I64_PPCF128] = "__floatditf";
  260. Names[RTLIB::SINTTOFP_I128_F32] = "__floattisf";
  261. Names[RTLIB::SINTTOFP_I128_F64] = "__floattidf";
  262. Names[RTLIB::SINTTOFP_I128_F80] = "__floattixf";
  263. Names[RTLIB::SINTTOFP_I128_F128] = "__floattitf";
  264. Names[RTLIB::SINTTOFP_I128_PPCF128] = "__floattitf";
  265. Names[RTLIB::UINTTOFP_I32_F32] = "__floatunsisf";
  266. Names[RTLIB::UINTTOFP_I32_F64] = "__floatunsidf";
  267. Names[RTLIB::UINTTOFP_I32_F80] = "__floatunsixf";
  268. Names[RTLIB::UINTTOFP_I32_F128] = "__floatunsitf";
  269. Names[RTLIB::UINTTOFP_I32_PPCF128] = "__floatunsitf";
  270. Names[RTLIB::UINTTOFP_I64_F32] = "__floatundisf";
  271. Names[RTLIB::UINTTOFP_I64_F64] = "__floatundidf";
  272. Names[RTLIB::UINTTOFP_I64_F80] = "__floatundixf";
  273. Names[RTLIB::UINTTOFP_I64_F128] = "__floatunditf";
  274. Names[RTLIB::UINTTOFP_I64_PPCF128] = "__floatunditf";
  275. Names[RTLIB::UINTTOFP_I128_F32] = "__floatuntisf";
  276. Names[RTLIB::UINTTOFP_I128_F64] = "__floatuntidf";
  277. Names[RTLIB::UINTTOFP_I128_F80] = "__floatuntixf";
  278. Names[RTLIB::UINTTOFP_I128_F128] = "__floatuntitf";
  279. Names[RTLIB::UINTTOFP_I128_PPCF128] = "__floatuntitf";
  280. Names[RTLIB::OEQ_F32] = "__eqsf2";
  281. Names[RTLIB::OEQ_F64] = "__eqdf2";
  282. Names[RTLIB::OEQ_F128] = "__eqtf2";
  283. Names[RTLIB::UNE_F32] = "__nesf2";
  284. Names[RTLIB::UNE_F64] = "__nedf2";
  285. Names[RTLIB::UNE_F128] = "__netf2";
  286. Names[RTLIB::OGE_F32] = "__gesf2";
  287. Names[RTLIB::OGE_F64] = "__gedf2";
  288. Names[RTLIB::OGE_F128] = "__getf2";
  289. Names[RTLIB::OLT_F32] = "__ltsf2";
  290. Names[RTLIB::OLT_F64] = "__ltdf2";
  291. Names[RTLIB::OLT_F128] = "__lttf2";
  292. Names[RTLIB::OLE_F32] = "__lesf2";
  293. Names[RTLIB::OLE_F64] = "__ledf2";
  294. Names[RTLIB::OLE_F128] = "__letf2";
  295. Names[RTLIB::OGT_F32] = "__gtsf2";
  296. Names[RTLIB::OGT_F64] = "__gtdf2";
  297. Names[RTLIB::OGT_F128] = "__gttf2";
  298. Names[RTLIB::UO_F32] = "__unordsf2";
  299. Names[RTLIB::UO_F64] = "__unorddf2";
  300. Names[RTLIB::UO_F128] = "__unordtf2";
  301. Names[RTLIB::O_F32] = "__unordsf2";
  302. Names[RTLIB::O_F64] = "__unorddf2";
  303. Names[RTLIB::O_F128] = "__unordtf2";
  304. Names[RTLIB::MEMCPY] = "memcpy";
  305. Names[RTLIB::MEMMOVE] = "memmove";
  306. Names[RTLIB::MEMSET] = "memset";
  307. Names[RTLIB::UNWIND_RESUME] = "_Unwind_Resume";
  308. Names[RTLIB::SYNC_VAL_COMPARE_AND_SWAP_1] = "__sync_val_compare_and_swap_1";
  309. Names[RTLIB::SYNC_VAL_COMPARE_AND_SWAP_2] = "__sync_val_compare_and_swap_2";
  310. Names[RTLIB::SYNC_VAL_COMPARE_AND_SWAP_4] = "__sync_val_compare_and_swap_4";
  311. Names[RTLIB::SYNC_VAL_COMPARE_AND_SWAP_8] = "__sync_val_compare_and_swap_8";
  312. Names[RTLIB::SYNC_LOCK_TEST_AND_SET_1] = "__sync_lock_test_and_set_1";
  313. Names[RTLIB::SYNC_LOCK_TEST_AND_SET_2] = "__sync_lock_test_and_set_2";
  314. Names[RTLIB::SYNC_LOCK_TEST_AND_SET_4] = "__sync_lock_test_and_set_4";
  315. Names[RTLIB::SYNC_LOCK_TEST_AND_SET_8] = "__sync_lock_test_and_set_8";
  316. Names[RTLIB::SYNC_FETCH_AND_ADD_1] = "__sync_fetch_and_add_1";
  317. Names[RTLIB::SYNC_FETCH_AND_ADD_2] = "__sync_fetch_and_add_2";
  318. Names[RTLIB::SYNC_FETCH_AND_ADD_4] = "__sync_fetch_and_add_4";
  319. Names[RTLIB::SYNC_FETCH_AND_ADD_8] = "__sync_fetch_and_add_8";
  320. Names[RTLIB::SYNC_FETCH_AND_SUB_1] = "__sync_fetch_and_sub_1";
  321. Names[RTLIB::SYNC_FETCH_AND_SUB_2] = "__sync_fetch_and_sub_2";
  322. Names[RTLIB::SYNC_FETCH_AND_SUB_4] = "__sync_fetch_and_sub_4";
  323. Names[RTLIB::SYNC_FETCH_AND_SUB_8] = "__sync_fetch_and_sub_8";
  324. Names[RTLIB::SYNC_FETCH_AND_AND_1] = "__sync_fetch_and_and_1";
  325. Names[RTLIB::SYNC_FETCH_AND_AND_2] = "__sync_fetch_and_and_2";
  326. Names[RTLIB::SYNC_FETCH_AND_AND_4] = "__sync_fetch_and_and_4";
  327. Names[RTLIB::SYNC_FETCH_AND_AND_8] = "__sync_fetch_and_and_8";
  328. Names[RTLIB::SYNC_FETCH_AND_OR_1] = "__sync_fetch_and_or_1";
  329. Names[RTLIB::SYNC_FETCH_AND_OR_2] = "__sync_fetch_and_or_2";
  330. Names[RTLIB::SYNC_FETCH_AND_OR_4] = "__sync_fetch_and_or_4";
  331. Names[RTLIB::SYNC_FETCH_AND_OR_8] = "__sync_fetch_and_or_8";
  332. Names[RTLIB::SYNC_FETCH_AND_XOR_1] = "__sync_fetch_and_xor_1";
  333. Names[RTLIB::SYNC_FETCH_AND_XOR_2] = "__sync_fetch_and_xor_2";
  334. Names[RTLIB::SYNC_FETCH_AND_XOR_4] = "__sync_fetch_and_xor_4";
  335. Names[RTLIB::SYNC_FETCH_AND_XOR_8] = "__sync_fetch_and_xor_8";
  336. Names[RTLIB::SYNC_FETCH_AND_NAND_1] = "__sync_fetch_and_nand_1";
  337. Names[RTLIB::SYNC_FETCH_AND_NAND_2] = "__sync_fetch_and_nand_2";
  338. Names[RTLIB::SYNC_FETCH_AND_NAND_4] = "__sync_fetch_and_nand_4";
  339. Names[RTLIB::SYNC_FETCH_AND_NAND_8] = "__sync_fetch_and_nand_8";
  340. if (Triple(TM.getTargetTriple()).getEnvironment() == Triple::GNU) {
  341. Names[RTLIB::SINCOS_F32] = "sincosf";
  342. Names[RTLIB::SINCOS_F64] = "sincos";
  343. Names[RTLIB::SINCOS_F80] = "sincosl";
  344. Names[RTLIB::SINCOS_F128] = "sincosl";
  345. Names[RTLIB::SINCOS_PPCF128] = "sincosl";
  346. } else {
  347. // These are generally not available.
  348. Names[RTLIB::SINCOS_F32] = 0;
  349. Names[RTLIB::SINCOS_F64] = 0;
  350. Names[RTLIB::SINCOS_F80] = 0;
  351. Names[RTLIB::SINCOS_F128] = 0;
  352. Names[RTLIB::SINCOS_PPCF128] = 0;
  353. }
  354. }
  355. /// InitLibcallCallingConvs - Set default libcall CallingConvs.
  356. ///
  357. static void InitLibcallCallingConvs(CallingConv::ID *CCs) {
  358. for (int i = 0; i < RTLIB::UNKNOWN_LIBCALL; ++i) {
  359. CCs[i] = CallingConv::C;
  360. }
  361. }
  362. /// getFPEXT - Return the FPEXT_*_* value for the given types, or
  363. /// UNKNOWN_LIBCALL if there is none.
  364. RTLIB::Libcall RTLIB::getFPEXT(EVT OpVT, EVT RetVT) {
  365. if (OpVT == MVT::f32) {
  366. if (RetVT == MVT::f64)
  367. return FPEXT_F32_F64;
  368. if (RetVT == MVT::f128)
  369. return FPEXT_F32_F128;
  370. } else if (OpVT == MVT::f64) {
  371. if (RetVT == MVT::f128)
  372. return FPEXT_F64_F128;
  373. }
  374. return UNKNOWN_LIBCALL;
  375. }
  376. /// getFPROUND - Return the FPROUND_*_* value for the given types, or
  377. /// UNKNOWN_LIBCALL if there is none.
  378. RTLIB::Libcall RTLIB::getFPROUND(EVT OpVT, EVT RetVT) {
  379. if (RetVT == MVT::f32) {
  380. if (OpVT == MVT::f64)
  381. return FPROUND_F64_F32;
  382. if (OpVT == MVT::f80)
  383. return FPROUND_F80_F32;
  384. if (OpVT == MVT::f128)
  385. return FPROUND_F128_F32;
  386. if (OpVT == MVT::ppcf128)
  387. return FPROUND_PPCF128_F32;
  388. } else if (RetVT == MVT::f64) {
  389. if (OpVT == MVT::f80)
  390. return FPROUND_F80_F64;
  391. if (OpVT == MVT::f128)
  392. return FPROUND_F128_F64;
  393. if (OpVT == MVT::ppcf128)
  394. return FPROUND_PPCF128_F64;
  395. }
  396. return UNKNOWN_LIBCALL;
  397. }
  398. /// getFPTOSINT - Return the FPTOSINT_*_* value for the given types, or
  399. /// UNKNOWN_LIBCALL if there is none.
  400. RTLIB::Libcall RTLIB::getFPTOSINT(EVT OpVT, EVT RetVT) {
  401. if (OpVT == MVT::f32) {
  402. if (RetVT == MVT::i8)
  403. return FPTOSINT_F32_I8;
  404. if (RetVT == MVT::i16)
  405. return FPTOSINT_F32_I16;
  406. if (RetVT == MVT::i32)
  407. return FPTOSINT_F32_I32;
  408. if (RetVT == MVT::i64)
  409. return FPTOSINT_F32_I64;
  410. if (RetVT == MVT::i128)
  411. return FPTOSINT_F32_I128;
  412. } else if (OpVT == MVT::f64) {
  413. if (RetVT == MVT::i8)
  414. return FPTOSINT_F64_I8;
  415. if (RetVT == MVT::i16)
  416. return FPTOSINT_F64_I16;
  417. if (RetVT == MVT::i32)
  418. return FPTOSINT_F64_I32;
  419. if (RetVT == MVT::i64)
  420. return FPTOSINT_F64_I64;
  421. if (RetVT == MVT::i128)
  422. return FPTOSINT_F64_I128;
  423. } else if (OpVT == MVT::f80) {
  424. if (RetVT == MVT::i32)
  425. return FPTOSINT_F80_I32;
  426. if (RetVT == MVT::i64)
  427. return FPTOSINT_F80_I64;
  428. if (RetVT == MVT::i128)
  429. return FPTOSINT_F80_I128;
  430. } else if (OpVT == MVT::f128) {
  431. if (RetVT == MVT::i32)
  432. return FPTOSINT_F128_I32;
  433. if (RetVT == MVT::i64)
  434. return FPTOSINT_F128_I64;
  435. if (RetVT == MVT::i128)
  436. return FPTOSINT_F128_I128;
  437. } else if (OpVT == MVT::ppcf128) {
  438. if (RetVT == MVT::i32)
  439. return FPTOSINT_PPCF128_I32;
  440. if (RetVT == MVT::i64)
  441. return FPTOSINT_PPCF128_I64;
  442. if (RetVT == MVT::i128)
  443. return FPTOSINT_PPCF128_I128;
  444. }
  445. return UNKNOWN_LIBCALL;
  446. }
  447. /// getFPTOUINT - Return the FPTOUINT_*_* value for the given types, or
  448. /// UNKNOWN_LIBCALL if there is none.
  449. RTLIB::Libcall RTLIB::getFPTOUINT(EVT OpVT, EVT RetVT) {
  450. if (OpVT == MVT::f32) {
  451. if (RetVT == MVT::i8)
  452. return FPTOUINT_F32_I8;
  453. if (RetVT == MVT::i16)
  454. return FPTOUINT_F32_I16;
  455. if (RetVT == MVT::i32)
  456. return FPTOUINT_F32_I32;
  457. if (RetVT == MVT::i64)
  458. return FPTOUINT_F32_I64;
  459. if (RetVT == MVT::i128)
  460. return FPTOUINT_F32_I128;
  461. } else if (OpVT == MVT::f64) {
  462. if (RetVT == MVT::i8)
  463. return FPTOUINT_F64_I8;
  464. if (RetVT == MVT::i16)
  465. return FPTOUINT_F64_I16;
  466. if (RetVT == MVT::i32)
  467. return FPTOUINT_F64_I32;
  468. if (RetVT == MVT::i64)
  469. return FPTOUINT_F64_I64;
  470. if (RetVT == MVT::i128)
  471. return FPTOUINT_F64_I128;
  472. } else if (OpVT == MVT::f80) {
  473. if (RetVT == MVT::i32)
  474. return FPTOUINT_F80_I32;
  475. if (RetVT == MVT::i64)
  476. return FPTOUINT_F80_I64;
  477. if (RetVT == MVT::i128)
  478. return FPTOUINT_F80_I128;
  479. } else if (OpVT == MVT::f128) {
  480. if (RetVT == MVT::i32)
  481. return FPTOUINT_F128_I32;
  482. if (RetVT == MVT::i64)
  483. return FPTOUINT_F128_I64;
  484. if (RetVT == MVT::i128)
  485. return FPTOUINT_F128_I128;
  486. } else if (OpVT == MVT::ppcf128) {
  487. if (RetVT == MVT::i32)
  488. return FPTOUINT_PPCF128_I32;
  489. if (RetVT == MVT::i64)
  490. return FPTOUINT_PPCF128_I64;
  491. if (RetVT == MVT::i128)
  492. return FPTOUINT_PPCF128_I128;
  493. }
  494. return UNKNOWN_LIBCALL;
  495. }
  496. /// getSINTTOFP - Return the SINTTOFP_*_* value for the given types, or
  497. /// UNKNOWN_LIBCALL if there is none.
  498. RTLIB::Libcall RTLIB::getSINTTOFP(EVT OpVT, EVT RetVT) {
  499. if (OpVT == MVT::i32) {
  500. if (RetVT == MVT::f32)
  501. return SINTTOFP_I32_F32;
  502. if (RetVT == MVT::f64)
  503. return SINTTOFP_I32_F64;
  504. if (RetVT == MVT::f80)
  505. return SINTTOFP_I32_F80;
  506. if (RetVT == MVT::f128)
  507. return SINTTOFP_I32_F128;
  508. if (RetVT == MVT::ppcf128)
  509. return SINTTOFP_I32_PPCF128;
  510. } else if (OpVT == MVT::i64) {
  511. if (RetVT == MVT::f32)
  512. return SINTTOFP_I64_F32;
  513. if (RetVT == MVT::f64)
  514. return SINTTOFP_I64_F64;
  515. if (RetVT == MVT::f80)
  516. return SINTTOFP_I64_F80;
  517. if (RetVT == MVT::f128)
  518. return SINTTOFP_I64_F128;
  519. if (RetVT == MVT::ppcf128)
  520. return SINTTOFP_I64_PPCF128;
  521. } else if (OpVT == MVT::i128) {
  522. if (RetVT == MVT::f32)
  523. return SINTTOFP_I128_F32;
  524. if (RetVT == MVT::f64)
  525. return SINTTOFP_I128_F64;
  526. if (RetVT == MVT::f80)
  527. return SINTTOFP_I128_F80;
  528. if (RetVT == MVT::f128)
  529. return SINTTOFP_I128_F128;
  530. if (RetVT == MVT::ppcf128)
  531. return SINTTOFP_I128_PPCF128;
  532. }
  533. return UNKNOWN_LIBCALL;
  534. }
  535. /// getUINTTOFP - Return the UINTTOFP_*_* value for the given types, or
  536. /// UNKNOWN_LIBCALL if there is none.
  537. RTLIB::Libcall RTLIB::getUINTTOFP(EVT OpVT, EVT RetVT) {
  538. if (OpVT == MVT::i32) {
  539. if (RetVT == MVT::f32)
  540. return UINTTOFP_I32_F32;
  541. if (RetVT == MVT::f64)
  542. return UINTTOFP_I32_F64;
  543. if (RetVT == MVT::f80)
  544. return UINTTOFP_I32_F80;
  545. if (RetVT == MVT::f128)
  546. return UINTTOFP_I32_F128;
  547. if (RetVT == MVT::ppcf128)
  548. return UINTTOFP_I32_PPCF128;
  549. } else if (OpVT == MVT::i64) {
  550. if (RetVT == MVT::f32)
  551. return UINTTOFP_I64_F32;
  552. if (RetVT == MVT::f64)
  553. return UINTTOFP_I64_F64;
  554. if (RetVT == MVT::f80)
  555. return UINTTOFP_I64_F80;
  556. if (RetVT == MVT::f128)
  557. return UINTTOFP_I64_F128;
  558. if (RetVT == MVT::ppcf128)
  559. return UINTTOFP_I64_PPCF128;
  560. } else if (OpVT == MVT::i128) {
  561. if (RetVT == MVT::f32)
  562. return UINTTOFP_I128_F32;
  563. if (RetVT == MVT::f64)
  564. return UINTTOFP_I128_F64;
  565. if (RetVT == MVT::f80)
  566. return UINTTOFP_I128_F80;
  567. if (RetVT == MVT::f128)
  568. return UINTTOFP_I128_F128;
  569. if (RetVT == MVT::ppcf128)
  570. return UINTTOFP_I128_PPCF128;
  571. }
  572. return UNKNOWN_LIBCALL;
  573. }
  574. /// InitCmpLibcallCCs - Set default comparison libcall CC.
  575. ///
  576. static void InitCmpLibcallCCs(ISD::CondCode *CCs) {
  577. memset(CCs, ISD::SETCC_INVALID, sizeof(ISD::CondCode)*RTLIB::UNKNOWN_LIBCALL);
  578. CCs[RTLIB::OEQ_F32] = ISD::SETEQ;
  579. CCs[RTLIB::OEQ_F64] = ISD::SETEQ;
  580. CCs[RTLIB::OEQ_F128] = ISD::SETEQ;
  581. CCs[RTLIB::UNE_F32] = ISD::SETNE;
  582. CCs[RTLIB::UNE_F64] = ISD::SETNE;
  583. CCs[RTLIB::UNE_F128] = ISD::SETNE;
  584. CCs[RTLIB::OGE_F32] = ISD::SETGE;
  585. CCs[RTLIB::OGE_F64] = ISD::SETGE;
  586. CCs[RTLIB::OGE_F128] = ISD::SETGE;
  587. CCs[RTLIB::OLT_F32] = ISD::SETLT;
  588. CCs[RTLIB::OLT_F64] = ISD::SETLT;
  589. CCs[RTLIB::OLT_F128] = ISD::SETLT;
  590. CCs[RTLIB::OLE_F32] = ISD::SETLE;
  591. CCs[RTLIB::OLE_F64] = ISD::SETLE;
  592. CCs[RTLIB::OLE_F128] = ISD::SETLE;
  593. CCs[RTLIB::OGT_F32] = ISD::SETGT;
  594. CCs[RTLIB::OGT_F64] = ISD::SETGT;
  595. CCs[RTLIB::OGT_F128] = ISD::SETGT;
  596. CCs[RTLIB::UO_F32] = ISD::SETNE;
  597. CCs[RTLIB::UO_F64] = ISD::SETNE;
  598. CCs[RTLIB::UO_F128] = ISD::SETNE;
  599. CCs[RTLIB::O_F32] = ISD::SETEQ;
  600. CCs[RTLIB::O_F64] = ISD::SETEQ;
  601. CCs[RTLIB::O_F128] = ISD::SETEQ;
  602. }
  603. /// NOTE: The constructor takes ownership of TLOF.
  604. TargetLoweringBase::TargetLoweringBase(const TargetMachine &tm,
  605. const TargetLoweringObjectFile *tlof)
  606. : TM(tm), TD(TM.getDataLayout()), TLOF(*tlof) {
  607. initActions();
  608. // Perform these initializations only once.
  609. IsLittleEndian = TD->isLittleEndian();
  610. PointerTy = MVT::getIntegerVT(8*TD->getPointerSize(0));
  611. MaxStoresPerMemset = MaxStoresPerMemcpy = MaxStoresPerMemmove = 8;
  612. MaxStoresPerMemsetOptSize = MaxStoresPerMemcpyOptSize
  613. = MaxStoresPerMemmoveOptSize = 4;
  614. UseUnderscoreSetJmp = false;
  615. UseUnderscoreLongJmp = false;
  616. SelectIsExpensive = false;
  617. IntDivIsCheap = false;
  618. Pow2DivIsCheap = false;
  619. JumpIsExpensive = false;
  620. PredictableSelectIsExpensive = false;
  621. StackPointerRegisterToSaveRestore = 0;
  622. ExceptionPointerRegister = 0;
  623. ExceptionSelectorRegister = 0;
  624. BooleanContents = UndefinedBooleanContent;
  625. BooleanVectorContents = UndefinedBooleanContent;
  626. SchedPreferenceInfo = Sched::ILP;
  627. JumpBufSize = 0;
  628. JumpBufAlignment = 0;
  629. MinFunctionAlignment = 0;
  630. PrefFunctionAlignment = 0;
  631. PrefLoopAlignment = 0;
  632. MinStackArgumentAlignment = 1;
  633. InsertFencesForAtomic = false;
  634. SupportJumpTables = true;
  635. MinimumJumpTableEntries = 4;
  636. InitLibcallNames(LibcallRoutineNames, TM);
  637. InitCmpLibcallCCs(CmpLibcallCCs);
  638. InitLibcallCallingConvs(LibcallCallingConvs);
  639. }
  640. TargetLoweringBase::~TargetLoweringBase() {
  641. delete &TLOF;
  642. }
  643. void TargetLoweringBase::initActions() {
  644. // All operations default to being supported.
  645. memset(OpActions, 0, sizeof(OpActions));
  646. memset(LoadExtActions, 0, sizeof(LoadExtActions));
  647. memset(TruncStoreActions, 0, sizeof(TruncStoreActions));
  648. memset(IndexedModeActions, 0, sizeof(IndexedModeActions));
  649. memset(CondCodeActions, 0, sizeof(CondCodeActions));
  650. memset(RegClassForVT, 0,MVT::LAST_VALUETYPE*sizeof(TargetRegisterClass*));
  651. memset(TargetDAGCombineArray, 0, array_lengthof(TargetDAGCombineArray));
  652. // Set default actions for various operations.
  653. for (unsigned VT = 0; VT != (unsigned)MVT::LAST_VALUETYPE; ++VT) {
  654. // Default all indexed load / store to expand.
  655. for (unsigned IM = (unsigned)ISD::PRE_INC;
  656. IM != (unsigned)ISD::LAST_INDEXED_MODE; ++IM) {
  657. setIndexedLoadAction(IM, (MVT::SimpleValueType)VT, Expand);
  658. setIndexedStoreAction(IM, (MVT::SimpleValueType)VT, Expand);
  659. }
  660. // These operations default to expand.
  661. setOperationAction(ISD::FGETSIGN, (MVT::SimpleValueType)VT, Expand);
  662. setOperationAction(ISD::CONCAT_VECTORS, (MVT::SimpleValueType)VT, Expand);
  663. }
  664. // Most targets ignore the @llvm.prefetch intrinsic.
  665. setOperationAction(ISD::PREFETCH, MVT::Other, Expand);
  666. // ConstantFP nodes default to expand. Targets can either change this to
  667. // Legal, in which case all fp constants are legal, or use isFPImmLegal()
  668. // to optimize expansions for certain constants.
  669. setOperationAction(ISD::ConstantFP, MVT::f16, Expand);
  670. setOperationAction(ISD::ConstantFP, MVT::f32, Expand);
  671. setOperationAction(ISD::ConstantFP, MVT::f64, Expand);
  672. setOperationAction(ISD::ConstantFP, MVT::f80, Expand);
  673. setOperationAction(ISD::ConstantFP, MVT::f128, Expand);
  674. // These library functions default to expand.
  675. setOperationAction(ISD::FLOG , MVT::f16, Expand);
  676. setOperationAction(ISD::FLOG2, MVT::f16, Expand);
  677. setOperationAction(ISD::FLOG10, MVT::f16, Expand);
  678. setOperationAction(ISD::FEXP , MVT::f16, Expand);
  679. setOperationAction(ISD::FEXP2, MVT::f16, Expand);
  680. setOperationAction(ISD::FFLOOR, MVT::f16, Expand);
  681. setOperationAction(ISD::FNEARBYINT, MVT::f16, Expand);
  682. setOperationAction(ISD::FCEIL, MVT::f16, Expand);
  683. setOperationAction(ISD::FRINT, MVT::f16, Expand);
  684. setOperationAction(ISD::FTRUNC, MVT::f16, Expand);
  685. setOperationAction(ISD::FLOG , MVT::f32, Expand);
  686. setOperationAction(ISD::FLOG2, MVT::f32, Expand);
  687. setOperationAction(ISD::FLOG10, MVT::f32, Expand);
  688. setOperationAction(ISD::FEXP , MVT::f32, Expand);
  689. setOperationAction(ISD::FEXP2, MVT::f32, Expand);
  690. setOperationAction(ISD::FFLOOR, MVT::f32, Expand);
  691. setOperationAction(ISD::FNEARBYINT, MVT::f32, Expand);
  692. setOperationAction(ISD::FCEIL, MVT::f32, Expand);
  693. setOperationAction(ISD::FRINT, MVT::f32, Expand);
  694. setOperationAction(ISD::FTRUNC, MVT::f32, Expand);
  695. setOperationAction(ISD::FLOG , MVT::f64, Expand);
  696. setOperationAction(ISD::FLOG2, MVT::f64, Expand);
  697. setOperationAction(ISD::FLOG10, MVT::f64, Expand);
  698. setOperationAction(ISD::FEXP , MVT::f64, Expand);
  699. setOperationAction(ISD::FEXP2, MVT::f64, Expand);
  700. setOperationAction(ISD::FFLOOR, MVT::f64, Expand);
  701. setOperationAction(ISD::FNEARBYINT, MVT::f64, Expand);
  702. setOperationAction(ISD::FCEIL, MVT::f64, Expand);
  703. setOperationAction(ISD::FRINT, MVT::f64, Expand);
  704. setOperationAction(ISD::FTRUNC, MVT::f64, Expand);
  705. setOperationAction(ISD::FLOG , MVT::f128, Expand);
  706. setOperationAction(ISD::FLOG2, MVT::f128, Expand);
  707. setOperationAction(ISD::FLOG10, MVT::f128, Expand);
  708. setOperationAction(ISD::FEXP , MVT::f128, Expand);
  709. setOperationAction(ISD::FEXP2, MVT::f128, Expand);
  710. setOperationAction(ISD::FFLOOR, MVT::f128, Expand);
  711. setOperationAction(ISD::FNEARBYINT, MVT::f128, Expand);
  712. setOperationAction(ISD::FCEIL, MVT::f128, Expand);
  713. setOperationAction(ISD::FRINT, MVT::f128, Expand);
  714. setOperationAction(ISD::FTRUNC, MVT::f128, Expand);
  715. // Default ISD::TRAP to expand (which turns it into abort).
  716. setOperationAction(ISD::TRAP, MVT::Other, Expand);
  717. // On most systems, DEBUGTRAP and TRAP have no difference. The "Expand"
  718. // here is to inform DAG Legalizer to replace DEBUGTRAP with TRAP.
  719. //
  720. setOperationAction(ISD::DEBUGTRAP, MVT::Other, Expand);
  721. }
  722. MVT TargetLoweringBase::getScalarShiftAmountTy(EVT LHSTy) const {
  723. return MVT::getIntegerVT(8*TD->getPointerSize(0));
  724. }
  725. EVT TargetLoweringBase::getShiftAmountTy(EVT LHSTy) const {
  726. assert(LHSTy.isInteger() && "Shift amount is not an integer type!");
  727. if (LHSTy.isVector())
  728. return LHSTy;
  729. return getScalarShiftAmountTy(LHSTy);
  730. }
  731. /// canOpTrap - Returns true if the operation can trap for the value type.
  732. /// VT must be a legal type.
  733. bool TargetLoweringBase::canOpTrap(unsigned Op, EVT VT) const {
  734. assert(isTypeLegal(VT));
  735. switch (Op) {
  736. default:
  737. return false;
  738. case ISD::FDIV:
  739. case ISD::FREM:
  740. case ISD::SDIV:
  741. case ISD::UDIV:
  742. case ISD::SREM:
  743. case ISD::UREM:
  744. return true;
  745. }
  746. }
  747. static unsigned getVectorTypeBreakdownMVT(MVT VT, MVT &IntermediateVT,
  748. unsigned &NumIntermediates,
  749. MVT &RegisterVT,
  750. TargetLoweringBase *TLI) {
  751. // Figure out the right, legal destination reg to copy into.
  752. unsigned NumElts = VT.getVectorNumElements();
  753. MVT EltTy = VT.getVectorElementType();
  754. unsigned NumVectorRegs = 1;
  755. // FIXME: We don't support non-power-of-2-sized vectors for now. Ideally we
  756. // could break down into LHS/RHS like LegalizeDAG does.
  757. if (!isPowerOf2_32(NumElts)) {
  758. NumVectorRegs = NumElts;
  759. NumElts = 1;
  760. }
  761. // Divide the input until we get to a supported size. This will always
  762. // end with a scalar if the target doesn't support vectors.
  763. while (NumElts > 1 && !TLI->isTypeLegal(MVT::getVectorVT(EltTy, NumElts))) {
  764. NumElts >>= 1;
  765. NumVectorRegs <<= 1;
  766. }
  767. NumIntermediates = NumVectorRegs;
  768. MVT NewVT = MVT::getVectorVT(EltTy, NumElts);
  769. if (!TLI->isTypeLegal(NewVT))
  770. NewVT = EltTy;
  771. IntermediateVT = NewVT;
  772. unsigned NewVTSize = NewVT.getSizeInBits();
  773. // Convert sizes such as i33 to i64.
  774. if (!isPowerOf2_32(NewVTSize))
  775. NewVTSize = NextPowerOf2(NewVTSize);
  776. MVT DestVT = TLI->getRegisterType(NewVT);
  777. RegisterVT = DestVT;
  778. if (EVT(DestVT).bitsLT(NewVT)) // Value is expanded, e.g. i64 -> i16.
  779. return NumVectorRegs*(NewVTSize/DestVT.getSizeInBits());
  780. // Otherwise, promotion or legal types use the same number of registers as
  781. // the vector decimated to the appropriate level.
  782. return NumVectorRegs;
  783. }
  784. /// isLegalRC - Return true if the value types that can be represented by the
  785. /// specified register class are all legal.
  786. bool TargetLoweringBase::isLegalRC(const TargetRegisterClass *RC) const {
  787. for (TargetRegisterClass::vt_iterator I = RC->vt_begin(), E = RC->vt_end();
  788. I != E; ++I) {
  789. if (isTypeLegal(*I))
  790. return true;
  791. }
  792. return false;
  793. }
  794. /// findRepresentativeClass - Return the largest legal super-reg register class
  795. /// of the register class for the specified type and its associated "cost".
  796. std::pair<const TargetRegisterClass*, uint8_t>
  797. TargetLoweringBase::findRepresentativeClass(MVT VT) const {
  798. const TargetRegisterInfo *TRI = getTargetMachine().getRegisterInfo();
  799. const TargetRegisterClass *RC = RegClassForVT[VT.SimpleTy];
  800. if (!RC)
  801. return std::make_pair(RC, 0);
  802. // Compute the set of all super-register classes.
  803. BitVector SuperRegRC(TRI->getNumRegClasses());
  804. for (SuperRegClassIterator RCI(RC, TRI); RCI.isValid(); ++RCI)
  805. SuperRegRC.setBitsInMask(RCI.getMask());
  806. // Find the first legal register class with the largest spill size.
  807. const TargetRegisterClass *BestRC = RC;
  808. for (int i = SuperRegRC.find_first(); i >= 0; i = SuperRegRC.find_next(i)) {
  809. const TargetRegisterClass *SuperRC = TRI->getRegClass(i);
  810. // We want the largest possible spill size.
  811. if (SuperRC->getSize() <= BestRC->getSize())
  812. continue;
  813. if (!isLegalRC(SuperRC))
  814. continue;
  815. BestRC = SuperRC;
  816. }
  817. return std::make_pair(BestRC, 1);
  818. }
  819. /// computeRegisterProperties - Once all of the register classes are added,
  820. /// this allows us to compute derived properties we expose.
  821. void TargetLoweringBase::computeRegisterProperties() {
  822. assert(MVT::LAST_VALUETYPE <= MVT::MAX_ALLOWED_VALUETYPE &&
  823. "Too many value types for ValueTypeActions to hold!");
  824. // Everything defaults to needing one register.
  825. for (unsigned i = 0; i != MVT::LAST_VALUETYPE; ++i) {
  826. NumRegistersForVT[i] = 1;
  827. RegisterTypeForVT[i] = TransformToType[i] = (MVT::SimpleValueType)i;
  828. }
  829. // ...except isVoid, which doesn't need any registers.
  830. NumRegistersForVT[MVT::isVoid] = 0;
  831. // Find the largest integer register class.
  832. unsigned LargestIntReg = MVT::LAST_INTEGER_VALUETYPE;
  833. for (; RegClassForVT[LargestIntReg] == 0; --LargestIntReg)
  834. assert(LargestIntReg != MVT::i1 && "No integer registers defined!");
  835. // Every integer value type larger than this largest register takes twice as
  836. // many registers to represent as the previous ValueType.
  837. for (unsigned ExpandedReg = LargestIntReg + 1;
  838. ExpandedReg <= MVT::LAST_INTEGER_VALUETYPE; ++ExpandedReg) {
  839. NumRegistersForVT[ExpandedReg] = 2*NumRegistersForVT[ExpandedReg-1];
  840. RegisterTypeForVT[ExpandedReg] = (MVT::SimpleValueType)LargestIntReg;
  841. TransformToType[ExpandedReg] = (MVT::SimpleValueType)(ExpandedReg - 1);
  842. ValueTypeActions.setTypeAction((MVT::SimpleValueType)ExpandedReg,
  843. TypeExpandInteger);
  844. }
  845. // Inspect all of the ValueType's smaller than the largest integer
  846. // register to see which ones need promotion.
  847. unsigned LegalIntReg = LargestIntReg;
  848. for (unsigned IntReg = LargestIntReg - 1;
  849. IntReg >= (unsigned)MVT::i1; --IntReg) {
  850. MVT IVT = (MVT::SimpleValueType)IntReg;
  851. if (isTypeLegal(IVT)) {
  852. LegalIntReg = IntReg;
  853. } else {
  854. RegisterTypeForVT[IntReg] = TransformToType[IntReg] =
  855. (const MVT::SimpleValueType)LegalIntReg;
  856. ValueTypeActions.setTypeAction(IVT, TypePromoteInteger);
  857. }
  858. }
  859. // ppcf128 type is really two f64's.
  860. if (!isTypeLegal(MVT::ppcf128)) {
  861. NumRegistersForVT[MVT::ppcf128] = 2*NumRegistersForVT[MVT::f64];
  862. RegisterTypeForVT[MVT::ppcf128] = MVT::f64;
  863. TransformToType[MVT::ppcf128] = MVT::f64;
  864. ValueTypeActions.setTypeAction(MVT::ppcf128, TypeExpandFloat);
  865. }
  866. // Decide how to handle f128. If the target does not have native f128 support,
  867. // expand it to i128 and we will be generating soft float library calls.
  868. if (!isTypeLegal(MVT::f128)) {
  869. NumRegistersForVT[MVT::f128] = NumRegistersForVT[MVT::i128];
  870. RegisterTypeForVT[MVT::f128] = RegisterTypeForVT[MVT::i128];
  871. TransformToType[MVT::f128] = MVT::i128;
  872. ValueTypeActions.setTypeAction(MVT::f128, TypeSoftenFloat);
  873. }
  874. // Decide how to handle f64. If the target does not have native f64 support,
  875. // expand it to i64 and we will be generating soft float library calls.
  876. if (!isTypeLegal(MVT::f64)) {
  877. NumRegistersForVT[MVT::f64] = NumRegistersForVT[MVT::i64];
  878. RegisterTypeForVT[MVT::f64] = RegisterTypeForVT[MVT::i64];
  879. TransformToType[MVT::f64] = MVT::i64;
  880. ValueTypeActions.setTypeAction(MVT::f64, TypeSoftenFloat);
  881. }
  882. // Decide how to handle f32. If the target does not have native support for
  883. // f32, promote it to f64 if it is legal. Otherwise, expand it to i32.
  884. if (!isTypeLegal(MVT::f32)) {
  885. if (isTypeLegal(MVT::f64)) {
  886. NumRegistersForVT[MVT::f32] = NumRegistersForVT[MVT::f64];
  887. RegisterTypeForVT[MVT::f32] = RegisterTypeForVT[MVT::f64];
  888. TransformToType[MVT::f32] = MVT::f64;
  889. ValueTypeActions.setTypeAction(MVT::f32, TypePromoteInteger);
  890. } else {
  891. NumRegistersForVT[MVT::f32] = NumRegistersForVT[MVT::i32];
  892. RegisterTypeForVT[MVT::f32] = RegisterTypeForVT[MVT::i32];
  893. TransformToType[MVT::f32] = MVT::i32;
  894. ValueTypeActions.setTypeAction(MVT::f32, TypeSoftenFloat);
  895. }
  896. }
  897. // Loop over all of the vector value types to see which need transformations.
  898. for (unsigned i = MVT::FIRST_VECTOR_VALUETYPE;
  899. i <= (unsigned)MVT::LAST_VECTOR_VALUETYPE; ++i) {
  900. MVT VT = (MVT::SimpleValueType)i;
  901. if (isTypeLegal(VT)) continue;
  902. // Determine if there is a legal wider type. If so, we should promote to
  903. // that wider vector type.
  904. MVT EltVT = VT.getVectorElementType();
  905. unsigned NElts = VT.getVectorNumElements();
  906. if (NElts != 1 && !shouldSplitVectorElementType(EltVT)) {
  907. bool IsLegalWiderType = false;
  908. // First try to promote the elements of integer vectors. If no legal
  909. // promotion was found, fallback to the widen-vector method.
  910. for (unsigned nVT = i+1; nVT <= MVT::LAST_VECTOR_VALUETYPE; ++nVT) {
  911. MVT SVT = (MVT::SimpleValueType)nVT;
  912. // Promote vectors of integers to vectors with the same number
  913. // of elements, with a wider element type.
  914. if (SVT.getVectorElementType().getSizeInBits() > EltVT.getSizeInBits()
  915. && SVT.getVectorNumElements() == NElts &&
  916. isTypeLegal(SVT) && SVT.getScalarType().isInteger()) {
  917. TransformToType[i] = SVT;
  918. RegisterTypeForVT[i] = SVT;
  919. NumRegistersForVT[i] = 1;
  920. ValueTypeActions.setTypeAction(VT, TypePromoteInteger);
  921. IsLegalWiderType = true;
  922. break;
  923. }
  924. }
  925. if (IsLegalWiderType) continue;
  926. // Try to widen the vector.
  927. for (unsigned nVT = i+1; nVT <= MVT::LAST_VECTOR_VALUETYPE; ++nVT) {
  928. MVT SVT = (MVT::SimpleValueType)nVT;
  929. if (SVT.getVectorElementType() == EltVT &&
  930. SVT.getVectorNumElements() > NElts &&
  931. isTypeLegal(SVT)) {
  932. TransformToType[i] = SVT;
  933. RegisterTypeForVT[i] = SVT;
  934. NumRegistersForVT[i] = 1;
  935. ValueTypeActions.setTypeAction(VT, TypeWidenVector);
  936. IsLegalWiderType = true;
  937. break;
  938. }
  939. }
  940. if (IsLegalWiderType) continue;
  941. }
  942. MVT IntermediateVT;
  943. MVT RegisterVT;
  944. unsigned NumIntermediates;
  945. NumRegistersForVT[i] =
  946. getVectorTypeBreakdownMVT(VT, IntermediateVT, NumIntermediates,
  947. RegisterVT, this);
  948. RegisterTypeForVT[i] = RegisterVT;
  949. MVT NVT = VT.getPow2VectorType();
  950. if (NVT == VT) {
  951. // Type is already a power of 2. The default action is to split.
  952. TransformToType[i] = MVT::Other;
  953. unsigned NumElts = VT.getVectorNumElements();
  954. ValueTypeActions.setTypeAction(VT,
  955. NumElts > 1 ? TypeSplitVector : TypeScalarizeVector);
  956. } else {
  957. TransformToType[i] = NVT;
  958. ValueTypeActions.setTypeAction(VT, TypeWidenVector);
  959. }
  960. }
  961. // Determine the 'representative' register class for each value type.
  962. // An representative register class is the largest (meaning one which is
  963. // not a sub-register class / subreg register class) legal register class for
  964. // a group of value types. For example, on i386, i8, i16, and i32
  965. // representative would be GR32; while on x86_64 it's GR64.
  966. for (unsigned i = 0; i != MVT::LAST_VALUETYPE; ++i) {
  967. const TargetRegisterClass* RRC;
  968. uint8_t Cost;
  969. tie(RRC, Cost) = findRepresentativeClass((MVT::SimpleValueType)i);
  970. RepRegClassForVT[i] = RRC;
  971. RepRegClassCostForVT[i] = Cost;
  972. }
  973. }
  974. EVT TargetLoweringBase::getSetCCResultType(LLVMContext &, EVT VT) const {
  975. assert(!VT.isVector() && "No default SetCC type for vectors!");
  976. return getPointerTy(0).SimpleTy;
  977. }
  978. MVT::SimpleValueType TargetLoweringBase::getCmpLibcallReturnType() const {
  979. return MVT::i32; // return the default value
  980. }
  981. /// getVectorTypeBreakdown - Vector types are broken down into some number of
  982. /// legal first class types. For example, MVT::v8f32 maps to 2 MVT::v4f32
  983. /// with Altivec or SSE1, or 8 promoted MVT::f64 values with the X86 FP stack.
  984. /// Similarly, MVT::v2i64 turns into 4 MVT::i32 values with both PPC and X86.
  985. ///
  986. /// This method returns the number of registers needed, and the VT for each
  987. /// register. It also returns the VT and quantity of the intermediate values
  988. /// before they are promoted/expanded.
  989. ///
  990. unsigned TargetLoweringBase::getVectorTypeBreakdown(LLVMContext &Context, EVT VT,
  991. EVT &IntermediateVT,
  992. unsigned &NumIntermediates,
  993. MVT &RegisterVT) const {
  994. unsigned NumElts = VT.getVectorNumElements();
  995. // If there is a wider vector type with the same element type as this one,
  996. // or a promoted vector type that has the same number of elements which
  997. // are wider, then we should convert to that legal vector type.
  998. // This handles things like <2 x float> -> <4 x float> and
  999. // <4 x i1> -> <4 x i32>.
  1000. LegalizeTypeAction TA = getTypeAction(Context, VT);
  1001. if (NumElts != 1 && (TA == TypeWidenVector || TA == TypePromoteInteger)) {
  1002. EVT RegisterEVT = getTypeToTransformTo(Context, VT);
  1003. if (isTypeLegal(RegisterEVT)) {
  1004. IntermediateVT = RegisterEVT;
  1005. RegisterVT = RegisterEVT.getSimpleVT();
  1006. NumIntermediates = 1;
  1007. return 1;
  1008. }
  1009. }
  1010. // Figure out the right, legal destination reg to copy into.
  1011. EVT EltTy = VT.getVectorElementType();
  1012. unsigned NumVectorRegs = 1;
  1013. // FIXME: We don't support non-power-of-2-sized vectors for now. Ideally we
  1014. // could break down into LHS/RHS like LegalizeDAG does.
  1015. if (!isPowerOf2_32(NumElts)) {
  1016. NumVectorRegs = NumElts;
  1017. NumElts = 1;
  1018. }
  1019. // Divide the input until we get to a supported size. This will always
  1020. // end with a scalar if the target doesn't support vectors.
  1021. while (NumElts > 1 && !isTypeLegal(
  1022. EVT::getVectorVT(Context, EltTy, NumElts))) {
  1023. NumElts >>= 1;
  1024. NumVectorRegs <<= 1;
  1025. }
  1026. NumIntermediates = NumVectorRegs;
  1027. EVT NewVT = EVT::getVectorVT(Context, EltTy, NumElts);
  1028. if (!isTypeLegal(NewVT))
  1029. NewVT = EltTy;
  1030. IntermediateVT = NewVT;
  1031. MVT DestVT = getRegisterType(Context, NewVT);
  1032. RegisterVT = DestVT;
  1033. unsigned NewVTSize = NewVT.getSizeInBits();
  1034. // Convert sizes such as i33 to i64.
  1035. if (!isPowerOf2_32(NewVTSize))
  1036. NewVTSize = NextPowerOf2(NewVTSize);
  1037. if (EVT(DestVT).bitsLT(NewVT)) // Value is expanded, e.g. i64 -> i16.
  1038. return NumVectorRegs*(NewVTSize/DestVT.getSizeInBits());
  1039. // Otherwise, promotion or legal types use the same number of registers as
  1040. // the vector decimated to the appropriate level.
  1041. return NumVectorRegs;
  1042. }
  1043. /// Get the EVTs and ArgFlags collections that represent the legalized return
  1044. /// type of the given function. This does not require a DAG or a return value,
  1045. /// and is suitable for use before any DAGs for the function are constructed.
  1046. /// TODO: Move this out of TargetLowering.cpp.
  1047. void llvm::GetReturnInfo(Type* ReturnType, AttributeSet attr,
  1048. SmallVectorImpl<ISD::OutputArg> &Outs,
  1049. const TargetLowering &TLI) {
  1050. SmallVector<EVT, 4> ValueVTs;
  1051. ComputeValueVTs(TLI, ReturnType, ValueVTs);
  1052. unsigned NumValues = ValueVTs.size();
  1053. if (NumValues == 0) return;
  1054. for (unsigned j = 0, f = NumValues; j != f; ++j) {
  1055. EVT VT = ValueVTs[j];
  1056. ISD::NodeType ExtendKind = ISD::ANY_EXTEND;
  1057. if (attr.hasAttribute(AttributeSet::ReturnIndex, Attribute::SExt))
  1058. ExtendKind = ISD::SIGN_EXTEND;
  1059. else if (attr.hasAttribute(AttributeSet::ReturnIndex, Attribute::ZExt))
  1060. ExtendKind = ISD::ZERO_EXTEND;
  1061. // FIXME: C calling convention requires the return type to be promoted to
  1062. // at least 32-bit. But this is not necessary for non-C calling
  1063. // conventions. The frontend should mark functions whose return values
  1064. // require promoting with signext or zeroext attributes.
  1065. if (ExtendKind != ISD::ANY_EXTEND && VT.isInteger()) {
  1066. MVT MinVT = TLI.getRegisterType(ReturnType->getContext(), MVT::i32);
  1067. if (VT.bitsLT(MinVT))
  1068. VT = MinVT;
  1069. }
  1070. unsigned NumParts = TLI.getNumRegisters(ReturnType->getContext(), VT);
  1071. MVT PartVT = TLI.getRegisterType(ReturnType->getContext(), VT);
  1072. // 'inreg' on function refers to return value
  1073. ISD::ArgFlagsTy Flags = ISD::ArgFlagsTy();
  1074. if (attr.hasAttribute(AttributeSet::ReturnIndex, Attribute::InReg))
  1075. Flags.setInReg();
  1076. // Propagate extension type if any
  1077. if (attr.hasAttribute(AttributeSet::ReturnIndex, Attribute::SExt))
  1078. Flags.setSExt();
  1079. else if (attr.hasAttribute(AttributeSet::ReturnIndex, Attribute::ZExt))
  1080. Flags.setZExt();
  1081. for (unsigned i = 0; i < NumParts; ++i)
  1082. Outs.push_back(ISD::OutputArg(Flags, PartVT, /*isFixed=*/true, 0, 0));
  1083. }
  1084. }
  1085. /// getByValTypeAlignment - Return the desired alignment for ByVal aggregate
  1086. /// function arguments in the caller parameter area. This is the actual
  1087. /// alignment, not its logarithm.
  1088. unsigned TargetLoweringBase::getByValTypeAlignment(Type *Ty) const {
  1089. return TD->getCallFrameTypeAlignment(Ty);
  1090. }
  1091. //===----------------------------------------------------------------------===//
  1092. // TargetTransformInfo Helpers
  1093. //===----------------------------------------------------------------------===//
  1094. int TargetLoweringBase::InstructionOpcodeToISD(unsigned Opcode) const {
  1095. enum InstructionOpcodes {
  1096. #define HANDLE_INST(NUM, OPCODE, CLASS) OPCODE = NUM,
  1097. #define LAST_OTHER_INST(NUM) InstructionOpcodesCount = NUM
  1098. #include "llvm/IR/Instruction.def"
  1099. };
  1100. switch (static_cast<InstructionOpcodes>(Opcode)) {
  1101. case Ret: return 0;
  1102. case Br: return 0;
  1103. case Switch: return 0;
  1104. case IndirectBr: return 0;
  1105. case Invoke: return 0;
  1106. case Resume: return 0;
  1107. case Unreachable: return 0;
  1108. case Add: return ISD::ADD;
  1109. case FAdd: return ISD::FADD;
  1110. case Sub: return ISD::SUB;
  1111. case FSub: return ISD::FSUB;
  1112. case Mul: return ISD::MUL;
  1113. case FMul: return ISD::FMUL;
  1114. case UDiv: return ISD::UDIV;
  1115. case SDiv: return ISD::UDIV;
  1116. case FDiv: return ISD::FDIV;
  1117. case URem: return ISD::UREM;
  1118. case SRem: return ISD::SREM;
  1119. case FRem: return ISD::FREM;
  1120. case Shl: return ISD::SHL;
  1121. case LShr: return ISD::SRL;
  1122. case AShr: return ISD::SRA;
  1123. case And: return ISD::AND;
  1124. case Or: return ISD::OR;
  1125. case Xor: return ISD::XOR;
  1126. case Alloca: return 0;
  1127. case Load: return ISD::LOAD;
  1128. case Store: return ISD::STORE;
  1129. case GetElementPtr: return 0;
  1130. case Fence: return 0;
  1131. case AtomicCmpXchg: return 0;
  1132. case AtomicRMW: return 0;
  1133. case Trunc: return ISD::TRUNCATE;
  1134. case ZExt: return ISD::ZERO_EXTEND;
  1135. case SExt: return ISD::SIGN_EXTEND;
  1136. case FPToUI: return ISD::FP_TO_UINT;
  1137. case FPToSI: return ISD::FP_TO_SINT;
  1138. case UIToFP: return ISD::UINT_TO_FP;
  1139. case SIToFP: return ISD::SINT_TO_FP;
  1140. case FPTrunc: return ISD::FP_ROUND;
  1141. case FPExt: return ISD::FP_EXTEND;
  1142. case PtrToInt: return ISD::BITCAST;
  1143. case IntToPtr: return ISD::BITCAST;
  1144. case BitCast: return ISD::BITCAST;
  1145. case ICmp: return ISD::SETCC;
  1146. case FCmp: return ISD::SETCC;
  1147. case PHI: return 0;
  1148. case Call: return 0;
  1149. case Select: return ISD::SELECT;
  1150. case UserOp1: return 0;
  1151. case UserOp2: return 0;
  1152. case VAArg: return 0;
  1153. case ExtractElement: return ISD::EXTRACT_VECTOR_ELT;
  1154. case InsertElement: return ISD::INSERT_VECTOR_ELT;
  1155. case ShuffleVector: return ISD::VECTOR_SHUFFLE;
  1156. case ExtractValue: return ISD::MERGE_VALUES;
  1157. case InsertValue: return ISD::MERGE_VALUES;
  1158. case LandingPad: return 0;
  1159. }
  1160. llvm_unreachable("Unknown instruction type encountered!");
  1161. }
  1162. std::pair<unsigned, MVT>
  1163. TargetLoweringBase::getTypeLegalizationCost(Type *Ty) const {
  1164. LLVMContext &C = Ty->getContext();
  1165. EVT MTy = getValueType(Ty);
  1166. unsigned Cost = 1;
  1167. // We keep legalizing the type until we find a legal kind. We assume that
  1168. // the only operation that costs anything is the split. After splitting
  1169. // we need to handle two types.
  1170. while (true) {
  1171. LegalizeKind LK = getTypeConversion(C, MTy);
  1172. if (LK.first == TypeLegal)
  1173. return std::make_pair(Cost, MTy.getSimpleVT());
  1174. if (LK.first == TypeSplitVector || LK.first == TypeExpandInteger)
  1175. Cost *= 2;
  1176. // Keep legalizing the type.
  1177. MTy = LK.second;
  1178. }
  1179. }
  1180. //===----------------------------------------------------------------------===//
  1181. // Loop Strength Reduction hooks
  1182. //===----------------------------------------------------------------------===//
  1183. /// isLegalAddressingMode - Return true if the addressing mode represented
  1184. /// by AM is legal for this target, for a load/store of the specified type.
  1185. bool TargetLoweringBase::isLegalAddressingMode(const AddrMode &AM,
  1186. Type *Ty) const {
  1187. // The default implementation of this implements a conservative RISCy, r+r and
  1188. // r+i addr mode.
  1189. // Allows a sign-extended 16-bit immediate field.
  1190. if (AM.BaseOffs <= -(1LL << 16) || AM.BaseOffs >= (1LL << 16)-1)
  1191. return false;
  1192. // No global is ever allowed as a base.
  1193. if (AM.BaseGV)
  1194. return false;
  1195. // Only support r+r,
  1196. switch (AM.Scale) {
  1197. case 0: // "r+i" or just "i", depending on HasBaseReg.
  1198. break;
  1199. case 1:
  1200. if (AM.HasBaseReg && AM.BaseOffs) // "r+r+i" is not allowed.
  1201. return false;
  1202. // Otherwise we have r+r or r+i.
  1203. break;
  1204. case 2:
  1205. if (AM.HasBaseReg || AM.BaseOffs) // 2*r+r or 2*r+i is not allowed.
  1206. return false;
  1207. // Allow 2*r as r+r.
  1208. break;
  1209. }
  1210. return true;
  1211. }