Path: blob/main/contrib/llvm-project/llvm/lib/Target/AArch64/AArch64A57FPLoadBalancing.cpp
35269 views
//===-- AArch64A57FPLoadBalancing.cpp - Balance FP ops statically on A57---===//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// For best-case performance on Cortex-A57, we should try to use a balanced8// mix of odd and even D-registers when performing a critical sequence of9// independent, non-quadword FP/ASIMD floating-point multiply or10// multiply-accumulate operations.11//12// This pass attempts to detect situations where the register allocation may13// adversely affect this load balancing and to change the registers used so as14// to better utilize the CPU.15//16// Ideally we'd just take each multiply or multiply-accumulate in turn and17// allocate it alternating even or odd registers. However, multiply-accumulates18// are most efficiently performed in the same functional unit as their19// accumulation operand. Therefore this pass tries to find maximal sequences20// ("Chains") of multiply-accumulates linked via their accumulation operand,21// and assign them all the same "color" (oddness/evenness).22//23// This optimization affects S-register and D-register floating point24// multiplies and FMADD/FMAs, as well as vector (floating point only) muls and25// FMADD/FMA. Q register instructions (and 128-bit vector instructions) are26// not affected.27//===----------------------------------------------------------------------===//2829#include "AArch64.h"30#include "AArch64InstrInfo.h"31#include "AArch64Subtarget.h"32#include "llvm/ADT/EquivalenceClasses.h"33#include "llvm/CodeGen/MachineFunction.h"34#include "llvm/CodeGen/MachineFunctionPass.h"35#include "llvm/CodeGen/MachineInstr.h"36#include "llvm/CodeGen/MachineInstrBuilder.h"37#include "llvm/CodeGen/MachineRegisterInfo.h"38#include "llvm/CodeGen/RegisterClassInfo.h"39#include "llvm/CodeGen/RegisterScavenging.h"40#include "llvm/Support/CommandLine.h"41#include "llvm/Support/Debug.h"42#include "llvm/Support/raw_ostream.h"43using namespace llvm;4445#define DEBUG_TYPE "aarch64-a57-fp-load-balancing"4647// Enforce the algorithm to use the scavenged register even when the original48// destination register is the correct color. Used for testing.49static cl::opt<bool>50TransformAll("aarch64-a57-fp-load-balancing-force-all",51cl::desc("Always modify dest registers regardless of color"),52cl::init(false), cl::Hidden);5354// Never use the balance information obtained from chains - return a specific55// color always. Used for testing.56static cl::opt<unsigned>57OverrideBalance("aarch64-a57-fp-load-balancing-override",58cl::desc("Ignore balance information, always return "59"(1: Even, 2: Odd)."),60cl::init(0), cl::Hidden);6162//===----------------------------------------------------------------------===//63// Helper functions6465// Is the instruction a type of multiply on 64-bit (or 32-bit) FPRs?66static bool isMul(MachineInstr *MI) {67switch (MI->getOpcode()) {68case AArch64::FMULSrr:69case AArch64::FNMULSrr:70case AArch64::FMULDrr:71case AArch64::FNMULDrr:72return true;73default:74return false;75}76}7778// Is the instruction a type of FP multiply-accumulate on 64-bit (or 32-bit) FPRs?79static bool isMla(MachineInstr *MI) {80switch (MI->getOpcode()) {81case AArch64::FMSUBSrrr:82case AArch64::FMADDSrrr:83case AArch64::FNMSUBSrrr:84case AArch64::FNMADDSrrr:85case AArch64::FMSUBDrrr:86case AArch64::FMADDDrrr:87case AArch64::FNMSUBDrrr:88case AArch64::FNMADDDrrr:89return true;90default:91return false;92}93}9495//===----------------------------------------------------------------------===//9697namespace {98/// A "color", which is either even or odd. Yes, these aren't really colors99/// but the algorithm is conceptually doing two-color graph coloring.100enum class Color { Even, Odd };101#ifndef NDEBUG102static const char *ColorNames[2] = { "Even", "Odd" };103#endif104105class Chain;106107class AArch64A57FPLoadBalancing : public MachineFunctionPass {108MachineRegisterInfo *MRI;109const TargetRegisterInfo *TRI;110RegisterClassInfo RCI;111112public:113static char ID;114explicit AArch64A57FPLoadBalancing() : MachineFunctionPass(ID) {115initializeAArch64A57FPLoadBalancingPass(*PassRegistry::getPassRegistry());116}117118bool runOnMachineFunction(MachineFunction &F) override;119120MachineFunctionProperties getRequiredProperties() const override {121return MachineFunctionProperties().set(122MachineFunctionProperties::Property::NoVRegs);123}124125StringRef getPassName() const override {126return "A57 FP Anti-dependency breaker";127}128129void getAnalysisUsage(AnalysisUsage &AU) const override {130AU.setPreservesCFG();131MachineFunctionPass::getAnalysisUsage(AU);132}133134private:135bool runOnBasicBlock(MachineBasicBlock &MBB);136bool colorChainSet(std::vector<Chain*> GV, MachineBasicBlock &MBB,137int &Balance);138bool colorChain(Chain *G, Color C, MachineBasicBlock &MBB);139int scavengeRegister(Chain *G, Color C, MachineBasicBlock &MBB);140void scanInstruction(MachineInstr *MI, unsigned Idx,141std::map<unsigned, Chain*> &Active,142std::vector<std::unique_ptr<Chain>> &AllChains);143void maybeKillChain(MachineOperand &MO, unsigned Idx,144std::map<unsigned, Chain*> &RegChains);145Color getColor(unsigned Register);146Chain *getAndEraseNext(Color PreferredColor, std::vector<Chain*> &L);147};148}149150char AArch64A57FPLoadBalancing::ID = 0;151152INITIALIZE_PASS_BEGIN(AArch64A57FPLoadBalancing, DEBUG_TYPE,153"AArch64 A57 FP Load-Balancing", false, false)154INITIALIZE_PASS_END(AArch64A57FPLoadBalancing, DEBUG_TYPE,155"AArch64 A57 FP Load-Balancing", false, false)156157namespace {158/// A Chain is a sequence of instructions that are linked together by159/// an accumulation operand. For example:160///161/// fmul def d0, ?162/// fmla def d1, ?, ?, killed d0163/// fmla def d2, ?, ?, killed d1164///165/// There may be other instructions interleaved in the sequence that166/// do not belong to the chain. These other instructions must not use167/// the "chain" register at any point.168///169/// We currently only support chains where the "chain" operand is killed170/// at each link in the chain for simplicity.171/// A chain has three important instructions - Start, Last and Kill.172/// * The start instruction is the first instruction in the chain.173/// * Last is the final instruction in the chain.174/// * Kill may or may not be defined. If defined, Kill is the instruction175/// where the outgoing value of the Last instruction is killed.176/// This information is important as if we know the outgoing value is177/// killed with no intervening uses, we can safely change its register.178///179/// Without a kill instruction, we must assume the outgoing value escapes180/// beyond our model and either must not change its register or must181/// create a fixup FMOV to keep the old register value consistent.182///183class Chain {184public:185/// The important (marker) instructions.186MachineInstr *StartInst, *LastInst, *KillInst;187/// The index, from the start of the basic block, that each marker188/// appears. These are stored so we can do quick interval tests.189unsigned StartInstIdx, LastInstIdx, KillInstIdx;190/// All instructions in the chain.191std::set<MachineInstr*> Insts;192/// True if KillInst cannot be modified. If this is true,193/// we cannot change LastInst's outgoing register.194/// This will be true for tied values and regmasks.195bool KillIsImmutable;196/// The "color" of LastInst. This will be the preferred chain color,197/// as changing intermediate nodes is easy but changing the last198/// instruction can be more tricky.199Color LastColor;200201Chain(MachineInstr *MI, unsigned Idx, Color C)202: StartInst(MI), LastInst(MI), KillInst(nullptr),203StartInstIdx(Idx), LastInstIdx(Idx), KillInstIdx(0),204LastColor(C) {205Insts.insert(MI);206}207208/// Add a new instruction into the chain. The instruction's dest operand209/// has the given color.210void add(MachineInstr *MI, unsigned Idx, Color C) {211LastInst = MI;212LastInstIdx = Idx;213LastColor = C;214assert((KillInstIdx == 0 || LastInstIdx < KillInstIdx) &&215"Chain: broken invariant. A Chain can only be killed after its last "216"def");217218Insts.insert(MI);219}220221/// Return true if MI is a member of the chain.222bool contains(MachineInstr &MI) { return Insts.count(&MI) > 0; }223224/// Return the number of instructions in the chain.225unsigned size() const {226return Insts.size();227}228229/// Inform the chain that its last active register (the dest register of230/// LastInst) is killed by MI with no intervening uses or defs.231void setKill(MachineInstr *MI, unsigned Idx, bool Immutable) {232KillInst = MI;233KillInstIdx = Idx;234KillIsImmutable = Immutable;235assert((KillInstIdx == 0 || LastInstIdx < KillInstIdx) &&236"Chain: broken invariant. A Chain can only be killed after its last "237"def");238}239240/// Return the first instruction in the chain.241MachineInstr *getStart() const { return StartInst; }242/// Return the last instruction in the chain.243MachineInstr *getLast() const { return LastInst; }244/// Return the "kill" instruction (as set with setKill()) or NULL.245MachineInstr *getKill() const { return KillInst; }246/// Return an instruction that can be used as an iterator for the end247/// of the chain. This is the maximum of KillInst (if set) and LastInst.248MachineBasicBlock::iterator end() const {249return ++MachineBasicBlock::iterator(KillInst ? KillInst : LastInst);250}251MachineBasicBlock::iterator begin() const { return getStart(); }252253/// Can the Kill instruction (assuming one exists) be modified?254bool isKillImmutable() const { return KillIsImmutable; }255256/// Return the preferred color of this chain.257Color getPreferredColor() {258if (OverrideBalance != 0)259return OverrideBalance == 1 ? Color::Even : Color::Odd;260return LastColor;261}262263/// Return true if this chain (StartInst..KillInst) overlaps with Other.264bool rangeOverlapsWith(const Chain &Other) const {265unsigned End = KillInst ? KillInstIdx : LastInstIdx;266unsigned OtherEnd = Other.KillInst ?267Other.KillInstIdx : Other.LastInstIdx;268269return StartInstIdx <= OtherEnd && Other.StartInstIdx <= End;270}271272/// Return true if this chain starts before Other.273bool startsBefore(const Chain *Other) const {274return StartInstIdx < Other->StartInstIdx;275}276277/// Return true if the group will require a fixup MOV at the end.278bool requiresFixup() const {279return (getKill() && isKillImmutable()) || !getKill();280}281282/// Return a simple string representation of the chain.283std::string str() const {284std::string S;285raw_string_ostream OS(S);286287OS << "{";288StartInst->print(OS, /* SkipOpers= */true);289OS << " -> ";290LastInst->print(OS, /* SkipOpers= */true);291if (KillInst) {292OS << " (kill @ ";293KillInst->print(OS, /* SkipOpers= */true);294OS << ")";295}296OS << "}";297298return OS.str();299}300301};302303} // end anonymous namespace304305//===----------------------------------------------------------------------===//306307bool AArch64A57FPLoadBalancing::runOnMachineFunction(MachineFunction &F) {308if (skipFunction(F.getFunction()))309return false;310311if (!F.getSubtarget<AArch64Subtarget>().balanceFPOps())312return false;313314bool Changed = false;315LLVM_DEBUG(dbgs() << "***** AArch64A57FPLoadBalancing *****\n");316317MRI = &F.getRegInfo();318TRI = F.getRegInfo().getTargetRegisterInfo();319RCI.runOnMachineFunction(F);320321for (auto &MBB : F) {322Changed |= runOnBasicBlock(MBB);323}324325return Changed;326}327328bool AArch64A57FPLoadBalancing::runOnBasicBlock(MachineBasicBlock &MBB) {329bool Changed = false;330LLVM_DEBUG(dbgs() << "Running on MBB: " << MBB331<< " - scanning instructions...\n");332333// First, scan the basic block producing a set of chains.334335// The currently "active" chains - chains that can be added to and haven't336// been killed yet. This is keyed by register - all chains can only have one337// "link" register between each inst in the chain.338std::map<unsigned, Chain*> ActiveChains;339std::vector<std::unique_ptr<Chain>> AllChains;340unsigned Idx = 0;341for (auto &MI : MBB)342scanInstruction(&MI, Idx++, ActiveChains, AllChains);343344LLVM_DEBUG(dbgs() << "Scan complete, " << AllChains.size()345<< " chains created.\n");346347// Group the chains into disjoint sets based on their liveness range. This is348// a poor-man's version of graph coloring. Ideally we'd create an interference349// graph and perform full-on graph coloring on that, but;350// (a) That's rather heavyweight for only two colors.351// (b) We expect multiple disjoint interference regions - in practice the live352// range of chains is quite small and they are clustered between loads353// and stores.354EquivalenceClasses<Chain*> EC;355for (auto &I : AllChains)356EC.insert(I.get());357358for (auto &I : AllChains)359for (auto &J : AllChains)360if (I != J && I->rangeOverlapsWith(*J))361EC.unionSets(I.get(), J.get());362LLVM_DEBUG(dbgs() << "Created " << EC.getNumClasses() << " disjoint sets.\n");363364// Now we assume that every member of an equivalence class interferes365// with every other member of that class, and with no members of other classes.366367// Convert the EquivalenceClasses to a simpler set of sets.368std::vector<std::vector<Chain*> > V;369for (auto I = EC.begin(), E = EC.end(); I != E; ++I) {370std::vector<Chain*> Cs(EC.member_begin(I), EC.member_end());371if (Cs.empty()) continue;372V.push_back(std::move(Cs));373}374375// Now we have a set of sets, order them by start address so376// we can iterate over them sequentially.377llvm::sort(V,378[](const std::vector<Chain *> &A, const std::vector<Chain *> &B) {379return A.front()->startsBefore(B.front());380});381382// As we only have two colors, we can track the global (BB-level) balance of383// odds versus evens. We aim to keep this near zero to keep both execution384// units fed.385// Positive means we're even-heavy, negative we're odd-heavy.386//387// FIXME: If chains have interdependencies, for example:388// mul r0, r1, r2389// mul r3, r0, r1390// We do not model this and may color each one differently, assuming we'll391// get ILP when we obviously can't. This hasn't been seen to be a problem392// in practice so far, so we simplify the algorithm by ignoring it.393int Parity = 0;394395for (auto &I : V)396Changed |= colorChainSet(std::move(I), MBB, Parity);397398return Changed;399}400401Chain *AArch64A57FPLoadBalancing::getAndEraseNext(Color PreferredColor,402std::vector<Chain*> &L) {403if (L.empty())404return nullptr;405406// We try and get the best candidate from L to color next, given that our407// preferred color is "PreferredColor". L is ordered from larger to smaller408// chains. It is beneficial to color the large chains before the small chains,409// but if we can't find a chain of the maximum length with the preferred color,410// we fuzz the size and look for slightly smaller chains before giving up and411// returning a chain that must be recolored.412413// FIXME: Does this need to be configurable?414const unsigned SizeFuzz = 1;415unsigned MinSize = L.front()->size() - SizeFuzz;416for (auto I = L.begin(), E = L.end(); I != E; ++I) {417if ((*I)->size() <= MinSize) {418// We've gone past the size limit. Return the previous item.419Chain *Ch = *--I;420L.erase(I);421return Ch;422}423424if ((*I)->getPreferredColor() == PreferredColor) {425Chain *Ch = *I;426L.erase(I);427return Ch;428}429}430431// Bailout case - just return the first item.432Chain *Ch = L.front();433L.erase(L.begin());434return Ch;435}436437bool AArch64A57FPLoadBalancing::colorChainSet(std::vector<Chain*> GV,438MachineBasicBlock &MBB,439int &Parity) {440bool Changed = false;441LLVM_DEBUG(dbgs() << "colorChainSet(): #sets=" << GV.size() << "\n");442443// Sort by descending size order so that we allocate the most important444// sets first.445// Tie-break equivalent sizes by sorting chains requiring fixups before446// those without fixups. The logic here is that we should look at the447// chains that we cannot change before we look at those we can,448// so the parity counter is updated and we know what color we should449// change them to!450// Final tie-break with instruction order so pass output is stable (i.e. not451// dependent on malloc'd pointer values).452llvm::sort(GV, [](const Chain *G1, const Chain *G2) {453if (G1->size() != G2->size())454return G1->size() > G2->size();455if (G1->requiresFixup() != G2->requiresFixup())456return G1->requiresFixup() > G2->requiresFixup();457// Make sure startsBefore() produces a stable final order.458assert((G1 == G2 || (G1->startsBefore(G2) ^ G2->startsBefore(G1))) &&459"Starts before not total order!");460return G1->startsBefore(G2);461});462463Color PreferredColor = Parity < 0 ? Color::Even : Color::Odd;464while (Chain *G = getAndEraseNext(PreferredColor, GV)) {465// Start off by assuming we'll color to our own preferred color.466Color C = PreferredColor;467if (Parity == 0)468// But if we really don't care, use the chain's preferred color.469C = G->getPreferredColor();470471LLVM_DEBUG(dbgs() << " - Parity=" << Parity472<< ", Color=" << ColorNames[(int)C] << "\n");473474// If we'll need a fixup FMOV, don't bother. Testing has shown that this475// happens infrequently and when it does it has at least a 50% chance of476// slowing code down instead of speeding it up.477if (G->requiresFixup() && C != G->getPreferredColor()) {478C = G->getPreferredColor();479LLVM_DEBUG(dbgs() << " - " << G->str()480<< " - not worthwhile changing; "481"color remains "482<< ColorNames[(int)C] << "\n");483}484485Changed |= colorChain(G, C, MBB);486487Parity += (C == Color::Even) ? G->size() : -G->size();488PreferredColor = Parity < 0 ? Color::Even : Color::Odd;489}490491return Changed;492}493494int AArch64A57FPLoadBalancing::scavengeRegister(Chain *G, Color C,495MachineBasicBlock &MBB) {496// Can we find an appropriate register that is available throughout the life497// of the chain? Simulate liveness backwards until the end of the chain.498LiveRegUnits Units(*TRI);499Units.addLiveOuts(MBB);500MachineBasicBlock::iterator I = MBB.end();501MachineBasicBlock::iterator ChainEnd = G->end();502while (I != ChainEnd) {503--I;504Units.stepBackward(*I);505}506507// Check which register units are alive throughout the chain.508MachineBasicBlock::iterator ChainBegin = G->begin();509assert(ChainBegin != ChainEnd && "Chain should contain instructions");510do {511--I;512Units.accumulate(*I);513} while (I != ChainBegin);514515// Make sure we allocate in-order, to get the cheapest registers first.516unsigned RegClassID = ChainBegin->getDesc().operands()[0].RegClass;517auto Ord = RCI.getOrder(TRI->getRegClass(RegClassID));518for (auto Reg : Ord) {519if (!Units.available(Reg))520continue;521if (C == getColor(Reg))522return Reg;523}524525return -1;526}527528bool AArch64A57FPLoadBalancing::colorChain(Chain *G, Color C,529MachineBasicBlock &MBB) {530bool Changed = false;531LLVM_DEBUG(dbgs() << " - colorChain(" << G->str() << ", "532<< ColorNames[(int)C] << ")\n");533534// Try and obtain a free register of the right class. Without a register535// to play with we cannot continue.536int Reg = scavengeRegister(G, C, MBB);537if (Reg == -1) {538LLVM_DEBUG(dbgs() << "Scavenging (thus coloring) failed!\n");539return false;540}541LLVM_DEBUG(dbgs() << " - Scavenged register: " << printReg(Reg, TRI) << "\n");542543std::map<unsigned, unsigned> Substs;544for (MachineInstr &I : *G) {545if (!G->contains(I) && (&I != G->getKill() || G->isKillImmutable()))546continue;547548// I is a member of G, or I is a mutable instruction that kills G.549550std::vector<unsigned> ToErase;551for (auto &U : I.operands()) {552if (U.isReg() && U.isUse() && Substs.find(U.getReg()) != Substs.end()) {553Register OrigReg = U.getReg();554U.setReg(Substs[OrigReg]);555if (U.isKill())556// Don't erase straight away, because there may be other operands557// that also reference this substitution!558ToErase.push_back(OrigReg);559} else if (U.isRegMask()) {560for (auto J : Substs) {561if (U.clobbersPhysReg(J.first))562ToErase.push_back(J.first);563}564}565}566// Now it's safe to remove the substs identified earlier.567for (auto J : ToErase)568Substs.erase(J);569570// Only change the def if this isn't the last instruction.571if (&I != G->getKill()) {572MachineOperand &MO = I.getOperand(0);573574bool Change = TransformAll || getColor(MO.getReg()) != C;575if (G->requiresFixup() && &I == G->getLast())576Change = false;577578if (Change) {579Substs[MO.getReg()] = Reg;580MO.setReg(Reg);581582Changed = true;583}584}585}586assert(Substs.size() == 0 && "No substitutions should be left active!");587588if (G->getKill()) {589LLVM_DEBUG(dbgs() << " - Kill instruction seen.\n");590} else {591// We didn't have a kill instruction, but we didn't seem to need to change592// the destination register anyway.593LLVM_DEBUG(dbgs() << " - Destination register not changed.\n");594}595return Changed;596}597598void AArch64A57FPLoadBalancing::scanInstruction(599MachineInstr *MI, unsigned Idx, std::map<unsigned, Chain *> &ActiveChains,600std::vector<std::unique_ptr<Chain>> &AllChains) {601// Inspect "MI", updating ActiveChains and AllChains.602603if (isMul(MI)) {604605for (auto &I : MI->uses())606maybeKillChain(I, Idx, ActiveChains);607for (auto &I : MI->defs())608maybeKillChain(I, Idx, ActiveChains);609610// Create a new chain. Multiplies don't require forwarding so can go on any611// unit.612Register DestReg = MI->getOperand(0).getReg();613614LLVM_DEBUG(dbgs() << "New chain started for register "615<< printReg(DestReg, TRI) << " at " << *MI);616617auto G = std::make_unique<Chain>(MI, Idx, getColor(DestReg));618ActiveChains[DestReg] = G.get();619AllChains.push_back(std::move(G));620621} else if (isMla(MI)) {622623// It is beneficial to keep MLAs on the same functional unit as their624// accumulator operand.625Register DestReg = MI->getOperand(0).getReg();626Register AccumReg = MI->getOperand(3).getReg();627628maybeKillChain(MI->getOperand(1), Idx, ActiveChains);629maybeKillChain(MI->getOperand(2), Idx, ActiveChains);630if (DestReg != AccumReg)631maybeKillChain(MI->getOperand(0), Idx, ActiveChains);632633if (ActiveChains.find(AccumReg) != ActiveChains.end()) {634LLVM_DEBUG(dbgs() << "Chain found for accumulator register "635<< printReg(AccumReg, TRI) << " in MI " << *MI);636637// For simplicity we only chain together sequences of MULs/MLAs where the638// accumulator register is killed on each instruction. This means we don't639// need to track other uses of the registers we want to rewrite.640//641// FIXME: We could extend to handle the non-kill cases for more coverage.642if (MI->getOperand(3).isKill()) {643// Add to chain.644LLVM_DEBUG(dbgs() << "Instruction was successfully added to chain.\n");645ActiveChains[AccumReg]->add(MI, Idx, getColor(DestReg));646// Handle cases where the destination is not the same as the accumulator.647if (DestReg != AccumReg) {648ActiveChains[DestReg] = ActiveChains[AccumReg];649ActiveChains.erase(AccumReg);650}651return;652}653654LLVM_DEBUG(655dbgs() << "Cannot add to chain because accumulator operand wasn't "656<< "marked <kill>!\n");657maybeKillChain(MI->getOperand(3), Idx, ActiveChains);658}659660LLVM_DEBUG(dbgs() << "Creating new chain for dest register "661<< printReg(DestReg, TRI) << "\n");662auto G = std::make_unique<Chain>(MI, Idx, getColor(DestReg));663ActiveChains[DestReg] = G.get();664AllChains.push_back(std::move(G));665666} else {667668// Non-MUL or MLA instruction. Invalidate any chain in the uses or defs669// lists.670for (auto &I : MI->uses())671maybeKillChain(I, Idx, ActiveChains);672for (auto &I : MI->defs())673maybeKillChain(I, Idx, ActiveChains);674675}676}677678void AArch64A57FPLoadBalancing::679maybeKillChain(MachineOperand &MO, unsigned Idx,680std::map<unsigned, Chain*> &ActiveChains) {681// Given an operand and the set of active chains (keyed by register),682// determine if a chain should be ended and remove from ActiveChains.683MachineInstr *MI = MO.getParent();684685if (MO.isReg()) {686687// If this is a KILL of a current chain, record it.688if (MO.isKill() && ActiveChains.find(MO.getReg()) != ActiveChains.end()) {689LLVM_DEBUG(dbgs() << "Kill seen for chain " << printReg(MO.getReg(), TRI)690<< "\n");691ActiveChains[MO.getReg()]->setKill(MI, Idx, /*Immutable=*/MO.isTied());692}693ActiveChains.erase(MO.getReg());694695} else if (MO.isRegMask()) {696697for (auto I = ActiveChains.begin(), E = ActiveChains.end();698I != E;) {699if (MO.clobbersPhysReg(I->first)) {700LLVM_DEBUG(dbgs() << "Kill (regmask) seen for chain "701<< printReg(I->first, TRI) << "\n");702I->second->setKill(MI, Idx, /*Immutable=*/true);703ActiveChains.erase(I++);704} else705++I;706}707708}709}710711Color AArch64A57FPLoadBalancing::getColor(unsigned Reg) {712if ((TRI->getEncodingValue(Reg) % 2) == 0)713return Color::Even;714else715return Color::Odd;716}717718// Factory function used by AArch64TargetMachine to add the pass to the passmanager.719FunctionPass *llvm::createAArch64A57FPLoadBalancing() {720return new AArch64A57FPLoadBalancing();721}722723724