1 //===- DataLayoutUpgradeTest.cpp - Tests for DataLayout upgrades ----------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "llvm/IR/AutoUpgrade.h"
10 #include "gtest/gtest.h"
16 TEST(DataLayoutUpgradeTest
, ValidDataLayoutUpgrade
) {
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(
23 "e-m:o-i64:64-f80:128-n8:16:32:64-S128", "x86_64-apple-macosx");
25 "e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128"
26 "-f80:128-n8:16:32:64-S128");
28 "e-m:w-p:32:32-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128"
29 "-f80:128-n8:16:32-S32");
30 EXPECT_EQ(DL3
, "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:"
31 "128-n8:16:32:64-S128");
33 // Check that AMDGPU targets add -G1 if it's not present.
34 EXPECT_EQ(UpgradeDataLayoutString("e-p:32:32", "r600"), "e-p:32:32-G1");
35 // and that ANDGCN adds p7 and p8 as well.
36 EXPECT_EQ(UpgradeDataLayoutString("e-p:64:64", "amdgcn"),
37 "e-p:64:64-G1-ni:7:8-p7:160:256:256:32-p8:128:128");
38 EXPECT_EQ(UpgradeDataLayoutString("e-p:64:64-G1", "amdgcn"),
39 "e-p:64:64-G1-ni:7:8-p7:160:256:256:32-p8:128:128");
40 // but that r600 does not.
41 EXPECT_EQ(UpgradeDataLayoutString("e-p:32:32-G1", "r600"), "e-p:32:32-G1");
43 // Ensure that the non-integral direction for address space 8 doesn't get
44 // added in to pointer declarations.
46 UpgradeDataLayoutString(
47 "e-p:64:64-p1:64:64-p2:32:32-p3:32:32-p4:64:64-p5:32:32-p6:32:32-i64:"
48 "64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-"
49 "v1024:1024-v2048:2048-n32:64-S32-A5-G1-ni:7",
51 "e-p:64:64-p1:64:64-p2:32:32-p3:32:32-p4:64:64-p5:32:32-p6:32:32-i64:64-"
52 "v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:"
53 "1024-v2048:2048-n32:64-S32-A5-G1-ni:7:8-p7:160:256:256:32-p8:128:128");
55 // Check that RISCV64 upgrades -n64 to -n32:64.
56 EXPECT_EQ(UpgradeDataLayoutString("e-m:e-p:64:64-i64:64-i128:128-n64-S128",
58 "e-m:e-p:64:64-i64:64-i128:128-n32:64-S128");
61 TEST(DataLayoutUpgradeTest
, NoDataLayoutUpgrade
) {
62 std::string DL1
= UpgradeDataLayoutString(
63 "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-i128:128:128-"
65 "-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128"
67 "x86_64-unknown-linux-gnu");
68 std::string DL2
= UpgradeDataLayoutString("e-m:e-i64:64-n32:64",
69 "powerpc64le-unknown-linux-gnu");
71 UpgradeDataLayoutString("e-m:o-i64:64-i128:128-n32:64-S128", "aarch64--");
74 "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-i128:128:128"
75 "-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64"
76 "-f80:128:128-n8:16:32:64-S128");
77 EXPECT_EQ(DL2
, "e-m:e-i64:64-n32:64");
78 EXPECT_EQ(DL3
, "e-m:o-i64:64-i128:128-n32:64-S128");
80 // Check that AMDGPU targets don't add -G1 if there is already a -G flag.
81 EXPECT_EQ(UpgradeDataLayoutString("e-p:32:32-G2", "r600"), "e-p:32:32-G2");
82 EXPECT_EQ(UpgradeDataLayoutString("G2", "r600"), "G2");
83 EXPECT_EQ(UpgradeDataLayoutString("e-p:64:64-G2", "amdgcn"),
84 "e-p:64:64-G2-ni:7:8-p7:160:256:256:32-p8:128:128");
85 EXPECT_EQ(UpgradeDataLayoutString("G2-e-p:64:64", "amdgcn"),
86 "G2-e-p:64:64-ni:7:8-p7:160:256:256:32-p8:128:128");
87 EXPECT_EQ(UpgradeDataLayoutString("e-p:64:64-G0", "amdgcn"),
88 "e-p:64:64-G0-ni:7:8-p7:160:256:256:32-p8:128:128");
90 // Check that AMDGCN targets don't add already declared address space 7.
91 EXPECT_EQ(UpgradeDataLayoutString("e-p:64:64-p7:64:64", "amdgcn"),
92 "e-p:64:64-p7:64:64-G1-ni:7:8-p8:128:128");
93 EXPECT_EQ(UpgradeDataLayoutString("p7:64:64-G2-e-p:64:64", "amdgcn"),
94 "p7:64:64-G2-e-p:64:64-ni:7:8-p8:128:128");
95 EXPECT_EQ(UpgradeDataLayoutString("e-p:64:64-p7:64:64-G1", "amdgcn"),
96 "e-p:64:64-p7:64:64-G1-ni:7:8-p8:128:128");
99 TEST(DataLayoutUpgradeTest
, EmptyDataLayout
) {
100 std::string DL1
= UpgradeDataLayoutString("", "x86_64-unknown-linux-gnu");
101 std::string DL2
= UpgradeDataLayoutString(
102 "e-m:e-p:32:32-i64:64-f80:128-n8:16:32:64-S128", "");
104 EXPECT_EQ(DL2
, "e-m:e-p:32:32-i64:64-f80:128-n8:16:32:64-S128");
106 // Check that AMDGPU targets add G1 if it's not present.
107 EXPECT_EQ(UpgradeDataLayoutString("", "r600"), "G1");
108 EXPECT_EQ(UpgradeDataLayoutString("", "amdgcn"),
109 "G1-ni:7:8-p7:160:256:256:32-p8:128:128");