1 //===- FIRContextTest.cpp -------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "flang/Optimizer/Dialect/Support/FIRContext.h"
10 #include "gtest/gtest.h"
11 #include "mlir/Dialect/LLVMIR/LLVMAttrs.h"
12 #include "mlir/Dialect/LLVMIR/LLVMDialect.h"
13 #include "mlir/IR/BuiltinAttributes.h"
14 #include "mlir/IR/BuiltinOps.h"
15 #include "flang/Optimizer/Dialect/Support/KindMapping.h"
16 #include "llvm/TargetParser/Host.h"
21 struct StringAttributesTests
: public testing::Test
{
24 context
.loadDialect
<mlir::LLVM::LLVMDialect
>();
25 kindMap
= new KindMapping(&context
, kindMapInit
, "r42a10c14d28i40l41");
26 mod
= mlir::ModuleOp::create(mlir::UnknownLoc::get(&context
));
29 void TearDown() { delete kindMap
; }
31 mlir::MLIRContext context
;
32 KindMapping
*kindMap
{};
33 std::string kindMapInit
=
34 "i10:80,l3:24,a1:8,r54:Double,r62:X86_FP80,r11:PPC_FP128";
35 std::string target
= "powerpc64le-unknown-linux-gnu";
36 std::string targetCPU
= "gfx90a";
37 std::string tuneCPU
= "generic";
38 std::string targetFeatures
= "+gfx9-insts,+wavefrontsize64";
42 TEST_F(StringAttributesTests
, moduleStringAttrTest
) {
43 setTargetTriple(mod
, target
);
44 setKindMapping(mod
, *kindMap
);
45 setTargetCPU(mod
, targetCPU
);
46 setTuneCPU(mod
, tuneCPU
);
47 setTargetFeatures(mod
, targetFeatures
);
49 auto triple
= getTargetTriple(mod
);
50 EXPECT_EQ(triple
.getArch(), llvm::Triple::ArchType::ppc64le
);
51 EXPECT_EQ(triple
.getOS(), llvm::Triple::OSType::Linux
);
53 auto map
= getKindMapping(mod
);
54 EXPECT_EQ(map
.defaultsToString(), "a10c14d28i40l41r42");
56 auto mapStr
= map
.mapToString();
57 EXPECT_EQ(mapStr
.size(), kindMapInit
.size());
58 EXPECT_TRUE(mapStr
.find("a1:8") != std::string::npos
);
59 EXPECT_TRUE(mapStr
.find("l3:24") != std::string::npos
);
60 EXPECT_TRUE(mapStr
.find("i10:80") != std::string::npos
);
61 EXPECT_TRUE(mapStr
.find("r11:PPC_FP128") != std::string::npos
);
62 EXPECT_TRUE(mapStr
.find("r54:Double") != std::string::npos
);
63 EXPECT_TRUE(mapStr
.find("r62:X86_FP80") != std::string::npos
);
65 EXPECT_EQ(getTargetCPU(mod
), targetCPU
);
66 EXPECT_EQ(getTuneCPU(mod
), tuneCPU
);
68 auto features
= getTargetFeatures(mod
);
69 auto featuresList
= features
.getFeatures();
70 EXPECT_EQ(features
.getFeaturesString(), targetFeatures
);
71 EXPECT_EQ(featuresList
.size(), 2u);
72 EXPECT_EQ(featuresList
[0].str(), "+gfx9-insts");
73 EXPECT_EQ(featuresList
[1].str(), "+wavefrontsize64");
76 // main() from gtest_main