LLVM API Documentation

AllocationOrder.cpp
Go to the documentation of this file.
00001 //===-- llvm/CodeGen/AllocationOrder.cpp - Allocation Order ---------------===//
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 file implements an allocation order for virtual registers.
00011 //
00012 // The preferred allocation order for a virtual register depends on allocation
00013 // hints and target hooks. The AllocationOrder class encapsulates all of that.
00014 //
00015 //===----------------------------------------------------------------------===//
00016 
00017 #include "AllocationOrder.h"
00018 #include "llvm/CodeGen/MachineFunction.h"
00019 #include "llvm/CodeGen/MachineRegisterInfo.h"
00020 #include "llvm/CodeGen/RegisterClassInfo.h"
00021 #include "llvm/CodeGen/VirtRegMap.h"
00022 #include "llvm/Support/Debug.h"
00023 #include "llvm/Support/raw_ostream.h"
00024 
00025 using namespace llvm;
00026 
00027 #define DEBUG_TYPE "regalloc"
00028 
00029 // Compare VirtRegMap::getRegAllocPref().
00030 AllocationOrder::AllocationOrder(unsigned VirtReg,
00031                                  const VirtRegMap &VRM,
00032                                  const RegisterClassInfo &RegClassInfo)
00033   : Pos(0) {
00034   const MachineFunction &MF = VRM.getMachineFunction();
00035   const TargetRegisterInfo *TRI = &VRM.getTargetRegInfo();
00036   Order = RegClassInfo.getOrder(MF.getRegInfo().getRegClass(VirtReg));
00037   TRI->getRegAllocationHints(VirtReg, Order, Hints, MF, &VRM);
00038   rewind();
00039 
00040   DEBUG({
00041     if (!Hints.empty()) {
00042       dbgs() << "hints:";
00043       for (unsigned I = 0, E = Hints.size(); I != E; ++I)
00044         dbgs() << ' ' << PrintReg(Hints[I], TRI);
00045       dbgs() << '\n';
00046     }
00047   });
00048 #ifndef NDEBUG
00049   for (unsigned I = 0, E = Hints.size(); I != E; ++I)
00050     assert(std::find(Order.begin(), Order.end(), Hints[I]) != Order.end() &&
00051            "Target hint is outside allocation order.");
00052 #endif
00053 }