TargetLoweringBase.cpp 57 KB

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