48 int vectorization = GetParam();
51 llvm::LLVMContext context;
52 llvm::Module llvmModule(
"module", context);
54 llvm::Type * int64Type = llvm::Type::getInt64Ty(context);
55 llvm::Type * int32Type = llvm::Type::getInt32Ty(context);
56 llvm::Type * pointerType = llvm::PointerType::getUnqual(context);
59 if (vectorization != 0)
61 auto ec = llvm::ElementCount::getFixed(vectorization);
62 int64Type = llvm::VectorType::get(int64Type, ec);
63 int32Type = llvm::VectorType::get(int32Type, ec);
64 pointerType = llvm::VectorType::get(pointerType, ec);
68 size_t sizeofX = 8 * std::max(1, vectorization);
69 auto ec = llvm::ElementCount::getFixed(sizeofX);
70 llvm::Type * byteVectorType = llvm::VectorType::get(llvm::Type::getInt8Ty(context), ec);
73 llvm::FunctionType::get(byteVectorType, llvm::ArrayRef<llvm::Type *>({ int32Type }),
false);
75 llvm::Function::Create(functionType, llvm::GlobalValue::ExternalLinkage,
"f", &llvmModule);
77 auto basicBlock = llvm::BasicBlock::Create(context,
"bb0", function);
79 llvm::IRBuilder<> builder(basicBlock);
80 auto zext = builder.CreateZExt(function->arg_begin(), int64Type);
81 auto trunc = builder.CreateTrunc(zext, int32Type);
82 auto sext = builder.CreateSExt(trunc, int64Type);
83 auto inttoptr = builder.CreateIntToPtr(sext, pointerType);
84 auto ptrtoint = builder.CreatePtrToInt(inttoptr, int64Type);
85 auto bitcast = builder.CreateBitCast(ptrtoint, byteVectorType);
86 builder.CreateRet(bitcast);
88 llvmModule.print(llvm::errs(),
nullptr);
92 print(*ipgModule, stdout);
104 auto controlFlowGraph =
105 dynamic_cast<const FunctionNode *
>(ipgModule->ipgraph().find(
"f"))->cfg();
109 size_t numUnaryVector = 0;
113 size_t numInttoptr = 0;
114 size_t numPtrtoint = 0;
115 size_t numBitcasts = 0;
116 for (
auto it = basicBlock->begin(); it != basicBlock->end(); it++)
118 auto op = &(*it)->operation();
124 op = &vecOp->operation();
127 std::cout << op->debug_string() << std::endl;
141 EXPECT_EQ(*op.argument(0), *jlmBits32);
142 EXPECT_EQ(*op.result(0), *jlmBits64);
147 EXPECT_EQ(*op.argument(0), *jlmBits64);
148 EXPECT_EQ(*op.result(0), *jlmBits32);
153 EXPECT_EQ(*op.argument(0), *jlmBits32);
154 EXPECT_EQ(*op.result(0), *jlmBits64);
159 EXPECT_EQ(*op.argument(0), *jlmBits64);
160 EXPECT_EQ(*op.result(0), *jlmPointerType);
165 EXPECT_EQ(*op.argument(0), *jlmPointerType);
166 EXPECT_EQ(*op.result(0), *jlmBits64);
176 const auto jlmBits64Vector =
178 EXPECT_EQ(*op.argument(0), *jlmBits64Vector);
183 EXPECT_EQ(*op.argument(0), *jlmBits64);
185 EXPECT_EQ(*op.result(0), *jlmByteVectorType);
189 EXPECT_EQ(numUnaryVector, vectorization ? 5 : 0u);
190 EXPECT_EQ(numZext, 1u);
191 EXPECT_EQ(numTrunc, 1u);
192 EXPECT_EQ(numSext, 1u);
193 EXPECT_EQ(numInttoptr, 1u);
194 EXPECT_EQ(numPtrtoint, 1u);
195 EXPECT_EQ(numBitcasts, 1u);