brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.7 KiB · 3f8b59a Raw
77 lines · cpp
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-exception6//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 19using namespace fir;20 21struct StringAttributesTests : public testing::Test {22public: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 tuneCPU = "generic";38  std::string targetFeatures = "+gfx9-insts,+wavefrontsize64";39  mlir::ModuleOp mod;40};41 42TEST_F(StringAttributesTests, moduleStringAttrTest) {43  setTargetTriple(mod, target);44  setKindMapping(mod, *kindMap);45  setTargetCPU(mod, targetCPU);46  setTuneCPU(mod, tuneCPU);47  setTargetFeatures(mod, targetFeatures);48 49  auto triple = getTargetTriple(mod);50  EXPECT_EQ(triple.getArch(), llvm::Triple::ArchType::ppc64le);51  EXPECT_EQ(triple.getOS(), llvm::Triple::OSType::Linux);52 53  auto map = getKindMapping(mod);54  EXPECT_EQ(map.defaultsToString(), "a10c14d28i40l41r42");55 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);64 65  EXPECT_EQ(getTargetCPU(mod), targetCPU);66  EXPECT_EQ(getTuneCPU(mod), tuneCPU);67 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");74}75 76// main() from gtest_main77