Skip to content

Commit bd6cd92

Browse files
authored
[MLIR][OpenMP][NFC] Use header guards for tblgen'd definitions (#146684)
Currently the generated `.h.inc` files are included coarse-grained header files that just happen to work in the current source. But if at another header, call it `A.h`, a definition from e.g. "OpenMPOpsEnums.h.inc" is needed, it cannot be included there because it `A.h` is also included in `B.h` that uses `OpenMPClauseOperands.h` which already includes `OpenMPOpsEnums.h.inc`. So the content of `OpenMPOpsEnums.h.inc` appears twice in the translation unit result in a compile failure because the same enum cannot be defined twice. This patch tries to use more fine-grained include header for generated content protected by header guards, so `OpenMPOpsEnums.h` can be included when ever needed. Some is done with `OpenMPOpsAttributes.h`. Needed for #144785. Also fixes the recursive #include of `OpenMPDialect.h` and `OpenMPInterfaces.h`. Patch extracted out of #144785
1 parent 2dba752 commit bd6cd92

File tree

5 files changed

+35
-8
lines changed

5 files changed

+35
-8
lines changed

mlir/include/mlir/Dialect/OpenMP/OpenMPClauseOperands.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,10 @@
1515
#ifndef MLIR_DIALECT_OPENMP_OPENMPCLAUSEOPERANDS_H_
1616
#define MLIR_DIALECT_OPENMP_OPENMPCLAUSEOPERANDS_H_
1717

18+
#include "mlir/Dialect/OpenMP/OpenMPOpsAttributes.h"
1819
#include "mlir/IR/BuiltinAttributes.h"
1920
#include "llvm/ADT/SmallVector.h"
2021

21-
#include "mlir/Dialect/OpenMP/OpenMPOpsEnums.h.inc"
22-
23-
#define GET_ATTRDEF_CLASSES
24-
#include "mlir/Dialect/OpenMP/OpenMPOpsAttributes.h.inc"
25-
2622
#include "mlir/Dialect/OpenMP/OpenMPClauseOps.h.inc"
2723

2824
namespace mlir {

mlir/include/mlir/Dialect/OpenMP/OpenMPDialect.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
1717
#include "mlir/Dialect/OpenACCMPCommon/Interfaces/AtomicInterfaces.h"
1818
#include "mlir/Dialect/OpenACCMPCommon/Interfaces/OpenACCMPOpsInterfaces.h"
19+
#include "mlir/Dialect/OpenMP/OpenMPInterfaces.h"
1920
#include "mlir/IR/Dialect.h"
2021
#include "mlir/IR/OpDefinition.h"
2122
#include "mlir/IR/PatternMatch.h"
@@ -33,8 +34,6 @@
3334

3435
#include "mlir/Dialect/OpenMP/OpenMPTypeInterfaces.h.inc"
3536

36-
#include "mlir/Dialect/OpenMP/OpenMPInterfaces.h"
37-
3837
#define GET_OP_CLASSES
3938
#include "mlir/Dialect/OpenMP/OpenMPOps.h.inc"
4039

mlir/include/mlir/Dialect/OpenMP/OpenMPInterfaces.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
#ifndef MLIR_DIALECT_OPENMP_OPENMPINTERFACES_H_
1414
#define MLIR_DIALECT_OPENMP_OPENMPINTERFACES_H_
1515

16-
#include "mlir/Dialect/LLVMIR/LLVMDialect.h"
16+
#include "mlir/Dialect/OpenMP/OpenMPClauseOperands.h"
17+
#include "mlir/Dialect/OpenMP/OpenMPOpsEnums.h"
1718
#include "mlir/IR/Dialect.h"
1819
#include "mlir/IR/OpDefinition.h"
1920
#include "mlir/IR/PatternMatch.h"
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//===- OpenMPOpsAttributes.h ------------------------------------*- C++ -*-===//
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+
#ifndef MLIR_DIALECT_OPENMP_OPENMPOPSATTRIBUTES_H_
10+
#define MLIR_DIALECT_OPENMP_OPENMPOPSATTRIBUTES_H_
11+
12+
#include "mlir/Dialect/OpenMP/OpenMPOpsEnums.h"
13+
14+
#define GET_ATTRDEF_CLASSES
15+
#include "mlir/Dialect/OpenMP/OpenMPOpsAttributes.h.inc"
16+
17+
#endif // MLIR_DIALECT_OPENMP_OPENMPOPSATTRIBUTES_H_
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//===- OpenMPOpsEnums.h -----------------------------------------*- C++ -*-===//
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+
#ifndef MLIR_DIALECT_OPENMP_OPENMPOPSENUMS_H_
10+
#define MLIR_DIALECT_OPENMP_OPENMPOPSENUMS_H_
11+
12+
#include "mlir/Dialect/OpenMP/OpenMPOpsEnums.h.inc"
13+
14+
#endif // MLIR_DIALECT_OPENMP_OPENMPOPSENUMS_H_

0 commit comments

Comments
 (0)