Skip to content
Snippets Groups Projects
Commit 67d9b170 authored by clc5q's avatar clc5q
Browse files

Disable back type inference for indirect memory operands; Fix DEF/no-USE case;...

Disable back type inference for indirect memory operands; Fix DEF/no-USE case; pretty up Dump() output.
parent ebf5f3f2
No related branches found
No related tags found
No related merge requests found
...@@ -178,28 +178,28 @@ void SMPBasicBlock::Dump(void) { ...@@ -178,28 +178,28 @@ void SMPBasicBlock::Dump(void) {
PrintListOperand(*SetItem); PrintListOperand(*SetItem);
} }
} }
msg("\n"); msg("\n\n");
msg("UpExposed set: "); msg("UpExposed set: ");
if (!this->UpExposedSet.empty()) { if (!this->UpExposedSet.empty()) {
for (SetItem = this->UpExposedSet.begin(); SetItem != this->UpExposedSet.end(); ++SetItem) { for (SetItem = this->UpExposedSet.begin(); SetItem != this->UpExposedSet.end(); ++SetItem) {
PrintListOperand(*SetItem); PrintListOperand(*SetItem);
} }
} }
msg("\n"); msg("\n\n");
msg("LiveIn set: "); msg("LiveIn set: ");
if (!this->LiveInSet.empty()) { if (!this->LiveInSet.empty()) {
for (SetItem = this->LiveInSet.begin(); SetItem != this->LiveInSet.end(); ++SetItem) { for (SetItem = this->LiveInSet.begin(); SetItem != this->LiveInSet.end(); ++SetItem) {
PrintListOperand(*SetItem); PrintListOperand(*SetItem);
} }
} }
msg("\n"); msg("\n\n");
msg("LiveOut set: "); msg("LiveOut set: ");
if (!this->LiveOutSet.empty()) { if (!this->LiveOutSet.empty()) {
for (SetItem = this->LiveOutSet.begin(); SetItem != this->LiveOutSet.end(); ++SetItem) { for (SetItem = this->LiveOutSet.begin(); SetItem != this->LiveOutSet.end(); ++SetItem) {
PrintListOperand(*SetItem); PrintListOperand(*SetItem);
} }
} }
msg("\n"); msg("\n\n");
msg("Dominance frontier: "); msg("Dominance frontier: ");
set<int>::iterator DomIter; set<int>::iterator DomIter;
if (!this->DomFrontier.empty()) { if (!this->DomFrontier.empty()) {
...@@ -207,7 +207,7 @@ void SMPBasicBlock::Dump(void) { ...@@ -207,7 +207,7 @@ void SMPBasicBlock::Dump(void) {
msg("%d ", *DomIter); msg("%d ", *DomIter);
} }
} }
msg("\n"); msg("\n\n");
set<SMPPhiFunction, LessPhi>::iterator PhiIter; set<SMPPhiFunction, LessPhi>::iterator PhiIter;
if (!this->PhiFunctions.empty()) { if (!this->PhiFunctions.empty()) {
for (PhiIter = this->PhiFunctions.begin(); PhiIter != this->PhiFunctions.end(); ++PhiIter) { for (PhiIter = this->PhiFunctions.begin(); PhiIter != this->PhiFunctions.end(); ++PhiIter) {
...@@ -216,15 +216,18 @@ void SMPBasicBlock::Dump(void) { ...@@ -216,15 +216,18 @@ void SMPBasicBlock::Dump(void) {
PhiIter->Dump(); PhiIter->Dump();
} }
} }
msg("\n");
msg("DEF-USE chains for block-local names: \n"); msg("DEF-USE chains for block-local names: \n");
this->LocalDUChains.Dump(); this->LocalDUChains.Dump();
#if SMP_FULL_LIVENESS_ANALYSIS #if SMP_FULL_LIVENESS_ANALYSIS
msg("\n");
msg("DEF-USE chains for block-local use of global names: \n"); msg("DEF-USE chains for block-local use of global names: \n");
this->GlobalDUChains.Dump(); this->GlobalDUChains.Dump();
#endif #endif
msg("\n");
if (this->IndirectJump) if (this->IndirectJump)
msg("Has indirect jump. "); msg("Has indirect jump. ");
if (this->Returns) if (this->Returns)
...@@ -659,7 +662,7 @@ void SMPBasicBlock::SSALocalRenumber(void) { ...@@ -659,7 +662,7 @@ void SMPBasicBlock::SSALocalRenumber(void) {
SSAIndex.push_back(-1); // init SSA indices to -1; first DEF will make it 0 SSAIndex.push_back(-1); // init SSA indices to -1; first DEF will make it 0
// Set the local name for each DU chain array. // Set the local name for each DU chain array.
if (LocalIndex > this->LocalDUChains.ChainsByName.size()) if (LocalIndex > this->LocalDUChains.ChainsByName.size())
msg("LocalIndex %d out of bounds in SSALocalRenumber.\n", LocalIndex); msg("ERROR: LocalIndex %d out of bounds in SSALocalRenumber.\n", LocalIndex);
if (DebugFlag) if (DebugFlag)
msg("Setting name for LocalIndex = %d\n", LocalIndex); msg("Setting name for LocalIndex = %d\n", LocalIndex);
this->LocalDUChains.ChainsByName.at(LocalIndex).SetName(*NameIter); this->LocalDUChains.ChainsByName.at(LocalIndex).SetName(*NameIter);
...@@ -681,7 +684,7 @@ void SMPBasicBlock::SSALocalRenumber(void) { ...@@ -681,7 +684,7 @@ void SMPBasicBlock::SSALocalRenumber(void) {
// Found USE of a local name. // Found USE of a local name.
NameIndex = ExtractGlobalIndex(*UseNameIter); NameIndex = ExtractGlobalIndex(*UseNameIter);
if (NameIndex > SSAIndex.size()) if (NameIndex > SSAIndex.size())
msg("NameIndex %d out of range in SSALocalRenumber.\n", NameIndex); msg("ERROR: NameIndex %d out of range in SSALocalRenumber.\n", NameIndex);
int SSANum = SSAIndex.at(NameIndex); int SSANum = SSAIndex.at(NameIndex);
// Update the SSA subscript in the DEF-USE list for the instruction. // Update the SSA subscript in the DEF-USE list for the instruction.
#if SMP_DEBUG_DATAFLOW #if SMP_DEBUG_DATAFLOW
...@@ -695,7 +698,7 @@ void SMPBasicBlock::SSALocalRenumber(void) { ...@@ -695,7 +698,7 @@ void SMPBasicBlock::SSALocalRenumber(void) {
CurrUse = (*InstIter)->SetUseSSA(UseOp, SSANum); CurrUse = (*InstIter)->SetUseSSA(UseOp, SSANum);
if (SSANum >= 0) { // skip USE before DEF names if (SSANum >= 0) { // skip USE before DEF names
if ((size_t) SSANum > this->LocalDUChains.ChainsByName.at(NameIndex).DUChains.size()) if ((size_t) SSANum > this->LocalDUChains.ChainsByName.at(NameIndex).DUChains.size())
msg("SSANum %d out of range in SSALocalRenumber.\n", SSANum); msg("ERROR: SSANum %d out of range in SSALocalRenumber.\n", SSANum);
// Push address of USE instruction onto the DEF-USE chain for this SSANum. // Push address of USE instruction onto the DEF-USE chain for this SSANum.
this->LocalDUChains.ChainsByName.at(NameIndex).DUChains.at(SSANum).PushUse((*InstIter)->GetAddr()); this->LocalDUChains.ChainsByName.at(NameIndex).DUChains.at(SSANum).PushUse((*InstIter)->GetAddr());
} }
...@@ -711,7 +714,7 @@ void SMPBasicBlock::SSALocalRenumber(void) { ...@@ -711,7 +714,7 @@ void SMPBasicBlock::SSALocalRenumber(void) {
// Found DEF of a local name. // Found DEF of a local name.
NameIndex = ExtractGlobalIndex(*DefNameIter); NameIndex = ExtractGlobalIndex(*DefNameIter);
if (NameIndex > SSAIndex.size()) if (NameIndex > SSAIndex.size())
msg("DEF NameIndex %d out of range in SSALocalRenumber.\n", NameIndex); msg("ERROR: DEF NameIndex %d out of range in SSALocalRenumber.\n", NameIndex);
++SSAIndex[NameIndex]; // move up to next SSA subscript number ++SSAIndex[NameIndex]; // move up to next SSA subscript number
int SSANum = SSAIndex.at(NameIndex); int SSANum = SSAIndex.at(NameIndex);
// Put new SSA number into DEF list entry in the instruction. // Put new SSA number into DEF list entry in the instruction.
...@@ -790,6 +793,8 @@ bool SMPBasicBlock::PropagateLocalDefType(op_t DefOp, SMPOperandType DefType, ea ...@@ -790,6 +793,8 @@ bool SMPBasicBlock::PropagateLocalDefType(op_t DefOp, SMPOperandType DefType, ea
ea_t StartAddr = this->LocalDUChains.ChainsByName.at(RegIndex).DUChains.at(SSANum).GetDef(); ea_t StartAddr = this->LocalDUChains.ChainsByName.at(RegIndex).DUChains.at(SSANum).GetDef();
assert(DefAddr == StartAddr); assert(DefAddr == StartAddr);
ea_t LastAddr = this->LocalDUChains.ChainsByName.at(RegIndex).DUChains.at(SSANum).GetLastUse(); ea_t LastAddr = this->LocalDUChains.ChainsByName.at(RegIndex).DUChains.at(SSANum).GetLastUse();
if (BADADDR == LastAddr)
return false; // DEF had no USEs, so no propagation
set<DefOrUse, LessDefUse>::iterator CurrUse; set<DefOrUse, LessDefUse>::iterator CurrUse;
// Go through the instructions in the block and find the instructions between StartAddr // Go through the instructions in the block and find the instructions between StartAddr
// and LastAddr that have USEs of DefOp. These will all have SSANum, based on the // and LastAddr that have USEs of DefOp. These will all have SSANum, based on the
...@@ -803,6 +808,7 @@ bool SMPBasicBlock::PropagateLocalDefType(op_t DefOp, SMPOperandType DefType, ea ...@@ -803,6 +808,7 @@ bool SMPBasicBlock::PropagateLocalDefType(op_t DefOp, SMPOperandType DefType, ea
CurrUse = (*InstIter)->FindUse(DefOp); CurrUse = (*InstIter)->FindUse(DefOp);
if (CurrUse != (*InstIter)->GetLastUse()) { // found a USE in the chain if (CurrUse != (*InstIter)->GetLastUse()) { // found a USE in the chain
if (CurrUse->GetType() == UNINIT) { if (CurrUse->GetType() == UNINIT) {
assert(SSANum == CurrUse->GetSSANum());
CurrUse = (*InstIter)->SetUseType(DefOp, DefType); CurrUse = (*InstIter)->SetUseType(DefOp, DefType);
assert(CurrUse != (*InstIter)->GetLastUse()); // found USE assert(CurrUse != (*InstIter)->GetLastUse()); // found USE
changed = true; changed = true;
...@@ -1019,6 +1025,8 @@ bool SMPBasicBlock::InferLocalDefType(op_t DefOp, unsigned int LocIndex, ea_t De ...@@ -1019,6 +1025,8 @@ bool SMPBasicBlock::InferLocalDefType(op_t DefOp, unsigned int LocIndex, ea_t De
ea_t StartAddr = this->LocalDUChains.ChainsByName.at(LocIndex).DUChains.at(SSANum).GetDef(); ea_t StartAddr = this->LocalDUChains.ChainsByName.at(LocIndex).DUChains.at(SSANum).GetDef();
assert(DefAddr == StartAddr); assert(DefAddr == StartAddr);
ea_t LastAddr = this->LocalDUChains.ChainsByName.at(LocIndex).DUChains.at(SSANum).GetLastUse(); ea_t LastAddr = this->LocalDUChains.ChainsByName.at(LocIndex).DUChains.at(SSANum).GetLastUse();
if (BADADDR == LastAddr)
return false; // DEF had no USEs, so no inference from USEs is possible
set<DefOrUse, LessDefUse>::iterator CurrUse; set<DefOrUse, LessDefUse>::iterator CurrUse;
// Go through the instructions in the block and find the instructions between StartAddr // Go through the instructions in the block and find the instructions between StartAddr
// and LastAddr that have USEs of DefOp. These will all have SSANum, based on the // and LastAddr that have USEs of DefOp. These will all have SSANum, based on the
...@@ -1026,7 +1034,7 @@ bool SMPBasicBlock::InferLocalDefType(op_t DefOp, unsigned int LocIndex, ea_t De ...@@ -1026,7 +1034,7 @@ bool SMPBasicBlock::InferLocalDefType(op_t DefOp, unsigned int LocIndex, ea_t De
// a single type (other than UNINIT), change the DEF type to match the USE type // a single type (other than UNINIT), change the DEF type to match the USE type
// and set changed to true. // and set changed to true.
bool FirstUseSeen = false; bool FirstUseSeen = false;
SMPOperandType UseType; SMPOperandType UseType = UNINIT;
for (InstIter = this->Instrs.begin(); InstIter != this->Instrs.end(); ++InstIter) { for (InstIter = this->Instrs.begin(); InstIter != this->Instrs.end(); ++InstIter) {
ea_t CurrAddr = (*InstIter)->GetAddr(); ea_t CurrAddr = (*InstIter)->GetAddr();
if (CurrAddr > LastAddr) if (CurrAddr > LastAddr)
...@@ -1103,7 +1111,8 @@ set<SMPPhiFunction, LessPhi>::iterator SMPBasicBlock::InferPhiDefType(set<SMPPhi ...@@ -1103,7 +1111,8 @@ set<SMPPhiFunction, LessPhi>::iterator SMPBasicBlock::InferPhiDefType(set<SMPPhi
ReturnPhi = this->SetPhiDefType(DefPhi->GetAnyOp(), UseType); ReturnPhi = this->SetPhiDefType(DefPhi->GetAnyOp(), UseType);
changed = true; changed = true;
// Propagate down to USEs of this DEF. // Propagate down to USEs of this DEF.
changed |= this->PropagateGlobalDefType(DefOp, UseType, SSANum); if (!MDIsIndirectMemoryOpnd(DefOp, this->MyFunc->UsesFramePointer()))
changed |= this->PropagateGlobalDefType(DefOp, UseType, SSANum);
return ReturnPhi; return ReturnPhi;
} // end of SMPBasicBlock::InferPhiDefType() } // end of SMPBasicBlock::InferPhiDefType()
...@@ -1288,8 +1297,10 @@ void SMPBasicBlock::MarkDeadRegs(void) { ...@@ -1288,8 +1297,10 @@ void SMPBasicBlock::MarkDeadRegs(void) {
oldCatch = this->AreGlobalFlagsDead(InstAddr, FlagsOp); oldCatch = this->AreGlobalFlagsDead(InstAddr, FlagsOp);
if (newCatch || oldCatch) if (newCatch || oldCatch)
qstrncat(DeadString, " EFLAGS", sizeof(DeadString) - 1); qstrncat(DeadString, " EFLAGS", sizeof(DeadString) - 1);
#if 0
if (newCatch && !oldCatch) if (newCatch && !oldCatch)
msg("We caught a new Flags!\n"); msg("We caught a new Flags!\n");
#endif
if (!newCatch && oldCatch) if (!newCatch && oldCatch)
msg("How did that slip by?\n"); msg("How did that slip by?\n");
#if 0 #if 0
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment