Re: [PATCH] D55802: Change CGObjC to use objc intrinsics instead of runtime methods

2019-02-24 Thread Pete Cooper via cfe-commits
Hey David

Thanks for letting me know, and analysing it this far!

I also can't see anything wrong with the intrinsic.  Its just defined as:

def int_objc_autoreleasePoolPop : Intrinsic<[], [llvm_ptr_ty]>;

which (I believe) means it has unmodelled side effects so it should have been 
fine for your example.

I'll try build the same file you did and see if I can reproduce.

Cheers,
Pete

> On Feb 24, 2019, at 7:48 AM, David Chisnall via Phabricator 
>  wrote:
> 
> theraven added a comment.
> Herald added a project: LLVM.
> 
> After some bisection, it appears that this is the revision that introduced 
> the regression in the GNUstep Objective-C runtime test suite that I reported 
> on the list a few weeks ago.  In this is the test (compiled with 
> `-fobjc-runtime=gnustep-2.0 -O3` and an ELF triple):
> 
> https://github.com/gnustep/libobjc2/blob/master/Test/AssociatedObject.m
> 
> After this change, Early CSE w/ MemorySSA is determining that the second load 
> of `deallocCalled` is redundant.  The code goes from:
> 
>%7 = load i1, i1* @deallocCalled, align 1
>br i1 %7, label %8, label %9
> 
>  ; :8:  ; preds = %0
>call void @__assert(i8* getelementptr inbounds ([5 x i8], [5 x i8]* 
> @__func__.main, i64 0, i64 0), i8* getelementptr inbounds ([27 x i8], [27 x 
> i8]* @.str, i64 0, i64 0), i32 26, i8* getelementptr inbounds ([15 x i8], [15 
> x i8]* @.str.1, i64 0, i64 0)) #5
>unreachable
> 
>  ; :9:  ; preds = %0
>call void @llvm.objc.autoreleasePoolPop(i8* %1)
>%10 = load i1, i1* @deallocCalled, align 1
>br i1 %10, label %12, label %11
> 
>  ; :11: ; preds = %9
>call void @__assert(i8* getelementptr inbounds ([5 x i8], [5 x i8]* 
> @__func__.main, i64 0, i64 0), i8* getelementptr inbounds ([27 x i8], [27 x 
> i8]* @.str, i64 0, i64 0), i32 29, i8* getelementptr inbounds ([14 x i8], [14 
> x i8]* @.str.2, i64 0, i64 0)) #5
>unreachable
> 
> to:
> 
>%7 = load i1, i1* @deallocCalled, align 1
>br i1 %7, label %8, label %9
> 
>  ; :8:  ; preds = %0
>call void @__assert(i8* getelementptr inbounds ([5 x i8], [5 x i8]* 
> @__func__.main, i64 0, i64 0), i8* getelementptr inbounds ([27 x i8], [27 x 
> i8]* @.str, i64 0, i64 0), i32 26, i8* getelementptr inbounds ([15 x i8], [15 
> x i8]* @.str.1, i64 0, i64 0)) #5
>unreachable
> 
>  ; :9:  ; preds = %0
>call void @llvm.objc.autoreleasePoolPop(i8* %1)
>br i1 %7, label %11, label %10
> 
>  ; :10: ; preds = %9
>call void @__assert(i8* getelementptr inbounds ([5 x i8], [5 x i8]* 
> @__func__.main, i64 0, i64 0), i8* getelementptr inbounds ([27 x i8], [27 x 
> i8]* @.str, i64 0, i64 0), i32 29, i8* getelementptr inbounds ([14 x i8], [14 
> x i8]* @.str.2, i64 0, i64 0)) #5
>unreachable
> 
> Later optimisations then determine that, because the assert does not return, 
> the only possible value for %7 is false and cause the second assert to fire 
> unconditionally.
> 
> It appears that we are not correctly modelling the side effects of the 
> `llvm.objc.autoreleasePoolPop` intrinsic, but it's not entirely clear why 
> not.  The same test compiled for the macos runtime does not appear to exhibit 
> the same behaviour.  The previous revision, where we emitted a call to 
> `objc_autoreleasePoolPop` and not the intrinsic worked correctly, but with 
> this change the optimisers are assuming that no globals can be modified 
> across an autorelease pool pop operation (at least, in some situations).
> 
> Looking at the definition of the intrinsic, I don't see anything wrong, so I 
> still suspect that there is a MemorySSA bug that this has uncovered, rather 
> than anything wrong in this series of commits.  Any suggestions as to where 
> to look would be appreciated.
> 
> 
> Repository:
>  rL LLVM
> 
> CHANGES SINCE LAST ACTION
>  https://reviews.llvm.org/D55802/new/
> 
> https://reviews.llvm.org/D55802
> 
> 
> 

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r350224 - Only convert objc messages to alloc to objc_alloc if the receiver is a class.

2019-01-02 Thread Pete Cooper via cfe-commits
Author: pete
Date: Wed Jan  2 09:25:30 2019
New Revision: 350224

URL: http://llvm.org/viewvc/llvm-project?rev=350224=rev
Log:
Only convert objc messages to alloc to objc_alloc if the receiver is a class.

r348687 converted [Foo alloc] to objc_alloc(Foo).  However the objc runtime 
method only takes a Class, not an arbitrary pointer.

This makes sure we are messaging a class before we convert these messages.

rdar://problem/46943703

Modified:
cfe/trunk/lib/CodeGen/CGObjC.cpp
cfe/trunk/test/CodeGenObjC/convert-messages-to-runtime-calls.m

Modified: cfe/trunk/lib/CodeGen/CGObjC.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjC.cpp?rev=350224=350223=350224=diff
==
--- cfe/trunk/lib/CodeGen/CGObjC.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjC.cpp Wed Jan  2 09:25:30 2019
@@ -370,7 +370,8 @@ static Optional
 tryGenerateSpecializedMessageSend(CodeGenFunction , QualType ResultType,
   llvm::Value *Receiver,
   const CallArgList& Args, Selector Sel,
-  const ObjCMethodDecl *method) {
+  const ObjCMethodDecl *method,
+  bool isClassMessage) {
   auto  = CGF.CGM;
   if (!CGM.getCodeGenOpts().ObjCConvertMessagesToRuntimeCalls)
 return None;
@@ -378,7 +379,8 @@ tryGenerateSpecializedMessageSend(CodeGe
   auto  = CGM.getLangOpts().ObjCRuntime;
   switch (Sel.getMethodFamily()) {
   case OMF_alloc:
-if (Runtime.shouldUseRuntimeFunctionsForAlloc() &&
+if (isClassMessage &&
+Runtime.shouldUseRuntimeFunctionsForAlloc() &&
 ResultType->isObjCObjectPointerType()) {
 // [Foo alloc] -> objc_alloc(Foo)
 if (Sel.isUnarySelector() && Sel.getNameForSlot(0) == "alloc")
@@ -550,7 +552,8 @@ RValue CodeGenFunction::EmitObjCMessageE
 // Call runtime methods directly if we can.
 if (Optional SpecializedResult =
 tryGenerateSpecializedMessageSend(*this, ResultType, Receiver, 
Args,
-  E->getSelector(), method)) {
+  E->getSelector(), method,
+  isClassMessage)) {
   result = RValue::get(SpecializedResult.getValue());
 } else {
   result = Runtime.GenerateMessageSend(*this, Return, ResultType,

Modified: cfe/trunk/test/CodeGenObjC/convert-messages-to-runtime-calls.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/convert-messages-to-runtime-calls.m?rev=350224=350223=350224=diff
==
--- cfe/trunk/test/CodeGenObjC/convert-messages-to-runtime-calls.m (original)
+++ cfe/trunk/test/CodeGenObjC/convert-messages-to-runtime-calls.m Wed Jan  2 
09:25:30 2019
@@ -54,7 +54,9 @@ void test2(void* x) {
 @class A;
 @interface B
 + (A*) alloc;
-+ (A*)allocWithZone:(void*)zone;
++ (A*) allocWithZone:(void*)zone;
+- (A*) alloc;
+- (A*) allocWithZone:(void*)zone;
 - (A*) retain;
 - (A*) autorelease;
 @end
@@ -79,6 +81,19 @@ A* test_allocWithZone_class_ptr() {
   return [B allocWithZone:nil];
 }
 
+// Only call objc_alloc on a Class, not an instance
+// CHECK-LABEL: define {{.*}}void @test_alloc_instance
+void test_alloc_instance(A *a) {
+  // CALLS: {{call.*@objc_alloc}}
+  // CALLS: {{call.*@objc_allocWithZone}}
+  // CALLS: {{call.*@objc_msgSend}}
+  // CALLS: {{call.*@objc_msgSend}}
+  [A alloc];
+  [A allocWithZone:nil];
+  [a alloc];
+  [a allocWithZone:nil];
+}
+
 // Make sure we get a bitcast on the return type as the
 // call will return i8* which we have to cast to A*
 // CHECK-LABEL: define {{.*}}void @test_retain_class_ptr


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r349952 - Convert some ObjC retain/release msgSends to runtime calls.

2018-12-21 Thread Pete Cooper via cfe-commits
Author: pete
Date: Fri Dec 21 13:00:32 2018
New Revision: 349952

URL: http://llvm.org/viewvc/llvm-project?rev=349952=rev
Log:
Convert some ObjC retain/release msgSends to runtime calls.

It is faster to directly call the ObjC runtime for methods such as 
retain/release instead of sending a message to those functions.

Differential Revision: https://reviews.llvm.org/D55869

Reviewed By: rjmccall

Modified:
cfe/trunk/include/clang/Basic/ObjCRuntime.h
cfe/trunk/lib/CodeGen/CGObjC.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/lib/CodeGen/CodeGenModule.h
cfe/trunk/test/CodeGenObjC/convert-messages-to-runtime-calls.m

Modified: cfe/trunk/include/clang/Basic/ObjCRuntime.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/ObjCRuntime.h?rev=349952=349951=349952=diff
==
--- cfe/trunk/include/clang/Basic/ObjCRuntime.h (original)
+++ cfe/trunk/include/clang/Basic/ObjCRuntime.h Fri Dec 21 13:00:32 2018
@@ -173,6 +173,43 @@ public:
 llvm_unreachable("bad kind");
   }
 
+  /// Does this runtime provide ARC entrypoints that are likely to be faster
+  /// than an ordinary message send of the appropriate selector?
+  ///
+  /// The ARC entrypoints are guaranteed to be equivalent to just sending the
+  /// corresponding message.  If the entrypoint is implemented naively as just 
a
+  /// message send, using it is a trade-off: it sacrifices a few cycles of
+  /// overhead to save a small amount of code.  However, it's possible for
+  /// runtimes to detect and special-case classes that use "standard"
+  /// retain/release behavior; if that's dynamically a large proportion of all
+  /// retained objects, using the entrypoint will also be faster than using a
+  /// message send.
+  ///
+  /// When this method returns true, Clang will turn non-super message sends of
+  /// certain selectors into calls to the correspond entrypoint:
+  ///   retain => objc_retain
+  ///   release => objc_release
+  ///   autorelease => objc_autorelease
+  bool shouldUseARCFunctionsForRetainRelease() const {
+switch (getKind()) {
+case FragileMacOSX:
+  return false;
+case MacOSX:
+  return getVersion() >= VersionTuple(10, 10);
+case iOS:
+  return getVersion() >= VersionTuple(8);
+case WatchOS:
+  return true;
+case GCC:
+  return false;
+case GNUstep:
+  return false;
+case ObjFW:
+  return false;
+}
+llvm_unreachable("bad kind");
+  }
+
   /// Does this runtime provide entrypoints that are likely to be faster
   /// than an ordinary message send of the "alloc" selector?
   ///

Modified: cfe/trunk/lib/CodeGen/CGObjC.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjC.cpp?rev=349952=349951=349952=diff
==
--- cfe/trunk/lib/CodeGen/CGObjC.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjC.cpp Fri Dec 21 13:00:32 2018
@@ -396,6 +396,29 @@ tryGenerateSpecializedMessageSend(CodeGe
 }
 break;
 
+  case OMF_autorelease:
+if (ResultType->isObjCObjectPointerType() &&
+CGM.getLangOpts().getGC() == LangOptions::NonGC &&
+Runtime.shouldUseARCFunctionsForRetainRelease())
+  return CGF.EmitObjCAutorelease(Receiver, CGF.ConvertType(ResultType));
+break;
+
+  case OMF_retain:
+if (ResultType->isObjCObjectPointerType() &&
+CGM.getLangOpts().getGC() == LangOptions::NonGC &&
+Runtime.shouldUseARCFunctionsForRetainRelease())
+  return CGF.EmitObjCRetainNonBlock(Receiver, CGF.ConvertType(ResultType));
+break;
+
+  case OMF_release:
+if (ResultType->isVoidType() &&
+CGM.getLangOpts().getGC() == LangOptions::NonGC &&
+Runtime.shouldUseARCFunctionsForRetainRelease()) {
+  CGF.EmitObjCRelease(Receiver, ARCPreciseLifetime);
+  return nullptr;
+}
+break;
+
   default:
 break;
   }
@@ -2006,6 +2029,11 @@ static llvm::Value *emitObjCValueOperati
 llvm::FunctionType *fnType =
   llvm::FunctionType::get(CGF.Int8PtrTy, CGF.Int8PtrTy, false);
 fn = CGF.CGM.CreateRuntimeFunction(fnType, fnName);
+
+// We have Native ARC, so set nonlazybind attribute for performance
+if (llvm::Function *f = dyn_cast(fn))
+  if (fnName == "objc_retain")
+f->addFnAttr(llvm::Attribute::NonLazyBind);
   }
 
   // Cast the argument to 'id'.
@@ -2510,6 +2538,55 @@ void CodeGenFunction::emitARCIntrinsicUs
   CGF.EmitARCIntrinsicUse(value);
 }
 
+/// Autorelease the given object.
+///   call i8* \@objc_autorelease(i8* %value)
+llvm::Value *CodeGenFunction::EmitObjCAutorelease(llvm::Value *value,
+  llvm::Type *returnType) {
+  return emitObjCValueOperation(*this, value, returnType,
+  CGM.getObjCEntrypoints().objc_autoreleaseRuntimeFunction,
+"objc_autorelease");
+}
+
+/// Retain the 

r349782 - Use @llvm.objc.clang.arc.use intrinsic instead of clang.arc.use function.

2018-12-20 Thread Pete Cooper via cfe-commits
Author: pete
Date: Thu Dec 20 10:05:41 2018
New Revision: 349782

URL: http://llvm.org/viewvc/llvm-project?rev=349782=rev
Log:
Use @llvm.objc.clang.arc.use intrinsic instead of clang.arc.use function.

Calls to this function are deleted in the ARC optimizer.  However when the ARC
optimizer was updated to use intrinsics instead of functions (r349534), the 
corresponding
clang change (r349535) to use intrinsics missed this one so it wasn't being 
deleted.

Modified:
cfe/trunk/lib/CodeGen/CGObjC.cpp
cfe/trunk/test/CodeGenObjC/arc-blocks.m
cfe/trunk/test/CodeGenObjC/arc-foreach.m
cfe/trunk/test/CodeGenObjC/arc-literals.m
cfe/trunk/test/CodeGenObjC/arc-ternary-op.m
cfe/trunk/test/CodeGenObjC/arc.m
cfe/trunk/test/CodeGenObjC/os_log.m
cfe/trunk/test/CodeGenObjCXX/arc.mm

Modified: cfe/trunk/lib/CodeGen/CGObjC.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjC.cpp?rev=349782=349781=349782=diff
==
--- cfe/trunk/lib/CodeGen/CGObjC.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjC.cpp Thu Dec 20 10:05:41 2018
@@ -1862,11 +1862,8 @@ llvm::Value *CodeGenFunction::EmitObjCEx
 /// being intrinsically used up until this point in the program.
 void CodeGenFunction::EmitARCIntrinsicUse(ArrayRef values) {
   llvm::Constant * = CGM.getObjCEntrypoints().clang_arc_use;
-  if (!fn) {
-llvm::FunctionType *fnType =
-  llvm::FunctionType::get(CGM.VoidTy, None, true);
-fn = CGM.CreateRuntimeFunction(fnType, "clang.arc.use");
-  }
+  if (!fn)
+fn = CGM.getIntrinsic(llvm::Intrinsic::objc_clang_arc_use);
 
   // This isn't really a "runtime" function, but as an intrinsic it
   // doesn't really matter as long as we align things up.

Modified: cfe/trunk/test/CodeGenObjC/arc-blocks.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/arc-blocks.m?rev=349782=349781=349782=diff
==
--- cfe/trunk/test/CodeGenObjC/arc-blocks.m (original)
+++ cfe/trunk/test/CodeGenObjC/arc-blocks.m Thu Dec 20 10:05:41 2018
@@ -96,7 +96,7 @@ void test3(void (^sink)(id*)) {
   // CHECK-NEXT: call void [[F1]](i8* [[BLOCK]], i8** [[TEMP]])
   // CHECK-NEXT: [[T0:%.*]] = load i8*, i8** [[TEMP]]
   // CHECK-NEXT: [[T1:%.*]] = call i8* @llvm.objc.retain(i8* [[T0]])
-  // CHECK-NEXT: call void (...) @clang.arc.use(i8* [[V]]) [[NUW]]
+  // CHECK-NEXT: call void (...) @llvm.objc.clang.arc.use(i8* [[V]]) [[NUW]]
   // CHECK-NEXT: [[T2:%.*]] = load i8*, i8** [[STRONG]]
   // CHECK-NEXT: store i8* [[T1]], i8** [[STRONG]]
   // CHECK-NEXT: call void @llvm.objc.release(i8* [[T2]])
@@ -303,7 +303,7 @@ void test7(void) {
 // CHECK-NEXT: bitcast [[BLOCK_T]]* [[BLOCK]] to
 // CHECK: call void @test8_helper(
 // CHECK-NEXT: [[T2:%.*]] = load [[TEST8]]*, [[TEST8]]** [[D0]]
-// CHECK-NEXT: call void (...) @clang.arc.use([[TEST8]]* [[T2]])
+// CHECK-NEXT: call void (...) @llvm.objc.clang.arc.use([[TEST8]]* [[T2]])
 // CHECK: ret void
 
   extern void test8_helper(void (^)(void));
@@ -712,7 +712,7 @@ void test19(void (^b)(void)) {
 // CHECK: [[CAPTURED:%.*]] = load i8*, i8** [[XADDR]]
 // CHECK: store i8* [[CAPTURED]], i8** [[BLOCKCAPTURED]]
 // CHECK: [[CAPTURE:%.*]] = load i8*, i8** [[CAPTUREFIELD]]
-// CHECK-NEXT: call void (...) @clang.arc.use(i8* [[CAPTURE]])
+// CHECK-NEXT: call void (...) @llvm.objc.clang.arc.use(i8* [[CAPTURE]])
 // CHECK-NEXT: [[X:%.*]] = load i8*, i8** [[XADDR]]
 // CHECK-NEXT: call void @llvm.objc.release(i8* [[X]])
 // CHECK-NEXT: ret void

Modified: cfe/trunk/test/CodeGenObjC/arc-foreach.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/arc-foreach.m?rev=349782=349781=349782=diff
==
--- cfe/trunk/test/CodeGenObjC/arc-foreach.m (original)
+++ cfe/trunk/test/CodeGenObjC/arc-foreach.m Thu Dec 20 10:05:41 2018
@@ -73,11 +73,11 @@ void test0(NSArray *array) {
 // CHECK-LP64-NEXT: [[BLOCK1:%.*]] = bitcast [[BLOCK_T]]* [[BLOCK]]
 // CHECK-LP64-NEXT: call void @use_block(void ()* [[BLOCK1]])
 // CHECK-LP64-NEXT: call void @llvm.objc.storeStrong(i8** [[D0]], i8* null)
-// CHECK-LP64-NOT:  call void (...) @clang.arc.use(i8* [[CAPTURE]])
+// CHECK-LP64-NOT:  call void (...) @llvm.objc.clang.arc.use(i8* [[CAPTURE]])
 
 // CHECK-LP64-OPT: [[D0:%.*]] = getelementptr inbounds [[BLOCK_T]], 
[[BLOCK_T]]* [[BLOCK]], i64 0, i32 5
 // CHECK-LP64-OPT: [[CAPTURE:%.*]] = load i8*, i8** [[D0]]
-// CHECK-LP64-OPT: call void (...) @clang.arc.use(i8* [[CAPTURE]])
+// CHECK-LP64-OPT: call void (...) @llvm.objc.clang.arc.use(i8* [[CAPTURE]])
 
 // CHECK-LP64:  [[T0:%.*]] = load i8*, i8** @OBJC_SELECTOR_REFERENCES_
 // CHECK-LP64-NEXT: [[T1:%.*]] = bitcast [[ARRAY_T]]* [[SAVED_ARRAY]] to i8*
@@ -220,14 +220,14 @@ NSArray *array4;
 
 // CHECK-LP64: [[T5:%.*]] = bitcast [[TY]]** [[T0]] to i8**
 // CHECK-LP64: call void 

r348687 - Convert some ObjC msgSends to runtime calls.

2018-12-07 Thread Pete Cooper via cfe-commits
Author: pete
Date: Fri Dec  7 21:13:50 2018
New Revision: 348687

URL: http://llvm.org/viewvc/llvm-project?rev=348687=rev
Log:
Convert some ObjC msgSends to runtime calls.

It is faster to directly call the ObjC runtime for methods such as 
alloc/allocWithZone instead of sending a message to those functions.

This patch adds support for converting messages to alloc/allocWithZone to their 
equivalent runtime calls.

Tests included for the positive case of applying this transformation, negative 
tests that we ensure we only convert "alloc" to objc_alloc, not "alloc2", and 
also a driver test to ensure we enable this only for supported runtime versions.

Reviewed By: rjmccall

https://reviews.llvm.org/D55349

Added:
cfe/trunk/test/CodeGenObjC/convert-messages-to-runtime-calls.m
cfe/trunk/test/Driver/objc-convert-messages-to-runtime-calls.m
Modified:
cfe/trunk/include/clang/Basic/ObjCRuntime.h
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/include/clang/Frontend/CodeGenOptions.def
cfe/trunk/lib/CodeGen/CGObjC.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/lib/CodeGen/CodeGenModule.h
cfe/trunk/lib/Driver/ToolChains/Clang.cpp
cfe/trunk/lib/Frontend/CompilerInvocation.cpp

Modified: cfe/trunk/include/clang/Basic/ObjCRuntime.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/ObjCRuntime.h?rev=348687=348686=348687=diff
==
--- cfe/trunk/include/clang/Basic/ObjCRuntime.h (original)
+++ cfe/trunk/include/clang/Basic/ObjCRuntime.h Fri Dec  7 21:13:50 2018
@@ -173,6 +173,43 @@ public:
 llvm_unreachable("bad kind");
   }
 
+  /// Does this runtime provide entrypoints that are likely to be faster
+  /// than an ordinary message send of the "alloc" selector?
+  ///
+  /// The "alloc" entrypoint is guaranteed to be equivalent to just sending the
+  /// corresponding message.  If the entrypoint is implemented naively as just 
a
+  /// message send, using it is a trade-off: it sacrifices a few cycles of
+  /// overhead to save a small amount of code.  However, it's possible for
+  /// runtimes to detect and special-case classes that use "standard"
+  /// alloc behavior; if that's dynamically a large proportion of all
+  /// objects, using the entrypoint will also be faster than using a message
+  /// send.
+  ///
+  /// When this method returns true, Clang will turn non-super message sends of
+  /// certain selectors into calls to the corresponding entrypoint:
+  ///   alloc => objc_alloc
+  ///   allocWithZone:nil => objc_allocWithZone
+  bool shouldUseRuntimeFunctionsForAlloc() const {
+switch (getKind()) {
+case FragileMacOSX:
+  return false;
+case MacOSX:
+  return getVersion() >= VersionTuple(10, 10);
+case iOS:
+  return getVersion() >= VersionTuple(8);
+case WatchOS:
+  return true;
+
+case GCC:
+  return false;
+case GNUstep:
+  return false;
+case ObjFW:
+  return false;
+}
+llvm_unreachable("bad kind");
+  }
+
   /// Does this runtime supports optimized setter entrypoints?
   bool hasOptimizedSetter() const {
 switch (getKind()) {

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=348687=348686=348687=diff
==
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Fri Dec  7 21:13:50 2018
@@ -1473,6 +1473,10 @@ def fno_zero_initialized_in_bss : Flag<[
 def fobjc_arc : Flag<["-"], "fobjc-arc">, Group, Flags<[CC1Option]>,
   HelpText<"Synthesize retain and release calls for Objective-C pointers">;
 def fno_objc_arc : Flag<["-"], "fno-objc-arc">, Group;
+def fobjc_convert_messages_to_runtime_calls :
+  Flag<["-"], "fobjc-convert-messages-to-runtime-calls">, Group;
+def fno_objc_convert_messages_to_runtime_calls :
+  Flag<["-"], "fno-objc-convert-messages-to-runtime-calls">, Group, 
Flags<[CC1Option]>;
 def fobjc_arc_exceptions : Flag<["-"], "fobjc-arc-exceptions">, 
Group, Flags<[CC1Option]>,
   HelpText<"Use EH-safe code when synthesizing retains and releases in 
-fobjc-arc">;
 def fno_objc_arc_exceptions : Flag<["-"], "fno-objc-arc-exceptions">, 
Group;

Modified: cfe/trunk/include/clang/Frontend/CodeGenOptions.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CodeGenOptions.def?rev=348687=348686=348687=diff
==
--- cfe/trunk/include/clang/Frontend/CodeGenOptions.def (original)
+++ cfe/trunk/include/clang/Frontend/CodeGenOptions.def Fri Dec  7 21:13:50 2018
@@ -149,6 +149,8 @@ CODEGENOPT(UniformWGSize , 1, 0) ///
 CODEGENOPT(NoZeroInitializedInBSS , 1, 0) ///< -fno-zero-initialized-in-bss.
 /// Method of Objective-C dispatch to use.
 ENUM_CODEGENOPT(ObjCDispatchMethod, 

r348431 - Fix title underlines being too short after r348429

2018-12-05 Thread Pete Cooper via cfe-commits
Author: pete
Date: Wed Dec  5 16:01:44 2018
New Revision: 348431

URL: http://llvm.org/viewvc/llvm-project?rev=348431=rev
Log:
Fix title underlines being too short after r348429

Modified:
cfe/trunk/docs/AutomaticReferenceCounting.rst

Modified: cfe/trunk/docs/AutomaticReferenceCounting.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/AutomaticReferenceCounting.rst?rev=348431=348430=348431=diff
==
--- cfe/trunk/docs/AutomaticReferenceCounting.rst (original)
+++ cfe/trunk/docs/AutomaticReferenceCounting.rst Wed Dec  5 16:01:44 2018
@@ -2285,7 +2285,7 @@ block exactly as if it had been sent the
 .. _arc.runtime.objc_storeStrong:
 
 ``void objc_storeStrong(id *object, id value);``
---
+
 
 *Precondition:* ``object`` is a valid pointer to a ``__strong`` object which is
 adequately aligned for a pointer.  ``value`` is null or a pointer to a valid


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r348429 - Update ARC docs as objc_storeStrong returns void not id

2018-12-05 Thread Pete Cooper via cfe-commits
Author: pete
Date: Wed Dec  5 15:49:52 2018
New Revision: 348429

URL: http://llvm.org/viewvc/llvm-project?rev=348429=rev
Log:
Update ARC docs as objc_storeStrong returns void not id

Modified:
cfe/trunk/docs/AutomaticReferenceCounting.rst

Modified: cfe/trunk/docs/AutomaticReferenceCounting.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/AutomaticReferenceCounting.rst?rev=348429=348428=348429=diff
==
--- cfe/trunk/docs/AutomaticReferenceCounting.rst (original)
+++ cfe/trunk/docs/AutomaticReferenceCounting.rst Wed Dec  5 15:49:52 2018
@@ -2284,7 +2284,7 @@ block exactly as if it had been sent the
 
 .. _arc.runtime.objc_storeStrong:
 
-``id objc_storeStrong(id *object, id value);``
+``void objc_storeStrong(id *object, id value);``
 --
 
 *Precondition:* ``object`` is a valid pointer to a ``__strong`` object which is


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r268385 - [Clang][avx512][Builtin] Adding intrinsics for cvtw2mask{128|256|512} instruction set

2016-05-03 Thread Pete Cooper via cfe-commits
Hi Michael

I was seeing issues with the CHECK lines referencing explicit value numbers.  
i.e., %1, %2, etc.

In r268416 I changed these to use a regex.  I hope this was ok.  Please let me 
know if you have an alternative you would prefer.

Thanks,
Pete
> On May 3, 2016, at 7:12 AM, Michael Zuckerman via cfe-commits 
>  wrote:
> 
> Author: mzuckerm
> Date: Tue May  3 09:12:23 2016
> New Revision: 268385
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=268385=rev
> Log:
> [Clang][avx512][Builtin] Adding intrinsics for cvtw2mask{128|256|512} 
> instruction set
> 
> Differential Revision: http://reviews.llvm.org/D19766
> 
> Modified:
>cfe/trunk/include/clang/Basic/BuiltinsX86.def
>cfe/trunk/lib/Headers/avx512bwintrin.h
>cfe/trunk/lib/Headers/avx512vlbwintrin.h
>cfe/trunk/test/CodeGen/avx512bw-builtins.c
>cfe/trunk/test/CodeGen/avx512vlbw-builtins.c
> 
> Modified: cfe/trunk/include/clang/Basic/BuiltinsX86.def
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsX86.def?rev=268385=268384=268385=diff
> ==
> --- cfe/trunk/include/clang/Basic/BuiltinsX86.def (original)
> +++ cfe/trunk/include/clang/Basic/BuiltinsX86.def Tue May  3 09:12:23 2016
> @@ -2256,6 +2256,9 @@ TARGET_BUILTIN(__builtin_ia32_vcvtph2ps_
> TARGET_BUILTIN(__builtin_ia32_vcvtph2ps256_mask, "V8fV8sV8fUc","","avx512vl")
> TARGET_BUILTIN(__builtin_ia32_vcvtps2ph_mask, "V8sV4fIiV8sUc","","avx512vl")
> TARGET_BUILTIN(__builtin_ia32_vcvtps2ph256_mask, 
> "V8sV8fIiV8sUc","","avx512vl")
> +TARGET_BUILTIN(__builtin_ia32_cvtw2mask512, "UiV32s","","avx512bw")
> +TARGET_BUILTIN(__builtin_ia32_cvtw2mask128, "UcV8s","","avx512bw,avx512vl")
> +TARGET_BUILTIN(__builtin_ia32_cvtw2mask256, "UsV16s","","avx512bw,avx512vl")
> 
> #undef BUILTIN
> #undef TARGET_BUILTIN
> 
> Modified: cfe/trunk/lib/Headers/avx512bwintrin.h
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/avx512bwintrin.h?rev=268385=268384=268385=diff
> ==
> --- cfe/trunk/lib/Headers/avx512bwintrin.h (original)
> +++ cfe/trunk/lib/Headers/avx512bwintrin.h Tue May  3 09:12:23 2016
> @@ -2063,6 +2063,12 @@ _mm512_movepi8_mask (__m512i __A)
>   return (__mmask64) __builtin_ia32_cvtb2mask512 ((__v64qi) __A);
> }
> 
> +static __inline__ __mmask32 __DEFAULT_FN_ATTRS
> +_mm512_movepi16_mask (__m512i __A)
> +{
> +  return (__mmask32) __builtin_ia32_cvtw2mask512 ((__v32hi) __A);
> +}
> +
> static __inline__ __m512i __DEFAULT_FN_ATTRS
> _mm512_movm_epi8 (__mmask64 __A)
> {
> 
> Modified: cfe/trunk/lib/Headers/avx512vlbwintrin.h
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/avx512vlbwintrin.h?rev=268385=268384=268385=diff
> ==
> --- cfe/trunk/lib/Headers/avx512vlbwintrin.h (original)
> +++ cfe/trunk/lib/Headers/avx512vlbwintrin.h Tue May  3 09:12:23 2016
> @@ -3181,6 +3181,18 @@ _mm256_movepi8_mask (__m256i __A)
>   return (__mmask32) __builtin_ia32_cvtb2mask256 ((__v32qi) __A);
> }
> 
> +static __inline__ __mmask8 __DEFAULT_FN_ATTRS
> +_mm_movepi16_mask (__m128i __A)
> +{
> +  return (__mmask8) __builtin_ia32_cvtw2mask128 ((__v8hi) __A);
> +}
> +
> +static __inline__ __mmask16 __DEFAULT_FN_ATTRS
> +_mm256_movepi16_mask (__m256i __A)
> +{
> +  return (__mmask16) __builtin_ia32_cvtw2mask256 ((__v16hi) __A);
> +}
> +
> static __inline__ __m128i __DEFAULT_FN_ATTRS
> _mm_movm_epi8 (__mmask16 __A)
> {
> 
> Modified: cfe/trunk/test/CodeGen/avx512bw-builtins.c
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/avx512bw-builtins.c?rev=268385=268384=268385=diff
> ==
> --- cfe/trunk/test/CodeGen/avx512bw-builtins.c (original)
> +++ cfe/trunk/test/CodeGen/avx512bw-builtins.c Tue May  3 09:12:23 2016
> @@ -1530,3 +1530,10 @@ __m512i test_mm512_sad_epu8(__m512i __A,
>   // CHECK: @llvm.x86.avx512.psad.bw.512
>   return _mm512_sad_epu8(__A, __B); 
> }
> +
> +__mmask32 test_mm512_movepi16_mask(__m512i __A) {
> +  // CHECK-LABEL: @test_mm512_movepi16_mask
> +  // CHECK: @llvm.x86.avx512.cvtw2mask.512
> +  return _mm512_movepi16_mask(__A); 
> +}
> +
> 
> Modified: cfe/trunk/test/CodeGen/avx512vlbw-builtins.c
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/avx512vlbw-builtins.c?rev=268385=268384=268385=diff
> ==
> --- cfe/trunk/test/CodeGen/avx512vlbw-builtins.c (original)
> +++ cfe/trunk/test/CodeGen/avx512vlbw-builtins.c Tue May  3 09:12:23 2016
> @@ -2375,3 +2375,15 @@ __m256i test_mm256_maskz_dbsad_epu8(__mm
>   // CHECK: @llvm.x86.avx512.mask.dbpsadbw.256
>   return _mm256_maskz_dbsad_epu8(__U, __A, __B, 170); 
> }
> +__mmask8 test_mm_movepi16_mask(__m128i __A) {
> +  // CHECK-LABEL: 

r268416 - Change test to use regex instead of explicit value numbers. NFC.

2016-05-03 Thread Pete Cooper via cfe-commits
Author: pete
Date: Tue May  3 13:32:01 2016
New Revision: 268416

URL: http://llvm.org/viewvc/llvm-project?rev=268416=rev
Log:
Change test to use regex instead of explicit value numbers.  NFC.

We were seeing an internal failure when running this test.  I can't
see a good reason for the difference, but the simple fix is to use
%{{.*}} instead of %1.

Modified:
cfe/trunk/test/CodeGen/avx512f-builtins.c

Modified: cfe/trunk/test/CodeGen/avx512f-builtins.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/avx512f-builtins.c?rev=268416=268415=268416=diff
==
--- cfe/trunk/test/CodeGen/avx512f-builtins.c (original)
+++ cfe/trunk/test/CodeGen/avx512f-builtins.c Tue May  3 13:32:01 2016
@@ -5591,25 +5591,25 @@ __m256i test_mm512_maskz_cvttpd_epu32(__
 
 __m512d test_mm512_castpd128_pd512(__m128d __A) {
   // CHECK-LABEL: @test_mm512_castpd128_pd512
-  // CHECK: shufflevector <2 x double> %1, <2 x double> %2, <8 x i32> 
+  // CHECK: shufflevector <2 x double> %{{.*}}, <2 x double> %{{.*}}, <8 x 
i32> 
   return _mm512_castpd128_pd512(__A); 
 }
 
 __m512 test_mm512_castps128_ps512(__m128 __A) {
   // CHECK-LABEL: @test_mm512_castps128_ps512
-  // CHECK: shufflevector <4 x float> %1, <4 x float> %2, <16 x i32> 
+  // CHECK: shufflevector <4 x float> %{{.*}}, <4 x float> %{{.*}}, <16 x i32> 

   return _mm512_castps128_ps512(__A); 
 }
 
 __m512i test_mm512_castsi128_si512(__m128i __A) {
   // CHECK-LABEL: @test_mm512_castsi128_si512
-  // CHECK: shufflevector <2 x i64> %1, <2 x i64> %2, <8 x i32> 
+  // CHECK: shufflevector <2 x i64> %{{.*}}, <2 x i64> %{{.*}}, <8 x i32> 
   return _mm512_castsi128_si512(__A); 
 }
 
 __m512i test_mm512_castsi256_si512(__m256i __A) {
   // CHECK-LABEL: @test_mm512_castsi256_si512
-  // CHECK: shufflevector <4 x i64> %1, <4 x i64> %2, <8 x i32> 
+  // CHECK: shufflevector <4 x i64> %{{.*}}, <4 x i64> %{{.*}}, <8 x i32> 
   return _mm512_castsi256_si512(__A); 
 }
 


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r268055 - Recommitted r264281 "Supporting all entities declared in lexical scope in LLVM debug info."

2016-04-29 Thread Pete Cooper via cfe-commits

> On Apr 29, 2016, at 10:27 AM, Aboud, Amjad  wrote:
> 
> Sorry for that, I broke a LIT test that I added few days ago.
> The LIT test need to be fixed and I already fixed it in r268063.
No problem.  Thanks for the quick reply.
>  
> Let’s wait till r268063 run bots and see that everything will pass.
Sounds good, thanks.  I’ll keep an eye on the bots.

Thanks,
Pete
>   <>
> Thanks,
> Amjad
>  <>From: peter_coo...@apple.com [mailto:peter_coo...@apple.com] 
> Sent: Friday, April 29, 2016 19:53
> To: Aboud, Amjad 
> Cc: cfe-commits@lists.llvm.org
> Subject: Re: r268055 - Recommitted r264281 "Supporting all entities declared 
> in lexical scope in LLVM debug info."
>  
> Hi Amjad
>  
> Either this change, or r268054, appears to have broken the bots.  Can you 
> please take a look?
>  
> The error at: 
> http://lab.llvm.org:8080/green/job/clang-stage1-cmake-RA-incremental_check/22409/consoleFull#8333002949ba4694-19c4-4d7e-bec5-911270d8a58c
>  
> 
>  
> Thanks,
> Pete
> On Apr 29, 2016, at 9:08 AM, Amjad Aboud via cfe-commits 
> > wrote:
>  
> Author: aaboud
> Date: Fri Apr 29 11:08:08 2016
> New Revision: 268055
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=268055=rev 
> 
> Log:
> Recommitted r264281 "Supporting all entities declared in lexical scope in 
> LLVM debug info."
> After fixing PR26942 in r267004.
> 
> Added:
>cfe/trunk/test/CodeGenCXX/debug-info-lb.cpp
> Modified:
>cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
>cfe/trunk/lib/CodeGen/CGDebugInfo.h
>cfe/trunk/lib/CodeGen/CGDecl.cpp
>cfe/trunk/test/CodeGenCXX/debug-info-anon-union-vars.cpp
> 
> Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=268055=268054=268055=diff
>  
> 
> ==
> --- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Fri Apr 29 11:08:08 2016
> @@ -814,15 +814,18 @@ llvm::DIType *CGDebugInfo::CreateType(co
> 
> llvm::DIType *CGDebugInfo::CreateType(const TypedefType *Ty,
>   llvm::DIFile *Unit) {
> +  TypedefNameDecl *TD = Ty->getDecl();
>   // We don't set size information, but do specify where the typedef was
>   // declared.
> -  SourceLocation Loc = Ty->getDecl()->getLocation();
> +  SourceLocation Loc = TD->getLocation();
> +
> +  llvm::DIScope *TDContext = getDeclarationLexicalScope(*TD, QualType(Ty, 
> 0));
> 
>   // Typedefs are derived from some other type.
>   return DBuilder.createTypedef(
>   getOrCreateType(Ty->getDecl()->getUnderlyingType(), Unit),
>   Ty->getDecl()->getName(), getOrCreateFile(Loc), getLineNumber(Loc),
> -  getDeclContextDescriptor(Ty->getDecl()));
> +  TDContext);
> }
> 
> llvm::DIType *CGDebugInfo::CreateType(const FunctionType *Ty,
> @@ -1457,6 +1460,23 @@ llvm::DIType *CGDebugInfo::getOrCreateSt
>   return T;
> }
> 
> +void CGDebugInfo::recordDeclarationLexicalScope(const Decl ) {
> +  assert(LexicalBlockMap.find() == LexicalBlockMap.end() &&
> + "D is already mapped to lexical block scope");
> +  if (!LexicalBlockStack.empty())
> +LexicalBlockMap[] = LexicalBlockStack.back();
> +}
> +
> +llvm::DIScope *CGDebugInfo::getDeclarationLexicalScope(const Decl ,
> +   QualType Ty) {
> +  auto I = LexicalBlockMap.find();
> +  if (I != LexicalBlockMap.end()) {
> +RetainedTypes.push_back(Ty.getAsOpaquePtr());
> +return I->second;
> +  }
> +  return getDeclContextDescriptor(cast());
> +}
> +
> void CGDebugInfo::completeType(const EnumDecl *ED) {
>   if (DebugKind <= codegenoptions::DebugLineTablesOnly)
> return;
> @@ -2060,7 +2080,7 @@ llvm::DIType *CGDebugInfo::CreateEnumTyp
> // entered into the ReplaceMap: finalize() will replace the first
> // FwdDecl with the second and then replace the second with
> // complete type.
> -llvm::DIScope *EDContext = getDeclContextDescriptor(ED);
> +llvm::DIScope *EDContext = getDeclarationLexicalScope(*ED, QualType(Ty, 
> 0));
> llvm::DIFile *DefUnit = getOrCreateFile(ED->getLocation());
> llvm::TempDIScope TmpContext(DBuilder.createReplaceableCompositeType(
> llvm::dwarf::DW_TAG_enumeration_type, "", TheCU, DefUnit, 0));
> @@ -2104,7 +2124,7 @@ llvm::DIType *CGDebugInfo::CreateTypeDef
> 
>   llvm::DIFile *DefUnit = getOrCreateFile(ED->getLocation());
>   unsigned Line = getLineNumber(ED->getLocation());
> -  llvm::DIScope *EnumContext = getDeclContextDescriptor(ED);
> +  llvm::DIScope *EnumContext 

Re: r268055 - Recommitted r264281 "Supporting all entities declared in lexical scope in LLVM debug info."

2016-04-29 Thread Pete Cooper via cfe-commits
Hi Amjad

Either this change, or r268054, appears to have broken the bots.  Can you 
please take a look?

The error at: 
http://lab.llvm.org:8080/green/job/clang-stage1-cmake-RA-incremental_check/22409/consoleFull#8333002949ba4694-19c4-4d7e-bec5-911270d8a58c
 


Thanks,
Pete
> On Apr 29, 2016, at 9:08 AM, Amjad Aboud via cfe-commits 
>  wrote:
> 
> Author: aaboud
> Date: Fri Apr 29 11:08:08 2016
> New Revision: 268055
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=268055=rev
> Log:
> Recommitted r264281 "Supporting all entities declared in lexical scope in 
> LLVM debug info."
> After fixing PR26942 in r267004.
> 
> Added:
>cfe/trunk/test/CodeGenCXX/debug-info-lb.cpp
> Modified:
>cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
>cfe/trunk/lib/CodeGen/CGDebugInfo.h
>cfe/trunk/lib/CodeGen/CGDecl.cpp
>cfe/trunk/test/CodeGenCXX/debug-info-anon-union-vars.cpp
> 
> Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=268055=268054=268055=diff
> ==
> --- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Fri Apr 29 11:08:08 2016
> @@ -814,15 +814,18 @@ llvm::DIType *CGDebugInfo::CreateType(co
> 
> llvm::DIType *CGDebugInfo::CreateType(const TypedefType *Ty,
>   llvm::DIFile *Unit) {
> +  TypedefNameDecl *TD = Ty->getDecl();
>   // We don't set size information, but do specify where the typedef was
>   // declared.
> -  SourceLocation Loc = Ty->getDecl()->getLocation();
> +  SourceLocation Loc = TD->getLocation();
> +
> +  llvm::DIScope *TDContext = getDeclarationLexicalScope(*TD, QualType(Ty, 
> 0));
> 
>   // Typedefs are derived from some other type.
>   return DBuilder.createTypedef(
>   getOrCreateType(Ty->getDecl()->getUnderlyingType(), Unit),
>   Ty->getDecl()->getName(), getOrCreateFile(Loc), getLineNumber(Loc),
> -  getDeclContextDescriptor(Ty->getDecl()));
> +  TDContext);
> }
> 
> llvm::DIType *CGDebugInfo::CreateType(const FunctionType *Ty,
> @@ -1457,6 +1460,23 @@ llvm::DIType *CGDebugInfo::getOrCreateSt
>   return T;
> }
> 
> +void CGDebugInfo::recordDeclarationLexicalScope(const Decl ) {
> +  assert(LexicalBlockMap.find() == LexicalBlockMap.end() &&
> + "D is already mapped to lexical block scope");
> +  if (!LexicalBlockStack.empty())
> +LexicalBlockMap[] = LexicalBlockStack.back();
> +}
> +
> +llvm::DIScope *CGDebugInfo::getDeclarationLexicalScope(const Decl ,
> +   QualType Ty) {
> +  auto I = LexicalBlockMap.find();
> +  if (I != LexicalBlockMap.end()) {
> +RetainedTypes.push_back(Ty.getAsOpaquePtr());
> +return I->second;
> +  }
> +  return getDeclContextDescriptor(cast());
> +}
> +
> void CGDebugInfo::completeType(const EnumDecl *ED) {
>   if (DebugKind <= codegenoptions::DebugLineTablesOnly)
> return;
> @@ -2060,7 +2080,7 @@ llvm::DIType *CGDebugInfo::CreateEnumTyp
> // entered into the ReplaceMap: finalize() will replace the first
> // FwdDecl with the second and then replace the second with
> // complete type.
> -llvm::DIScope *EDContext = getDeclContextDescriptor(ED);
> +llvm::DIScope *EDContext = getDeclarationLexicalScope(*ED, QualType(Ty, 
> 0));
> llvm::DIFile *DefUnit = getOrCreateFile(ED->getLocation());
> llvm::TempDIScope TmpContext(DBuilder.createReplaceableCompositeType(
> llvm::dwarf::DW_TAG_enumeration_type, "", TheCU, DefUnit, 0));
> @@ -2104,7 +2124,7 @@ llvm::DIType *CGDebugInfo::CreateTypeDef
> 
>   llvm::DIFile *DefUnit = getOrCreateFile(ED->getLocation());
>   unsigned Line = getLineNumber(ED->getLocation());
> -  llvm::DIScope *EnumContext = getDeclContextDescriptor(ED);
> +  llvm::DIScope *EnumContext = getDeclarationLexicalScope(*ED, QualType(Ty, 
> 0));
>   llvm::DIType *ClassTy =
>   ED->isFixed() ? getOrCreateType(ED->getIntegerType(), DefUnit) : 
> nullptr;
>   return DBuilder.createEnumerationType(EnumContext, ED->getName(), DefUnit,
> @@ -2365,7 +2385,7 @@ llvm::DICompositeType *CGDebugInfo::Crea
>   unsigned Line = getLineNumber(RD->getLocation());
>   StringRef RDName = getClassName(RD);
> 
> -  llvm::DIScope *RDContext = getDeclContextDescriptor(RD);
> +  llvm::DIScope *RDContext = getDeclarationLexicalScope(*RD, QualType(Ty, 
> 0));
> 
>   // If we ended up creating the type during the context chain construction,
>   // just return that.
> @@ -2536,8 +2556,15 @@ void CGDebugInfo::collectVarDeclProps(co
>   if (DC->isRecord())
> DC = CGM.getContext().getTranslationUnitDecl();
> 
> - llvm::DIScope *Mod = getParentModuleOrNull(VD);
> - VDContext = getContextDescriptor(cast(DC), Mod ? Mod : TheCU);
> +  if 

r263984 - Revert "Convert some ObjC msgSends to runtime calls."

2016-03-21 Thread Pete Cooper via cfe-commits
Author: pete
Date: Mon Mar 21 15:50:03 2016
New Revision: 263984

URL: http://llvm.org/viewvc/llvm-project?rev=263984=rev
Log:
Revert "Convert some ObjC msgSends to runtime calls."

This reverts commit r263607.

This change caused more objc_retain/objc_release calls in the IR but those
are then incorrectly optimized by the ARC optimizer.  Work is going to have
to be done to ensure the ARC optimizer doesn't optimize user written RR, but
that should land before this change.

This change will also need to be updated to take account for any changes 
required
to ensure that user written calls to RR are distinct from those inserted by ARC.

Removed:
cfe/trunk/test/CodeGenObjC/convert-messages-to-runtime-calls.m
cfe/trunk/test/Driver/objc-convert-messages-to-runtime-calls.m
Modified:
cfe/trunk/include/clang/Basic/ObjCRuntime.h
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/include/clang/Frontend/CodeGenOptions.def
cfe/trunk/lib/CodeGen/CGObjC.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/lib/CodeGen/CodeGenModule.h
cfe/trunk/lib/Driver/Tools.cpp
cfe/trunk/lib/Frontend/CompilerInvocation.cpp

Modified: cfe/trunk/include/clang/Basic/ObjCRuntime.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/ObjCRuntime.h?rev=263984=263983=263984=diff
==
--- cfe/trunk/include/clang/Basic/ObjCRuntime.h (original)
+++ cfe/trunk/include/clang/Basic/ObjCRuntime.h Mon Mar 21 15:50:03 2016
@@ -171,79 +171,6 @@ public:
 llvm_unreachable("bad kind");
   }
 
-  /// Does this runtime provide ARC entrypoints that are likely to be faster
-  /// than an ordinary message send of the appropriate selector?
-  ///
-  /// The ARC entrypoints are guaranteed to be equivalent to just sending the
-  /// corresponding message.  If the entrypoint is implemented naively as just 
a
-  /// message send, using it is a trade-off: it sacrifices a few cycles of
-  /// overhead to save a small amount of code.  However, it's possible for
-  /// runtimes to detect and special-case classes that use "standard"
-  /// retain/release behavior; if that's dynamically a large proportion of all
-  /// retained objects, using the entrypoint will also be faster than using a
-  /// message send.
-  ///
-  /// When this method returns true, Clang will turn non-super message sends of
-  /// certain selectors into calls to the correspond entrypoint:
-  ///   retain => objc_retain
-  ///   release => objc_release
-  bool shouldUseARCFunctionsForRetainRelease() const {
-switch (getKind()) {
-case FragileMacOSX:
-  return false;
-case MacOSX:
-  return getVersion() >= VersionTuple(10, 10);
-case iOS:
-  return getVersion() >= VersionTuple(8);
-case WatchOS:
-  return true;
-
-case GCC:
-  return false;
-case GNUstep:
-  return false;
-case ObjFW:
-  return false;
-}
-llvm_unreachable("bad kind");
-  }
-
-  /// Does this runtime provide entrypoints that are likely to be faster
-  /// than an ordinary message send of the "alloc" selector?
-  ///
-  /// The "alloc" entrypoint is guaranteed to be equivalent to just sending the
-  /// corresponding message.  If the entrypoint is implemented naively as just 
a
-  /// message send, using it is a trade-off: it sacrifices a few cycles of
-  /// overhead to save a small amount of code.  However, it's possible for
-  /// runtimes to detect and special-case classes that use "standard"
-  /// alloc behavior; if that's dynamically a large proportion of all
-  /// objects, using the entrypoint will also be faster than using a message
-  /// send.
-  ///
-  /// When this method returns true, Clang will turn non-super message sends of
-  /// certain selectors into calls to the correspond entrypoint:
-  ///   alloc => objc_alloc
-  bool shouldUseRuntimeFunctionsForAlloc() const {
-switch (getKind()) {
-case FragileMacOSX:
-  return false;
-case MacOSX:
-  return getVersion() >= VersionTuple(10, 10);
-case iOS:
-  return getVersion() >= VersionTuple(8);
-case WatchOS:
-  return true;
-
-case GCC:
-  return false;
-case GNUstep:
-  return false;
-case ObjFW:
-  return false;
-}
-llvm_unreachable("bad kind");
-  }
-
   /// \brief Does this runtime supports optimized setter entrypoints?
   bool hasOptimizedSetter() const {
 switch (getKind()) {

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=263984=263983=263984=diff
==
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Mon Mar 21 15:50:03 2016
@@ -933,10 +933,6 @@ def fno_zero_initialized_in_bss : Flag<[
 def fobjc_arc : Flag<["-"], "fobjc-arc">, Group, Flags<[CC1Option]>,
   

Re: [PATCH] D14737: Convert some ObjC msgSends to runtime calls

2016-03-15 Thread Pete Cooper via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL263607: Convert some ObjC msgSends to runtime calls. 
(authored by pete).

Changed prior to commit:
  http://reviews.llvm.org/D14737?vs=50651=50785#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D14737

Files:
  cfe/trunk/include/clang/Basic/ObjCRuntime.h
  cfe/trunk/include/clang/Driver/Options.td
  cfe/trunk/include/clang/Frontend/CodeGenOptions.def
  cfe/trunk/lib/CodeGen/CGObjC.cpp
  cfe/trunk/lib/CodeGen/CodeGenFunction.h
  cfe/trunk/lib/CodeGen/CodeGenModule.h
  cfe/trunk/lib/Driver/Tools.cpp
  cfe/trunk/lib/Frontend/CompilerInvocation.cpp
  cfe/trunk/test/CodeGenObjC/convert-messages-to-runtime-calls.m
  cfe/trunk/test/Driver/objc-convert-messages-to-runtime-calls.m

Index: cfe/trunk/lib/CodeGen/CGObjC.cpp
===
--- cfe/trunk/lib/CodeGen/CGObjC.cpp
+++ cfe/trunk/lib/CodeGen/CGObjC.cpp
@@ -338,6 +338,69 @@
   return nullptr;
 }
 
+/// The ObjC runtime may provide entrypoints that are likely to be faster
+/// than an ordinary message send of the appropriate selector.
+///
+/// The entrypoints are guaranteed to be equivalent to just sending the
+/// corresponding message.  If the entrypoint is implemented naively as just a
+/// message send, using it is a trade-off: it sacrifices a few cycles of
+/// overhead to save a small amount of code.  However, it's possible for
+/// runtimes to detect and special-case classes that use "standard"
+/// retain/release behavior; if that's dynamically a large proportion of all
+/// retained objects, using the entrypoint will also be faster than using a
+/// message send.
+///
+/// If the runtime does support a required entrypoint, then this method will
+/// generate a call and return the resulting value.  Otherwise it will return
+/// None and the caller can generate a msgSend instead.
+static Optional
+tryGenerateSpecializedMessageSend(CodeGenFunction , QualType ResultType,
+  llvm::Value *Receiver, Selector Sel,
+  const ObjCMethodDecl *method) {
+  auto  = CGF.CGM;
+  if (!CGM.getCodeGenOpts().ObjCConvertMessagesToRuntimeCalls)
+return None;
+
+  auto  = CGM.getLangOpts().ObjCRuntime;
+  switch (Sel.getMethodFamily()) {
+  case OMF_alloc:
+// Make sure the name is exactly 'alloc'.  All methods with that
+// prefix are identified as OMF_alloc but we only want to call the
+// runtime for this version.
+if (Runtime.shouldUseRuntimeFunctionsForAlloc() && Sel.isUnarySelector() &&
+Sel.getNameForSlot(0) == "alloc" &&
+ResultType->isObjCObjectPointerType())
+  return CGF.EmitObjCAlloc(Receiver, CGF.ConvertType(ResultType));
+break;
+
+  case OMF_autorelease:
+if (ResultType->isObjCObjectPointerType() &&
+CGM.getLangOpts().getGC() == LangOptions::NonGC &&
+Runtime.shouldUseARCFunctionsForRetainRelease())
+  return CGF.EmitARCAutorelease(Receiver, CGF.ConvertType(ResultType));
+break;
+
+  case OMF_retain:
+if (ResultType->isObjCObjectPointerType() &&
+CGM.getLangOpts().getGC() == LangOptions::NonGC &&
+Runtime.shouldUseARCFunctionsForRetainRelease())
+  return CGF.EmitARCRetainNonBlock(Receiver, CGF.ConvertType(ResultType));
+break;
+
+  case OMF_release:
+if (ResultType->isVoidType() &&
+CGM.getLangOpts().getGC() == LangOptions::NonGC &&
+Runtime.shouldUseARCFunctionsForRetainRelease()) {
+  CGF.EmitARCRelease(Receiver, ARCPreciseLifetime);
+  return nullptr;
+}
+break;
+  default:
+break;
+  }
+  return None;
+}
+
 RValue CodeGenFunction::EmitObjCMessageExpr(const ObjCMessageExpr *E,
 ReturnValueSlot Return) {
   // Only the lookup mechanism and first two arguments of the method
@@ -460,10 +523,16 @@
   Args,
   method);
   } else {
-result = Runtime.GenerateMessageSend(*this, Return, ResultType,
- E->getSelector(),
- Receiver, Args, OID,
- method);
+// Call runtime methods directly if we can.
+if (Optional SpecializedResult =
+tryGenerateSpecializedMessageSend(*this, ResultType, Receiver,
+  E->getSelector(), method)) {
+  result = RValue::get(SpecializedResult.getValue());
+} else {
+  result = Runtime.GenerateMessageSend(*this, Return, ResultType,
+   E->getSelector(), Receiver, Args,
+   OID, method);
+}
   }
 
   // For delegate init calls in ARC, implicitly store the result of
@@ -1814,6 +1883,7 @@
 /// where a null input causes a no-op and returns null.
 static llvm::Value 

r263607 - Convert some ObjC msgSends to runtime calls.

2016-03-15 Thread Pete Cooper via cfe-commits
Author: pete
Date: Tue Mar 15 19:33:21 2016
New Revision: 263607

URL: http://llvm.org/viewvc/llvm-project?rev=263607=rev
Log:
Convert some ObjC msgSends to runtime calls.

It is faster to directly call the ObjC runtime for methods such as 
retain/release instead of sending a message to those functions.

This patch adds support for converting messages to 
retain/release/alloc/autorelease to their equivalent runtime calls.

Tests included for the positive case of applying this transformation, negative 
tests that we ensure we only convert "alloc" to objc_alloc, not "alloc2", and 
also a driver test to ensure we enable this only for supported runtime versions.

Reviewed by John McCall.

Differential Revision: http://reviews.llvm.org/D14737

Added:
cfe/trunk/test/CodeGenObjC/convert-messages-to-runtime-calls.m
cfe/trunk/test/Driver/objc-convert-messages-to-runtime-calls.m
Modified:
cfe/trunk/include/clang/Basic/ObjCRuntime.h
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/include/clang/Frontend/CodeGenOptions.def
cfe/trunk/lib/CodeGen/CGObjC.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/lib/CodeGen/CodeGenModule.h
cfe/trunk/lib/Driver/Tools.cpp
cfe/trunk/lib/Frontend/CompilerInvocation.cpp

Modified: cfe/trunk/include/clang/Basic/ObjCRuntime.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/ObjCRuntime.h?rev=263607=263606=263607=diff
==
--- cfe/trunk/include/clang/Basic/ObjCRuntime.h (original)
+++ cfe/trunk/include/clang/Basic/ObjCRuntime.h Tue Mar 15 19:33:21 2016
@@ -171,6 +171,79 @@ public:
 llvm_unreachable("bad kind");
   }
 
+  /// Does this runtime provide ARC entrypoints that are likely to be faster
+  /// than an ordinary message send of the appropriate selector?
+  ///
+  /// The ARC entrypoints are guaranteed to be equivalent to just sending the
+  /// corresponding message.  If the entrypoint is implemented naively as just 
a
+  /// message send, using it is a trade-off: it sacrifices a few cycles of
+  /// overhead to save a small amount of code.  However, it's possible for
+  /// runtimes to detect and special-case classes that use "standard"
+  /// retain/release behavior; if that's dynamically a large proportion of all
+  /// retained objects, using the entrypoint will also be faster than using a
+  /// message send.
+  ///
+  /// When this method returns true, Clang will turn non-super message sends of
+  /// certain selectors into calls to the correspond entrypoint:
+  ///   retain => objc_retain
+  ///   release => objc_release
+  bool shouldUseARCFunctionsForRetainRelease() const {
+switch (getKind()) {
+case FragileMacOSX:
+  return false;
+case MacOSX:
+  return getVersion() >= VersionTuple(10, 10);
+case iOS:
+  return getVersion() >= VersionTuple(8);
+case WatchOS:
+  return true;
+
+case GCC:
+  return false;
+case GNUstep:
+  return false;
+case ObjFW:
+  return false;
+}
+llvm_unreachable("bad kind");
+  }
+
+  /// Does this runtime provide entrypoints that are likely to be faster
+  /// than an ordinary message send of the "alloc" selector?
+  ///
+  /// The "alloc" entrypoint is guaranteed to be equivalent to just sending the
+  /// corresponding message.  If the entrypoint is implemented naively as just 
a
+  /// message send, using it is a trade-off: it sacrifices a few cycles of
+  /// overhead to save a small amount of code.  However, it's possible for
+  /// runtimes to detect and special-case classes that use "standard"
+  /// alloc behavior; if that's dynamically a large proportion of all
+  /// objects, using the entrypoint will also be faster than using a message
+  /// send.
+  ///
+  /// When this method returns true, Clang will turn non-super message sends of
+  /// certain selectors into calls to the correspond entrypoint:
+  ///   alloc => objc_alloc
+  bool shouldUseRuntimeFunctionsForAlloc() const {
+switch (getKind()) {
+case FragileMacOSX:
+  return false;
+case MacOSX:
+  return getVersion() >= VersionTuple(10, 10);
+case iOS:
+  return getVersion() >= VersionTuple(8);
+case WatchOS:
+  return true;
+
+case GCC:
+  return false;
+case GNUstep:
+  return false;
+case ObjFW:
+  return false;
+}
+llvm_unreachable("bad kind");
+  }
+
   /// \brief Does this runtime supports optimized setter entrypoints?
   bool hasOptimizedSetter() const {
 switch (getKind()) {

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=263607=263606=263607=diff
==
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Tue Mar 15 19:33:21 2016
@@ -933,6 +933,10 @@ def 

Re: [PATCH] D14737: Convert some ObjC msgSends to runtime calls

2016-03-15 Thread Pete Cooper via cfe-commits
pete added a comment.

In http://reviews.llvm.org/D14737#375739, @rjmccall wrote:

> Ah, okay, if you changed it to cast explicitly, that's all I was concerned 
> about.


Cool.  Thanks.  Any other concerns or does this look good to you?


http://reviews.llvm.org/D14737



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D14737: Convert some ObjC msgSends to runtime calls

2016-03-15 Thread Pete Cooper via cfe-commits
pete added a comment.

In http://reviews.llvm.org/D14737#375735, @rjmccall wrote:

> Can you find where that bitcast is being added?  I know that different parts 
> of IRGen are differently sensitive to types — it's possible that the return 
> code is one of those more-permissive places.


Sure, will do.

I should say that the bit cast here is my doing.  I should have said that I 
added code to emitARCValueOperation which optionally takes a return type to 
cast to, instead of always casting to the receiver type as you noted it was 
doing before.  But as you point out, even without that change, the IR is still 
getting bit casts when needed.


http://reviews.llvm.org/D14737



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D14737: Convert some ObjC msgSends to runtime calls

2016-03-14 Thread Pete Cooper via cfe-commits
pete updated this revision to Diff 50651.
pete added a comment.

Thanks for the example John.  I understand what you mean now.

I've added this piece to the test case which verifies that the following IR has 
the correct bit cast in it.  Similarly added cases for alloc and autorelease.

@class A;
@interface B

- (A*) retain;

@end

A* test_retain_class_ptr(B *b) {

  return [b retain];

}

define %1* @test_retain_class_ptr(%2* %b) #0 {
entry:

  %b.addr = alloca %2*, align 8
  store %2* %b, %2** %b.addr, align 8
  %0 = load %2*, %2** %b.addr, align 8
  %1 = bitcast %2* %0 to i8*
  %2 = call i8* @objc_retain(i8* %1) #2
  %3 = bitcast i8* %2 to %1*
  ret %1* %3

}


http://reviews.llvm.org/D14737

Files:
  include/clang/Basic/ObjCRuntime.h
  include/clang/Driver/Options.td
  include/clang/Frontend/CodeGenOptions.def
  lib/CodeGen/CGObjC.cpp
  lib/CodeGen/CodeGenFunction.h
  lib/CodeGen/CodeGenModule.h
  lib/Driver/Tools.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/CodeGenObjC/convert-messages-to-runtime-calls.m
  test/Driver/objc-convert-messages-to-runtime-calls.m

Index: test/Driver/objc-convert-messages-to-runtime-calls.m
===
--- /dev/null
+++ test/Driver/objc-convert-messages-to-runtime-calls.m
@@ -0,0 +1,7 @@
+// RUN: %clang %s -### -o %t.o 2>&1 -fsyntax-only -fobjc-convert-messages-to-runtime-calls -fno-objc-convert-messages-to-runtime-calls -target x86_64-apple-macosx10.10.0 | FileCheck  %s --check-prefix=DISABLE
+// RUN: %clang %s -### -o %t.o 2>&1 -fsyntax-only -fno-objc-convert-messages-to-runtime-calls -fobjc-convert-messages-to-runtime-calls -target x86_64-apple-macosx10.10.0 | FileCheck  %s --check-prefix=ENABLE
+
+// Check that we pass fobjc-convert-messages-to-runtime-calls only when supported, and not explicitly disabled.
+
+// DISABLE: "-fno-objc-convert-messages-to-runtime-calls"
+// ENABLE-NOT: "-fno-objc-convert-messages-to-runtime-calls"
Index: test/CodeGenObjC/convert-messages-to-runtime-calls.m
===
--- /dev/null
+++ test/CodeGenObjC/convert-messages-to-runtime-calls.m
@@ -0,0 +1,129 @@
+// RUN: %clang_cc1 -fobjc-runtime=macosx-10.10.0 -emit-llvm -o - %s -fno-objc-convert-messages-to-runtime-calls | FileCheck %s --check-prefix=MSGS
+// RUN: %clang_cc1 -fobjc-runtime=macosx-10.10.0 -emit-llvm -o - %s | FileCheck %s --check-prefix=CALLS
+// RUN: %clang_cc1 -fobjc-runtime=macosx-10.9.0 -emit-llvm -o - %s | FileCheck %s --check-prefix=MSGS
+// RUN: %clang_cc1 -fobjc-runtime=macosx-fragile-10.10.0 -emit-llvm -o - %s | FileCheck %s --check-prefix=MSGS
+// Make sure we don't do calls to retain/release when using GC.
+// RUN: %clang_cc1 -fobjc-runtime=macosx-10.10.0 -emit-llvm -o - %s -fobjc-gc | FileCheck %s --check-prefix=GC
+// RUN: %clang_cc1 -fobjc-runtime=ios-8.0 -emit-llvm -o - %s | FileCheck %s --check-prefix=CALLS
+// RUN: %clang_cc1 -fobjc-runtime=ios-7.0 -emit-llvm -o - %s | FileCheck %s --check-prefix=MSGS
+// Note: This line below is for tvos for which the driver passes through to use the ios9.0 runtime.
+// RUN: %clang_cc1 -fobjc-runtime=ios-9.0 -emit-llvm -o - %s | FileCheck %s --check-prefix=CALLS
+// RUN: %clang_cc1 -fobjc-runtime=watchos-2.0 -emit-llvm -o - %s | FileCheck %s --check-prefix=CALLS
+
+@interface NSObject
++ (id)alloc;
++ (id)alloc2;
+- (id)init;
+- (id)retain;
+- (void)release;
+- (id)autorelease;
+@end
+
+@interface NSString : NSObject
++ (void)retain_self;
+- (void)retain_super;
+@end
+
+// CHECK-LABEL: define {{.*}}void @test1
+void test1(id x) {
+  // MSGS: {{call.*@objc_msgSend}}
+  // MSGS: {{call.*@objc_msgSend}}
+  // MSGS: {{call.*@objc_msgSend}}
+  // MSGS: {{call.*@objc_msgSend}}
+  // CALLS: {{call.*@objc_alloc}}
+  // CALLS: {{call.*@objc_retain}}
+  // CALLS: {{call.*@objc_release}}
+  // CALLS: {{call.*@objc_autorelease}}
+  // GC: {{call.*@objc_alloc}}
+  // GC: {{call.*@objc_msgSend}}
+  // GC: {{call.*@objc_msgSend}}
+  // GC: {{call.*@objc_msgSend}}
+  [NSObject alloc];
+  [x retain];
+  [x release];
+  [x autorelease];
+}
+
+// CHECK-LABEL: define {{.*}}void @test2
+void test2() {
+  // MSGS: {{call.*@objc_msgSend}}
+  // CALLS: {{call.*@objc_msgSend}}
+  // GC: {{call.*@objc_msgSend}}
+  // Make sure alloc has the correct name and number of types.
+  [NSObject alloc2];
+}
+
+@class A;
+@interface B
++ (A*) alloc;
+- (A*) retain;
+- (A*) autorelease;
+@end
+
+// Make sure we get a bitcast on the return type as the
+// call will return i8* which we have to cast to A*
+// CHECK-LABEL: define {{.*}}void @test_alloc_class_ptr
+A* test_alloc_class_ptr() {
+  // CALLS: {{call.*@objc_alloc}}
+  // CALLS-NEXT: bitcast i8*
+  // CALLS-NEXT: ret
+  return [B alloc];
+}
+
+// Make sure we get a bitcast on the return type as the
+// call will return i8* which we have to cast to A*
+// CHECK-LABEL: define {{.*}}void @test_retain_class_ptr
+A* test_retain_class_ptr(B *b) {
+  // CALLS: {{call.*@objc_retain}}
+  // CALLS-NEXT: 

Re: [PATCH] D14737: Convert some ObjC msgSends to runtime calls

2016-03-11 Thread Pete Cooper via cfe-commits
pete added a comment.

Hi John

Sorry, getting back to this after way too long!

In http://reviews.llvm.org/D14737#294218, @rjmccall wrote:

> In http://reviews.llvm.org/D14737#293967, @pete wrote:
>
> > Added a couple of tests for retain returning types other than id.  
> > Returning a pointer should still be converted to a call, while returning a 
> > non-pointer such as float will get a message instead.
> >
> > I walked through the code in the debugger to check on the return cast.  
> > Turns out it is handled at the very end of emitARCValueOperation as follows:
> >
> >  
> >   // Cast the result back to the original type.
> >   return CGF.Builder.CreateBitCast(call, origType);
>
>
> Right, that'll cast back to the original type.  That will be the type of the 
> receiver of the message, which is not necessarily the type of the result of 
> the message.


I stepped through this one in the debugger to make sure I had it right.

So the reason the bit cast ends up not being needed is because we restricted 
this optimization to cases where the result type "isObjCObjectPointerType()" 
which conveniently ends up begin i8* and is exactly the same type as the 
message receiver.  I guess if either the receiver type or the result type 
wasn't represented as i8* then the IRBuilder would have crashed.

If we permitted converting say messaging (int*)retain to a call to objc_retain 
then the bit cast would be needed.  Would you like me to permit this change on 
functions returning anything other than isObjCObjectPointerType(), eg, change 
that to "isAnyPointerType()"?

Cheers,
Pete


http://reviews.llvm.org/D14737



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D16821: Add whole-program vtable optimization feature to Clang.

2016-02-22 Thread Pete Cooper via cfe-commits

> On Feb 22, 2016, at 1:30 PM, Peter Collingbourne  wrote:
> 
> One thing that I'd like to do (and this would help CFI as well) is to 
> specifically recognize cases like this:
> 
> ```
> struct B {
>  virtual void vf();
> };
> 
> struct D1 {
> };
I assume you meant D1 : B here?
> 
> struct D2 : B {
>  virtual void vf();
> };
> 
> void f(D1 *d) {
>  d->vf();
> }
> ```
> 
> In this case I'd like to devirtualize the virtual call in `f()` to `B::vf()`. 
> But because the implicit cast to `B` in `f()` removes the information that 
> `d` cannot be of type `D2`, we cannot eliminate `D2::vf()` as a candidate 
> target (see also `test/cfi/sibling.cpp` in the CFI test suite).
> 
> Although this could possibly be emitted and pattern matched at the IR level, 
> it seems simpler (and would probably catch enough cases) to have Clang look 
> through the implicit cast when IR gen'ing for the call.
So my devirtualizer dealt with this by marking each call site with the most 
specific class we know of in the hierarchy.  

In this case, then class hierarchy would contain the pairs: (B, B), (D1, B), 
(D2, B).

The call site in f() would be tagged with (D1, B) not (B, B).  Then, when we 
are in the pass, we look at the subclasses from (D1, B), see that there are 
none (or that none override vf), and devirtualize to B::vf().

If that isn’t possible in the current solution (I didn’t check), then it should 
be easy enough to add.  I certainly don’t think any of the current 
implementation would be hard to adapt to support this use case.

Cheers,
Pete



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D16821: Add whole-program vtable optimization feature to Clang.

2016-02-05 Thread Pete Cooper via cfe-commits
pete added a comment.

Sorry I haven't got to this sooner.  I'll try review what I can over the next 
day or two.

Saying that, i'm not experienced enough in the clang codebase to give a LGTM.  
I can comment on style, but someone else will need to give the final ok.


http://reviews.llvm.org/D16821



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D14737: Convert some ObjC msgSends to runtime calls

2015-11-20 Thread Pete Cooper via cfe-commits
pete updated this revision to Diff 40790.
pete added a comment.

Added a couple of tests for retain returning types other than id.  Returning a 
pointer should still be converted to a call, while returning a non-pointer such 
as float will get a message instead.

I walked through the code in the debugger to check on the return cast.  Turns 
out it is handled at the very end of emitARCValueOperation as follows:

  // Cast the result back to the original type.
  return CGF.Builder.CreateBitCast(call, origType);


http://reviews.llvm.org/D14737

Files:
  include/clang/Basic/ObjCRuntime.h
  include/clang/Driver/Options.td
  include/clang/Frontend/CodeGenOptions.def
  lib/CodeGen/CGObjC.cpp
  lib/CodeGen/CodeGenFunction.h
  lib/CodeGen/CodeGenModule.h
  lib/Driver/Tools.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/CodeGenObjC/convert-messages-to-runtime-calls.m
  test/Driver/objc-convert-messages-to-runtime-calls.m

Index: test/Driver/objc-convert-messages-to-runtime-calls.m
===
--- /dev/null
+++ test/Driver/objc-convert-messages-to-runtime-calls.m
@@ -0,0 +1,7 @@
+// RUN: %clang %s -### -o %t.o 2>&1 -fsyntax-only -fobjc-convert-messages-to-runtime-calls -fno-objc-convert-messages-to-runtime-calls -target x86_64-apple-macosx10.10.0 | FileCheck  %s --check-prefix=DISABLE
+// RUN: %clang %s -### -o %t.o 2>&1 -fsyntax-only -fno-objc-convert-messages-to-runtime-calls -fobjc-convert-messages-to-runtime-calls -target x86_64-apple-macosx10.10.0 | FileCheck  %s --check-prefix=ENABLE
+
+// Check that we pass fobjc-convert-messages-to-runtime-calls only when supported, and not explicitly disabled.
+
+// DISABLE: "-fno-objc-convert-messages-to-runtime-calls"
+// ENABLE-NOT: "-fno-objc-convert-messages-to-runtime-calls"
Index: test/CodeGenObjC/convert-messages-to-runtime-calls.m
===
--- /dev/null
+++ test/CodeGenObjC/convert-messages-to-runtime-calls.m
@@ -0,0 +1,109 @@
+// RUN: %clang_cc1 -fobjc-runtime=macosx-10.10.0 -emit-llvm -o - %s -fno-objc-convert-messages-to-runtime-calls | FileCheck %s --check-prefix=MSGS
+// RUN: %clang_cc1 -fobjc-runtime=macosx-10.10.0 -emit-llvm -o - %s | FileCheck %s --check-prefix=CALLS
+// RUN: %clang_cc1 -fobjc-runtime=macosx-10.9.0 -emit-llvm -o - %s | FileCheck %s --check-prefix=MSGS
+// RUN: %clang_cc1 -fobjc-runtime=macosx-fragile-10.10.0 -emit-llvm -o - %s | FileCheck %s --check-prefix=MSGS
+// Make sure we don't do calls to retain/release when using GC.
+// RUN: %clang_cc1 -fobjc-runtime=macosx-10.10.0 -emit-llvm -o - %s -fobjc-gc | FileCheck %s --check-prefix=GC
+// RUN: %clang_cc1 -fobjc-runtime=ios-8.0 -emit-llvm -o - %s | FileCheck %s --check-prefix=CALLS
+// RUN: %clang_cc1 -fobjc-runtime=ios-7.0 -emit-llvm -o - %s | FileCheck %s --check-prefix=MSGS
+// Note: This line below is for tvos for which the driver passes through to use the ios9.0 runtime.
+// RUN: %clang_cc1 -fobjc-runtime=ios-9.0 -emit-llvm -o - %s | FileCheck %s --check-prefix=CALLS
+// RUN: %clang_cc1 -fobjc-runtime=watchos-2.0 -emit-llvm -o - %s | FileCheck %s --check-prefix=CALLS
+
+@interface NSObject
++ (id)alloc;
++ (id)alloc2;
+- (id)init;
+- (id)retain;
+- (void)release;
+- (id)autorelease;
+@end
+
+@interface NSString : NSObject
++ (void)retain_self;
+- (void)retain_super;
+@end
+
+// CHECK-LABEL: define {{.*}}void @test1
+void test1(id x) {
+  // MSGS: {{call.*@objc_msgSend}}
+  // MSGS: {{call.*@objc_msgSend}}
+  // MSGS: {{call.*@objc_msgSend}}
+  // MSGS: {{call.*@objc_msgSend}}
+  // CALLS: {{call.*@objc_alloc}}
+  // CALLS: {{call.*@objc_retain}}
+  // CALLS: {{call.*@objc_release}}
+  // CALLS: {{call.*@objc_autorelease}}
+  // GC: {{call.*@objc_alloc}}
+  // GC: {{call.*@objc_msgSend}}
+  // GC: {{call.*@objc_msgSend}}
+  // GC: {{call.*@objc_msgSend}}
+  [NSObject alloc];
+  [x retain];
+  [x release];
+  [x autorelease];
+}
+
+// CHECK-LABEL: define {{.*}}void @test2
+void test2() {
+  // MSGS: {{call.*@objc_msgSend}}
+  // CALLS: {{call.*@objc_msgSend}}
+  // GC: {{call.*@objc_msgSend}}
+  // Make sure alloc has the correct name and number of types.
+  [NSObject alloc2];
+}
+
+@class A;
+@interface B
+- (A*) retain;
+@end
+
+// Make sure we get a bitcast on the return type as the
+// objc_retain call will return i8* which we have to cast
+// to A*
+// CHECK-LABEL: define {{.*}}void @test_return_bitcast
+A* test_return_bitcast(B *b) {
+  // MSGS: {{call.*@objc_msgSend}}
+  // CALLS: {{call.*@objc_retain}}
+  // CALLS-NEXT: bitcast i8*
+  // GC: {{call.*@objc_msgSend}}
+  return [b retain];
+}
+
+@interface C
+- (float) retain;
+@end
+
+// Make sure we use a message and not a call as the return type is
+// not a pointer type.
+// CHECK-LABEL: define {{.*}}void @test_cannot_message_return_float
+float test_cannot_message_return_float(C *c) {
+  // MSGS: {{call.*@objc_msgSend}}
+  // CALLS: {{call.*@objc_msgSend}}
+  // GC: {{call.*@objc_msgSend}}
+  return [c retain];

Re: [PATCH] Change memcpy/memmove/memset to have dest and source alignment

2015-11-18 Thread Pete Cooper via cfe-commits
Pushed this in LLVM r253511 and clang 253512.

Thanks again for the review Hal.

BTW, I realized the docs need to be updated.  I’ll let the bots run on this for 
a while and if it all goes well I’ll commit the docs update.

Cheers,
Pete
> On Nov 11, 2015, at 11:25 AM, Pete Cooper via cfe-commits 
> <cfe-commits@lists.llvm.org> wrote:
> 
> 
>> On Nov 11, 2015, at 11:16 AM, Hal Finkel <hfin...@anl.gov 
>> <mailto:hfin...@anl.gov>> wrote:
>> 
>> It seems like I dropped the ball on this. Yes, I recall being fine with them 
>> otherwise.
> Thanks Hal!  I’ll rebase the patches and land them over the next day or two.
> 
> Thanks,
> Pete
>> 
>> Thanks again,
>> Hal
> 
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D14737: Convert some ObjC msgSends to runtime calls

2015-11-18 Thread Pete Cooper via cfe-commits

> On Nov 18, 2015, at 4:21 PM, John McCall  wrote:
> 
> rjmccall added inline comments.
> 
> 
> Comment at: include/clang/Basic/ObjCRuntime.h:182
> @@ +181,3 @@
> +switch (getKind()) {
> +case FragileMacOSX: return false;
> +case MacOSX: return getVersion() >= VersionTuple(10, 10);
> 
> I went ahead and asked Greg, and he agreed that it's best to not enable this 
> on the Mac fragile runtime.  The functions exist, but they aren't profitable 
> to call, other than a small code-size decrease.
Ah cool.  Thanks for checking.

I’m working on updating the patch now with your feedback.  Should have a new 
version soon.

I will now also add tests to ensure the fragile runtime does not get this 
change, since i’d been missing that before.

Thanks,
Pete
> 
> 
> http://reviews.llvm.org/D14737
> 
> 
> 

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r253519 - Fix debian build after r253512.

2015-11-18 Thread Pete Cooper via cfe-commits
Author: pete
Date: Wed Nov 18 16:53:40 2015
New Revision: 253519

URL: http://llvm.org/viewvc/llvm-project?rev=253519=rev
Log:
Fix debian build after r253512.

The conversion from QuantityType to the (temporary) IntegerAlignment class
was ambiguous.

For now add in explicit conversion to unsigned to satisfy the 
clang-x86_64-debian-fast bot.

I'll remove the explicit conversion when I remove the IntegerAlignment class.

Modified:
cfe/trunk/lib/CodeGen/CGBuilder.h

Modified: cfe/trunk/lib/CodeGen/CGBuilder.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuilder.h?rev=253519=253518=253519=diff
==
--- cfe/trunk/lib/CodeGen/CGBuilder.h (original)
+++ cfe/trunk/lib/CodeGen/CGBuilder.h Wed Nov 18 16:53:40 2015
@@ -273,13 +273,13 @@ public:
bool IsVolatile = false) {
 return CreateMemCpy(Dest.getPointer(), Src.getPointer(), Size,
 Dest.getAlignment().getQuantity(),
-Src.getAlignment().getQuantity(), IsVolatile);
+(unsigned)Src.getAlignment().getQuantity(), 
IsVolatile);
   }
   llvm::CallInst *CreateMemCpy(Address Dest, Address Src, uint64_t Size,
bool IsVolatile = false) {
 return CreateMemCpy(Dest.getPointer(), Src.getPointer(), Size,
 Dest.getAlignment().getQuantity(),
-Src.getAlignment().getQuantity(), IsVolatile);
+(unsigned)Src.getAlignment().getQuantity(), 
IsVolatile);
   }
 
   using CGBuilderBaseTy::CreateMemMove;
@@ -287,7 +287,8 @@ public:
 bool IsVolatile = false) {
 return CreateMemMove(Dest.getPointer(), Src.getPointer(), Size,
  Dest.getAlignment().getQuantity(),
- Src.getAlignment().getQuantity(), IsVolatile);
+ (unsigned)Src.getAlignment().getQuantity(),
+ IsVolatile);
   }
 
   using CGBuilderBaseTy::CreateMemSet;


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r253541 - Revert "Fix debian build after r253512."

2015-11-18 Thread Pete Cooper via cfe-commits
Author: pete
Date: Wed Nov 18 23:55:44 2015
New Revision: 253541

URL: http://llvm.org/viewvc/llvm-project?rev=253541=rev
Log:
Revert "Fix debian build after r253512."

This reverts commit r253519.

This likely broke the bots in
http://lab.llvm.org:8011/builders/clang-ppc64-elf-linux2/builds/20202
http://bb.pgr.jp/builders/clang-3stage-i686-linux/builds/3787

Modified:
cfe/trunk/lib/CodeGen/CGBuilder.h

Modified: cfe/trunk/lib/CodeGen/CGBuilder.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuilder.h?rev=253541=253540=253541=diff
==
--- cfe/trunk/lib/CodeGen/CGBuilder.h (original)
+++ cfe/trunk/lib/CodeGen/CGBuilder.h Wed Nov 18 23:55:44 2015
@@ -273,13 +273,13 @@ public:
bool IsVolatile = false) {
 return CreateMemCpy(Dest.getPointer(), Src.getPointer(), Size,
 Dest.getAlignment().getQuantity(),
-(unsigned)Src.getAlignment().getQuantity(), 
IsVolatile);
+Src.getAlignment().getQuantity(), IsVolatile);
   }
   llvm::CallInst *CreateMemCpy(Address Dest, Address Src, uint64_t Size,
bool IsVolatile = false) {
 return CreateMemCpy(Dest.getPointer(), Src.getPointer(), Size,
 Dest.getAlignment().getQuantity(),
-(unsigned)Src.getAlignment().getQuantity(), 
IsVolatile);
+Src.getAlignment().getQuantity(), IsVolatile);
   }
 
   using CGBuilderBaseTy::CreateMemMove;
@@ -287,8 +287,7 @@ public:
 bool IsVolatile = false) {
 return CreateMemMove(Dest.getPointer(), Src.getPointer(), Size,
  Dest.getAlignment().getQuantity(),
- (unsigned)Src.getAlignment().getQuantity(),
- IsVolatile);
+ Src.getAlignment().getQuantity(), IsVolatile);
   }
 
   using CGBuilderBaseTy::CreateMemSet;


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D14737: Convert some ObjC msgSends to runtime calls

2015-11-16 Thread Pete Cooper via cfe-commits
pete created this revision.
pete added a reviewer: rjmccall.
pete added a subscriber: cfe-commits.

It is faster to directly call the ObjC runtime for methods such as 
retain/release instead of sending a message to those functions.

This patch adds support for converting messages to 
retain/release/alloc/autorelease to their equivalent runtime calls.

Tests included for the positive case of applying this transformation, negative 
tests that we ensure we only convert "alloc" to objc_alloc, not "alloc2", and 
also a driver test to ensure we enable this only for supported runtime versions.

http://reviews.llvm.org/D14737

Files:
  include/clang/Basic/LangOptions.def
  include/clang/Basic/ObjCRuntime.h
  include/clang/Driver/Options.td
  lib/CodeGen/CGObjC.cpp
  lib/CodeGen/CGObjCMac.cpp
  lib/CodeGen/CodeGenFunction.h
  lib/CodeGen/CodeGenModule.h
  lib/Driver/Tools.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/CodeGenObjC/convert-messages-to-runtime-calls.m
  test/Driver/objc-convert-messages-to-runtime-calls.m

Index: test/Driver/objc-convert-messages-to-runtime-calls.m
===
--- /dev/null
+++ test/Driver/objc-convert-messages-to-runtime-calls.m
@@ -0,0 +1,17 @@
+// RUN: %clang %s -### -o %t.o 2>&1 -fobjc-convert-messages-to-runtime-calls -fsyntax-only -fno-objc-convert-messages-to-runtime-calls -target x86_64-apple-macosx10.10.0 | FileCheck  %s --check-prefix=DISABLE
+// RUN: %clang %s -### -o %t.o 2>&1 -fobjc-convert-messages-to-runtime-calls -fsyntax-only -target x86_64-apple-macosx10.10.0 | FileCheck  %s --check-prefix=ENABLE
+// RUN: %clang %s -### -o %t.o 2>&1 -fsyntax-only -target x86_64-apple-macosx10.10.0 | FileCheck  %s --check-prefix=SUPPORTED_MACOS
+// RUN: %clang %s -### -o %t.o 2>&1 -fsyntax-only -target x86_64-apple-macosx10.9.0 | FileCheck  %s --check-prefix=UNSUPPORTED_MACOS
+// RUN: %clang %s -### -o %t.o 2>&1 -fsyntax-only -target armv7-apple-ios8.0 | FileCheck  %s --check-prefix=SUPPORTED_IOS
+// RUN: %clang %s -### -o %t.o 2>&1 -fsyntax-only -target armv7-apple-ios7.0 | FileCheck  %s --check-prefix=UNSUPPORTED_IOS
+
+// Check that we pass fobjc-convert-messages-to-runtime-calls only when supported, and not explicitly disabled.
+
+// DISABLE-NOT: "-fobjc-convert-messages-to-runtime-calls"
+// ENABLE: "-fobjc-convert-messages-to-runtime-calls"
+// SUPPORTED_MACOS: "-fobjc-convert-messages-to-runtime-calls"
+// UNSUPPORTED_MACOS-NOT: "-fobjc-convert-messages-to-runtime-calls"
+// SUPPORTED_IOS: "-fobjc-convert-messages-to-runtime-calls"
+// UNSUPPORTED_IOS-NOT: "-fobjc-convert-messages-to-runtime-calls"
+
+
Index: test/CodeGenObjC/convert-messages-to-runtime-calls.m
===
--- /dev/null
+++ test/CodeGenObjC/convert-messages-to-runtime-calls.m
@@ -0,0 +1,38 @@
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.10.0 -emit-llvm -o - %s | FileCheck %s --check-prefix=MSGS
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.10.0 -emit-llvm -o - %s -fobjc-convert-messages-to-runtime-calls | FileCheck %s --check-prefix=CALLS
+
+@interface NSObject
++ (id)alloc;
++ (id)alloc2;
+- (id)init;
+- (id)retain;
+- (void)release;
+- (id)autorelease;
+@end
+
+@interface NSString : NSObject
+@end
+
+// CHECK-LABEL: define {{.*}}void @test1
+void test1(id x) {
+  // MSGS: {{call.*@objc_msgSend}}
+  // MSGS: {{call.*@objc_msgSend}}
+  // MSGS: {{call.*@objc_msgSend}}
+  // MSGS: {{call.*@objc_msgSend}}
+  // CALLS: {{call.*@objc_alloc}}
+  // CALLS: {{call.*@objc_retain}}
+  // CALLS: {{call.*@objc_release}}
+  // CALLS: {{call.*@objc_autorelease}}
+  [NSObject alloc];
+  [x retain];
+  [x release];
+  [x autorelease];
+}
+
+// CHECK-LABEL: define {{.*}}void @test2
+void test2() {
+  // MSGS: {{call.*@objc_msgSend}}
+  // CALLS: {{call.*@objc_msgSend}}
+  // Make sure alloc has the correct name and number of types.
+  [NSObject alloc2];
+}
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -1519,6 +1519,9 @@
 if (Args.hasArg(OPT_fobjc_subscripting_legacy_runtime))
   Opts.ObjCSubscriptingLegacyRuntime =
 (Opts.ObjCRuntime.getKind() == ObjCRuntime::FragileMacOSX);
+
+if (Args.hasArg(OPT_fobjc_convert_messages_to_runtime_calls))
+  Opts.ObjCConvertMessagesToRuntimeCalls = 1;
   }
 
   if (Args.hasArg(OPT_fgnu89_inline)) {
Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -4842,6 +4842,15 @@
 
   }
 
+  // Allow the user to control whether messages can be converted to runtime
+  // functions.
+  if (types::isObjC(InputType) &&
+  Args.hasFlag(options::OPT_fobjc_convert_messages_to_runtime_calls,
+   options::OPT_fno_objc_convert_messages_to_runtime_calls,
+   true) &&
+  

Re: [PATCH] Change memcpy/memmove/memset to have dest and source alignment

2015-09-28 Thread Pete Cooper via cfe-commits
Hey Hal

Thanks for the review. I really appreciate it given the scale of this.
> On Sep 25, 2015, at 1:13 PM, Hal Finkel  wrote:
> 
> Hi Pete,
> 
> Thanks for working on this.
> 
> +  class IntegerAlignment {
> +  private:
> +uint64_t Align;
> 
> You explain in the patch summary why this is here, but please add a comment 
> with the explanation as well.
Will do.  Good catch.
> 
> Regarding the auto-upgrade, are we going to run into problems if we separate 
> our the 'volatile' tag for the source and the destination as Lang had 
> suggested? If we're going to do that, should we do it all at the same time? 
> Does it change the need for the IntegerAlignment class?
Luckily I think this will be easier as its just an addition, unlike this patch 
which is moving things around to attributes.  I’m also pretty confident about 
using sed to auto-upgrade all the tests with the volatile flag.  Its much 
easier to sed for the ‘i1 [true|false])’ at the end of the call and just 
duplicate that piece, than it is to extract the alignment out from the middle 
and print it back out as an attribute.

Saying that, there will be similar churn on things like the IRBuilder, and we 
may want some way to (temporarily at the least) make sure that everyone is 
forced to consider whether they want to set both isVolatile flags given that 
they set one of them.  A few possibilities are:

// Bad, because we don’t know whether current users who set isDestVolatile to 
true also want source volatility too
Create(..., bool isDestVolatile = false, bool isSrcVolatile = false) 

// Better, all current users will have to change anyway, and then we know they 
all care about src/dest volatility
Create(…, std::pair isDestSrcVolatile = std::pair(false, false))

// Another option, and we would use an assert perhaps to make sure that if dest 
is set, then so is src
Create(…, Optional isDestVolatile = None, Optional isSrcVolatile = 
None) {
  assert(isDestVolatile.hasValue() == isSrcVolatile.hasValue());
  …

Anyway, I think changes can come later, but just a few ideas there.
> 
> Everything else looks good, and I like the cleanup in 
> AlignmentFromAssumptions :-)
Thanks :)  Can I take that as a LGTM, or...
> 
> Thanks again,
> Hal
> 
> P.S. I find full-context patches in Phabricator much easier than diffs; this 
> does not matter for the automated regression-test updates, but for the code 
> changes, I appreciate patches there.
… would you prefer to see the patch in phab first?  I’m happy either way.  I 
will leave the test case changes here though, and just put the code in phab if 
needed and if thats ok.

Cheers,
Pete
> 
> - Original Message -
>> From: "Pete Cooper" 
>> To: "Hal J. Finkel" 
>> Cc: "Lang Hames" , "LLVM Commits" 
>> , cfe-commits@lists.llvm.org
>> Sent: Friday, August 28, 2015 5:59:18 PM
>> Subject: [PATCH] Change memcpy/memmove/memset to have dest and source 
>> alignment
>> 
>> 
>> 
>> Hi Hal/Lang
>> 
>> This came out of a discussion here:
>> http://lists.llvm.org/pipermail/llvm-dev/2015-August/089384.html
>> 
>> We want to be able to provide alignment for both the source and dest
>> of mem intrinsics, instead of the alignment argument which only
>> provides the minimum of dest/src.
>> 
>> Instead of adding another argument, I removed the alignment argument
>> and added the align attributes to the src/dest pointer arguments.
>> 
>> I’ve updated the MemIntrinsic definition to handle this, and all of
>> the code to now call getDestAlignment/getSrcAlignment instead of
>> getAlignment. For the few places where it wasn’t clear whether
>> dest/src was the right choice, i’ve left a FIXME and I take the
>> minimum of dest/src so as to match the current behavior.
>> 
>> I’ve also updated the create methods in the IR builder. There is a
>> (temporary) class there to handle the new source alignment
>> parameter, as otherwise existing callers of this code could end up
>> having the isVolatile bool implicitly converted to the source
>> alignment. I’ll remove this once out-of-tree users have had a chance
>> to update to this patch.
>> 
>> Tests were updated to automatically strip out the alignment argument
>> (the regex find/replace is in the patch). I then ran make check and
>> explicitly added back in alignments to all tests which needed it. I
>> tried to automatically update tests to transfer alignment to the
>> attributes, but that wasn’t feasible due to constant expressions
>> confusing regex (turns out regex doesn’t like recursion, which is
>> more or less what you need to get balanced braces in gep(bit
>> cast(inttoptr())) type expressions which we have in our tests).
>> 
>> There’s also a commit which shows how auto upgrading bitcode is
>> handled. There was already a test for llvm 3.2 which called memcpy
>> so is used for this. I’ll add tests to upgrade memmove and memset
>> prior to committing 

Re: [clang-tools-extra] r245471 - [clang-tidy] Fix a bug in UseNullptrCheck.

2015-08-19 Thread Pete Cooper via cfe-commits
Yep, works for me locally.  Thanks for fixing it.

Pete
 On Aug 19, 2015, at 3:24 PM, Alexander Kornienko ale...@google.com wrote:
 
 I've committed the check with minor modifications and without the offending 
 test in r245511. Could you verify that it works in your setup?
 
 -- Alex
 
 On Wed, Aug 19, 2015 at 11:41 PM, Pete Cooper peter_coo...@apple.com 
 mailto:peter_coo...@apple.com wrote:
 
 On Aug 19, 2015, at 2:38 PM, Alexander Kornienko ale...@google.com 
 mailto:ale...@google.com wrote:
 
 The check has been reverted in r245493. Sorry for the breakage, I was hoping 
 that this commit fixes it.
 No problem.  Thanks for taking a look.
 
 If you think the rest of the code is good and want to land it again then 
 thats fine.  You can leave out the check below until you are happy that its 
 working too.  That way you potentially won’t be blocked for too long.
 
 Thanks,
 Pete
 
 On Wed, Aug 19, 2015 at 10:31 PM, Pete Cooper peter_coo...@apple.com 
 mailto:peter_coo...@apple.com wrote:
 Looks like its only a single test thats failing.
 
 Would you mind if I remove this piece of the test until we can get to the 
 bottom of it?
 
 void test_macro_expansion4() {
 #define MY_NULL NULL
   int *p = MY_NULL;
   // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: use nullptr 
 [modernize-use-nullptr]
   // CHECK-FIXES: int *p = nullptr;
 #undef MY_NULL
 }
 
 Thanks,
 Pete
 On Aug 19, 2015, at 1:00 PM, Pete Cooper peter_coo...@apple.com 
 mailto:peter_coo...@apple.com wrote:
 
 Hi Alexander
 
 We’re still getting a green dragon failure on the null ptr check test.  
 Mind taking a look?
 
 http://lab.llvm.org:8080/green/job/clang-stage1-configure-RA_check/10351/consoleFull#50560140149ba4694-19c4-4d7e-bec5-911270d8a58c
  
 https://urldefense.proofpoint.com/v2/url?u=http-3A__lab.llvm.org-3A8080_green_job_clang-2Dstage1-2Dconfigure-2DRA-5Fcheck_10351_consoleFull-2350560140149ba4694-2D19c4-2D4d7e-2Dbec5-2D911270d8a58cd=BQMFaQc=eEvniauFctOgLOKGJOplqwr=03tkj3107244TlY4t3_hEgkDY-UG6gKwwK0wOUS3qjMm=egkIy3ZyHViev_djzwydHEvkmBTxiHkYi7IViAItTvYs=Jk2TDC-f1lko8XlDHLjnD9998CpHgKUoBidcEOk2xIce=
 
 Thanks
 Pete
 On Aug 19, 2015, at 10:50 AM, Alexander Kornienko via cfe-commits 
 cfe-commits@lists.llvm.org mailto:cfe-commits@lists.llvm.org wrote:
 
 Author: alexfh
 Date: Wed Aug 19 12:50:22 2015
 New Revision: 245471
 
 URL: 
 https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject-3Frev-3D245471-26view-3Drevd=BQIGaQc=eEvniauFctOgLOKGJOplqwr=03tkj3107244TlY4t3_hEgkDY-UG6gKwwK0wOUS3qjMm=vEGzlOUc6IO5ny5JKNkJAUEoiokQ1N60GDcHk0yboKQs=wuoYp-wW8aBSkIHSX7igi7DHfur7JyIHWwnzHMTYdlge=
  
 https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject-3Frev-3D245471-26view-3Drevd=BQIGaQc=eEvniauFctOgLOKGJOplqwr=03tkj3107244TlY4t3_hEgkDY-UG6gKwwK0wOUS3qjMm=vEGzlOUc6IO5ny5JKNkJAUEoiokQ1N60GDcHk0yboKQs=wuoYp-wW8aBSkIHSX7igi7DHfur7JyIHWwnzHMTYdlge=
  
 Log:
 [clang-tidy] Fix a bug in UseNullptrCheck.
 
 https://urldefense.proofpoint.com/v2/url?u=http-3A__reviews.llvm.org_D12162d=BQIGaQc=eEvniauFctOgLOKGJOplqwr=03tkj3107244TlY4t3_hEgkDY-UG6gKwwK0wOUS3qjMm=vEGzlOUc6IO5ny5JKNkJAUEoiokQ1N60GDcHk0yboKQs=YiXUYCqfOl7durvaPOdifn3l7_G0FJhlE4A_q5Q6xwMe=
  
 https://urldefense.proofpoint.com/v2/url?u=http-3A__reviews.llvm.org_D12162d=BQIGaQc=eEvniauFctOgLOKGJOplqwr=03tkj3107244TlY4t3_hEgkDY-UG6gKwwK0wOUS3qjMm=vEGzlOUc6IO5ny5JKNkJAUEoiokQ1N60GDcHk0yboKQs=YiXUYCqfOl7durvaPOdifn3l7_G0FJhlE4A_q5Q6xwMe=
  
 
 Patch by Angel Garcia!
 
 Modified:
clang-tools-extra/trunk/clang-tidy/modernize/UseNullptrCheck.cpp
 
 Modified: clang-tools-extra/trunk/clang-tidy/modernize/UseNullptrCheck.cpp
 URL: 
 https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_clang-2Dtools-2Dextra_trunk_clang-2Dtidy_modernize_UseNullptrCheck.cpp-3Frev-3D245471-26r1-3D245470-26r2-3D245471-26view-3Ddiffd=BQIGaQc=eEvniauFctOgLOKGJOplqwr=03tkj3107244TlY4t3_hEgkDY-UG6gKwwK0wOUS3qjMm=vEGzlOUc6IO5ny5JKNkJAUEoiokQ1N60GDcHk0yboKQs=4y-EkuMJJlcYjI15KrZY8VE3eGEhkvg9ScDcHtItY2ge=
  
 https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_clang-2Dtools-2Dextra_trunk_clang-2Dtidy_modernize_UseNullptrCheck.cpp-3Frev-3D245471-26r1-3D245470-26r2-3D245471-26view-3Ddiffd=BQIGaQc=eEvniauFctOgLOKGJOplqwr=03tkj3107244TlY4t3_hEgkDY-UG6gKwwK0wOUS3qjMm=vEGzlOUc6IO5ny5JKNkJAUEoiokQ1N60GDcHk0yboKQs=4y-EkuMJJlcYjI15KrZY8VE3eGEhkvg9ScDcHtItY2ge=
  
 ==
 --- clang-tools-extra/trunk/clang-tidy/modernize/UseNullptrCheck.cpp 
 (original)
 +++ clang-tools-extra/trunk/clang-tidy/modernize/UseNullptrCheck.cpp Wed 
 Aug 19 12:50:22 2015
 @@ -175,10 +175,10 @@ private:
 class CastSequenceVisitor : public 
 RecursiveASTVisitorCastSequenceVisitor {
 public:
   CastSequenceVisitor(ASTContext Context,
 -  SmallVectorStringRef, 1 UserNullMacros,
 +  ArrayRefStringRef UserNullMacros,
   ClangTidyCheck 

Re: [clang-tools-extra] r245471 - [clang-tidy] Fix a bug in UseNullptrCheck.

2015-08-19 Thread Pete Cooper via cfe-commits

 On Aug 19, 2015, at 2:38 PM, Alexander Kornienko ale...@google.com wrote:
 
 The check has been reverted in r245493. Sorry for the breakage, I was hoping 
 that this commit fixes it.
No problem.  Thanks for taking a look.

If you think the rest of the code is good and want to land it again then thats 
fine.  You can leave out the check below until you are happy that its working 
too.  That way you potentially won’t be blocked for too long.

Thanks,
Pete
 
 On Wed, Aug 19, 2015 at 10:31 PM, Pete Cooper peter_coo...@apple.com 
 mailto:peter_coo...@apple.com wrote:
 Looks like its only a single test thats failing.
 
 Would you mind if I remove this piece of the test until we can get to the 
 bottom of it?
 
 void test_macro_expansion4() {
 #define MY_NULL NULL
   int *p = MY_NULL;
   // CHECK-MESSAGES: :[[@LINE-1]]:12: warning: use nullptr 
 [modernize-use-nullptr]
   // CHECK-FIXES: int *p = nullptr;
 #undef MY_NULL
 }
 
 Thanks,
 Pete
 On Aug 19, 2015, at 1:00 PM, Pete Cooper peter_coo...@apple.com 
 mailto:peter_coo...@apple.com wrote:
 
 Hi Alexander
 
 We’re still getting a green dragon failure on the null ptr check test.  Mind 
 taking a look?
 
 http://lab.llvm.org:8080/green/job/clang-stage1-configure-RA_check/10351/consoleFull#50560140149ba4694-19c4-4d7e-bec5-911270d8a58c
  
 https://urldefense.proofpoint.com/v2/url?u=http-3A__lab.llvm.org-3A8080_green_job_clang-2Dstage1-2Dconfigure-2DRA-5Fcheck_10351_consoleFull-2350560140149ba4694-2D19c4-2D4d7e-2Dbec5-2D911270d8a58cd=BQMFaQc=eEvniauFctOgLOKGJOplqwr=03tkj3107244TlY4t3_hEgkDY-UG6gKwwK0wOUS3qjMm=egkIy3ZyHViev_djzwydHEvkmBTxiHkYi7IViAItTvYs=Jk2TDC-f1lko8XlDHLjnD9998CpHgKUoBidcEOk2xIce=
 
 Thanks
 Pete
 On Aug 19, 2015, at 10:50 AM, Alexander Kornienko via cfe-commits 
 cfe-commits@lists.llvm.org mailto:cfe-commits@lists.llvm.org wrote:
 
 Author: alexfh
 Date: Wed Aug 19 12:50:22 2015
 New Revision: 245471
 
 URL: 
 https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject-3Frev-3D245471-26view-3Drevd=BQIGaQc=eEvniauFctOgLOKGJOplqwr=03tkj3107244TlY4t3_hEgkDY-UG6gKwwK0wOUS3qjMm=vEGzlOUc6IO5ny5JKNkJAUEoiokQ1N60GDcHk0yboKQs=wuoYp-wW8aBSkIHSX7igi7DHfur7JyIHWwnzHMTYdlge=
  
 https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject-3Frev-3D245471-26view-3Drevd=BQIGaQc=eEvniauFctOgLOKGJOplqwr=03tkj3107244TlY4t3_hEgkDY-UG6gKwwK0wOUS3qjMm=vEGzlOUc6IO5ny5JKNkJAUEoiokQ1N60GDcHk0yboKQs=wuoYp-wW8aBSkIHSX7igi7DHfur7JyIHWwnzHMTYdlge=
  
 Log:
 [clang-tidy] Fix a bug in UseNullptrCheck.
 
 https://urldefense.proofpoint.com/v2/url?u=http-3A__reviews.llvm.org_D12162d=BQIGaQc=eEvniauFctOgLOKGJOplqwr=03tkj3107244TlY4t3_hEgkDY-UG6gKwwK0wOUS3qjMm=vEGzlOUc6IO5ny5JKNkJAUEoiokQ1N60GDcHk0yboKQs=YiXUYCqfOl7durvaPOdifn3l7_G0FJhlE4A_q5Q6xwMe=
  
 https://urldefense.proofpoint.com/v2/url?u=http-3A__reviews.llvm.org_D12162d=BQIGaQc=eEvniauFctOgLOKGJOplqwr=03tkj3107244TlY4t3_hEgkDY-UG6gKwwK0wOUS3qjMm=vEGzlOUc6IO5ny5JKNkJAUEoiokQ1N60GDcHk0yboKQs=YiXUYCqfOl7durvaPOdifn3l7_G0FJhlE4A_q5Q6xwMe=
  
 
 Patch by Angel Garcia!
 
 Modified:
clang-tools-extra/trunk/clang-tidy/modernize/UseNullptrCheck.cpp
 
 Modified: clang-tools-extra/trunk/clang-tidy/modernize/UseNullptrCheck.cpp
 URL: 
 https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_clang-2Dtools-2Dextra_trunk_clang-2Dtidy_modernize_UseNullptrCheck.cpp-3Frev-3D245471-26r1-3D245470-26r2-3D245471-26view-3Ddiffd=BQIGaQc=eEvniauFctOgLOKGJOplqwr=03tkj3107244TlY4t3_hEgkDY-UG6gKwwK0wOUS3qjMm=vEGzlOUc6IO5ny5JKNkJAUEoiokQ1N60GDcHk0yboKQs=4y-EkuMJJlcYjI15KrZY8VE3eGEhkvg9ScDcHtItY2ge=
  
 https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_clang-2Dtools-2Dextra_trunk_clang-2Dtidy_modernize_UseNullptrCheck.cpp-3Frev-3D245471-26r1-3D245470-26r2-3D245471-26view-3Ddiffd=BQIGaQc=eEvniauFctOgLOKGJOplqwr=03tkj3107244TlY4t3_hEgkDY-UG6gKwwK0wOUS3qjMm=vEGzlOUc6IO5ny5JKNkJAUEoiokQ1N60GDcHk0yboKQs=4y-EkuMJJlcYjI15KrZY8VE3eGEhkvg9ScDcHtItY2ge=
  
 ==
 --- clang-tools-extra/trunk/clang-tidy/modernize/UseNullptrCheck.cpp 
 (original)
 +++ clang-tools-extra/trunk/clang-tidy/modernize/UseNullptrCheck.cpp Wed 
 Aug 19 12:50:22 2015
 @@ -175,10 +175,10 @@ private:
 class CastSequenceVisitor : public RecursiveASTVisitorCastSequenceVisitor 
 {
 public:
   CastSequenceVisitor(ASTContext Context,
 -  SmallVectorStringRef, 1 UserNullMacros,
 +  ArrayRefStringRef UserNullMacros,
   ClangTidyCheck check)
   : SM(Context.getSourceManager()), Context(Context),
 -UserNullMacros(std::move(UserNullMacros)), Check(check),
 +UserNullMacros(UserNullMacros), Check(check),
 FirstSubExpr(nullptr), PruneSubtree(false) {}
 
   bool TraverseStmt(Stmt *S) {
 @@ -435,7 +435,7 @@ private:
 private:
   SourceManager SM;
   ASTContext Context;
 -  const SmallVectorStringRef, 1 UserNullMacros;
 +