From a85448506d26407c501fa81f06aed3566b755ae7 Mon Sep 17 00:00:00 2001 From: Duncan Sands Date: Mon, 18 Feb 2008 17:32:13 +0000 Subject: [PATCH] Simplify caller updating using a CallSite, as requested by Chris. While there, do the same for an existing function committed by someone called "lattner" :) llvm-svn: 47273 --- include/llvm/Support/CallSite.h | 1 + lib/Transforms/IPO/GlobalOpt.cpp | 38 ++++++++++++++------------------ lib/VMCore/Instructions.cpp | 4 ++++ 3 files changed, 21 insertions(+), 22 deletions(-) diff --git a/include/llvm/Support/CallSite.h b/include/llvm/Support/CallSite.h index 7e95e5db7b6..cbb6548fc47 100644 --- a/include/llvm/Support/CallSite.h +++ b/include/llvm/Support/CallSite.h @@ -35,6 +35,7 @@ public: CallSite() : I(0) {} CallSite(CallInst *CI) : I(reinterpret_cast(CI)) {} CallSite(InvokeInst *II) : I(reinterpret_cast(II)) {} + CallSite(Instruction *C); CallSite(const CallSite &CS) : I(CS.I) {} CallSite &operator=(const CallSite &CS) { I = CS.I; return *this; } diff --git a/lib/Transforms/IPO/GlobalOpt.cpp b/lib/Transforms/IPO/GlobalOpt.cpp index fd71dfb8261..ef76a6e42d4 100644 --- a/lib/Transforms/IPO/GlobalOpt.cpp +++ b/lib/Transforms/IPO/GlobalOpt.cpp @@ -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(*UI); - if (CallInst *CI = dyn_cast(User)) - CI->setCallingConv(CallingConv::Fast); - else - cast(User)->setCallingConv(CallingConv::Fast); + CallSite User(cast(*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(*UI); - if (CallInst *CI = dyn_cast(User)) { - CI->setParamAttrs(StripNest(CI->getParamAttrs())); - } else { - InvokeInst *II = cast(User); - II->setParamAttrs(StripNest(II->getParamAttrs())); - } + CallSite User(cast(*UI)); + User.setParamAttrs(StripNest(User.getParamAttrs())); } } diff --git a/lib/VMCore/Instructions.cpp b/lib/VMCore/Instructions.cpp index b945a5a0dd7..1a4a5ce7258 100644 --- a/lib/VMCore/Instructions.cpp +++ b/lib/VMCore/Instructions.cpp @@ -27,6 +27,10 @@ using namespace llvm; // CallSite Class //===----------------------------------------------------------------------===// +CallSite::CallSite(Instruction *C) { + assert((isa(C) || isa(C)) && "Not a call!"); + I = C; +} unsigned CallSite::getCallingConv() const { if (CallInst *CI = dyn_cast(I)) return CI->getCallingConv();