Hi,

Sorry for reply late.  Attached is the modified patch. It's now just for
NoAlias attribute and more safe for just eliminating bitcast that losing
attribute case. Thanks for reviewing in advance.

Sheng.

2007/11/9, Duncan Sands <[EMAIL PROTECTED]>:
>
> Hi,
>
> > This patch is for PR1582. As recent discuss on that pr, the C++ FE
> doesn't
> > track the restrict qualifier in the function declaration at all. When
> > llvm-gcc handling CALL_EXPR and emiting callInst instruction, it can't
> get
> > the "NoAlias" attribute, and hence insert a BitCast in CallInst. This
> patch
> > is to eliminate this bitcast.
>
> what if one is varargs but not the other?  Also, your patch is quite
> general
> in that it ignores *any* parameter attributes, not just restrict.  I think
> this
> is basically ok (though it should presumably also ignore return
> attributes).
> That said, it could instead form the union of the previous attributes and
> any new ones.
> But I think the safest approach is to assert that any new attributes
> include the old
> ones, meaning that attributes can only be added, and no attributes
> removed,
> when going from the old to the new functions.
>
> Ciao,
>
> Duncan.
>
Index: llvm-convert.cpp
===================================================================
--- llvm-convert.cpp	(revision 44005)
+++ llvm-convert.cpp	(working copy)
@@ -34,6 +34,7 @@
 #include "llvm/InlineAsm.h"
 #include "llvm/Instructions.h"
 #include "llvm/Module.h"
+#include "llvm/ParameterAttributes.h"
 #include "llvm/Analysis/ConstantFolding.h"
 #include "llvm/Target/TargetAsmInfo.h"
 #include "llvm/Target/TargetData.h"
@@ -2846,8 +2847,16 @@
   // to:
   //   %tmp = call float @foo( )
   // This commonly occurs due to C "implicit ..." semantics.
+  //
+  // Or
+  //
+  //   call void bitcast (void (i32* noalias)* @foo to void (i32*)*)(i32* %x)
+  // to:
+  //   call void @foo(i32* %x noalias)
+  // This occurs due to C++ FE doesn't track the restrict qualifier 
+  // in the function declaration at all.
   if (ConstantExpr *CE = dyn_cast<ConstantExpr>(Callee)) {
-    if (CallOperands.empty() && CE->getOpcode() == Instruction::BitCast) {
+    if (CE->getOpcode() == Instruction::BitCast) {
       Constant *RealCallee = CE->getOperand(0);
       assert(isa<PointerType>(RealCallee->getType()) &&
              "Bitcast to ptr not from ptr?");
@@ -2858,8 +2867,30 @@
         const FunctionType *ActualFT =
           cast<FunctionType>(ActualPT->getElementType());
         if (RealFT->getReturnType() == ActualFT->getReturnType() &&
-            ActualFT->getNumParams() == 0)
+            ActualFT->getNumParams() == 0 && CallOperands.empty())
           Callee = RealCallee;
+        else if (RealFT->getReturnType() == ActualFT->getReturnType() &&
+                 RealFT->getNumParams() == ActualFT->getNumParams() &&
+                 RealFT->getNumParams() == CallOperands.size() &&
+                 RealFT->getParamAttrs()) {
+          bool isSame = true;
+          for (unsigned i = 0; i < RealFT->getNumParams(); ++i) {
+            if (RealFT->getParamType(i) != ActualFT->getParamType(i)) {
+              isSame = false;
+              break;
+            } else if (ActualFT->getParamAttrs()){
+              uint16_t RealAttr = RealFT->getParamAttrs()->getParamAttrs(i);
+              uint16_t ActualAttr = ActualFT->getParamAttrs()->getParamAttrs(i);
+              if (RealAttr != ActualAttr && 
+                  RealAttr != (ActualAttr | ParamAttr::NoAlias)) {
+                isSame = false;
+                break;
+              }
+            }
+          }
+          if (isSame)
+            Callee = RealCallee;
+        }
       }
     }
   }
_______________________________________________
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits

Reply via email to