[llvm-commits] [llvm] r45073 - in /llvm/trunk: include/llvm/Support/CallSite.h lib/Transforms/Scalar/InstructionCombining.cpp lib/Transforms/Utils/InlineFunction.cpp lib/VMCore/Instructions.cpp test/CFrontend/2007-12-16-AsmNoUnwind.c test/Transforms/Inline/2007-04-15-InlineEH.ll test/Transforms/InstCombine/2007-12-16-AsmNoUnwind.ll

Duncan Sands baldrick at free.fr
Sun Dec 16 07:51:50 PST 2007


Author: baldrick
Date: Sun Dec 16 09:51:49 2007
New Revision: 45073

URL: http://llvm.org/viewvc/llvm-project?rev=45073&view=rev
Log:
Make instcombine promote inline asm calls to 'nounwind'
calls.  Remove special casing of inline asm from the
inliner.  There is a potential problem: the verifier
rejects invokes of inline asm (not sure why).  If an
asm call is not marked "nounwind" in some .ll, and
instcombine is not run, but the inliner is run, then
an illegal module will be created.  This is bad but
I'm not sure what the best approach is.  I'm tempted
to remove the check in the verifier...

Added:
    llvm/trunk/test/CFrontend/2007-12-16-AsmNoUnwind.c
    llvm/trunk/test/Transforms/InstCombine/2007-12-16-AsmNoUnwind.ll
Modified:
    llvm/trunk/include/llvm/Support/CallSite.h
    llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp
    llvm/trunk/lib/Transforms/Utils/InlineFunction.cpp
    llvm/trunk/lib/VMCore/Instructions.cpp
    llvm/trunk/test/Transforms/Inline/2007-04-15-InlineEH.ll

Modified: llvm/trunk/include/llvm/Support/CallSite.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/CallSite.h?rev=45073&r1=45072&r2=45073&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Support/CallSite.h (original)
+++ llvm/trunk/include/llvm/Support/CallSite.h Sun Dec 16 09:51:49 2007
@@ -73,6 +73,9 @@
   /// @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(); }

Modified: llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp?rev=45073&r1=45072&r2=45073&view=diff

==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp Sun Dec 16 09:51:49 2007
@@ -7972,6 +7972,19 @@
       }
   }
 
+  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;
 }
 

Modified: llvm/trunk/lib/Transforms/Utils/InlineFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/InlineFunction.cpp?rev=45073&r1=45072&r2=45073&view=diff

==============================================================================
--- llvm/trunk/lib/Transforms/Utils/InlineFunction.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/InlineFunction.cpp Sun Dec 16 09:51:49 2007
@@ -69,9 +69,8 @@
           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.

Modified: llvm/trunk/lib/VMCore/Instructions.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Instructions.cpp?rev=45073&r1=45072&r2=45073&view=diff

==============================================================================
--- llvm/trunk/lib/VMCore/Instructions.cpp (original)
+++ llvm/trunk/lib/VMCore/Instructions.cpp Sun Dec 16 09:51:49 2007
@@ -65,6 +65,12 @@
   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();
+}
 
 
 

Added: llvm/trunk/test/CFrontend/2007-12-16-AsmNoUnwind.c
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CFrontend/2007-12-16-AsmNoUnwind.c?rev=45073&view=auto

==============================================================================
--- llvm/trunk/test/CFrontend/2007-12-16-AsmNoUnwind.c (added)
+++ llvm/trunk/test/CFrontend/2007-12-16-AsmNoUnwind.c Sun Dec 16 09:51:49 2007
@@ -0,0 +1,3 @@
+// RUN: %llvmgcc %s -S -o - | grep nounwind
+
+void bar() { asm (""); }

Modified: llvm/trunk/test/Transforms/Inline/2007-04-15-InlineEH.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/Inline/2007-04-15-InlineEH.ll?rev=45073&r1=45072&r2=45073&view=diff

==============================================================================
--- llvm/trunk/test/Transforms/Inline/2007-04-15-InlineEH.ll (original)
+++ llvm/trunk/test/Transforms/Inline/2007-04-15-InlineEH.ll Sun Dec 16 09:51:49 2007
@@ -8,7 +8,7 @@
 
 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
 }
 

Added: llvm/trunk/test/Transforms/InstCombine/2007-12-16-AsmNoUnwind.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/2007-12-16-AsmNoUnwind.ll?rev=45073&view=auto

==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/2007-12-16-AsmNoUnwind.ll (added)
+++ llvm/trunk/test/Transforms/InstCombine/2007-12-16-AsmNoUnwind.ll Sun Dec 16 09:51:49 2007
@@ -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
+}





More information about the llvm-commits mailing list