================
@@ -22,13 +34,127 @@ using namespace llvm;
 namespace cir {
 namespace direct {
 
+struct ConvertCIRToLLVMPass
+    : public mlir::PassWrapper<ConvertCIRToLLVMPass,
+                               mlir::OperationPass<mlir::ModuleOp>> {
+  void getDependentDialects(mlir::DialectRegistry &registry) const override {
+    registry.insert<mlir::BuiltinDialect, mlir::DLTIDialect,
+                    mlir::LLVM::LLVMDialect, mlir::func::FuncDialect>();
+  }
+  void runOnOperation() final;
+
+  StringRef getDescription() const override {
+    return "Convert the prepared CIR dialect module to LLVM dialect";
+  }
+
+  StringRef getArgument() const override { return "cir-flat-to-llvm"; }
+};
+
+mlir::LogicalResult CIRToLLVMGlobalOpLowering::matchAndRewrite(
+    cir::GlobalOp op, OpAdaptor adaptor,
+    mlir::ConversionPatternRewriter &rewriter) const {
+
+  // Fetch required values to create LLVM op.
+  const mlir::Type cirSymType = op.getSymType();
+
+  // This is the LLVM dialect type
+  const mlir::Type llvmType = getTypeConverter()->convertType(cirSymType);
+  // These defaults are just here until the equivalent attributes are
+  // available on cir.global ops.
+  const bool isConst = false;
+  const bool isDsoLocal = true;
+  const mlir::LLVM::Linkage linkage = mlir::LLVM::Linkage::External;
+  const StringRef symbol = op.getSymName();
+  std::optional<mlir::Attribute> init = op.getInitialValue();
+
+  SmallVector<mlir::NamedAttribute> attributes;
+
+  // Check for missing funcionalities.
+  if (!init.has_value()) {
+    rewriter.replaceOpWithNewOp<mlir::LLVM::GlobalOp>(
+        op, llvmType, isConst, linkage, symbol, mlir::Attribute(),
+        /*alignment*/ 0, /*addrSpace*/ 0, /*dsoLocal*/ isDsoLocal,
----------------
erichkeane wrote:

Clang typically uses `paramname=`.  Also, don't need a comment if the variable 
name tells you what it is.

https://github.com/llvm/llvm-project/pull/125260
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to