1 // Copyright 2015 the V8 project authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "src/base/logging.h" 6 #include "src/compiler/backend/instruction-codes.h" 7 #include "src/compiler/backend/instruction-scheduler.h" 8 #include "src/compiler/backend/instruction.h" 9 10 namespace v8 { 11 namespace internal { 12 namespace compiler { 13 SchedulerSupported()14bool InstructionScheduler::SchedulerSupported() { return true; } 15 GetTargetInstructionFlags(const Instruction * instr) const16int InstructionScheduler::GetTargetInstructionFlags( 17 const Instruction* instr) const { 18 switch (instr->arch_opcode()) { 19 case kIA32Add: 20 case kIA32And: 21 case kIA32Cmp: 22 case kIA32Cmp16: 23 case kIA32Cmp8: 24 case kIA32Test: 25 case kIA32Test16: 26 case kIA32Test8: 27 case kIA32Or: 28 case kIA32Xor: 29 case kIA32Sub: 30 case kIA32Imul: 31 case kIA32ImulHigh: 32 case kIA32UmulHigh: 33 case kIA32Not: 34 case kIA32Neg: 35 case kIA32Shl: 36 case kIA32Shr: 37 case kIA32Sar: 38 case kIA32AddPair: 39 case kIA32SubPair: 40 case kIA32MulPair: 41 case kIA32ShlPair: 42 case kIA32ShrPair: 43 case kIA32SarPair: 44 case kIA32Rol: 45 case kIA32Ror: 46 case kIA32Lzcnt: 47 case kIA32Tzcnt: 48 case kIA32Popcnt: 49 case kIA32Bswap: 50 case kIA32Lea: 51 case kIA32Float32Cmp: 52 case kIA32Float32Sqrt: 53 case kIA32Float32Round: 54 case kIA32Float64Cmp: 55 case kIA32Float64Mod: 56 case kIA32Float32Max: 57 case kIA32Float64Max: 58 case kIA32Float32Min: 59 case kIA32Float64Min: 60 case kIA32Float64Sqrt: 61 case kIA32Float64Round: 62 case kIA32Float32ToFloat64: 63 case kIA32Float64ToFloat32: 64 case kIA32Float32ToInt32: 65 case kIA32Float32ToUint32: 66 case kIA32Float64ToInt32: 67 case kIA32Float64ToUint32: 68 case kSSEInt32ToFloat32: 69 case kIA32Uint32ToFloat32: 70 case kSSEInt32ToFloat64: 71 case kIA32Uint32ToFloat64: 72 case kIA32Float64ExtractLowWord32: 73 case kIA32Float64ExtractHighWord32: 74 case kIA32Float64InsertLowWord32: 75 case kIA32Float64InsertHighWord32: 76 case kIA32Float64LoadLowWord32: 77 case kIA32Float64SilenceNaN: 78 case kFloat32Add: 79 case kFloat32Sub: 80 case kFloat64Add: 81 case kFloat64Sub: 82 case kFloat32Mul: 83 case kFloat32Div: 84 case kFloat64Mul: 85 case kFloat64Div: 86 case kFloat64Abs: 87 case kFloat64Neg: 88 case kFloat32Abs: 89 case kFloat32Neg: 90 case kIA32BitcastFI: 91 case kIA32BitcastIF: 92 case kIA32Pblendvb: 93 case kIA32Cvttps2dq: 94 case kIA32Cvttpd2dq: 95 case kIA32I32x4TruncF32x4U: 96 case kIA32I32x4TruncF64x2UZero: 97 case kIA32F64x2Splat: 98 case kIA32F64x2ExtractLane: 99 case kIA32F64x2ReplaceLane: 100 case kIA32F64x2Sqrt: 101 case kIA32F64x2Add: 102 case kIA32F64x2Sub: 103 case kIA32F64x2Mul: 104 case kIA32F64x2Div: 105 case kIA32F64x2Min: 106 case kIA32F64x2Max: 107 case kIA32F64x2Eq: 108 case kIA32F64x2Ne: 109 case kIA32F64x2Lt: 110 case kIA32F64x2Le: 111 case kIA32F64x2Qfma: 112 case kIA32F64x2Qfms: 113 case kIA32Minpd: 114 case kIA32Maxpd: 115 case kIA32F64x2Round: 116 case kIA32F64x2ConvertLowI32x4S: 117 case kIA32F64x2ConvertLowI32x4U: 118 case kIA32F64x2PromoteLowF32x4: 119 case kIA32I64x2SplatI32Pair: 120 case kIA32I64x2ReplaceLaneI32Pair: 121 case kIA32I64x2Abs: 122 case kIA32I64x2Neg: 123 case kIA32I64x2Shl: 124 case kIA32I64x2ShrS: 125 case kIA32I64x2Add: 126 case kIA32I64x2Sub: 127 case kIA32I64x2Mul: 128 case kIA32I64x2ShrU: 129 case kIA32I64x2BitMask: 130 case kIA32I64x2Eq: 131 case kIA32I64x2Ne: 132 case kIA32I64x2GtS: 133 case kIA32I64x2GeS: 134 case kIA32I64x2ExtMulLowI32x4S: 135 case kIA32I64x2ExtMulHighI32x4S: 136 case kIA32I64x2ExtMulLowI32x4U: 137 case kIA32I64x2ExtMulHighI32x4U: 138 case kIA32I64x2SConvertI32x4Low: 139 case kIA32I64x2SConvertI32x4High: 140 case kIA32I64x2UConvertI32x4Low: 141 case kIA32I64x2UConvertI32x4High: 142 case kIA32F32x4Splat: 143 case kIA32F32x4ExtractLane: 144 case kIA32Insertps: 145 case kIA32F32x4SConvertI32x4: 146 case kIA32F32x4UConvertI32x4: 147 case kIA32F32x4Sqrt: 148 case kIA32F32x4RecipApprox: 149 case kIA32F32x4RecipSqrtApprox: 150 case kIA32F32x4Add: 151 case kIA32F32x4Sub: 152 case kIA32F32x4Mul: 153 case kIA32F32x4Div: 154 case kIA32F32x4Min: 155 case kIA32F32x4Max: 156 case kIA32F32x4Eq: 157 case kIA32F32x4Ne: 158 case kIA32F32x4Lt: 159 case kIA32F32x4Le: 160 case kIA32F32x4Qfma: 161 case kIA32F32x4Qfms: 162 case kIA32Minps: 163 case kIA32Maxps: 164 case kIA32F32x4Round: 165 case kIA32F32x4DemoteF64x2Zero: 166 case kIA32I32x4Splat: 167 case kIA32I32x4ExtractLane: 168 case kIA32I32x4SConvertF32x4: 169 case kIA32I32x4SConvertI16x8Low: 170 case kIA32I32x4SConvertI16x8High: 171 case kIA32I32x4Neg: 172 case kIA32I32x4Shl: 173 case kIA32I32x4ShrS: 174 case kIA32I32x4Add: 175 case kIA32I32x4Sub: 176 case kIA32I32x4Mul: 177 case kIA32I32x4MinS: 178 case kIA32I32x4MaxS: 179 case kIA32I32x4Eq: 180 case kIA32I32x4Ne: 181 case kIA32I32x4GtS: 182 case kIA32I32x4GeS: 183 case kSSEI32x4UConvertF32x4: 184 case kAVXI32x4UConvertF32x4: 185 case kIA32I32x4UConvertI16x8Low: 186 case kIA32I32x4UConvertI16x8High: 187 case kIA32I32x4ShrU: 188 case kIA32I32x4MinU: 189 case kIA32I32x4MaxU: 190 case kSSEI32x4GtU: 191 case kAVXI32x4GtU: 192 case kSSEI32x4GeU: 193 case kAVXI32x4GeU: 194 case kIA32I32x4Abs: 195 case kIA32I32x4BitMask: 196 case kIA32I32x4DotI16x8S: 197 case kIA32I32x4ExtMulLowI16x8S: 198 case kIA32I32x4ExtMulHighI16x8S: 199 case kIA32I32x4ExtMulLowI16x8U: 200 case kIA32I32x4ExtMulHighI16x8U: 201 case kIA32I32x4ExtAddPairwiseI16x8S: 202 case kIA32I32x4ExtAddPairwiseI16x8U: 203 case kIA32I32x4TruncSatF64x2SZero: 204 case kIA32I32x4TruncSatF64x2UZero: 205 case kIA32I16x8Splat: 206 case kIA32I16x8ExtractLaneS: 207 case kIA32I16x8SConvertI8x16Low: 208 case kIA32I16x8SConvertI8x16High: 209 case kIA32I16x8Neg: 210 case kIA32I16x8Shl: 211 case kIA32I16x8ShrS: 212 case kIA32I16x8SConvertI32x4: 213 case kIA32I16x8Add: 214 case kIA32I16x8AddSatS: 215 case kIA32I16x8Sub: 216 case kIA32I16x8SubSatS: 217 case kIA32I16x8Mul: 218 case kIA32I16x8MinS: 219 case kIA32I16x8MaxS: 220 case kIA32I16x8Eq: 221 case kSSEI16x8Ne: 222 case kAVXI16x8Ne: 223 case kIA32I16x8GtS: 224 case kSSEI16x8GeS: 225 case kAVXI16x8GeS: 226 case kIA32I16x8UConvertI8x16Low: 227 case kIA32I16x8UConvertI8x16High: 228 case kIA32I16x8ShrU: 229 case kIA32I16x8UConvertI32x4: 230 case kIA32I16x8AddSatU: 231 case kIA32I16x8SubSatU: 232 case kIA32I16x8MinU: 233 case kIA32I16x8MaxU: 234 case kSSEI16x8GtU: 235 case kAVXI16x8GtU: 236 case kSSEI16x8GeU: 237 case kAVXI16x8GeU: 238 case kIA32I16x8RoundingAverageU: 239 case kIA32I16x8Abs: 240 case kIA32I16x8BitMask: 241 case kIA32I16x8ExtMulLowI8x16S: 242 case kIA32I16x8ExtMulHighI8x16S: 243 case kIA32I16x8ExtMulLowI8x16U: 244 case kIA32I16x8ExtMulHighI8x16U: 245 case kIA32I16x8ExtAddPairwiseI8x16S: 246 case kIA32I16x8ExtAddPairwiseI8x16U: 247 case kIA32I16x8Q15MulRSatS: 248 case kIA32I8x16Splat: 249 case kIA32I8x16ExtractLaneS: 250 case kIA32Pinsrb: 251 case kIA32Pinsrw: 252 case kIA32Pinsrd: 253 case kIA32Pextrb: 254 case kIA32Pextrw: 255 case kIA32S128Store32Lane: 256 case kIA32I8x16SConvertI16x8: 257 case kIA32I8x16Neg: 258 case kIA32I8x16Shl: 259 case kIA32I8x16ShrS: 260 case kIA32I8x16Add: 261 case kIA32I8x16AddSatS: 262 case kIA32I8x16Sub: 263 case kIA32I8x16SubSatS: 264 case kIA32I8x16MinS: 265 case kIA32I8x16MaxS: 266 case kIA32I8x16Eq: 267 case kSSEI8x16Ne: 268 case kAVXI8x16Ne: 269 case kIA32I8x16GtS: 270 case kSSEI8x16GeS: 271 case kAVXI8x16GeS: 272 case kIA32I8x16UConvertI16x8: 273 case kIA32I8x16AddSatU: 274 case kIA32I8x16SubSatU: 275 case kIA32I8x16ShrU: 276 case kIA32I8x16MinU: 277 case kIA32I8x16MaxU: 278 case kSSEI8x16GtU: 279 case kAVXI8x16GtU: 280 case kSSEI8x16GeU: 281 case kAVXI8x16GeU: 282 case kIA32I8x16RoundingAverageU: 283 case kIA32I8x16Abs: 284 case kIA32I8x16BitMask: 285 case kIA32I8x16Popcnt: 286 case kIA32S128Const: 287 case kIA32S128Zero: 288 case kIA32S128AllOnes: 289 case kIA32S128Not: 290 case kIA32S128And: 291 case kIA32S128Or: 292 case kIA32S128Xor: 293 case kIA32S128Select: 294 case kIA32S128AndNot: 295 case kIA32I8x16Swizzle: 296 case kIA32I8x16Shuffle: 297 case kIA32S32x4Rotate: 298 case kIA32S32x4Swizzle: 299 case kIA32S32x4Shuffle: 300 case kIA32S16x8Blend: 301 case kIA32S16x8HalfShuffle1: 302 case kIA32S16x8HalfShuffle2: 303 case kIA32S8x16Alignr: 304 case kIA32S16x8Dup: 305 case kIA32S8x16Dup: 306 case kSSES16x8UnzipHigh: 307 case kAVXS16x8UnzipHigh: 308 case kSSES16x8UnzipLow: 309 case kAVXS16x8UnzipLow: 310 case kSSES8x16UnzipHigh: 311 case kAVXS8x16UnzipHigh: 312 case kSSES8x16UnzipLow: 313 case kAVXS8x16UnzipLow: 314 case kIA32S64x2UnpackHigh: 315 case kIA32S32x4UnpackHigh: 316 case kIA32S16x8UnpackHigh: 317 case kIA32S8x16UnpackHigh: 318 case kIA32S64x2UnpackLow: 319 case kIA32S32x4UnpackLow: 320 case kIA32S16x8UnpackLow: 321 case kIA32S8x16UnpackLow: 322 case kSSES8x16TransposeLow: 323 case kAVXS8x16TransposeLow: 324 case kSSES8x16TransposeHigh: 325 case kAVXS8x16TransposeHigh: 326 case kSSES8x8Reverse: 327 case kAVXS8x8Reverse: 328 case kSSES8x4Reverse: 329 case kAVXS8x4Reverse: 330 case kSSES8x2Reverse: 331 case kAVXS8x2Reverse: 332 case kIA32S128AnyTrue: 333 case kIA32I64x2AllTrue: 334 case kIA32I32x4AllTrue: 335 case kIA32I16x8AllTrue: 336 case kIA32I8x16AllTrue: 337 return (instr->addressing_mode() == kMode_None) 338 ? kNoOpcodeFlags 339 : kIsLoadOperation | kHasSideEffect; 340 341 case kIA32Idiv: 342 case kIA32Udiv: 343 return (instr->addressing_mode() == kMode_None) 344 ? kMayNeedDeoptOrTrapCheck 345 : kMayNeedDeoptOrTrapCheck | kIsLoadOperation | kHasSideEffect; 346 347 case kIA32Movsxbl: 348 case kIA32Movzxbl: 349 case kIA32Movb: 350 case kIA32Movsxwl: 351 case kIA32Movzxwl: 352 case kIA32Movw: 353 case kIA32Movl: 354 case kIA32Movss: 355 case kIA32Movsd: 356 case kIA32Movdqu: 357 case kIA32Movlps: 358 case kIA32Movhps: 359 // Moves are used for memory load/store operations. 360 case kIA32S128Load8Splat: 361 case kIA32S128Load16Splat: 362 case kIA32S128Load32Splat: 363 case kIA32S128Load64Splat: 364 case kIA32S128Load8x8S: 365 case kIA32S128Load8x8U: 366 case kIA32S128Load16x4S: 367 case kIA32S128Load16x4U: 368 case kIA32S128Load32x2S: 369 case kIA32S128Load32x2U: 370 return instr->HasOutput() ? kIsLoadOperation : kHasSideEffect; 371 372 case kIA32Peek: 373 return kIsLoadOperation; 374 375 case kIA32Push: 376 case kIA32Poke: 377 case kIA32MFence: 378 case kIA32LFence: 379 return kHasSideEffect; 380 381 case kIA32Word32AtomicPairLoad: 382 return kIsLoadOperation; 383 384 case kIA32Word32ReleasePairStore: 385 case kIA32Word32SeqCstPairStore: 386 case kIA32Word32AtomicPairAdd: 387 case kIA32Word32AtomicPairSub: 388 case kIA32Word32AtomicPairAnd: 389 case kIA32Word32AtomicPairOr: 390 case kIA32Word32AtomicPairXor: 391 case kIA32Word32AtomicPairExchange: 392 case kIA32Word32AtomicPairCompareExchange: 393 return kHasSideEffect; 394 395 #define CASE(Name) case k##Name: 396 COMMON_ARCH_OPCODE_LIST(CASE) 397 #undef CASE 398 // Already covered in architecture independent code. 399 UNREACHABLE(); 400 } 401 402 UNREACHABLE(); 403 } 404 GetInstructionLatency(const Instruction * instr)405int InstructionScheduler::GetInstructionLatency(const Instruction* instr) { 406 // Basic latency modeling for ia32 instructions. They have been determined 407 // in an empirical way. 408 switch (instr->arch_opcode()) { 409 case kFloat64Mul: 410 return 5; 411 case kIA32Imul: 412 case kIA32ImulHigh: 413 return 5; 414 case kIA32Float32Cmp: 415 case kIA32Float64Cmp: 416 return 9; 417 case kFloat32Add: 418 case kFloat32Sub: 419 case kFloat64Add: 420 case kFloat64Sub: 421 case kFloat32Abs: 422 case kFloat32Neg: 423 case kIA32Float64Max: 424 case kIA32Float64Min: 425 case kFloat64Abs: 426 case kFloat64Neg: 427 return 5; 428 case kFloat32Mul: 429 return 4; 430 case kIA32Float32ToFloat64: 431 case kIA32Float64ToFloat32: 432 return 6; 433 case kIA32Float32Round: 434 case kIA32Float64Round: 435 case kIA32Float32ToInt32: 436 case kIA32Float64ToInt32: 437 return 8; 438 case kIA32Float32ToUint32: 439 return 21; 440 case kIA32Float64ToUint32: 441 return 15; 442 case kIA32Idiv: 443 return 33; 444 case kIA32Udiv: 445 return 26; 446 case kFloat32Div: 447 return 35; 448 case kFloat64Div: 449 return 63; 450 case kIA32Float32Sqrt: 451 case kIA32Float64Sqrt: 452 return 25; 453 case kIA32Float64Mod: 454 return 50; 455 case kArchTruncateDoubleToI: 456 return 9; 457 default: 458 return 1; 459 } 460 } 461 462 } // namespace compiler 463 } // namespace internal 464 } // namespace v8 465