6 #include <gtest/gtest.h>
13 #include <llvm/IR/BasicBlock.h>
14 #include <llvm/IR/IRBuilder.h>
15 #include <llvm/IR/Module.h>
23 bool has_select =
false;
25 auto bb =
dynamic_cast<const BasicBlock *
>(cfg->entry()->OutEdge(0)->sink());
27 has_select = has_select || is<OP>(tac);
32 TEST(SelectTests, test_scalar_select)
34 auto setup = [](llvm::LLVMContext & ctx)
38 std::unique_ptr<Module> module(
new Module(
"module", ctx));
40 auto int1 = Type::getIntNTy(ctx, 1);
41 auto int64 = Type::getIntNTy(ctx, 64);
43 auto fctargs = std::vector<Type *>({ int1, int64, int64 });
44 auto fcttype = FunctionType::get(int64, fctargs,
false);
45 auto fct = Function::Create(fcttype, GlobalValue::ExternalLinkage,
"f", module.get());
47 auto bb = BasicBlock::Create(ctx,
"bb", fct);
49 IRBuilder<> builder(bb);
50 auto r = builder.CreateSelect(fct->arg_begin(), fct->arg_begin() + 1, fct->arg_begin() + 2);
56 llvm::LLVMContext ctx;
57 auto llvmModule = setup(ctx);
58 llvmModule->print(llvm::errs(),
nullptr);
61 print(*ipgmod, stdout);
63 EXPECT_TRUE(contains<jlm::llvm::SelectOperation>(*ipgmod,
"f"));
66 TEST(SelectTests, test_vector_select)
68 auto setup = [](llvm::LLVMContext & ctx)
72 std::unique_ptr<Module> module(
new Module(
"module", ctx));
74 auto vint1 = VectorType::get(Type::getIntNTy(ctx, 1), 4,
false);
75 auto vint64 = VectorType::get(Type::getIntNTy(ctx, 64), 4,
false);
77 auto fctargs = std::vector<Type *>({ vint1, vint64, vint64 });
78 auto fcttype = FunctionType::get(vint64, fctargs,
false);
79 auto fct = Function::Create(fcttype, GlobalValue::ExternalLinkage,
"f", module.get());
81 auto bb = BasicBlock::Create(ctx,
"bb", fct);
83 IRBuilder<> builder(bb);
84 auto r = builder.CreateSelect(fct->arg_begin(), fct->arg_begin() + 1, fct->arg_begin() + 2);
90 llvm::LLVMContext ctx;
91 auto llvmModule = setup(ctx);
92 llvmModule->print(llvm::errs(),
nullptr);
95 print(*ipgmod, stdout);
97 EXPECT_TRUE(contains<jlm::llvm::VectorSelectOperation>(*ipgmod,
"f"));
static bool contains(const jlm::llvm::InterProceduralGraphModule &module, const std::string &fctname)
TEST(SelectTests, test_scalar_select)
InterProceduralGraph & ipgraph() noexcept
const InterProceduralGraphNode * find(const std::string &name) const noexcept
Global memory state passed between functions.
void print(const AggregationNode &n, const AnnotationMap &dm, FILE *out)
std::unique_ptr< InterProceduralGraphModule > ConvertLlvmModule(::llvm::Module &llvmModule)