r202002 - Do not put instrumentation counters before phis in ObjC for-in loops.
Bob Wilson
bob.wilson at apple.com
Sun Feb 23 17:13:09 PST 2014
Author: bwilson
Date: Sun Feb 23 19:13:09 2014
New Revision: 202002
URL: http://llvm.org/viewvc/llvm-project?rev=202002&view=rev
Log:
Do not put instrumentation counters before phis in ObjC for-in loops.
We still don't use the PGO to set branch weights for these loops, but at
least this keeps the compiler from crashing. <rdar://problem/16137778>
Added:
cfe/trunk/test/CodeGenObjC/Inputs/instr-profile.profdata
cfe/trunk/test/CodeGenObjC/instr-profile.m
Modified:
cfe/trunk/lib/CodeGen/CGObjC.cpp
Modified: cfe/trunk/lib/CodeGen/CGObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjC.cpp?rev=202002&r1=202001&r2=202002&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjC.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjC.cpp Sun Feb 23 19:13:09 2014
@@ -1525,13 +1525,10 @@ void CodeGenFunction::EmitObjCForCollect
llvm::Value *initialMutations =
Builder.CreateLoad(StateMutationsPtr, "forcoll.initial-mutations");
- RegionCounter Cnt = getPGORegionCounter(&S);
-
// Start looping. This is the point we return to whenever we have a
// fresh, non-empty batch of objects.
llvm::BasicBlock *LoopBodyBB = createBasicBlock("forcoll.loopbody");
EmitBlock(LoopBodyBB);
- Cnt.beginRegion(Builder);
// The current index into the buffer.
llvm::PHINode *index = Builder.CreatePHI(UnsignedLongLTy, 3, "forcoll.index");
@@ -1541,6 +1538,9 @@ void CodeGenFunction::EmitObjCForCollect
llvm::PHINode *count = Builder.CreatePHI(UnsignedLongLTy, 3, "forcoll.count");
count->addIncoming(initialBufferLimit, LoopInitBB);
+ RegionCounter Cnt = getPGORegionCounter(&S);
+ Cnt.beginRegion(Builder);
+
// Check whether the mutations value has changed from where it was
// at start. StateMutationsPtr should actually be invariant between
// refreshes.
Added: cfe/trunk/test/CodeGenObjC/Inputs/instr-profile.profdata
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/Inputs/instr-profile.profdata?rev=202002&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenObjC/Inputs/instr-profile.profdata (added)
+++ cfe/trunk/test/CodeGenObjC/Inputs/instr-profile.profdata Sun Feb 23 19:13:09 2014
@@ -0,0 +1,7 @@
+foreach 2
+1
+2
+
+main 1
+1
+
Added: cfe/trunk/test/CodeGenObjC/instr-profile.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/instr-profile.m?rev=202002&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenObjC/instr-profile.m (added)
+++ cfe/trunk/test/CodeGenObjC/instr-profile.m Sun Feb 23 19:13:09 2014
@@ -0,0 +1,38 @@
+// Test that instrumentation based profiling feeds branch prediction
+// correctly. This tests both generation of profile data and use of the same,
+// and the input file for the -fprofile-instr-use case is expected to be result
+// of running the program generated by the -fprofile-instr-generate case. As
+// such, main() should call every function in this test.
+
+// RUN: %clang %s -o - -emit-llvm -S -fprofile-instr-generate | FileCheck -check-prefix=PGOGEN %s
+// RUN: %clang %s -o - -emit-llvm -S -fprofile-instr-use=%S/Inputs/instr-profile.profdata | FileCheck -check-prefix=PGOUSE %s
+
+#ifdef HAVE_FOUNDATION
+// Use this to build an instrumented version to regenerate the input file.
+#import <Foundation/Foundation.h>
+#else
+struct NSFastEnumerationState;
+ at interface NSArray
+- (unsigned long) countByEnumeratingWithState: (struct NSFastEnumerationState*) state
+ objects: (id*) buffer
+ count: (unsigned long) bufferSize;
++(NSArray*) arrayWithObjects: (id) first, ...;
+ at end;
+#endif
+
+// PGOGEN: @[[FOR:__llvm_pgo_ctr[0-9]*]] = private global [2 x i64] zeroinitializer
+
+// PGOGEN-LABEL: @foreach
+// PGOUSE-LABEL: @foreach
+// PGOGEN: store {{.*}} @[[FOR]], i64 0, i64 0
+void foreach(NSArray *array) {
+ // PGOGEN: store {{.*}} @[[FOR]], i64 0, i64 1
+ // FIXME: We don't emit branch weights for this yet.
+ for (id x in array) {
+ }
+}
+
+int main(int argc, const char *argv[]) {
+ NSArray *array = [NSArray arrayWithObjects: @"0", @"1", (void*)0];
+ foreach(array);
+}
More information about the cfe-commits
mailing list