diff --git a/llvm/lib/AsmParser/LLParser.h b/llvm/lib/AsmParser/LLParser.h --- a/llvm/lib/AsmParser/LLParser.h +++ b/llvm/lib/AsmParser/LLParser.h @@ -308,6 +308,7 @@ bool ParseTopLevelEntities(); bool ValidateEndOfModule(); bool ValidateEndOfIndex(); + bool ParseTargetDefinitions(); bool ParseTargetDefinition(); bool ParseModuleAsm(); bool ParseSourceFileName(); diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp --- a/llvm/lib/AsmParser/LLParser.cpp +++ b/llvm/lib/AsmParser/LLParser.cpp @@ -70,6 +70,11 @@ Lex.getLoc(), "Can't read textual IR with a Context that discards named Values"); + if (M) { + if (ParseTargetDefinitions()) + return true; + } + return ParseTopLevelEntities() || ValidateEndOfModule() || ValidateEndOfIndex(); } @@ -294,6 +299,20 @@ // Top-Level Entities //===----------------------------------------------------------------------===// +bool LLParser::ParseTargetDefinitions() { + while (true) { + if (Lex.getKind() == lltok::kw_target) { + if (ParseTargetDefinition()) + return true; + } else if (Lex.getKind() == lltok::kw_source_filename) { + if (ParseSourceFileName()) + return true; + } else { + return false; + } + } +} + bool LLParser::ParseTopLevelEntities() { // If there is no Module, then parse just the summary index entries. if (!M) { @@ -322,11 +341,6 @@ case lltok::kw_declare: if (ParseDeclare()) return true; break; case lltok::kw_define: if (ParseDefine()) return true; break; case lltok::kw_module: if (ParseModuleAsm()) return true; break; - case lltok::kw_target: if (ParseTargetDefinition()) return true; break; - case lltok::kw_source_filename: - if (ParseSourceFileName()) - return true; - break; case lltok::kw_deplibs: if (ParseDepLibs()) return true; break; case lltok::LocalVarID: if (ParseUnnamedType()) return true; break; case lltok::LocalVar: if (ParseNamedType()) return true; break; diff --git a/llvm/test/Analysis/DependenceAnalysis/NonCanonicalizedSubscript.ll b/llvm/test/Analysis/DependenceAnalysis/NonCanonicalizedSubscript.ll --- a/llvm/test/Analysis/DependenceAnalysis/NonCanonicalizedSubscript.ll +++ b/llvm/test/Analysis/DependenceAnalysis/NonCanonicalizedSubscript.ll @@ -36,9 +36,6 @@ ret void } -target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" -target triple = "x86_64-unknown-linux-gnu" - ; unsigned i, j; ; for (i = 1; i < SIZE; i++) { ; for (j = i; j < SIZE; j++) { diff --git a/llvm/test/Analysis/ScalarEvolution/2012-05-29-MulAddRec.ll b/llvm/test/Analysis/ScalarEvolution/2012-05-29-MulAddRec.ll --- a/llvm/test/Analysis/ScalarEvolution/2012-05-29-MulAddRec.ll +++ b/llvm/test/Analysis/ScalarEvolution/2012-05-29-MulAddRec.ll @@ -8,6 +8,8 @@ ; ; PR12929: cast() argument of incompatible type +target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128" + declare void @use(i8 %x) ; CHECK: @func @@ -20,7 +22,6 @@ ; CHECK: %0 = add i8 %inc1, 10 ; CHECK: br label %for.cond -target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128" define void @func() noreturn nounwind uwtable ssp { entry: br label %for.cond diff --git a/llvm/test/Transforms/InstCombine/2012-09-17-ZeroSizedAlloca.ll b/llvm/test/Transforms/InstCombine/2012-09-17-ZeroSizedAlloca.ll --- a/llvm/test/Transforms/InstCombine/2012-09-17-ZeroSizedAlloca.ll +++ b/llvm/test/Transforms/InstCombine/2012-09-17-ZeroSizedAlloca.ll @@ -3,12 +3,12 @@ ; When merging zero sized alloca check that requested alignments of the allocas ; are obeyed. -@x = global i8* null, align 8 -@y = global i8* null, align 8 - target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128" target triple = "x86_64-apple-macosx10.8.0" +@x = global i8* null, align 8 +@y = global i8* null, align 8 + ; CHECK-LABEL: @f( ; CHECK-NEXT: alloca [0 x i8], align 1024 ; CHECK-NOT: alloca diff --git a/llvm/test/Transforms/InstCombine/getelementptr-folding.ll b/llvm/test/Transforms/InstCombine/getelementptr-folding.ll --- a/llvm/test/Transforms/InstCombine/getelementptr-folding.ll +++ b/llvm/test/Transforms/InstCombine/getelementptr-folding.ll @@ -1,13 +1,13 @@ ; RUN: opt -instcombine -S < %s | FileCheck %s -%struct.matrix_float3x3 = type { [3 x <3 x float>] } - ; We used to fold this by rewriting the indices to 0, 0, 2, 0. This is ; invalid because there is a 4-byte padding after each <3 x float> field. target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128" target triple = "x86_64-apple-macosx10.11.0" +%struct.matrix_float3x3 = type { [3 x <3 x float>] } + @matrix_identity_float3x3 = external global %struct.matrix_float3x3, align 16 @bbb = global float* getelementptr inbounds (%struct.matrix_float3x3, %struct.matrix_float3x3* @matrix_identity_float3x3, i64 0, i32 0, i64 1, i64 3) ; CHECK: @bbb = global float* getelementptr inbounds (%struct.matrix_float3x3, %struct.matrix_float3x3* @matrix_identity_float3x3, i64 0, i32 0, i64 1, i64 3) diff --git a/llvm/test/Transforms/InstCombine/overflow-mul.ll b/llvm/test/Transforms/InstCombine/overflow-mul.ll --- a/llvm/test/Transforms/InstCombine/overflow-mul.ll +++ b/llvm/test/Transforms/InstCombine/overflow-mul.ll @@ -1,5 +1,16 @@ ; RUN: opt -S -instcombine < %s | FileCheck %s +; The last test needs this weird datalayout. +target datalayout = "i32:8:8" +; Without it, InstCombine will align the pointed on 4 Bytes +; The KnownBitsZero that result from the alignment allows to +; turn: +; and i32 %mul, 255 +; to: +; and i32 %mul, 252 +; The mask is no longer in the form 2^n-1 and this prevents the transformation. + + ; return mul(zext x, zext y) > MAX define i32 @pr4917_1(i32 %x, i32 %y) nounwind { ; CHECK-LABEL: @pr4917_1( @@ -175,16 +186,6 @@ } -; The last test needs this weird datalayout. -target datalayout = "i32:8:8" -; Without it, InstCombine will align the pointed on 4 Bytes -; The KnownBitsZero that result from the alignment allows to -; turn: -; and i32 %mul, 255 -; to: -; and i32 %mul, 252 -; The mask is no longer in the form 2^n-1 and this prevents the transformation. - @pr21445_data = external global i32 define i1 @pr21445(i8 %a) { ; CHECK-LABEL: @pr21445( diff --git a/llvm/test/Transforms/InstCombine/wcslen-3.ll b/llvm/test/Transforms/InstCombine/wcslen-3.ll --- a/llvm/test/Transforms/InstCombine/wcslen-3.ll +++ b/llvm/test/Transforms/InstCombine/wcslen-3.ll @@ -3,12 +3,12 @@ ; ; RUN: opt < %s -instcombine -S | FileCheck %s +target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128" + ; Test behavior for wchar_size==2 !llvm.module.flags = !{!0} !0 = !{i32 1, !"wchar_size", i32 2} -target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128" - declare i64 @wcslen(i16*) @hello = constant [6 x i16] [i16 104, i16 101, i16 108, i16 108, i16 111, i16 0] diff --git a/llvm/test/Transforms/LoopIdiom/X86/popcnt.ll b/llvm/test/Transforms/LoopIdiom/X86/popcnt.ll --- a/llvm/test/Transforms/LoopIdiom/X86/popcnt.ll +++ b/llvm/test/Transforms/LoopIdiom/X86/popcnt.ll @@ -1,5 +1,7 @@ ; RUN: opt -loop-idiom < %s -mtriple=x86_64-apple-darwin -mcpu=corei7 -S | FileCheck %s +target triple = "x86_64-apple-macosx10.8.0" + ;To recognize this pattern: ;int popcount(unsigned long long a) { ; int c = 0; @@ -75,7 +77,6 @@ } ; Some variants once cause crash -target triple = "x86_64-apple-macosx10.8.0" define i32 @PopCntCrash1(i64 %a) nounwind uwtable readnone ssp { entry: diff --git a/llvm/test/Transforms/LoopVectorize/explicit_outer_nonuniform_inner.ll b/llvm/test/Transforms/LoopVectorize/explicit_outer_nonuniform_inner.ll --- a/llvm/test/Transforms/LoopVectorize/explicit_outer_nonuniform_inner.ll +++ b/llvm/test/Transforms/LoopVectorize/explicit_outer_nonuniform_inner.ll @@ -73,8 +73,6 @@ ; CHECK: LV: Not vectorizing: Outer loop contains divergent loops. ; CHECK: LV: Not vectorizing: Unsupported outer loop. -target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" - define void @loop_ub(i32* nocapture %a, i32* nocapture readonly %b, i32 %N, i32 %M) local_unnamed_addr { entry: %cmp32 = icmp sgt i32 %N, 0 @@ -121,8 +119,6 @@ ; CHECK: LV: Not vectorizing: Outer loop contains divergent loops. ; CHECK: LV: Not vectorizing: Unsupported outer loop. -target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" - define void @iv_step(i32* nocapture %a, i32* nocapture readonly %b, i32 %N, i32 %M) local_unnamed_addr { entry: %cmp33 = icmp sgt i32 %N, 0 diff --git a/llvm/test/Transforms/LoopVectorize/explicit_outer_uniform_diverg_branch.ll b/llvm/test/Transforms/LoopVectorize/explicit_outer_uniform_diverg_branch.ll --- a/llvm/test/Transforms/LoopVectorize/explicit_outer_uniform_diverg_branch.ll +++ b/llvm/test/Transforms/LoopVectorize/explicit_outer_uniform_diverg_branch.ll @@ -77,8 +77,6 @@ ; CHECK: Unsupported conditional branch. ; CHECK: LV: Not vectorizing: Unsupported outer loop. -target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" - define void @divergent_branch(i32* nocapture %a, i32* nocapture readonly %b, i32 %N, i32 %M) local_unnamed_addr { entry: %cmp39 = icmp sgt i32 %N, 0 diff --git a/llvm/test/Transforms/NewGVN/pr33187.ll b/llvm/test/Transforms/NewGVN/pr33187.ll --- a/llvm/test/Transforms/NewGVN/pr33187.ll +++ b/llvm/test/Transforms/NewGVN/pr33187.ll @@ -111,8 +111,6 @@ attributes #0 = { nounwind uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "frame-pointer"="none" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" } -source_filename = "pr33187-c.ll" - define void @a() { ; CHECK-LABEL: @a( ; CHECK-NEXT: b: diff --git a/llvm/test/Transforms/NewGVN/refine-stores.ll b/llvm/test/Transforms/NewGVN/refine-stores.ll --- a/llvm/test/Transforms/NewGVN/refine-stores.ll +++ b/llvm/test/Transforms/NewGVN/refine-stores.ll @@ -5,6 +5,10 @@ ;; We also are testing that various variations that cause stores to move classes ;; have the right class movement happen ;; All of these tests result in verification failures if it does not. + +source_filename = "bugpoint-output-daef094.bc" +target triple = "x86_64-apple-darwin16.5.0" + %struct.eggs = type {} define void @spam(i32 *%a) { @@ -78,10 +82,6 @@ br i1 undef, label %c, label %e } -; ModuleID = 'bugpoint-reduced-simplified.bc' -source_filename = "bugpoint-output-daef094.bc" -target triple = "x86_64-apple-darwin16.5.0" - %struct.hoge = type {} define void @widget(%struct.hoge* %arg) { @@ -132,8 +132,6 @@ } declare void @quux() -; ModuleID = 'short.ll' -source_filename = "short.ll" %struct.a = type {} diff --git a/llvm/test/Transforms/SafeStack/X86/call.ll b/llvm/test/Transforms/SafeStack/X86/call.ll --- a/llvm/test/Transforms/SafeStack/X86/call.ll +++ b/llvm/test/Transforms/SafeStack/X86/call.ll @@ -1,6 +1,9 @@ ; RUN: opt -safe-stack -S -mtriple=i386-pc-linux-gnu < %s -o - | FileCheck %s ; RUN: opt -safe-stack -S -mtriple=x86_64-pc-linux-gnu < %s -o - | FileCheck %s +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + @.str = private unnamed_addr constant [4 x i8] c"%s\0A\00", align 1 ; no arrays / no nested arrays @@ -20,9 +23,6 @@ declare i32 @printf(i8*, ...) -target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" -target triple = "x86_64-unknown-linux-gnu" - define void @call_memset(i64 %len) safestack { entry: ; CHECK-LABEL: define void @call_memset