mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-11-26 23:21:11 +00:00
[MLIR][LLVM] Add explicit target_cpu attribute to llvm.func (#78287)
This patch adds the target_cpu attribute to llvm.func MLIR operations and updates the translation to/from LLVM IR to match "target-cpu" function attributes.
This commit is contained in:
parent
3a82a1c3f6
commit
8fb685fb7e
@ -1427,6 +1427,7 @@ def LLVM_LLVMFuncOp : LLVM_Op<"func", [
|
||||
OptionalAttr<I64Attr>:$alignment,
|
||||
OptionalAttr<LLVM_VScaleRangeAttr>:$vscale_range,
|
||||
OptionalAttr<FramePointerKindAttr>:$frame_pointer,
|
||||
OptionalAttr<StrAttr>:$target_cpu,
|
||||
OptionalAttr<LLVM_TargetFeaturesAttr>:$target_features
|
||||
);
|
||||
|
||||
|
@ -1744,11 +1744,14 @@ void ModuleImport::processFunctionAttributes(llvm::Function *func,
|
||||
.value()));
|
||||
}
|
||||
|
||||
if (llvm::Attribute attr = func->getFnAttribute("target-cpu");
|
||||
attr.isStringAttribute())
|
||||
funcOp.setTargetCpuAttr(StringAttr::get(context, attr.getValueAsString()));
|
||||
|
||||
if (llvm::Attribute attr = func->getFnAttribute("target-features");
|
||||
attr.isStringAttribute()) {
|
||||
attr.isStringAttribute())
|
||||
funcOp.setTargetFeaturesAttr(
|
||||
LLVM::TargetFeaturesAttr::get(context, attr.getValueAsString()));
|
||||
}
|
||||
}
|
||||
|
||||
DictionaryAttr
|
||||
|
@ -1104,6 +1104,9 @@ LogicalResult ModuleTranslation::convertOneFunction(LLVMFuncOp func) {
|
||||
if (func.getArmPreservesZa())
|
||||
llvmFunc->addFnAttr("aarch64_pstate_za_preserved");
|
||||
|
||||
if (auto targetCpu = func.getTargetCpu())
|
||||
llvmFunc->addFnAttr("target-cpu", *targetCpu);
|
||||
|
||||
if (auto targetFeatures = func.getTargetFeatures())
|
||||
llvmFunc->addFnAttr("target-features", targetFeatures->getFeaturesString());
|
||||
|
||||
|
@ -61,6 +61,16 @@ func.func @variadic_func(%arg0: i32) attributes { "func.varargs" = true } {
|
||||
return
|
||||
}
|
||||
|
||||
// CHECK-LABEL: llvm.func @target_cpu()
|
||||
// CHECK-SAME: target_cpu = "gfx90a"
|
||||
func.func private @target_cpu() attributes { "target_cpu" = "gfx90a" }
|
||||
|
||||
// CHECK-LABEL: llvm.func @target_features()
|
||||
// CHECK-SAME: target_features = #llvm.target_features<["+sme", "+sve"]>
|
||||
func.func private @target_features() attributes {
|
||||
"target_features" = #llvm.target_features<["+sme", "+sve"]>
|
||||
}
|
||||
|
||||
// -----
|
||||
|
||||
// CHECK-LABEL: llvm.func @private_callee
|
||||
|
@ -772,7 +772,7 @@ func.func @insert_slice_chain(
|
||||
// CHECK-SAME: bufferization.access = "none"
|
||||
%arg2: tensor<62x90xf32> {bufferization.buffer_layout = affine_map<(d0, d1) -> (d0, d1)>, bufferization.writable = true})
|
||||
// CHECK-SAME: bufferization.access = "write"
|
||||
-> tensor<62x90xf32> attributes {passthrough = [["target-cpu", "skylake-avx512"], ["prefer-vector-width", "512"]]}
|
||||
-> tensor<62x90xf32> attributes {passthrough = [["prefer-vector-width", "512"]], target_cpu = "skylake-avx512"}
|
||||
{
|
||||
%c0 = arith.constant 0 : index
|
||||
%cst = arith.constant 0.000000e+00 : f32
|
||||
|
9
mlir/test/Target/LLVMIR/Import/target-cpu.ll
Normal file
9
mlir/test/Target/LLVMIR/Import/target-cpu.ll
Normal file
@ -0,0 +1,9 @@
|
||||
; RUN: mlir-translate -import-llvm -split-input-file %s | FileCheck %s
|
||||
|
||||
; CHECK-LABEL: llvm.func @target_cpu()
|
||||
; CHECK-SAME: target_cpu = "gfx90a"
|
||||
define void @target_cpu() #0 {
|
||||
ret void
|
||||
}
|
||||
|
||||
attributes #0 = { "target-cpu"="gfx90a" }
|
7
mlir/test/Target/LLVMIR/target-cpu.mlir
Normal file
7
mlir/test/Target/LLVMIR/target-cpu.mlir
Normal file
@ -0,0 +1,7 @@
|
||||
// RUN: mlir-translate -mlir-to-llvmir %s | FileCheck %s
|
||||
|
||||
// CHECK: define void @target_cpu() #[[ATTRS:.*]] {
|
||||
// CHECK: attributes #[[ATTRS]] = { "target-cpu"="gfx90a" }
|
||||
llvm.func @target_cpu() attributes {target_cpu = "gfx90a"} {
|
||||
llvm.return
|
||||
}
|
Loading…
Reference in New Issue
Block a user