Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(56)

Side by Side Diff: src/IceTargetLoweringX8664Traits.h

Issue 1419903002: Subzero: Refactor x86 register definitions to use the alias mechanism. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: Fix assembler unit tests. Fix register names. Code review changes. Rebase Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/IceTargetLoweringX8632Traits.h ('k') | src/IceTargetLoweringX86BaseImpl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 //===- subzero/src/IceTargetLoweringX8664Traits.h - x86-64 traits -*- C++ -*-=// 1 //===- subzero/src/IceTargetLoweringX8664Traits.h - x86-64 traits -*- C++ -*-=//
2 // 2 //
3 // The Subzero Code Generator 3 // The Subzero Code Generator
4 // 4 //
5 // This file is distributed under the University of Illinois Open Source 5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details. 6 // License. See LICENSE.TXT for details.
7 // 7 //
8 //===----------------------------------------------------------------------===// 8 //===----------------------------------------------------------------------===//
9 /// 9 ///
10 /// \file 10 /// \file
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 static constexpr bool Is64Bit = true; 53 static constexpr bool Is64Bit = true;
54 static constexpr bool HasPopa = false; 54 static constexpr bool HasPopa = false;
55 static constexpr bool HasPusha = false; 55 static constexpr bool HasPusha = false;
56 static constexpr bool UsesX87 = false; 56 static constexpr bool UsesX87 = false;
57 static constexpr ::Ice::RegX8664::GPRRegister Last8BitGPR = 57 static constexpr ::Ice::RegX8664::GPRRegister Last8BitGPR =
58 ::Ice::RegX8664::GPRRegister::Encoded_Reg_r15d; 58 ::Ice::RegX8664::GPRRegister::Encoded_Reg_r15d;
59 59
60 enum ScaleFactor { TIMES_1 = 0, TIMES_2 = 1, TIMES_4 = 2, TIMES_8 = 3 }; 60 enum ScaleFactor { TIMES_1 = 0, TIMES_2 = 1, TIMES_4 = 2, TIMES_8 = 3 };
61 61
62 using GPRRegister = ::Ice::RegX8664::GPRRegister; 62 using GPRRegister = ::Ice::RegX8664::GPRRegister;
63 using ByteRegister = ::Ice::RegX8664::ByteRegister;
63 using XmmRegister = ::Ice::RegX8664::XmmRegister; 64 using XmmRegister = ::Ice::RegX8664::XmmRegister;
64 using ByteRegister = ::Ice::RegX8664::ByteRegister;
65 65
66 using Cond = ::Ice::CondX8664; 66 using Cond = ::Ice::CondX8664;
67 67
68 using RegisterSet = ::Ice::RegX8664; 68 using RegisterSet = ::Ice::RegX8664;
69 static const GPRRegister Encoded_Reg_Accumulator = RegX8664::Encoded_Reg_eax; 69 static const GPRRegister Encoded_Reg_Accumulator = RegX8664::Encoded_Reg_eax;
70 static const GPRRegister Encoded_Reg_Counter = RegX8664::Encoded_Reg_ecx; 70 static const GPRRegister Encoded_Reg_Counter = RegX8664::Encoded_Reg_ecx;
71 static const FixupKind PcRelFixup = llvm::ELF::R_X86_64_PC32; 71 static const FixupKind PcRelFixup = llvm::ELF::R_X86_64_PC32;
72 static const FixupKind RelFixup = llvm::ELF::R_X86_64_32S; 72 static const FixupKind RelFixup = llvm::ELF::R_X86_64_32S;
73 73
74 class Operand { 74 class Operand {
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 Begin, 282 Begin,
283 // SSE2 is the PNaCl baseline instruction set. 283 // SSE2 is the PNaCl baseline instruction set.
284 SSE2 = Begin, 284 SSE2 = Begin,
285 SSE4_1, 285 SSE4_1,
286 End 286 End
287 }; 287 };
288 288
289 static const char *TargetName; 289 static const char *TargetName;
290 static constexpr Type WordType = IceType_i64; 290 static constexpr Type WordType = IceType_i64;
291 291
292 static IceString getRegName(SizeT RegNum, Type Ty) { 292 static IceString getRegName(int32_t RegNum) {
293 assert(RegNum < RegisterSet::Reg_NUM); 293 static const char *const RegNames[] = {
294 static const struct { 294 #define X(val, encode, name, base, scratch, preserved, stackptr, frameptr, \
295 const char *const Name8; 295 isGPR, is64, is32, is16, is8, isXmm, is64To8, is32To8, is16To8, \
296 const char *const Name16; 296 isTrunc8Rcvr, isAhRcvr, aliases) \
297 const char *const Name /*32*/; 297 name,
298 const char *const Name64;
299 } RegNames[] = {
300 #define X(val, encode, name64, name32, name16, name8, scratch, preserved, \
301 stackptr, frameptr, isInt, isFP) \
302 { name8, name16, name32, name64 } \
303 ,
304 REGX8664_TABLE 298 REGX8664_TABLE
305 #undef X 299 #undef X
306 }; 300 };
301 assert(RegNum >= 0);
302 assert(RegNum < RegisterSet::Reg_NUM);
303 return RegNames[RegNum];
304 }
307 305
308 switch (Ty) { 306 static GPRRegister getEncodedGPR(int32_t RegNum) {
309 case IceType_i1: 307 static const GPRRegister GPRRegs[] = {
310 case IceType_i8: 308 #define X(val, encode, name, base, scratch, preserved, stackptr, frameptr, \
311 return RegNames[RegNum].Name8; 309 isGPR, is64, is32, is16, is8, isXmm, is64To8, is32To8, is16To8, \
312 case IceType_i16: 310 isTrunc8Rcvr, isAhRcvr, aliases) \
313 return RegNames[RegNum].Name16; 311 GPRRegister(isGPR ? encode : GPRRegister::Encoded_Not_GPR),
314 case IceType_i64: 312 REGX8664_TABLE
315 return RegNames[RegNum].Name64; 313 #undef X
316 default: 314 };
317 return RegNames[RegNum].Name; 315 assert(RegNum >= 0);
318 } 316 assert(RegNum < RegisterSet::Reg_NUM);
317 assert(GPRRegs[RegNum] != GPRRegister::Encoded_Not_GPR);
318 return GPRRegs[RegNum];
319 } 319 }
320 320
321 static ByteRegister getEncodedByteReg(int32_t RegNum) {
322 static const ByteRegister ByteRegs[] = {
323 #define X(val, encode, name, base, scratch, preserved, stackptr, frameptr, \
324 isGPR, is64, is32, is16, is8, isXmm, is64To8, is32To8, is16To8, \
325 isTrunc8Rcvr, isAhRcvr, aliases) \
326 ByteRegister(is8 ? encode : ByteRegister::Encoded_Not_ByteReg),
327 REGX8664_TABLE
328 #undef X
329 };
330 assert(RegNum >= 0);
331 assert(RegNum < RegisterSet::Reg_NUM);
332 assert(ByteRegs[RegNum] != ByteRegister::Encoded_Not_ByteReg);
333 return ByteRegs[RegNum];
334 }
335
336 static XmmRegister getEncodedXmm(int32_t RegNum) {
337 static const XmmRegister XmmRegs[] = {
338 #define X(val, encode, name, base, scratch, preserved, stackptr, frameptr, \
339 isGPR, is64, is32, is16, is8, isXmm, is64To8, is32To8, is16To8, \
340 isTrunc8Rcvr, isAhRcvr, aliases) \
341 XmmRegister(isXmm ? encode : XmmRegister::Encoded_Not_Xmm),
342 REGX8664_TABLE
343 #undef X
344 };
345 assert(RegNum >= 0);
346 assert(RegNum < RegisterSet::Reg_NUM);
347 assert(XmmRegs[RegNum] != XmmRegister::Encoded_Not_Xmm);
348 return XmmRegs[RegNum];
349 }
350
351 static uint32_t getEncoding(int32_t RegNum) {
352 static const uint32_t Encoding[] = {
353 #define X(val, encode, name, base, scratch, preserved, stackptr, frameptr, \
354 isGPR, is64, is32, is16, is8, isXmm, is64To8, is32To8, is16To8, \
355 isTrunc8Rcvr, isAhRcvr, aliases) \
356 encode,
357 REGX8664_TABLE
358 #undef X
359 };
360 assert(RegNum >= 0);
361 assert(RegNum < RegisterSet::Reg_NUM);
362 return Encoding[RegNum];
363 }
364
365 static inline int32_t getBaseReg(int32_t RegNum) {
366 static const int32_t BaseRegs[] = {
367 #define X(val, encode, name, base, scratch, preserved, stackptr, frameptr, \
368 isGPR, is64, is32, is16, is8, isXmm, is64To8, is32To8, is16To8, \
369 isTrunc8Rcvr, isAhRcvr, aliases) \
370 RegisterSet::base,
371 REGX8664_TABLE
372 #undef X
373 };
374 assert(RegNum >= 0);
375 assert(RegNum < RegisterSet::Reg_NUM);
376 return BaseRegs[RegNum];
377 }
378
379 static int32_t getGprForType(Type, int32_t RegNum) { return RegNum; }
380
321 static void initRegisterSet( 381 static void initRegisterSet(
322 std::array<llvm::SmallBitVector, IceType_NUM> *TypeToRegisterSet, 382 std::array<llvm::SmallBitVector, IceType_NUM> *TypeToRegisterSet,
323 std::array<llvm::SmallBitVector, RegisterSet::Reg_NUM> *RegisterAliases, 383 std::array<llvm::SmallBitVector, RegisterSet::Reg_NUM> *RegisterAliases,
324 llvm::SmallBitVector *ScratchRegs) { 384 llvm::SmallBitVector *ScratchRegs) {
325 llvm::SmallBitVector IntegerRegisters(RegisterSet::Reg_NUM); 385 llvm::SmallBitVector IntegerRegistersI64(RegisterSet::Reg_NUM);
386 llvm::SmallBitVector IntegerRegistersI32(RegisterSet::Reg_NUM);
387 llvm::SmallBitVector IntegerRegistersI16(RegisterSet::Reg_NUM);
326 llvm::SmallBitVector IntegerRegistersI8(RegisterSet::Reg_NUM); 388 llvm::SmallBitVector IntegerRegistersI8(RegisterSet::Reg_NUM);
327 llvm::SmallBitVector FloatRegisters(RegisterSet::Reg_NUM); 389 llvm::SmallBitVector FloatRegisters(RegisterSet::Reg_NUM);
328 llvm::SmallBitVector VectorRegisters(RegisterSet::Reg_NUM); 390 llvm::SmallBitVector VectorRegisters(RegisterSet::Reg_NUM);
329 llvm::SmallBitVector InvalidRegisters(RegisterSet::Reg_NUM); 391 llvm::SmallBitVector InvalidRegisters(RegisterSet::Reg_NUM);
330 ScratchRegs->resize(RegisterSet::Reg_NUM); 392 ScratchRegs->resize(RegisterSet::Reg_NUM);
331 393
332 #define X(val, encode, name64, name32, name16, name8, scratch, preserved, \ 394 #define X(val, encode, name, base, scratch, preserved, stackptr, frameptr, \
333 stackptr, frameptr, isInt, isFP) \ 395 isGPR, is64, is32, is16, is8, isXmm, is64To8, is32To8, is16To8, \
334 (IntegerRegisters)[RegisterSet::val] = isInt; \ 396 isTrunc8Rcvr, isAhRcvr, aliases) \
335 (IntegerRegistersI8)[RegisterSet::val] = isInt; \ 397 (IntegerRegistersI64)[RegisterSet::val] = is64; \
336 (FloatRegisters)[RegisterSet::val] = isFP; \ 398 (IntegerRegistersI32)[RegisterSet::val] = is32; \
337 (VectorRegisters)[RegisterSet::val] = isFP; \ 399 (IntegerRegistersI16)[RegisterSet::val] = is16; \
400 (IntegerRegistersI8)[RegisterSet::val] = is8; \
401 (FloatRegisters)[RegisterSet::val] = isXmm; \
402 (VectorRegisters)[RegisterSet::val] = isXmm; \
338 (*RegisterAliases)[RegisterSet::val].resize(RegisterSet::Reg_NUM); \ 403 (*RegisterAliases)[RegisterSet::val].resize(RegisterSet::Reg_NUM); \
404 for (SizeT RegAlias : aliases) { \
405 assert(!(*RegisterAliases)[RegisterSet::val][RegAlias] && \
406 "Duplicate alias for " #val); \
407 (*RegisterAliases)[RegisterSet::val].set(RegAlias); \
408 } \
339 (*RegisterAliases)[RegisterSet::val].set(RegisterSet::val); \ 409 (*RegisterAliases)[RegisterSet::val].set(RegisterSet::val); \
340 (*ScratchRegs)[RegisterSet::val] = scratch; 410 (*ScratchRegs)[RegisterSet::val] = scratch;
341 REGX8664_TABLE; 411 REGX8664_TABLE;
342 #undef X 412 #undef X
343 413
344 (*TypeToRegisterSet)[IceType_void] = InvalidRegisters; 414 (*TypeToRegisterSet)[IceType_void] = InvalidRegisters;
345 (*TypeToRegisterSet)[IceType_i1] = IntegerRegistersI8; 415 (*TypeToRegisterSet)[IceType_i1] = IntegerRegistersI8;
346 (*TypeToRegisterSet)[IceType_i8] = IntegerRegistersI8; 416 (*TypeToRegisterSet)[IceType_i8] = IntegerRegistersI8;
347 (*TypeToRegisterSet)[IceType_i16] = IntegerRegisters; 417 (*TypeToRegisterSet)[IceType_i16] = IntegerRegistersI16;
348 (*TypeToRegisterSet)[IceType_i32] = IntegerRegisters; 418 (*TypeToRegisterSet)[IceType_i32] = IntegerRegistersI32;
349 (*TypeToRegisterSet)[IceType_i64] = IntegerRegisters; 419 (*TypeToRegisterSet)[IceType_i64] = IntegerRegistersI64;
350 (*TypeToRegisterSet)[IceType_f32] = FloatRegisters; 420 (*TypeToRegisterSet)[IceType_f32] = FloatRegisters;
351 (*TypeToRegisterSet)[IceType_f64] = FloatRegisters; 421 (*TypeToRegisterSet)[IceType_f64] = FloatRegisters;
352 (*TypeToRegisterSet)[IceType_v4i1] = VectorRegisters; 422 (*TypeToRegisterSet)[IceType_v4i1] = VectorRegisters;
353 (*TypeToRegisterSet)[IceType_v8i1] = VectorRegisters; 423 (*TypeToRegisterSet)[IceType_v8i1] = VectorRegisters;
354 (*TypeToRegisterSet)[IceType_v16i1] = VectorRegisters; 424 (*TypeToRegisterSet)[IceType_v16i1] = VectorRegisters;
355 (*TypeToRegisterSet)[IceType_v16i8] = VectorRegisters; 425 (*TypeToRegisterSet)[IceType_v16i8] = VectorRegisters;
356 (*TypeToRegisterSet)[IceType_v8i16] = VectorRegisters; 426 (*TypeToRegisterSet)[IceType_v8i16] = VectorRegisters;
357 (*TypeToRegisterSet)[IceType_v4i32] = VectorRegisters; 427 (*TypeToRegisterSet)[IceType_v4i32] = VectorRegisters;
358 (*TypeToRegisterSet)[IceType_v4f32] = VectorRegisters; 428 (*TypeToRegisterSet)[IceType_v4f32] = VectorRegisters;
359 } 429 }
360 430
361 static llvm::SmallBitVector 431 static llvm::SmallBitVector
362 getRegisterSet(TargetLowering::RegSetMask Include, 432 getRegisterSet(TargetLowering::RegSetMask Include,
363 TargetLowering::RegSetMask Exclude) { 433 TargetLowering::RegSetMask Exclude) {
364 llvm::SmallBitVector Registers(RegisterSet::Reg_NUM); 434 llvm::SmallBitVector Registers(RegisterSet::Reg_NUM);
365 435
366 #define X(val, encode, name64, name32, name16, name8, scratch, preserved, \ 436 #define X(val, encode, name, base, scratch, preserved, stackptr, frameptr, \
367 stackptr, frameptr, isInt, isFP) \ 437 isGPR, is64, is32, is16, is8, isXmm, is64To8, is32To8, is16To8, \
438 isTrunc8Rcvr, isAhRcvr, aliases) \
368 if (scratch && (Include & ::Ice::TargetLowering::RegSet_CallerSave)) \ 439 if (scratch && (Include & ::Ice::TargetLowering::RegSet_CallerSave)) \
369 Registers[RegisterSet::val] = true; \ 440 Registers[RegisterSet::val] = true; \
370 if (preserved && (Include & ::Ice::TargetLowering::RegSet_CalleeSave)) \ 441 if (preserved && (Include & ::Ice::TargetLowering::RegSet_CalleeSave)) \
371 Registers[RegisterSet::val] = true; \ 442 Registers[RegisterSet::val] = true; \
372 if (stackptr && (Include & ::Ice::TargetLowering::RegSet_StackPointer)) \ 443 if (stackptr && (Include & ::Ice::TargetLowering::RegSet_StackPointer)) \
373 Registers[RegisterSet::val] = true; \ 444 Registers[RegisterSet::val] = true; \
374 if (frameptr && (Include & ::Ice::TargetLowering::RegSet_FramePointer)) \ 445 if (frameptr && (Include & ::Ice::TargetLowering::RegSet_FramePointer)) \
375 Registers[RegisterSet::val] = true; \ 446 Registers[RegisterSet::val] = true; \
376 if (scratch && (Exclude & ::Ice::TargetLowering::RegSet_CallerSave)) \ 447 if (scratch && (Exclude & ::Ice::TargetLowering::RegSet_CallerSave)) \
377 Registers[RegisterSet::val] = false; \ 448 Registers[RegisterSet::val] = false; \
(...skipping 24 matching lines...) Expand all
402 // for performance, not correctness. 473 // for performance, not correctness.
403 static const unsigned MaxEquivalenceClassSize = 8; 474 static const unsigned MaxEquivalenceClassSize = 8;
404 using RegisterList = llvm::SmallVector<int32_t, MaxEquivalenceClassSize>; 475 using RegisterList = llvm::SmallVector<int32_t, MaxEquivalenceClassSize>;
405 using EquivalenceClassMap = std::map<uint32_t, RegisterList>; 476 using EquivalenceClassMap = std::map<uint32_t, RegisterList>;
406 EquivalenceClassMap EquivalenceClasses; 477 EquivalenceClassMap EquivalenceClasses;
407 SizeT NumShuffled = 0, NumPreserved = 0; 478 SizeT NumShuffled = 0, NumPreserved = 0;
408 479
409 // Build up the equivalence classes of registers by looking at the register 480 // Build up the equivalence classes of registers by looking at the register
410 // properties as well as whether the registers should be explicitly excluded 481 // properties as well as whether the registers should be explicitly excluded
411 // from shuffling. 482 // from shuffling.
412 #define X(val, encode, name64, name32, name16, name8, scratch, preserved, \ 483 #define X(val, encode, name, base, scratch, preserved, stackptr, frameptr, \
413 stackptr, frameptr, isInt, isFP) \ 484 isGPR, is64, is32, is16, is8, isXmm, is64To8, is32To8, is16To8, \
485 isTrunc8Rcvr, isAhRcvr, aliases) \
414 if (ExcludeRegisters[RegisterSet::val]) { \ 486 if (ExcludeRegisters[RegisterSet::val]) { \
415 /* val stays the same in the resulting permutation. */ \ 487 /* val stays the same in the resulting permutation. */ \
416 Permutation[RegisterSet::val] = RegisterSet::val; \ 488 Permutation[RegisterSet::val] = RegisterSet::val; \
417 ++NumPreserved; \ 489 ++NumPreserved; \
418 } else { \ 490 } else { \
419 const uint32_t Index = (scratch << 0) | (preserved << 1) | \ 491 uint32_t AttrKey = 0; \
420 (/*isI8=*/1 << 2) | (isInt << 3) | (isFP << 4); \ 492 uint32_t Index = 0; \
493 /* Combine relevant attributes into an equivalence class key. */ \
494 Index |= (scratch << (AttrKey++)); \
495 Index |= (preserved << (AttrKey++)); \
496 Index |= (is8 << (AttrKey++)); \
497 Index |= (is16 << (AttrKey++)); \
498 Index |= (is32 << (AttrKey++)); \
499 Index |= (is64 << (AttrKey++)); \
500 Index |= (isXmm << (AttrKey++)); \
421 /* val is assigned to an equivalence class based on its properties. */ \ 501 /* val is assigned to an equivalence class based on its properties. */ \
422 EquivalenceClasses[Index].push_back(RegisterSet::val); \ 502 EquivalenceClasses[Index].push_back(RegisterSet::val); \
423 } 503 }
424 REGX8664_TABLE 504 REGX8664_TABLE
425 #undef X 505 #undef X
426 506
427 // Create a random number generator for regalloc randomization. 507 // Create a random number generator for regalloc randomization.
428 RandomNumberGenerator RNG(Ctx->getFlags().getRandomSeed(), 508 RandomNumberGenerator RNG(Ctx->getFlags().getRandomSeed(),
429 RPE_RegAllocRandomization, Salt); 509 RPE_RegAllocRandomization, Salt);
430 RandomNumberGeneratorWrapper RNGW(RNG); 510 RandomNumberGeneratorWrapper RNGW(RNG);
(...skipping 16 matching lines...) Expand all
447 Ostream &Str = Func->getContext()->getStrDump(); 527 Ostream &Str = Func->getContext()->getStrDump();
448 Str << "Register equivalence classes:\n"; 528 Str << "Register equivalence classes:\n";
449 for (auto I : EquivalenceClasses) { 529 for (auto I : EquivalenceClasses) {
450 Str << "{"; 530 Str << "{";
451 const RegisterList &List = I.second; 531 const RegisterList &List = I.second;
452 bool First = true; 532 bool First = true;
453 for (int32_t Register : List) { 533 for (int32_t Register : List) {
454 if (!First) 534 if (!First)
455 Str << " "; 535 Str << " ";
456 First = false; 536 First = false;
457 Str << getRegName(Register, IceType_i32); 537 Str << getRegName(Register);
458 } 538 }
459 Str << "}\n"; 539 Str << "}\n";
460 } 540 }
461 } 541 }
462 } 542 }
463 543
464 /// The maximum number of arguments to pass in XMM registers 544 /// The maximum number of arguments to pass in XMM registers
465 static const uint32_t X86_MAX_XMM_ARGS = 8; 545 static const uint32_t X86_MAX_XMM_ARGS = 8;
466 /// The maximum number of arguments to pass in GPR registers 546 /// The maximum number of arguments to pass in GPR registers
467 static const uint32_t X86_MAX_GPR_ARGS = 6; 547 static const uint32_t X86_MAX_GPR_ARGS = 6;
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
739 819
740 } // end of namespace X86Internal 820 } // end of namespace X86Internal
741 821
742 namespace X8664 { 822 namespace X8664 {
743 using Traits = ::Ice::X86Internal::MachineTraits<TargetX8664>; 823 using Traits = ::Ice::X86Internal::MachineTraits<TargetX8664>;
744 } // end of namespace X8664 824 } // end of namespace X8664
745 825
746 } // end of namespace Ice 826 } // end of namespace Ice
747 827
748 #endif // SUBZERO_SRC_ICETARGETLOWERINGX8664TRAITS_H 828 #endif // SUBZERO_SRC_ICETARGETLOWERINGX8664TRAITS_H
OLDNEW
« no previous file with comments | « src/IceTargetLoweringX8632Traits.h ('k') | src/IceTargetLoweringX86BaseImpl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698