• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===- DataLayoutUpgradeTest.cpp - Tests for DataLayout upgrades ----------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #include "llvm/IR/AutoUpgrade.h"
10 #include "gtest/gtest.h"
11 
12 using namespace llvm;
13 
14 namespace {
15 
TEST(DataLayoutUpgradeTest,ValidDataLayoutUpgrade)16 TEST(DataLayoutUpgradeTest, ValidDataLayoutUpgrade) {
17   std::string DL1 =
18       UpgradeDataLayoutString("e-m:e-p:32:32-i64:64-f80:128-n8:16:32:64-S128",
19                               "x86_64-unknown-linux-gnu");
20   std::string DL2 = UpgradeDataLayoutString(
21       "e-m:w-p:32:32-i64:64-f80:32-n8:16:32-S32", "i686-pc-windows-msvc");
22   std::string DL3 = UpgradeDataLayoutString("e-m:o-i64:64-i128:128-n32:64-S128",
23                                             "x86_64-apple-macosx");
24   EXPECT_EQ(DL1, "e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-i64:64"
25                  "-f80:128-n8:16:32:64-S128");
26   EXPECT_EQ(DL2, "e-m:w-p:32:32-p270:32:32-p271:32:32-p272:64:64-i64:64"
27                  "-f80:32-n8:16:32-S32");
28   EXPECT_EQ(DL3, "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128"
29                  "-n32:64-S128");
30 
31   // Check that AMDGPU targets add -G1 if it's not present.
32   EXPECT_EQ(UpgradeDataLayoutString("e-p:32:32", "r600"), "e-p:32:32-G1");
33   EXPECT_EQ(UpgradeDataLayoutString("e-p:64:64", "amdgcn"), "e-p:64:64-G1");
34 }
35 
TEST(DataLayoutUpgradeTest,NoDataLayoutUpgrade)36 TEST(DataLayoutUpgradeTest, NoDataLayoutUpgrade) {
37   std::string DL1 = UpgradeDataLayoutString(
38       "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32"
39       "-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128"
40       "-n8:16:32:64-S128",
41       "x86_64-unknown-linux-gnu");
42   std::string DL2 = UpgradeDataLayoutString("e-p:32:32", "i686-apple-darwin9");
43   std::string DL3 = UpgradeDataLayoutString("e-m:e-i64:64-n32:64",
44                                             "powerpc64le-unknown-linux-gnu");
45   std::string DL4 =
46       UpgradeDataLayoutString("e-m:o-i64:64-i128:128-n32:64-S128", "aarch64--");
47   EXPECT_EQ(DL1, "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64"
48                  "-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64"
49                  "-f80:128:128-n8:16:32:64-S128");
50   EXPECT_EQ(DL2, "e-p:32:32");
51   EXPECT_EQ(DL3, "e-m:e-i64:64-n32:64");
52   EXPECT_EQ(DL4, "e-m:o-i64:64-i128:128-n32:64-S128");
53 
54   // Check that AMDGPU targets don't add -G1 if there is already a -G flag.
55   EXPECT_EQ(UpgradeDataLayoutString("e-p:32:32-G2", "r600"), "e-p:32:32-G2");
56   EXPECT_EQ(UpgradeDataLayoutString("G2", "r600"), "G2");
57   EXPECT_EQ(UpgradeDataLayoutString("e-p:64:64-G2", "amdgcn"), "e-p:64:64-G2");
58   EXPECT_EQ(UpgradeDataLayoutString("G2-e-p:64:64", "amdgcn"), "G2-e-p:64:64");
59   EXPECT_EQ(UpgradeDataLayoutString("e-p:64:64-G0", "amdgcn"), "e-p:64:64-G0");
60 }
61 
TEST(DataLayoutUpgradeTest,EmptyDataLayout)62 TEST(DataLayoutUpgradeTest, EmptyDataLayout) {
63   std::string DL1 = UpgradeDataLayoutString("", "x86_64-unknown-linux-gnu");
64   std::string DL2 = UpgradeDataLayoutString(
65       "e-m:e-p:32:32-i64:64-f80:128-n8:16:32:64-S128", "");
66   EXPECT_EQ(DL1, "");
67   EXPECT_EQ(DL2, "e-m:e-p:32:32-i64:64-f80:128-n8:16:32:64-S128");
68 
69   // Check that AMDGPU targets add G1 if it's not present.
70   EXPECT_EQ(UpgradeDataLayoutString("", "r600"), "G1");
71   EXPECT_EQ(UpgradeDataLayoutString("", "amdgcn"), "G1");
72 }
73 
74 } // end namespace
75