
This patch forwards the target CPU and features information from the Flang frontend to MLIR func.func operation attributes, which are later used to populate the target_cpu and target_features llvm.func attributes. This is achieved in two stages: 1. Introduce the `fir.target_cpu` and `fir.target_features` module attributes with information from the target machine immediately after the initial creation of the MLIR module in the lowering bridge. 2. Update the target rewrite flang pass to get this information from the module and pass it along to all func.func MLIR operations, respectively as attributes named `target_cpu` and `target_features`. These attributes will be automatically picked up during Func to LLVM dialect lowering and used to initialize the corresponding llvm.func named attributes. The target rewrite and FIR to LLVM lowering passes are updated with the ability to override these module attributes, and the `CodeGenSpecifics` optimizer class is augmented to make this information available to target-specific MLIR transformations. This completes a full flow by which target CPU and features make it all the way from compiler options to LLVM IR function attributes.
36 lines
1017 B
Plaintext
36 lines
1017 B
Plaintext
// RUN: fir-opt --target-rewrite %s | FileCheck %s --check-prefixes=ALL_MLIR,UNCHANGED_MLIR
|
|
// RUN: fir-opt --target-rewrite="target-cpu=gfx90a" %s | FileCheck %s --check-prefixes=ALL_MLIR,CHANGED_MLIR
|
|
|
|
// RUN: tco %s | FileCheck %s --check-prefixes=ALL_LLVM,UNCHANGED_LLVM
|
|
// RUN: tco -target-cpu=gfx90a %s | FileCheck %s --check-prefixes=ALL_LLVM,CHANGED_LLVM
|
|
|
|
|
|
// Check MLIR output from the 'fir-opt' tool
|
|
|
|
// ALL_MLIR: module attributes {
|
|
// ALL_MLIR-SAME: fir.target_cpu =
|
|
|
|
// UNCHANGED_MLIR-SAME: "x86_64"
|
|
// CHANGED_MLIR-SAME: "gfx90a"
|
|
|
|
// ALL_MLIR: func.func @dummyfunc() attributes {
|
|
// ALL_MLIR-SAME: target_cpu =
|
|
|
|
// UNCHANGED_MLIR-SAME: "x86_64"
|
|
// CHANGED_MLIR-SAME: "gfx90a"
|
|
|
|
|
|
// Check LLVM output from the 'tco' tool
|
|
|
|
// ALL_LLVM: define void @dummyfunc() #[[ATTRS:.*]] {
|
|
// ALL_LLVM: attributes #[[ATTRS]] = {
|
|
|
|
// UNCHANGED_LLVM-SAME: "target-cpu"="x86_64"
|
|
// CHANGED_LLVM-SAME: "target-cpu"="gfx90a"
|
|
|
|
module attributes {fir.target_cpu = "x86_64"} {
|
|
func.func @dummyfunc() -> () {
|
|
return
|
|
}
|
|
}
|