summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen/MachineInstr.cpp
diff options
context:
space:
mode:
authorPetar Jovanovic <petar.jovanovic@mips.com>2017-11-07 14:40:27 +0000
committerPetar Jovanovic <petar.jovanovic@mips.com>2017-11-07 14:40:27 +0000
commite2a585dddc9402f96350f61991bdc76aa0600aca (patch)
tree4c9d8d91e07148c9e2dd04511638465ac6c2f460 /llvm/lib/CodeGen/MachineInstr.cpp
parentd5b7a00fd53398211a048e534ad43b32d474cf7c (diff)
downloadbcm5719-llvm-e2a585dddc9402f96350f61991bdc76aa0600aca.tar.gz
bcm5719-llvm-e2a585dddc9402f96350f61991bdc76aa0600aca.zip
Reland "Correct dwarf unwind information in function epilogue for X86"
Reland r317100 with minor fix regarding ComputeCommonTailLength function in BranchFolding.cpp. Skipping top CFI instructions block needs to executed on several more return points in ComputeCommonTailLength(). Original r317100 message: "Correct dwarf unwind information in function epilogue for X86" This patch aims to provide correct dwarf unwind information in function epilogue for X86. It consists of two parts. The first part inserts CFI instructions that set appropriate cfa offset and cfa register in emitEpilogue() in X86FrameLowering. This part is X86 specific. The second part is platform independent and ensures that: - CFI instructions do not affect code generation - Unwind information remains correct when a function is modified by different passes. This is done in a late pass by analyzing information about cfa offset and cfa register in BBs and inserting additional CFI directives where necessary. Changed CFI instructions so that they: - are duplicable - are not counted as instructions when tail duplicating or tail merging - can be compared as equal Added CFIInstrInserter pass: - analyzes each basic block to determine cfa offset and register valid at its entry and exit - verifies that outgoing cfa offset and register of predecessor blocks match incoming values of their successors - inserts additional CFI directives at basic block beginning to correct the rule for calculating CFA Having CFI instructions in function epilogue can cause incorrect CFA calculation rule for some basic blocks. This can happen if, due to basic block reordering, or the existence of multiple epilogue blocks, some of the blocks have wrong cfa offset and register values set by the epilogue block above them. CFIInstrInserter is currently run only on X86, but can be used by any target that implements support for adding CFI instructions in epilogue. Patch by Violeta Vukobrat. llvm-svn: 317579
Diffstat (limited to 'llvm/lib/CodeGen/MachineInstr.cpp')
-rw-r--r--llvm/lib/CodeGen/MachineInstr.cpp50
1 files changed, 46 insertions, 4 deletions
diff --git a/llvm/lib/CodeGen/MachineInstr.cpp b/llvm/lib/CodeGen/MachineInstr.cpp
index bb2dda980e4..9137c836caa 100644
--- a/llvm/lib/CodeGen/MachineInstr.cpp
+++ b/llvm/lib/CodeGen/MachineInstr.cpp
@@ -320,8 +320,45 @@ bool MachineOperand::isIdenticalTo(const MachineOperand &Other) const {
}
case MachineOperand::MO_MCSymbol:
return getMCSymbol() == Other.getMCSymbol();
- case MachineOperand::MO_CFIIndex:
- return getCFIIndex() == Other.getCFIIndex();
+ case MachineOperand::MO_CFIIndex: {
+ const MachineFunction *MF = getParent()->getParent()->getParent();
+ const MachineFunction *OtherMF =
+ Other.getParent()->getParent()->getParent();
+ MCCFIInstruction Inst = MF->getFrameInstructions()[getCFIIndex()];
+ MCCFIInstruction OtherInst =
+ OtherMF->getFrameInstructions()[Other.getCFIIndex()];
+ MCCFIInstruction::OpType op = Inst.getOperation();
+ if (op != OtherInst.getOperation()) return false;
+ switch (op) {
+ case MCCFIInstruction::OpDefCfa:
+ case MCCFIInstruction::OpOffset:
+ case MCCFIInstruction::OpRelOffset:
+ if (Inst.getRegister() != OtherInst.getRegister()) return false;
+ if (Inst.getOffset() != OtherInst.getOffset()) return false;
+ break;
+ case MCCFIInstruction::OpRestore:
+ case MCCFIInstruction::OpUndefined:
+ case MCCFIInstruction::OpSameValue:
+ case MCCFIInstruction::OpDefCfaRegister:
+ if (Inst.getRegister() != OtherInst.getRegister()) return false;
+ break;
+ case MCCFIInstruction::OpRegister:
+ if (Inst.getRegister() != OtherInst.getRegister()) return false;
+ if (Inst.getRegister2() != OtherInst.getRegister2()) return false;
+ break;
+ case MCCFIInstruction::OpDefCfaOffset:
+ case MCCFIInstruction::OpAdjustCfaOffset:
+ case MCCFIInstruction::OpGnuArgsSize:
+ if (Inst.getOffset() != OtherInst.getOffset()) return false;
+ break;
+ case MCCFIInstruction::OpRememberState:
+ case MCCFIInstruction::OpRestoreState:
+ case MCCFIInstruction::OpEscape:
+ case MCCFIInstruction::OpWindowSave:
+ break;
+ }
+ return true;
+ }
case MachineOperand::MO_Metadata:
return getMetadata() == Other.getMetadata();
case MachineOperand::MO_IntrinsicID:
@@ -370,8 +407,13 @@ hash_code llvm::hash_value(const MachineOperand &MO) {
return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getMetadata());
case MachineOperand::MO_MCSymbol:
return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getMCSymbol());
- case MachineOperand::MO_CFIIndex:
- return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getCFIIndex());
+ case MachineOperand::MO_CFIIndex: {
+ const MachineFunction *MF = MO.getParent()->getParent()->getParent();
+ MCCFIInstruction Inst = MF->getFrameInstructions()[MO.getCFIIndex()];
+ return hash_combine(MO.getType(), MO.getTargetFlags(), Inst.getOperation(),
+ Inst.getRegister(), Inst.getRegister2(),
+ Inst.getOffset());
+ }
case MachineOperand::MO_IntrinsicID:
return hash_combine(MO.getType(), MO.getTargetFlags(), MO.getIntrinsicID());
case MachineOperand::MO_Predicate:
OpenPOWER on IntegriCloud