[llvm-commits] [PATCH] Configurable CallSiteBase

Dan Gohman gohman at apple.com
Tue Mar 30 16:46:29 PDT 2010


On Mar 30, 2010, at 3:49 PM, Gabor Greif wrote:

> Am 30.03.2010 um 21:44 schrieb Dan Gohman:
> 
>> 
>> On Mar 30, 2010, at 2:34 AM, Gabor Greif wrote:
>>> 
>>> CallSiteBase now provides three convenience features (some of
>>> them are inherited by CallSite too) :
>>> - operator bool: this conversion allows to check whether we have
>>>  a proper call site. Allows to eliminate an indentation level of
>>>  "if" statements.
>>> - operator ->: gives back the payload as an instruction (InstrTy*)
>>> - constructor from ValueTy: this may supplant the static "get"
>>>  method in the future (ATM it is implementer in terms of "get").
>>>  Anyway, this constructor can be used in "if" statements to
>>>  get rid of a free-standing wide-scope local binding.
>> 
>> Another way to provide this functionality would be to redo the CallSite
>> abstraction as a pseudo-class, following the IntrinsicInst.h example.
>> That way, it could use dyn_cast like everything else instead of its
>> own syntax.
>> 
>> For example, something like this:
>> 
>> class CallSite : public User {
>>   CallSite();                       // DO NOT IMPLEMENT
>>   CallSite(const CallSite &);       // DO NOT IMPLEMENT
>>   void operator=(const CallSite &); // DO NOT IMPLEMENT
>> public:
>>    // ...
>> 
>>    // Methods for support type inquiry through isa, cast, and dyn_cast:
>>    static inline bool classof(const CallSite *) { return true; }
>>    static inline bool classof(const CallInst *I) { return true; }
>>    static inline bool classof(const InvokeInst *I) { return true; }
>>    static inline bool classof(const Value *V) {
>>      return isa<CallInst>(V) || isa<InvokeInst>(V);
>>    }
>> };
> 
> Hmmm, CallSite is supposed to have the weight of a pointer, and the above
> is rather heavy, certainly not "value semantics". I do not like the idea.

It isn't actually heavy. This kind of CallSite would be passed around by
pointer rather than by value, so it would still have the weight of
a pointer. Typical use would be like this:

  if (CallSite *CS = dyn_cast<CallSite>(V)) {
    doStuffWith(CS);
  }

Dan




More information about the llvm-commits mailing list