[cfe-commits] r102833 - in /cfe/trunk/lib/CodeGen: CGCall.cpp CGObjCGNU.cpp CodeGenFunction.h

Chris Lattner clattner at apple.com
Sat May 1 11:10:35 PDT 2010


On May 1, 2010, at 4:15 AM, David Chisnall wrote:

> Author: theraven
> Date: Sat May  1 06:15:56 2010
> New Revision: 102833
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=102833&view=rev
> Log:
> Tweaked EmitCall() to permit the caller to provide some metadata to attach to the call site.
> 
> Used this in CGObjCGNU to attach metadata about message sends to permit speculative inlining.

Would it make sense to return the created Instruction* by reference, and let the client install the metadata?  If the client wanted to install multiple pieces of metadata or do other things with the call, this would be a more natural interface.  I think this would also simplify some debug info stuff.

-Chris

> 
> 
> Modified:
>    cfe/trunk/lib/CodeGen/CGCall.cpp
>    cfe/trunk/lib/CodeGen/CGObjCGNU.cpp
>    cfe/trunk/lib/CodeGen/CodeGenFunction.h
> 
> Modified: cfe/trunk/lib/CodeGen/CGCall.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=102833&r1=102832&r2=102833&view=diff
> ==============================================================================
> --- cfe/trunk/lib/CodeGen/CGCall.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CGCall.cpp Sat May  1 06:15:56 2010
> @@ -869,7 +869,9 @@
>                                  llvm::Value *Callee,
>                                  ReturnValueSlot ReturnValue,
>                                  const CallArgList &CallArgs,
> -                                 const Decl *TargetDecl) {
> +                                 const Decl *TargetDecl,
> +                                 unsigned MDKind,
> +                                 llvm::MDNode *Metadata) {
>   // FIXME: We no longer need the types from CallArgs; lift up and simplify.
>   llvm::SmallVector<llvm::Value*, 16> Args;
> 
> @@ -995,6 +997,9 @@
>                               Args.data(), Args.data()+Args.size());
>     EmitBlock(Cont);
>   }
> +  if (Metadata) {
> +    CS->setMetadata(MDKind, Metadata);
> +  }
> 
>   CS.setAttributes(Attrs);
>   CS.setCallingConv(static_cast<llvm::CallingConv::ID>(CallingConv));
> 
> Modified: cfe/trunk/lib/CodeGen/CGObjCGNU.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCGNU.cpp?rev=102833&r1=102832&r2=102833&view=diff
> ==============================================================================
> --- cfe/trunk/lib/CodeGen/CGObjCGNU.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CGObjCGNU.cpp Sat May  1 06:15:56 2010
> @@ -539,7 +539,15 @@
>   llvm::Value *imp = CGF.Builder.CreateCall(lookupFunction, lookupArgs,
>       lookupArgs+2);
> 
> -  return CGF.EmitCall(FnInfo, imp, ReturnValueSlot(), ActualArgs);
> +  llvm::Value *impMD[] = {
> +      llvm::MDString::get(VMContext, Sel.getAsString()),
> +      llvm::MDString::get(VMContext, Class->getSuperClass()->getNameAsString()),
> +      llvm::ConstantInt::get(llvm::Type::getInt1Ty(VMContext), IsClassMessage)
> +   };
> +  llvm::MDNode *node = llvm::MDNode::get(VMContext, impMD, 3);
> +
> +  return CGF.EmitCall(FnInfo, imp, ReturnValueSlot(), ActualArgs,
> +          0, msgSendMDKind, node);
> }
> 
> /// Generate code for a message send expression.
> @@ -653,12 +661,6 @@
>     slot->setOnlyReadsMemory();
> 
>     imp = Builder.CreateLoad(Builder.CreateStructGEP(slot, 4));
> -    llvm::Value *impMD[] = {
> -          llvm::MDString::get(VMContext, Sel.getAsString()),
> -          llvm::MDString::get(VMContext, Class ? Class->getNameAsString() :""),
> -     };
> -    llvm::MDNode *node = llvm::MDNode::get(VMContext, impMD, 2);
> -    cast<llvm::Instruction>(imp)->setMetadata(msgSendMDKind, node);
> 
>     // The lookup function may have changed the receiver, so make sure we use
>     // the new one.
> @@ -675,8 +677,15 @@
> 
>     imp = Builder.CreateCall2(lookupFunction, Receiver, cmd);
>   }
> -  RValue msgRet = 
> -      CGF.EmitCall(FnInfo, imp, ReturnValueSlot(), ActualArgs);
> +  llvm::Value *impMD[] = {
> +        llvm::MDString::get(VMContext, Sel.getAsString()),
> +        llvm::MDString::get(VMContext, Class ? Class->getNameAsString() :""),
> +        llvm::ConstantInt::get(llvm::Type::getInt1Ty(VMContext), Class!=0)
> +   };
> +  llvm::MDNode *node = llvm::MDNode::get(VMContext, impMD, 3);
> +
> +  RValue msgRet = CGF.EmitCall(FnInfo, imp, ReturnValueSlot(), ActualArgs,
> +      0, msgSendMDKind, node);
> 
>   if (!isPointerSizedReturn) {
>     CGF.EmitBlock(contiueBB);
> 
> Modified: cfe/trunk/lib/CodeGen/CodeGenFunction.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenFunction.h?rev=102833&r1=102832&r2=102833&view=diff
> ==============================================================================
> --- cfe/trunk/lib/CodeGen/CodeGenFunction.h (original)
> +++ cfe/trunk/lib/CodeGen/CodeGenFunction.h Sat May  1 06:15:56 2010
> @@ -32,6 +32,7 @@
> namespace llvm {
>   class BasicBlock;
>   class LLVMContext;
> +  class MDNode;
>   class Module;
>   class SwitchInst;
>   class Twine;
> @@ -1116,7 +1117,9 @@
>                   llvm::Value *Callee,
>                   ReturnValueSlot ReturnValue,
>                   const CallArgList &Args,
> -                  const Decl *TargetDecl = 0);
> +                  const Decl *TargetDecl = 0,
> +                  unsigned MDKind = 0,
> +                  llvm::MDNode *Metadata = 0);
> 
>   RValue EmitCall(QualType FnType, llvm::Value *Callee,
>                   ReturnValueSlot ReturnValue,
> 
> 
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits





More information about the cfe-commits mailing list