[flang-commits] [flang] [llvm] [flang] Use backend fp128 support to determine REAL(16) availability (PR #221907)

Michael Kruse via flang-commits flang-commits at lists.llvm.org
Mon Sep 14 08:46:14 PDT 2026


================
@@ -67,7 +71,30 @@ namespace Fortran::tools {
   constexpr bool f128Support = false;
 #endif
 
-  if constexpr (!f128Support) {
+  bool f128BESupport = false;
+  llvm::LLVMContext ctx;
+  std::unique_ptr<llvm::Module> dummyModule =
+      std::make_unique<llvm::Module>("quad-test", ctx);
+  dummyModule->setTargetTriple(targetMachine.getTargetTriple());
+  dummyModule->setDataLayout(targetMachine.createDataLayout());
+
+  llvm::FunctionType *dummyFTy =
+      llvm::FunctionType::get(llvm::Type::getVoidTy(ctx), false);
+  llvm::Function *dummyF = llvm::Function::Create(dummyFTy,
+      llvm::GlobalValue::ExternalLinkage, "quad-test", dummyModule.get());
+
+  const llvm::TargetLowering *dummyTLI =
+      targetMachine.getSubtargetImpl(*dummyF)->getTargetLowering();
+
+  if (dummyTLI) {
+    llvm::EVT fp128EVT = llvm::EVT::getEVT(llvm::Type::getFP128Ty(ctx));
+
+    // Query for fp128 backend support. Based on this, determine whether
+    // compilation is possible on the frontend.
+    f128BESupport = dummyTLI->isTypeLegal(fp128EVT);
+  }
+
+  if (!f128Support && !f128BESupport) {
----------------
Meinersbur wrote:

```suggestion
  if (!f128BESupport) {
```
If the backend cannot emit `REAL(16)`, it will not be able to use generate code for the library intrinsics either. 

https://github.com/llvm/llvm-project/pull/221907


More information about the flang-commits mailing list