2017-09-30 05:55:49 +08:00
|
|
|
//==- llvm/CodeGen/AggressiveAntiDepBreaker.h - Anti-Dep Support -*- C++ -*-==//
|
2009-10-27 03:32:42 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2009-10-27 03:32:42 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements the AggressiveAntiDepBreaker class, which
|
|
|
|
// implements register anti-dependence breaking during post-RA
|
|
|
|
// scheduling. It attempts to break all anti-dependencies within a
|
|
|
|
// block.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-08-14 00:26:38 +08:00
|
|
|
#ifndef LLVM_LIB_CODEGEN_AGGRESSIVEANTIDEPBREAKER_H
|
|
|
|
#define LLVM_LIB_CODEGEN_AGGRESSIVEANTIDEPBREAKER_H
|
2009-10-27 03:32:42 +08:00
|
|
|
|
2012-12-04 15:12:27 +08:00
|
|
|
#include "llvm/ADT/BitVector.h"
|
2020-04-14 03:26:44 +08:00
|
|
|
#include "llvm/CodeGen/AntiDepBreaker.h"
|
2017-11-17 09:07:10 +08:00
|
|
|
#include "llvm/CodeGen/TargetSubtargetInfo.h"
|
2017-09-30 05:55:49 +08:00
|
|
|
#include "llvm/Support/Compiler.h"
|
2009-11-21 03:32:48 +08:00
|
|
|
#include <map>
|
2017-09-30 05:55:49 +08:00
|
|
|
#include <set>
|
|
|
|
#include <vector>
|
2009-10-27 03:32:42 +08:00
|
|
|
|
|
|
|
namespace llvm {
|
2017-09-30 05:55:49 +08:00
|
|
|
|
|
|
|
class MachineBasicBlock;
|
|
|
|
class MachineFunction;
|
|
|
|
class MachineInstr;
|
|
|
|
class MachineOperand;
|
|
|
|
class MachineRegisterInfo;
|
2011-06-17 05:56:21 +08:00
|
|
|
class RegisterClassInfo;
|
2017-09-30 05:55:49 +08:00
|
|
|
class TargetInstrInfo;
|
|
|
|
class TargetRegisterClass;
|
|
|
|
class TargetRegisterInfo;
|
2011-06-17 05:56:21 +08:00
|
|
|
|
2009-11-21 03:32:48 +08:00
|
|
|
/// Contains all the state necessary for anti-dep breaking.
|
2015-07-01 22:47:39 +08:00
|
|
|
class LLVM_LIBRARY_VISIBILITY AggressiveAntiDepState {
|
2009-10-27 06:31:16 +08:00
|
|
|
public:
|
2014-09-21 22:48:16 +08:00
|
|
|
/// Information about a register reference within a liverange
|
2017-09-30 05:55:49 +08:00
|
|
|
struct RegisterReference {
|
2014-09-21 22:48:16 +08:00
|
|
|
/// The registers operand
|
2009-10-27 03:32:42 +08:00
|
|
|
MachineOperand *Operand;
|
2017-09-30 05:55:49 +08:00
|
|
|
|
2014-09-21 22:48:16 +08:00
|
|
|
/// The register class
|
2009-10-27 03:32:42 +08:00
|
|
|
const TargetRegisterClass *RC;
|
2017-09-30 05:55:49 +08:00
|
|
|
};
|
2009-10-27 03:32:42 +08:00
|
|
|
|
2009-10-27 06:31:16 +08:00
|
|
|
private:
|
2014-09-21 22:48:16 +08:00
|
|
|
/// Number of non-virtual target registers (i.e. TRI->getNumRegs()).
|
2009-12-10 01:18:22 +08:00
|
|
|
const unsigned NumTargetRegs;
|
|
|
|
|
2014-09-21 22:48:16 +08:00
|
|
|
/// Implements a disjoint-union data structure to
|
2009-10-27 03:32:42 +08:00
|
|
|
/// form register groups. A node is represented by an index into
|
|
|
|
/// the vector. A node can "point to" itself to indicate that it
|
|
|
|
/// is the parent of a group, or point to another node to indicate
|
|
|
|
/// that it is a member of the same group as that node.
|
|
|
|
std::vector<unsigned> GroupNodes;
|
2010-01-07 00:48:02 +08:00
|
|
|
|
2014-09-21 22:48:16 +08:00
|
|
|
/// For each register, the index of the GroupNode
|
2009-10-27 03:32:42 +08:00
|
|
|
/// currently representing the group that the register belongs to.
|
|
|
|
/// Register 0 is always represented by the 0 group, a group
|
|
|
|
/// composed of registers that are not eligible for anti-aliasing.
|
2010-07-16 02:40:50 +08:00
|
|
|
std::vector<unsigned> GroupNodeIndices;
|
2010-01-07 00:48:02 +08:00
|
|
|
|
2014-09-21 22:48:16 +08:00
|
|
|
/// Map registers to all their references within a live range.
|
2009-10-27 03:32:42 +08:00
|
|
|
std::multimap<unsigned, RegisterReference> RegRefs;
|
2010-01-07 00:48:02 +08:00
|
|
|
|
2015-04-23 01:42:37 +08:00
|
|
|
/// The index of the most recent kill (proceeding bottom-up),
|
2009-10-27 03:32:42 +08:00
|
|
|
/// or ~0u if the register is not live.
|
2010-07-16 02:43:09 +08:00
|
|
|
std::vector<unsigned> KillIndices;
|
2010-01-07 00:48:02 +08:00
|
|
|
|
2015-04-23 01:42:37 +08:00
|
|
|
/// The index of the most recent complete def (proceeding bottom
|
2009-10-27 03:32:42 +08:00
|
|
|
/// up), or ~0u if the register is live.
|
2010-07-16 02:43:09 +08:00
|
|
|
std::vector<unsigned> DefIndices;
|
2009-10-27 03:32:42 +08:00
|
|
|
|
|
|
|
public:
|
2009-12-10 01:18:22 +08:00
|
|
|
AggressiveAntiDepState(const unsigned TargetRegs, MachineBasicBlock *BB);
|
2010-01-07 00:48:02 +08:00
|
|
|
|
2014-09-21 22:48:16 +08:00
|
|
|
/// Return the kill indices.
|
2010-07-16 02:43:09 +08:00
|
|
|
std::vector<unsigned> &GetKillIndices() { return KillIndices; }
|
2009-10-27 03:32:42 +08:00
|
|
|
|
2014-09-21 22:48:16 +08:00
|
|
|
/// Return the define indices.
|
2010-07-16 02:43:09 +08:00
|
|
|
std::vector<unsigned> &GetDefIndices() { return DefIndices; }
|
2009-10-27 03:32:42 +08:00
|
|
|
|
2014-09-21 22:48:16 +08:00
|
|
|
/// Return the RegRefs map.
|
2009-10-27 06:31:16 +08:00
|
|
|
std::multimap<unsigned, RegisterReference>& GetRegRefs() { return RegRefs; }
|
2009-10-27 03:32:42 +08:00
|
|
|
|
2014-09-21 22:48:16 +08:00
|
|
|
// Get the group for a register. The returned value is
|
2009-10-27 03:32:42 +08:00
|
|
|
// the index of the GroupNode representing the group.
|
|
|
|
unsigned GetGroup(unsigned Reg);
|
2010-01-07 00:48:02 +08:00
|
|
|
|
2014-09-21 22:48:16 +08:00
|
|
|
// Return a vector of the registers belonging to a group.
|
|
|
|
// If RegRefs is non-NULL then only included referenced registers.
|
2009-11-14 03:52:48 +08:00
|
|
|
void GetGroupRegs(
|
|
|
|
unsigned Group,
|
|
|
|
std::vector<unsigned> &Regs,
|
2010-01-07 00:48:02 +08:00
|
|
|
std::multimap<unsigned,
|
|
|
|
AggressiveAntiDepState::RegisterReference> *RegRefs);
|
2009-10-27 03:32:42 +08:00
|
|
|
|
2014-09-21 22:48:16 +08:00
|
|
|
// Union Reg1's and Reg2's groups to form a new group.
|
|
|
|
// Return the index of the GroupNode representing the group.
|
2009-10-27 03:32:42 +08:00
|
|
|
unsigned UnionGroups(unsigned Reg1, unsigned Reg2);
|
|
|
|
|
2014-09-21 22:48:16 +08:00
|
|
|
// Remove a register from its current group and place
|
2009-10-27 03:32:42 +08:00
|
|
|
// it alone in its own group. Return the index of the GroupNode
|
|
|
|
// representing the registers new group.
|
|
|
|
unsigned LeaveGroup(unsigned Reg);
|
|
|
|
|
2014-09-21 22:48:16 +08:00
|
|
|
/// Return true if Reg is live.
|
2009-10-27 03:32:42 +08:00
|
|
|
bool IsLive(unsigned Reg);
|
2009-10-27 06:31:16 +08:00
|
|
|
};
|
|
|
|
|
2015-07-01 22:47:39 +08:00
|
|
|
class LLVM_LIBRARY_VISIBILITY AggressiveAntiDepBreaker
|
|
|
|
: public AntiDepBreaker {
|
2017-09-30 05:55:49 +08:00
|
|
|
MachineFunction &MF;
|
2009-10-27 06:31:16 +08:00
|
|
|
MachineRegisterInfo &MRI;
|
2010-06-16 15:35:02 +08:00
|
|
|
const TargetInstrInfo *TII;
|
2009-10-27 06:31:16 +08:00
|
|
|
const TargetRegisterInfo *TRI;
|
2011-06-17 05:56:21 +08:00
|
|
|
const RegisterClassInfo &RegClassInfo;
|
2009-11-14 03:52:48 +08:00
|
|
|
|
2014-09-21 22:48:16 +08:00
|
|
|
/// The set of registers that should only be
|
2009-11-14 03:52:48 +08:00
|
|
|
/// renamed if they are on the critical path.
|
|
|
|
BitVector CriticalPathSet;
|
2009-10-27 06:31:16 +08:00
|
|
|
|
2014-09-21 22:48:16 +08:00
|
|
|
/// The state used to identify and rename anti-dependence registers.
|
2017-09-30 05:55:49 +08:00
|
|
|
AggressiveAntiDepState *State = nullptr;
|
2009-10-27 06:31:16 +08:00
|
|
|
|
|
|
|
public:
|
2017-09-30 05:55:49 +08:00
|
|
|
AggressiveAntiDepBreaker(MachineFunction &MFi,
|
2011-07-02 05:01:15 +08:00
|
|
|
const RegisterClassInfo &RCI,
|
|
|
|
TargetSubtargetInfo::RegClassVector& CriticalPathRCs);
|
2015-04-11 10:11:45 +08:00
|
|
|
~AggressiveAntiDepBreaker() override;
|
2010-01-07 00:48:02 +08:00
|
|
|
|
2014-09-21 22:48:16 +08:00
|
|
|
/// Initialize anti-dep breaking for a new basic block.
|
2014-03-07 17:26:03 +08:00
|
|
|
void StartBlock(MachineBasicBlock *BB) override;
|
2009-10-27 06:31:16 +08:00
|
|
|
|
2014-09-21 22:48:16 +08:00
|
|
|
/// Identifiy anti-dependencies along the critical path
|
2009-10-27 06:31:16 +08:00
|
|
|
/// of the ScheduleDAG and break them by renaming registers.
|
2017-09-30 05:55:49 +08:00
|
|
|
unsigned BreakAntiDependencies(const std::vector<SUnit> &SUnits,
|
2010-04-20 07:11:58 +08:00
|
|
|
MachineBasicBlock::iterator Begin,
|
|
|
|
MachineBasicBlock::iterator End,
|
2011-06-03 05:26:52 +08:00
|
|
|
unsigned InsertPosIndex,
|
2014-03-07 17:26:03 +08:00
|
|
|
DbgValueVector &DbgValues) override;
|
2009-10-27 06:31:16 +08:00
|
|
|
|
2014-09-21 22:48:16 +08:00
|
|
|
/// Update liveness information to account for the current
|
2009-10-27 06:31:16 +08:00
|
|
|
/// instruction, which will not be scheduled.
|
2016-02-28 03:33:37 +08:00
|
|
|
void Observe(MachineInstr &MI, unsigned Count,
|
2014-03-07 17:26:03 +08:00
|
|
|
unsigned InsertPosIndex) override;
|
2009-10-27 06:31:16 +08:00
|
|
|
|
2014-09-21 22:48:16 +08:00
|
|
|
/// Finish anti-dep breaking for a basic block.
|
2014-03-07 17:26:03 +08:00
|
|
|
void FinishBlock() override;
|
2009-10-27 06:31:16 +08:00
|
|
|
|
|
|
|
private:
|
2011-06-17 05:56:21 +08:00
|
|
|
/// Keep track of a position in the allocation order for each regclass.
|
2017-09-30 05:55:49 +08:00
|
|
|
using RenameOrderType = std::map<const TargetRegisterClass *, unsigned>;
|
2009-11-05 09:19:35 +08:00
|
|
|
|
2014-09-21 22:48:16 +08:00
|
|
|
/// Return true if MO represents a register
|
2009-10-27 03:32:42 +08:00
|
|
|
/// that is both implicitly used and defined in MI
|
2016-02-28 03:33:37 +08:00
|
|
|
bool IsImplicitDefUse(MachineInstr &MI, MachineOperand &MO);
|
2010-01-07 00:48:02 +08:00
|
|
|
|
2014-09-21 22:48:16 +08:00
|
|
|
/// If MI implicitly def/uses a register, then
|
2009-10-27 03:32:42 +08:00
|
|
|
/// return that register and all subregisters.
|
2016-02-28 03:33:37 +08:00
|
|
|
void GetPassthruRegs(MachineInstr &MI, std::set<unsigned> &PassthruRegs);
|
2009-10-27 03:32:42 +08:00
|
|
|
|
2009-11-20 07:12:37 +08:00
|
|
|
void HandleLastUse(unsigned Reg, unsigned KillIdx, const char *tag,
|
2014-04-16 12:21:27 +08:00
|
|
|
const char *header = nullptr,
|
|
|
|
const char *footer = nullptr);
|
2009-11-20 07:12:37 +08:00
|
|
|
|
2016-02-28 03:33:37 +08:00
|
|
|
void PrescanInstruction(MachineInstr &MI, unsigned Count,
|
|
|
|
std::set<unsigned> &PassthruRegs);
|
|
|
|
void ScanInstruction(MachineInstr &MI, unsigned Count);
|
2009-10-27 03:32:42 +08:00
|
|
|
BitVector GetRenameRegisters(unsigned Reg);
|
|
|
|
bool FindSuitableFreeRegisters(unsigned AntiDepGroupIndex,
|
2009-11-05 09:19:35 +08:00
|
|
|
RenameOrderType& RenameOrder,
|
2009-10-27 03:32:42 +08:00
|
|
|
std::map<unsigned, unsigned> &RenameMap);
|
|
|
|
};
|
|
|
|
|
2017-09-30 05:55:49 +08:00
|
|
|
} // end namespace llvm
|
|
|
|
|
|
|
|
#endif // LLVM_LIB_CODEGEN_AGGRESSIVEANTIDEPBREAKER_H
|