LLVM API Documentation
00001 //===-- TargetLoweringBase.cpp - Implement the TargetLoweringBase class ---===// 00002 // 00003 // The LLVM Compiler Infrastructure 00004 // 00005 // This file is distributed under the University of Illinois Open Source 00006 // License. See LICENSE.TXT for details. 00007 // 00008 //===----------------------------------------------------------------------===// 00009 // 00010 // This implements the TargetLoweringBase class. 00011 // 00012 //===----------------------------------------------------------------------===// 00013 00014 #include "llvm/Target/TargetLowering.h" 00015 #include "llvm/ADT/BitVector.h" 00016 #include "llvm/ADT/STLExtras.h" 00017 #include "llvm/ADT/Triple.h" 00018 #include "llvm/CodeGen/Analysis.h" 00019 #include "llvm/CodeGen/MachineFrameInfo.h" 00020 #include "llvm/CodeGen/MachineFunction.h" 00021 #include "llvm/CodeGen/MachineInstrBuilder.h" 00022 #include "llvm/CodeGen/MachineJumpTableInfo.h" 00023 #include "llvm/CodeGen/StackMaps.h" 00024 #include "llvm/IR/DataLayout.h" 00025 #include "llvm/IR/DerivedTypes.h" 00026 #include "llvm/IR/GlobalVariable.h" 00027 #include "llvm/IR/Mangler.h" 00028 #include "llvm/MC/MCAsmInfo.h" 00029 #include "llvm/MC/MCContext.h" 00030 #include "llvm/MC/MCExpr.h" 00031 #include "llvm/Support/CommandLine.h" 00032 #include "llvm/Support/ErrorHandling.h" 00033 #include "llvm/Support/MathExtras.h" 00034 #include "llvm/Target/TargetLoweringObjectFile.h" 00035 #include "llvm/Target/TargetMachine.h" 00036 #include "llvm/Target/TargetRegisterInfo.h" 00037 #include "llvm/Target/TargetSubtargetInfo.h" 00038 #include <cctype> 00039 using namespace llvm; 00040 00041 /// InitLibcallNames - Set default libcall names. 00042 /// 00043 static void InitLibcallNames(const char **Names, const Triple &TT) { 00044 Names[RTLIB::SHL_I16] = "__ashlhi3"; 00045 Names[RTLIB::SHL_I32] = "__ashlsi3"; 00046 Names[RTLIB::SHL_I64] = "__ashldi3"; 00047 Names[RTLIB::SHL_I128] = "__ashlti3"; 00048 Names[RTLIB::SRL_I16] = "__lshrhi3"; 00049 Names[RTLIB::SRL_I32] = "__lshrsi3"; 00050 Names[RTLIB::SRL_I64] = "__lshrdi3"; 00051 Names[RTLIB::SRL_I128] = "__lshrti3"; 00052 Names[RTLIB::SRA_I16] = "__ashrhi3"; 00053 Names[RTLIB::SRA_I32] = "__ashrsi3"; 00054 Names[RTLIB::SRA_I64] = "__ashrdi3"; 00055 Names[RTLIB::SRA_I128] = "__ashrti3"; 00056 Names[RTLIB::MUL_I8] = "__mulqi3"; 00057 Names[RTLIB::MUL_I16] = "__mulhi3"; 00058 Names[RTLIB::MUL_I32] = "__mulsi3"; 00059 Names[RTLIB::MUL_I64] = "__muldi3"; 00060 Names[RTLIB::MUL_I128] = "__multi3"; 00061 Names[RTLIB::MULO_I32] = "__mulosi4"; 00062 Names[RTLIB::MULO_I64] = "__mulodi4"; 00063 Names[RTLIB::MULO_I128] = "__muloti4"; 00064 Names[RTLIB::SDIV_I8] = "__divqi3"; 00065 Names[RTLIB::SDIV_I16] = "__divhi3"; 00066 Names[RTLIB::SDIV_I32] = "__divsi3"; 00067 Names[RTLIB::SDIV_I64] = "__divdi3"; 00068 Names[RTLIB::SDIV_I128] = "__divti3"; 00069 Names[RTLIB::UDIV_I8] = "__udivqi3"; 00070 Names[RTLIB::UDIV_I16] = "__udivhi3"; 00071 Names[RTLIB::UDIV_I32] = "__udivsi3"; 00072 Names[RTLIB::UDIV_I64] = "__udivdi3"; 00073 Names[RTLIB::UDIV_I128] = "__udivti3"; 00074 Names[RTLIB::SREM_I8] = "__modqi3"; 00075 Names[RTLIB::SREM_I16] = "__modhi3"; 00076 Names[RTLIB::SREM_I32] = "__modsi3"; 00077 Names[RTLIB::SREM_I64] = "__moddi3"; 00078 Names[RTLIB::SREM_I128] = "__modti3"; 00079 Names[RTLIB::UREM_I8] = "__umodqi3"; 00080 Names[RTLIB::UREM_I16] = "__umodhi3"; 00081 Names[RTLIB::UREM_I32] = "__umodsi3"; 00082 Names[RTLIB::UREM_I64] = "__umoddi3"; 00083 Names[RTLIB::UREM_I128] = "__umodti3"; 00084 00085 // These are generally not available. 00086 Names[RTLIB::SDIVREM_I8] = nullptr; 00087 Names[RTLIB::SDIVREM_I16] = nullptr; 00088 Names[RTLIB::SDIVREM_I32] = nullptr; 00089 Names[RTLIB::SDIVREM_I64] = nullptr; 00090 Names[RTLIB::SDIVREM_I128] = nullptr; 00091 Names[RTLIB::UDIVREM_I8] = nullptr; 00092 Names[RTLIB::UDIVREM_I16] = nullptr; 00093 Names[RTLIB::UDIVREM_I32] = nullptr; 00094 Names[RTLIB::UDIVREM_I64] = nullptr; 00095 Names[RTLIB::UDIVREM_I128] = nullptr; 00096 00097 Names[RTLIB::NEG_I32] = "__negsi2"; 00098 Names[RTLIB::NEG_I64] = "__negdi2"; 00099 Names[RTLIB::ADD_F32] = "__addsf3"; 00100 Names[RTLIB::ADD_F64] = "__adddf3"; 00101 Names[RTLIB::ADD_F80] = "__addxf3"; 00102 Names[RTLIB::ADD_F128] = "__addtf3"; 00103 Names[RTLIB::ADD_PPCF128] = "__gcc_qadd"; 00104 Names[RTLIB::SUB_F32] = "__subsf3"; 00105 Names[RTLIB::SUB_F64] = "__subdf3"; 00106 Names[RTLIB::SUB_F80] = "__subxf3"; 00107 Names[RTLIB::SUB_F128] = "__subtf3"; 00108 Names[RTLIB::SUB_PPCF128] = "__gcc_qsub"; 00109 Names[RTLIB::MUL_F32] = "__mulsf3"; 00110 Names[RTLIB::MUL_F64] = "__muldf3"; 00111 Names[RTLIB::MUL_F80] = "__mulxf3"; 00112 Names[RTLIB::MUL_F128] = "__multf3"; 00113 Names[RTLIB::MUL_PPCF128] = "__gcc_qmul"; 00114 Names[RTLIB::DIV_F32] = "__divsf3"; 00115 Names[RTLIB::DIV_F64] = "__divdf3"; 00116 Names[RTLIB::DIV_F80] = "__divxf3"; 00117 Names[RTLIB::DIV_F128] = "__divtf3"; 00118 Names[RTLIB::DIV_PPCF128] = "__gcc_qdiv"; 00119 Names[RTLIB::REM_F32] = "fmodf"; 00120 Names[RTLIB::REM_F64] = "fmod"; 00121 Names[RTLIB::REM_F80] = "fmodl"; 00122 Names[RTLIB::REM_F128] = "fmodl"; 00123 Names[RTLIB::REM_PPCF128] = "fmodl"; 00124 Names[RTLIB::FMA_F32] = "fmaf"; 00125 Names[RTLIB::FMA_F64] = "fma"; 00126 Names[RTLIB::FMA_F80] = "fmal"; 00127 Names[RTLIB::FMA_F128] = "fmal"; 00128 Names[RTLIB::FMA_PPCF128] = "fmal"; 00129 Names[RTLIB::POWI_F32] = "__powisf2"; 00130 Names[RTLIB::POWI_F64] = "__powidf2"; 00131 Names[RTLIB::POWI_F80] = "__powixf2"; 00132 Names[RTLIB::POWI_F128] = "__powitf2"; 00133 Names[RTLIB::POWI_PPCF128] = "__powitf2"; 00134 Names[RTLIB::SQRT_F32] = "sqrtf"; 00135 Names[RTLIB::SQRT_F64] = "sqrt"; 00136 Names[RTLIB::SQRT_F80] = "sqrtl"; 00137 Names[RTLIB::SQRT_F128] = "sqrtl"; 00138 Names[RTLIB::SQRT_PPCF128] = "sqrtl"; 00139 Names[RTLIB::LOG_F32] = "logf"; 00140 Names[RTLIB::LOG_F64] = "log"; 00141 Names[RTLIB::LOG_F80] = "logl"; 00142 Names[RTLIB::LOG_F128] = "logl"; 00143 Names[RTLIB::LOG_PPCF128] = "logl"; 00144 Names[RTLIB::LOG2_F32] = "log2f"; 00145 Names[RTLIB::LOG2_F64] = "log2"; 00146 Names[RTLIB::LOG2_F80] = "log2l"; 00147 Names[RTLIB::LOG2_F128] = "log2l"; 00148 Names[RTLIB::LOG2_PPCF128] = "log2l"; 00149 Names[RTLIB::LOG10_F32] = "log10f"; 00150 Names[RTLIB::LOG10_F64] = "log10"; 00151 Names[RTLIB::LOG10_F80] = "log10l"; 00152 Names[RTLIB::LOG10_F128] = "log10l"; 00153 Names[RTLIB::LOG10_PPCF128] = "log10l"; 00154 Names[RTLIB::EXP_F32] = "expf"; 00155 Names[RTLIB::EXP_F64] = "exp"; 00156 Names[RTLIB::EXP_F80] = "expl"; 00157 Names[RTLIB::EXP_F128] = "expl"; 00158 Names[RTLIB::EXP_PPCF128] = "expl"; 00159 Names[RTLIB::EXP2_F32] = "exp2f"; 00160 Names[RTLIB::EXP2_F64] = "exp2"; 00161 Names[RTLIB::EXP2_F80] = "exp2l"; 00162 Names[RTLIB::EXP2_F128] = "exp2l"; 00163 Names[RTLIB::EXP2_PPCF128] = "exp2l"; 00164 Names[RTLIB::SIN_F32] = "sinf"; 00165 Names[RTLIB::SIN_F64] = "sin"; 00166 Names[RTLIB::SIN_F80] = "sinl"; 00167 Names[RTLIB::SIN_F128] = "sinl"; 00168 Names[RTLIB::SIN_PPCF128] = "sinl"; 00169 Names[RTLIB::COS_F32] = "cosf"; 00170 Names[RTLIB::COS_F64] = "cos"; 00171 Names[RTLIB::COS_F80] = "cosl"; 00172 Names[RTLIB::COS_F128] = "cosl"; 00173 Names[RTLIB::COS_PPCF128] = "cosl"; 00174 Names[RTLIB::POW_F32] = "powf"; 00175 Names[RTLIB::POW_F64] = "pow"; 00176 Names[RTLIB::POW_F80] = "powl"; 00177 Names[RTLIB::POW_F128] = "powl"; 00178 Names[RTLIB::POW_PPCF128] = "powl"; 00179 Names[RTLIB::CEIL_F32] = "ceilf"; 00180 Names[RTLIB::CEIL_F64] = "ceil"; 00181 Names[RTLIB::CEIL_F80] = "ceill"; 00182 Names[RTLIB::CEIL_F128] = "ceill"; 00183 Names[RTLIB::CEIL_PPCF128] = "ceill"; 00184 Names[RTLIB::TRUNC_F32] = "truncf"; 00185 Names[RTLIB::TRUNC_F64] = "trunc"; 00186 Names[RTLIB::TRUNC_F80] = "truncl"; 00187 Names[RTLIB::TRUNC_F128] = "truncl"; 00188 Names[RTLIB::TRUNC_PPCF128] = "truncl"; 00189 Names[RTLIB::RINT_F32] = "rintf"; 00190 Names[RTLIB::RINT_F64] = "rint"; 00191 Names[RTLIB::RINT_F80] = "rintl"; 00192 Names[RTLIB::RINT_F128] = "rintl"; 00193 Names[RTLIB::RINT_PPCF128] = "rintl"; 00194 Names[RTLIB::NEARBYINT_F32] = "nearbyintf"; 00195 Names[RTLIB::NEARBYINT_F64] = "nearbyint"; 00196 Names[RTLIB::NEARBYINT_F80] = "nearbyintl"; 00197 Names[RTLIB::NEARBYINT_F128] = "nearbyintl"; 00198 Names[RTLIB::NEARBYINT_PPCF128] = "nearbyintl"; 00199 Names[RTLIB::ROUND_F32] = "roundf"; 00200 Names[RTLIB::ROUND_F64] = "round"; 00201 Names[RTLIB::ROUND_F80] = "roundl"; 00202 Names[RTLIB::ROUND_F128] = "roundl"; 00203 Names[RTLIB::ROUND_PPCF128] = "roundl"; 00204 Names[RTLIB::FLOOR_F32] = "floorf"; 00205 Names[RTLIB::FLOOR_F64] = "floor"; 00206 Names[RTLIB::FLOOR_F80] = "floorl"; 00207 Names[RTLIB::FLOOR_F128] = "floorl"; 00208 Names[RTLIB::FLOOR_PPCF128] = "floorl"; 00209 Names[RTLIB::ROUND_F32] = "roundf"; 00210 Names[RTLIB::ROUND_F64] = "round"; 00211 Names[RTLIB::ROUND_F80] = "roundl"; 00212 Names[RTLIB::ROUND_F128] = "roundl"; 00213 Names[RTLIB::ROUND_PPCF128] = "roundl"; 00214 Names[RTLIB::COPYSIGN_F32] = "copysignf"; 00215 Names[RTLIB::COPYSIGN_F64] = "copysign"; 00216 Names[RTLIB::COPYSIGN_F80] = "copysignl"; 00217 Names[RTLIB::COPYSIGN_F128] = "copysignl"; 00218 Names[RTLIB::COPYSIGN_PPCF128] = "copysignl"; 00219 Names[RTLIB::FPEXT_F64_F128] = "__extenddftf2"; 00220 Names[RTLIB::FPEXT_F32_F128] = "__extendsftf2"; 00221 Names[RTLIB::FPEXT_F32_F64] = "__extendsfdf2"; 00222 Names[RTLIB::FPEXT_F16_F32] = "__gnu_h2f_ieee"; 00223 Names[RTLIB::FPROUND_F32_F16] = "__gnu_f2h_ieee"; 00224 Names[RTLIB::FPROUND_F64_F16] = "__truncdfhf2"; 00225 Names[RTLIB::FPROUND_F80_F16] = "__truncxfhf2"; 00226 Names[RTLIB::FPROUND_F128_F16] = "__trunctfhf2"; 00227 Names[RTLIB::FPROUND_PPCF128_F16] = "__trunctfhf2"; 00228 Names[RTLIB::FPROUND_F64_F32] = "__truncdfsf2"; 00229 Names[RTLIB::FPROUND_F80_F32] = "__truncxfsf2"; 00230 Names[RTLIB::FPROUND_F128_F32] = "__trunctfsf2"; 00231 Names[RTLIB::FPROUND_PPCF128_F32] = "__trunctfsf2"; 00232 Names[RTLIB::FPROUND_F80_F64] = "__truncxfdf2"; 00233 Names[RTLIB::FPROUND_F128_F64] = "__trunctfdf2"; 00234 Names[RTLIB::FPROUND_PPCF128_F64] = "__trunctfdf2"; 00235 Names[RTLIB::FPTOSINT_F32_I8] = "__fixsfqi"; 00236 Names[RTLIB::FPTOSINT_F32_I16] = "__fixsfhi"; 00237 Names[RTLIB::FPTOSINT_F32_I32] = "__fixsfsi"; 00238 Names[RTLIB::FPTOSINT_F32_I64] = "__fixsfdi"; 00239 Names[RTLIB::FPTOSINT_F32_I128] = "__fixsfti"; 00240 Names[RTLIB::FPTOSINT_F64_I8] = "__fixdfqi"; 00241 Names[RTLIB::FPTOSINT_F64_I16] = "__fixdfhi"; 00242 Names[RTLIB::FPTOSINT_F64_I32] = "__fixdfsi"; 00243 Names[RTLIB::FPTOSINT_F64_I64] = "__fixdfdi"; 00244 Names[RTLIB::FPTOSINT_F64_I128] = "__fixdfti"; 00245 Names[RTLIB::FPTOSINT_F80_I32] = "__fixxfsi"; 00246 Names[RTLIB::FPTOSINT_F80_I64] = "__fixxfdi"; 00247 Names[RTLIB::FPTOSINT_F80_I128] = "__fixxfti"; 00248 Names[RTLIB::FPTOSINT_F128_I32] = "__fixtfsi"; 00249 Names[RTLIB::FPTOSINT_F128_I64] = "__fixtfdi"; 00250 Names[RTLIB::FPTOSINT_F128_I128] = "__fixtfti"; 00251 Names[RTLIB::FPTOSINT_PPCF128_I32] = "__fixtfsi"; 00252 Names[RTLIB::FPTOSINT_PPCF128_I64] = "__fixtfdi"; 00253 Names[RTLIB::FPTOSINT_PPCF128_I128] = "__fixtfti"; 00254 Names[RTLIB::FPTOUINT_F32_I8] = "__fixunssfqi"; 00255 Names[RTLIB::FPTOUINT_F32_I16] = "__fixunssfhi"; 00256 Names[RTLIB::FPTOUINT_F32_I32] = "__fixunssfsi"; 00257 Names[RTLIB::FPTOUINT_F32_I64] = "__fixunssfdi"; 00258 Names[RTLIB::FPTOUINT_F32_I128] = "__fixunssfti"; 00259 Names[RTLIB::FPTOUINT_F64_I8] = "__fixunsdfqi"; 00260 Names[RTLIB::FPTOUINT_F64_I16] = "__fixunsdfhi"; 00261 Names[RTLIB::FPTOUINT_F64_I32] = "__fixunsdfsi"; 00262 Names[RTLIB::FPTOUINT_F64_I64] = "__fixunsdfdi"; 00263 Names[RTLIB::FPTOUINT_F64_I128] = "__fixunsdfti"; 00264 Names[RTLIB::FPTOUINT_F80_I32] = "__fixunsxfsi"; 00265 Names[RTLIB::FPTOUINT_F80_I64] = "__fixunsxfdi"; 00266 Names[RTLIB::FPTOUINT_F80_I128] = "__fixunsxfti"; 00267 Names[RTLIB::FPTOUINT_F128_I32] = "__fixunstfsi"; 00268 Names[RTLIB::FPTOUINT_F128_I64] = "__fixunstfdi"; 00269 Names[RTLIB::FPTOUINT_F128_I128] = "__fixunstfti"; 00270 Names[RTLIB::FPTOUINT_PPCF128_I32] = "__fixunstfsi"; 00271 Names[RTLIB::FPTOUINT_PPCF128_I64] = "__fixunstfdi"; 00272 Names[RTLIB::FPTOUINT_PPCF128_I128] = "__fixunstfti"; 00273 Names[RTLIB::SINTTOFP_I32_F32] = "__floatsisf"; 00274 Names[RTLIB::SINTTOFP_I32_F64] = "__floatsidf"; 00275 Names[RTLIB::SINTTOFP_I32_F80] = "__floatsixf"; 00276 Names[RTLIB::SINTTOFP_I32_F128] = "__floatsitf"; 00277 Names[RTLIB::SINTTOFP_I32_PPCF128] = "__floatsitf"; 00278 Names[RTLIB::SINTTOFP_I64_F32] = "__floatdisf"; 00279 Names[RTLIB::SINTTOFP_I64_F64] = "__floatdidf"; 00280 Names[RTLIB::SINTTOFP_I64_F80] = "__floatdixf"; 00281 Names[RTLIB::SINTTOFP_I64_F128] = "__floatditf"; 00282 Names[RTLIB::SINTTOFP_I64_PPCF128] = "__floatditf"; 00283 Names[RTLIB::SINTTOFP_I128_F32] = "__floattisf"; 00284 Names[RTLIB::SINTTOFP_I128_F64] = "__floattidf"; 00285 Names[RTLIB::SINTTOFP_I128_F80] = "__floattixf"; 00286 Names[RTLIB::SINTTOFP_I128_F128] = "__floattitf"; 00287 Names[RTLIB::SINTTOFP_I128_PPCF128] = "__floattitf"; 00288 Names[RTLIB::UINTTOFP_I32_F32] = "__floatunsisf"; 00289 Names[RTLIB::UINTTOFP_I32_F64] = "__floatunsidf"; 00290 Names[RTLIB::UINTTOFP_I32_F80] = "__floatunsixf"; 00291 Names[RTLIB::UINTTOFP_I32_F128] = "__floatunsitf"; 00292 Names[RTLIB::UINTTOFP_I32_PPCF128] = "__floatunsitf"; 00293 Names[RTLIB::UINTTOFP_I64_F32] = "__floatundisf"; 00294 Names[RTLIB::UINTTOFP_I64_F64] = "__floatundidf"; 00295 Names[RTLIB::UINTTOFP_I64_F80] = "__floatundixf"; 00296 Names[RTLIB::UINTTOFP_I64_F128] = "__floatunditf"; 00297 Names[RTLIB::UINTTOFP_I64_PPCF128] = "__floatunditf"; 00298 Names[RTLIB::UINTTOFP_I128_F32] = "__floatuntisf"; 00299 Names[RTLIB::UINTTOFP_I128_F64] = "__floatuntidf"; 00300 Names[RTLIB::UINTTOFP_I128_F80] = "__floatuntixf"; 00301 Names[RTLIB::UINTTOFP_I128_F128] = "__floatuntitf"; 00302 Names[RTLIB::UINTTOFP_I128_PPCF128] = "__floatuntitf"; 00303 Names[RTLIB::OEQ_F32] = "__eqsf2"; 00304 Names[RTLIB::OEQ_F64] = "__eqdf2"; 00305 Names[RTLIB::OEQ_F128] = "__eqtf2"; 00306 Names[RTLIB::UNE_F32] = "__nesf2"; 00307 Names[RTLIB::UNE_F64] = "__nedf2"; 00308 Names[RTLIB::UNE_F128] = "__netf2"; 00309 Names[RTLIB::OGE_F32] = "__gesf2"; 00310 Names[RTLIB::OGE_F64] = "__gedf2"; 00311 Names[RTLIB::OGE_F128] = "__getf2"; 00312 Names[RTLIB::OLT_F32] = "__ltsf2"; 00313 Names[RTLIB::OLT_F64] = "__ltdf2"; 00314 Names[RTLIB::OLT_F128] = "__lttf2"; 00315 Names[RTLIB::OLE_F32] = "__lesf2"; 00316 Names[RTLIB::OLE_F64] = "__ledf2"; 00317 Names[RTLIB::OLE_F128] = "__letf2"; 00318 Names[RTLIB::OGT_F32] = "__gtsf2"; 00319 Names[RTLIB::OGT_F64] = "__gtdf2"; 00320 Names[RTLIB::OGT_F128] = "__gttf2"; 00321 Names[RTLIB::UO_F32] = "__unordsf2"; 00322 Names[RTLIB::UO_F64] = "__unorddf2"; 00323 Names[RTLIB::UO_F128] = "__unordtf2"; 00324 Names[RTLIB::O_F32] = "__unordsf2"; 00325 Names[RTLIB::O_F64] = "__unorddf2"; 00326 Names[RTLIB::O_F128] = "__unordtf2"; 00327 Names[RTLIB::MEMCPY] = "memcpy"; 00328 Names[RTLIB::MEMMOVE] = "memmove"; 00329 Names[RTLIB::MEMSET] = "memset"; 00330 Names[RTLIB::UNWIND_RESUME] = "_Unwind_Resume"; 00331 Names[RTLIB::SYNC_VAL_COMPARE_AND_SWAP_1] = "__sync_val_compare_and_swap_1"; 00332 Names[RTLIB::SYNC_VAL_COMPARE_AND_SWAP_2] = "__sync_val_compare_and_swap_2"; 00333 Names[RTLIB::SYNC_VAL_COMPARE_AND_SWAP_4] = "__sync_val_compare_and_swap_4"; 00334 Names[RTLIB::SYNC_VAL_COMPARE_AND_SWAP_8] = "__sync_val_compare_and_swap_8"; 00335 Names[RTLIB::SYNC_VAL_COMPARE_AND_SWAP_16] = "__sync_val_compare_and_swap_16"; 00336 Names[RTLIB::SYNC_LOCK_TEST_AND_SET_1] = "__sync_lock_test_and_set_1"; 00337 Names[RTLIB::SYNC_LOCK_TEST_AND_SET_2] = "__sync_lock_test_and_set_2"; 00338 Names[RTLIB::SYNC_LOCK_TEST_AND_SET_4] = "__sync_lock_test_and_set_4"; 00339 Names[RTLIB::SYNC_LOCK_TEST_AND_SET_8] = "__sync_lock_test_and_set_8"; 00340 Names[RTLIB::SYNC_LOCK_TEST_AND_SET_16] = "__sync_lock_test_and_set_16"; 00341 Names[RTLIB::SYNC_FETCH_AND_ADD_1] = "__sync_fetch_and_add_1"; 00342 Names[RTLIB::SYNC_FETCH_AND_ADD_2] = "__sync_fetch_and_add_2"; 00343 Names[RTLIB::SYNC_FETCH_AND_ADD_4] = "__sync_fetch_and_add_4"; 00344 Names[RTLIB::SYNC_FETCH_AND_ADD_8] = "__sync_fetch_and_add_8"; 00345 Names[RTLIB::SYNC_FETCH_AND_ADD_16] = "__sync_fetch_and_add_16"; 00346 Names[RTLIB::SYNC_FETCH_AND_SUB_1] = "__sync_fetch_and_sub_1"; 00347 Names[RTLIB::SYNC_FETCH_AND_SUB_2] = "__sync_fetch_and_sub_2"; 00348 Names[RTLIB::SYNC_FETCH_AND_SUB_4] = "__sync_fetch_and_sub_4"; 00349 Names[RTLIB::SYNC_FETCH_AND_SUB_8] = "__sync_fetch_and_sub_8"; 00350 Names[RTLIB::SYNC_FETCH_AND_SUB_16] = "__sync_fetch_and_sub_16"; 00351 Names[RTLIB::SYNC_FETCH_AND_AND_1] = "__sync_fetch_and_and_1"; 00352 Names[RTLIB::SYNC_FETCH_AND_AND_2] = "__sync_fetch_and_and_2"; 00353 Names[RTLIB::SYNC_FETCH_AND_AND_4] = "__sync_fetch_and_and_4"; 00354 Names[RTLIB::SYNC_FETCH_AND_AND_8] = "__sync_fetch_and_and_8"; 00355 Names[RTLIB::SYNC_FETCH_AND_AND_16] = "__sync_fetch_and_and_16"; 00356 Names[RTLIB::SYNC_FETCH_AND_OR_1] = "__sync_fetch_and_or_1"; 00357 Names[RTLIB::SYNC_FETCH_AND_OR_2] = "__sync_fetch_and_or_2"; 00358 Names[RTLIB::SYNC_FETCH_AND_OR_4] = "__sync_fetch_and_or_4"; 00359 Names[RTLIB::SYNC_FETCH_AND_OR_8] = "__sync_fetch_and_or_8"; 00360 Names[RTLIB::SYNC_FETCH_AND_OR_16] = "__sync_fetch_and_or_16"; 00361 Names[RTLIB::SYNC_FETCH_AND_XOR_1] = "__sync_fetch_and_xor_1"; 00362 Names[RTLIB::SYNC_FETCH_AND_XOR_2] = "__sync_fetch_and_xor_2"; 00363 Names[RTLIB::SYNC_FETCH_AND_XOR_4] = "__sync_fetch_and_xor_4"; 00364 Names[RTLIB::SYNC_FETCH_AND_XOR_8] = "__sync_fetch_and_xor_8"; 00365 Names[RTLIB::SYNC_FETCH_AND_XOR_16] = "__sync_fetch_and_xor_16"; 00366 Names[RTLIB::SYNC_FETCH_AND_NAND_1] = "__sync_fetch_and_nand_1"; 00367 Names[RTLIB::SYNC_FETCH_AND_NAND_2] = "__sync_fetch_and_nand_2"; 00368 Names[RTLIB::SYNC_FETCH_AND_NAND_4] = "__sync_fetch_and_nand_4"; 00369 Names[RTLIB::SYNC_FETCH_AND_NAND_8] = "__sync_fetch_and_nand_8"; 00370 Names[RTLIB::SYNC_FETCH_AND_NAND_16] = "__sync_fetch_and_nand_16"; 00371 Names[RTLIB::SYNC_FETCH_AND_MAX_1] = "__sync_fetch_and_max_1"; 00372 Names[RTLIB::SYNC_FETCH_AND_MAX_2] = "__sync_fetch_and_max_2"; 00373 Names[RTLIB::SYNC_FETCH_AND_MAX_4] = "__sync_fetch_and_max_4"; 00374 Names[RTLIB::SYNC_FETCH_AND_MAX_8] = "__sync_fetch_and_max_8"; 00375 Names[RTLIB::SYNC_FETCH_AND_MAX_16] = "__sync_fetch_and_max_16"; 00376 Names[RTLIB::SYNC_FETCH_AND_UMAX_1] = "__sync_fetch_and_umax_1"; 00377 Names[RTLIB::SYNC_FETCH_AND_UMAX_2] = "__sync_fetch_and_umax_2"; 00378 Names[RTLIB::SYNC_FETCH_AND_UMAX_4] = "__sync_fetch_and_umax_4"; 00379 Names[RTLIB::SYNC_FETCH_AND_UMAX_8] = "__sync_fetch_and_umax_8"; 00380 Names[RTLIB::SYNC_FETCH_AND_UMAX_16] = "__sync_fetch_and_umax_16"; 00381 Names[RTLIB::SYNC_FETCH_AND_MIN_1] = "__sync_fetch_and_min_1"; 00382 Names[RTLIB::SYNC_FETCH_AND_MIN_2] = "__sync_fetch_and_min_2"; 00383 Names[RTLIB::SYNC_FETCH_AND_MIN_4] = "__sync_fetch_and_min_4"; 00384 Names[RTLIB::SYNC_FETCH_AND_MIN_8] = "__sync_fetch_and_min_8"; 00385 Names[RTLIB::SYNC_FETCH_AND_MIN_16] = "__sync_fetch_and_min_16"; 00386 Names[RTLIB::SYNC_FETCH_AND_UMIN_1] = "__sync_fetch_and_umin_1"; 00387 Names[RTLIB::SYNC_FETCH_AND_UMIN_2] = "__sync_fetch_and_umin_2"; 00388 Names[RTLIB::SYNC_FETCH_AND_UMIN_4] = "__sync_fetch_and_umin_4"; 00389 Names[RTLIB::SYNC_FETCH_AND_UMIN_8] = "__sync_fetch_and_umin_8"; 00390 Names[RTLIB::SYNC_FETCH_AND_UMIN_16] = "__sync_fetch_and_umin_16"; 00391 00392 if (TT.getEnvironment() == Triple::GNU) { 00393 Names[RTLIB::SINCOS_F32] = "sincosf"; 00394 Names[RTLIB::SINCOS_F64] = "sincos"; 00395 Names[RTLIB::SINCOS_F80] = "sincosl"; 00396 Names[RTLIB::SINCOS_F128] = "sincosl"; 00397 Names[RTLIB::SINCOS_PPCF128] = "sincosl"; 00398 } else { 00399 // These are generally not available. 00400 Names[RTLIB::SINCOS_F32] = nullptr; 00401 Names[RTLIB::SINCOS_F64] = nullptr; 00402 Names[RTLIB::SINCOS_F80] = nullptr; 00403 Names[RTLIB::SINCOS_F128] = nullptr; 00404 Names[RTLIB::SINCOS_PPCF128] = nullptr; 00405 } 00406 00407 if (TT.getOS() != Triple::OpenBSD) { 00408 Names[RTLIB::STACKPROTECTOR_CHECK_FAIL] = "__stack_chk_fail"; 00409 } else { 00410 // These are generally not available. 00411 Names[RTLIB::STACKPROTECTOR_CHECK_FAIL] = nullptr; 00412 } 00413 } 00414 00415 /// InitLibcallCallingConvs - Set default libcall CallingConvs. 00416 /// 00417 static void InitLibcallCallingConvs(CallingConv::ID *CCs) { 00418 for (int i = 0; i < RTLIB::UNKNOWN_LIBCALL; ++i) { 00419 CCs[i] = CallingConv::C; 00420 } 00421 } 00422 00423 /// getFPEXT - Return the FPEXT_*_* value for the given types, or 00424 /// UNKNOWN_LIBCALL if there is none. 00425 RTLIB::Libcall RTLIB::getFPEXT(EVT OpVT, EVT RetVT) { 00426 if (OpVT == MVT::f16) { 00427 if (RetVT == MVT::f32) 00428 return FPEXT_F16_F32; 00429 } else if (OpVT == MVT::f32) { 00430 if (RetVT == MVT::f64) 00431 return FPEXT_F32_F64; 00432 if (RetVT == MVT::f128) 00433 return FPEXT_F32_F128; 00434 } else if (OpVT == MVT::f64) { 00435 if (RetVT == MVT::f128) 00436 return FPEXT_F64_F128; 00437 } 00438 00439 return UNKNOWN_LIBCALL; 00440 } 00441 00442 /// getFPROUND - Return the FPROUND_*_* value for the given types, or 00443 /// UNKNOWN_LIBCALL if there is none. 00444 RTLIB::Libcall RTLIB::getFPROUND(EVT OpVT, EVT RetVT) { 00445 if (RetVT == MVT::f16) { 00446 if (OpVT == MVT::f32) 00447 return FPROUND_F32_F16; 00448 if (OpVT == MVT::f64) 00449 return FPROUND_F64_F16; 00450 if (OpVT == MVT::f80) 00451 return FPROUND_F80_F16; 00452 if (OpVT == MVT::f128) 00453 return FPROUND_F128_F16; 00454 if (OpVT == MVT::ppcf128) 00455 return FPROUND_PPCF128_F16; 00456 } else if (RetVT == MVT::f32) { 00457 if (OpVT == MVT::f64) 00458 return FPROUND_F64_F32; 00459 if (OpVT == MVT::f80) 00460 return FPROUND_F80_F32; 00461 if (OpVT == MVT::f128) 00462 return FPROUND_F128_F32; 00463 if (OpVT == MVT::ppcf128) 00464 return FPROUND_PPCF128_F32; 00465 } else if (RetVT == MVT::f64) { 00466 if (OpVT == MVT::f80) 00467 return FPROUND_F80_F64; 00468 if (OpVT == MVT::f128) 00469 return FPROUND_F128_F64; 00470 if (OpVT == MVT::ppcf128) 00471 return FPROUND_PPCF128_F64; 00472 } 00473 00474 return UNKNOWN_LIBCALL; 00475 } 00476 00477 /// getFPTOSINT - Return the FPTOSINT_*_* value for the given types, or 00478 /// UNKNOWN_LIBCALL if there is none. 00479 RTLIB::Libcall RTLIB::getFPTOSINT(EVT OpVT, EVT RetVT) { 00480 if (OpVT == MVT::f32) { 00481 if (RetVT == MVT::i8) 00482 return FPTOSINT_F32_I8; 00483 if (RetVT == MVT::i16) 00484 return FPTOSINT_F32_I16; 00485 if (RetVT == MVT::i32) 00486 return FPTOSINT_F32_I32; 00487 if (RetVT == MVT::i64) 00488 return FPTOSINT_F32_I64; 00489 if (RetVT == MVT::i128) 00490 return FPTOSINT_F32_I128; 00491 } else if (OpVT == MVT::f64) { 00492 if (RetVT == MVT::i8) 00493 return FPTOSINT_F64_I8; 00494 if (RetVT == MVT::i16) 00495 return FPTOSINT_F64_I16; 00496 if (RetVT == MVT::i32) 00497 return FPTOSINT_F64_I32; 00498 if (RetVT == MVT::i64) 00499 return FPTOSINT_F64_I64; 00500 if (RetVT == MVT::i128) 00501 return FPTOSINT_F64_I128; 00502 } else if (OpVT == MVT::f80) { 00503 if (RetVT == MVT::i32) 00504 return FPTOSINT_F80_I32; 00505 if (RetVT == MVT::i64) 00506 return FPTOSINT_F80_I64; 00507 if (RetVT == MVT::i128) 00508 return FPTOSINT_F80_I128; 00509 } else if (OpVT == MVT::f128) { 00510 if (RetVT == MVT::i32) 00511 return FPTOSINT_F128_I32; 00512 if (RetVT == MVT::i64) 00513 return FPTOSINT_F128_I64; 00514 if (RetVT == MVT::i128) 00515 return FPTOSINT_F128_I128; 00516 } else if (OpVT == MVT::ppcf128) { 00517 if (RetVT == MVT::i32) 00518 return FPTOSINT_PPCF128_I32; 00519 if (RetVT == MVT::i64) 00520 return FPTOSINT_PPCF128_I64; 00521 if (RetVT == MVT::i128) 00522 return FPTOSINT_PPCF128_I128; 00523 } 00524 return UNKNOWN_LIBCALL; 00525 } 00526 00527 /// getFPTOUINT - Return the FPTOUINT_*_* value for the given types, or 00528 /// UNKNOWN_LIBCALL if there is none. 00529 RTLIB::Libcall RTLIB::getFPTOUINT(EVT OpVT, EVT RetVT) { 00530 if (OpVT == MVT::f32) { 00531 if (RetVT == MVT::i8) 00532 return FPTOUINT_F32_I8; 00533 if (RetVT == MVT::i16) 00534 return FPTOUINT_F32_I16; 00535 if (RetVT == MVT::i32) 00536 return FPTOUINT_F32_I32; 00537 if (RetVT == MVT::i64) 00538 return FPTOUINT_F32_I64; 00539 if (RetVT == MVT::i128) 00540 return FPTOUINT_F32_I128; 00541 } else if (OpVT == MVT::f64) { 00542 if (RetVT == MVT::i8) 00543 return FPTOUINT_F64_I8; 00544 if (RetVT == MVT::i16) 00545 return FPTOUINT_F64_I16; 00546 if (RetVT == MVT::i32) 00547 return FPTOUINT_F64_I32; 00548 if (RetVT == MVT::i64) 00549 return FPTOUINT_F64_I64; 00550 if (RetVT == MVT::i128) 00551 return FPTOUINT_F64_I128; 00552 } else if (OpVT == MVT::f80) { 00553 if (RetVT == MVT::i32) 00554 return FPTOUINT_F80_I32; 00555 if (RetVT == MVT::i64) 00556 return FPTOUINT_F80_I64; 00557 if (RetVT == MVT::i128) 00558 return FPTOUINT_F80_I128; 00559 } else if (OpVT == MVT::f128) { 00560 if (RetVT == MVT::i32) 00561 return FPTOUINT_F128_I32; 00562 if (RetVT == MVT::i64) 00563 return FPTOUINT_F128_I64; 00564 if (RetVT == MVT::i128) 00565 return FPTOUINT_F128_I128; 00566 } else if (OpVT == MVT::ppcf128) { 00567 if (RetVT == MVT::i32) 00568 return FPTOUINT_PPCF128_I32; 00569 if (RetVT == MVT::i64) 00570 return FPTOUINT_PPCF128_I64; 00571 if (RetVT == MVT::i128) 00572 return FPTOUINT_PPCF128_I128; 00573 } 00574 return UNKNOWN_LIBCALL; 00575 } 00576 00577 /// getSINTTOFP - Return the SINTTOFP_*_* value for the given types, or 00578 /// UNKNOWN_LIBCALL if there is none. 00579 RTLIB::Libcall RTLIB::getSINTTOFP(EVT OpVT, EVT RetVT) { 00580 if (OpVT == MVT::i32) { 00581 if (RetVT == MVT::f32) 00582 return SINTTOFP_I32_F32; 00583 if (RetVT == MVT::f64) 00584 return SINTTOFP_I32_F64; 00585 if (RetVT == MVT::f80) 00586 return SINTTOFP_I32_F80; 00587 if (RetVT == MVT::f128) 00588 return SINTTOFP_I32_F128; 00589 if (RetVT == MVT::ppcf128) 00590 return SINTTOFP_I32_PPCF128; 00591 } else if (OpVT == MVT::i64) { 00592 if (RetVT == MVT::f32) 00593 return SINTTOFP_I64_F32; 00594 if (RetVT == MVT::f64) 00595 return SINTTOFP_I64_F64; 00596 if (RetVT == MVT::f80) 00597 return SINTTOFP_I64_F80; 00598 if (RetVT == MVT::f128) 00599 return SINTTOFP_I64_F128; 00600 if (RetVT == MVT::ppcf128) 00601 return SINTTOFP_I64_PPCF128; 00602 } else if (OpVT == MVT::i128) { 00603 if (RetVT == MVT::f32) 00604 return SINTTOFP_I128_F32; 00605 if (RetVT == MVT::f64) 00606 return SINTTOFP_I128_F64; 00607 if (RetVT == MVT::f80) 00608 return SINTTOFP_I128_F80; 00609 if (RetVT == MVT::f128) 00610 return SINTTOFP_I128_F128; 00611 if (RetVT == MVT::ppcf128) 00612 return SINTTOFP_I128_PPCF128; 00613 } 00614 return UNKNOWN_LIBCALL; 00615 } 00616 00617 /// getUINTTOFP - Return the UINTTOFP_*_* value for the given types, or 00618 /// UNKNOWN_LIBCALL if there is none. 00619 RTLIB::Libcall RTLIB::getUINTTOFP(EVT OpVT, EVT RetVT) { 00620 if (OpVT == MVT::i32) { 00621 if (RetVT == MVT::f32) 00622 return UINTTOFP_I32_F32; 00623 if (RetVT == MVT::f64) 00624 return UINTTOFP_I32_F64; 00625 if (RetVT == MVT::f80) 00626 return UINTTOFP_I32_F80; 00627 if (RetVT == MVT::f128) 00628 return UINTTOFP_I32_F128; 00629 if (RetVT == MVT::ppcf128) 00630 return UINTTOFP_I32_PPCF128; 00631 } else if (OpVT == MVT::i64) { 00632 if (RetVT == MVT::f32) 00633 return UINTTOFP_I64_F32; 00634 if (RetVT == MVT::f64) 00635 return UINTTOFP_I64_F64; 00636 if (RetVT == MVT::f80) 00637 return UINTTOFP_I64_F80; 00638 if (RetVT == MVT::f128) 00639 return UINTTOFP_I64_F128; 00640 if (RetVT == MVT::ppcf128) 00641 return UINTTOFP_I64_PPCF128; 00642 } else if (OpVT == MVT::i128) { 00643 if (RetVT == MVT::f32) 00644 return UINTTOFP_I128_F32; 00645 if (RetVT == MVT::f64) 00646 return UINTTOFP_I128_F64; 00647 if (RetVT == MVT::f80) 00648 return UINTTOFP_I128_F80; 00649 if (RetVT == MVT::f128) 00650 return UINTTOFP_I128_F128; 00651 if (RetVT == MVT::ppcf128) 00652 return UINTTOFP_I128_PPCF128; 00653 } 00654 return UNKNOWN_LIBCALL; 00655 } 00656 00657 /// InitCmpLibcallCCs - Set default comparison libcall CC. 00658 /// 00659 static void InitCmpLibcallCCs(ISD::CondCode *CCs) { 00660 memset(CCs, ISD::SETCC_INVALID, sizeof(ISD::CondCode)*RTLIB::UNKNOWN_LIBCALL); 00661 CCs[RTLIB::OEQ_F32] = ISD::SETEQ; 00662 CCs[RTLIB::OEQ_F64] = ISD::SETEQ; 00663 CCs[RTLIB::OEQ_F128] = ISD::SETEQ; 00664 CCs[RTLIB::UNE_F32] = ISD::SETNE; 00665 CCs[RTLIB::UNE_F64] = ISD::SETNE; 00666 CCs[RTLIB::UNE_F128] = ISD::SETNE; 00667 CCs[RTLIB::OGE_F32] = ISD::SETGE; 00668 CCs[RTLIB::OGE_F64] = ISD::SETGE; 00669 CCs[RTLIB::OGE_F128] = ISD::SETGE; 00670 CCs[RTLIB::OLT_F32] = ISD::SETLT; 00671 CCs[RTLIB::OLT_F64] = ISD::SETLT; 00672 CCs[RTLIB::OLT_F128] = ISD::SETLT; 00673 CCs[RTLIB::OLE_F32] = ISD::SETLE; 00674 CCs[RTLIB::OLE_F64] = ISD::SETLE; 00675 CCs[RTLIB::OLE_F128] = ISD::SETLE; 00676 CCs[RTLIB::OGT_F32] = ISD::SETGT; 00677 CCs[RTLIB::OGT_F64] = ISD::SETGT; 00678 CCs[RTLIB::OGT_F128] = ISD::SETGT; 00679 CCs[RTLIB::UO_F32] = ISD::SETNE; 00680 CCs[RTLIB::UO_F64] = ISD::SETNE; 00681 CCs[RTLIB::UO_F128] = ISD::SETNE; 00682 CCs[RTLIB::O_F32] = ISD::SETEQ; 00683 CCs[RTLIB::O_F64] = ISD::SETEQ; 00684 CCs[RTLIB::O_F128] = ISD::SETEQ; 00685 } 00686 00687 /// NOTE: The constructor takes ownership of TLOF. 00688 TargetLoweringBase::TargetLoweringBase(const TargetMachine &tm, 00689 const TargetLoweringObjectFile *tlof) 00690 : TM(tm), DL(TM.getSubtargetImpl()->getDataLayout()), TLOF(*tlof) { 00691 initActions(); 00692 00693 // Perform these initializations only once. 00694 IsLittleEndian = DL->isLittleEndian(); 00695 MaxStoresPerMemset = MaxStoresPerMemcpy = MaxStoresPerMemmove = 8; 00696 MaxStoresPerMemsetOptSize = MaxStoresPerMemcpyOptSize 00697 = MaxStoresPerMemmoveOptSize = 4; 00698 UseUnderscoreSetJmp = false; 00699 UseUnderscoreLongJmp = false; 00700 SelectIsExpensive = false; 00701 HasMultipleConditionRegisters = false; 00702 HasExtractBitsInsn = false; 00703 IntDivIsCheap = false; 00704 Pow2SDivIsCheap = false; 00705 JumpIsExpensive = false; 00706 PredictableSelectIsExpensive = false; 00707 MaskAndBranchFoldingIsLegal = false; 00708 HasFloatingPointExceptions = true; 00709 StackPointerRegisterToSaveRestore = 0; 00710 ExceptionPointerRegister = 0; 00711 ExceptionSelectorRegister = 0; 00712 BooleanContents = UndefinedBooleanContent; 00713 BooleanFloatContents = UndefinedBooleanContent; 00714 BooleanVectorContents = UndefinedBooleanContent; 00715 SchedPreferenceInfo = Sched::ILP; 00716 JumpBufSize = 0; 00717 JumpBufAlignment = 0; 00718 MinFunctionAlignment = 0; 00719 PrefFunctionAlignment = 0; 00720 PrefLoopAlignment = 0; 00721 MinStackArgumentAlignment = 1; 00722 InsertFencesForAtomic = false; 00723 MinimumJumpTableEntries = 4; 00724 00725 InitLibcallNames(LibcallRoutineNames, Triple(TM.getTargetTriple())); 00726 InitCmpLibcallCCs(CmpLibcallCCs); 00727 InitLibcallCallingConvs(LibcallCallingConvs); 00728 } 00729 00730 TargetLoweringBase::~TargetLoweringBase() { 00731 delete &TLOF; 00732 } 00733 00734 void TargetLoweringBase::initActions() { 00735 // All operations default to being supported. 00736 memset(OpActions, 0, sizeof(OpActions)); 00737 memset(LoadExtActions, 0, sizeof(LoadExtActions)); 00738 memset(TruncStoreActions, 0, sizeof(TruncStoreActions)); 00739 memset(IndexedModeActions, 0, sizeof(IndexedModeActions)); 00740 memset(CondCodeActions, 0, sizeof(CondCodeActions)); 00741 memset(RegClassForVT, 0,MVT::LAST_VALUETYPE*sizeof(TargetRegisterClass*)); 00742 memset(TargetDAGCombineArray, 0, array_lengthof(TargetDAGCombineArray)); 00743 00744 // Set default actions for various operations. 00745 for (unsigned VT = 0; VT != (unsigned)MVT::LAST_VALUETYPE; ++VT) { 00746 // Default all indexed load / store to expand. 00747 for (unsigned IM = (unsigned)ISD::PRE_INC; 00748 IM != (unsigned)ISD::LAST_INDEXED_MODE; ++IM) { 00749 setIndexedLoadAction(IM, (MVT::SimpleValueType)VT, Expand); 00750 setIndexedStoreAction(IM, (MVT::SimpleValueType)VT, Expand); 00751 } 00752 00753 // Most backends expect to see the node which just returns the value loaded. 00754 setOperationAction(ISD::ATOMIC_CMP_SWAP_WITH_SUCCESS, 00755 (MVT::SimpleValueType)VT, Expand); 00756 00757 // These operations default to expand. 00758 setOperationAction(ISD::FGETSIGN, (MVT::SimpleValueType)VT, Expand); 00759 setOperationAction(ISD::CONCAT_VECTORS, (MVT::SimpleValueType)VT, Expand); 00760 00761 // These library functions default to expand. 00762 setOperationAction(ISD::FROUND, (MVT::SimpleValueType)VT, Expand); 00763 00764 // These operations default to expand for vector types. 00765 if (VT >= MVT::FIRST_VECTOR_VALUETYPE && 00766 VT <= MVT::LAST_VECTOR_VALUETYPE) { 00767 setOperationAction(ISD::FCOPYSIGN, (MVT::SimpleValueType)VT, Expand); 00768 setOperationAction(ISD::ANY_EXTEND_VECTOR_INREG, 00769 (MVT::SimpleValueType)VT, Expand); 00770 setOperationAction(ISD::SIGN_EXTEND_VECTOR_INREG, 00771 (MVT::SimpleValueType)VT, Expand); 00772 setOperationAction(ISD::ZERO_EXTEND_VECTOR_INREG, 00773 (MVT::SimpleValueType)VT, Expand); 00774 } 00775 } 00776 00777 // Most targets ignore the @llvm.prefetch intrinsic. 00778 setOperationAction(ISD::PREFETCH, MVT::Other, Expand); 00779 00780 // ConstantFP nodes default to expand. Targets can either change this to 00781 // Legal, in which case all fp constants are legal, or use isFPImmLegal() 00782 // to optimize expansions for certain constants. 00783 setOperationAction(ISD::ConstantFP, MVT::f16, Expand); 00784 setOperationAction(ISD::ConstantFP, MVT::f32, Expand); 00785 setOperationAction(ISD::ConstantFP, MVT::f64, Expand); 00786 setOperationAction(ISD::ConstantFP, MVT::f80, Expand); 00787 setOperationAction(ISD::ConstantFP, MVT::f128, Expand); 00788 00789 // These library functions default to expand. 00790 setOperationAction(ISD::FLOG , MVT::f16, Expand); 00791 setOperationAction(ISD::FLOG2, MVT::f16, Expand); 00792 setOperationAction(ISD::FLOG10, MVT::f16, Expand); 00793 setOperationAction(ISD::FEXP , MVT::f16, Expand); 00794 setOperationAction(ISD::FEXP2, MVT::f16, Expand); 00795 setOperationAction(ISD::FFLOOR, MVT::f16, Expand); 00796 setOperationAction(ISD::FNEARBYINT, MVT::f16, Expand); 00797 setOperationAction(ISD::FCEIL, MVT::f16, Expand); 00798 setOperationAction(ISD::FRINT, MVT::f16, Expand); 00799 setOperationAction(ISD::FTRUNC, MVT::f16, Expand); 00800 setOperationAction(ISD::FROUND, MVT::f16, Expand); 00801 setOperationAction(ISD::FLOG , MVT::f32, Expand); 00802 setOperationAction(ISD::FLOG2, MVT::f32, Expand); 00803 setOperationAction(ISD::FLOG10, MVT::f32, Expand); 00804 setOperationAction(ISD::FEXP , MVT::f32, Expand); 00805 setOperationAction(ISD::FEXP2, MVT::f32, Expand); 00806 setOperationAction(ISD::FFLOOR, MVT::f32, Expand); 00807 setOperationAction(ISD::FNEARBYINT, MVT::f32, Expand); 00808 setOperationAction(ISD::FCEIL, MVT::f32, Expand); 00809 setOperationAction(ISD::FRINT, MVT::f32, Expand); 00810 setOperationAction(ISD::FTRUNC, MVT::f32, Expand); 00811 setOperationAction(ISD::FROUND, MVT::f32, Expand); 00812 setOperationAction(ISD::FLOG , MVT::f64, Expand); 00813 setOperationAction(ISD::FLOG2, MVT::f64, Expand); 00814 setOperationAction(ISD::FLOG10, MVT::f64, Expand); 00815 setOperationAction(ISD::FEXP , MVT::f64, Expand); 00816 setOperationAction(ISD::FEXP2, MVT::f64, Expand); 00817 setOperationAction(ISD::FFLOOR, MVT::f64, Expand); 00818 setOperationAction(ISD::FNEARBYINT, MVT::f64, Expand); 00819 setOperationAction(ISD::FCEIL, MVT::f64, Expand); 00820 setOperationAction(ISD::FRINT, MVT::f64, Expand); 00821 setOperationAction(ISD::FTRUNC, MVT::f64, Expand); 00822 setOperationAction(ISD::FROUND, MVT::f64, Expand); 00823 setOperationAction(ISD::FLOG , MVT::f128, Expand); 00824 setOperationAction(ISD::FLOG2, MVT::f128, Expand); 00825 setOperationAction(ISD::FLOG10, MVT::f128, Expand); 00826 setOperationAction(ISD::FEXP , MVT::f128, Expand); 00827 setOperationAction(ISD::FEXP2, MVT::f128, Expand); 00828 setOperationAction(ISD::FFLOOR, MVT::f128, Expand); 00829 setOperationAction(ISD::FNEARBYINT, MVT::f128, Expand); 00830 setOperationAction(ISD::FCEIL, MVT::f128, Expand); 00831 setOperationAction(ISD::FRINT, MVT::f128, Expand); 00832 setOperationAction(ISD::FTRUNC, MVT::f128, Expand); 00833 setOperationAction(ISD::FROUND, MVT::f128, Expand); 00834 00835 // Default ISD::TRAP to expand (which turns it into abort). 00836 setOperationAction(ISD::TRAP, MVT::Other, Expand); 00837 00838 // On most systems, DEBUGTRAP and TRAP have no difference. The "Expand" 00839 // here is to inform DAG Legalizer to replace DEBUGTRAP with TRAP. 00840 // 00841 setOperationAction(ISD::DEBUGTRAP, MVT::Other, Expand); 00842 } 00843 00844 MVT TargetLoweringBase::getPointerTy(uint32_t AS) const { 00845 return MVT::getIntegerVT(getPointerSizeInBits(AS)); 00846 } 00847 00848 unsigned TargetLoweringBase::getPointerSizeInBits(uint32_t AS) const { 00849 return DL->getPointerSizeInBits(AS); 00850 } 00851 00852 unsigned TargetLoweringBase::getPointerTypeSizeInBits(Type *Ty) const { 00853 assert(Ty->isPointerTy()); 00854 return getPointerSizeInBits(Ty->getPointerAddressSpace()); 00855 } 00856 00857 MVT TargetLoweringBase::getScalarShiftAmountTy(EVT LHSTy) const { 00858 return MVT::getIntegerVT(8*DL->getPointerSize(0)); 00859 } 00860 00861 EVT TargetLoweringBase::getShiftAmountTy(EVT LHSTy) const { 00862 assert(LHSTy.isInteger() && "Shift amount is not an integer type!"); 00863 if (LHSTy.isVector()) 00864 return LHSTy; 00865 return getScalarShiftAmountTy(LHSTy); 00866 } 00867 00868 /// canOpTrap - Returns true if the operation can trap for the value type. 00869 /// VT must be a legal type. 00870 bool TargetLoweringBase::canOpTrap(unsigned Op, EVT VT) const { 00871 assert(isTypeLegal(VT)); 00872 switch (Op) { 00873 default: 00874 return false; 00875 case ISD::FDIV: 00876 case ISD::FREM: 00877 case ISD::SDIV: 00878 case ISD::UDIV: 00879 case ISD::SREM: 00880 case ISD::UREM: 00881 return true; 00882 } 00883 } 00884 00885 00886 static unsigned getVectorTypeBreakdownMVT(MVT VT, MVT &IntermediateVT, 00887 unsigned &NumIntermediates, 00888 MVT &RegisterVT, 00889 TargetLoweringBase *TLI) { 00890 // Figure out the right, legal destination reg to copy into. 00891 unsigned NumElts = VT.getVectorNumElements(); 00892 MVT EltTy = VT.getVectorElementType(); 00893 00894 unsigned NumVectorRegs = 1; 00895 00896 // FIXME: We don't support non-power-of-2-sized vectors for now. Ideally we 00897 // could break down into LHS/RHS like LegalizeDAG does. 00898 if (!isPowerOf2_32(NumElts)) { 00899 NumVectorRegs = NumElts; 00900 NumElts = 1; 00901 } 00902 00903 // Divide the input until we get to a supported size. This will always 00904 // end with a scalar if the target doesn't support vectors. 00905 while (NumElts > 1 && !TLI->isTypeLegal(MVT::getVectorVT(EltTy, NumElts))) { 00906 NumElts >>= 1; 00907 NumVectorRegs <<= 1; 00908 } 00909 00910 NumIntermediates = NumVectorRegs; 00911 00912 MVT NewVT = MVT::getVectorVT(EltTy, NumElts); 00913 if (!TLI->isTypeLegal(NewVT)) 00914 NewVT = EltTy; 00915 IntermediateVT = NewVT; 00916 00917 unsigned NewVTSize = NewVT.getSizeInBits(); 00918 00919 // Convert sizes such as i33 to i64. 00920 if (!isPowerOf2_32(NewVTSize)) 00921 NewVTSize = NextPowerOf2(NewVTSize); 00922 00923 MVT DestVT = TLI->getRegisterType(NewVT); 00924 RegisterVT = DestVT; 00925 if (EVT(DestVT).bitsLT(NewVT)) // Value is expanded, e.g. i64 -> i16. 00926 return NumVectorRegs*(NewVTSize/DestVT.getSizeInBits()); 00927 00928 // Otherwise, promotion or legal types use the same number of registers as 00929 // the vector decimated to the appropriate level. 00930 return NumVectorRegs; 00931 } 00932 00933 /// isLegalRC - Return true if the value types that can be represented by the 00934 /// specified register class are all legal. 00935 bool TargetLoweringBase::isLegalRC(const TargetRegisterClass *RC) const { 00936 for (TargetRegisterClass::vt_iterator I = RC->vt_begin(), E = RC->vt_end(); 00937 I != E; ++I) { 00938 if (isTypeLegal(*I)) 00939 return true; 00940 } 00941 return false; 00942 } 00943 00944 /// Replace/modify any TargetFrameIndex operands with a targte-dependent 00945 /// sequence of memory operands that is recognized by PrologEpilogInserter. 00946 MachineBasicBlock* 00947 TargetLoweringBase::emitPatchPoint(MachineInstr *MI, 00948 MachineBasicBlock *MBB) const { 00949 MachineFunction &MF = *MI->getParent()->getParent(); 00950 00951 // MI changes inside this loop as we grow operands. 00952 for(unsigned OperIdx = 0; OperIdx != MI->getNumOperands(); ++OperIdx) { 00953 MachineOperand &MO = MI->getOperand(OperIdx); 00954 if (!MO.isFI()) 00955 continue; 00956 00957 // foldMemoryOperand builds a new MI after replacing a single FI operand 00958 // with the canonical set of five x86 addressing-mode operands. 00959 int FI = MO.getIndex(); 00960 MachineInstrBuilder MIB = BuildMI(MF, MI->getDebugLoc(), MI->getDesc()); 00961 00962 // Copy operands before the frame-index. 00963 for (unsigned i = 0; i < OperIdx; ++i) 00964 MIB.addOperand(MI->getOperand(i)); 00965 // Add frame index operands: direct-mem-ref tag, #FI, offset. 00966 MIB.addImm(StackMaps::DirectMemRefOp); 00967 MIB.addOperand(MI->getOperand(OperIdx)); 00968 MIB.addImm(0); 00969 // Copy the operands after the frame index. 00970 for (unsigned i = OperIdx + 1; i != MI->getNumOperands(); ++i) 00971 MIB.addOperand(MI->getOperand(i)); 00972 00973 // Inherit previous memory operands. 00974 MIB->setMemRefs(MI->memoperands_begin(), MI->memoperands_end()); 00975 assert(MIB->mayLoad() && "Folded a stackmap use to a non-load!"); 00976 00977 // Add a new memory operand for this FI. 00978 const MachineFrameInfo &MFI = *MF.getFrameInfo(); 00979 assert(MFI.getObjectOffset(FI) != -1); 00980 MachineMemOperand *MMO = MF.getMachineMemOperand( 00981 MachinePointerInfo::getFixedStack(FI), MachineMemOperand::MOLoad, 00982 TM.getSubtargetImpl()->getDataLayout()->getPointerSize(), 00983 MFI.getObjectAlignment(FI)); 00984 MIB->addMemOperand(MF, MMO); 00985 00986 // Replace the instruction and update the operand index. 00987 MBB->insert(MachineBasicBlock::iterator(MI), MIB); 00988 OperIdx += (MIB->getNumOperands() - MI->getNumOperands()) - 1; 00989 MI->eraseFromParent(); 00990 MI = MIB; 00991 } 00992 return MBB; 00993 } 00994 00995 /// findRepresentativeClass - Return the largest legal super-reg register class 00996 /// of the register class for the specified type and its associated "cost". 00997 std::pair<const TargetRegisterClass*, uint8_t> 00998 TargetLoweringBase::findRepresentativeClass(MVT VT) const { 00999 const TargetRegisterInfo *TRI = 01000 getTargetMachine().getSubtargetImpl()->getRegisterInfo(); 01001 const TargetRegisterClass *RC = RegClassForVT[VT.SimpleTy]; 01002 if (!RC) 01003 return std::make_pair(RC, 0); 01004 01005 // Compute the set of all super-register classes. 01006 BitVector SuperRegRC(TRI->getNumRegClasses()); 01007 for (SuperRegClassIterator RCI(RC, TRI); RCI.isValid(); ++RCI) 01008 SuperRegRC.setBitsInMask(RCI.getMask()); 01009 01010 // Find the first legal register class with the largest spill size. 01011 const TargetRegisterClass *BestRC = RC; 01012 for (int i = SuperRegRC.find_first(); i >= 0; i = SuperRegRC.find_next(i)) { 01013 const TargetRegisterClass *SuperRC = TRI->getRegClass(i); 01014 // We want the largest possible spill size. 01015 if (SuperRC->getSize() <= BestRC->getSize()) 01016 continue; 01017 if (!isLegalRC(SuperRC)) 01018 continue; 01019 BestRC = SuperRC; 01020 } 01021 return std::make_pair(BestRC, 1); 01022 } 01023 01024 /// computeRegisterProperties - Once all of the register classes are added, 01025 /// this allows us to compute derived properties we expose. 01026 void TargetLoweringBase::computeRegisterProperties() { 01027 assert(MVT::LAST_VALUETYPE <= MVT::MAX_ALLOWED_VALUETYPE && 01028 "Too many value types for ValueTypeActions to hold!"); 01029 01030 // Everything defaults to needing one register. 01031 for (unsigned i = 0; i != MVT::LAST_VALUETYPE; ++i) { 01032 NumRegistersForVT[i] = 1; 01033 RegisterTypeForVT[i] = TransformToType[i] = (MVT::SimpleValueType)i; 01034 } 01035 // ...except isVoid, which doesn't need any registers. 01036 NumRegistersForVT[MVT::isVoid] = 0; 01037 01038 // Find the largest integer register class. 01039 unsigned LargestIntReg = MVT::LAST_INTEGER_VALUETYPE; 01040 for (; RegClassForVT[LargestIntReg] == nullptr; --LargestIntReg) 01041 assert(LargestIntReg != MVT::i1 && "No integer registers defined!"); 01042 01043 // Every integer value type larger than this largest register takes twice as 01044 // many registers to represent as the previous ValueType. 01045 for (unsigned ExpandedReg = LargestIntReg + 1; 01046 ExpandedReg <= MVT::LAST_INTEGER_VALUETYPE; ++ExpandedReg) { 01047 NumRegistersForVT[ExpandedReg] = 2*NumRegistersForVT[ExpandedReg-1]; 01048 RegisterTypeForVT[ExpandedReg] = (MVT::SimpleValueType)LargestIntReg; 01049 TransformToType[ExpandedReg] = (MVT::SimpleValueType)(ExpandedReg - 1); 01050 ValueTypeActions.setTypeAction((MVT::SimpleValueType)ExpandedReg, 01051 TypeExpandInteger); 01052 } 01053 01054 // Inspect all of the ValueType's smaller than the largest integer 01055 // register to see which ones need promotion. 01056 unsigned LegalIntReg = LargestIntReg; 01057 for (unsigned IntReg = LargestIntReg - 1; 01058 IntReg >= (unsigned)MVT::i1; --IntReg) { 01059 MVT IVT = (MVT::SimpleValueType)IntReg; 01060 if (isTypeLegal(IVT)) { 01061 LegalIntReg = IntReg; 01062 } else { 01063 RegisterTypeForVT[IntReg] = TransformToType[IntReg] = 01064 (const MVT::SimpleValueType)LegalIntReg; 01065 ValueTypeActions.setTypeAction(IVT, TypePromoteInteger); 01066 } 01067 } 01068 01069 // ppcf128 type is really two f64's. 01070 if (!isTypeLegal(MVT::ppcf128)) { 01071 NumRegistersForVT[MVT::ppcf128] = 2*NumRegistersForVT[MVT::f64]; 01072 RegisterTypeForVT[MVT::ppcf128] = MVT::f64; 01073 TransformToType[MVT::ppcf128] = MVT::f64; 01074 ValueTypeActions.setTypeAction(MVT::ppcf128, TypeExpandFloat); 01075 } 01076 01077 // Decide how to handle f128. If the target does not have native f128 support, 01078 // expand it to i128 and we will be generating soft float library calls. 01079 if (!isTypeLegal(MVT::f128)) { 01080 NumRegistersForVT[MVT::f128] = NumRegistersForVT[MVT::i128]; 01081 RegisterTypeForVT[MVT::f128] = RegisterTypeForVT[MVT::i128]; 01082 TransformToType[MVT::f128] = MVT::i128; 01083 ValueTypeActions.setTypeAction(MVT::f128, TypeSoftenFloat); 01084 } 01085 01086 // Decide how to handle f64. If the target does not have native f64 support, 01087 // expand it to i64 and we will be generating soft float library calls. 01088 if (!isTypeLegal(MVT::f64)) { 01089 NumRegistersForVT[MVT::f64] = NumRegistersForVT[MVT::i64]; 01090 RegisterTypeForVT[MVT::f64] = RegisterTypeForVT[MVT::i64]; 01091 TransformToType[MVT::f64] = MVT::i64; 01092 ValueTypeActions.setTypeAction(MVT::f64, TypeSoftenFloat); 01093 } 01094 01095 // Decide how to handle f32. If the target does not have native support for 01096 // f32, promote it to f64 if it is legal. Otherwise, expand it to i32. 01097 if (!isTypeLegal(MVT::f32)) { 01098 if (isTypeLegal(MVT::f64)) { 01099 NumRegistersForVT[MVT::f32] = NumRegistersForVT[MVT::f64]; 01100 RegisterTypeForVT[MVT::f32] = RegisterTypeForVT[MVT::f64]; 01101 TransformToType[MVT::f32] = MVT::f64; 01102 ValueTypeActions.setTypeAction(MVT::f32, TypePromoteInteger); 01103 } else { 01104 NumRegistersForVT[MVT::f32] = NumRegistersForVT[MVT::i32]; 01105 RegisterTypeForVT[MVT::f32] = RegisterTypeForVT[MVT::i32]; 01106 TransformToType[MVT::f32] = MVT::i32; 01107 ValueTypeActions.setTypeAction(MVT::f32, TypeSoftenFloat); 01108 } 01109 } 01110 01111 if (!isTypeLegal(MVT::f16)) { 01112 NumRegistersForVT[MVT::f16] = NumRegistersForVT[MVT::i16]; 01113 RegisterTypeForVT[MVT::f16] = RegisterTypeForVT[MVT::i16]; 01114 TransformToType[MVT::f16] = MVT::i16; 01115 ValueTypeActions.setTypeAction(MVT::f16, TypeSoftenFloat); 01116 } 01117 01118 // Loop over all of the vector value types to see which need transformations. 01119 for (unsigned i = MVT::FIRST_VECTOR_VALUETYPE; 01120 i <= (unsigned)MVT::LAST_VECTOR_VALUETYPE; ++i) { 01121 MVT VT = (MVT::SimpleValueType) i; 01122 if (isTypeLegal(VT)) 01123 continue; 01124 01125 MVT EltVT = VT.getVectorElementType(); 01126 unsigned NElts = VT.getVectorNumElements(); 01127 bool IsLegalWiderType = false; 01128 LegalizeTypeAction PreferredAction = getPreferredVectorAction(VT); 01129 switch (PreferredAction) { 01130 case TypePromoteInteger: { 01131 // Try to promote the elements of integer vectors. If no legal 01132 // promotion was found, fall through to the widen-vector method. 01133 for (unsigned nVT = i + 1; nVT <= MVT::LAST_VECTOR_VALUETYPE; ++nVT) { 01134 MVT SVT = (MVT::SimpleValueType) nVT; 01135 // Promote vectors of integers to vectors with the same number 01136 // of elements, with a wider element type. 01137 if (SVT.getVectorElementType().getSizeInBits() > EltVT.getSizeInBits() 01138 && SVT.getVectorNumElements() == NElts && isTypeLegal(SVT) 01139 && SVT.getScalarType().isInteger()) { 01140 TransformToType[i] = SVT; 01141 RegisterTypeForVT[i] = SVT; 01142 NumRegistersForVT[i] = 1; 01143 ValueTypeActions.setTypeAction(VT, TypePromoteInteger); 01144 IsLegalWiderType = true; 01145 break; 01146 } 01147 } 01148 if (IsLegalWiderType) 01149 break; 01150 } 01151 case TypeWidenVector: { 01152 // Try to widen the vector. 01153 for (unsigned nVT = i + 1; nVT <= MVT::LAST_VECTOR_VALUETYPE; ++nVT) { 01154 MVT SVT = (MVT::SimpleValueType) nVT; 01155 if (SVT.getVectorElementType() == EltVT 01156 && SVT.getVectorNumElements() > NElts && isTypeLegal(SVT)) { 01157 TransformToType[i] = SVT; 01158 RegisterTypeForVT[i] = SVT; 01159 NumRegistersForVT[i] = 1; 01160 ValueTypeActions.setTypeAction(VT, TypeWidenVector); 01161 IsLegalWiderType = true; 01162 break; 01163 } 01164 } 01165 if (IsLegalWiderType) 01166 break; 01167 } 01168 case TypeSplitVector: 01169 case TypeScalarizeVector: { 01170 MVT IntermediateVT; 01171 MVT RegisterVT; 01172 unsigned NumIntermediates; 01173 NumRegistersForVT[i] = getVectorTypeBreakdownMVT(VT, IntermediateVT, 01174 NumIntermediates, RegisterVT, this); 01175 RegisterTypeForVT[i] = RegisterVT; 01176 01177 MVT NVT = VT.getPow2VectorType(); 01178 if (NVT == VT) { 01179 // Type is already a power of 2. The default action is to split. 01180 TransformToType[i] = MVT::Other; 01181 if (PreferredAction == TypeScalarizeVector) 01182 ValueTypeActions.setTypeAction(VT, TypeScalarizeVector); 01183 else 01184 ValueTypeActions.setTypeAction(VT, TypeSplitVector); 01185 } else { 01186 TransformToType[i] = NVT; 01187 ValueTypeActions.setTypeAction(VT, TypeWidenVector); 01188 } 01189 break; 01190 } 01191 default: 01192 llvm_unreachable("Unknown vector legalization action!"); 01193 } 01194 } 01195 01196 // Determine the 'representative' register class for each value type. 01197 // An representative register class is the largest (meaning one which is 01198 // not a sub-register class / subreg register class) legal register class for 01199 // a group of value types. For example, on i386, i8, i16, and i32 01200 // representative would be GR32; while on x86_64 it's GR64. 01201 for (unsigned i = 0; i != MVT::LAST_VALUETYPE; ++i) { 01202 const TargetRegisterClass* RRC; 01203 uint8_t Cost; 01204 std::tie(RRC, Cost) = findRepresentativeClass((MVT::SimpleValueType)i); 01205 RepRegClassForVT[i] = RRC; 01206 RepRegClassCostForVT[i] = Cost; 01207 } 01208 } 01209 01210 EVT TargetLoweringBase::getSetCCResultType(LLVMContext &, EVT VT) const { 01211 assert(!VT.isVector() && "No default SetCC type for vectors!"); 01212 return getPointerTy(0).SimpleTy; 01213 } 01214 01215 MVT::SimpleValueType TargetLoweringBase::getCmpLibcallReturnType() const { 01216 return MVT::i32; // return the default value 01217 } 01218 01219 /// getVectorTypeBreakdown - Vector types are broken down into some number of 01220 /// legal first class types. For example, MVT::v8f32 maps to 2 MVT::v4f32 01221 /// with Altivec or SSE1, or 8 promoted MVT::f64 values with the X86 FP stack. 01222 /// Similarly, MVT::v2i64 turns into 4 MVT::i32 values with both PPC and X86. 01223 /// 01224 /// This method returns the number of registers needed, and the VT for each 01225 /// register. It also returns the VT and quantity of the intermediate values 01226 /// before they are promoted/expanded. 01227 /// 01228 unsigned TargetLoweringBase::getVectorTypeBreakdown(LLVMContext &Context, EVT VT, 01229 EVT &IntermediateVT, 01230 unsigned &NumIntermediates, 01231 MVT &RegisterVT) const { 01232 unsigned NumElts = VT.getVectorNumElements(); 01233 01234 // If there is a wider vector type with the same element type as this one, 01235 // or a promoted vector type that has the same number of elements which 01236 // are wider, then we should convert to that legal vector type. 01237 // This handles things like <2 x float> -> <4 x float> and 01238 // <4 x i1> -> <4 x i32>. 01239 LegalizeTypeAction TA = getTypeAction(Context, VT); 01240 if (NumElts != 1 && (TA == TypeWidenVector || TA == TypePromoteInteger)) { 01241 EVT RegisterEVT = getTypeToTransformTo(Context, VT); 01242 if (isTypeLegal(RegisterEVT)) { 01243 IntermediateVT = RegisterEVT; 01244 RegisterVT = RegisterEVT.getSimpleVT(); 01245 NumIntermediates = 1; 01246 return 1; 01247 } 01248 } 01249 01250 // Figure out the right, legal destination reg to copy into. 01251 EVT EltTy = VT.getVectorElementType(); 01252 01253 unsigned NumVectorRegs = 1; 01254 01255 // FIXME: We don't support non-power-of-2-sized vectors for now. Ideally we 01256 // could break down into LHS/RHS like LegalizeDAG does. 01257 if (!isPowerOf2_32(NumElts)) { 01258 NumVectorRegs = NumElts; 01259 NumElts = 1; 01260 } 01261 01262 // Divide the input until we get to a supported size. This will always 01263 // end with a scalar if the target doesn't support vectors. 01264 while (NumElts > 1 && !isTypeLegal( 01265 EVT::getVectorVT(Context, EltTy, NumElts))) { 01266 NumElts >>= 1; 01267 NumVectorRegs <<= 1; 01268 } 01269 01270 NumIntermediates = NumVectorRegs; 01271 01272 EVT NewVT = EVT::getVectorVT(Context, EltTy, NumElts); 01273 if (!isTypeLegal(NewVT)) 01274 NewVT = EltTy; 01275 IntermediateVT = NewVT; 01276 01277 MVT DestVT = getRegisterType(Context, NewVT); 01278 RegisterVT = DestVT; 01279 unsigned NewVTSize = NewVT.getSizeInBits(); 01280 01281 // Convert sizes such as i33 to i64. 01282 if (!isPowerOf2_32(NewVTSize)) 01283 NewVTSize = NextPowerOf2(NewVTSize); 01284 01285 if (EVT(DestVT).bitsLT(NewVT)) // Value is expanded, e.g. i64 -> i16. 01286 return NumVectorRegs*(NewVTSize/DestVT.getSizeInBits()); 01287 01288 // Otherwise, promotion or legal types use the same number of registers as 01289 // the vector decimated to the appropriate level. 01290 return NumVectorRegs; 01291 } 01292 01293 /// Get the EVTs and ArgFlags collections that represent the legalized return 01294 /// type of the given function. This does not require a DAG or a return value, 01295 /// and is suitable for use before any DAGs for the function are constructed. 01296 /// TODO: Move this out of TargetLowering.cpp. 01297 void llvm::GetReturnInfo(Type* ReturnType, AttributeSet attr, 01298 SmallVectorImpl<ISD::OutputArg> &Outs, 01299 const TargetLowering &TLI) { 01300 SmallVector<EVT, 4> ValueVTs; 01301 ComputeValueVTs(TLI, ReturnType, ValueVTs); 01302 unsigned NumValues = ValueVTs.size(); 01303 if (NumValues == 0) return; 01304 01305 for (unsigned j = 0, f = NumValues; j != f; ++j) { 01306 EVT VT = ValueVTs[j]; 01307 ISD::NodeType ExtendKind = ISD::ANY_EXTEND; 01308 01309 if (attr.hasAttribute(AttributeSet::ReturnIndex, Attribute::SExt)) 01310 ExtendKind = ISD::SIGN_EXTEND; 01311 else if (attr.hasAttribute(AttributeSet::ReturnIndex, Attribute::ZExt)) 01312 ExtendKind = ISD::ZERO_EXTEND; 01313 01314 // FIXME: C calling convention requires the return type to be promoted to 01315 // at least 32-bit. But this is not necessary for non-C calling 01316 // conventions. The frontend should mark functions whose return values 01317 // require promoting with signext or zeroext attributes. 01318 if (ExtendKind != ISD::ANY_EXTEND && VT.isInteger()) { 01319 MVT MinVT = TLI.getRegisterType(ReturnType->getContext(), MVT::i32); 01320 if (VT.bitsLT(MinVT)) 01321 VT = MinVT; 01322 } 01323 01324 unsigned NumParts = TLI.getNumRegisters(ReturnType->getContext(), VT); 01325 MVT PartVT = TLI.getRegisterType(ReturnType->getContext(), VT); 01326 01327 // 'inreg' on function refers to return value 01328 ISD::ArgFlagsTy Flags = ISD::ArgFlagsTy(); 01329 if (attr.hasAttribute(AttributeSet::ReturnIndex, Attribute::InReg)) 01330 Flags.setInReg(); 01331 01332 // Propagate extension type if any 01333 if (attr.hasAttribute(AttributeSet::ReturnIndex, Attribute::SExt)) 01334 Flags.setSExt(); 01335 else if (attr.hasAttribute(AttributeSet::ReturnIndex, Attribute::ZExt)) 01336 Flags.setZExt(); 01337 01338 for (unsigned i = 0; i < NumParts; ++i) 01339 Outs.push_back(ISD::OutputArg(Flags, PartVT, VT, /*isFixed=*/true, 0, 0)); 01340 } 01341 } 01342 01343 /// getByValTypeAlignment - Return the desired alignment for ByVal aggregate 01344 /// function arguments in the caller parameter area. This is the actual 01345 /// alignment, not its logarithm. 01346 unsigned TargetLoweringBase::getByValTypeAlignment(Type *Ty) const { 01347 return DL->getABITypeAlignment(Ty); 01348 } 01349 01350 //===----------------------------------------------------------------------===// 01351 // TargetTransformInfo Helpers 01352 //===----------------------------------------------------------------------===// 01353 01354 int TargetLoweringBase::InstructionOpcodeToISD(unsigned Opcode) const { 01355 enum InstructionOpcodes { 01356 #define HANDLE_INST(NUM, OPCODE, CLASS) OPCODE = NUM, 01357 #define LAST_OTHER_INST(NUM) InstructionOpcodesCount = NUM 01358 #include "llvm/IR/Instruction.def" 01359 }; 01360 switch (static_cast<InstructionOpcodes>(Opcode)) { 01361 case Ret: return 0; 01362 case Br: return 0; 01363 case Switch: return 0; 01364 case IndirectBr: return 0; 01365 case Invoke: return 0; 01366 case Resume: return 0; 01367 case Unreachable: return 0; 01368 case Add: return ISD::ADD; 01369 case FAdd: return ISD::FADD; 01370 case Sub: return ISD::SUB; 01371 case FSub: return ISD::FSUB; 01372 case Mul: return ISD::MUL; 01373 case FMul: return ISD::FMUL; 01374 case UDiv: return ISD::UDIV; 01375 case SDiv: return ISD::SDIV; 01376 case FDiv: return ISD::FDIV; 01377 case URem: return ISD::UREM; 01378 case SRem: return ISD::SREM; 01379 case FRem: return ISD::FREM; 01380 case Shl: return ISD::SHL; 01381 case LShr: return ISD::SRL; 01382 case AShr: return ISD::SRA; 01383 case And: return ISD::AND; 01384 case Or: return ISD::OR; 01385 case Xor: return ISD::XOR; 01386 case Alloca: return 0; 01387 case Load: return ISD::LOAD; 01388 case Store: return ISD::STORE; 01389 case GetElementPtr: return 0; 01390 case Fence: return 0; 01391 case AtomicCmpXchg: return 0; 01392 case AtomicRMW: return 0; 01393 case Trunc: return ISD::TRUNCATE; 01394 case ZExt: return ISD::ZERO_EXTEND; 01395 case SExt: return ISD::SIGN_EXTEND; 01396 case FPToUI: return ISD::FP_TO_UINT; 01397 case FPToSI: return ISD::FP_TO_SINT; 01398 case UIToFP: return ISD::UINT_TO_FP; 01399 case SIToFP: return ISD::SINT_TO_FP; 01400 case FPTrunc: return ISD::FP_ROUND; 01401 case FPExt: return ISD::FP_EXTEND; 01402 case PtrToInt: return ISD::BITCAST; 01403 case IntToPtr: return ISD::BITCAST; 01404 case BitCast: return ISD::BITCAST; 01405 case AddrSpaceCast: return ISD::ADDRSPACECAST; 01406 case ICmp: return ISD::SETCC; 01407 case FCmp: return ISD::SETCC; 01408 case PHI: return 0; 01409 case Call: return 0; 01410 case Select: return ISD::SELECT; 01411 case UserOp1: return 0; 01412 case UserOp2: return 0; 01413 case VAArg: return 0; 01414 case ExtractElement: return ISD::EXTRACT_VECTOR_ELT; 01415 case InsertElement: return ISD::INSERT_VECTOR_ELT; 01416 case ShuffleVector: return ISD::VECTOR_SHUFFLE; 01417 case ExtractValue: return ISD::MERGE_VALUES; 01418 case InsertValue: return ISD::MERGE_VALUES; 01419 case LandingPad: return 0; 01420 } 01421 01422 llvm_unreachable("Unknown instruction type encountered!"); 01423 } 01424 01425 std::pair<unsigned, MVT> 01426 TargetLoweringBase::getTypeLegalizationCost(Type *Ty) const { 01427 LLVMContext &C = Ty->getContext(); 01428 EVT MTy = getValueType(Ty); 01429 01430 unsigned Cost = 1; 01431 // We keep legalizing the type until we find a legal kind. We assume that 01432 // the only operation that costs anything is the split. After splitting 01433 // we need to handle two types. 01434 while (true) { 01435 LegalizeKind LK = getTypeConversion(C, MTy); 01436 01437 if (LK.first == TypeLegal) 01438 return std::make_pair(Cost, MTy.getSimpleVT()); 01439 01440 if (LK.first == TypeSplitVector || LK.first == TypeExpandInteger) 01441 Cost *= 2; 01442 01443 // Keep legalizing the type. 01444 MTy = LK.second; 01445 } 01446 } 01447 01448 //===----------------------------------------------------------------------===// 01449 // Loop Strength Reduction hooks 01450 //===----------------------------------------------------------------------===// 01451 01452 /// isLegalAddressingMode - Return true if the addressing mode represented 01453 /// by AM is legal for this target, for a load/store of the specified type. 01454 bool TargetLoweringBase::isLegalAddressingMode(const AddrMode &AM, 01455 Type *Ty) const { 01456 // The default implementation of this implements a conservative RISCy, r+r and 01457 // r+i addr mode. 01458 01459 // Allows a sign-extended 16-bit immediate field. 01460 if (AM.BaseOffs <= -(1LL << 16) || AM.BaseOffs >= (1LL << 16)-1) 01461 return false; 01462 01463 // No global is ever allowed as a base. 01464 if (AM.BaseGV) 01465 return false; 01466 01467 // Only support r+r, 01468 switch (AM.Scale) { 01469 case 0: // "r+i" or just "i", depending on HasBaseReg. 01470 break; 01471 case 1: 01472 if (AM.HasBaseReg && AM.BaseOffs) // "r+r+i" is not allowed. 01473 return false; 01474 // Otherwise we have r+r or r+i. 01475 break; 01476 case 2: 01477 if (AM.HasBaseReg || AM.BaseOffs) // 2*r+r or 2*r+i is not allowed. 01478 return false; 01479 // Allow 2*r as r+r. 01480 break; 01481 default: // Don't allow n * r 01482 return false; 01483 } 01484 01485 return true; 01486 }