[llvm] r269413 - Assure calling "cld" instruction in prologue of X86 interrupt handler function.
Amjad Aboud via llvm-commits
llvm-commits at lists.llvm.org
Fri May 13 05:46:58 PDT 2016
Author: aaboud
Date: Fri May 13 07:46:57 2016
New Revision: 269413
URL: http://llvm.org/viewvc/llvm-project?rev=269413&view=rev
Log:
Assure calling "cld" instruction in prologue of X86 interrupt handler function.
Differential Revision: http://reviews.llvm.org/D18725
Added:
llvm/trunk/test/CodeGen/X86/x86-interrupt_cld.ll
Modified:
llvm/trunk/lib/Target/X86/X86FrameLowering.cpp
Modified: llvm/trunk/lib/Target/X86/X86FrameLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86FrameLowering.cpp?rev=269413&r1=269412&r2=269413&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86FrameLowering.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86FrameLowering.cpp Fri May 13 07:46:57 2016
@@ -1381,6 +1381,18 @@ void X86FrameLowering::emitPrologue(Mach
if (PushedRegs)
emitCalleeSavedFrameMoves(MBB, MBBI, DL);
}
+
+ // X86 Interrupt handling function cannot assume anything about the direction
+ // flag (DF in EFLAGS register). Clear this flag by creating "cld" instruction
+ // in each prologue of interrupt handler function.
+ //
+ // FIXME: Create "cld" instruction only in these cases:
+ // 1. The interrupt handling function uses any of the "rep" instructions.
+ // 2. Interrupt handling function calls another function.
+ //
+ if (Fn->getCallingConv() == CallingConv::X86_INTR)
+ BuildMI(MBB, MBBI, DL, TII.get(X86::CLD))
+ .setMIFlag(MachineInstr::FrameSetup);
}
bool X86FrameLowering::canUseLEAForSPInEpilogue(
Added: llvm/trunk/test/CodeGen/X86/x86-interrupt_cld.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/x86-interrupt_cld.ll?rev=269413&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/X86/x86-interrupt_cld.ll (added)
+++ llvm/trunk/test/CodeGen/X86/x86-interrupt_cld.ll Fri May 13 07:46:57 2016
@@ -0,0 +1,17 @@
+; RUN: llc -mtriple=x86_64-unknown-unknown < %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()
+
More information about the llvm-commits
mailing list