[polly] 9b9454a - Require "target datalayout" to be at the beginning of an IR file.

Eli Friedman via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 20 11:56:05 PDT 2020


Author: Eli Friedman
Date: 2020-04-20T11:55:49-07:00
New Revision: 9b9454af8a525f92a19cc0a568777bb7c599c4cb

URL: https://github.com/llvm/llvm-project/commit/9b9454af8a525f92a19cc0a568777bb7c599c4cb
DIFF: https://github.com/llvm/llvm-project/commit/9b9454af8a525f92a19cc0a568777bb7c599c4cb.diff

LOG: 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

Added: 
    

Modified: 
    llvm/lib/AsmParser/LLParser.cpp
    llvm/lib/AsmParser/LLParser.h
    llvm/test/Analysis/DependenceAnalysis/NonCanonicalizedSubscript.ll
    llvm/test/Analysis/ScalarEvolution/2012-05-29-MulAddRec.ll
    llvm/test/Transforms/InstCombine/2012-09-17-ZeroSizedAlloca.ll
    llvm/test/Transforms/InstCombine/getelementptr-folding.ll
    llvm/test/Transforms/InstCombine/overflow-mul.ll
    llvm/test/Transforms/InstCombine/wcslen-3.ll
    llvm/test/Transforms/LoopIdiom/X86/popcnt.ll
    llvm/test/Transforms/LoopVectorize/explicit_outer_nonuniform_inner.ll
    llvm/test/Transforms/LoopVectorize/explicit_outer_uniform_diverg_branch.ll
    llvm/test/Transforms/NewGVN/pr33187.ll
    llvm/test/Transforms/NewGVN/refine-stores.ll
    llvm/test/Transforms/SafeStack/X86/call.ll
    polly/test/Isl/CodeGen/20150328-SCEVExpanderIntroducesNewIV.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp
index e2d0180eb3c6..73809197f08f 100644
--- a/llvm/lib/AsmParser/LLParser.cpp
+++ b/llvm/lib/AsmParser/LLParser.cpp
@@ -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;

diff  --git a/llvm/lib/AsmParser/LLParser.h b/llvm/lib/AsmParser/LLParser.h
index 7e496f3031af..d85341395440 100644
--- a/llvm/lib/AsmParser/LLParser.h
+++ b/llvm/lib/AsmParser/LLParser.h
@@ -308,6 +308,7 @@ namespace llvm {
     bool ParseTopLevelEntities();
     bool ValidateEndOfModule();
     bool ValidateEndOfIndex();
+    bool ParseTargetDefinitions();
     bool ParseTargetDefinition();
     bool ParseModuleAsm();
     bool ParseSourceFileName();

diff  --git a/llvm/test/Analysis/DependenceAnalysis/NonCanonicalizedSubscript.ll b/llvm/test/Analysis/DependenceAnalysis/NonCanonicalizedSubscript.ll
index 1da2672ffd46..2105023dfc4a 100644
--- a/llvm/test/Analysis/DependenceAnalysis/NonCanonicalizedSubscript.ll
+++ b/llvm/test/Analysis/DependenceAnalysis/NonCanonicalizedSubscript.ll
@@ -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++) {

diff  --git a/llvm/test/Analysis/ScalarEvolution/2012-05-29-MulAddRec.ll b/llvm/test/Analysis/ScalarEvolution/2012-05-29-MulAddRec.ll
index 5777e968f07e..f395059ba5cc 100644
--- 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<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

diff  --git a/llvm/test/Transforms/InstCombine/2012-09-17-ZeroSizedAlloca.ll b/llvm/test/Transforms/InstCombine/2012-09-17-ZeroSizedAlloca.ll
index 1c5a9813e6b3..369228c15aab 100644
--- 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.
 
- at x = global i8* null, align 8
- at 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"
 
+ at x = global i8* null, align 8
+ at 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
index 11e7e43a6b44..7803b2b35452 100644
--- 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
index bc0504b0a96d..9dce5bde2c4f 100644
--- 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 @@ 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(

diff  --git a/llvm/test/Transforms/InstCombine/wcslen-3.ll b/llvm/test/Transforms/InstCombine/wcslen-3.ll
index e789442f4905..9fd94752c81e 100644
--- 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
index 4c8920358d6a..09b1af6027d6 100644
--- 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 @@ 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:

diff  --git a/llvm/test/Transforms/LoopVectorize/explicit_outer_nonuniform_inner.ll b/llvm/test/Transforms/LoopVectorize/explicit_outer_nonuniform_inner.ll
index d0ab58b30e3f..657822d6364e 100644
--- a/llvm/test/Transforms/LoopVectorize/explicit_outer_nonuniform_inner.ll
+++ b/llvm/test/Transforms/LoopVectorize/explicit_outer_nonuniform_inner.ll
@@ -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

diff  --git a/llvm/test/Transforms/LoopVectorize/explicit_outer_uniform_diverg_branch.ll b/llvm/test/Transforms/LoopVectorize/explicit_outer_uniform_diverg_branch.ll
index e05e9dd813b8..bfb0a5e81a81 100644
--- 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 @@ 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

diff  --git a/llvm/test/Transforms/NewGVN/pr33187.ll b/llvm/test/Transforms/NewGVN/pr33187.ll
index 1410edc221d0..d7daffd864d9 100644
--- a/llvm/test/Transforms/NewGVN/pr33187.ll
+++ b/llvm/test/Transforms/NewGVN/pr33187.ll
@@ -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:

diff  --git a/llvm/test/Transforms/NewGVN/refine-stores.ll b/llvm/test/Transforms/NewGVN/refine-stores.ll
index a48f2fe7fdb6..e49e324c6e67 100644
--- 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 @@ 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 {}
 

diff  --git a/llvm/test/Transforms/SafeStack/X86/call.ll b/llvm/test/Transforms/SafeStack/X86/call.ll
index a7bf9ae6e7e2..a1ce30ae56a8 100644
--- 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 @@ 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

diff  --git a/polly/test/Isl/CodeGen/20150328-SCEVExpanderIntroducesNewIV.ll b/polly/test/Isl/CodeGen/20150328-SCEVExpanderIntroducesNewIV.ll
index 7460e3074a7c..57eba11204ad 100644
--- a/polly/test/Isl/CodeGen/20150328-SCEVExpanderIntroducesNewIV.ll
+++ b/polly/test/Isl/CodeGen/20150328-SCEVExpanderIntroducesNewIV.ll
@@ -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:


        


More information about the llvm-commits mailing list