[clang] [CIR] Upstream builtin lowering emitter & FAbs op (PR #151750)
Andy Kaylor via cfe-commits
cfe-commits at lists.llvm.org
Fri Aug 1 16:19:44 PDT 2025
================
@@ -0,0 +1,108 @@
+//===- CIRLoweringEmitter.cpp - Generate lowering of builtins --=-*- 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
+//
+//===----------------------------------------------------------------------===//
+
+#include "TableGenBackends.h"
+#include "llvm/TableGen/TableGenBackend.h"
+
+using namespace llvm;
+
+namespace {
+std::string ClassDeclaration;
+std::string ClassDefinitions;
+std::string ClassList;
+
+// Adapted from mlir/lib/TableGen/Operator.cpp
+// Returns the C++ class name of the operation, which is the name of the
+// operation with the dialect prefix removed and the first underscore removed.
+// If the operation name starts with an underscore, the underscore is considered
+// part of the class name.
+std::string getCppClassName(const Record *Operation) {
+ StringRef Name = Operation->getName();
+ auto [prefix, cppClassName] = Name.split('_');
+ if (prefix.empty()) {
+ // Class name with a leading underscore and without dialect prefix
+ return Name.str();
+ }
+
+ if (cppClassName.empty()) {
+ // Class name without dialect prefix
+ return prefix.str();
+ }
+
+ return cppClassName.str();
+}
+
+void GenerateLowering(const Record *Operation) {
----------------
andykaylor wrote:
Can you add a test for the tablegen handling in this file? There are some examples in `clang/test/TableGen/` of clang-tablegen testing in general. What is the minimum .td file needed to make this work?
https://github.com/llvm/llvm-project/pull/151750
More information about the cfe-commits
mailing list