Path: blob/main/contrib/llvm-project/llvm/lib/CodeGen/AllocationOrder.cpp
35232 views
//===-- llvm/CodeGen/AllocationOrder.cpp - Allocation Order ---------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file implements an allocation order for virtual registers.9//10// The preferred allocation order for a virtual register depends on allocation11// hints and target hooks. The AllocationOrder class encapsulates all of that.12//13//===----------------------------------------------------------------------===//1415#include "AllocationOrder.h"16#include "llvm/CodeGen/MachineFunction.h"17#include "llvm/CodeGen/MachineRegisterInfo.h"18#include "llvm/CodeGen/RegisterClassInfo.h"19#include "llvm/CodeGen/VirtRegMap.h"20#include "llvm/Support/Debug.h"21#include "llvm/Support/raw_ostream.h"2223using namespace llvm;2425#define DEBUG_TYPE "regalloc"2627// Compare VirtRegMap::getRegAllocPref().28AllocationOrder AllocationOrder::create(unsigned VirtReg, const VirtRegMap &VRM,29const RegisterClassInfo &RegClassInfo,30const LiveRegMatrix *Matrix) {31const MachineFunction &MF = VRM.getMachineFunction();32const TargetRegisterInfo *TRI = &VRM.getTargetRegInfo();33auto Order = RegClassInfo.getOrder(MF.getRegInfo().getRegClass(VirtReg));34SmallVector<MCPhysReg, 16> Hints;35bool HardHints =36TRI->getRegAllocationHints(VirtReg, Order, Hints, MF, &VRM, Matrix);3738LLVM_DEBUG({39if (!Hints.empty()) {40dbgs() << "hints:";41for (MCPhysReg Hint : Hints)42dbgs() << ' ' << printReg(Hint, TRI);43dbgs() << '\n';44}45});46assert(all_of(Hints,47[&](MCPhysReg Hint) { return is_contained(Order, Hint); }) &&48"Target hint is outside allocation order.");49return AllocationOrder(std::move(Hints), Order, HardHints);50}515253