diff options
author | David Chisnall <csdavec@swan.ac.uk> | 2010-05-01 11:15:56 +0000 |
---|---|---|
committer | David Chisnall <csdavec@swan.ac.uk> | 2010-05-01 11:15:56 +0000 |
commit | dd5c98f709837e5dd3da08d44d1ce407975df2cf (patch) | |
tree | 5b53442ade12cab1703622ac8ec42ace1b4706fc | |
parent | afaf0fa8c2a3ec069cef0f895f6bc52cd3fdf8b0 (diff) |
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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@102833 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/CodeGen/CGCall.cpp | 7 | ||||
-rw-r--r-- | lib/CodeGen/CGObjCGNU.cpp | 27 | ||||
-rw-r--r-- | lib/CodeGen/CodeGenFunction.h | 5 |
3 files changed, 28 insertions, 11 deletions
diff --git a/lib/CodeGen/CGCall.cpp b/lib/CodeGen/CGCall.cpp index 8b5c3a0f6c..f7db0d19a2 100644 --- a/lib/CodeGen/CGCall.cpp +++ b/lib/CodeGen/CGCall.cpp @@ -869,7 +869,9 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo, 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 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo, 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)); diff --git a/lib/CodeGen/CGObjCGNU.cpp b/lib/CodeGen/CGObjCGNU.cpp index 9e999ace16..8173aa0425 100644 --- a/lib/CodeGen/CGObjCGNU.cpp +++ b/lib/CodeGen/CGObjCGNU.cpp @@ -539,7 +539,15 @@ CGObjCGNU::GenerateMessageSendSuper(CodeGen::CodeGenFunction &CGF, 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 @@ CGObjCGNU::GenerateMessageSend(CodeGen::CodeGenFunction &CGF, 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 @@ CGObjCGNU::GenerateMessageSend(CodeGen::CodeGenFunction &CGF, 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); diff --git a/lib/CodeGen/CodeGenFunction.h b/lib/CodeGen/CodeGenFunction.h index f164cf5b84..c62d19a7ab 100644 --- a/lib/CodeGen/CodeGenFunction.h +++ b/lib/CodeGen/CodeGenFunction.h @@ -32,6 +32,7 @@ namespace llvm { class BasicBlock; class LLVMContext; + class MDNode; class Module; class SwitchInst; class Twine; @@ -1116,7 +1117,9 @@ public: 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, |