================
@@ -47,6 +59,32 @@ class CIRDialectLLVMIRTranslationInterface
 
     return mlir::success();
   }
+
+  // Translate CIR's inline attribute to LLVM's function attributes.
+  void amendFunction(mlir::LLVM::LLVMFuncOp func,
+                     llvm::ArrayRef<llvm::Instruction *> instructions,
+                     mlir::NamedAttribute attribute,
+                     mlir::LLVM::ModuleTranslation &moduleTranslation) const {
+    llvm::Function *llvmFunc = 
moduleTranslation.lookupFunction(func.getName());
+    if (auto inlineAttr = 
mlir::dyn_cast<cir::InlineAttr>(attribute.getValue())) {
+      if (inlineAttr.isNoInline())
+        llvmFunc->addFnAttr(llvm::Attribute::NoInline);
+      else if (inlineAttr.isAlwaysInline())
+        llvmFunc->addFnAttr(llvm::Attribute::AlwaysInline);
+      else if (inlineAttr.isInlineHint())
+        llvmFunc->addFnAttr(llvm::Attribute::InlineHint);
+      else
+        llvm_unreachable("Unknown inline kind");
+      // Drop ammended CIR attribute from LLVM op.
+      func->removeAttr(attribute.getName());
+    }
----------------
xlauko wrote:

I would prefer switch over branching code to always safely cover all 
posibilities and create a helper method for the translation, e.g.:

```
llvm::Attribute toLLVMAttr(cir::InlineAttr attr) {
   switch (attr.getValue()) {
   case InlineKind::NoInline: return llvm::Attribute::NoInline;
    ...
   }
}
```



https://github.com/llvm/llvm-project/pull/162866
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to