[X86] Split rr/rm CVT schedules on SNB/HSW/BDW (#117494)
[llvm-project.git] / llvm / unittests / SandboxIR / TypesTest.cpp
blob6ccd08d4e710fba67630b380a3ff97e9a49c09fd
1 //===- TypesTest.cpp ------------------------------------------------------===//
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 //===----------------------------------------------------------------------===//
9 #include "llvm/ADT/SmallPtrSet.h"
10 #include "llvm/AsmParser/Parser.h"
11 #include "llvm/IR/BasicBlock.h"
12 #include "llvm/IR/Constants.h"
13 #include "llvm/IR/DataLayout.h"
14 #include "llvm/IR/Function.h"
15 #include "llvm/IR/Instruction.h"
16 #include "llvm/IR/Module.h"
17 #include "llvm/SandboxIR/Constant.h"
18 #include "llvm/SandboxIR/Context.h"
19 #include "llvm/SandboxIR/Function.h"
20 #include "llvm/Support/SourceMgr.h"
21 #include "gtest/gtest.h"
23 using namespace llvm;
25 struct SandboxTypeTest : public testing::Test {
26 LLVMContext C;
27 std::unique_ptr<Module> M;
29 void parseIR(LLVMContext &C, const char *IR) {
30 SMDiagnostic Err;
31 M = parseAssemblyString(IR, Err, C);
32 if (!M)
33 Err.print("SandboxTypeTest", errs());
35 BasicBlock *getBasicBlockByName(Function &F, StringRef Name) {
36 for (BasicBlock &BB : F)
37 if (BB.getName() == Name)
38 return &BB;
39 llvm_unreachable("Expected to find basic block!");
43 TEST_F(SandboxTypeTest, Type) {
44 parseIR(C, R"IR(
45 define void @foo(i32 %v0) {
46 ret void
48 )IR");
49 llvm::Function *LLVMF = &*M->getFunction("foo");
50 sandboxir::Context Ctx(C);
51 auto *F = Ctx.createFunction(LLVMF);
52 sandboxir::Type *I32Ty = F->getArg(0)->getType();
54 auto *LLVMInt32Ty = llvm::Type::getInt32Ty(C);
55 auto *LLVMFloatTy = llvm::Type::getFloatTy(C);
56 auto *LLVMInt8Ty = llvm::Type::getInt8Ty(C);
58 auto *Int32Ty = Ctx.getType(LLVMInt32Ty);
59 auto *FloatTy = Ctx.getType(LLVMFloatTy);
61 // Check print().
62 std::string Buff1;
63 raw_string_ostream BS1(Buff1);
64 Int32Ty->print(BS1, /*IsForDebug=*/true, /*NoDetails=*/false);
65 std::string Buff2;
66 raw_string_ostream BS2(Buff2);
67 LLVMInt32Ty->print(BS2, /*IsForDebug=*/true, /*NoDetails=*/false);
68 EXPECT_EQ(Buff1, Buff2);
70 // Check getContext().
71 EXPECT_EQ(&I32Ty->getContext(), &Ctx);
72 // Check that Ctx.getType(nullptr) == nullptr.
73 EXPECT_EQ(Ctx.getType(nullptr), nullptr);
75 #define CHK(LLVMCreate, SBCheck) \
76 Ctx.getType(llvm::Type::LLVMCreate(C))->SBCheck()
77 // Check isVoidTy().
78 EXPECT_TRUE(Ctx.getType(llvm::Type::getVoidTy(C))->isVoidTy());
79 EXPECT_TRUE(CHK(getVoidTy, isVoidTy));
80 // Check isHalfTy().
81 EXPECT_TRUE(CHK(getHalfTy, isHalfTy));
82 // Check isBFloatTy().
83 EXPECT_TRUE(CHK(getBFloatTy, isBFloatTy));
84 // Check is16bitFPTy().
85 EXPECT_TRUE(CHK(getHalfTy, is16bitFPTy));
86 // Check isFloatTy().
87 EXPECT_TRUE(CHK(getFloatTy, isFloatTy));
88 // Check isDoubleTy().
89 EXPECT_TRUE(CHK(getDoubleTy, isDoubleTy));
90 // Check isX86_FP80Ty().
91 EXPECT_TRUE(CHK(getX86_FP80Ty, isX86_FP80Ty));
92 // Check isFP128Ty().
93 EXPECT_TRUE(CHK(getFP128Ty, isFP128Ty));
94 // Check isPPC_FP128Ty().
95 EXPECT_TRUE(CHK(getPPC_FP128Ty, isPPC_FP128Ty));
96 // Check isIEEELikeFPTy().
97 EXPECT_TRUE(CHK(getFloatTy, isIEEELikeFPTy));
98 // Check isFloatingPointTy().
99 EXPECT_TRUE(CHK(getFloatTy, isFloatingPointTy));
100 EXPECT_TRUE(CHK(getDoubleTy, isFloatingPointTy));
101 // Check isMultiUnitFPType().
102 EXPECT_TRUE(CHK(getPPC_FP128Ty, isMultiUnitFPType));
103 EXPECT_FALSE(CHK(getFloatTy, isMultiUnitFPType));
104 // Check getFltSemantics().
105 EXPECT_EQ(&sandboxir::Type::getFloatTy(Ctx)->getFltSemantics(),
106 &llvm::Type::getFloatTy(C)->getFltSemantics());
107 // Check isX86_AMXTy().
108 EXPECT_TRUE(CHK(getX86_AMXTy, isX86_AMXTy));
109 // Check isTargetExtTy().
110 EXPECT_TRUE(Ctx.getType(llvm::TargetExtType::get(C, "foo"))->isTargetExtTy());
111 // Check isScalableTargetExtTy().
112 EXPECT_TRUE(Ctx.getType(llvm::TargetExtType::get(C, "aarch64.svcount"))
113 ->isScalableTargetExtTy());
114 // Check isScalableTy().
115 EXPECT_TRUE(Ctx.getType(llvm::ScalableVectorType::get(LLVMInt32Ty, 2u))
116 ->isScalableTy());
117 // Check isFPOrFPVectorTy().
118 EXPECT_TRUE(CHK(getFloatTy, isFPOrFPVectorTy));
119 EXPECT_FALSE(CHK(getInt32Ty, isFPOrFPVectorTy));
120 // Check isLabelTy().
121 EXPECT_TRUE(CHK(getLabelTy, isLabelTy));
122 // Check isMetadataTy().
123 EXPECT_TRUE(CHK(getMetadataTy, isMetadataTy));
124 // Check isTokenTy().
125 EXPECT_TRUE(CHK(getTokenTy, isTokenTy));
126 // Check isIntegerTy().
127 EXPECT_TRUE(CHK(getInt32Ty, isIntegerTy));
128 EXPECT_FALSE(CHK(getFloatTy, isIntegerTy));
129 // Check isIntegerTy(Bitwidth).
130 EXPECT_TRUE(LLVMInt32Ty->isIntegerTy(32u));
131 EXPECT_FALSE(LLVMInt32Ty->isIntegerTy(31u));
132 EXPECT_FALSE(Ctx.getType(llvm::Type::getFloatTy(C))->isIntegerTy(32u));
133 // Check isIntOrIntVectorTy().
134 EXPECT_TRUE(LLVMInt32Ty->isIntOrIntVectorTy());
135 EXPECT_TRUE(Ctx.getType(llvm::FixedVectorType::get(LLVMInt32Ty, 8))
136 ->isIntOrIntVectorTy());
137 EXPECT_FALSE(Ctx.getType(LLVMFloatTy)->isIntOrIntVectorTy());
138 EXPECT_FALSE(Ctx.getType(llvm::FixedVectorType::get(LLVMFloatTy, 8))
139 ->isIntOrIntVectorTy());
140 // Check isIntOrPtrTy().
141 EXPECT_TRUE(Int32Ty->isIntOrPtrTy());
142 EXPECT_TRUE(Ctx.getType(llvm::PointerType::get(C, 0u))->isIntOrPtrTy());
143 EXPECT_FALSE(FloatTy->isIntOrPtrTy());
144 // Check isFunctionTy().
145 EXPECT_TRUE(Ctx.getType(llvm::FunctionType::get(LLVMInt32Ty, {}, false))
146 ->isFunctionTy());
147 // Check isStructTy().
148 EXPECT_TRUE(Ctx.getType(llvm::StructType::get(C))->isStructTy());
149 // Check isArrayTy().
150 EXPECT_TRUE(Ctx.getType(llvm::ArrayType::get(LLVMInt32Ty, 10))->isArrayTy());
151 // Check isPointerTy().
152 EXPECT_TRUE(Ctx.getType(llvm::PointerType::get(C, 0u))->isPointerTy());
153 // Check isPtrOrPtrVectroTy().
154 EXPECT_TRUE(
155 Ctx.getType(llvm::FixedVectorType::get(llvm::PointerType::get(C, 0u), 8u))
156 ->isPtrOrPtrVectorTy());
157 // Check isVectorTy().
158 EXPECT_TRUE(
159 Ctx.getType(llvm::FixedVectorType::get(LLVMInt32Ty, 8u))->isVectorTy());
160 // Check canLosslesslyBitCastTo().
161 auto *VecTy32x4 = Ctx.getType(llvm::FixedVectorType::get(LLVMInt32Ty, 4u));
162 auto *VecTy32x2 = Ctx.getType(llvm::FixedVectorType::get(LLVMInt32Ty, 2u));
163 auto *VecTy8x16 = Ctx.getType(llvm::FixedVectorType::get(LLVMInt8Ty, 16u));
164 EXPECT_TRUE(VecTy32x4->canLosslesslyBitCastTo(VecTy8x16));
165 EXPECT_FALSE(VecTy32x4->canLosslesslyBitCastTo(VecTy32x2));
166 // Check isEmptyTy().
167 EXPECT_TRUE(Ctx.getType(llvm::StructType::get(C))->isEmptyTy());
168 // Check isFirstClassType().
169 EXPECT_TRUE(Int32Ty->isFirstClassType());
170 // Check isSingleValueType().
171 EXPECT_TRUE(Int32Ty->isSingleValueType());
172 // Check isAggregateType().
173 EXPECT_FALSE(Int32Ty->isAggregateType());
174 // Check isSized().
175 SmallPtrSet<sandboxir::Type *, 1> Visited;
176 EXPECT_TRUE(Int32Ty->isSized(&Visited));
177 // Check getPrimitiveSizeInBits().
178 EXPECT_EQ(VecTy32x2->getPrimitiveSizeInBits(), 32u * 2);
179 // Check getScalarSizeInBits().
180 EXPECT_EQ(VecTy32x2->getScalarSizeInBits(), 32u);
181 // Check getFPMantissaWidth().
182 EXPECT_EQ(FloatTy->getFPMantissaWidth(), LLVMFloatTy->getFPMantissaWidth());
183 // Check isIEEE().
184 EXPECT_EQ(FloatTy->isIEEE(), LLVMFloatTy->isIEEE());
185 // Check getScalarType().
186 EXPECT_EQ(
187 Ctx.getType(llvm::FixedVectorType::get(LLVMInt32Ty, 8u))->getScalarType(),
188 Int32Ty);
190 #define CHK_GET(TY) \
191 EXPECT_EQ(Ctx.getType(llvm::Type::get##TY##Ty(C)), \
192 sandboxir::Type::get##TY##Ty(Ctx))
193 // Check getInt64Ty().
194 CHK_GET(Int64);
195 // Check getInt32Ty().
196 CHK_GET(Int32);
197 // Check getInt16Ty().
198 CHK_GET(Int16);
199 // Check getInt8Ty().
200 CHK_GET(Int8);
201 // Check getInt1Ty().
202 CHK_GET(Int1);
203 // Check getDoubleTy().
204 CHK_GET(Double);
205 // Check getFloatTy().
206 CHK_GET(Float);
209 TEST_F(SandboxTypeTest, PointerType) {
210 parseIR(C, R"IR(
211 define void @foo(ptr %ptr) {
212 ret void
214 )IR");
215 llvm::Function *LLVMF = &*M->getFunction("foo");
216 sandboxir::Context Ctx(C);
217 auto *F = Ctx.createFunction(LLVMF);
218 // Check classof(), creation.
219 auto *PtrTy = cast<sandboxir::PointerType>(F->getArg(0)->getType());
220 // Check get(ElementType, AddressSpace).
221 auto *NewPtrTy =
222 sandboxir::PointerType::get(sandboxir::Type::getInt32Ty(Ctx), 0u);
223 EXPECT_EQ(NewPtrTy, PtrTy);
224 // Check get(Ctx, AddressSpace).
225 auto *NewPtrTy2 = sandboxir::PointerType::get(Ctx, 0u);
226 EXPECT_EQ(NewPtrTy2, PtrTy);
229 TEST_F(SandboxTypeTest, ArrayType) {
230 parseIR(C, R"IR(
231 define void @foo([2 x i8] %v0) {
232 ret void
234 )IR");
235 llvm::Function *LLVMF = &*M->getFunction("foo");
236 sandboxir::Context Ctx(C);
237 auto *F = Ctx.createFunction(LLVMF);
238 // Check classof(), creation.
239 [[maybe_unused]] auto *ArrayTy =
240 cast<sandboxir::ArrayType>(F->getArg(0)->getType());
241 // Check get().
242 auto *NewArrayTy =
243 sandboxir::ArrayType::get(sandboxir::Type::getInt8Ty(Ctx), 2u);
244 EXPECT_EQ(NewArrayTy, ArrayTy);
247 TEST_F(SandboxTypeTest, StructType) {
248 parseIR(C, R"IR(
249 define void @foo({i32, i8} %v0) {
250 ret void
252 )IR");
253 llvm::Function *LLVMF = &*M->getFunction("foo");
254 sandboxir::Context Ctx(C);
255 auto *F = Ctx.createFunction(LLVMF);
256 auto *Int32Ty = sandboxir::Type::getInt32Ty(Ctx);
257 auto *Int8Ty = sandboxir::Type::getInt8Ty(Ctx);
258 // Check classof(), creation.
259 [[maybe_unused]] auto *StructTy =
260 cast<sandboxir::StructType>(F->getArg(0)->getType());
261 // Check get().
262 auto *NewStructTy = sandboxir::StructType::get(Ctx, {Int32Ty, Int8Ty});
263 EXPECT_EQ(NewStructTy, StructTy);
264 // Check get(Packed).
265 auto *NewStructTyPacked =
266 sandboxir::StructType::get(Ctx, {Int32Ty, Int8Ty}, /*Packed=*/true);
267 EXPECT_NE(NewStructTyPacked, StructTy);
268 EXPECT_TRUE(NewStructTyPacked->isPacked());
271 TEST_F(SandboxTypeTest, VectorType) {
272 parseIR(C, R"IR(
273 define void @foo(<4 x i16> %vi0, <4 x float> %vf1, i8 %i0) {
274 ret void
276 )IR");
277 llvm::Function *LLVMF = &*M->getFunction("foo");
278 sandboxir::Context Ctx(C);
279 auto *F = Ctx.createFunction(LLVMF);
280 // Check classof(), creation, accessors
281 auto *VecTy = cast<sandboxir::VectorType>(F->getArg(0)->getType());
282 EXPECT_TRUE(VecTy->getElementType()->isIntegerTy(16));
283 EXPECT_EQ(VecTy->getElementCount(), ElementCount::getFixed(4));
285 // get(ElementType, NumElements, Scalable)
286 EXPECT_EQ(sandboxir::VectorType::get(sandboxir::Type::getInt16Ty(Ctx), 4,
287 /*Scalable=*/false),
288 F->getArg(0)->getType());
289 // get(ElementType, Other)
290 EXPECT_EQ(sandboxir::VectorType::get(
291 sandboxir::Type::getInt16Ty(Ctx),
292 cast<sandboxir::VectorType>(F->getArg(0)->getType())),
293 F->getArg(0)->getType());
294 auto *FVecTy = cast<sandboxir::VectorType>(F->getArg(1)->getType());
295 EXPECT_TRUE(FVecTy->getElementType()->isFloatTy());
296 // getInteger
297 auto *IVecTy = sandboxir::VectorType::getInteger(FVecTy);
298 EXPECT_TRUE(IVecTy->getElementType()->isIntegerTy(32));
299 EXPECT_EQ(IVecTy->getElementCount(), FVecTy->getElementCount());
300 // getExtendedElementCountVectorType
301 auto *ExtVecTy = sandboxir::VectorType::getExtendedElementVectorType(IVecTy);
302 EXPECT_TRUE(ExtVecTy->getElementType()->isIntegerTy(64));
303 EXPECT_EQ(ExtVecTy->getElementCount(), VecTy->getElementCount());
304 // getTruncatedElementVectorType
305 auto *TruncVecTy =
306 sandboxir::VectorType::getTruncatedElementVectorType(IVecTy);
307 EXPECT_TRUE(TruncVecTy->getElementType()->isIntegerTy(16));
308 EXPECT_EQ(TruncVecTy->getElementCount(), VecTy->getElementCount());
309 // getSubdividedVectorType
310 auto *SubVecTy = sandboxir::VectorType::getSubdividedVectorType(VecTy, 1);
311 EXPECT_TRUE(SubVecTy->getElementType()->isIntegerTy(8));
312 EXPECT_EQ(SubVecTy->getElementCount(), ElementCount::getFixed(8));
313 // getHalfElementsVectorType
314 auto *HalfVecTy = sandboxir::VectorType::getHalfElementsVectorType(VecTy);
315 EXPECT_TRUE(HalfVecTy->getElementType()->isIntegerTy(16));
316 EXPECT_EQ(HalfVecTy->getElementCount(), ElementCount::getFixed(2));
317 // getDoubleElementsVectorType
318 auto *DoubleVecTy = sandboxir::VectorType::getDoubleElementsVectorType(VecTy);
319 EXPECT_TRUE(DoubleVecTy->getElementType()->isIntegerTy(16));
320 EXPECT_EQ(DoubleVecTy->getElementCount(), ElementCount::getFixed(8));
321 // isValidElementType
322 auto *I8Type = F->getArg(2)->getType();
323 EXPECT_TRUE(I8Type->isIntegerTy());
324 EXPECT_TRUE(sandboxir::VectorType::isValidElementType(I8Type));
325 EXPECT_FALSE(sandboxir::VectorType::isValidElementType(FVecTy));
328 TEST_F(SandboxTypeTest, FixedVectorType) {
329 parseIR(C, R"IR(
330 define void @foo(<4 x i16> %vi0, <4 x float> %vf1, i8 %i0) {
331 ret void
333 )IR");
334 llvm::Function *LLVMF = &*M->getFunction("foo");
335 sandboxir::Context Ctx(C);
336 auto *F = Ctx.createFunction(LLVMF);
337 // Check classof(), creation, accessors
338 auto *Vec4i16Ty = cast<sandboxir::FixedVectorType>(F->getArg(0)->getType());
339 EXPECT_TRUE(Vec4i16Ty->getElementType()->isIntegerTy(16));
340 EXPECT_EQ(Vec4i16Ty->getElementCount(), ElementCount::getFixed(4));
342 // get(ElementType, NumElements)
343 EXPECT_EQ(
344 sandboxir::FixedVectorType::get(sandboxir::Type::getInt16Ty(Ctx), 4),
345 F->getArg(0)->getType());
346 // get(ElementType, Other)
347 EXPECT_EQ(sandboxir::FixedVectorType::get(
348 sandboxir::Type::getInt16Ty(Ctx),
349 cast<sandboxir::FixedVectorType>(F->getArg(0)->getType())),
350 F->getArg(0)->getType());
351 auto *Vec4FTy = cast<sandboxir::FixedVectorType>(F->getArg(1)->getType());
352 EXPECT_TRUE(Vec4FTy->getElementType()->isFloatTy());
353 // getInteger
354 auto *Vec4i32Ty = sandboxir::FixedVectorType::getInteger(Vec4FTy);
355 EXPECT_TRUE(Vec4i32Ty->getElementType()->isIntegerTy(32));
356 EXPECT_EQ(Vec4i32Ty->getElementCount(), Vec4FTy->getElementCount());
357 // getExtendedElementCountVectorType
358 auto *Vec4i64Ty =
359 sandboxir::FixedVectorType::getExtendedElementVectorType(Vec4i16Ty);
360 EXPECT_TRUE(Vec4i64Ty->getElementType()->isIntegerTy(32));
361 EXPECT_EQ(Vec4i64Ty->getElementCount(), Vec4i16Ty->getElementCount());
362 // getTruncatedElementVectorType
363 auto *Vec4i8Ty =
364 sandboxir::FixedVectorType::getTruncatedElementVectorType(Vec4i16Ty);
365 EXPECT_TRUE(Vec4i8Ty->getElementType()->isIntegerTy(8));
366 EXPECT_EQ(Vec4i8Ty->getElementCount(), Vec4i8Ty->getElementCount());
367 // getSubdividedVectorType
368 auto *Vec8i8Ty =
369 sandboxir::FixedVectorType::getSubdividedVectorType(Vec4i16Ty, 1);
370 EXPECT_TRUE(Vec8i8Ty->getElementType()->isIntegerTy(8));
371 EXPECT_EQ(Vec8i8Ty->getElementCount(), ElementCount::getFixed(8));
372 // getNumElements
373 EXPECT_EQ(Vec8i8Ty->getNumElements(), 8u);
374 // getHalfElementsVectorType
375 auto *Vec2i16Ty =
376 sandboxir::FixedVectorType::getHalfElementsVectorType(Vec4i16Ty);
377 EXPECT_TRUE(Vec2i16Ty->getElementType()->isIntegerTy(16));
378 EXPECT_EQ(Vec2i16Ty->getElementCount(), ElementCount::getFixed(2));
379 // getDoubleElementsVectorType
380 auto *Vec8i16Ty =
381 sandboxir::FixedVectorType::getDoubleElementsVectorType(Vec4i16Ty);
382 EXPECT_TRUE(Vec8i16Ty->getElementType()->isIntegerTy(16));
383 EXPECT_EQ(Vec8i16Ty->getElementCount(), ElementCount::getFixed(8));
386 TEST_F(SandboxTypeTest, ScalableVectorType) {
387 parseIR(C, R"IR(
388 define void @foo(<vscale x 4 x i16> %vi0, <vscale x 4 x float> %vf1, i8 %i0) {
389 ret void
391 )IR");
392 llvm::Function *LLVMF = &*M->getFunction("foo");
393 sandboxir::Context Ctx(C);
394 auto *F = Ctx.createFunction(LLVMF);
395 // Check classof(), creation, accessors
396 auto *Vec4i16Ty =
397 cast<sandboxir::ScalableVectorType>(F->getArg(0)->getType());
398 EXPECT_TRUE(Vec4i16Ty->getElementType()->isIntegerTy(16));
399 EXPECT_EQ(Vec4i16Ty->getMinNumElements(), 4u);
401 // get(ElementType, NumElements)
402 EXPECT_EQ(
403 sandboxir::ScalableVectorType::get(sandboxir::Type::getInt16Ty(Ctx), 4),
404 F->getArg(0)->getType());
405 // get(ElementType, Other)
406 EXPECT_EQ(sandboxir::ScalableVectorType::get(
407 sandboxir::Type::getInt16Ty(Ctx),
408 cast<sandboxir::ScalableVectorType>(F->getArg(0)->getType())),
409 F->getArg(0)->getType());
410 auto *Vec4FTy = cast<sandboxir::ScalableVectorType>(F->getArg(1)->getType());
411 EXPECT_TRUE(Vec4FTy->getElementType()->isFloatTy());
412 // getInteger
413 auto *Vec4i32Ty = sandboxir::ScalableVectorType::getInteger(Vec4FTy);
414 EXPECT_TRUE(Vec4i32Ty->getElementType()->isIntegerTy(32));
415 EXPECT_EQ(Vec4i32Ty->getMinNumElements(), Vec4FTy->getMinNumElements());
416 // getExtendedElementCountVectorType
417 auto *Vec4i64Ty =
418 sandboxir::ScalableVectorType::getExtendedElementVectorType(Vec4i16Ty);
419 EXPECT_TRUE(Vec4i64Ty->getElementType()->isIntegerTy(32));
420 EXPECT_EQ(Vec4i64Ty->getMinNumElements(), Vec4i16Ty->getMinNumElements());
421 // getTruncatedElementVectorType
422 auto *Vec4i8Ty =
423 sandboxir::ScalableVectorType::getTruncatedElementVectorType(Vec4i16Ty);
424 EXPECT_TRUE(Vec4i8Ty->getElementType()->isIntegerTy(8));
425 EXPECT_EQ(Vec4i8Ty->getMinNumElements(), Vec4i8Ty->getMinNumElements());
426 // getSubdividedVectorType
427 auto *Vec8i8Ty =
428 sandboxir::ScalableVectorType::getSubdividedVectorType(Vec4i16Ty, 1);
429 EXPECT_TRUE(Vec8i8Ty->getElementType()->isIntegerTy(8));
430 EXPECT_EQ(Vec8i8Ty->getMinNumElements(), 8u);
431 // getMinNumElements
432 EXPECT_EQ(Vec8i8Ty->getMinNumElements(), 8u);
433 // getHalfElementsVectorType
434 auto *Vec2i16Ty =
435 sandboxir::ScalableVectorType::getHalfElementsVectorType(Vec4i16Ty);
436 EXPECT_TRUE(Vec2i16Ty->getElementType()->isIntegerTy(16));
437 EXPECT_EQ(Vec2i16Ty->getMinNumElements(), 2u);
438 // getDoubleElementsVectorType
439 auto *Vec8i16Ty =
440 sandboxir::ScalableVectorType::getDoubleElementsVectorType(Vec4i16Ty);
441 EXPECT_TRUE(Vec8i16Ty->getElementType()->isIntegerTy(16));
442 EXPECT_EQ(Vec8i16Ty->getMinNumElements(), 8u);
445 TEST_F(SandboxTypeTest, FunctionType) {
446 parseIR(C, R"IR(
447 define void @foo() {
448 ret void
450 )IR");
451 llvm::Function *LLVMF = &*M->getFunction("foo");
452 sandboxir::Context Ctx(C);
453 auto *F = Ctx.createFunction(LLVMF);
454 // Check classof(), creation.
455 [[maybe_unused]] auto *FTy =
456 cast<sandboxir::FunctionType>(F->getFunctionType());
459 TEST_F(SandboxTypeTest, IntegerType) {
460 parseIR(C, R"IR(
461 define void @foo(i32 %v0) {
462 ret void
464 )IR");
465 llvm::Function *LLVMF = &*M->getFunction("foo");
466 sandboxir::Context Ctx(C);
467 auto *F = Ctx.createFunction(LLVMF);
468 // Check classof(), creation.
469 auto *Int32Ty = cast<sandboxir::IntegerType>(F->getArg(0)->getType());
470 // Check get().
471 auto *NewInt32Ty = sandboxir::IntegerType::get(Ctx, 32u);
472 EXPECT_EQ(NewInt32Ty, Int32Ty);