Author: Konstantinos Parasyris
Date: 2026-10-30T06:46:42-07:00
New Revision: 16cb85f2711e89d6d893f61948ebdf579a1ca3e7

URL: 
https://github.com/llvm/llvm-project/commit/16cb85f2711e89d6d893f61948ebdf579a1ca3e7
DIFF: 
https://github.com/llvm/llvm-project/commit/16cb85f2711e89d6d893f61948ebdf579a1ca3e7.diff

LOG: [CIR] Shard generated operation definitions (NFC) (#232894)

`CIRDialect.cpp` includes the TableGen-generated definitions of all CIR
operations (`CIROps.cpp.inc`, ~5.1 MB). It is the slowest translation
unit in a ClangIR-enabled build and sits on the critical path to linking
`clang`. Nothing in the source is slow by itself: the time is spread
over ~23k generated functions, ~80% of it in the optimizer and code
generation.

This patch splits the generated definitions into eight shards. It
follows the approach used for the
LLVM, NVVM, ROCDL, and SPIR-V dialects (#221813, #221812, #221729,
#221811):

- `CIROps.{h,cpp}.inc` are generated with `-op-shard-count=8`.
- `mlir-src-sharder` produces `CIROpDefinitions.{0..7}.cpp` from a new
`CIROpDefinitions.cpp` template, and these are compiled as part of
`MLIRCIR`.
- `CIRDialect::initialize()` uses the generated
`registerCIRDialectOperations` hook instead of
`addOperations<GET_OP_LIST>`.
- The custom-directive parsers and printers called by the generated code
(the `custom<...>` entries in `CIROps.td`) stay in `CIRDialect.cpp`.
They lose `static` and are declared in a new private header,
`CIROpDefinitions.h`. No handwritten logic changes.

## Build-time impact
| | before | after |
|---|---|---|
| `CIRDialect.cpp` | 108.2 s | 28.0 s |
| largest CIR op-definition TU | 108.2 s | 43.5 s |
| ninja build (wall) | 169.8 ± 3.1 s | 146.9 ± 1.0 s (−13.4%) |
| total user CPU | 21231 s | 21447 s (+1.0%) |
| configure | 21.8 s | 21.7 s |

The extra CPU time comes from each shard parsing the same headers again.
After this change, the CIR dialect is no longer on the critical path to
linking `clang`.

I come clean here, I used AI to explore completely this and used the
above PRs as a guideline. Everything here makes sense to me.

---------

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>

Added: 
    clang/lib/CIR/Dialect/IR/CIROpDefinitions.cpp
    clang/lib/CIR/Dialect/IR/CIROpDefinitions.h

Modified: 
    clang/CMakeLists.txt
    clang/include/clang/CIR/Dialect/IR/CMakeLists.txt
    clang/lib/CIR/Dialect/IR/CIRDialect.cpp
    clang/lib/CIR/Dialect/IR/CIRTypes.cpp
    clang/lib/CIR/Dialect/IR/CMakeLists.txt

Removed: 
    


################################################################################
diff  --git a/clang/CMakeLists.txt b/clang/CMakeLists.txt
index a516c7a72ff06..44dd935be5e5d 100644
--- a/clang/CMakeLists.txt
+++ b/clang/CMakeLists.txt
@@ -205,6 +205,10 @@ if(CLANG_ENABLE_CIR)
     message(FATAL_ERROR
       "Cannot build ClangIR without MLIR enabled")
   endif()
+  # Number of translation units the TableGen-generated CIR operation
+  # definitions are split into. Shared by the CIROps.td TableGen invocations
+  # and the MLIRCIR library sources.
+  set(CLANG_CIR_OP_SHARD_COUNT 8)
 endif()
 
 include(CheckIncludeFile)

diff  --git a/clang/include/clang/CIR/Dialect/IR/CMakeLists.txt 
b/clang/include/clang/CIR/Dialect/IR/CMakeLists.txt
index 66fa7a40d28f7..7cadc1424a82b 100644
--- a/clang/include/clang/CIR/Dialect/IR/CMakeLists.txt
+++ b/clang/include/clang/CIR/Dialect/IR/CMakeLists.txt
@@ -5,8 +5,8 @@
 
 # Equivalent to add_mlir_dialect(CIROps cir)
 set(LLVM_TARGET_DEFINITIONS CIROps.td)
-mlir_tablegen(CIROps.h.inc -gen-op-decls)
-mlir_tablegen(CIROps.cpp.inc -gen-op-defs)
+mlir_tablegen(CIROps.h.inc -gen-op-decls 
-op-shard-count=${CLANG_CIR_OP_SHARD_COUNT})
+mlir_tablegen(CIROps.cpp.inc -gen-op-defs 
-op-shard-count=${CLANG_CIR_OP_SHARD_COUNT})
 mlir_tablegen(CIROpsTypes.h.inc -gen-typedef-decls)
 mlir_tablegen(CIROpsTypes.cpp.inc -gen-typedef-defs)
 mlir_tablegen(CIROpsDialect.h.inc -gen-dialect-decls)

diff  --git a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp 
b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
index 1012827cdcc6e..dae8005f870d7 100644
--- a/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
+++ b/clang/lib/CIR/Dialect/IR/CIRDialect.cpp
@@ -37,6 +37,7 @@
 #include "llvm/Support/LogicalResult.h"
 
 #include "CIRDialectBytecode.h"
+#include "CIROpDefinitions.h"
 
 using namespace mlir;
 using namespace cir;
@@ -100,10 +101,7 @@ struct CIROpAsmDialectInterface : public 
OpAsmDialectInterface {
 void cir::CIRDialect::initialize() {
   registerTypes();
   registerAttributes();
-  addOperations<
-#define GET_OP_LIST
-#include "clang/CIR/Dialect/IR/CIROps.cpp.inc"
-      >();
+  registerCIRDialectOperations(this);
   addInterfaces<CIROpAsmDialectInterface>();
   detail::addBytecodeInterface(this);
 }
@@ -486,8 +484,8 @@ void printInlineKindAttr(OpAsmPrinter &p, 
cir::InlineKindAttr inlineKindAttr) {
 // CIR Custom Parsers/Printers
 
//===----------------------------------------------------------------------===//
 
-static mlir::ParseResult parseOmittedTerminatorRegion(mlir::OpAsmParser 
&parser,
-                                                      mlir::Region &region) {
+mlir::ParseResult cir::parseOmittedTerminatorRegion(mlir::OpAsmParser &parser,
+                                                    mlir::Region &region) {
   auto regionLoc = parser.getCurrentLocation();
   if (parser.parseRegion(region))
     return failure();
@@ -496,21 +494,13 @@ static mlir::ParseResult 
parseOmittedTerminatorRegion(mlir::OpAsmParser &parser,
   return success();
 }
 
-static void printOmittedTerminatorRegion(mlir::OpAsmPrinter &printer,
-                                         cir::ScopeOp &op,
-                                         mlir::Region &region) {
+void cir::printOmittedTerminatorRegion(mlir::OpAsmPrinter &printer,
+                                       cir::ScopeOp &op, mlir::Region &region) 
{
   printer.printRegion(region,
                       /*printEntryBlockArgs=*/false,
                       /*printBlockTerminators=*/!omitRegionTerm(region));
 }
 
-mlir::OptionalParseResult
-parseGlobalMemorySpace(mlir::AsmParser &p,
-                       mlir::ptr::MemorySpaceAttrInterface &attr);
-
-void printGlobalMemorySpace(mlir::AsmPrinter &printer, cir::GlobalOp op,
-                            mlir::ptr::MemorySpaceAttrInterface attr);
-
 
//===----------------------------------------------------------------------===//
 // AllocaOp
 
//===----------------------------------------------------------------------===//
@@ -622,10 +612,9 @@ LogicalResult cir::DeleteArrayOp::verify() {
 // AssumeOp
 
//===----------------------------------------------------------------------===//
 
-static void printAssumeBundle(OpAsmPrinter &p, cir::AssumeOp op,
-                              cir::AssumeBundleKindAttr kindAttr,
-                              OperandRange bundleArgs,
-                              TypeRange bundleArgTypes) {
+void cir::printAssumeBundle(OpAsmPrinter &p, cir::AssumeOp op,
+                            cir::AssumeBundleKindAttr kindAttr,
+                            OperandRange bundleArgs, TypeRange bundleArgTypes) 
{
   cir::AssumeBundleKind kind = kindAttr.getValue();
   if (kind == cir::AssumeBundleKind::None)
     return;
@@ -641,7 +630,7 @@ static void printAssumeBundle(OpAsmPrinter &p, 
cir::AssumeOp op,
   p << ")";
 }
 
-static ParseResult parseAssumeBundle(
+ParseResult cir::parseAssumeBundle(
     OpAsmParser &p, cir::AssumeBundleKindAttr &bundleKindAttr,
     llvm::SmallVector<mlir::OpAsmParser::UnresolvedOperand, 4> &bundleArgs,
     llvm::SmallVector<mlir::Type, 1> &bundleArgTypes) {
@@ -2219,7 +2208,7 @@ cir::IndirectBrOp::getSuccessorOperands(unsigned index) {
   return mlir::SuccessorOperands(getSuccOperandsMutable()[index]);
 }
 
-ParseResult parseIndirectBrOpSucessors(
+ParseResult cir::parseIndirectBrOpSucessors(
     OpAsmParser &parser, Type &flagType,
     SmallVectorImpl<Block *> &succOperandBlocks,
     SmallVectorImpl<SmallVector<OpAsmParser::UnresolvedOperand>> &succOperands,
@@ -2251,10 +2240,10 @@ ParseResult parseIndirectBrOpSucessors(
   return success();
 }
 
-void printIndirectBrOpSucessors(OpAsmPrinter &p, cir::IndirectBrOp op,
-                                Type flagType, SuccessorRange succs,
-                                OperandRangeRange succOperands,
-                                const TypeRangeRange &succOperandsTypes) {
+void cir::printIndirectBrOpSucessors(OpAsmPrinter &p, cir::IndirectBrOp op,
+                                     Type flagType, SuccessorRange succs,
+                                     OperandRangeRange succOperands,
+                                     const TypeRangeRange &succOperandsTypes) {
   p << "[";
   llvm::interleave(
       llvm::zip(succs, succOperands),
@@ -2388,7 +2377,7 @@ 
cir::SwitchFlatOp::getSuccessorForOperands(ArrayRef<Attribute> operands) {
 
 /// <cases> ::= `[` (case (`,` case )* )? `]`
 /// <case>  ::= integer `:` bb-id (`(` ssa-use-and-type-list `)`)?
-static ParseResult parseSwitchFlatOpCases(
+ParseResult cir::parseSwitchFlatOpCases(
     OpAsmParser &parser, Type flagType, mlir::ArrayAttr &caseValues,
     SmallVectorImpl<Block *> &caseDestinations,
     SmallVectorImpl<llvm::SmallVector<OpAsmParser::UnresolvedOperand>>
@@ -2431,11 +2420,11 @@ static ParseResult parseSwitchFlatOpCases(
   return parser.parseRSquare();
 }
 
-static void printSwitchFlatOpCases(OpAsmPrinter &p, cir::SwitchFlatOp op,
-                                   Type flagType, mlir::ArrayAttr caseValues,
-                                   SuccessorRange caseDestinations,
-                                   OperandRangeRange caseOperands,
-                                   const TypeRangeRange &caseOperandTypes) {
+void cir::printSwitchFlatOpCases(OpAsmPrinter &p, cir::SwitchFlatOp op,
+                                 Type flagType, mlir::ArrayAttr caseValues,
+                                 SuccessorRange caseDestinations,
+                                 OperandRangeRange caseOperands,
+                                 const TypeRangeRange &caseOperandTypes) {
   p << '[';
   p.printNewline();
   if (!caseValues) {
@@ -2611,13 +2600,12 @@ static void printComdatName(OpAsmPrinter &p, StringAttr 
comdat) {
     p << "(\"" << comdat.getValue() << "\")";
 }
 
-static void printComdatName(OpAsmPrinter &p, cir::GlobalOp op,
-                            StringAttr comdat) {
-  printComdatName(p, comdat);
+void cir::printComdatName(OpAsmPrinter &p, cir::GlobalOp op,
+                          StringAttr comdat) {
+  ::printComdatName(p, comdat);
 }
 
-static ParseResult parseComdatName(OpAsmParser &parser,
-                                   StringAttr &comdatAttr) {
+ParseResult cir::parseComdatName(OpAsmParser &parser, StringAttr &comdatAttr) {
   if (parser.parseOptionalKeyword("comdat").failed())
     return success();
   std::string comdatKey;
@@ -2630,10 +2618,10 @@ static ParseResult parseComdatName(OpAsmParser &parser,
   return success();
 }
 
-static void printGlobalOpTypeAndInitialValue(OpAsmPrinter &p, cir::GlobalOp op,
-                                             TypeAttr type, Attribute initAttr,
-                                             mlir::Region &ctorRegion,
-                                             mlir::Region &dtorRegion) {
+void cir::printGlobalOpTypeAndInitialValue(OpAsmPrinter &p, cir::GlobalOp op,
+                                           TypeAttr type, Attribute initAttr,
+                                           mlir::Region &ctorRegion,
+                                           mlir::Region &dtorRegion) {
   auto printType = [&]() { p << ": " << type; };
   // Aliases are definitions but they have no initial value or ctor/dtor; the
   // assembly prints them like declarations (`: type`).
@@ -2661,11 +2649,11 @@ static void 
printGlobalOpTypeAndInitialValue(OpAsmPrinter &p, cir::GlobalOp op,
   }
 }
 
-static ParseResult parseGlobalOpTypeAndInitialValue(OpAsmParser &parser,
-                                                    TypeAttr &typeAttr,
-                                                    Attribute 
&initialValueAttr,
-                                                    mlir::Region &ctorRegion,
-                                                    mlir::Region &dtorRegion) {
+ParseResult cir::parseGlobalOpTypeAndInitialValue(OpAsmParser &parser,
+                                                  TypeAttr &typeAttr,
+                                                  Attribute &initialValueAttr,
+                                                  mlir::Region &ctorRegion,
+                                                  mlir::Region &dtorRegion) {
   mlir::Type opTy;
   if (parser.parseOptionalEqual().failed()) {
     // Absence of equal means a declaration, so we need to parse the type.
@@ -3272,7 +3260,7 @@ void cir::FuncOp::print(OpAsmPrinter &p) {
 
   if (getComdatAttr()) {
     p << ' ';
-    printComdatName(p, getComdatAttr());
+    ::printComdatName(p, getComdatAttr());
   }
 
   if (getAlignment())
@@ -4008,8 +3996,8 @@ LogicalResult cir::CoroutineOp::verify() {
 // Prints the pointer type(s) for a `cir.copy`. `src` and `dst` share the same
 // pointee type but may 
diff er in address space; a single type is printed when
 // they match, otherwise both are printed (`src` first).
-static void printCopyTypes(mlir::OpAsmPrinter &printer, mlir::Operation *,
-                           mlir::Type srcType, mlir::Type dstType) {
+void cir::printCopyTypes(mlir::OpAsmPrinter &printer, mlir::Operation *,
+                         mlir::Type srcType, mlir::Type dstType) {
   printer.printType(srcType);
   if (srcType != dstType) {
     printer << ", ";
@@ -4017,9 +4005,9 @@ static void printCopyTypes(mlir::OpAsmPrinter &printer, 
mlir::Operation *,
   }
 }
 
-static mlir::ParseResult parseCopyTypes(mlir::OpAsmParser &parser,
-                                        mlir::Type &srcType,
-                                        mlir::Type &dstType) {
+mlir::ParseResult cir::parseCopyTypes(mlir::OpAsmParser &parser,
+                                      mlir::Type &srcType,
+                                      mlir::Type &dstType) {
   if (parser.parseType(srcType))
     return mlir::failure();
   if (parser.parseOptionalComma().succeeded()) {
@@ -5323,10 +5311,10 @@ LogicalResult cir::TryOp::verifyRegions() {
   return success();
 }
 
-static void
-printTryHandlerRegions(mlir::OpAsmPrinter &printer, cir::TryOp op,
-                       mlir::MutableArrayRef<mlir::Region> handlerRegions,
-                       mlir::ArrayAttr handlerTypes) {
+void cir::printTryHandlerRegions(
+    mlir::OpAsmPrinter &printer, cir::TryOp op,
+    mlir::MutableArrayRef<mlir::Region> handlerRegions,
+    mlir::ArrayAttr handlerTypes) {
   if (!handlerTypes)
     return;
 
@@ -5366,7 +5354,7 @@ printTryHandlerRegions(mlir::OpAsmPrinter &printer, 
cir::TryOp op,
   }
 }
 
-static mlir::ParseResult parseTryHandlerRegions(
+mlir::ParseResult cir::parseTryHandlerRegions(
     mlir::OpAsmParser &parser,
     llvm::SmallVectorImpl<std::unique_ptr<mlir::Region>> &handlerRegions,
     mlir::ArrayAttr &handlerTypes) {
@@ -5665,11 +5653,10 @@ LogicalResult cir::EhDispatchOp::verify() {
   return success();
 }
 
-static ParseResult
-parseEhDispatchDestinations(OpAsmParser &parser, mlir::ArrayAttr &catchTypes,
-                            SmallVectorImpl<Block *> &catchDestinations,
-                            Block *&defaultDestination,
-                            mlir::UnitAttr &defaultIsCatchAll) {
+ParseResult cir::parseEhDispatchDestinations(
+    OpAsmParser &parser, mlir::ArrayAttr &catchTypes,
+    SmallVectorImpl<Block *> &catchDestinations, Block *&defaultDestination,
+    mlir::UnitAttr &defaultIsCatchAll) {
   // Parse: [ ... ]
   if (parser.parseLSquare())
     return failure();
@@ -5805,11 +5792,11 @@ parseEhDispatchDestinations(OpAsmParser &parser, 
mlir::ArrayAttr &catchTypes,
   return success();
 }
 
-static void printEhDispatchDestinations(OpAsmPrinter &p, cir::EhDispatchOp op,
-                                        mlir::ArrayAttr catchTypes,
-                                        SuccessorRange catchDestinations,
-                                        Block *defaultDestination,
-                                        mlir::UnitAttr defaultIsCatchAll) {
+void cir::printEhDispatchDestinations(OpAsmPrinter &p, cir::EhDispatchOp op,
+                                      mlir::ArrayAttr catchTypes,
+                                      SuccessorRange catchDestinations,
+                                      Block *defaultDestination,
+                                      mlir::UnitAttr defaultIsCatchAll) {
   p << " [";
   p.printNewline();
 
@@ -5863,10 +5850,3 @@ bool cir::StdFindOp::signatureMatches(mlir::TypeRange 
operands,
   mlir::Type iterTy = operands[0];
   return iterTy == operands[1] && iterTy == operands[2] && iterTy == 
results[0];
 }
-
-//===----------------------------------------------------------------------===//
-// TableGen'd op method definitions
-//===----------------------------------------------------------------------===//
-
-#define GET_OP_CLASSES
-#include "clang/CIR/Dialect/IR/CIROps.cpp.inc"

diff  --git a/clang/lib/CIR/Dialect/IR/CIROpDefinitions.cpp 
b/clang/lib/CIR/Dialect/IR/CIROpDefinitions.cpp
new file mode 100644
index 0000000000000..629fcb53bbbe4
--- /dev/null
+++ b/clang/lib/CIR/Dialect/IR/CIROpDefinitions.cpp
@@ -0,0 +1,24 @@
+//===- CIROpDefinitions.cpp - Generated CIR op definitions 
----------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file is the template for the CIROpDefinitions.<N>.cpp shards. Each 
shard
+// defines GET_OP_DEFS_<N> and includes the TableGen-generated definitions of
+// one subset of the CIR operations.
+//
+//===----------------------------------------------------------------------===//
+
+#include "clang/CIR/Dialect/IR/CIRDialect.h"
+
+#include "CIROpDefinitions.h"
+
+#include "mlir/IR/DialectImplementation.h"
+
+using namespace mlir;
+using namespace cir;
+
+#include "clang/CIR/Dialect/IR/CIROps.cpp.inc"

diff  --git a/clang/lib/CIR/Dialect/IR/CIROpDefinitions.h 
b/clang/lib/CIR/Dialect/IR/CIROpDefinitions.h
new file mode 100644
index 0000000000000..9268f540f3ce3
--- /dev/null
+++ b/clang/lib/CIR/Dialect/IR/CIROpDefinitions.h
@@ -0,0 +1,107 @@
+//===- CIROpDefinitions.h - CIR op implementation helpers -------*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This header declares the custom directive parsers and printers implemented
+// in CIRDialect.cpp and referenced by the TableGen-generated CIR operation
+// definitions, which are compiled in separate shards.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef CLANG_LIB_CIR_DIALECT_IR_CIROPDEFINITIONS_H
+#define CLANG_LIB_CIR_DIALECT_IR_CIROPDEFINITIONS_H
+
+#include "clang/CIR/Dialect/IR/CIRDialect.h"
+
+#include "mlir/IR/OpImplementation.h"
+
+namespace cir {
+
+mlir::ParseResult parseOmittedTerminatorRegion(mlir::OpAsmParser &parser,
+                                               mlir::Region &region);
+void printOmittedTerminatorRegion(mlir::OpAsmPrinter &printer, cir::ScopeOp 
&op,
+                                  mlir::Region &region);
+
+mlir::OptionalParseResult
+parseGlobalMemorySpace(mlir::AsmParser &p,
+                       mlir::ptr::MemorySpaceAttrInterface &attr);
+void printGlobalMemorySpace(mlir::AsmPrinter &printer, cir::GlobalOp op,
+                            mlir::ptr::MemorySpaceAttrInterface attr);
+
+mlir::ParseResult parseAssumeBundle(
+    mlir::OpAsmParser &p, cir::AssumeBundleKindAttr &bundleKindAttr,
+    llvm::SmallVector<mlir::OpAsmParser::UnresolvedOperand, 4> &bundleArgs,
+    llvm::SmallVector<mlir::Type, 1> &bundleArgTypes);
+void printAssumeBundle(mlir::OpAsmPrinter &p, cir::AssumeOp op,
+                       cir::AssumeBundleKindAttr kindAttr,
+                       mlir::OperandRange bundleArgs,
+                       mlir::TypeRange bundleArgTypes);
+
+mlir::ParseResult parseIndirectBrOpSucessors(
+    mlir::OpAsmParser &parser, mlir::Type &flagType,
+    llvm::SmallVectorImpl<mlir::Block *> &succOperandBlocks,
+    llvm::SmallVectorImpl<
+        llvm::SmallVector<mlir::OpAsmParser::UnresolvedOperand>> &succOperands,
+    llvm::SmallVectorImpl<llvm::SmallVector<mlir::Type>> &succOperandsTypes);
+void printIndirectBrOpSucessors(mlir::OpAsmPrinter &p, cir::IndirectBrOp op,
+                                mlir::Type flagType, mlir::SuccessorRange 
succs,
+                                mlir::OperandRangeRange succOperands,
+                                const mlir::TypeRangeRange &succOperandsTypes);
+
+mlir::ParseResult parseSwitchFlatOpCases(
+    mlir::OpAsmParser &parser, mlir::Type flagType, mlir::ArrayAttr 
&caseValues,
+    llvm::SmallVectorImpl<mlir::Block *> &caseDestinations,
+    llvm::SmallVectorImpl<
+        llvm::SmallVector<mlir::OpAsmParser::UnresolvedOperand>> &caseOperands,
+    llvm::SmallVectorImpl<llvm::SmallVector<mlir::Type>> &caseOperandTypes);
+void printSwitchFlatOpCases(mlir::OpAsmPrinter &p, cir::SwitchFlatOp op,
+                            mlir::Type flagType, mlir::ArrayAttr caseValues,
+                            mlir::SuccessorRange caseDestinations,
+                            mlir::OperandRangeRange caseOperands,
+                            const mlir::TypeRangeRange &caseOperandTypes);
+
+mlir::ParseResult parseComdatName(mlir::OpAsmParser &parser,
+                                  mlir::StringAttr &comdatAttr);
+void printComdatName(mlir::OpAsmPrinter &p, cir::GlobalOp op,
+                     mlir::StringAttr comdat);
+
+mlir::ParseResult parseGlobalOpTypeAndInitialValue(
+    mlir::OpAsmParser &parser, mlir::TypeAttr &typeAttr,
+    mlir::Attribute &initialValueAttr, mlir::Region &ctorRegion,
+    mlir::Region &dtorRegion);
+void printGlobalOpTypeAndInitialValue(mlir::OpAsmPrinter &p, cir::GlobalOp op,
+                                      mlir::TypeAttr type,
+                                      mlir::Attribute initAttr,
+                                      mlir::Region &ctorRegion,
+                                      mlir::Region &dtorRegion);
+
+mlir::ParseResult parseCopyTypes(mlir::OpAsmParser &parser, mlir::Type 
&srcType,
+                                 mlir::Type &dstType);
+void printCopyTypes(mlir::OpAsmPrinter &printer, mlir::Operation *,
+                    mlir::Type srcType, mlir::Type dstType);
+
+mlir::ParseResult parseTryHandlerRegions(
+    mlir::OpAsmParser &parser,
+    llvm::SmallVectorImpl<std::unique_ptr<mlir::Region>> &handlerRegions,
+    mlir::ArrayAttr &handlerTypes);
+void printTryHandlerRegions(mlir::OpAsmPrinter &printer, cir::TryOp op,
+                            mlir::MutableArrayRef<mlir::Region> handlerRegions,
+                            mlir::ArrayAttr handlerTypes);
+
+mlir::ParseResult parseEhDispatchDestinations(
+    mlir::OpAsmParser &parser, mlir::ArrayAttr &catchTypes,
+    llvm::SmallVectorImpl<mlir::Block *> &catchDestinations,
+    mlir::Block *&defaultDestination, mlir::UnitAttr &defaultIsCatchAll);
+void printEhDispatchDestinations(mlir::OpAsmPrinter &p, cir::EhDispatchOp op,
+                                 mlir::ArrayAttr catchTypes,
+                                 mlir::SuccessorRange catchDestinations,
+                                 mlir::Block *defaultDestination,
+                                 mlir::UnitAttr defaultIsCatchAll);
+
+} // namespace cir
+
+#endif // CLANG_LIB_CIR_DIALECT_IR_CIROPDEFINITIONS_H

diff  --git a/clang/lib/CIR/Dialect/IR/CIRTypes.cpp 
b/clang/lib/CIR/Dialect/IR/CIRTypes.cpp
index 9f58c60f97a47..a25e2e0576838 100644
--- a/clang/lib/CIR/Dialect/IR/CIRTypes.cpp
+++ b/clang/lib/CIR/Dialect/IR/CIRTypes.cpp
@@ -29,6 +29,8 @@
 #include "llvm/ADT/TypeSwitch.h"
 #include "llvm/Support/MathExtras.h"
 
+#include "CIROpDefinitions.h"
+
 
//===----------------------------------------------------------------------===//
 // CIR Helpers
 
//===----------------------------------------------------------------------===//
@@ -1787,8 +1789,8 @@ void printMemorySpace(mlir::AsmPrinter &p,
 }
 
 mlir::OptionalParseResult
-parseGlobalMemorySpace(mlir::AsmParser &p,
-                       mlir::ptr::MemorySpaceAttrInterface &attr) {
+cir::parseGlobalMemorySpace(mlir::AsmParser &p,
+                            mlir::ptr::MemorySpaceAttrInterface &attr) {
 
   mlir::SMLoc loc = p.getCurrentLocation();
   if (parseMemorySpace(p, attr).failed())
@@ -1796,8 +1798,8 @@ parseGlobalMemorySpace(mlir::AsmParser &p,
   return mlir::success();
 }
 
-void printGlobalMemorySpace(mlir::AsmPrinter &printer, cir::GlobalOp,
-                            mlir::ptr::MemorySpaceAttrInterface attr) {
+void cir::printGlobalMemorySpace(mlir::AsmPrinter &printer, cir::GlobalOp,
+                                 mlir::ptr::MemorySpaceAttrInterface attr) {
   printMemorySpace(printer, attr);
 }
 

diff  --git a/clang/lib/CIR/Dialect/IR/CMakeLists.txt 
b/clang/lib/CIR/Dialect/IR/CMakeLists.txt
index a326c329cbf93..fb10f71e5ecf2 100644
--- a/clang/lib/CIR/Dialect/IR/CMakeLists.txt
+++ b/clang/lib/CIR/Dialect/IR/CMakeLists.txt
@@ -1,3 +1,19 @@
+set(LLVM_OPTIONAL_SOURCES
+  CIROpDefinitions.cpp
+  )
+
+# Compile the TableGen-generated op definitions in shards to reduce the
+# compile time of the largest CIR translation unit.
+set(LLVM_TARGET_DEFINITIONS CIROpDefinitions.cpp)
+math(EXPR CIR_LAST_SHARD_INDEX "${CLANG_CIR_OP_SHARD_COUNT} - 1")
+foreach(index RANGE ${CIR_LAST_SHARD_INDEX})
+  set(CIR_SHARDED_SRC CIROpDefinitions.${index}.cpp)
+  list(APPEND CIR_SHARDED_SRCS ${CIR_SHARDED_SRC})
+  tablegen(MLIR_SRC_SHARDER ${CIR_SHARDED_SRC}
+    -op-shard-index=${index})
+endforeach()
+add_public_tablegen_target(MLIRCIROpsShardGen)
+
 add_clang_library(MLIRCIR
   CIRAttrs.cpp
   CIRDialect.cpp
@@ -6,8 +22,10 @@ add_clang_library(MLIRCIR
   CIRTypes.cpp
   CIRDataLayout.cpp
   CIROpenCLAttrs.cpp
+  ${CIR_SHARDED_SRCS}
 
   DEPENDS
+  MLIRCIROpsShardGen
   MLIRCIRDialectBytecodeIncGen
   MLIRCIREnumsGen
   mlir-headers


        
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to