X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=include%2Fllvm%2FSupport%2FCallSite.h;h=7a0b8db9bb84d6fec3385076036596f240f06c89;hb=57ac1f458a754f30cf500410b438fb260f9b8fe5;hp=0650b61fbcfa1063247c3968a2b786a74113f693;hpb=607a7ab3da72a2eb53553a520507cbb8068dd1d8;p=oota-llvm.git diff --git a/include/llvm/Support/CallSite.h b/include/llvm/Support/CallSite.h index 0650b61fbcf..7a0b8db9bb8 100644 --- a/include/llvm/Support/CallSite.h +++ b/include/llvm/Support/CallSite.h @@ -26,8 +26,8 @@ #ifndef LLVM_SUPPORT_CALLSITE_H #define LLVM_SUPPORT_CALLSITE_H -#include "llvm/Attributes.h" #include "llvm/ADT/PointerIntPair.h" +#include "llvm/Attributes.h" #include "llvm/BasicBlock.h" #include "llvm/CallingConv.h" #include "llvm/Instructions.h" @@ -49,15 +49,10 @@ protected: PointerIntPair I; public: CallSiteBase() : I(0, false) {} - CallSiteBase(CallTy *CI) : I(reinterpret_cast(CI), true) {} - CallSiteBase(InvokeTy *II) : I(reinterpret_cast(II), false) {} + CallSiteBase(CallTy *CI) : I(CI, true) { assert(CI); } + CallSiteBase(InvokeTy *II) : I(II, false) { assert(II); } CallSiteBase(ValTy *II) { *this = get(II); } - CallSiteBase(InstrTy *II) { - assert(II && "Null instruction given?"); - *this = get(II); - assert(I.getPointer()); - } - +protected: /// CallSiteBase::get - This static method is sort of like a constructor. It /// will create an appropriate call site for a Call or Invoke instruction, but /// it can also create a null initialized CallSiteBase object for something @@ -66,13 +61,13 @@ public: static CallSiteBase get(ValTy *V) { if (InstrTy *II = dyn_cast(V)) { if (II->getOpcode() == Instruction::Call) - return CallSiteBase(reinterpret_cast(II)); + return CallSiteBase(static_cast(II)); else if (II->getOpcode() == Instruction::Invoke) - return CallSiteBase(reinterpret_cast(II)); + return CallSiteBase(static_cast(II)); } return CallSiteBase(); } - +public: /// isCall - true if a CallInst is enclosed. /// Note that !isCall() does not mean it is an InvokeInst enclosed, /// it also could signify a NULL Instruction pointer. @@ -86,7 +81,7 @@ public: InstrTy *operator->() const { return I.getPointer(); } operator bool() const { return I.getPointer(); } - /// getCalledValue - Return the pointer to function that is being called... + /// getCalledValue - Return the pointer to function that is being called. /// ValTy *getCalledValue() const { assert(getInstruction() && "Not a call or invoke instruction!"); @@ -100,7 +95,7 @@ public: return dyn_cast(getCalledValue()); } - /// setCalledFunction - Set the callee to the specified value... + /// setCalledFunction - Set the callee to the specified value. /// void setCalledFunction(Value *V) { assert(getInstruction() && "Not a call or invoke instruction!"); @@ -116,13 +111,13 @@ public: ValTy *getArgument(unsigned ArgNo) const { assert(arg_begin() + ArgNo < arg_end() && "Argument # out of range!"); - return *(arg_begin()+ArgNo); + return *(arg_begin() + ArgNo); } void setArgument(unsigned ArgNo, Value* newVal) { assert(getInstruction() && "Not a call or invoke instruction!"); assert(arg_begin() + ArgNo < arg_end() && "Argument # out of range!"); - getInstruction()->setOperand(getArgumentOffset() + ArgNo, newVal); + getInstruction()->setOperand(ArgNo, newVal); } /// Given a value use iterator, returns the argument that corresponds to it. @@ -135,7 +130,7 @@ public: } /// arg_iterator - The type of iterator to use when looping over actual - /// arguments at this call site... + /// arguments at this call site. typedef IterTy arg_iterator; /// arg_begin/arg_end - Return iterators corresponding to the actual argument @@ -143,7 +138,7 @@ public: IterTy arg_begin() const { assert(getInstruction() && "Not a call or invoke instruction!"); // Skip non-arguments - return (*this)->op_begin() + getArgumentOffset(); + return (*this)->op_begin(); } IterTy arg_end() const { return (*this)->op_end() - getArgumentEndOffset(); } @@ -152,7 +147,7 @@ public: /// getType - Return the type of the instruction that generated this call site /// - const Type *getType() const { return (*this)->getType(); } + Type *getType() const { return (*this)->getType(); } /// getCaller - Return the caller function for this call site /// @@ -182,16 +177,21 @@ public: /// getAttributes/setAttributes - get or set the parameter attributes of /// the call. - const AttrListPtr &getAttributes() const { + const AttributeSet &getAttributes() const { CALLSITE_DELEGATE_GETTER(getAttributes()); } - void setAttributes(const AttrListPtr &PAL) { + void setAttributes(const AttributeSet &PAL) { CALLSITE_DELEGATE_SETTER(setAttributes(PAL)); } - /// paramHasAttr - whether the call or the callee has the given attribute. - bool paramHasAttr(uint16_t i, Attributes attr) const { - CALLSITE_DELEGATE_GETTER(paramHasAttr(i, attr)); + /// \brief Return true if this function has the given attribute. + bool hasFnAttr(Attributes::AttrVal A) const { + CALLSITE_DELEGATE_GETTER(hasFnAttr(A)); + } + + /// \brief Return true if the call or the callee has the given attribute. + bool paramHasAttr(unsigned i, Attributes::AttrVal A) const { + CALLSITE_DELEGATE_GETTER(paramHasAttr(i, A)); } /// @brief Extract the alignment for a call or parameter (0=unknown). @@ -204,44 +204,54 @@ public: CALLSITE_DELEGATE_GETTER(isNoInline()); } void setIsNoInline(bool Value = true) { - CALLSITE_DELEGATE_GETTER(setIsNoInline(Value)); + CALLSITE_DELEGATE_SETTER(setIsNoInline(Value)); } - + /// @brief Determine if the call does not access memory. bool doesNotAccessMemory() const { CALLSITE_DELEGATE_GETTER(doesNotAccessMemory()); } - void setDoesNotAccessMemory(bool doesNotAccessMemory = true) { - CALLSITE_DELEGATE_SETTER(setDoesNotAccessMemory(doesNotAccessMemory)); + void setDoesNotAccessMemory() { + CALLSITE_DELEGATE_SETTER(setDoesNotAccessMemory()); } /// @brief Determine if the call does not access or only reads memory. bool onlyReadsMemory() const { CALLSITE_DELEGATE_GETTER(onlyReadsMemory()); } - void setOnlyReadsMemory(bool onlyReadsMemory = true) { - CALLSITE_DELEGATE_SETTER(setOnlyReadsMemory(onlyReadsMemory)); + void setOnlyReadsMemory() { + CALLSITE_DELEGATE_SETTER(setOnlyReadsMemory()); } /// @brief Determine if the call cannot return. bool doesNotReturn() const { CALLSITE_DELEGATE_GETTER(doesNotReturn()); } - void setDoesNotReturn(bool doesNotReturn = true) { - CALLSITE_DELEGATE_SETTER(setDoesNotReturn(doesNotReturn)); + void setDoesNotReturn() { + CALLSITE_DELEGATE_SETTER(setDoesNotReturn()); } /// @brief Determine if the call cannot unwind. bool doesNotThrow() const { CALLSITE_DELEGATE_GETTER(doesNotThrow()); } - void setDoesNotThrow(bool doesNotThrow = true) { - CALLSITE_DELEGATE_SETTER(setDoesNotThrow(doesNotThrow)); + void setDoesNotThrow() { + CALLSITE_DELEGATE_SETTER(setDoesNotThrow()); } #undef CALLSITE_DELEGATE_GETTER #undef CALLSITE_DELEGATE_SETTER + /// @brief Determine whether this argument is not captured. + bool doesNotCapture(unsigned ArgNo) const { + return paramHasAttr(ArgNo + 1, Attributes::NoCapture); + } + + /// @brief Determine whether this argument is passed by value. + bool isByValArgument(unsigned ArgNo) const { + return paramHasAttr(ArgNo + 1, Attributes::ByVal); + } + /// hasArgument - Returns true if this CallSite passes the given Value* as an /// argument to the called function. bool hasArgument(const Value *Arg) const { @@ -253,42 +263,21 @@ public: } private: - /// Returns the operand number of the first argument - unsigned getArgumentOffset() const { - if (isCall()) - return 1; // Skip Function (ATM) - else - return 0; // Args are at the front - } - unsigned getArgumentEndOffset() const { if (isCall()) - return 0; // Unchanged (ATM) + return 1; // Skip Callee else - return 3; // Skip BB, BB, Function + return 3; // Skip BB, BB, Callee } IterTy getCallee() const { - // FIXME: this is slow, since we do not have the fast versions - // of the op_*() functions here. See CallSite::getCallee. - // - if (isCall()) - return getInstruction()->op_begin(); // Unchanged (ATM) - else - return getInstruction()->op_end() - 3; // Skip BB, BB, Function + if (isCall()) // Skip Callee + return cast(getInstruction())->op_end() - 1; + else // Skip BB, BB, Callee + return cast(getInstruction())->op_end() - 3; } }; -/// ImmutableCallSite - establish a view to a call site for examination -class ImmutableCallSite : public CallSiteBase<> { - typedef CallSiteBase<> Base; -public: - ImmutableCallSite(const Value* V) : Base(V) {} - ImmutableCallSite(const CallInst *CI) : Base(CI) {} - ImmutableCallSite(const InvokeInst *II) : Base(II) {} - ImmutableCallSite(const Instruction *II) : Base(II) {} -}; - class CallSite : public CallSiteBase { typedef CallSiteBase { + typedef CallSiteBase<> Base; +public: + ImmutableCallSite(const Value* V) : Base(V) {} + ImmutableCallSite(const CallInst *CI) : Base(CI) {} + ImmutableCallSite(const InvokeInst *II) : Base(II) {} + ImmutableCallSite(const Instruction *II) : Base(II) {} + ImmutableCallSite(CallSite CS) : Base(CS.getInstruction()) {} +}; + } // End llvm namespace #endif