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.

llvm-svn: 102833
This commit is contained in:
David Chisnall 2010-05-01 11:15:56 +00:00
parent 8a855e1f7f
commit 9eecafa480
3 changed files with 28 additions and 11 deletions

View File

@ -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));

View File

@ -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);

View File

@ -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,