From a61e73bda5125c28e48b52e573d115370838596b Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Tue, 26 Apr 2011 17:18:34 +0000 Subject: [PATCH] Fast-isel support for simple inline asms. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@130205 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/SelectionDAG/FastISel.cpp | 41 ++++++++++++++++++++------- test/CodeGen/X86/fast-isel.ll | 1 + 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/lib/CodeGen/SelectionDAG/FastISel.cpp b/lib/CodeGen/SelectionDAG/FastISel.cpp index e8dfed395c0..a4dd5f9640e 100644 --- a/lib/CodeGen/SelectionDAG/FastISel.cpp +++ b/lib/CodeGen/SelectionDAG/FastISel.cpp @@ -482,14 +482,35 @@ bool FastISel::SelectGetElementPtr(const User *I) { } bool FastISel::SelectCall(const User *I) { - const Function *F = cast(I)->getCalledFunction(); + const CallInst *Call = cast(I); + + // Handle simple inline asms. + if (const InlineAsm *IA = dyn_cast(Call->getArgOperand(0))) { + // Don't attempt to handle constraints. + if (!IA->getConstraintString().empty()) + return false; + + unsigned ExtraInfo = 0; + if (IA->hasSideEffects()) + ExtraInfo |= InlineAsm::Extra_HasSideEffects; + if (IA->isAlignStack()) + ExtraInfo |= InlineAsm::Extra_IsAlignStack; + + BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, + TII.get(TargetOpcode::INLINEASM)) + .addExternalSymbol(IA->getAsmString().c_str()) + .addImm(ExtraInfo); + return true; + } + + const Function *F = Call->getCalledFunction(); if (!F) return false; // Handle selected intrinsic function calls. switch (F->getIntrinsicID()) { default: break; case Intrinsic::dbg_declare: { - const DbgDeclareInst *DI = cast(I); + const DbgDeclareInst *DI = cast(Call); if (!DIVariable(DI->getVariable()).Verify() || !FuncInfo.MF->getMMI().hasDebugInfo()) return true; @@ -521,7 +542,7 @@ bool FastISel::SelectCall(const User *I) { } case Intrinsic::dbg_value: { // This form of DBG_VALUE is target-independent. - const DbgValueInst *DI = cast(I); + const DbgValueInst *DI = cast(Call); const TargetInstrDesc &II = TII.get(TargetOpcode::DBG_VALUE); const Value *V = DI->getValue(); if (!V) { @@ -550,7 +571,7 @@ bool FastISel::SelectCall(const User *I) { return true; } case Intrinsic::eh_exception: { - EVT VT = TLI.getValueType(I->getType()); + EVT VT = TLI.getValueType(Call->getType()); if (TLI.getOperationAction(ISD::EXCEPTIONADDR, VT)!=TargetLowering::Expand) break; @@ -561,18 +582,18 @@ bool FastISel::SelectCall(const User *I) { unsigned ResultReg = createResultReg(RC); BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(TargetOpcode::COPY), ResultReg).addReg(Reg); - UpdateValueMap(I, ResultReg); + UpdateValueMap(Call, ResultReg); return true; } case Intrinsic::eh_selector: { - EVT VT = TLI.getValueType(I->getType()); + EVT VT = TLI.getValueType(Call->getType()); if (TLI.getOperationAction(ISD::EHSELECTION, VT) != TargetLowering::Expand) break; if (FuncInfo.MBB->isLandingPad()) - AddCatchInfo(*cast(I), &FuncInfo.MF->getMMI(), FuncInfo.MBB); + AddCatchInfo(*Call, &FuncInfo.MF->getMMI(), FuncInfo.MBB); else { #ifndef NDEBUG - FuncInfo.CatchInfoLost.insert(cast(I)); + FuncInfo.CatchInfoLost.insert(Call); #endif // FIXME: Mark exception selector register as live in. Hack for PR1508. unsigned Reg = TLI.getExceptionSelectorRegister(); @@ -586,7 +607,7 @@ bool FastISel::SelectCall(const User *I) { BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(TargetOpcode::COPY), ResultReg).addReg(Reg); - bool ResultRegIsKill = hasTrivialKill(I); + bool ResultRegIsKill = hasTrivialKill(Call); // Cast the register to the type of the selector. if (SrcVT.bitsGT(MVT::i32)) @@ -599,7 +620,7 @@ bool FastISel::SelectCall(const User *I) { // Unhandled operand. Halt "fast" selection and bail. return false; - UpdateValueMap(I, ResultReg); + UpdateValueMap(Call, ResultReg); return true; } diff --git a/test/CodeGen/X86/fast-isel.ll b/test/CodeGen/X86/fast-isel.ll index a978aa7a1ea..5a1d2136ce4 100644 --- a/test/CodeGen/X86/fast-isel.ll +++ b/test/CodeGen/X86/fast-isel.ll @@ -20,6 +20,7 @@ fast: %t6 = add i32 %t5, 2 %t7 = getelementptr i32* %y, i32 1 %t8 = getelementptr i32* %t7, i32 %t6 + call void asm sideeffect "hello world", ""() br label %exit exit: