Simplify caller updating using a CallSite, as
authorDuncan Sands <baldrick@free.fr>
Mon, 18 Feb 2008 17:32:13 +0000 (17:32 +0000)
committerDuncan Sands <baldrick@free.fr>
Mon, 18 Feb 2008 17:32:13 +0000 (17:32 +0000)
requested by Chris.  While there, do the same
for an existing function committed by someone
called "lattner" :)

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@47273 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Support/CallSite.h
lib/Transforms/IPO/GlobalOpt.cpp
lib/VMCore/Instructions.cpp

index 7e95e5db7b6e9309582a8ffe1e61ccfb71ad25b9..cbb6548fc474122a07c2a2ed676e052d0ce7c1ab 100644 (file)
@@ -35,6 +35,7 @@ public:
   CallSite() : I(0) {}
   CallSite(CallInst *CI) : I(reinterpret_cast<Instruction*>(CI)) {}
   CallSite(InvokeInst *II) : I(reinterpret_cast<Instruction*>(II)) {}
+  CallSite(Instruction *C);
   CallSite(const CallSite &CS) : I(CS.I) {}
   CallSite &operator=(const CallSite &CS) { I = CS.I; return *this; }
 
index fd71dfb826148bcd968f8fda23dfdb86ff5f63ac..ef76a6e42d46214375c19ef1bae3ac49ebfca8c4 100644 (file)
@@ -25,6 +25,7 @@
 #include "llvm/Pass.h"
 #include "llvm/Analysis/ConstantFolding.h"
 #include "llvm/Target/TargetData.h"
+#include "llvm/Support/CallSite.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Support/GetElementPtrTypeIterator.h"
@@ -1584,25 +1585,23 @@ static bool OnlyCalledDirectly(Function *F) {
 /// function, changing them to FastCC.
 static void ChangeCalleesToFastCall(Function *F) {
   for (Value::use_iterator UI = F->use_begin(), E = F->use_end(); UI != E;++UI){
-    Instruction *User = cast<Instruction>(*UI);
-    if (CallInst *CI = dyn_cast<CallInst>(User))
-      CI->setCallingConv(CallingConv::Fast);
-    else
-      cast<InvokeInst>(User)->setCallingConv(CallingConv::Fast);
+    CallSite User(cast<Instruction>(*UI));
+    User.setCallingConv(CallingConv::Fast);
   }
 }
 
 static const ParamAttrsList *StripNest(const ParamAttrsList *Attrs) {
-  if (Attrs) {
-    for (unsigned i = 0, e = Attrs->size(); i != e; ++i) {
-      uint16_t A = Attrs->getParamAttrsAtIndex(i);
-      if (A & ParamAttr::Nest) {
-        Attrs = ParamAttrsList::excludeAttrs(Attrs, Attrs->getParamIndex(i),
-                                             ParamAttr::Nest);
-        // There can be only one.
-        break;
-      }
-    }
+  if (!Attrs)
+    return NULL;
+
+  for (unsigned i = 0, e = Attrs->size(); i != e; ++i) {
+    if ((Attrs->getParamAttrsAtIndex(i) & ParamAttr::Nest) == 0)
+      continue;
+
+    Attrs = ParamAttrsList::excludeAttrs(Attrs, Attrs->getParamIndex(i),
+                                         ParamAttr::Nest);
+    // There can be only one.
+    break;
   }
 
   return Attrs;
@@ -1611,13 +1610,8 @@ static const ParamAttrsList *StripNest(const ParamAttrsList *Attrs) {
 static void RemoveNestAttribute(Function *F) {
   F->setParamAttrs(StripNest(F->getParamAttrs()));
   for (Value::use_iterator UI = F->use_begin(), E = F->use_end(); UI != E;++UI){
-    Instruction *User = cast<Instruction>(*UI);
-    if (CallInst *CI = dyn_cast<CallInst>(User)) {
-      CI->setParamAttrs(StripNest(CI->getParamAttrs()));
-    } else {
-      InvokeInst *II = cast<InvokeInst>(User);
-      II->setParamAttrs(StripNest(II->getParamAttrs()));
-    }
+    CallSite User(cast<Instruction>(*UI));
+    User.setParamAttrs(StripNest(User.getParamAttrs()));
   }
 }
 
index b945a5a0dd7e13fdf193436fb3e9cd79339d2978..1a4a5ce7258de9c166f288324520ea61ad984a30 100644 (file)
@@ -27,6 +27,10 @@ using namespace llvm;
 //                            CallSite Class
 //===----------------------------------------------------------------------===//
 
+CallSite::CallSite(Instruction *C) {
+  assert((isa<CallInst>(C) || isa<InvokeInst>(C)) && "Not a call!");
+  I = C;
+}
 unsigned CallSite::getCallingConv() const {
   if (CallInst *CI = dyn_cast<CallInst>(I))
     return CI->getCallingConv();