Skip to content

Commit

Permalink
Require "target datalayout" to be at the beginning of an IR file.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
efriedma-quic committed Apr 20, 2020
1 parent e128d53 commit 9b9454a
Show file tree
Hide file tree
Showing 15 changed files with 54 additions and 45 deletions.
27 changes: 22 additions & 5 deletions llvm/lib/AsmParser/LLParser.cpp
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions llvm/lib/AsmParser/LLParser.h
Expand Up @@ -308,6 +308,7 @@ namespace llvm {
bool ParseTopLevelEntities();
bool ValidateEndOfModule();
bool ValidateEndOfIndex();
bool ParseTargetDefinitions();
bool ParseTargetDefinition();
bool ParseModuleAsm();
bool ParseSourceFileName();
Expand Down
Expand Up @@ -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++) {
Expand Down
3 changes: 2 additions & 1 deletion llvm/test/Analysis/ScalarEvolution/2012-05-29-MulAddRec.ll
Expand Up @@ -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
Expand All @@ -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
Expand Down
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions 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)
21 changes: 11 additions & 10 deletions 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(
Expand Down Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions llvm/test/Transforms/InstCombine/wcslen-3.ll
Expand Up @@ -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]
Expand Down
3 changes: 2 additions & 1 deletion 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;
Expand Down Expand Up @@ -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:
Expand Down
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions llvm/test/Transforms/NewGVN/pr33187.ll
Expand Up @@ -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:
Expand Down
10 changes: 4 additions & 6 deletions llvm/test/Transforms/NewGVN/refine-stores.ll
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -132,8 +132,6 @@ bb7: ; preds = %bb5, %bb2
}

declare void @quux()
; ModuleID = 'short.ll'
source_filename = "short.ll"

%struct.a = type {}

Expand Down
6 changes: 3 additions & 3 deletions 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
Expand All @@ -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
Expand Down
@@ -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:
Expand Down

0 comments on commit 9b9454a

Please sign in to comment.