Jlm
Loading...
Searching...
No Matches
SpecializedArithmeticIntrinsicOperationTests.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2025 Nico Reißmann <nico.reissmann@gmail.com>
3 * See COPYING for terms of redistribution.
4 */
5
6#include <gtest/gtest.h>
7
8#include <llvm/IR/BasicBlock.h>
9#include <llvm/IR/IRBuilder.h>
10#include <llvm/IR/Module.h>
11
14#include <jlm/llvm/ir/print.hpp>
15
16TEST(ViewTests, TestFMulAdd)
17{
18 // Arrange
19 using namespace llvm;
20
21 LLVMContext context;
22 Module llvmModule("module", context);
23
24 {
25 auto doubleType = Type::getDoubleTy(context);
26
27 const auto functionArguments = std::vector<Type *>({ doubleType, doubleType, doubleType });
28 const auto functionType = FunctionType::get(doubleType, functionArguments, false);
29 const auto function =
30 Function::Create(functionType, GlobalValue::ExternalLinkage, "f", &llvmModule);
31
32 const auto basicBlock = BasicBlock::Create(context, "basicBlock", function);
33
34 IRBuilder builder(basicBlock);
35 const auto returnValue = builder.CreateIntrinsic(
36 Intrinsic::fmuladd,
37 { doubleType },
38 { function->getArg(0), function->getArg(1), function->getArg(2) });
39 builder.CreateRet(returnValue);
40 }
41
42 llvmModule.print(llvm::errs(), nullptr);
43
44 // Act
45 const auto ipgModule = jlm::llvm::ConvertLlvmModule(llvmModule);
46 print(*ipgModule, stdout);
47
48 // Assert
49 {
50 const auto controlFlowGraph =
51 dynamic_cast<const jlm::llvm::FunctionNode *>(ipgModule->ipgraph().find("f"))->cfg();
52 const auto basicBlock =
53 dynamic_cast<const jlm::llvm::BasicBlock *>(controlFlowGraph->entry()->OutEdge(0)->sink());
54 const auto fMulAdd = *std::next(basicBlock->rbegin(), 1);
55 EXPECT_TRUE(jlm::llvm::is<jlm::llvm::FMulAddIntrinsicOperation>(fMulAdd));
56 }
57}
static void print(const jlm::util::DisjointSet< int >::Set &set)
TEST(ViewTests, TestFMulAdd)
std::unique_ptr< InterProceduralGraphModule > ConvertLlvmModule(::llvm::Module &llvmModule)