summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/include/llvm/Support/CallSite.h3
-rw-r--r--llvm/lib/Transforms/Scalar/InstructionCombining.cpp13
-rw-r--r--llvm/lib/Transforms/Utils/InlineFunction.cpp5
-rw-r--r--llvm/lib/VMCore/Instructions.cpp6
-rw-r--r--llvm/test/CFrontend/2007-12-16-AsmNoUnwind.c3
-rw-r--r--llvm/test/Transforms/Inline/2007-04-15-InlineEH.ll2
-rw-r--r--llvm/test/Transforms/InstCombine/2007-12-16-AsmNoUnwind.ll7
7 files changed, 35 insertions, 4 deletions
diff --git a/llvm/include/llvm/Support/CallSite.h b/llvm/include/llvm/Support/CallSite.h
index 5bb60a8a8af..3735842e724 100644
--- a/llvm/include/llvm/Support/CallSite.h
+++ b/llvm/include/llvm/Support/CallSite.h
@@ -73,6 +73,9 @@ public:
/// @brief Determine if the call does not access or only reads memory.
bool onlyReadsMemory() const;
+ /// @brief Determine if the call cannot unwind.
+ bool isNoUnwind() const;
+
/// getType - Return the type of the instruction that generated this call site
///
const Type *getType() const { return I->getType(); }
diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
index 653d35e34f4..aa9e932fc52 100644
--- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -7972,6 +7972,19 @@ Instruction *InstCombiner::visitCallSite(CallSite CS) {
}
}
+ if (isa<InlineAsm>(Callee) && !CS.isNoUnwind()) {
+ // Inline asm calls cannot throw - mark them 'nounwind'.
+ const ParamAttrsList *PAL = CS.getParamAttrs();
+ uint16_t RAttributes = PAL ? PAL->getParamAttrs(0) : 0;
+ RAttributes |= ParamAttr::NoUnwind;
+
+ ParamAttrsVector modVec;
+ modVec.push_back(ParamAttrsWithIndex::get(0, RAttributes));
+ PAL = ParamAttrsList::getModified(PAL, modVec);
+ CS.setParamAttrs(PAL);
+ Changed = true;
+ }
+
return Changed ? CS.getInstruction() : 0;
}
diff --git a/llvm/lib/Transforms/Utils/InlineFunction.cpp b/llvm/lib/Transforms/Utils/InlineFunction.cpp
index e9f6b28e98b..3d31f71300a 100644
--- a/llvm/lib/Transforms/Utils/InlineFunction.cpp
+++ b/llvm/lib/Transforms/Utils/InlineFunction.cpp
@@ -69,9 +69,8 @@ static void HandleInlinedInvoke(InvokeInst *II, BasicBlock *FirstNewBlock,
if (!isa<CallInst>(I)) continue;
CallInst *CI = cast<CallInst>(I);
- // If this call cannot unwind or is an inline asm, don't
- // convert it to an invoke.
- if (CI->isNoUnwind() || isa<InlineAsm>(CI->getCalledValue()))
+ // If this call cannot unwind, don't convert it to an invoke.
+ if (CI->isNoUnwind())
continue;
// Convert this function call into an invoke instruction.
diff --git a/llvm/lib/VMCore/Instructions.cpp b/llvm/lib/VMCore/Instructions.cpp
index 5207ea52f49..511a0e851a1 100644
--- a/llvm/lib/VMCore/Instructions.cpp
+++ b/llvm/lib/VMCore/Instructions.cpp
@@ -65,6 +65,12 @@ bool CallSite::onlyReadsMemory() const {
else
return cast<InvokeInst>(I)->onlyReadsMemory();
}
+bool CallSite::isNoUnwind() const {
+ if (CallInst *CI = dyn_cast<CallInst>(I))
+ return CI->isNoUnwind();
+ else
+ return cast<InvokeInst>(I)->isNoUnwind();
+}
diff --git a/llvm/test/CFrontend/2007-12-16-AsmNoUnwind.c b/llvm/test/CFrontend/2007-12-16-AsmNoUnwind.c
new file mode 100644
index 00000000000..b080e6a511e
--- /dev/null
+++ b/llvm/test/CFrontend/2007-12-16-AsmNoUnwind.c
@@ -0,0 +1,3 @@
+// RUN: %llvmgcc %s -S -o - | grep nounwind
+
+void bar() { asm (""); }
diff --git a/llvm/test/Transforms/Inline/2007-04-15-InlineEH.ll b/llvm/test/Transforms/Inline/2007-04-15-InlineEH.ll
index 73b0e215e8c..9d28755d289 100644
--- a/llvm/test/Transforms/Inline/2007-04-15-InlineEH.ll
+++ b/llvm/test/Transforms/Inline/2007-04-15-InlineEH.ll
@@ -8,7 +8,7 @@ target triple = "i686-pc-linux-gnu"
define void @bc__support__high_resolution_time__clock() {
entry:
- call void asm "rdtsc\0A\09movl %eax, $0\0A\09movl %edx, $1", "=*imr,=*imr,~{dirflag},~{fpsr},~{flags},~{dx},~{ax}"( i32* null, i32* null )
+ call void asm "rdtsc\0A\09movl %eax, $0\0A\09movl %edx, $1", "=*imr,=*imr,~{dirflag},~{fpsr},~{flags},~{dx},~{ax}"( i32* null, i32* null ) nounwind
unreachable
}
diff --git a/llvm/test/Transforms/InstCombine/2007-12-16-AsmNoUnwind.ll b/llvm/test/Transforms/InstCombine/2007-12-16-AsmNoUnwind.ll
new file mode 100644
index 00000000000..336c6d5a2eb
--- /dev/null
+++ b/llvm/test/Transforms/InstCombine/2007-12-16-AsmNoUnwind.ll
@@ -0,0 +1,7 @@
+; RUN: llvm-as < %s | opt -instcombine | llvm-dis | grep nounwind
+
+define void @bar() {
+entry:
+ call void asm sideeffect "", "~{dirflag},~{fpsr},~{flags}"( )
+ ret void
+}
OpenPOWER on IntegriCloud