Require "target datalayout" to be at the beginning of an IR file.

This will allow us to use the datalayout to disambiguate other
constructs in IR, like load alignment. Split off from D78403.

Differential Revision: https://reviews.llvm.org/D78413
This commit is contained in:
Eli Friedman 2020-04-17 19:33:26 -07:00
parent e128d53895
commit 9b9454af8a
15 changed files with 54 additions and 45 deletions

View File

@ -70,6 +70,11 @@ bool LLParser::Run() {
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,23 @@ bool LLParser::ValidateEndOfIndex() {
// Top-Level Entities
//===----------------------------------------------------------------------===//
bool LLParser::ParseTargetDefinitions() {
while (true) {
switch (Lex.getKind()) {
case lltok::kw_target:
if (ParseTargetDefinition())
return true;
break;
case lltok::kw_source_filename:
if (ParseSourceFileName())
return true;
break;
default:
return false;
}
}
}
bool LLParser::ParseTopLevelEntities() {
// If there is no Module, then parse just the summary index entries.
if (!M) {
@ -322,11 +344,6 @@ bool LLParser::ParseTopLevelEntities() {
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;

View File

@ -308,6 +308,7 @@ namespace llvm {
bool ParseTopLevelEntities();
bool ValidateEndOfModule();
bool ValidateEndOfIndex();
bool ParseTargetDefinitions();
bool ParseTargetDefinition();
bool ParseModuleAsm();
bool ParseSourceFileName();

View File

@ -36,9 +36,6 @@ for.end:
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++) {

View File

@ -8,6 +8,8 @@
;
; PR12929: cast<Ty>() 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 @@ declare void @use(i8 %x)
; 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

View File

@ -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

View File

@ -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)

View File

@ -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 @@ define <4 x i32> @pr20113(<4 x i16> %a, <4 x i16> %b) {
}
; 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(

View File

@ -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]

View File

@ -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 @@ while.end: ; preds = %while.body, %entry
}
; Some variants once cause crash
target triple = "x86_64-apple-macosx10.8.0"
define i32 @PopCntCrash1(i64 %a) nounwind uwtable readnone ssp {
entry:

View File

@ -73,8 +73,6 @@ for.end15: ; preds = %outer.inc, %entry
; 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 @@ for.end15: ; preds = %outer.inc, %entry
; 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

View File

@ -77,8 +77,6 @@ for.end19: ; preds = %outer.inc, %entry
; 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

View File

@ -111,8 +111,6 @@ bb1: ; preds = %bb1, %bb
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:

View File

@ -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 @@ e: ; preds = %e, %c
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 @@ bb7: ; preds = %bb5, %bb2
}
declare void @quux()
; ModuleID = 'short.ll'
source_filename = "short.ll"
%struct.a = type {}

View File

@ -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 @@ entry:
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

View File

@ -1,9 +1,10 @@
; RUN: opt %loadPolly -polly-codegen -S < %s | FileCheck %s
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
@A = common global [1536 x float] zeroinitializer
; CHECK: polly
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
define void @foo() {
entry: