[clang] [CIR] Upstream builtin lowering emitter & FAbs op (PR #151750)
Amr Hesham via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 4 11:02:30 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) {
+ using namespace std::string_literals;
+ std::string Name = getCppClassName(Operation);
+ std::string LLVMOp = Operation->getValueAsString("llvmOp").str();
+
+ ClassDeclaration +=
----------------
AmrDeveloper wrote:
I think we can't create lowering for the table gen `class CIR_ UnaryFPToFPBuiltinOp`, I will try to create an interface or see how it can be handled without using emitter 🤔
https://github.com/llvm/llvm-project/pull/151750
More information about the cfe-commits
mailing list