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
diff --git a/lib/CodeGen/CGCall.cpp b/lib/CodeGen/CGCall.cpp
index 8b5c3a0..f7db0d1 100644
--- a/lib/CodeGen/CGCall.cpp
+++ b/lib/CodeGen/CGCall.cpp
@@ -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));
diff --git a/lib/CodeGen/CGObjCGNU.cpp b/lib/CodeGen/CGObjCGNU.cpp
index 9e999ac..8173aa0 100644
--- a/lib/CodeGen/CGObjCGNU.cpp
+++ b/lib/CodeGen/CGObjCGNU.cpp
@@ -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);
diff --git a/lib/CodeGen/CodeGenFunction.h b/lib/CodeGen/CodeGenFunction.h
index f164cf5..c62d19a 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 @@
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,