1//===- AffineExprTest.cpp - unit tests for affine expression API ----------===//
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 "mlir/IR/AffineExpr.h"
10#include "mlir/IR/Builders.h"
11#include "gtest/gtest.h"
12
13using namespace mlir;
14
15// Test creating AffineExprs using the overloaded binary operators.
16TEST(AffineExprTest, constructFromBinaryOperators) {
17 MLIRContext ctx;
18 OpBuilder b(&ctx);
19
20 auto d0 = b.getAffineDimExpr(position: 0);
21 auto d1 = b.getAffineDimExpr(position: 1);
22
23 auto sum = d0 + d1;
24 auto difference = d0 - d1;
25 auto product = d0 * d1;
26 auto remainder = d0 % d1;
27
28 ASSERT_EQ(sum.getKind(), AffineExprKind::Add);
29 ASSERT_EQ(difference.getKind(), AffineExprKind::Add);
30 ASSERT_EQ(product.getKind(), AffineExprKind::Mul);
31 ASSERT_EQ(remainder.getKind(), AffineExprKind::Mod);
32}
33

source code of mlir/unittests/IR/AffineExprTest.cpp