================
@@ -0,0 +1,41 @@
+//====- LowerToLLVM.cpp - Lowering from CIR to LLVMIR 
---------------------===//
+//
+// 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 implements lowering of CIR operations to LLVMIR.
+//
+//===----------------------------------------------------------------------===//
+
+#include "clang/CIR/LowerToLLVM.h"
+
+#include "mlir/IR/BuiltinOps.h"
+#include "mlir/Pass/Pass.h"
+#include "mlir/Pass/PassManager.h"
+#include "llvm/IR/Module.h"
+#include "llvm/Support/TimeProfiler.h"
+
+using namespace cir;
+using namespace llvm;
+
+namespace cir {
+namespace direct {
+
+std::unique_ptr<llvm::Module>
+lowerDirectlyFromCIRToLLVMIR(mlir::ModuleOp MOp, LLVMContext &LLVMCtx) {
+  llvm::TimeTraceScope scope("lower from CIR to LLVM directly");
+
+  std::optional<StringRef> ModuleName = MOp.getName();
+  auto M = std::make_unique<llvm::Module>(
+      ModuleName ? *ModuleName : "CIRToLLVMModule", LLVMCtx);
+
+  if (!M)
+    report_fatal_error("Lowering from LLVMIR dialect to llvm IR failed!");
----------------
AaronBallman wrote:

"It depends" (sorry for the total non-answer, lol).

If the reason for the failure is because of user error, then we would want to 
thread in a DiagnosticsEngine so we can report diagnostics the usual way.

If the reason for the failure is because the CIR developer is holding things 
wrong, then we probably would want an assertion closer to the actual issue, and 
then silently return null here.

If the reason for the failure leads to "there's no way to recover from this, 
everything is in a horrible state", then report_fatal_error is more reasonable.

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

Reply via email to