When generating code for Win64 EH, emit StartProc and EndProc directives.
authorCharles Davis <cdavis@mines.edu>
Sat, 28 May 2011 04:21:04 +0000 (04:21 +0000)
committerCharles Davis <cdavis@mines.edu>
Sat, 28 May 2011 04:21:04 +0000 (04:21 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@132250 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/CodeGen/AsmPrinter.h
lib/CodeGen/AsmPrinter/AsmPrinter.cpp
lib/CodeGen/AsmPrinter/Win64Exception.cpp

index d509c22b82949c44e9ad5e1d2ef00c83e215c17d..5eea0999b0c5251e127e7f212014bdbed562f892 100644 (file)
@@ -192,6 +192,8 @@ namespace llvm {
     };
     CFIMoveType needsCFIMoves();
 
+    bool needsSEHMoves();
+
     /// EmitConstantPool - Print to the current output stream assembly
     /// representations of the constants in the constant pool MCP. This is
     /// used to print out constants which have been "spilled to memory" by
index dee6e53226279a9f3e1c1e97b9ce88e6c80d6770..81782ea43675dc5ea841684ca5689254b393fd20 100644 (file)
@@ -604,6 +604,11 @@ AsmPrinter::CFIMoveType AsmPrinter::needsCFIMoves() {
   return CFI_M_None;
 }
 
+bool AsmPrinter::needsSEHMoves() {
+  return MAI->getExceptionHandlingType() == ExceptionHandling::Win64 &&
+    MF->getFunction()->needsUnwindTableEntry();
+}
+
 void AsmPrinter::emitPrologLabel(const MachineInstr &MI) {
   MCSymbol *Label = MI.getOperand(0).getMCSymbol();
 
index c217aaeb3a43b2526e04ebfe2e2294279ac038f7..a23c05ece290900f4e302fda050cea10884afc14 100644 (file)
@@ -54,9 +54,35 @@ void Win64Exception::EndModule() {
 /// BeginFunction - Gather pre-function exception information. Assumes it's
 /// being emitted immediately after the function entry point.
 void Win64Exception::BeginFunction(const MachineFunction *MF) {
+  shouldEmitMoves = shouldEmitPersonality = shouldEmitLSDA = false;
+
+  // If any landing pads survive, we need an EH table.
+  bool hasLandingPads = !MMI->getLandingPads().empty();
+
+  shouldEmitMoves = Asm->needsSEHMoves();
+
+  const TargetLoweringObjectFile &TLOF = Asm->getObjFileLowering();
+  unsigned PerEncoding = TLOF.getPersonalityEncoding();
+  const Function *Per = MMI->getPersonalities()[MMI->getPersonalityIndex()];
+
+  shouldEmitPersonality = hasLandingPads &&
+    PerEncoding != dwarf::DW_EH_PE_omit && Per;
+
+  unsigned LSDAEncoding = TLOF.getLSDAEncoding();
+  shouldEmitLSDA = shouldEmitPersonality &&
+    LSDAEncoding != dwarf::DW_EH_PE_omit;
+
+  if (!shouldEmitPersonality && !shouldEmitMoves)
+    return;
+
+  Asm->OutStreamer.EmitWin64EHStartProc(Asm->CurrentFnSym);
 }
 
 /// EndFunction - Gather and emit post-function exception information.
 ///
 void Win64Exception::EndFunction() {
+  if (!shouldEmitPersonality && !shouldEmitMoves)
+    return;
+
+  Asm->OutStreamer.EmitWin64EHEndProc();
 }