Make DataLayout Non-Optional in the Module

Summary:
DataLayout keeps the string used for its creation.

As a side effect it is no longer needed in the Module.
This is "almost" NFC, the string is no longer
canonicalized, you can't rely on two "equals" DataLayout
having the same string returned by getStringRepresentation().

Get rid of DataLayoutPass: the DataLayout is in the Module

The DataLayout is "per-module", let's enforce this by not
duplicating it more than necessary.
One more step toward non-optionality of the DataLayout in the
module.

Make DataLayout Non-Optional in the Module

Module->getDataLayout() will never returns nullptr anymore.

Reviewers: echristo

Subscribers: resistor, llvm-commits, jholewinski

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

From: Mehdi Amini <mehdi.amini@apple.com>
llvm-svn: 231270
diff --git a/llvm/test/Transforms/LoopStrengthReduce/2008-08-13-CmpStride.ll b/llvm/test/Transforms/LoopStrengthReduce/2008-08-13-CmpStride.ll
index 11b3171..1e57aee 100644
--- a/llvm/test/Transforms/LoopStrengthReduce/2008-08-13-CmpStride.ll
+++ b/llvm/test/Transforms/LoopStrengthReduce/2008-08-13-CmpStride.ll
@@ -1,5 +1,9 @@
 ; RUN: opt < %s -loop-reduce -S | grep add | count 2
 ; PR 2662
+
+; Provide legal integer types.
+target datalayout = "n8:16:32:64"
+
 @g_3 = common global i16 0		; <i16*> [#uses=2]
 @"\01LC" = internal constant [4 x i8] c"%d\0A\00"		; <[4 x i8]*> [#uses=1]
 
diff --git a/llvm/test/Transforms/LoopStrengthReduce/2008-09-09-Overflow.ll b/llvm/test/Transforms/LoopStrengthReduce/2008-09-09-Overflow.ll
index 5fb157b..ee21ea4 100644
--- a/llvm/test/Transforms/LoopStrengthReduce/2008-09-09-Overflow.ll
+++ b/llvm/test/Transforms/LoopStrengthReduce/2008-09-09-Overflow.ll
@@ -1,5 +1,9 @@
 ; RUN: opt < %s -loop-reduce -S | grep phi | count 2
 ; PR 2779
+
+; Provide legal integer types.
+target datalayout = "n8:16:32:64"
+
 @g_19 = common global i32 0		; <i32*> [#uses=3]
 @"\01LC" = internal constant [4 x i8] c"%d\0A\00"		; <[4 x i8]*> [#uses=1]
 
diff --git a/llvm/test/Transforms/LoopStrengthReduce/2011-10-03-CritEdgeMerge.ll b/llvm/test/Transforms/LoopStrengthReduce/2011-10-03-CritEdgeMerge.ll
index 3ea4abf..5588995 100644
--- a/llvm/test/Transforms/LoopStrengthReduce/2011-10-03-CritEdgeMerge.ll
+++ b/llvm/test/Transforms/LoopStrengthReduce/2011-10-03-CritEdgeMerge.ll
@@ -4,6 +4,10 @@
 
 target triple = "x86-apple-darwin"
 
+; Provide legal integer types.
+target datalayout = "n8:16:32:64"
+
+
 ; Verify that identical edges are merged. rdar://problem/6453893
 ; CHECK-LABEL: @test1(
 ; CHECK: bb89:
diff --git a/llvm/test/Transforms/LoopStrengthReduce/2011-10-06-ReusePhi.ll b/llvm/test/Transforms/LoopStrengthReduce/2011-10-06-ReusePhi.ll
index 4388a33..cc8226e 100644
--- a/llvm/test/Transforms/LoopStrengthReduce/2011-10-06-ReusePhi.ll
+++ b/llvm/test/Transforms/LoopStrengthReduce/2011-10-06-ReusePhi.ll
@@ -5,6 +5,10 @@
 
 target triple = "x86-apple-darwin"
 
+; Provide legal integer types.
+target datalayout = "n8:16:32:64"
+
+
 ; CHECK-LABEL: @test(
 ; multiplies are hoisted out of the loop
 ; CHECK: while.body.lr.ph:
@@ -17,10 +21,10 @@
 ; CHECK: phi
 ; CHECK: phi
 ; CHECK-NOT: phi
-; CHECK: bitcast float* {{.*}} to i8*
-; CHECK: bitcast float* {{.*}} to i8*
-; CHECK: getelementptr i8, i8*
-; CHECK: getelementptr i8, i8*
+; CHECK: bitcast float* {{.*}} to i1*
+; CHECK: bitcast float* {{.*}} to i1*
+; CHECK: getelementptr i1, i1*
+; CHECK: getelementptr i1, i1*
 
 define float @test(float* nocapture %A, float* nocapture %B, i32 %N, i32 %IA, i32 %IB) nounwind uwtable readonly ssp {
 entry:
diff --git a/llvm/test/Transforms/LoopStrengthReduce/2012-07-18-LimitReassociate.ll b/llvm/test/Transforms/LoopStrengthReduce/2012-07-18-LimitReassociate.ll
index 7cac15f..edd333b 100644
--- a/llvm/test/Transforms/LoopStrengthReduce/2012-07-18-LimitReassociate.ll
+++ b/llvm/test/Transforms/LoopStrengthReduce/2012-07-18-LimitReassociate.ll
@@ -1,5 +1,4 @@
-; RUN: opt -loop-reduce -disable-output -debug-only=loop-reduce < %s 2> %t
-; RUN: FileCheck %s < %t
+; RUN: opt -loop-reduce -disable-output -debug-only=loop-reduce < %s 2>&1 | FileCheck %s
 ; REQUIRES: asserts
 ;
 ; PR13361: LSR + SCEV "hangs" on reasonably sized test with sequence of loops
@@ -18,6 +17,10 @@
 ; CHECK-NOT:reg
 ; CHECK: Filtering for use
 
+; Provide legal integer types.
+target datalayout = "n8:16:32:64"
+
+
 %struct.snork = type { %struct.fuga, i32, i32, i32, i32, i32, i32 }
 %struct.fuga = type { %struct.gork, i64 }
 %struct.gork = type { i8*, i32, i32, %struct.noot* }
diff --git a/llvm/test/Transforms/LoopStrengthReduce/X86/2008-08-14-ShadowIV.ll b/llvm/test/Transforms/LoopStrengthReduce/X86/2008-08-14-ShadowIV.ll
index 9a7f486..ba03597 100644
--- a/llvm/test/Transforms/LoopStrengthReduce/X86/2008-08-14-ShadowIV.ll
+++ b/llvm/test/Transforms/LoopStrengthReduce/X86/2008-08-14-ShadowIV.ll
@@ -1,5 +1,9 @@
 ; RUN: opt < %s -loop-reduce -S -mtriple=x86_64-unknown-unknown | grep "phi double" | count 1
 
+; Provide legal integer types.
+target datalayout = "n8:16:32:64"
+
+
 define void @foobar(i32 %n) nounwind {
 entry:
 	icmp eq i32 %n, 0		; <i1>:0 [#uses=2]
diff --git a/llvm/test/Transforms/LoopStrengthReduce/X86/2011-07-20-DoubleIV.ll b/llvm/test/Transforms/LoopStrengthReduce/X86/2011-07-20-DoubleIV.ll
index 2fe62e3..0fc928c 100644
--- a/llvm/test/Transforms/LoopStrengthReduce/X86/2011-07-20-DoubleIV.ll
+++ b/llvm/test/Transforms/LoopStrengthReduce/X86/2011-07-20-DoubleIV.ll
@@ -4,6 +4,10 @@
 ; nonzero initial value.
 ; rdar://9786536
 
+; Provide legal integer types.
+target datalayout = "n8:16:32:64"
+
+
 ; First, make sure LSR doesn't crash on an empty IVUsers list.
 ; CHECK-LABEL: @dummyIV(
 ; CHECK-NOT: phi
diff --git a/llvm/test/Transforms/LoopStrengthReduce/count-to-zero.ll b/llvm/test/Transforms/LoopStrengthReduce/count-to-zero.ll
index 0e96f02..ca93e38 100644
--- a/llvm/test/Transforms/LoopStrengthReduce/count-to-zero.ll
+++ b/llvm/test/Transforms/LoopStrengthReduce/count-to-zero.ll
@@ -1,6 +1,9 @@
 ; RUN: opt < %s -loop-reduce -S | FileCheck %s
 ; rdar://7382068
 
+; Provide legal integer types.
+target datalayout = "n8:16:32:64"
+
 define void @t(i32 %c) nounwind optsize {
 entry:
   br label %bb6
diff --git a/llvm/test/Transforms/LoopStrengthReduce/dont_reverse.ll b/llvm/test/Transforms/LoopStrengthReduce/dont_reverse.ll
index 4809def..551bd03 100644
--- a/llvm/test/Transforms/LoopStrengthReduce/dont_reverse.ll
+++ b/llvm/test/Transforms/LoopStrengthReduce/dont_reverse.ll
@@ -4,6 +4,10 @@
 ; Don't reverse the iteration if the rhs of the compare is defined
 ; inside the loop.
 
+; Provide legal integer types.
+; Declare i2 as legal so that IVUsers accepts to consider %indvar3451
+target datalayout = "n2:8:16:32:64"
+
 define void @Fill_Buffer(i2* %p) nounwind {
 entry:
 	br label %bb8
diff --git a/llvm/test/Transforms/LoopStrengthReduce/ivchain.ll b/llvm/test/Transforms/LoopStrengthReduce/ivchain.ll
index f996f22..d95220d 100644
--- a/llvm/test/Transforms/LoopStrengthReduce/ivchain.ll
+++ b/llvm/test/Transforms/LoopStrengthReduce/ivchain.ll
@@ -4,6 +4,10 @@
 ; A sign extend feeds an IVUser and cannot be hoisted into the AddRec.
 ; CollectIVChains should bailout on this case.
 
+
+; Provide legal integer types.
+target datalayout = "n8:16:32:64"
+
 %struct = type { i8*, i8*, i16, i64, i16, i16, i16, i64, i64, i16, i8*, i64, i64, i64 }
 
 ; CHECK-LABEL: @test(
diff --git a/llvm/test/Transforms/LoopStrengthReduce/nested-reduce.ll b/llvm/test/Transforms/LoopStrengthReduce/nested-reduce.ll
index 58b8d3e..c05b19d 100644
--- a/llvm/test/Transforms/LoopStrengthReduce/nested-reduce.ll
+++ b/llvm/test/Transforms/LoopStrengthReduce/nested-reduce.ll
@@ -1,5 +1,8 @@
 ; RUN: opt < %s -loop-reduce -S | not grep mul
 
+; Provide legal integer types.
+target datalayout = "n8:16:32:64"
+
 ; Make sure we don't get a multiply by 6 in this loop.
 
 define i32 @foo(i32 %A, i32 %B, i32 %C, i32 %D) {
diff --git a/llvm/test/Transforms/LoopStrengthReduce/pr12691.ll b/llvm/test/Transforms/LoopStrengthReduce/pr12691.ll
index dfc1343..e33e405 100644
--- a/llvm/test/Transforms/LoopStrengthReduce/pr12691.ll
+++ b/llvm/test/Transforms/LoopStrengthReduce/pr12691.ll
@@ -1,5 +1,8 @@
 ; RUN: opt < %s -loop-reduce -S | FileCheck %s
 
+; Provide legal integer types.
+target datalayout = "n8:16:32:64"
+
 @d = common global i32 0, align 4
 
 define void @fn2(i32 %x) nounwind uwtable {
diff --git a/llvm/test/Transforms/LoopStrengthReduce/quadradic-exit-value.ll b/llvm/test/Transforms/LoopStrengthReduce/quadradic-exit-value.ll
index 65aa61f..483becc 100644
--- a/llvm/test/Transforms/LoopStrengthReduce/quadradic-exit-value.ll
+++ b/llvm/test/Transforms/LoopStrengthReduce/quadradic-exit-value.ll
@@ -1,5 +1,8 @@
 ; RUN: opt < %s -analyze -iv-users | FileCheck %s
 
+; Provide legal integer types.
+target datalayout = "n8:16:32:64"
+
 ; The value of %r is dependent on a polynomial iteration expression.
 ;
 ; CHECK-LABEL: IV Users for loop %foo.loop
diff --git a/llvm/test/Transforms/LoopStrengthReduce/remove_indvar.ll b/llvm/test/Transforms/LoopStrengthReduce/remove_indvar.ll
index fd0e9a5..3b92c25 100644
--- a/llvm/test/Transforms/LoopStrengthReduce/remove_indvar.ll
+++ b/llvm/test/Transforms/LoopStrengthReduce/remove_indvar.ll
@@ -1,6 +1,9 @@
 ; Check that this test makes INDVAR and related stuff dead.
 ; RUN: opt < %s -loop-reduce -S | not grep INDVAR
 
+; Provide legal integer types.
+target datalayout = "n8:16:32:64"
+
 declare i1 @pred()
 
 define void @test(i32* %P) {
diff --git a/llvm/test/Transforms/LoopStrengthReduce/variable_stride.ll b/llvm/test/Transforms/LoopStrengthReduce/variable_stride.ll
index 7c0f053..f82b2fc 100644
--- a/llvm/test/Transforms/LoopStrengthReduce/variable_stride.ll
+++ b/llvm/test/Transforms/LoopStrengthReduce/variable_stride.ll
@@ -1,6 +1,9 @@
 ; Check that variable strides are reduced to adds instead of multiplies.
 ; RUN: opt < %s -loop-reduce -S | not grep mul
 
+; Provide legal integer types.
+target datalayout = "n8:16:32:64"
+
 declare i1 @pred(i32)
 
 define void @test([10000 x i32]* %P, i32 %STRIDE) {