2
0

AllocationOrder.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. //===-- llvm/CodeGen/AllocationOrder.cpp - Allocation Order ---------------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. //
  10. // This file implements an allocation order for virtual registers.
  11. //
  12. // The preferred allocation order for a virtual register depends on allocation
  13. // hints and target hooks. The AllocationOrder class encapsulates all of that.
  14. //
  15. //===----------------------------------------------------------------------===//
  16. #include "AllocationOrder.h"
  17. #include "llvm/CodeGen/MachineFunction.h"
  18. #include "llvm/CodeGen/MachineRegisterInfo.h"
  19. #include "llvm/CodeGen/RegisterClassInfo.h"
  20. #include "llvm/CodeGen/VirtRegMap.h"
  21. #include "llvm/Support/Debug.h"
  22. #include "llvm/Support/raw_ostream.h"
  23. using namespace llvm;
  24. #define DEBUG_TYPE "regalloc"
  25. // Compare VirtRegMap::getRegAllocPref().
  26. AllocationOrder::AllocationOrder(unsigned VirtReg,
  27. const VirtRegMap &VRM,
  28. const RegisterClassInfo &RegClassInfo)
  29. : Pos(0) {
  30. const MachineFunction &MF = VRM.getMachineFunction();
  31. const TargetRegisterInfo *TRI = &VRM.getTargetRegInfo();
  32. Order = RegClassInfo.getOrder(MF.getRegInfo().getRegClass(VirtReg));
  33. TRI->getRegAllocationHints(VirtReg, Order, Hints, MF, &VRM);
  34. rewind();
  35. DEBUG({
  36. if (!Hints.empty()) {
  37. dbgs() << "hints:";
  38. for (unsigned I = 0, E = Hints.size(); I != E; ++I)
  39. dbgs() << ' ' << PrintReg(Hints[I], TRI);
  40. dbgs() << '\n';
  41. }
  42. });
  43. #ifndef NDEBUG
  44. for (unsigned I = 0, E = Hints.size(); I != E; ++I)
  45. assert(std::find(Order.begin(), Order.end(), Hints[I]) != Order.end() &&
  46. "Target hint is outside allocation order.");
  47. #endif
  48. }