[PATCH] D18725: Assure calling cld instruction in prologue of interrupt handler function

Amjad Aboud via llvm-commits llvm-commits at lists.llvm.org
Sat Apr 2 10:22:29 PDT 2016


aaboud created this revision.
aaboud added reviewers: nadav, DavidKreitzer, hjl.tools, qcolombet.
aaboud added a subscriber: llvm-commits.

Interrupt handling function cannot assume anything about the direction flag (DF in EFLAGS register), and it must clear it using "cld" instruction in these cases:
1. The interrupt handling function uses any of the "rep" instructions.
2. Interrupt handling function calls another function.

However, to simplify the implementation we just create "cld" instruction in each prologue of interrupt handler function.

http://reviews.llvm.org/D18725

Files:
  lib/Target/X86/X86FrameLowering.cpp
  test/CodeGen/X86/x86-interrupt_cld.ll

Index: lib/Target/X86/X86FrameLowering.cpp
===================================================================
--- lib/Target/X86/X86FrameLowering.cpp
+++ lib/Target/X86/X86FrameLowering.cpp
@@ -1368,6 +1368,10 @@
     if (PushedRegs)
       emitCalleeSavedFrameMoves(MBB, MBBI, DL);
   }
+
+  if (Fn->getCallingConv() == CallingConv::X86_INTR)
+    BuildMI(MBB, MBBI, DL, TII.get(X86::CLD))
+        .setMIFlag(MachineInstr::FrameSetup);
 }
 
 bool X86FrameLowering::canUseLEAForSPInEpilogue(
Index: test/CodeGen/X86/x86-interrupt_cld.ll
===================================================================
--- test/CodeGen/X86/x86-interrupt_cld.ll
+++ test/CodeGen/X86/x86-interrupt_cld.ll
@@ -0,0 +1,17 @@
+; RUN: llc -mtriple=x86_64-unknown-unknown -mattr=+avx < %s | FileCheck %s
+
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; Checks that interrupt handler code calls cld before calling an external
+;; function.
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+
+; CHECK: cld
+; CHECK: call
+
+define x86_intrcc void @foo(i8* %frame) {
+  call void @bar()
+  ret void
+}
+
+declare void @bar()
+


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D18725.52466.patch
Type: text/x-patch
Size: 1203 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160402/11f622d4/attachment.bin>


More information about the llvm-commits mailing list