81 printv(
unsigned r) : R(r) {}
117 unsigned n = RC.Bits.
size();
125 bool ConstRef =
false;
127 for (
unsigned i = 1, n = RC.Bits.
size(); i < n; ++i) {
132 if (!IsRef && V == SV)
148 unsigned Count = i - Start;
152 OS <<
'-' << i-1 <<
"]:";
155 << SV.
RefI.
Pos+(Count-1) <<
']';
160 SeqRef = ConstRef =
false;
164 unsigned Count = n - Start;
166 OS <<
"]:" << RC[Start];
168 OS <<
'-' << n-1 <<
"]:";
172 << SV.
RefI.
Pos+(Count-1) <<
']';
184 for (
const std::pair<unsigned, RegisterCell>
P : Map)
185 dbgs() <<
printReg(
P.first, &ME.TRI) <<
" -> " <<
P.second <<
"\n";
206 bool Changed =
false;
207 for (uint16_t i = 0, n = Bits.
size(); i < n; ++i) {
209 Changed |= Bits[i].meet(RCV,
BitRef(SelfR, i));
225 for (uint16_t i = 0; i <=
E-
B; ++i)
228 for (uint16_t i = 0; i <
W-
B; ++i)
230 for (uint16_t i = 0; i <=
E; ++i)
231 Bits[i] = RC[i+(
W-B)];
241 for (uint16_t i = B; i <=
E; ++i)
242 RC.Bits[i-B] = Bits[i];
247 for (uint16_t i = 0; i <
W-
B; ++i)
248 RC.Bits[i] = Bits[i+B];
249 for (uint16_t i = 0; i <=
E; ++i)
250 RC.Bits[i+(
W-B)] = Bits[i];
264 for (uint16_t i = 0; i < W-Sh; ++i)
267 for (uint16_t i = 0; i < Sh; ++i)
268 Bits[i] = Bits[W-Sh+i];
270 for (uint16_t i = 0; i < W-Sh; ++i)
271 Bits[i+Sh] = Tmp.Bits[i];
288 for (uint16_t i = 0; i < WRC; ++i)
289 Bits[i+W] = RC.Bits[i];
297 while (C < W && Bits[C] == V)
306 while (C < W && Bits[W-(C+1)] == V)
312 uint16_t
W = Bits.
size();
313 if (RC.Bits.
size() !=
W)
315 for (uint16_t i = 0; i <
W; ++i)
316 if (Bits[i] != RC[i])
322 for (
unsigned i = 0, n =
width(); i < n; ++i) {
325 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");
390 for (uint16_t i = 0; i <
W; ++i)
391 if (!A[i].is(0) && !A[i].is(1))
401 for (uint16_t i = 0; i <
W; ++i) {
415 for (uint16_t i = 0; i <
W; ++i) {
427 for (uint16_t i = 0; i < BW; ++i)
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;
501 uint16_t
Z = A1.
ct(
false) + A2.
ct(
false);
511 uint16_t
Z = A1.
ct(
false) + A2.
ct(
false);
544 Res.
fill(W-Sh, W, Sign);
553 for (uint16_t i = 0; i <
W; ++i) {
560 else if (V1.
is(0) || V2.
is(0))
575 for (uint16_t i = 0; i <
W; ++i) {
578 if (V1.
is(1) || V2.
is(1))
597 for (uint16_t i = 0; i <
W; ++i) {
615 for (uint16_t i = 0; i <
W; ++i) {
628 uint16_t BitN)
const {
636 uint16_t BitN)
const {
645 uint16_t
C = A1.
cl(B), AW = A1.
width();
648 if ((C < AW && A1[AW-1-C].num()) || C == AW)
655 uint16_t
C = A1.
ct(B), AW = A1.
width();
658 if ((C < AW && A1[C].num()) || C == AW)
664 uint16_t FromN)
const {
670 Res.
fill(FromN, W, Sign);
675 uint16_t FromN)
const {
684 uint16_t
B, uint16_t
E)
const {
689 uint16_t Last = (E > 0) ? E-1 : W-1;
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");
725 case TargetOpcode::REG_SEQUENCE: {
742 case TargetOpcode::COPY: {
766 bool BT::UseQueueType::Cmp::operator()(
const MachineInstr *InstA,
783 auto F = Dist.find(
MI);
788 unsigned D = std::distance(
I, E);
789 Dist.insert(std::make_pair(
MI, D));
793 return getDist(InstA) > getDist(InstB);
804 assert(MD.getSubReg() == 0 &&
"Unexpected sub-register in definition");
806 uint16_t DefBW = ME.getRegBitWidth(DefRR);
812 bool Changed =
false;
820 if (!EdgeExec.count(CFGEdge(PredN, ThisN))) {
822 dbgs() <<
" not executable\n";
830 <<
" cell: " << ResC <<
"\n";
831 Changed |= DefC.
meet(ResC, DefRR.Reg);
836 dbgs() <<
"Output: " <<
printReg(DefRR.Reg, &ME.TRI, DefRR.Sub)
837 <<
" cell: " << DefC <<
"\n";
838 ME.putCell(DefRR, DefC, Map);
839 visitUsesOf(DefRR.Reg);
851 bool Eval = ME.evaluate(MI, Map, ResMap);
860 <<
" cell: " << ME.getCell(RU, Map) <<
"\n";
862 dbgs() <<
"Outputs:\n";
863 for (
const std::pair<unsigned, RegisterCell> &
P : ResMap) {
866 << ME.getCell(RD, ResMap) <<
"\n";
874 if (!MO.isReg() || !MO.isDef())
877 assert(RD.
Sub == 0 &&
"Unexpected sub-register in definition");
881 bool Changed =
false;
882 if (!Eval || ResMap.count(RD.
Reg) == 0) {
884 uint16_t DefBW = ME.getRegBitWidth(RD);
886 if (RefC != ME.getCell(RD, Map)) {
887 ME.putCell(RD, RefC, Map);
900 for (uint16_t i = 0, w = DefC.
width(); i < w; ++i) {
912 ME.putCell(RD, DefC, Map);
923 bool FallsThrough =
true, DefaultToAll =
false;
932 InstrExec.insert(&MI);
933 bool Eval = ME.evaluate(MI, Map, BTs, FallsThrough);
940 dbgs() <<
" failed to evaluate: will add all CFG successors\n";
941 }
else if (!DefaultToAll) {
944 dbgs() <<
" adding targets:";
945 for (
unsigned i = 0, n = BTs.
size(); i < n; ++i)
948 dbgs() <<
"\n falls through\n";
950 dbgs() <<
"\n does not fall through\n";
955 }
while (FallsThrough && It != End);
968 if (Next != MF.end())
977 FlowQ.push(CFGEdge(ThisN,
TB->getNumber()));
980 void BT::visitUsesOf(
unsigned Reg) {
982 dbgs() <<
"queuing uses of modified reg " <<
printReg(Reg, &ME.TRI)
983 <<
" cell: " << ME.getCell(Reg, Map) <<
'\n';
990 return ME.getCell(RR, Map);
994 ME.putCell(RR, RC, Map);
1000 assert(Map.count(OldRR.
Reg) > 0 &&
"OldRR not present in map");
1003 uint16_t OMB = OM.
first(), OME = OM.last();
1004 uint16_t NMB = NM.
first(), NME = NM.
last();
1006 assert((OME-OMB == NME-NMB) &&
1007 "Substituting registers of different lengths");
1008 for (std::pair<const unsigned, RegisterCell> &
P : Map) {
1010 for (uint16_t i = 0, w = RC.
width(); i < w; ++i) {
1027 return ReachedBB.count(BN);
1034 InstrExec.insert(&MI);
1041 while (!FlowQ.empty())
1050 ReachedBB.reserve(MF.size());
1053 void BT::runEdgeQueue(
BitVector &BlockScanned) {
1054 while (!FlowQ.empty()) {
1055 CFGEdge Edge = FlowQ.front();
1058 if (EdgeExec.count(Edge))
1060 EdgeExec.insert(Edge);
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);
1091 int NextN = Next->getNumber();
1092 FlowQ.push(CFGEdge(ThisN, NextN));
1097 visitBranchesFrom(*It);
1102 void 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();
1138 FlowQ.push(CFGEdge(-1, EntryN));
1140 while (!FlowQ.empty() || !UseQ.empty()) {
1141 runEdgeQueue(BlockScanned);
virtual bool evaluate(const MachineInstr &MI, const CellMapType &Inputs, CellMapType &Outputs) const
RegisterCell eASL(const RegisterCell &A1, uint16_t Sh) const
const TargetRegisterInfo & TRI
MachineBasicBlock * getMBB() const
const TargetRegisterClass * getRegClass(unsigned Reg) const
Return the register class of the specified virtual register.
RegisterCell & fill(uint16_t B, uint16_t E, const BitValue &V)
static unsigned virtReg2Index(unsigned Reg)
Convert a virtual register number to a 0-based index.
This class represents lattice values for constants.
size_type size() const
Determine the number of elements in the SetVector.
RegisterCell eASR(const RegisterCell &A1, uint16_t Sh) const
static RegisterCell top(uint16_t Width)
static bool isVirtualRegister(unsigned Reg)
Return true if the specified register number is in the virtual register namespace.
void putCell(const RegisterRef &RR, RegisterCell RC, CellMapType &M) const
void visit(const MachineInstr &MI)
static RegisterCell self(unsigned Reg, uint16_t Width)
RegisterCell & rol(uint16_t Sh)
bool isInt(const RegisterCell &A) const
iterator_range< mop_iterator > operands()
iterator end()
Get an iterator to the end of the SetVector.
RegisterCell eORL(const RegisterCell &A1, const RegisterCell &A2) const
unsigned getBitWidth() const
Return the number of bits in the APInt.
iterator_range< succ_iterator > successors()
void print_cells(raw_ostream &OS) const
Printable printMBBReference(const MachineBasicBlock &MBB)
Prints a machine basic block reference.
unsigned getNumOperands() const
Retuns the total number of operands.
Printable printReg(unsigned Reg, const TargetRegisterInfo *TRI=nullptr, unsigned SubIdx=0, const MachineRegisterInfo *MRI=nullptr)
Prints virtual and physical registers with or without a TRI instance.
RegisterCell extract(const BitMask &M) const
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
RegisterCell eLSR(const RegisterCell &A1, uint16_t Sh) const
zlib-gnu style compression
This file implements a class to represent arbitrary precision integral constant values and operations...
uint16_t cl(bool B) const
bool insert(const value_type &X)
Insert a new element into the SetVector.
iterator begin()
Get an iterator to the beginning of the SetVector.
const APInt & getValue() const
Return the constant as an APInt value reference.
RegisterCell eADD(const RegisterCell &A1, const RegisterCell &A2) const
bool reached(const MachineBasicBlock *B) const
int getNumber() const
MachineBasicBlocks are uniquely numbered at the function level, unless they're not in a MachineFuncti...
bool isBranch(QueryType Type=AnyInBundle) const
Returns true if this is a conditional, unconditional, or indirect branch.
RegisterCell eCLB(const RegisterCell &A1, bool B, uint16_t W) const
RegisterCell eSUB(const RegisterCell &A1, const RegisterCell &A2) const
RegisterCell eIMM(int64_t V, uint16_t W) const
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
unsigned const MachineRegisterInfo * MRI
bool operator==(const RegisterCell &RC) const
RegisterCell eNOT(const RegisterCell &A1) const
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file contains the declarations for the subclasses of Constant, which represent the different fla...
virtual const TargetRegisterClass & composeWithSubRegIndex(const TargetRegisterClass &RC, unsigned Idx) const
unsigned getSubReg(unsigned Reg, unsigned Idx) const
Returns the physical register number of sub-register "Index" for physical register RegNo...
RegisterCell eAND(const RegisterCell &A1, const RegisterCell &A2) const
void subst(RegisterRef OldRR, RegisterRef NewRR)
virtual uint16_t getPhysRegBitWidth(unsigned Reg) const
self_iterator getIterator()
virtual bool track(const TargetRegisterClass *RC) const
virtual BitMask mask(unsigned Reg, unsigned Sub) const
RegisterCell eINS(const RegisterCell &A1, const RegisterCell &A2, uint16_t AtN) const
bool isDebugInstr() const
std::map< unsigned, RegisterCell > CellMapType
RegisterCell eMLS(const RegisterCell &A1, const RegisterCell &A2) const
uint16_t getRegBitWidth(const RegisterRef &RR) const
Iterator for intrusive lists based on ilist_node.
This is the shared class of boolean and integer constants.
static BitValue self(const BitRef &Self=BitRef())
RegisterCell eSET(const RegisterCell &A1, uint16_t BitN) const
uint64_t toInt(const RegisterCell &A) const
MachineOperand class - Representation of each machine instruction operand.
RegisterCell eXOR(const RegisterCell &A1, const RegisterCell &A2) const
RegisterCell eCTB(const RegisterCell &A1, bool B, uint16_t W) const
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
RegisterCell eCLR(const RegisterCell &A1, uint16_t BitN) const
bool is(unsigned T) const
MachineRegisterInfo & MRI
uint16_t ct(bool B) const
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
void clear()
Completely clear the SetVector.
Class for arbitrary precision integers.
RegisterCell getCell(const RegisterRef &RR, const CellMapType &M) const
RegisterCell & insert(const RegisterCell &RC, const BitMask &M)
const MachineBasicBlock * getParent() const
Representation of each machine instruction.
static bool isPhysicalRegister(unsigned Reg)
Return true if the specified register number is in the physical register namespace.
RegisterCell & cat(const RegisterCell &RC)
BitTracker(const MachineEvaluator &E, MachineFunction &F)
bool isSuccessor(const MachineBasicBlock *MBB) const
Return true if the specified MBB is a successor of this block.
raw_ostream & operator<<(raw_ostream &OS, const APInt &I)
const TargetRegisterClass * getMinimalPhysRegClass(unsigned Reg, MVT VT=MVT::Other) const
Returns the Register Class of a physical register of the given type, picking the most sub register cl...
RegisterCell get(RegisterRef RR) const
bool isReg() const
isReg - Tests if this is a MO_Register operand.
RegisterCell eXTR(const RegisterCell &A1, uint16_t B, uint16_t E) const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
RegisterCell eSXT(const RegisterCell &A1, uint16_t FromN) const
RegisterCell eMLU(const RegisterCell &A1, const RegisterCell &A2) const
A vector that has set insertion semantics.
void put(RegisterRef RR, const RegisterCell &RC)
RegisterCell eZXT(const RegisterCell &A1, uint16_t FromN) const
This class implements an extremely fast bulk output stream that can only output to a stream...
bool meet(const RegisterCell &RC, unsigned SelfR)
unsigned getRegSizeInBits(const TargetRegisterClass &RC) const
Return the size in bits of a register from class RC.
RegisterCell & regify(unsigned R)
static RegisterCell ref(const RegisterCell &C)
for(unsigned i=Desc.getNumOperands(), e=OldMI.getNumOperands();i !=e;++i)
const MachineOperand & getOperand(unsigned i) const
iterator_range< use_instr_nodbg_iterator > use_nodbg_instructions(unsigned Reg) const
static BitValue ref(const BitValue &V)