1 | //===- FIRContextTest.cpp -------------------------------------------------===// |
2 | // |
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 |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | |
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" |
17 | #include <string> |
18 | |
19 | using namespace fir; |
20 | |
21 | struct StringAttributesTests : public testing::Test { |
22 | public: |
23 | void SetUp() { |
24 | context.loadDialect<mlir::LLVM::LLVMDialect>(); |
25 | kindMap = new KindMapping(&context, kindMapInit, "r42a10c14d28i40l41" ); |
26 | mod = mlir::ModuleOp::create(mlir::UnknownLoc::get(&context)); |
27 | } |
28 | |
29 | void TearDown() { delete kindMap; } |
30 | |
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 targetFeatures = "+gfx9-insts,+wavefrontsize64" ; |
38 | mlir::ModuleOp mod; |
39 | }; |
40 | |
41 | TEST_F(StringAttributesTests, moduleStringAttrTest) { |
42 | setTargetTriple(mod, target); |
43 | setKindMapping(mod, *kindMap); |
44 | setTargetCPU(mod, targetCPU); |
45 | setTargetFeatures(mod, targetFeatures); |
46 | |
47 | auto triple = getTargetTriple(mod); |
48 | EXPECT_EQ(triple.getArch(), llvm::Triple::ArchType::ppc64le); |
49 | EXPECT_EQ(triple.getOS(), llvm::Triple::OSType::Linux); |
50 | |
51 | auto map = getKindMapping(mod); |
52 | EXPECT_EQ(map.defaultsToString(), "a10c14d28i40l41r42" ); |
53 | |
54 | auto mapStr = map.mapToString(); |
55 | EXPECT_EQ(mapStr.size(), kindMapInit.size()); |
56 | EXPECT_TRUE(mapStr.find("a1:8" ) != std::string::npos); |
57 | EXPECT_TRUE(mapStr.find("l3:24" ) != std::string::npos); |
58 | EXPECT_TRUE(mapStr.find("i10:80" ) != std::string::npos); |
59 | EXPECT_TRUE(mapStr.find("r11:PPC_FP128" ) != std::string::npos); |
60 | EXPECT_TRUE(mapStr.find("r54:Double" ) != std::string::npos); |
61 | EXPECT_TRUE(mapStr.find("r62:X86_FP80" ) != std::string::npos); |
62 | |
63 | EXPECT_EQ(getTargetCPU(mod), targetCPU); |
64 | |
65 | auto features = getTargetFeatures(mod); |
66 | auto featuresList = features.getFeatures(); |
67 | EXPECT_EQ(features.getFeaturesString(), targetFeatures); |
68 | EXPECT_EQ(featuresList.size(), 2u); |
69 | EXPECT_EQ(featuresList[0].str(), "+gfx9-insts" ); |
70 | EXPECT_EQ(featuresList[1].str(), "+wavefrontsize64" ); |
71 | } |
72 | |
73 | // main() from gtest_main |
74 | |