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 hasInstruction =
false;
24 auto controlFlowGraph =
28 for (
auto threeAddressCode : *basicBlock)
29 hasInstruction = hasInstruction || jlm::llvm::is<OP>(threeAddressCode);
31 return hasInstruction;
34 TEST(FNegTests, TestFNegScalar)
36 auto Setup = [](llvm::LLVMContext & context)
40 std::unique_ptr<Module> module(
new Module(
"module", context));
42 auto doubleType = Type::getDoubleTy(context);
44 auto functionArguments = std::vector<Type *>({ doubleType });
45 auto functionType = FunctionType::get(doubleType, functionArguments,
false);
46 auto function = Function::Create(functionType, GlobalValue::ExternalLinkage,
"f", module.get());
48 auto basicBlock = BasicBlock::Create(context,
"basicBlock",
function);
50 IRBuilder<> builder(basicBlock);
51 auto returnValue = builder.CreateFNeg(function->arg_begin());
52 builder.CreateRet(returnValue);
57 llvm::LLVMContext context;
58 auto llvmModule = Setup(context);
59 llvmModule->print(llvm::errs(),
nullptr);
62 print(*ipgModule, stdout);
64 EXPECT_TRUE(Contains<jlm::llvm::FNegOperation>(*ipgModule,
"f"));
67 TEST(FNegTests, TestFNegVector)
69 auto Setup = [](llvm::LLVMContext & context)
73 std::unique_ptr<Module> module(
new Module(
"module", context));
75 auto vectorType = VectorType::get(Type::getDoubleTy(context), 2,
false);
77 auto functionArguments = std::vector<Type *>({ vectorType });
78 auto functionType = FunctionType::get(vectorType, functionArguments,
false);
79 auto function = Function::Create(functionType, GlobalValue::ExternalLinkage,
"f", module.get());
81 auto basicBlock = BasicBlock::Create(context,
"basicBlock",
function);
83 IRBuilder<> builder(basicBlock);
84 auto returnValue = builder.CreateFNeg(function->arg_begin());
85 builder.CreateRet(returnValue);
90 llvm::LLVMContext context;
91 auto llvmModule = Setup(context);
92 llvmModule->print(llvm::errs(),
nullptr);
95 print(*ipgModule, stdout);
97 EXPECT_TRUE(Contains<jlm::llvm::VectorUnaryOperation>(*ipgModule,
"f"));
TEST(FNegTests, TestFNegScalar)
static bool Contains(const jlm::llvm::InterProceduralGraphModule &module, const std::string &)
InterProceduralGraph & ipgraph() noexcept
const InterProceduralGraphNode * find(const std::string &name) const noexcept
void print(const AggregationNode &n, const AnnotationMap &dm, FILE *out)
std::unique_ptr< InterProceduralGraphModule > ConvertLlvmModule(::llvm::Module &llvmModule)