-
Notifications
You must be signed in to change notification settings - Fork 15.5k
[CIR] Add CIRGenUtils.h for shared CIR codegen utilities #172735
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Extract `emitIntrinsicCallOp`, which was previously defined independently in CIRGenBuiltinAArch64.cpp and CIRGenBuiltinX86.cpp, into a shared header (CIRGenUtils.h).
|
@llvm/pr-subscribers-clang Author: Andrzej Warzyński (banach-space) ChangesExtract Full diff: https://github.com/llvm/llvm-project/pull/172735.diff 3 Files Affected:
diff --git a/clang/lib/CIR/CodeGen/CIRGenBuiltinAArch64.cpp b/clang/lib/CIR/CodeGen/CIRGenBuiltinAArch64.cpp
index e28b3c6cdc2ff..3e4b31ce3fbf2 100644
--- a/clang/lib/CIR/CodeGen/CIRGenBuiltinAArch64.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenBuiltinAArch64.cpp
@@ -13,6 +13,7 @@
#include "CIRGenBuilder.h"
#include "CIRGenFunction.h"
+#include "CIRGenUtils.h"
#include "clang/CIR/MissingFeatures.h"
// TODO(cir): once all builtins are covered, decide whether we still
@@ -31,17 +32,6 @@ using namespace clang;
using namespace clang::CIRGen;
using namespace llvm;
-template <typename... Operands>
-static mlir::Value emitIntrinsicCallOp(CIRGenBuilderTy &builder,
- mlir::Location loc, const StringRef str,
- const mlir::Type &resTy,
- Operands &&...op) {
- return cir::LLVMIntrinsicCallOp::create(builder, loc,
- builder.getStringAttr(str), resTy,
- std::forward<Operands>(op)...)
- .getResult();
-}
-
// Generate vscale * scalingFactor
static mlir::Value genVscaleTimesFactor(mlir::Location loc,
CIRGenBuilderTy builder,
diff --git a/clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp b/clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp
index 72e6bea244802..3e13dea9b4811 100644
--- a/clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp
@@ -14,6 +14,7 @@
#include "CIRGenBuilder.h"
#include "CIRGenFunction.h"
#include "CIRGenModule.h"
+#include "CIRGenUtils.h"
#include "mlir/IR/Location.h"
#include "mlir/IR/ValueRange.h"
#include "clang/Basic/Builtins.h"
@@ -25,17 +26,6 @@
using namespace clang;
using namespace clang::CIRGen;
-template <typename... Operands>
-static mlir::Value emitIntrinsicCallOp(CIRGenBuilderTy &builder,
- mlir::Location loc, const StringRef str,
- const mlir::Type &resTy,
- Operands &&...op) {
- return cir::LLVMIntrinsicCallOp::create(builder, loc,
- builder.getStringAttr(str), resTy,
- std::forward<Operands>(op)...)
- .getResult();
-}
-
// OG has unordered comparison as a form of optimization in addition to
// ordered comparison, while CIR doesn't.
//
diff --git a/clang/lib/CIR/CodeGen/CIRGenUtils.h b/clang/lib/CIR/CodeGen/CIRGenUtils.h
new file mode 100644
index 0000000000000..054c5d6ade5e2
--- /dev/null
+++ b/clang/lib/CIR/CodeGen/CIRGenUtils.h
@@ -0,0 +1,34 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+//
+// Miscellaneous utility functions used by CIR code-gen.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_LIB_CIR_CODEGEN_CIRGENUTILS_H
+#define LLVM_CLANG_LIB_CIR_CODEGEN_CIRGENUTILS_H
+
+#include "CIRGenBuilder.h"
+#include "mlir/IR/Value.h"
+#include "llvm/ADT/StringRef.h"
+
+namespace clang::CIRGen {
+
+template <typename... Operands>
+mlir::Value emitIntrinsicCallOp(CIRGenBuilderTy &builder, mlir::Location loc,
+ const llvm::StringRef str,
+ const mlir::Type &resTy, Operands &&...op) {
+ return cir::LLVMIntrinsicCallOp::create(builder, loc,
+ builder.getStringAttr(str), resTy,
+ std::forward<Operands>(op)...)
+ .getResult();
+}
+
+} // namespace clang::CIRGen
+
+#endif
|
|
@llvm/pr-subscribers-clangir Author: Andrzej Warzyński (banach-space) ChangesExtract Full diff: https://github.com/llvm/llvm-project/pull/172735.diff 3 Files Affected:
diff --git a/clang/lib/CIR/CodeGen/CIRGenBuiltinAArch64.cpp b/clang/lib/CIR/CodeGen/CIRGenBuiltinAArch64.cpp
index e28b3c6cdc2ff..3e4b31ce3fbf2 100644
--- a/clang/lib/CIR/CodeGen/CIRGenBuiltinAArch64.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenBuiltinAArch64.cpp
@@ -13,6 +13,7 @@
#include "CIRGenBuilder.h"
#include "CIRGenFunction.h"
+#include "CIRGenUtils.h"
#include "clang/CIR/MissingFeatures.h"
// TODO(cir): once all builtins are covered, decide whether we still
@@ -31,17 +32,6 @@ using namespace clang;
using namespace clang::CIRGen;
using namespace llvm;
-template <typename... Operands>
-static mlir::Value emitIntrinsicCallOp(CIRGenBuilderTy &builder,
- mlir::Location loc, const StringRef str,
- const mlir::Type &resTy,
- Operands &&...op) {
- return cir::LLVMIntrinsicCallOp::create(builder, loc,
- builder.getStringAttr(str), resTy,
- std::forward<Operands>(op)...)
- .getResult();
-}
-
// Generate vscale * scalingFactor
static mlir::Value genVscaleTimesFactor(mlir::Location loc,
CIRGenBuilderTy builder,
diff --git a/clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp b/clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp
index 72e6bea244802..3e13dea9b4811 100644
--- a/clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenBuiltinX86.cpp
@@ -14,6 +14,7 @@
#include "CIRGenBuilder.h"
#include "CIRGenFunction.h"
#include "CIRGenModule.h"
+#include "CIRGenUtils.h"
#include "mlir/IR/Location.h"
#include "mlir/IR/ValueRange.h"
#include "clang/Basic/Builtins.h"
@@ -25,17 +26,6 @@
using namespace clang;
using namespace clang::CIRGen;
-template <typename... Operands>
-static mlir::Value emitIntrinsicCallOp(CIRGenBuilderTy &builder,
- mlir::Location loc, const StringRef str,
- const mlir::Type &resTy,
- Operands &&...op) {
- return cir::LLVMIntrinsicCallOp::create(builder, loc,
- builder.getStringAttr(str), resTy,
- std::forward<Operands>(op)...)
- .getResult();
-}
-
// OG has unordered comparison as a form of optimization in addition to
// ordered comparison, while CIR doesn't.
//
diff --git a/clang/lib/CIR/CodeGen/CIRGenUtils.h b/clang/lib/CIR/CodeGen/CIRGenUtils.h
new file mode 100644
index 0000000000000..054c5d6ade5e2
--- /dev/null
+++ b/clang/lib/CIR/CodeGen/CIRGenUtils.h
@@ -0,0 +1,34 @@
+//===----------------------------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+//
+// Miscellaneous utility functions used by CIR code-gen.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_LIB_CIR_CODEGEN_CIRGENUTILS_H
+#define LLVM_CLANG_LIB_CIR_CODEGEN_CIRGENUTILS_H
+
+#include "CIRGenBuilder.h"
+#include "mlir/IR/Value.h"
+#include "llvm/ADT/StringRef.h"
+
+namespace clang::CIRGen {
+
+template <typename... Operands>
+mlir::Value emitIntrinsicCallOp(CIRGenBuilderTy &builder, mlir::Location loc,
+ const llvm::StringRef str,
+ const mlir::Type &resTy, Operands &&...op) {
+ return cir::LLVMIntrinsicCallOp::create(builder, loc,
+ builder.getStringAttr(str), resTy,
+ std::forward<Operands>(op)...)
+ .getResult();
+}
+
+} // namespace clang::CIRGen
+
+#endif
|
f0a31d9 to
14428f3
Compare
andykaylor
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is basically what I had in mind. I was thinking of it as specific to the builtin handling, but I suppose there is no reason it needs to be.
This function in particular has been a bit slippery. I like it as a helper function. It feels like it could just be moved to CIRGenFunction, but if we did that we'd have to pass cgf around to a lot of other helper functions that otherwise only need the builder.
@HendrikHuebner You did a lot of the work to cleanup the builtin handling code, including introducing this function. What do you think about this?
Moving some of the helper functions to a different file sounds like a good idea. We could also consider making this particular function a member of |
|
I like this direction, but if we expect this to grow, it might be worth to have a |
Extract
emitIntrinsicCallOp, which was previously definedindependently in CIRGenBuiltinAArch64.cpp and CIRGenBuiltinX86.cpp, into
a shared header (CIRGenUtils.h).