80 printv(
unsigned r) : R(r) {}
99 case BT::BitValue::Top:
102 case BT::BitValue::Zero:
105 case BT::BitValue::One:
108 case BT::BitValue::Ref:
116 unsigned n = RC.Bits.
size();
124 bool ConstRef =
false;
126 for (
unsigned i = 1, n = RC.Bits.
size(); i < n; ++i) {
129 bool IsRef = (V.Type == BT::BitValue::Ref);
131 if (!IsRef && V == SV)
133 if (IsRef && SV.
Type == BT::BitValue::Ref && V.RefI.Reg == SV.
RefI.
Reg) {
135 SeqRef = (V.RefI.Pos == SV.
RefI.
Pos+1);
136 ConstRef = (V.RefI.Pos == SV.
RefI.
Pos);
138 if (SeqRef && V.RefI.Pos == SV.
RefI.
Pos+(i-Start))
140 if (ConstRef && V.RefI.Pos == SV.
RefI.
Pos)
147 unsigned Count = i - Start;
151 OS <<
'-' << i-1 <<
"]:";
152 if (SV.
Type == BT::BitValue::Ref && SeqRef)
154 << SV.
RefI.
Pos+(Count-1) <<
']';
159 SeqRef = ConstRef =
false;
163 unsigned Count = n - Start;
165 OS <<
"]:" << RC[Start];
167 OS <<
'-' << n-1 <<
"]:";
169 if (SV.
Type == BT::BitValue::Ref && SeqRef)
171 << SV.
RefI.
Pos+(Count-1) <<
']';
183 for (
const std::pair<unsigned, RegisterCell>
P : Map)
205 bool Changed =
false;
208 Changed |= Bits[i].meet(RCV,
BitRef(SelfR, i));
230 Bits[i] = RC[i+(W-
B)];
241 RC.Bits[i-
B] = Bits[i];
247 RC.Bits[i] = Bits[i+
B];
249 RC.Bits[i+(W-
B)] = Bits[i];
267 Bits[i] = Bits[W-Sh+i];
270 Bits[i+Sh] = Tmp.Bits[i];
288 Bits[i+W] = RC.Bits[i];
296 while (
C < W && Bits[
C] == V)
305 while (
C < W && Bits[W-(
C+1)] == V)
312 if (RC.Bits.
size() != W)
315 if (Bits[i] != RC[i])
321 for (
unsigned i = 0, n =
width(); i < n; ++i) {
324 Bits[i].RefI =
BitRef(R, i);
364 CellMapType::const_iterator
F = M.find(RR.
Reg);
369 return F->second.extract(M);
382 assert(RR.
Sub == 0 &&
"Unexpected sub-register in definition");
391 if (!
A[i].is(0) && !
A[i].is(1))
425 assert((
unsigned)BW ==
A.getBitWidth() &&
"BitWidth overflow");
439 for (
I = 0;
I < W; ++
I) {
442 if (!V1.
num() || !V2.num())
444 unsigned S =
bool(V1) +
bool(V2) + Carry;
455 else if (V2.is(Carry))
472 for (
I = 0;
I < W; ++
I) {
475 if (!V1.
num() || !V2.num())
477 unsigned S =
bool(V1) -
bool(V2) - Borrow;
544 Res.
fill(W-Sh, W, Sign);
560 else if (V1.
is(0) || V2.is(0))
578 if (V1.
is(1) || V2.is(1))
648 if ((
C < AW && A1[AW-1-
C].num()) ||
C == AW)
658 if ((
C < AW && A1[
C].num()) ||
C == AW)
670 Res.
fill(FromN, W, Sign);
699 assert(AtN < W1 && AtN+W2 <= W1);
708 assert(Sub == 0 &&
"Generic BitTracker::mask called for Sub != 0");
710 assert(W > 0 &&
"Cannot generate mask for empty register");
722 unsigned Opc =
MI.getOpcode();
724 case TargetOpcode::REG_SEQUENCE: {
728 unsigned SS =
MI.getOperand(2).getImm();
730 unsigned ST =
MI.getOperand(4).getImm();
741 case TargetOpcode::COPY: {
765bool BT::UseQueueType::Cmp::operator()(
const MachineInstr *InstA,
782 auto F = Dist.find(
MI);
787 unsigned D = std::distance(
I, E);
788 Dist.insert(std::make_pair(
MI,
D));
792 return getDist(InstA) > getDist(InstB);
803 assert(MD.
getSubReg() == 0 &&
"Unexpected sub-register in definition");
804 RegisterRef DefRR(MD);
807 RegisterCell DefC = ME.
getCell(DefRR, Map);
811 bool Changed =
false;
815 int PredN =
PB->getNumber();
819 if (!EdgeExec.count(CFGEdge(PredN, ThisN))) {
821 dbgs() <<
" not executable\n";
826 RegisterCell ResC = ME.
getCell(RU, Map);
829 <<
" cell: " << ResC <<
"\n";
830 Changed |= DefC.meet(ResC, DefRR.Reg);
836 <<
" cell: " << DefC <<
"\n";
838 visitUsesOf(DefRR.Reg);
845 if (
MI.isDebugInstr())
847 assert(!
MI.isBranch() &&
"Unexpected branch instruction");
854 if (!MO.isReg() || !MO.isUse())
858 <<
" cell: " << ME.
getCell(RU, Map) <<
"\n";
860 dbgs() <<
"Outputs:\n";
861 for (
const std::pair<const unsigned, RegisterCell> &
P : ResMap) {
862 RegisterRef RD(
P.first);
864 << ME.
getCell(RD, ResMap) <<
"\n";
872 if (!MO.isReg() || !MO.isDef())
875 assert(RD.Sub == 0 &&
"Unexpected sub-register in definition");
876 if (!RD.Reg.isVirtual())
879 bool Changed =
false;
880 if (!Eval || ResMap.count(RD.Reg) == 0) {
884 if (RefC != ME.
getCell(RD, Map)) {
889 RegisterCell DefC = ME.
getCell(RD, Map);
890 RegisterCell ResC = ME.
getCell(RD, ResMap);
898 for (
uint16_t i = 0, w = DefC.width(); i < w; ++i) {
899 BitValue &
V = DefC[i];
921 bool FallsThrough =
true, DefaultToAll =
false;
922 int ThisN =
B.getNumber();
929 assert(
MI.isBranch() &&
"Expecting branch instruction");
930 InstrExec.insert(&
MI);
931 bool Eval = ME.
evaluate(
MI, Map, BTs, FallsThrough);
938 dbgs() <<
" failed to evaluate: will add all CFG successors\n";
939 }
else if (!DefaultToAll) {
942 dbgs() <<
" adding targets:";
946 dbgs() <<
"\n falls through\n";
948 dbgs() <<
"\n does not fall through\n";
950 Targets.insert(BTs.begin(), BTs.end());
953 }
while (FallsThrough && It !=
End);
955 if (
B.mayHaveInlineAsmBr())
969 if (Next != MF.
end())
970 Targets.insert(&*Next);
978 FlowQ.push(CFGEdge(ThisN,
TB->getNumber()));
984 <<
" cell: " << ME.
getCell(Reg, Map) <<
'\n';
1001 assert(Map.count(OldRR.
Reg) > 0 &&
"OldRR not present in map");
1007 assert((OME-OMB == NME-NMB) &&
1008 "Substituting registers of different lengths");
1009 for (std::pair<const unsigned, RegisterCell> &
P : Map) {
1015 if (V.RefI.Pos < OMB || V.RefI.Pos > OME)
1017 V.RefI.Reg = NewRR.
Reg;
1018 V.RefI.Pos += NMB-OMB;
1026 int BN =
B->getNumber();
1028 return ReachedBB.
count(BN);
1034 assert(!
MI.isBranch() &&
"Only non-branches are allowed");
1035 InstrExec.insert(&
MI);
1042 while (!FlowQ.empty())
1054void BT::runEdgeQueue(
BitVector &BlockScanned) {
1055 while (!FlowQ.empty()) {
1056 CFGEdge Edge = FlowQ.front();
1059 if (!EdgeExec.insert(Edge).second)
1061 ReachedBB.
insert(Edge.second);
1066 while (It !=
End && It->isPHI()) {
1068 InstrExec.insert(&PI);
1075 if (BlockScanned[Edge.second])
1077 BlockScanned[Edge.second] =
true;
1080 while (It !=
End && !It->isBranch()) {
1082 InstrExec.insert(&
MI);
1089 if (Next != MF.
end() &&
B.isSuccessor(&*Next)) {
1090 int ThisN =
B.getNumber();
1091 int NextN = Next->getNumber();
1092 FlowQ.push(CFGEdge(ThisN, NextN));
1097 visitBranchesFrom(*It);
1102void BT::runUseQueue() {
1103 while (!UseQ.empty()) {
1107 if (!InstrExec.count(&UseI))
1112 visitNonBranch(UseI);
1114 visitBranchesFrom(UseI);
1127 assert(
B.getNumber() >= 0 &&
"Disconnected block");
1128 unsigned BN =
B.getNumber();
1136 int EntryN = Entry->getNumber();
1138 FlowQ.push(CFGEdge(-1, EntryN));
1140 while (!FlowQ.empty() || !UseQ.empty()) {
1141 runEdgeQueue(BlockScanned);
unsigned const MachineRegisterInfo * MRI
for(const MachineOperand &MO :llvm::drop_begin(OldMI.operands(), Desc.getNumOperands()))
This file implements a class to represent arbitrary precision integral constant values and operations...
This file implements the BitVector class.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
PassBuilder PB(Machine, PassOpts->PTO, std::nullopt, &PIC)
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Class for arbitrary precision integers.
This is the shared class of boolean and integer constants.
const APInt & getValue() const
Return the constant as an APInt value reference.
Wrapper class representing physical registers. Should be passed by value.
int getNumber() const
MachineBasicBlocks are uniquely numbered at the function level, unless they're not in a MachineFuncti...
MachineBasicBlock * getBlockNumbered(unsigned N) const
getBlockNumbered - MachineBasicBlocks are automatically numbered when they are inserted into the mach...
BasicBlockListType::const_iterator const_iterator
Representation of each machine instruction.
const MachineBasicBlock * getParent() const
unsigned getNumOperands() const
Retuns the total number of operands.
bool isBranch(QueryType Type=AnyInBundle) const
Returns true if this is a conditional, unconditional, or indirect branch.
const MachineOperand & getOperand(unsigned i) const
MachineOperand class - Representation of each machine instruction operand.
unsigned getSubReg() const
MachineBasicBlock * getMBB() const
const TargetRegisterClass * getRegClass(Register Reg) const
Return the register class of the specified virtual register.
iterator_range< use_instr_nodbg_iterator > use_nodbg_instructions(Register Reg) const
Wrapper class representing virtual and physical registers.
MCRegister asMCReg() const
Utility to check-convert this value to a MCRegister.
static unsigned virtReg2Index(Register Reg)
Convert a virtual register number to a 0-based index.
constexpr bool isVirtual() const
Return true if the specified register number is in the virtual register namespace.
constexpr bool isPhysical() const
Return true if the specified register number is in the physical register namespace.
const TargetRegisterClass * getMinimalPhysRegClass(MCRegister Reg, MVT VT=MVT::Other) const
Returns the Register Class of a physical register of the given type, picking the most sub register cl...
TypeSize getRegSizeInBits(const TargetRegisterClass &RC) const
Return the size in bits of a register from class RC.
MCRegister getSubReg(MCRegister Reg, unsigned Idx) const
Returns the physical register number of sub-register "Index" for physical register RegNo.
std::pair< iterator, bool > insert(const ValueT &V)
void reserve(size_t Size)
Grow the DenseSet so that it can contain at least NumEntries items before resizing again.
size_type count(const_arg_type_t< ValueT > V) const
Return 1 if the specified key is in the set, 0 otherwise.
This class implements an extremely fast bulk output stream that can only output to a stream.
@ C
The default llvm calling convention, compatible with C.
@ TB
TB - TwoByte - Set if this instruction has a two byte opcode, which starts with a 0x0F byte before th...
This is an optimization pass for GlobalISel generic memory operations.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
raw_ostream & operator<<(raw_ostream &OS, const APFixedPoint &FX)
Printable printReg(Register Reg, const TargetRegisterInfo *TRI=nullptr, unsigned SubIdx=0, const MachineRegisterInfo *MRI=nullptr)
Prints virtual and physical registers with or without a TRI instance.
Printable printMBBReference(const MachineBasicBlock &MBB)
Prints a machine basic block reference.
static BitValue ref(const BitValue &V)
bool is(unsigned T) const
static BitValue self(const BitRef &Self=BitRef())
virtual bool evaluate(const MachineInstr &MI, const CellMapType &Inputs, CellMapType &Outputs) const
const TargetRegisterInfo & TRI
RegisterCell eIMM(int64_t V, uint16_t W) const
uint16_t getRegBitWidth(const RegisterRef &RR) const
bool isInt(const RegisterCell &A) const
MachineRegisterInfo & MRI
virtual const TargetRegisterClass & composeWithSubRegIndex(const TargetRegisterClass &RC, unsigned Idx) const
virtual bool track(const TargetRegisterClass *RC) const
void putCell(const RegisterRef &RR, RegisterCell RC, CellMapType &M) const
virtual uint16_t getPhysRegBitWidth(MCRegister Reg) const
RegisterCell getCell(const RegisterRef &RR, const CellMapType &M) const
virtual BitMask mask(Register Reg, unsigned Sub) const
static RegisterCell self(unsigned Reg, uint16_t Width)
static RegisterCell ref(const RegisterCell &C)
RegisterCell & fill(uint16_t B, uint16_t E, const BitValue &V)
RegisterCell extract(const BitMask &M) const
RegisterCell & regify(unsigned R)
uint16_t ct(bool B) const
RegisterCell & insert(const RegisterCell &RC, const BitMask &M)
static RegisterCell top(uint16_t Width)
uint16_t cl(bool B) const
RegisterCell & rol(uint16_t Sh)
SetVector< const MachineBasicBlock * > BranchTargetList
bool reached(const MachineBasicBlock *B) const
void subst(RegisterRef OldRR, RegisterRef NewRR)
void print_cells(raw_ostream &OS) const
std::map< unsigned, RegisterCell > CellMapType
void put(RegisterRef RR, const RegisterCell &RC)
BitTracker(const MachineEvaluator &E, MachineFunction &F)
void visit(const MachineInstr &MI)
RegisterCell get(RegisterRef RR) const