Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/dotnet/llvm-project.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/llvm
diff options
context:
space:
mode:
authorZoltan Varga <vargaz@gmail.com>2019-07-08 23:52:35 +0300
committerImran Hameed <imhameed@microsoft.com>2021-06-03 00:03:08 +0300
commitc9d3cd78413d29453a267b3f66136be51e67f181 (patch)
treeb705a47bc06974635142265b52b707d6d78ba175 /llvm
parent9d7d3f848ed718e13f7152173c7be97ebee4c11e (diff)
Merge pull request #48 from lewurm/armv7-hasfp-fix-cfa
[arm] fix CFA when frame pointer is used
Diffstat (limited to 'llvm')
-rw-r--r--llvm/lib/CodeGen/AsmPrinter/MonoException.cpp48
-rw-r--r--llvm/lib/CodeGen/AsmPrinter/MonoException.h9
-rw-r--r--llvm/lib/Target/ARM/ARMFrameLowering.cpp14
3 files changed, 43 insertions, 28 deletions
diff --git a/llvm/lib/CodeGen/AsmPrinter/MonoException.cpp b/llvm/lib/CodeGen/AsmPrinter/MonoException.cpp
index 08f86a2df35a..0721ff887559 100644
--- a/llvm/lib/CodeGen/AsmPrinter/MonoException.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/MonoException.cpp
@@ -220,19 +220,22 @@ static void
emitCFIInstructions(MCStreamer &streamer,
const std::vector<MCCFIInstruction> &Instrs,
MCSymbol *BaseLabel,
- const std::vector<MCSymbol*> *Labels,
+ const std::vector<MonoLabeledCfiInstruction> &labeled_cfi,
int &CFAOffset,
int DataAlignmentFactor)
{
- for (unsigned i = 0, N = Instrs.size(); i < N; ++i) {
- const MCCFIInstruction &Instr = Instrs[i];
- MCSymbol *Label = Labels ? ((*Labels)[i]) : NULL;
+ for (const auto &lblcfi : labeled_cfi) {
+ const auto ix = lblcfi.CfiIndex;
+ const auto Label = lblcfi.Label;
+ const auto &Instr = Instrs.at(ix);
+ // Throw out move if the Label is invalid.
+ if (Label && !Label->isDefined()) continue; // Not emitted, in dead code.
// Advance row if new location.
if (BaseLabel && Label) {
MCSymbol *ThisSym = Label;
if (ThisSym != BaseLabel) {
- streamer.AddComment ("cfa_advance");
+ streamer.AddComment("cfa_advance");
streamer.emitDwarfAdvanceFrameAddr(BaseLabel, ThisSym);
BaseLabel = ThisSym;
}
@@ -257,7 +260,7 @@ void
MonoException::beginFunction(const MachineFunction *MF)
{
EmitFnStart();
- EHLabels.clear();
+ CfiInstructions.clear();
}
void
@@ -418,11 +421,10 @@ MonoException::endFunction(const MachineFunction *MF)
info.FunctionNumber = Asm->getFunctionNumber();
info.BeginSym = Asm->getFunctionBegin ();
info.EndSym = Asm->getFunctionEnd ();
- info.EHLabels = EHLabels;
info.MonoMethodIdx = monoMethodIdx;
info.HasLandingPads = !MF->getLandingPads().empty();
info.Instructions = MF->getFrameInstructions();
- assert (info.Instructions.size () == info.EHLabels.size());
+ info.CfiInstructions = std::move(CfiInstructions);
if (DisableGNUEH)
/* ARMAsmPrinter generates references to this */
@@ -431,7 +433,6 @@ MonoException::endFunction(const MachineFunction *MF)
PrepareMonoLSDA(&info);
Frames.push_back(info);
- EHLabels.clear();
EmitFnEnd ();
}
@@ -609,7 +610,12 @@ MonoException::endModule()
int cfaOffset = 0;
// Initial CIE program
- emitCFIInstructions(streamer, streamer.getContext().getAsmInfo()->getInitialFrameState(), NULL, NULL, cfaOffset, stackGrowth);
+ std::vector<MonoLabeledCfiInstruction> cieInstructions;
+ const unsigned int cieSize = streamer.getContext().getAsmInfo()->getInitialFrameState().size();
+ for (unsigned int i = 0; i < cieSize; ++i) {
+ cieInstructions.push_back({ nullptr, i });
+ }
+ emitCFIInstructions(streamer, streamer.getContext().getAsmInfo()->getInitialFrameState(), nullptr, cieInstructions, cfaOffset, stackGrowth);
streamer.AddComment("End of CIE program");
streamer.emitIntValue(dwarf::DW_CFA_nop, 1);
@@ -644,7 +650,7 @@ MonoException::endModule()
// Emit unwind info
cfaOffset = cieCfaOffset;
- emitCFIInstructions(streamer, info.Instructions, info.BeginSym, &info.EHLabels, cfaOffset, dataAlignmentFactor);
+ emitCFIInstructions(streamer, info.Instructions, info.BeginSym, info.CfiInstructions, cfaOffset, dataAlignmentFactor);
streamer.AddBlankLine();
}
@@ -656,18 +662,10 @@ MonoException::endModule()
void
MonoException::beginInstruction(const MachineInstr *MI)
{
- if (MI->getOpcode() == TargetOpcode::CFI_INSTRUCTION) {
- unsigned CFIIndex = MI->getOperand(0).getCFIIndex();
-
- //outs () << "D: " << CFIIndex << " " << EHLabels.size() << "\n";
-
- /* Emit a label and save the label-cfi index association */
- if (CFIIndex != EHLabels.size())
- assert (0);
-
- MCSymbol *Label = Asm->OutContext.createTempSymbol();
- Asm->OutStreamer->emitLabel(Label);
-
- EHLabels.push_back(Label);
- }
+ if (MI->getOpcode() == TargetOpcode::CFI_INSTRUCTION) {
+ const auto cfiIndex = MI->getOperand(0).getCFIIndex();
+ const auto label = Asm->OutContext.createTempSymbol();
+ Asm->OutStreamer->emitLabel(label);
+ CfiInstructions.push_back({ label, cfiIndex });
+ }
}
diff --git a/llvm/lib/CodeGen/AsmPrinter/MonoException.h b/llvm/lib/CodeGen/AsmPrinter/MonoException.h
index 5fd983ed5626..de092dac3c60 100644
--- a/llvm/lib/CodeGen/AsmPrinter/MonoException.h
+++ b/llvm/lib/CodeGen/AsmPrinter/MonoException.h
@@ -17,6 +17,11 @@ namespace llvm {
class TargetRegisterInfo;
+struct MonoLabeledCfiInstruction {
+ MCSymbol *Label;
+ unsigned int CfiIndex;
+};
+
class MonoException : public EHStreamer {
public:
MonoException(AsmPrinter *A, bool disableGNUEH);
@@ -45,11 +50,11 @@ private:
struct EHInfo {
int FunctionNumber, MonoMethodIdx;
MCSymbol *BeginSym, *EndSym, *FDESym;
- std::vector<MCSymbol*> EHLabels;
std::vector<MCCFIInstruction> Instructions;
std::vector<MonoCallSiteEntry> CallSites;
std::vector<const GlobalValue *> TypeInfos;
std::vector<LandingPadInfo> PadInfos;
+ std::vector<MonoLabeledCfiInstruction> CfiInstructions;
int FrameReg;
int ThisOffset;
bool HasLandingPads;
@@ -70,7 +75,7 @@ private:
void EmitFnStart();
void EmitFnEnd();
- std::vector<MCSymbol*> EHLabels;
+ std::vector<MonoLabeledCfiInstruction> CfiInstructions;
std::vector<EHInfo> Frames;
StringMap<int> FuncIndexes;
const TargetRegisterInfo *RI;
diff --git a/llvm/lib/Target/ARM/ARMFrameLowering.cpp b/llvm/lib/Target/ARM/ARMFrameLowering.cpp
index 8a8f3237bb6f..82ff4e306f90 100644
--- a/llvm/lib/Target/ARM/ARMFrameLowering.cpp
+++ b/llvm/lib/Target/ARM/ARMFrameLowering.cpp
@@ -352,6 +352,7 @@ void ARMFrameLowering::emitPrologue(MachineFunction &MF,
unsigned NumBytes = MFI.getStackSize();
const std::vector<CalleeSavedInfo> &CSI = MFI.getCalleeSavedInfo();
int FPCXTSaveSize = 0;
+ bool AvoidNonfpCFA = false;
// Debug location must be unknown since the first debug location is used
// to determine the end of the prologue.
@@ -592,6 +593,7 @@ void ARMFrameLowering::emitPrologue(MachineFunction &MF,
dl, TII, FramePtr, ARM::SP,
PushSize + FramePtrOffsetInPush,
MachineInstr::FrameSetup);
+#if 0
if (FramePtrOffsetInPush + PushSize != 0) {
unsigned CFIIndex = MF.addFrameInst(MCCFIInstruction::cfiDefCfa(
nullptr, MRI->getDwarfRegNum(FramePtr, true),
@@ -607,6 +609,15 @@ void ARMFrameLowering::emitPrologue(MachineFunction &MF,
.addCFIIndex(CFIIndex)
.setMIFlags(MachineInstr::FrameSetup);
}
+#else
+ /* on iOS `r7 + 8` is always the previous stack pointer */
+ unsigned CFIIndex = MF.addFrameInst(MCCFIInstruction::cfiDefCfa(nullptr, MRI->getDwarfRegNum(FramePtr, true), 8));
+ BuildMI(MBB, AfterPush, dl, TII.get(TargetOpcode::CFI_INSTRUCTION))
+ .addCFIIndex(CFIIndex)
+ .setMIFlags(MachineInstr::FrameSetup);
+
+ AvoidNonfpCFA = true;
+#endif
}
// Now that the prologue's actual instructions are finalised, we can insert
@@ -695,7 +706,8 @@ void ARMFrameLowering::emitPrologue(MachineFunction &MF,
// throughout the process. If we have a frame pointer, it takes over the job
// half-way through, so only the first few .cfi_def_cfa_offset instructions
// actually get emitted.
- DefCFAOffsetCandidates.emitDefCFAOffsets(MBB, dl, TII, HasFP);
+ if (!AvoidNonfpCFA)
+ DefCFAOffsetCandidates.emitDefCFAOffsets(MBB, dl, TII, HasFP);
if (STI.isTargetELF() && hasFP(MF))
MFI.setOffsetAdjustment(MFI.getOffsetAdjustment() -