summaryrefslogtreecommitdiffstats
path: root/lib/CodeGen
diff options
context:
space:
mode:
authorDavid Chisnall <csdavec@swan.ac.uk>2012-04-09 15:42:15 +0000
committerDavid Chisnall <csdavec@swan.ac.uk>2012-04-09 15:42:15 +0000
commit649ee3fec12dcf7167630ff88087ad116e9eefa6 (patch)
tree2b788913f6a8820107f5e6a76c9653a5b0ca70f9 /lib/CodeGen
parente2571793ba6fc13e5525b8d7224812f99842a1a4 (diff)
Add -fobjc-trace to emit a call before and after each Objective-C message send
for hooking in code flow visualisation applications. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@154321 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen')
-rw-r--r--lib/CodeGen/CGObjCGNU.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/CodeGen/CGObjCGNU.cpp b/lib/CodeGen/CGObjCGNU.cpp
index db0bd951c1..6cf370f79e 100644
--- a/lib/CodeGen/CGObjCGNU.cpp
+++ b/lib/CodeGen/CGObjCGNU.cpp
@@ -322,6 +322,11 @@ private:
/// Function used for non-object declared property setters.
LazyRuntimeFunction SetStructPropertyFn;
+ /// Function called before message sends, when tracing
+ LazyRuntimeFunction TraceEnterFn;
+ /// Function called after message sends, when tracing
+ LazyRuntimeFunction TraceExitFn;
+
/// The version of the runtime that this class targets. Must match the
/// version in the runtime.
int RuntimeVersion;
@@ -768,6 +773,9 @@ CGObjCGNU::CGObjCGNU(CodeGenModule &cgm, unsigned runtimeABIVersion,
SetStructPropertyFn.init(&CGM, "objc_setPropertyStruct", VoidTy, PtrTy, PtrTy,
PtrDiffTy, BoolTy, BoolTy, NULL);
+ TraceEnterFn.init(&CGM, "objc_trace_enter", VoidTy, IdTy, SelectorTy, NULL);
+ TraceExitFn.init(&CGM, "objc_trace_exit", VoidTy, IdTy, SelectorTy, NULL);
+
// IMP type
llvm::Type *IMPArgs[] = { IdTy, SelectorTy };
IMPTy = llvm::PointerType::getUnqual(llvm::FunctionType::get(IdTy, IMPArgs,
@@ -1212,12 +1220,19 @@ CGObjCGNU::GenerateMessageSend(CodeGenFunction &CGF,
ActualArgs[0] = CallArg(RValue::get(Receiver), ASTIdTy, false);
imp = EnforceType(Builder, imp, MSI.MessengerType);
+ if (CGM.getCodeGenOpts().ObjCTrace) {
+ Builder.CreateCall2(TraceEnterFn, Receiver, cmd);
+ }
llvm::Instruction *call;
RValue msgRet = CGF.EmitCall(MSI.CallInfo, imp, Return, ActualArgs,
0, &call);
call->setMetadata(msgSendMDKind, node);
+ if (CGM.getCodeGenOpts().ObjCTrace) {
+ Builder.CreateCall2(TraceExitFn, Receiver, cmd);
+ }
+
if (!isPointerSizedReturn) {
messageBB = CGF.Builder.GetInsertBlock();