[cfe-commits] r154321 - in /cfe/trunk: include/clang/Driver/CC1Options.td include/clang/Driver/Options.td include/clang/Frontend/CodeGenOptions.h lib/CodeGen/CGObjCGNU.cpp lib/Driver/Tools.cpp lib/Frontend/CompilerInvocation.cpp test/CodeGenObjC/trace.m
Chris Lattner
clattner at apple.com
Mon Apr 9 10:14:34 PDT 2012
On Apr 9, 2012, at 8:42 AM, David Chisnall wrote:
> Author: theraven
> Date: Mon Apr 9 10:42:15 2012
> New Revision: 154321
>
> URL: http://llvm.org/viewvc/llvm-project?rev=154321&view=rev
> Log:
> Add -fobjc-trace to emit a call before and after each Objective-C message send
> for hooking in code flow visualisation applications.
Hi David,
Please revert this, and propose it on cfe-dev.
-Chris
>
>
> Added:
> cfe/trunk/test/CodeGenObjC/trace.m
> Modified:
> cfe/trunk/include/clang/Driver/CC1Options.td
> cfe/trunk/include/clang/Driver/Options.td
> cfe/trunk/include/clang/Frontend/CodeGenOptions.h
> cfe/trunk/lib/CodeGen/CGObjCGNU.cpp
> cfe/trunk/lib/Driver/Tools.cpp
> cfe/trunk/lib/Frontend/CompilerInvocation.cpp
>
> Modified: cfe/trunk/include/clang/Driver/CC1Options.td
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CC1Options.td?rev=154321&r1=154320&r2=154321&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/Driver/CC1Options.td (original)
> +++ cfe/trunk/include/clang/Driver/CC1Options.td Mon Apr 9 10:42:15 2012
> @@ -619,6 +619,8 @@
> HelpText<"Enable Objective-C Ivar layout bitmap print trace">;
> def fobjc_fragile_abi : Flag<"-fobjc-fragile-abi">,
> HelpText<"Use Objective-C's fragile ABI">;
> +def fobjc_trace : Flag<"-fobjc-trace">,
> + HelpText<"Enable tracing of Objective-C message sends">;
> def fno_objc_infer_related_result_type : Flag<
> "-fno-objc-infer-related-result-type">,
> HelpText<
>
> Modified: cfe/trunk/include/clang/Driver/Options.td
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=154321&r1=154320&r2=154321&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/Driver/Options.td (original)
> +++ cfe/trunk/include/clang/Driver/Options.td Mon Apr 9 10:42:15 2012
> @@ -476,6 +476,9 @@
> "-fno-objc-infer-related-result-type">, Group<f_Group>;
> def fobjc_link_runtime: Flag<"-fobjc-link-runtime">, Group<f_Group>;
>
> +def fobjc_trace: Flag<"-fobjc-trace">, Group<f_Group>;
> +def fno_objc_trace: Flag<"-fno-objc-trace">, Group<f_Group>;
> +
> // Objective-C ABI options.
> def fobjc_abi_version_EQ : Joined<"-fobjc-abi-version=">, Group<f_Group>;
> def fobjc_nonfragile_abi_version_EQ : Joined<"-fobjc-nonfragile-abi-version=">, Group<f_Group>;
>
> Modified: cfe/trunk/include/clang/Frontend/CodeGenOptions.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CodeGenOptions.h?rev=154321&r1=154320&r2=154321&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/Frontend/CodeGenOptions.h (original)
> +++ cfe/trunk/include/clang/Frontend/CodeGenOptions.h Mon Apr 9 10:42:15 2012
> @@ -82,6 +82,8 @@
> /// use of the inline keyword.
> unsigned NoNaNsFPMath : 1; /// Assume FP arguments, results not NaN.
> unsigned NoZeroInitializedInBSS : 1; /// -fno-zero-initialized-in-bss
> + unsigned ObjCTrace : 1; /// Emit tracing calls for visualising code
> + /// flow in Objective-C programs
> unsigned ObjCDispatchMethod : 2; /// Method of Objective-C dispatch to use.
> unsigned ObjCRuntimeHasARC : 1; /// The target runtime supports ARC natively
> unsigned ObjCRuntimeHasTerminate : 1; /// The ObjC runtime has objc_terminate
>
> Modified: cfe/trunk/lib/CodeGen/CGObjCGNU.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCGNU.cpp?rev=154321&r1=154320&r2=154321&view=diff
> ==============================================================================
> --- cfe/trunk/lib/CodeGen/CGObjCGNU.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CGObjCGNU.cpp Mon Apr 9 10:42:15 2012
> @@ -322,6 +322,11 @@
> /// 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 @@
> 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 @@
> 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();
>
> Modified: cfe/trunk/lib/Driver/Tools.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=154321&r1=154320&r2=154321&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Driver/Tools.cpp (original)
> +++ cfe/trunk/lib/Driver/Tools.cpp Mon Apr 9 10:42:15 2012
> @@ -2400,6 +2400,10 @@
> CmdArgs.push_back("-fobjc-default-synthesize-properties");
> }
>
> + if (Args.hasFlag(options::OPT_fobjc_trace, options::OPT_fno_objc_trace,
> + false))
> + CmdArgs.push_back("-fobjc-trace");
> +
> // Allow -fno-objc-arr to trump -fobjc-arr/-fobjc-arc.
> // NOTE: This logic is duplicated in ToolChains.cpp.
> bool ARC = isObjCAutoRefCount(Args);
>
> Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/CompilerInvocation.cpp?rev=154321&r1=154320&r2=154321&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Frontend/CompilerInvocation.cpp (original)
> +++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp Mon Apr 9 10:42:15 2012
> @@ -249,6 +249,8 @@
> Res.push_back("-mconstructor-aliases");
> if (Opts.ObjCAutoRefCountExceptions)
> Res.push_back("-fobjc-arc-eh");
> + if (Opts.ObjCTrace)
> + Res.push_back("-fobjc-trace");
> if (!Opts.DebugPass.empty()) {
> Res.push_back("-mdebug-pass", Opts.DebugPass);
> }
> @@ -1109,6 +1111,7 @@
>
> Opts.AsmVerbose = Args.hasArg(OPT_masm_verbose);
> Opts.ObjCAutoRefCountExceptions = Args.hasArg(OPT_fobjc_arc_exceptions);
> + Opts.ObjCTrace = Args.hasArg(OPT_fobjc_trace);
> Opts.ObjCRuntimeHasARC = Args.hasArg(OPT_fobjc_runtime_has_arc);
> Opts.ObjCRuntimeHasTerminate = Args.hasArg(OPT_fobjc_runtime_has_terminate);
> Opts.CUDAIsDevice = Args.hasArg(OPT_fcuda_is_device);
>
> Added: cfe/trunk/test/CodeGenObjC/trace.m
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/trace.m?rev=154321&view=auto
> ==============================================================================
> --- cfe/trunk/test/CodeGenObjC/trace.m (added)
> +++ cfe/trunk/test/CodeGenObjC/trace.m Mon Apr 9 10:42:15 2012
> @@ -0,0 +1,13 @@
> +///RUN: %clang_cc1 -triple x86_64-unknown-freebsd9.0 -fobjc-trace -fgnu-runtime -fobjc-dispatch-method=non-legacy -emit-llvm -o - %s | FileCheck %s
> +
> +
> + at interface A
> ++ (id)msg;
> + at end
> +
> +void f(void) {
> + [A msg];
> + // CHECK: call void @objc_trace_enter(
> + // CHECK: @objc_msgSend
> + // CHECK: call void @objc_trace_exit(
> +}
>
>
> _______________________________________________
> 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