[COFF] Don't mark mingw .eh_frame sections writable
[llvm-core.git] / unittests / CodeGen / LowLevelTypeTest.cpp
bloba4765d99856200c7e2f24c47efab1b1250b07e16
1 //===- llvm/unittest/CodeGen/GlobalISel/LowLevelTypeTest.cpp --------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
10 #include "llvm/CodeGen/LowLevelType.h"
11 #include "llvm/IR/DataLayout.h"
12 #include "llvm/IR/DerivedTypes.h"
13 #include "llvm/IR/LLVMContext.h"
14 #include "llvm/IR/Type.h"
15 #include "gtest/gtest.h"
17 using namespace llvm;
19 // Define a pretty printer to help debugging when things go wrong.
20 namespace llvm {
21 std::ostream &
22 operator<<(std::ostream &OS, const llvm::LLT Ty) {
23 std::string Repr;
24 raw_string_ostream SS{Repr};
25 Ty.print(SS);
26 OS << SS.str();
27 return OS;
31 namespace {
33 TEST(LowLevelTypeTest, Scalar) {
34 LLVMContext C;
35 DataLayout DL("");
37 for (unsigned S : {1U, 17U, 32U, 64U, 0xfffffU}) {
38 const LLT Ty = LLT::scalar(S);
40 // Test kind.
41 ASSERT_TRUE(Ty.isValid());
42 ASSERT_TRUE(Ty.isScalar());
44 ASSERT_FALSE(Ty.isPointer());
45 ASSERT_FALSE(Ty.isVector());
47 // Test sizes.
48 EXPECT_EQ(S, Ty.getSizeInBits());
49 EXPECT_EQ(S, Ty.getScalarSizeInBits());
51 // Test equality operators.
52 EXPECT_TRUE(Ty == Ty);
53 EXPECT_FALSE(Ty != Ty);
55 // Test Type->LLT conversion.
56 Type *IRTy = IntegerType::get(C, S);
57 EXPECT_EQ(Ty, getLLTForType(*IRTy, DL));
61 TEST(LowLevelTypeTest, Vector) {
62 LLVMContext C;
63 DataLayout DL("");
65 for (unsigned S : {1U, 17U, 32U, 64U, 0xfffU}) {
66 for (uint16_t Elts : {2U, 3U, 4U, 32U, 0xffU}) {
67 const LLT STy = LLT::scalar(S);
68 const LLT VTy = LLT::vector(Elts, S);
70 // Test the alternative vector().
72 const LLT VSTy = LLT::vector(Elts, STy);
73 EXPECT_EQ(VTy, VSTy);
76 // Test getElementType().
77 EXPECT_EQ(STy, VTy.getElementType());
79 // Test kind.
80 ASSERT_TRUE(VTy.isValid());
81 ASSERT_TRUE(VTy.isVector());
83 ASSERT_FALSE(VTy.isScalar());
84 ASSERT_FALSE(VTy.isPointer());
86 // Test sizes.
87 EXPECT_EQ(S * Elts, VTy.getSizeInBits());
88 EXPECT_EQ(S, VTy.getScalarSizeInBits());
89 EXPECT_EQ(Elts, VTy.getNumElements());
91 // Test equality operators.
92 EXPECT_TRUE(VTy == VTy);
93 EXPECT_FALSE(VTy != VTy);
95 // Test inequality operators on..
96 // ..different kind.
97 EXPECT_NE(VTy, STy);
99 // Test Type->LLT conversion.
100 Type *IRSTy = IntegerType::get(C, S);
101 Type *IRTy = VectorType::get(IRSTy, Elts);
102 EXPECT_EQ(VTy, getLLTForType(*IRTy, DL));
107 TEST(LowLevelTypeTest, Pointer) {
108 LLVMContext C;
109 DataLayout DL("");
111 for (unsigned AS : {0U, 1U, 127U, 0xffffU}) {
112 const LLT Ty = LLT::pointer(AS, DL.getPointerSizeInBits(AS));
113 const LLT VTy = LLT::vector(4, Ty);
115 // Test kind.
116 ASSERT_TRUE(Ty.isValid());
117 ASSERT_TRUE(Ty.isPointer());
119 ASSERT_FALSE(Ty.isScalar());
120 ASSERT_FALSE(Ty.isVector());
122 ASSERT_TRUE(VTy.isValid());
123 ASSERT_TRUE(VTy.isVector());
124 ASSERT_TRUE(VTy.getElementType().isPointer());
126 // Test addressspace.
127 EXPECT_EQ(AS, Ty.getAddressSpace());
128 EXPECT_EQ(AS, VTy.getElementType().getAddressSpace());
130 // Test equality operators.
131 EXPECT_TRUE(Ty == Ty);
132 EXPECT_FALSE(Ty != Ty);
133 EXPECT_TRUE(VTy == VTy);
134 EXPECT_FALSE(VTy != VTy);
136 // Test Type->LLT conversion.
137 Type *IRTy = PointerType::get(IntegerType::get(C, 8), AS);
138 EXPECT_EQ(Ty, getLLTForType(*IRTy, DL));
139 Type *IRVTy =
140 VectorType::get(PointerType::get(IntegerType::get(C, 8), AS), 4);
141 EXPECT_EQ(VTy, getLLTForType(*IRVTy, DL));
145 TEST(LowLevelTypeTest, Invalid) {
146 const LLT Ty;
148 ASSERT_FALSE(Ty.isValid());
149 ASSERT_FALSE(Ty.isScalar());
150 ASSERT_FALSE(Ty.isPointer());
151 ASSERT_FALSE(Ty.isVector());