llvm.org GIT mirror llvm / b566062
[ms-inline asm] Do not omit the frame pointer if we have ms-inline assembly. If the frame pointer is omitted, and any stack changes occur in the inline assembly, e.g.: "pusha", then any C local variable or C argument references will be incorrect. I pass no judgement on anyone who would do such a thing. ;) rdar://13218191 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@175334 91177308-0d34-0410-b5e6-96231b3b80d8 Chad Rosier 7 years ago
5 changed file(s) with 46 addition(s) and 20 deletion(s). Raw diff Collapse all Expand all
130130 /// about the control flow of such functions.
131131 bool ExposesReturnsTwice;
132132
133 /// True if the function includes MS-style inline assembly.
134 bool HasMSInlineAsm;
135
133136 MachineFunction(const MachineFunction &) LLVM_DELETED_FUNCTION;
134137 void operator=(const MachineFunction&) LLVM_DELETED_FUNCTION;
135138 public:
212215 /// a "returns twice" function.
213216 void setExposesReturnsTwice(bool B) {
214217 ExposesReturnsTwice = B;
218 }
219
220 /// Returns true if the function contains any MS-style inline assembly.
221 bool hasMSInlineAsm() const {
222 return HasMSInlineAsm;
223 }
224
225 /// Set a flag that indicates that the function contains MS-style inline
226 /// assembly.
227 void setHasMSInlineAsm(bool B) {
228 HasMSInlineAsm = B;
215229 }
216230
217231 /// getInfo - Keep track of various per-function pieces of information for
641641 bool isKill() const { return getOpcode() == TargetOpcode::KILL; }
642642 bool isImplicitDef() const { return getOpcode()==TargetOpcode::IMPLICIT_DEF; }
643643 bool isInlineAsm() const { return getOpcode() == TargetOpcode::INLINEASM; }
644 bool isMSInlineAsm() const {
645 return getOpcode() == TargetOpcode::INLINEASM && getInlineAsmDialect();
646 }
644647 bool isStackAligningInlineAsm() const;
645648 InlineAsm::AsmDialect getInlineAsmDialect() const;
646649 bool isInsertSubreg() const {
440440 }
441441
442442 // Determine if there are any calls in this machine function.
443 MF->setHasMSInlineAsm(false);
443444 MachineFrameInfo *MFI = MF->getFrameInfo();
444 if (!MFI->hasCalls()) {
445 for (MachineFunction::const_iterator
446 I = MF->begin(), E = MF->end(); I != E; ++I) {
447 const MachineBasicBlock *MBB = I;
448 for (MachineBasicBlock::const_iterator
449 II = MBB->begin(), IE = MBB->end(); II != IE; ++II) {
450 const MCInstrDesc &MCID = TM.getInstrInfo()->get(II->getOpcode());
451
452 if ((MCID.isCall() && !MCID.isReturn()) ||
453 II->isStackAligningInlineAsm()) {
454 MFI->setHasCalls(true);
455 goto done;
456 }
445 for (MachineFunction::const_iterator I = MF->begin(), E = MF->end(); I != E;
446 ++I) {
447
448 if (MFI->hasCalls() && MF->hasMSInlineAsm())
449 break;
450
451 const MachineBasicBlock *MBB = I;
452 for (MachineBasicBlock::const_iterator II = MBB->begin(), IE = MBB->end();
453 II != IE; ++II) {
454 const MCInstrDesc &MCID = TM.getInstrInfo()->get(II->getOpcode());
455 if ((MCID.isCall() && !MCID.isReturn()) ||
456 II->isStackAligningInlineAsm()) {
457 MFI->setHasCalls(true);
457458 }
458 }
459 }
460
461 done:
459 if (II->isMSInlineAsm()) {
460 MF->setHasMSInlineAsm(true);
461 }
462 }
463 }
464
462465 // Determine if there is a call to setjmp in the machine function.
463466 MF->setExposesReturnsTwice(Fn.callsFunctionThatReturnsTwice());
464467
4949 return (MF.getTarget().Options.DisableFramePointerElim(MF) ||
5050 RegInfo->needsStackRealignment(MF) ||
5151 MFI->hasVarSizedObjects() ||
52 MFI->isFrameAddressTaken() ||
52 MFI->isFrameAddressTaken() || MF.hasMSInlineAsm() ||
5353 MF.getInfo()->getForceFramePointer() ||
5454 MMI.callsUnwindInit() || MMI.callsEHReturn());
5555 }
44 %0 = tail call i32 asm sideeffect inteldialect "mov eax, $1\0A\09mov $0, eax", "=r,r,~{eax},~{dirflag},~{fpsr},~{flags}"(i32 1) nounwind
55 ret i32 %0
66 ; CHECK: t1
7 ; CHECK: movl %esp, %ebp
78 ; CHECK: {{## InlineAsm Start|#APP}}
89 ; CHECK: .intel_syntax
910 ; CHECK: mov eax, ecx
1718 call void asm sideeffect inteldialect "mov eax, $$1", "~{eax},~{dirflag},~{fpsr},~{flags}"() nounwind
1819 ret void
1920 ; CHECK: t2
21 ; CHECK: movl %esp, %ebp
2022 ; CHECK: {{## InlineAsm Start|#APP}}
2123 ; CHECK: .intel_syntax
2224 ; CHECK: mov eax, 1
3133 call void asm sideeffect inteldialect "mov eax, DWORD PTR [$0]", "*m,~{eax},~{dirflag},~{fpsr},~{flags}"(i32* %V.addr) nounwind
3234 ret void
3335 ; CHECK: t3
36 ; CHECK: movl %esp, %ebp
3437 ; CHECK: {{## InlineAsm Start|#APP}}
3538 ; CHECK: .intel_syntax
3639 ; CHECK: mov eax, DWORD PTR {{[[esp]}}
5255 %0 = load i32* %b1, align 4
5356 ret i32 %0
5457 ; CHECK: t18
58 ; CHECK: movl %esp, %ebp
5559 ; CHECK: {{## InlineAsm Start|#APP}}
5660 ; CHECK: .intel_syntax
5761 ; CHECK: lea ebx, foo
7175 call void asm sideeffect inteldialect "call $0", "r,~{dirflag},~{fpsr},~{flags}"(void ()* @t19_helper) nounwind
7276 ret void
7377 ; CHECK: t19:
78 ; CHECK: movl %esp, %ebp
7479 ; CHECK: movl ${{_?}}t19_helper, %eax
7580 ; CHECK: {{## InlineAsm Start|#APP}}
7681 ; CHECK: .intel_syntax
8994 %0 = load i32** %res, align 4
9095 ret i32* %0
9196 ; CHECK: t30:
97 ; CHECK: movl %esp, %ebp
9298 ; CHECK: {{## InlineAsm Start|#APP}}
9399 ; CHECK: .intel_syntax
94100 ; CHECK: lea edi, dword ptr [{{_?}}results]
96102 ; CHECK: {{## InlineAsm End|#NO_APP}}
97103 ; CHECK: {{## InlineAsm Start|#APP}}
98104 ; CHECK: .intel_syntax
99 ; CHECK: mov dword ptr [esp], edi
105 ; CHECK: mov dword ptr [ebp - 8], edi
100106 ; CHECK: .att_syntax
101107 ; CHECK: {{## InlineAsm End|#NO_APP}}
102 ; CHECK: movl (%esp), %eax
108 ; CHECK: movl -8(%ebp), %eax
103109 }