mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-19 20:34:38 +00:00
Remove unused constant pool entries.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@35635 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
92ca81601c
commit
ed884f3a2f
@ -139,13 +139,15 @@ namespace {
|
|||||||
MachineBasicBlock *SplitBlockBeforeInstr(MachineInstr *MI);
|
MachineBasicBlock *SplitBlockBeforeInstr(MachineInstr *MI);
|
||||||
void UpdateForInsertedWaterBlock(MachineBasicBlock *NewBB);
|
void UpdateForInsertedWaterBlock(MachineBasicBlock *NewBB);
|
||||||
void AdjustBBOffsetsAfter(MachineBasicBlock *BB, int delta);
|
void AdjustBBOffsetsAfter(MachineBasicBlock *BB, int delta);
|
||||||
bool DecrementOldEntry(unsigned CPI, MachineInstr* CPEMI, unsigned Size);
|
bool DecrementOldEntry(unsigned CPI, MachineInstr* CPEMI);
|
||||||
int LookForExistingCPEntry(CPUser& U, unsigned UserOffset);
|
int LookForExistingCPEntry(CPUser& U, unsigned UserOffset);
|
||||||
bool LookForWater(CPUser&U, unsigned UserOffset, bool* PadNewWater,
|
bool LookForWater(CPUser&U, unsigned UserOffset, bool* PadNewWater,
|
||||||
MachineBasicBlock** NewMBB);
|
MachineBasicBlock** NewMBB);
|
||||||
void CreateNewWater(unsigned CPUserIndex, unsigned UserOffset,
|
void CreateNewWater(unsigned CPUserIndex, unsigned UserOffset,
|
||||||
MachineBasicBlock** NewMBB);
|
MachineBasicBlock** NewMBB);
|
||||||
bool HandleConstantPoolUser(MachineFunction &Fn, unsigned CPUserIndex);
|
bool HandleConstantPoolUser(MachineFunction &Fn, unsigned CPUserIndex);
|
||||||
|
void RemoveDeadCPEMI(MachineInstr *CPEMI);
|
||||||
|
bool RemoveUnusedCPEntries();
|
||||||
bool CPEIsInRange(MachineInstr *MI, unsigned UserOffset,
|
bool CPEIsInRange(MachineInstr *MI, unsigned UserOffset,
|
||||||
MachineInstr *CPEMI, unsigned Disp,
|
MachineInstr *CPEMI, unsigned Disp,
|
||||||
bool DoDump);
|
bool DoDump);
|
||||||
@ -197,6 +199,9 @@ bool ARMConstantIslands::runOnMachineFunction(MachineFunction &Fn) {
|
|||||||
InitialFunctionScan(Fn, CPEMIs);
|
InitialFunctionScan(Fn, CPEMIs);
|
||||||
CPEMIs.clear();
|
CPEMIs.clear();
|
||||||
|
|
||||||
|
/// Remove dead constant pool entries.
|
||||||
|
RemoveUnusedCPEntries();
|
||||||
|
|
||||||
// Iteratively place constant pool entries and fix up branches until there
|
// Iteratively place constant pool entries and fix up branches until there
|
||||||
// is no change.
|
// is no change.
|
||||||
bool MadeChange = false;
|
bool MadeChange = false;
|
||||||
@ -210,7 +215,7 @@ bool ARMConstantIslands::runOnMachineFunction(MachineFunction &Fn) {
|
|||||||
break;
|
break;
|
||||||
MadeChange = true;
|
MadeChange = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If LR has been forced spilled and no far jumps (i.e. BL) has been issued.
|
// If LR has been forced spilled and no far jumps (i.e. BL) has been issued.
|
||||||
// Undo the spill / restore of LR if possible.
|
// Undo the spill / restore of LR if possible.
|
||||||
if (!HasFarJump && AFI->isLRSpilledForFarJump() && isThumb)
|
if (!HasFarJump && AFI->isLRSpilledForFarJump() && isThumb)
|
||||||
@ -648,34 +653,13 @@ void ARMConstantIslands::AdjustBBOffsetsAfter(MachineBasicBlock *BB, int delta)
|
|||||||
/// becomes 0 remove the entry and instruction. Returns true if we removed
|
/// becomes 0 remove the entry and instruction. Returns true if we removed
|
||||||
/// the entry, false if we didn't.
|
/// the entry, false if we didn't.
|
||||||
|
|
||||||
bool ARMConstantIslands::DecrementOldEntry(unsigned CPI, MachineInstr *CPEMI,
|
bool ARMConstantIslands::DecrementOldEntry(unsigned CPI, MachineInstr *CPEMI) {
|
||||||
unsigned Size) {
|
|
||||||
// Find the old entry. Eliminate it if it is no longer used.
|
// Find the old entry. Eliminate it if it is no longer used.
|
||||||
CPEntry *OldCPE = findConstPoolEntry(CPI, CPEMI);
|
CPEntry *CPE = findConstPoolEntry(CPI, CPEMI);
|
||||||
assert(OldCPE && "Unexpected!");
|
assert(CPE && "Unexpected!");
|
||||||
if (--OldCPE->RefCount == 0) {
|
if (--CPE->RefCount == 0) {
|
||||||
MachineBasicBlock *OldCPEBB = OldCPE->CPEMI->getParent();
|
RemoveDeadCPEMI(CPEMI);
|
||||||
if (OldCPEBB->empty()) {
|
CPE->CPEMI = NULL;
|
||||||
// In thumb mode, the size of island is padded by two to compensate for
|
|
||||||
// the alignment requirement. Thus it will now be 2 when the block is
|
|
||||||
// empty, so fix this.
|
|
||||||
// All succeeding offsets have the current size value added in, fix this.
|
|
||||||
if (BBSizes[OldCPEBB->getNumber()] != 0) {
|
|
||||||
AdjustBBOffsetsAfter(OldCPEBB, -BBSizes[OldCPEBB->getNumber()]);
|
|
||||||
BBSizes[OldCPEBB->getNumber()] = 0;
|
|
||||||
}
|
|
||||||
// An island has only one predecessor BB and one successor BB. Check if
|
|
||||||
// this BB's predecessor jumps directly to this BB's successor. This
|
|
||||||
// shouldn't happen currently.
|
|
||||||
assert(!BBIsJumpedOver(OldCPEBB) && "How did this happen?");
|
|
||||||
// FIXME: remove the empty blocks after all the work is done?
|
|
||||||
} else {
|
|
||||||
BBSizes[OldCPEBB->getNumber()] -= Size;
|
|
||||||
// All succeeding offsets have the current size value added in, fix this.
|
|
||||||
AdjustBBOffsetsAfter(OldCPEBB, -Size);
|
|
||||||
}
|
|
||||||
OldCPE->CPEMI->eraseFromParent();
|
|
||||||
OldCPE->CPEMI = NULL;
|
|
||||||
NumCPEs--;
|
NumCPEs--;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -723,8 +707,7 @@ int ARMConstantIslands::LookForExistingCPEntry(CPUser& U, unsigned UserOffset)
|
|||||||
CPEs[i].RefCount++;
|
CPEs[i].RefCount++;
|
||||||
// ...and the original. If we didn't remove the old entry, none of the
|
// ...and the original. If we didn't remove the old entry, none of the
|
||||||
// addresses changed, so we don't need another pass.
|
// addresses changed, so we don't need another pass.
|
||||||
unsigned Size = CPEMI->getOperand(2).getImm();
|
return DecrementOldEntry(CPI, CPEMI) ? 2 : 1;
|
||||||
return DecrementOldEntry(CPI, CPEMI, Size) ? 2 : 1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@ -910,7 +893,7 @@ bool ARMConstantIslands::HandleConstantPoolUser(MachineFunction &Fn,
|
|||||||
UpdateForInsertedWaterBlock(NewIsland);
|
UpdateForInsertedWaterBlock(NewIsland);
|
||||||
|
|
||||||
// Decrement the old entry, and remove it if refcount becomes 0.
|
// Decrement the old entry, and remove it if refcount becomes 0.
|
||||||
DecrementOldEntry(CPI, CPEMI, Size);
|
DecrementOldEntry(CPI, CPEMI);
|
||||||
|
|
||||||
// Now that we have an island to add the CPE to, clone the original CPE and
|
// Now that we have an island to add the CPE to, clone the original CPE and
|
||||||
// add it to the island.
|
// add it to the island.
|
||||||
@ -938,6 +921,51 @@ bool ARMConstantIslands::HandleConstantPoolUser(MachineFunction &Fn,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// RemoveDeadCPEMI - Remove a dead constant pool entry instruction. Update
|
||||||
|
/// sizes and offsets of impacted basic blocks.
|
||||||
|
void ARMConstantIslands::RemoveDeadCPEMI(MachineInstr *CPEMI) {
|
||||||
|
MachineBasicBlock *CPEBB = CPEMI->getParent();
|
||||||
|
if (CPEBB->empty()) {
|
||||||
|
// In thumb mode, the size of island is padded by two to compensate for
|
||||||
|
// the alignment requirement. Thus it will now be 2 when the block is
|
||||||
|
// empty, so fix this.
|
||||||
|
// All succeeding offsets have the current size value added in, fix this.
|
||||||
|
if (BBSizes[CPEBB->getNumber()] != 0) {
|
||||||
|
AdjustBBOffsetsAfter(CPEBB, -BBSizes[CPEBB->getNumber()]);
|
||||||
|
BBSizes[CPEBB->getNumber()] = 0;
|
||||||
|
}
|
||||||
|
// An island has only one predecessor BB and one successor BB. Check if
|
||||||
|
// this BB's predecessor jumps directly to this BB's successor. This
|
||||||
|
// shouldn't happen currently.
|
||||||
|
assert(!BBIsJumpedOver(CPEBB) && "How did this happen?");
|
||||||
|
// FIXME: remove the empty blocks after all the work is done?
|
||||||
|
} else {
|
||||||
|
unsigned Size = CPEMI->getOperand(2).getImm();
|
||||||
|
BBSizes[CPEBB->getNumber()] -= Size;
|
||||||
|
// All succeeding offsets have the current size value added in, fix this.
|
||||||
|
AdjustBBOffsetsAfter(CPEBB, -Size);
|
||||||
|
}
|
||||||
|
|
||||||
|
CPEMI->eraseFromParent();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// RemoveUnusedCPEntries - Remove constant pool entries whose refcounts
|
||||||
|
/// are zero.
|
||||||
|
bool ARMConstantIslands::RemoveUnusedCPEntries() {
|
||||||
|
unsigned MadeChange = false;
|
||||||
|
for (unsigned i = 0, e = CPEntries.size(); i != e; ++i) {
|
||||||
|
std::vector<CPEntry> &CPEs = CPEntries[i];
|
||||||
|
for (unsigned j = 0, ee = CPEs.size(); j != ee; ++j) {
|
||||||
|
if (CPEs[j].RefCount == 0 && CPEs[j].CPEMI) {
|
||||||
|
RemoveDeadCPEMI(CPEs[j].CPEMI);
|
||||||
|
CPEs[j].CPEMI = NULL;
|
||||||
|
MadeChange = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return MadeChange;
|
||||||
|
}
|
||||||
|
|
||||||
/// BBIsInRange - Returns true if the distance between specific MI and
|
/// BBIsInRange - Returns true if the distance between specific MI and
|
||||||
/// specific BB can fit in MI's displacement field.
|
/// specific BB can fit in MI's displacement field.
|
||||||
bool ARMConstantIslands::BBIsInRange(MachineInstr *MI,MachineBasicBlock *DestBB,
|
bool ARMConstantIslands::BBIsInRange(MachineInstr *MI,MachineBasicBlock *DestBB,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user