[PATCH] D95745: Support unwinding from inline assembly
cynecx added a comment. I would be great if someone with commit rights could push this through since I don't have commit rights :) Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D95745/new/ https://reviews.llvm.org/D95745 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D95745: Support unwinding from inline assembly
cynecx added a comment. @Amanieu Thanks for the review and commit! :) Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D95745/new/ https://reviews.llvm.org/D95745 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D95745: Support unwinding from inline assembly
cynecx added a comment. Hmm, there is build-failure when buildbot is running extended tests (MachineVerifier): https://lab.llvm.org/buildbot/#/builders/16/builds/10825 Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D95745/new/ https://reviews.llvm.org/D95745 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D95745: Support unwinding from inline assembly
cynecx added a comment. Something unrelated might be wrong with the test because I can reproduce the MachineVerifier issue (liveins + non-entry/landingpad) on llvm-stable (11.1) and even without the inline-asm call (replaced by a normal invoke to the target). Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D95745/new/ https://reviews.llvm.org/D95745 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D95745: Support unwinding from inline assembly
cynecx added a comment. Okay. This is a known issue https://bugs.llvm.org/show_bug.cgi?id=39439. I'll upload a new patch which includes`-verify-machineinstrs=0` as a temporary workaround. (See the sjlj-eh.ll test) Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D95745/new/ https://reviews.llvm.org/D95745 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D95745: Support unwinding from inline assembly
cynecx added a comment. https://reviews.llvm.org/D102433 Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D95745/new/ https://reviews.llvm.org/D95745 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D95745: Support unwinding from inline assembly
cynecx created this revision. cynecx added reviewers: LLVM, clang. cynecx added projects: LLVM, clang. Herald added a reviewer: deadalnix. Herald added subscribers: dexonsmith, hiraditya. cynecx requested review of this revision. Herald added subscribers: llvm-commits, cfe-commits, aheejin. I haven't received any feedback about the approach I've taken yet (https://lists.llvm.org/pipermail/llvm-dev/2021-January/148175.html). So I thought I'd try my luck here. A splitted patchset can be found here: https://github.com/cynecx/llvm-project/commits/invokeasm2 I've taken the following steps to add support to unwinding from inline assembly: 1. Add a new `canThrow` "attribute" (like `sideeffect`) to the asm syntax: invoke void asm sideeffect unwind "call thrower", "~{dirflag},~{fpsr},~{flags}"() to label %exit unwind label %uexit 2.) Add Bitcode writing/reading support + LLVM-IR parsing. 3.) Emit EHLabels around inline assembly lowering (SelectionDAGBuilder + GlobalISel) when canThrow is enabled. 4.) Tweak InstCombineCalls/InlineFunction pass to not mark inline assembly "calls" as nounwind. 5.) Add clang support by introducing a new clobber: "unwind", which lower to the `canThrow` being enabled. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D95745 Files: clang/lib/Basic/TargetInfo.cpp clang/lib/CodeGen/CGStmt.cpp clang/lib/Sema/SemaStmtAsm.cpp llvm/bindings/go/llvm/ir.go llvm/include/llvm-c/Core.h llvm/include/llvm/Bitcode/LLVMBitCodes.h llvm/include/llvm/IR/InlineAsm.h llvm/lib/AsmParser/LLParser.cpp llvm/lib/Bitcode/Reader/BitcodeReader.cpp llvm/lib/Bitcode/Writer/BitcodeWriter.cpp llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h llvm/lib/IR/AsmWriter.cpp llvm/lib/IR/ConstantsContext.h llvm/lib/IR/Core.cpp llvm/lib/IR/InlineAsm.cpp llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp llvm/lib/Transforms/Utils/InlineFunction.cpp Index: llvm/lib/Transforms/Utils/InlineFunction.cpp === --- llvm/lib/Transforms/Utils/InlineFunction.cpp +++ llvm/lib/Transforms/Utils/InlineFunction.cpp @@ -56,6 +56,7 @@ #include "llvm/IR/Type.h" #include "llvm/IR/User.h" #include "llvm/IR/Value.h" +#include "llvm/IR/InlineAsm.h" #include "llvm/Support/Casting.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/ErrorHandling.h" @@ -543,9 +544,16 @@ // instructions require no special handling. CallInst *CI = dyn_cast(I); -if (!CI || CI->doesNotThrow() || CI->isInlineAsm()) +if (!CI || CI->doesNotThrow()) continue; +if (CI->isInlineAsm()) { + InlineAsm *IA = cast(CI->getCalledOperand()); + if (!IA->canThrow()) { +continue; + } +} + // We do not need to (and in fact, cannot) convert possibly throwing calls // to @llvm.experimental_deoptimize (resp. @llvm.experimental.guard) into // invokes. The caller's "segment" of the deoptimization continuation Index: llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp === --- llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp +++ llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp @@ -56,6 +56,7 @@ #include "llvm/IR/User.h" #include "llvm/IR/Value.h" #include "llvm/IR/ValueHandle.h" +#include "llvm/IR/InlineAsm.h" #include "llvm/Support/AtomicOrdering.h" #include "llvm/Support/Casting.h" #include "llvm/Support/CommandLine.h" @@ -2121,9 +2122,13 @@ } if (isa(Callee) && !Call.doesNotThrow()) { -// Inline asm calls cannot throw - mark them 'nounwind'. -Call.setDoesNotThrow(); -Changed = true; +InlineAsm *IA = cast(Callee); +if (!IA->canThrow()) { + // Normal inline asm calls cannot throw - mark them + // 'nounwind'. + Call.setDoesNotThrow(); + Changed = true; +} } // Try to optimize the call if possible, we require DataLayout for most of Index: llvm/lib/IR/InlineAsm.cpp === --- llvm/lib/IR/InlineAsm.cpp +++ llvm/lib/IR/InlineAsm.cpp @@ -29,11 +29,11 @@ InlineAsm::InlineAsm(FunctionType *FTy, const std::string &asmString, const std::string &constraints, bool hasSideEffects, - bool isAlignStack, AsmDialect asmDialect) + bool isAlignStack, AsmDialect asmDialect, bool canThrow) : Value(PointerType::getUnqual(FTy), Value::InlineAsmVal), AsmString(asmString), Constraints(constraints), FTy(FTy), HasSideEffects(hasSideEffects), IsAlignStack(isAlignStack), - Dialect(asmDialect) { + Dialect(asmDialect), CanThrow(canThrow) { // Do various checks on the constraint string and type. assert(Verify(getFunctionType(), constraints) && "Function type not legal for constraints!"); @@ -41
[PATCH] D95745: Support unwinding from inline assembly
cynecx added a comment. Tests are missing right now. But I'd like to get some feedback first whether this approach goes in the right direction. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D95745/new/ https://reviews.llvm.org/D95745 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D96052: [clang] add new unwind inline asm clobber which lowers to throwable inline assembly
cynecx created this revision. cynecx requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D96052 Files: clang/lib/Basic/TargetInfo.cpp clang/lib/CodeGen/CGStmt.cpp clang/lib/Sema/SemaStmtAsm.cpp Index: clang/lib/Sema/SemaStmtAsm.cpp === --- clang/lib/Sema/SemaStmtAsm.cpp +++ clang/lib/Sema/SemaStmtAsm.cpp @@ -228,7 +228,7 @@ StringRef Clobber = Clobbers[i]->getString(); // We only check registers, therefore we don't check cc and memory // clobbers -if (Clobber == "cc" || Clobber == "memory") +if (Clobber == "cc" || Clobber == "memory" || Clobber == "unwind") continue; Clobber = Target.getNormalizedGCCRegisterName(Clobber, true); // Go over the output's registers we collected Index: clang/lib/CodeGen/CGStmt.cpp === --- clang/lib/CodeGen/CGStmt.cpp +++ clang/lib/CodeGen/CGStmt.cpp @@ -2115,13 +2115,15 @@ } static void UpdateAsmCallInst(llvm::CallBase &Result, bool HasSideEffect, - bool ReadOnly, bool ReadNone, bool NoMerge, - const AsmStmt &S, + bool HasUnwindClobber, bool ReadOnly, + bool ReadNone, bool NoMerge, const AsmStmt &S, const std::vector &ResultRegTypes, CodeGenFunction &CGF, std::vector &RegResults) { - Result.addAttribute(llvm::AttributeList::FunctionIndex, - llvm::Attribute::NoUnwind); + if (!HasUnwindClobber) +Result.addAttribute(llvm::AttributeList::FunctionIndex, +llvm::Attribute::NoUnwind); + if (NoMerge) Result.addAttribute(llvm::AttributeList::FunctionIndex, llvm::Attribute::NoMerge); @@ -2468,13 +2470,18 @@ } Constraints += InOutConstraints; + bool HasUnwindClobber = false; + // Clobbers for (unsigned i = 0, e = S.getNumClobbers(); i != e; i++) { StringRef Clobber = S.getClobber(i); if (Clobber == "memory") ReadOnly = ReadNone = false; -else if (Clobber != "cc") { +else if (Clobber == "unwind") { + HasUnwindClobber = true; + continue; +} else if (Clobber != "cc") { Clobber = getTarget().getNormalizedGCCRegisterName(Clobber); if (CGM.getCodeGenOpts().StackClashProtector && getTarget().isSPRegName(Clobber)) { @@ -2508,6 +2515,9 @@ Constraints += '}'; } + assert(!(HasUnwindClobber && IsGCCAsmGoto) && + "unwind clobber can't be used with asm goto"); + // Add machine specific clobbers std::string MachineClobbers = getTarget().getClobbers(); if (!MachineClobbers.empty()) { @@ -2530,23 +2540,28 @@ bool HasSideEffect = S.isVolatile() || S.getNumOutputs() == 0; llvm::InlineAsm::AsmDialect AsmDialect = isa(&S) ? llvm::InlineAsm::AD_Intel : llvm::InlineAsm::AD_ATT; - llvm::InlineAsm *IA = -llvm::InlineAsm::get(FTy, AsmString, Constraints, HasSideEffect, - /* IsAlignStack */ false, AsmDialect); + llvm::InlineAsm *IA = llvm::InlineAsm::get( + FTy, AsmString, Constraints, HasSideEffect, + /* IsAlignStack */ false, AsmDialect, HasUnwindClobber); std::vector RegResults; if (IsGCCAsmGoto) { llvm::CallBrInst *Result = Builder.CreateCallBr(IA, Fallthrough, Transfer, Args); EmitBlock(Fallthrough); -UpdateAsmCallInst(cast(*Result), HasSideEffect, ReadOnly, - ReadNone, InNoMergeAttributedStmt, S, ResultRegTypes, - *this, RegResults); +UpdateAsmCallInst(cast(*Result), HasSideEffect, false, + ReadOnly, ReadNone, InNoMergeAttributedStmt, S, + ResultRegTypes, *this, RegResults); + } else if (HasUnwindClobber) { +llvm::CallBase *Result = EmitCallOrInvoke(IA, Args, ""); +UpdateAsmCallInst(*Result, HasSideEffect, true, ReadOnly, ReadNone, + InNoMergeAttributedStmt, S, ResultRegTypes, *this, + RegResults); } else { llvm::CallInst *Result = Builder.CreateCall(IA, Args, getBundlesForFunclet(IA)); -UpdateAsmCallInst(cast(*Result), HasSideEffect, ReadOnly, - ReadNone, InNoMergeAttributedStmt, S, ResultRegTypes, - *this, RegResults); +UpdateAsmCallInst(cast(*Result), HasSideEffect, false, + ReadOnly, ReadNone, InNoMergeAttributedStmt, S, + ResultRegTypes, *this, RegResults); } assert(RegResults.size() == ResultRegTypes.size()); Index: clang/lib/Basic/TargetInfo.cpp === --- clang/lib/Basic/TargetInfo.cpp +++ clang/lib/Basic/TargetInfo.cpp @@ -4
[PATCH] D96053: [clang] add new unwind inline asm clobber which lowers to throwable inline assembly
cynecx created this revision. cynecx requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D96053 Files: clang/lib/Basic/TargetInfo.cpp clang/lib/CodeGen/CGStmt.cpp clang/lib/Sema/SemaStmtAsm.cpp Index: clang/lib/Sema/SemaStmtAsm.cpp === --- clang/lib/Sema/SemaStmtAsm.cpp +++ clang/lib/Sema/SemaStmtAsm.cpp @@ -228,7 +228,7 @@ StringRef Clobber = Clobbers[i]->getString(); // We only check registers, therefore we don't check cc and memory // clobbers -if (Clobber == "cc" || Clobber == "memory") +if (Clobber == "cc" || Clobber == "memory" || Clobber == "unwind") continue; Clobber = Target.getNormalizedGCCRegisterName(Clobber, true); // Go over the output's registers we collected Index: clang/lib/CodeGen/CGStmt.cpp === --- clang/lib/CodeGen/CGStmt.cpp +++ clang/lib/CodeGen/CGStmt.cpp @@ -2115,13 +2115,15 @@ } static void UpdateAsmCallInst(llvm::CallBase &Result, bool HasSideEffect, - bool ReadOnly, bool ReadNone, bool NoMerge, - const AsmStmt &S, + bool HasUnwindClobber, bool ReadOnly, + bool ReadNone, bool NoMerge, const AsmStmt &S, const std::vector &ResultRegTypes, CodeGenFunction &CGF, std::vector &RegResults) { - Result.addAttribute(llvm::AttributeList::FunctionIndex, - llvm::Attribute::NoUnwind); + if (!HasUnwindClobber) +Result.addAttribute(llvm::AttributeList::FunctionIndex, +llvm::Attribute::NoUnwind); + if (NoMerge) Result.addAttribute(llvm::AttributeList::FunctionIndex, llvm::Attribute::NoMerge); @@ -2468,13 +2470,18 @@ } Constraints += InOutConstraints; + bool HasUnwindClobber = false; + // Clobbers for (unsigned i = 0, e = S.getNumClobbers(); i != e; i++) { StringRef Clobber = S.getClobber(i); if (Clobber == "memory") ReadOnly = ReadNone = false; -else if (Clobber != "cc") { +else if (Clobber == "unwind") { + HasUnwindClobber = true; + continue; +} else if (Clobber != "cc") { Clobber = getTarget().getNormalizedGCCRegisterName(Clobber); if (CGM.getCodeGenOpts().StackClashProtector && getTarget().isSPRegName(Clobber)) { @@ -2508,6 +2515,9 @@ Constraints += '}'; } + assert(!(HasUnwindClobber && IsGCCAsmGoto) && + "unwind clobber can't be used with asm goto"); + // Add machine specific clobbers std::string MachineClobbers = getTarget().getClobbers(); if (!MachineClobbers.empty()) { @@ -2530,23 +2540,28 @@ bool HasSideEffect = S.isVolatile() || S.getNumOutputs() == 0; llvm::InlineAsm::AsmDialect AsmDialect = isa(&S) ? llvm::InlineAsm::AD_Intel : llvm::InlineAsm::AD_ATT; - llvm::InlineAsm *IA = -llvm::InlineAsm::get(FTy, AsmString, Constraints, HasSideEffect, - /* IsAlignStack */ false, AsmDialect); + llvm::InlineAsm *IA = llvm::InlineAsm::get( + FTy, AsmString, Constraints, HasSideEffect, + /* IsAlignStack */ false, AsmDialect, HasUnwindClobber); std::vector RegResults; if (IsGCCAsmGoto) { llvm::CallBrInst *Result = Builder.CreateCallBr(IA, Fallthrough, Transfer, Args); EmitBlock(Fallthrough); -UpdateAsmCallInst(cast(*Result), HasSideEffect, ReadOnly, - ReadNone, InNoMergeAttributedStmt, S, ResultRegTypes, - *this, RegResults); +UpdateAsmCallInst(cast(*Result), HasSideEffect, false, + ReadOnly, ReadNone, InNoMergeAttributedStmt, S, + ResultRegTypes, *this, RegResults); + } else if (HasUnwindClobber) { +llvm::CallBase *Result = EmitCallOrInvoke(IA, Args, ""); +UpdateAsmCallInst(*Result, HasSideEffect, true, ReadOnly, ReadNone, + InNoMergeAttributedStmt, S, ResultRegTypes, *this, + RegResults); } else { llvm::CallInst *Result = Builder.CreateCall(IA, Args, getBundlesForFunclet(IA)); -UpdateAsmCallInst(cast(*Result), HasSideEffect, ReadOnly, - ReadNone, InNoMergeAttributedStmt, S, ResultRegTypes, - *this, RegResults); +UpdateAsmCallInst(cast(*Result), HasSideEffect, false, + ReadOnly, ReadNone, InNoMergeAttributedStmt, S, + ResultRegTypes, *this, RegResults); } assert(RegResults.size() == ResultRegTypes.size()); Index: clang/lib/Basic/TargetInfo.cpp === --- clang/lib/Basic/TargetInfo.cpp +++ clang/lib/Basic/TargetInfo.cpp @@ -4
[PATCH] D96054: Support unwinding from inline assembly
cynecx created this revision. cynecx requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D96054 Files: clang/lib/Basic/TargetInfo.cpp clang/lib/CodeGen/CGStmt.cpp clang/lib/Sema/SemaStmtAsm.cpp Index: clang/lib/Sema/SemaStmtAsm.cpp === --- clang/lib/Sema/SemaStmtAsm.cpp +++ clang/lib/Sema/SemaStmtAsm.cpp @@ -228,7 +228,7 @@ StringRef Clobber = Clobbers[i]->getString(); // We only check registers, therefore we don't check cc and memory // clobbers -if (Clobber == "cc" || Clobber == "memory") +if (Clobber == "cc" || Clobber == "memory" || Clobber == "unwind") continue; Clobber = Target.getNormalizedGCCRegisterName(Clobber, true); // Go over the output's registers we collected Index: clang/lib/CodeGen/CGStmt.cpp === --- clang/lib/CodeGen/CGStmt.cpp +++ clang/lib/CodeGen/CGStmt.cpp @@ -2115,13 +2115,15 @@ } static void UpdateAsmCallInst(llvm::CallBase &Result, bool HasSideEffect, - bool ReadOnly, bool ReadNone, bool NoMerge, - const AsmStmt &S, + bool HasUnwindClobber, bool ReadOnly, + bool ReadNone, bool NoMerge, const AsmStmt &S, const std::vector &ResultRegTypes, CodeGenFunction &CGF, std::vector &RegResults) { - Result.addAttribute(llvm::AttributeList::FunctionIndex, - llvm::Attribute::NoUnwind); + if (!HasUnwindClobber) +Result.addAttribute(llvm::AttributeList::FunctionIndex, +llvm::Attribute::NoUnwind); + if (NoMerge) Result.addAttribute(llvm::AttributeList::FunctionIndex, llvm::Attribute::NoMerge); @@ -2468,13 +2470,18 @@ } Constraints += InOutConstraints; + bool HasUnwindClobber = false; + // Clobbers for (unsigned i = 0, e = S.getNumClobbers(); i != e; i++) { StringRef Clobber = S.getClobber(i); if (Clobber == "memory") ReadOnly = ReadNone = false; -else if (Clobber != "cc") { +else if (Clobber == "unwind") { + HasUnwindClobber = true; + continue; +} else if (Clobber != "cc") { Clobber = getTarget().getNormalizedGCCRegisterName(Clobber); if (CGM.getCodeGenOpts().StackClashProtector && getTarget().isSPRegName(Clobber)) { @@ -2508,6 +2515,9 @@ Constraints += '}'; } + assert(!(HasUnwindClobber && IsGCCAsmGoto) && + "unwind clobber can't be used with asm goto"); + // Add machine specific clobbers std::string MachineClobbers = getTarget().getClobbers(); if (!MachineClobbers.empty()) { @@ -2530,23 +2540,28 @@ bool HasSideEffect = S.isVolatile() || S.getNumOutputs() == 0; llvm::InlineAsm::AsmDialect AsmDialect = isa(&S) ? llvm::InlineAsm::AD_Intel : llvm::InlineAsm::AD_ATT; - llvm::InlineAsm *IA = -llvm::InlineAsm::get(FTy, AsmString, Constraints, HasSideEffect, - /* IsAlignStack */ false, AsmDialect); + llvm::InlineAsm *IA = llvm::InlineAsm::get( + FTy, AsmString, Constraints, HasSideEffect, + /* IsAlignStack */ false, AsmDialect, HasUnwindClobber); std::vector RegResults; if (IsGCCAsmGoto) { llvm::CallBrInst *Result = Builder.CreateCallBr(IA, Fallthrough, Transfer, Args); EmitBlock(Fallthrough); -UpdateAsmCallInst(cast(*Result), HasSideEffect, ReadOnly, - ReadNone, InNoMergeAttributedStmt, S, ResultRegTypes, - *this, RegResults); +UpdateAsmCallInst(cast(*Result), HasSideEffect, false, + ReadOnly, ReadNone, InNoMergeAttributedStmt, S, + ResultRegTypes, *this, RegResults); + } else if (HasUnwindClobber) { +llvm::CallBase *Result = EmitCallOrInvoke(IA, Args, ""); +UpdateAsmCallInst(*Result, HasSideEffect, true, ReadOnly, ReadNone, + InNoMergeAttributedStmt, S, ResultRegTypes, *this, + RegResults); } else { llvm::CallInst *Result = Builder.CreateCall(IA, Args, getBundlesForFunclet(IA)); -UpdateAsmCallInst(cast(*Result), HasSideEffect, ReadOnly, - ReadNone, InNoMergeAttributedStmt, S, ResultRegTypes, - *this, RegResults); +UpdateAsmCallInst(cast(*Result), HasSideEffect, false, + ReadOnly, ReadNone, InNoMergeAttributedStmt, S, + ResultRegTypes, *this, RegResults); } assert(RegResults.size() == ResultRegTypes.size()); Index: clang/lib/Basic/TargetInfo.cpp === --- clang/lib/Basic/TargetInfo.cpp +++ clang/lib/Basic/TargetInfo.cpp @@ -4
[PATCH] D95745: Support unwinding from inline assembly
cynecx updated this revision to Diff 321479. cynecx added a comment. clang-format changes Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D95745/new/ https://reviews.llvm.org/D95745 Files: clang/lib/Basic/TargetInfo.cpp clang/lib/CodeGen/CGStmt.cpp clang/lib/Sema/SemaStmtAsm.cpp llvm/bindings/go/llvm/ir.go llvm/include/llvm-c/Core.h llvm/include/llvm/Bitcode/LLVMBitCodes.h llvm/include/llvm/IR/InlineAsm.h llvm/lib/AsmParser/LLParser.cpp llvm/lib/Bitcode/Reader/BitcodeReader.cpp llvm/lib/Bitcode/Writer/BitcodeWriter.cpp llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h llvm/lib/IR/AsmWriter.cpp llvm/lib/IR/ConstantsContext.h llvm/lib/IR/Core.cpp llvm/lib/IR/InlineAsm.cpp llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp llvm/lib/Transforms/Utils/InlineFunction.cpp Index: llvm/lib/Transforms/Utils/InlineFunction.cpp === --- llvm/lib/Transforms/Utils/InlineFunction.cpp +++ llvm/lib/Transforms/Utils/InlineFunction.cpp @@ -28,7 +28,6 @@ #include "llvm/Analysis/EHPersonalities.h" #include "llvm/Analysis/InstructionSimplify.h" #include "llvm/Analysis/ProfileSummaryInfo.h" -#include "llvm/Transforms/Utils/Local.h" #include "llvm/Analysis/ValueTracking.h" #include "llvm/Analysis/VectorUtils.h" #include "llvm/IR/Argument.h" @@ -44,6 +43,7 @@ #include "llvm/IR/Dominators.h" #include "llvm/IR/Function.h" #include "llvm/IR/IRBuilder.h" +#include "llvm/IR/InlineAsm.h" #include "llvm/IR/InstrTypes.h" #include "llvm/IR/Instruction.h" #include "llvm/IR/Instructions.h" @@ -61,6 +61,7 @@ #include "llvm/Support/ErrorHandling.h" #include "llvm/Transforms/Utils/AssumeBundleBuilder.h" #include "llvm/Transforms/Utils/Cloning.h" +#include "llvm/Transforms/Utils/Local.h" #include "llvm/Transforms/Utils/ValueMapper.h" #include #include @@ -543,9 +544,16 @@ // instructions require no special handling. CallInst *CI = dyn_cast(I); -if (!CI || CI->doesNotThrow() || CI->isInlineAsm()) +if (!CI || CI->doesNotThrow()) continue; +if (CI->isInlineAsm()) { + InlineAsm *IA = cast(CI->getCalledOperand()); + if (!IA->canThrow()) { +continue; + } +} + // We do not need to (and in fact, cannot) convert possibly throwing calls // to @llvm.experimental_deoptimize (resp. @llvm.experimental.guard) into // invokes. The caller's "segment" of the deoptimization continuation Index: llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp === --- llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp +++ llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp @@ -39,6 +39,7 @@ #include "llvm/IR/DerivedTypes.h" #include "llvm/IR/Function.h" #include "llvm/IR/GlobalVariable.h" +#include "llvm/IR/InlineAsm.h" #include "llvm/IR/InstrTypes.h" #include "llvm/IR/Instruction.h" #include "llvm/IR/Instructions.h" @@ -2139,9 +2140,13 @@ } if (isa(Callee) && !Call.doesNotThrow()) { -// Inline asm calls cannot throw - mark them 'nounwind'. -Call.setDoesNotThrow(); -Changed = true; +InlineAsm *IA = cast(Callee); +if (!IA->canThrow()) { + // Normal inline asm calls cannot throw - mark them + // 'nounwind'. + Call.setDoesNotThrow(); + Changed = true; +} } // Try to optimize the call if possible, we require DataLayout for most of Index: llvm/lib/IR/InlineAsm.cpp === --- llvm/lib/IR/InlineAsm.cpp +++ llvm/lib/IR/InlineAsm.cpp @@ -29,11 +29,11 @@ InlineAsm::InlineAsm(FunctionType *FTy, const std::string &asmString, const std::string &constraints, bool hasSideEffects, - bool isAlignStack, AsmDialect asmDialect) + bool isAlignStack, AsmDialect asmDialect, bool canThrow) : Value(PointerType::getUnqual(FTy), Value::InlineAsmVal), AsmString(asmString), Constraints(constraints), FTy(FTy), HasSideEffects(hasSideEffects), IsAlignStack(isAlignStack), - Dialect(asmDialect) { + Dialect(asmDialect), CanThrow(canThrow) { // Do various checks on the constraint string and type. assert(Verify(getFunctionType(), constraints) && "Function type not legal for constraints!"); @@ -41,9 +41,10 @@ InlineAsm *InlineAsm::get(FunctionType *FTy, StringRef AsmString, StringRef Constraints, bool hasSideEffects, - bool isAlignStack, AsmDialect asmDialect) { + bool isAlignStack, AsmDialect asmDialect, + bool canThrow) { InlineAsmKeyType Key(AsmString, Constraints, FTy, hasSideEffects, - isAlignStack, asmDialect); + isAlign
[PATCH] D95745: Support unwinding from inline assembly
cynecx updated this revision to Diff 325323. cynecx edited the summary of this revision. cynecx added a comment. Herald added a subscriber: pengfei. Added tests and updated splitted patchset. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D95745/new/ https://reviews.llvm.org/D95745 Files: clang/lib/Basic/TargetInfo.cpp clang/lib/CodeGen/CGStmt.cpp clang/lib/Sema/SemaStmtAsm.cpp clang/test/CodeGenCXX/unwind-inline-asm.cpp llvm/bindings/go/llvm/ir.go llvm/include/llvm-c/Core.h llvm/include/llvm/Bitcode/LLVMBitCodes.h llvm/include/llvm/IR/InlineAsm.h llvm/lib/AsmParser/LLParser.cpp llvm/lib/Bitcode/Reader/BitcodeReader.cpp llvm/lib/Bitcode/Writer/BitcodeWriter.cpp llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h llvm/lib/IR/AsmWriter.cpp llvm/lib/IR/ConstantsContext.h llvm/lib/IR/Core.cpp llvm/lib/IR/InlineAsm.cpp llvm/lib/IR/Verifier.cpp llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp llvm/lib/Transforms/Utils/InlineFunction.cpp llvm/test/CodeGen/AArch64/GlobalISel/irtranslator-no-unwind-inline-asm.ll llvm/test/CodeGen/AArch64/GlobalISel/irtranslator-unwind-inline-asm.ll llvm/test/CodeGen/AArch64/GlobalISel/unwind-inline-asm.ll llvm/test/CodeGen/X86/no-unwind-inline-asm-codegen.ll llvm/test/CodeGen/X86/unwind-inline-asm-codegen.ll llvm/test/Transforms/Inline/no-unwind-inline-asm.ll llvm/test/Transforms/Inline/unwind-inline-asm.ll llvm/test/Transforms/InstCombine/no-unwind-inline-asm.ll llvm/test/Transforms/InstCombine/unwind-inline-asm.ll Index: llvm/test/Transforms/InstCombine/unwind-inline-asm.ll === --- /dev/null +++ llvm/test/Transforms/InstCombine/unwind-inline-asm.ll @@ -0,0 +1,38 @@ +; RUN: opt < %s -O2 -S | FileCheck %s + +target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +@.str.2 = private unnamed_addr constant [7 x i8] c"Boom!\0A\00", align 1 + +define dso_local void @trap() { +entry: + unreachable +} + +define dso_local void @test() personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) { +entry: +; CHECK: define dso_local void @test() +; CHECK-NEXT: entry: +; CHECK-NEXT: invoke void asm sideeffect unwind + + invoke void asm sideeffect unwind "call trap", "~{dirflag},~{fpsr},~{flags}"() + to label %invoke.cont unwind label %lpad + +invoke.cont: + ret void + +lpad: +; CHECK: %0 = landingpad { i8*, i32 } +; CHECK: resume { i8*, i32 } %0 + + %0 = landingpad { i8*, i32 } + cleanup + call void (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0)) + resume { i8*, i32 } %0 + +} + +declare dso_local i32 @__gxx_personality_v0(...) + +declare dso_local void @printf(i8*, ...) Index: llvm/test/Transforms/InstCombine/no-unwind-inline-asm.ll === --- /dev/null +++ llvm/test/Transforms/InstCombine/no-unwind-inline-asm.ll @@ -0,0 +1,36 @@ +; RUN: opt < %s -O2 -S | FileCheck %s + +target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +@.str.2 = private unnamed_addr constant [7 x i8] c"Boom!\0A\00", align 1 + +define dso_local void @trap() { +entry: + unreachable +} + +define dso_local void @test() personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) { +entry: +; CHECK: define dso_local void @test() +; CHECK-NEXT: entry: +; CHECK-NEXT: tail call void asm sideeffect +; CHECK-NEXT: ret void + + invoke void asm sideeffect "call trap", "~{dirflag},~{fpsr},~{flags}"() + to label %invoke.cont unwind label %lpad + +invoke.cont: + ret void + +lpad: + %0 = landingpad { i8*, i32 } + cleanup + call void (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0)) + resume { i8*, i32 } %0 + +} + +declare dso_local i32 @__gxx_personality_v0(...) + +declare dso_local void @printf(i8*, ...) Index: llvm/test/Transforms/Inline/unwind-inline-asm.ll === --- /dev/null +++ llvm/test/Transforms/Inline/unwind-inline-asm.ll @@ -0,0 +1,46 @@ +; RUN: opt < %s -inline -S | FileCheck %s + +target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +@.str.2 = private unnamed_addr constant [7 x i8] c"Boom!\0A\00", align 1 + +define dso_local void @trap() { +entry: + unreachable +} + +define dso_local void @proxy() personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) { +entry: + call void asm sideeffect unwind "call trap", "~{dirflag},~{fpsr},~{flags}"() + call void asm sideeffect unwind "call trap", "~{dirflag},~{fpsr},~{flags}"() + ret void
[PATCH] D95745: Support unwinding from inline assembly
cynecx added a comment. @rnk This is ready for a proper review :) Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D95745/new/ https://reviews.llvm.org/D95745 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D95745: Support unwinding from inline assembly
cynecx updated this revision to Diff 325328. cynecx added a comment. clang-format CHANGES SINCE LAST ACTION https://reviews.llvm.org/D95745/new/ https://reviews.llvm.org/D95745 Files: clang/lib/Basic/TargetInfo.cpp clang/lib/CodeGen/CGStmt.cpp clang/lib/Sema/SemaStmtAsm.cpp clang/test/CodeGenCXX/unwind-inline-asm.cpp llvm/bindings/go/llvm/ir.go llvm/include/llvm-c/Core.h llvm/include/llvm/Bitcode/LLVMBitCodes.h llvm/include/llvm/IR/InlineAsm.h llvm/lib/AsmParser/LLParser.cpp llvm/lib/Bitcode/Reader/BitcodeReader.cpp llvm/lib/Bitcode/Writer/BitcodeWriter.cpp llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h llvm/lib/IR/AsmWriter.cpp llvm/lib/IR/ConstantsContext.h llvm/lib/IR/Core.cpp llvm/lib/IR/InlineAsm.cpp llvm/lib/IR/Verifier.cpp llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp llvm/lib/Transforms/Utils/InlineFunction.cpp llvm/test/CodeGen/AArch64/GlobalISel/irtranslator-no-unwind-inline-asm.ll llvm/test/CodeGen/AArch64/GlobalISel/irtranslator-unwind-inline-asm.ll llvm/test/CodeGen/AArch64/GlobalISel/unwind-inline-asm.ll llvm/test/CodeGen/X86/no-unwind-inline-asm-codegen.ll llvm/test/CodeGen/X86/unwind-inline-asm-codegen.ll llvm/test/Transforms/Inline/no-unwind-inline-asm.ll llvm/test/Transforms/Inline/unwind-inline-asm.ll llvm/test/Transforms/InstCombine/no-unwind-inline-asm.ll llvm/test/Transforms/InstCombine/unwind-inline-asm.ll Index: llvm/test/Transforms/InstCombine/unwind-inline-asm.ll === --- /dev/null +++ llvm/test/Transforms/InstCombine/unwind-inline-asm.ll @@ -0,0 +1,38 @@ +; RUN: opt < %s -O2 -S | FileCheck %s + +target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +@.str.2 = private unnamed_addr constant [7 x i8] c"Boom!\0A\00", align 1 + +define dso_local void @trap() { +entry: + unreachable +} + +define dso_local void @test() personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) { +entry: +; CHECK: define dso_local void @test() +; CHECK-NEXT: entry: +; CHECK-NEXT: invoke void asm sideeffect unwind + + invoke void asm sideeffect unwind "call trap", "~{dirflag},~{fpsr},~{flags}"() + to label %invoke.cont unwind label %lpad + +invoke.cont: + ret void + +lpad: +; CHECK: %0 = landingpad { i8*, i32 } +; CHECK: resume { i8*, i32 } %0 + + %0 = landingpad { i8*, i32 } + cleanup + call void (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0)) + resume { i8*, i32 } %0 + +} + +declare dso_local i32 @__gxx_personality_v0(...) + +declare dso_local void @printf(i8*, ...) Index: llvm/test/Transforms/InstCombine/no-unwind-inline-asm.ll === --- /dev/null +++ llvm/test/Transforms/InstCombine/no-unwind-inline-asm.ll @@ -0,0 +1,36 @@ +; RUN: opt < %s -O2 -S | FileCheck %s + +target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +@.str.2 = private unnamed_addr constant [7 x i8] c"Boom!\0A\00", align 1 + +define dso_local void @trap() { +entry: + unreachable +} + +define dso_local void @test() personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) { +entry: +; CHECK: define dso_local void @test() +; CHECK-NEXT: entry: +; CHECK-NEXT: tail call void asm sideeffect +; CHECK-NEXT: ret void + + invoke void asm sideeffect "call trap", "~{dirflag},~{fpsr},~{flags}"() + to label %invoke.cont unwind label %lpad + +invoke.cont: + ret void + +lpad: + %0 = landingpad { i8*, i32 } + cleanup + call void (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0)) + resume { i8*, i32 } %0 + +} + +declare dso_local i32 @__gxx_personality_v0(...) + +declare dso_local void @printf(i8*, ...) Index: llvm/test/Transforms/Inline/unwind-inline-asm.ll === --- /dev/null +++ llvm/test/Transforms/Inline/unwind-inline-asm.ll @@ -0,0 +1,46 @@ +; RUN: opt < %s -inline -S | FileCheck %s + +target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +@.str.2 = private unnamed_addr constant [7 x i8] c"Boom!\0A\00", align 1 + +define dso_local void @trap() { +entry: + unreachable +} + +define dso_local void @proxy() personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) { +entry: + call void asm sideeffect unwind "call trap", "~{dirflag},~{fpsr},~{flags}"() + call void asm sideeffect unwind "call trap", "~{dirflag},~{fpsr},~{flags}"() + ret void +} + +define dso_local void @test() personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) { +entry: +; CHECK: define dso_local void @tes
[PATCH] D95745: Support unwinding from inline assembly
cynecx added a comment. Weekly ping :) CHANGES SINCE LAST ACTION https://reviews.llvm.org/D95745/new/ https://reviews.llvm.org/D95745 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D95745: Support unwinding from inline assembly
cynecx added a comment. Weekly ping! CHANGES SINCE LAST ACTION https://reviews.llvm.org/D95745/new/ https://reviews.llvm.org/D95745 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D25051: Fix PR 10758: Infinite recursion when dealing with copy-initialization
cynecx added a comment. Would it be possible to land this patch? I would really like to see this fixed. Repository: rL LLVM https://reviews.llvm.org/D25051 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D25051: Fix PR 10758: Infinite recursion when dealing with copy-initialization
cynecx added a comment. Gentle ping. Repository: rL LLVM https://reviews.llvm.org/D25051 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D95745: Support unwinding from inline assembly
cynecx updated this revision to Diff 343853. cynecx marked 4 inline comments as done. cynecx added a comment. Address review Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D95745/new/ https://reviews.llvm.org/D95745 Files: clang/include/clang/Basic/DiagnosticSemaKinds.td clang/lib/Basic/TargetInfo.cpp clang/lib/CodeGen/CGStmt.cpp clang/lib/Sema/SemaStmtAsm.cpp clang/test/CodeGenCXX/unwind-inline-asm.cpp llvm/bindings/go/llvm/ir.go llvm/include/llvm-c/Core.h llvm/include/llvm/Bitcode/LLVMBitCodes.h llvm/include/llvm/IR/InlineAsm.h llvm/lib/AsmParser/LLParser.cpp llvm/lib/Bitcode/Reader/BitcodeReader.cpp llvm/lib/Bitcode/Writer/BitcodeWriter.cpp llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h llvm/lib/IR/AsmWriter.cpp llvm/lib/IR/ConstantsContext.h llvm/lib/IR/Core.cpp llvm/lib/IR/InlineAsm.cpp llvm/lib/IR/Verifier.cpp llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp llvm/lib/Transforms/Utils/InlineFunction.cpp llvm/lib/Transforms/Utils/ValueMapper.cpp llvm/test/CodeGen/AArch64/GlobalISel/irtranslator-no-unwind-inline-asm.ll llvm/test/CodeGen/AArch64/GlobalISel/irtranslator-unwind-inline-asm.ll llvm/test/CodeGen/AArch64/GlobalISel/unwind-inline-asm.ll llvm/test/CodeGen/X86/no-seh-unwind-inline-asm-codegen.ll llvm/test/CodeGen/X86/no-unwind-inline-asm-codegen.ll llvm/test/CodeGen/X86/seh-unwind-inline-asm-codegen.ll llvm/test/CodeGen/X86/sjlj-unwind-inline-asm-codegen.ll llvm/test/CodeGen/X86/unwind-inline-asm-codegen.ll llvm/test/Transforms/Inline/no-unwind-inline-asm.ll llvm/test/Transforms/Inline/unwind-inline-asm.ll llvm/test/Transforms/InstCombine/no-unwind-inline-asm.ll llvm/test/Transforms/InstCombine/unwind-inline-asm.ll Index: llvm/test/Transforms/InstCombine/unwind-inline-asm.ll === --- /dev/null +++ llvm/test/Transforms/InstCombine/unwind-inline-asm.ll @@ -0,0 +1,38 @@ +; RUN: opt < %s -O2 -S | FileCheck %s + +target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +@.str.2 = private unnamed_addr constant [7 x i8] c"Boom!\0A\00", align 1 + +define dso_local void @trap() { +entry: + unreachable +} + +define dso_local void @test() personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) { +entry: +; CHECK: define dso_local void @test() +; CHECK-NEXT: entry: +; CHECK-NEXT: invoke void asm sideeffect unwind + + invoke void asm sideeffect unwind "call trap", "~{dirflag},~{fpsr},~{flags}"() + to label %invoke.cont unwind label %lpad + +invoke.cont: + ret void + +lpad: +; CHECK: %0 = landingpad { i8*, i32 } +; CHECK: resume { i8*, i32 } %0 + + %0 = landingpad { i8*, i32 } + cleanup + call void (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0)) + resume { i8*, i32 } %0 + +} + +declare dso_local i32 @__gxx_personality_v0(...) + +declare dso_local void @printf(i8*, ...) Index: llvm/test/Transforms/InstCombine/no-unwind-inline-asm.ll === --- /dev/null +++ llvm/test/Transforms/InstCombine/no-unwind-inline-asm.ll @@ -0,0 +1,36 @@ +; RUN: opt < %s -O2 -S | FileCheck %s + +target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +@.str.2 = private unnamed_addr constant [7 x i8] c"Boom!\0A\00", align 1 + +define dso_local void @trap() { +entry: + unreachable +} + +define dso_local void @test() personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) { +entry: +; CHECK: define dso_local void @test() +; CHECK-NEXT: entry: +; CHECK-NEXT: tail call void asm sideeffect +; CHECK-NEXT: ret void + + invoke void asm sideeffect "call trap", "~{dirflag},~{fpsr},~{flags}"() + to label %invoke.cont unwind label %lpad + +invoke.cont: + ret void + +lpad: + %0 = landingpad { i8*, i32 } + cleanup + call void (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0)) + resume { i8*, i32 } %0 + +} + +declare dso_local i32 @__gxx_personality_v0(...) + +declare dso_local void @printf(i8*, ...) Index: llvm/test/Transforms/Inline/unwind-inline-asm.ll === --- /dev/null +++ llvm/test/Transforms/Inline/unwind-inline-asm.ll @@ -0,0 +1,46 @@ +; RUN: opt < %s -inline -S | FileCheck %s + +target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +@.str.2 = private unnamed_addr constant [7 x i8] c"Boom!\0A\00", align 1 + +define dso_local void @trap() { +entry: + unreachable +} + +define dso_local void @proxy() personality i8* bitcast (i32 (...)* @__gxx_p
[PATCH] D95745: Support unwinding from inline assembly
cynecx added inline comments. Comment at: llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp:2446 +if (!IA->canThrow()) { + // Fast path without emitting EH_LABELs. + Amanieu wrote: > Is this fast path actually useful? The frontend will almost never emit an > invoke instruction for inline asm that can't unwind. This is just an optimization so that we don't emit unwind information since the inline asm doesn't "throw" and also matches the old/new SelectionDAG behavior. Either way I don't really mind removing this but I'd personally keep this for consistency. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D95745/new/ https://reviews.llvm.org/D95745 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D95745: Support unwinding from inline assembly
cynecx added a comment. Sorry about the delay. I've updated and rebased the patchset (which also includes tests for different exception models like seh/sjlj). Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D95745/new/ https://reviews.llvm.org/D95745 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D95745: Support unwinding from inline assembly
cynecx updated this revision to Diff 343924. cynecx added a comment. Fix assertion and clang-format patch. CHANGES SINCE LAST ACTION https://reviews.llvm.org/D95745/new/ https://reviews.llvm.org/D95745 Files: clang/include/clang/Basic/DiagnosticSemaKinds.td clang/lib/Basic/TargetInfo.cpp clang/lib/CodeGen/CGStmt.cpp clang/lib/Sema/SemaStmtAsm.cpp clang/test/CodeGenCXX/unwind-inline-asm.cpp llvm/bindings/go/llvm/ir.go llvm/include/llvm-c/Core.h llvm/include/llvm/Bitcode/LLVMBitCodes.h llvm/include/llvm/IR/InlineAsm.h llvm/lib/AsmParser/LLParser.cpp llvm/lib/Bitcode/Reader/BitcodeReader.cpp llvm/lib/Bitcode/Writer/BitcodeWriter.cpp llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h llvm/lib/IR/AsmWriter.cpp llvm/lib/IR/ConstantsContext.h llvm/lib/IR/Core.cpp llvm/lib/IR/InlineAsm.cpp llvm/lib/IR/Verifier.cpp llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp llvm/lib/Transforms/Utils/InlineFunction.cpp llvm/lib/Transforms/Utils/ValueMapper.cpp llvm/test/CodeGen/AArch64/GlobalISel/irtranslator-no-unwind-inline-asm.ll llvm/test/CodeGen/AArch64/GlobalISel/irtranslator-unwind-inline-asm.ll llvm/test/CodeGen/AArch64/GlobalISel/unwind-inline-asm.ll llvm/test/CodeGen/X86/no-seh-unwind-inline-asm-codegen.ll llvm/test/CodeGen/X86/no-unwind-inline-asm-codegen.ll llvm/test/CodeGen/X86/seh-unwind-inline-asm-codegen.ll llvm/test/CodeGen/X86/sjlj-unwind-inline-asm-codegen.ll llvm/test/CodeGen/X86/unwind-inline-asm-codegen.ll llvm/test/Transforms/Inline/no-unwind-inline-asm.ll llvm/test/Transforms/Inline/unwind-inline-asm.ll llvm/test/Transforms/InstCombine/no-unwind-inline-asm.ll llvm/test/Transforms/InstCombine/unwind-inline-asm.ll Index: llvm/test/Transforms/InstCombine/unwind-inline-asm.ll === --- /dev/null +++ llvm/test/Transforms/InstCombine/unwind-inline-asm.ll @@ -0,0 +1,38 @@ +; RUN: opt < %s -O2 -S | FileCheck %s + +target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +@.str.2 = private unnamed_addr constant [7 x i8] c"Boom!\0A\00", align 1 + +define dso_local void @trap() { +entry: + unreachable +} + +define dso_local void @test() personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) { +entry: +; CHECK: define dso_local void @test() +; CHECK-NEXT: entry: +; CHECK-NEXT: invoke void asm sideeffect unwind + + invoke void asm sideeffect unwind "call trap", "~{dirflag},~{fpsr},~{flags}"() + to label %invoke.cont unwind label %lpad + +invoke.cont: + ret void + +lpad: +; CHECK: %0 = landingpad { i8*, i32 } +; CHECK: resume { i8*, i32 } %0 + + %0 = landingpad { i8*, i32 } + cleanup + call void (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0)) + resume { i8*, i32 } %0 + +} + +declare dso_local i32 @__gxx_personality_v0(...) + +declare dso_local void @printf(i8*, ...) Index: llvm/test/Transforms/InstCombine/no-unwind-inline-asm.ll === --- /dev/null +++ llvm/test/Transforms/InstCombine/no-unwind-inline-asm.ll @@ -0,0 +1,36 @@ +; RUN: opt < %s -O2 -S | FileCheck %s + +target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +@.str.2 = private unnamed_addr constant [7 x i8] c"Boom!\0A\00", align 1 + +define dso_local void @trap() { +entry: + unreachable +} + +define dso_local void @test() personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) { +entry: +; CHECK: define dso_local void @test() +; CHECK-NEXT: entry: +; CHECK-NEXT: tail call void asm sideeffect +; CHECK-NEXT: ret void + + invoke void asm sideeffect "call trap", "~{dirflag},~{fpsr},~{flags}"() + to label %invoke.cont unwind label %lpad + +invoke.cont: + ret void + +lpad: + %0 = landingpad { i8*, i32 } + cleanup + call void (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0)) + resume { i8*, i32 } %0 + +} + +declare dso_local i32 @__gxx_personality_v0(...) + +declare dso_local void @printf(i8*, ...) Index: llvm/test/Transforms/Inline/unwind-inline-asm.ll === --- /dev/null +++ llvm/test/Transforms/Inline/unwind-inline-asm.ll @@ -0,0 +1,46 @@ +; RUN: opt < %s -inline -S | FileCheck %s + +target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +@.str.2 = private unnamed_addr constant [7 x i8] c"Boom!\0A\00", align 1 + +define dso_local void @trap() { +entry: + unreachable +} + +define dso_local void @proxy() personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) { +entry: + call void asm sideeffe
[PATCH] D95745: Support unwinding from inline assembly
cynecx updated this revision to Diff 343932. cynecx added a comment. actually run clang-format Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D95745/new/ https://reviews.llvm.org/D95745 Files: clang/include/clang/Basic/DiagnosticSemaKinds.td clang/lib/Basic/TargetInfo.cpp clang/lib/CodeGen/CGStmt.cpp clang/lib/Sema/SemaStmtAsm.cpp clang/test/CodeGenCXX/unwind-inline-asm.cpp llvm/bindings/go/llvm/ir.go llvm/include/llvm-c/Core.h llvm/include/llvm/Bitcode/LLVMBitCodes.h llvm/include/llvm/IR/InlineAsm.h llvm/lib/AsmParser/LLParser.cpp llvm/lib/Bitcode/Reader/BitcodeReader.cpp llvm/lib/Bitcode/Writer/BitcodeWriter.cpp llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h llvm/lib/IR/AsmWriter.cpp llvm/lib/IR/ConstantsContext.h llvm/lib/IR/Core.cpp llvm/lib/IR/InlineAsm.cpp llvm/lib/IR/Verifier.cpp llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp llvm/lib/Transforms/Utils/InlineFunction.cpp llvm/lib/Transforms/Utils/ValueMapper.cpp llvm/test/CodeGen/AArch64/GlobalISel/irtranslator-no-unwind-inline-asm.ll llvm/test/CodeGen/AArch64/GlobalISel/irtranslator-unwind-inline-asm.ll llvm/test/CodeGen/AArch64/GlobalISel/unwind-inline-asm.ll llvm/test/CodeGen/X86/no-seh-unwind-inline-asm-codegen.ll llvm/test/CodeGen/X86/no-unwind-inline-asm-codegen.ll llvm/test/CodeGen/X86/seh-unwind-inline-asm-codegen.ll llvm/test/CodeGen/X86/sjlj-unwind-inline-asm-codegen.ll llvm/test/CodeGen/X86/unwind-inline-asm-codegen.ll llvm/test/Transforms/Inline/no-unwind-inline-asm.ll llvm/test/Transforms/Inline/unwind-inline-asm.ll llvm/test/Transforms/InstCombine/no-unwind-inline-asm.ll llvm/test/Transforms/InstCombine/unwind-inline-asm.ll Index: llvm/test/Transforms/InstCombine/unwind-inline-asm.ll === --- /dev/null +++ llvm/test/Transforms/InstCombine/unwind-inline-asm.ll @@ -0,0 +1,38 @@ +; RUN: opt < %s -O2 -S | FileCheck %s + +target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +@.str.2 = private unnamed_addr constant [7 x i8] c"Boom!\0A\00", align 1 + +define dso_local void @trap() { +entry: + unreachable +} + +define dso_local void @test() personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) { +entry: +; CHECK: define dso_local void @test() +; CHECK-NEXT: entry: +; CHECK-NEXT: invoke void asm sideeffect unwind + + invoke void asm sideeffect unwind "call trap", "~{dirflag},~{fpsr},~{flags}"() + to label %invoke.cont unwind label %lpad + +invoke.cont: + ret void + +lpad: +; CHECK: %0 = landingpad { i8*, i32 } +; CHECK: resume { i8*, i32 } %0 + + %0 = landingpad { i8*, i32 } + cleanup + call void (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0)) + resume { i8*, i32 } %0 + +} + +declare dso_local i32 @__gxx_personality_v0(...) + +declare dso_local void @printf(i8*, ...) Index: llvm/test/Transforms/InstCombine/no-unwind-inline-asm.ll === --- /dev/null +++ llvm/test/Transforms/InstCombine/no-unwind-inline-asm.ll @@ -0,0 +1,36 @@ +; RUN: opt < %s -O2 -S | FileCheck %s + +target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +@.str.2 = private unnamed_addr constant [7 x i8] c"Boom!\0A\00", align 1 + +define dso_local void @trap() { +entry: + unreachable +} + +define dso_local void @test() personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) { +entry: +; CHECK: define dso_local void @test() +; CHECK-NEXT: entry: +; CHECK-NEXT: tail call void asm sideeffect +; CHECK-NEXT: ret void + + invoke void asm sideeffect "call trap", "~{dirflag},~{fpsr},~{flags}"() + to label %invoke.cont unwind label %lpad + +invoke.cont: + ret void + +lpad: + %0 = landingpad { i8*, i32 } + cleanup + call void (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0)) + resume { i8*, i32 } %0 + +} + +declare dso_local i32 @__gxx_personality_v0(...) + +declare dso_local void @printf(i8*, ...) Index: llvm/test/Transforms/Inline/unwind-inline-asm.ll === --- /dev/null +++ llvm/test/Transforms/Inline/unwind-inline-asm.ll @@ -0,0 +1,46 @@ +; RUN: opt < %s -inline -S | FileCheck %s + +target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +@.str.2 = private unnamed_addr constant [7 x i8] c"Boom!\0A\00", align 1 + +define dso_local void @trap() { +entry: + unreachable +} + +define dso_local void @proxy() personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) { +entry
[PATCH] D95745: Support unwinding from inline assembly
cynecx added a comment. Weekly Ping! CHANGES SINCE LAST ACTION https://reviews.llvm.org/D95745/new/ https://reviews.llvm.org/D95745 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits