- 
                Notifications
    
You must be signed in to change notification settings  - Fork 15.1k
 
[MLIR][LLVMIR][DLTI] Pass to update #llvm.target's features per relevant backend #154938
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Merged
      
      
    
  
     Merged
                    Changes from 9 commits
      Commits
    
    
            Show all changes
          
          
            16 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      d95c6ed
              
                [MLIR][LLVMIR][DLTI] Pass for updating target features per TargetMachine
              
              
                rolfmorel fbcd09d
              
                Sharing is caring
              
              
                rolfmorel ec15717
              
                Get feature flags from proper source
              
              
                rolfmorel 32c9cea
              
                Add test cases
              
              
                rolfmorel facc907
              
                Add comment explaining file structuring
              
              
                rolfmorel 36c3ba4
              
                Add tests exercising DLTI
              
              
                rolfmorel b3e91bf
              
                Update DLTI tests
              
              
                rolfmorel 27a9749
              
                Address Mehdi's comments
              
              
                rolfmorel 1f29675
              
                Add missing file
              
              
                rolfmorel a6cb7fb
              
                Fix cyclic dependency issue through a coarse type
              
              
                rolfmorel 3bc26b1
              
                Better init
              
              
                rolfmorel 79e99b9
              
                Remove extraneaous dialect dependency
              
              
                rolfmorel b7e5765
              
                Update cast
              
              
                rolfmorel d49b0db
              
                Obsolete
              
              
                rolfmorel 6149b17
              
                Address Medhi's and Tobias' comments
              
              
                rolfmorel 2a2ce61
              
                Merge remote-tracking branch 'origin/main' into dlti-target-features
              
              
                rolfmorel File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| //===-- LLVMAttrDefs.td - Solely LLVM Attribute and Enum definitions ----*-===// | ||
| // | ||
| // 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 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
| 
     | 
||
| include "mlir/Dialect/LLVMIR/LLVMAttrDefs.td" | ||
| include "mlir/Dialect/LLVMIR/LLVMEnums.td" | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
        
          
          
            89 changes: 89 additions & 0 deletions
          
          89 
        
  mlir/include/mlir/Dialect/LLVMIR/LLVMTargetFeaturesAttrDefs.td
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| //===-- LLVMTargetFeaturesAttrDefs.td ----------------------*- tablegen -*-===// | ||
| // | ||
| // 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 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // Separate out the LLVM_TargetFeaturesAttr definition from LLVMAttrDefs.td so | ||
| // as to break a circular dependency between LLVMInterfaces.td and LLVMAttrDefs. | ||
| // In particular, the TargetAttrInterface requires LLVMTargetFeaturesAttr | ||
| // and attrs in LLVMAttrDefs.td require interfaces from LLVMInterfaces.td. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
| 
     | 
||
| #ifndef LLVMIR_TARGETFEATURESATTRDEFS | ||
| #define LLVMIR_TARGETFEATURESATTRDEFS | ||
| 
     | 
||
| include "mlir/Dialect/LLVMIR/LLVMDialect.td" | ||
| include "mlir/Interfaces/DataLayoutInterfaces.td" | ||
| 
     | 
||
| //===----------------------------------------------------------------------===// | ||
| // TargetFeaturesAttr | ||
| //===----------------------------------------------------------------------===// | ||
| 
     | 
||
| def LLVM_TargetFeaturesAttr : LLVM_Attr<"TargetFeatures", "target_features", | ||
| [DLTIQueryInterface]> | ||
| { | ||
| let summary = "LLVM target features attribute"; | ||
| 
     | 
||
| let description = [{ | ||
| Represents the LLVM target features as a list that can be checked within | ||
| passes/rewrites. | ||
| 
     | 
||
| Example: | ||
| ```mlir | ||
| #llvm.target_features<["+sme", "+sve", "+sme-f64f64"]> | ||
| ``` | ||
| 
     | 
||
| Then within a pass or rewrite the features active at an op can be queried: | ||
| 
     | 
||
| ```c++ | ||
| auto targetFeatures = LLVM::TargetFeaturesAttr::featuresAt(op); | ||
| 
     | 
||
| if (!targetFeatures.contains("+sme-f64f64")) | ||
| return failure(); | ||
| ``` | ||
| }]; | ||
| 
     | 
||
| let parameters = (ins OptionalArrayRefParameter<"StringAttr">:$features); | ||
| 
     | 
||
| let builders = [ | ||
| TypeBuilder<(ins "::llvm::StringRef":$features)>, | ||
| TypeBuilder<(ins "::llvm::ArrayRef<::llvm::StringRef>":$features)> | ||
| ]; | ||
| 
     | 
||
| let extraClassDeclaration = [{ | ||
| /// Checks if a feature is contained within the features list. | ||
| /// Note: Using a StringAttr allows doing pointer-comparisons. | ||
| bool contains(::mlir::StringAttr feature) const; | ||
| bool contains(::llvm::StringRef feature) const; | ||
| 
     | 
||
| bool nullOrEmpty() const { | ||
| // Checks if this attribute is null, or the features are empty. | ||
| return !bool(*this) || getFeatures().empty(); | ||
| } | ||
| 
     | 
||
| /// Returns the list of features as an LLVM-compatible string. | ||
| std::string getFeaturesString() const; | ||
| 
     | 
||
| /// Finds the target features on the parent FunctionOpInterface. | ||
| /// Note: This assumes the attribute name matches the return value of | ||
| /// `getAttributeName()`. | ||
| static TargetFeaturesAttr featuresAt(Operation* op); | ||
| 
     | 
||
| /// Canonical name for this attribute within MLIR. | ||
| static constexpr StringLiteral getAttributeName() { | ||
| return StringLiteral("target_features"); | ||
| } | ||
| 
     | 
||
| /// Returns the attribute associated with the key. | ||
| FailureOr<Attribute> query(DataLayoutEntryKey key); | ||
| }]; | ||
| 
     | 
||
| let assemblyFormat = "`<` `[` (`]`) : ($features^ `]`)? `>`"; | ||
| let genVerifyDecl = 1; | ||
| } | ||
| 
     | 
||
| #endif // LLVMIR_TARGETFEATURESATTRDEFS | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| 
          
            
          
           | 
    @@ -12,7 +12,6 @@ | |
| #include "mlir/Pass/Pass.h" | ||
| 
     | 
||
| namespace mlir { | ||
| 
     | 
||
| namespace LLVM { | ||
| 
     | 
||
| #define GEN_PASS_DECL | ||
| 
          
            
          
           | 
    ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| //===- TargetUtils.h - Utils to obtain LLVM's TargetMachine and DataLayout ===// | ||
| // | ||
| // 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 | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
| 
     | 
||
| #ifndef MLIR_TARGET_LLVMIR_TRANSFORMS_TARGETUTILS_H | ||
| #define MLIR_TARGET_LLVMIR_TRANSFORMS_TARGETUTILS_H | ||
| 
     | 
||
| #include "mlir/Dialect/LLVMIR/LLVMInterfaces.h" | ||
| #include "llvm/Support/Threading.h" | ||
| #include "llvm/Target/TargetMachine.h" | ||
| 
     | 
||
| namespace mlir { | ||
| namespace LLVM { | ||
| namespace detail { | ||
| /// Idempotent helper to register/initialize all backends that LLVM has been | ||
| /// configured to support. Only runs the first time it is called. | ||
| void initializeBackendsOnce(); | ||
| 
     | 
||
| /// Helper to obtain the TargetMachine specified by the properties of the | ||
| /// TargetAttrInterface-implementing attribute. | ||
| FailureOr<std::unique_ptr<llvm::TargetMachine>> | ||
| getTargetMachine(mlir::LLVM::TargetAttrInterface attr); | ||
| 
     | 
||
| /// Helper to obtain the DataLayout of the target specified by the properties of | ||
| /// the TargetAttrInterface-implementing attribute. | ||
| FailureOr<llvm::DataLayout> getDataLayout(mlir::LLVM::TargetAttrInterface attr); | ||
| } // namespace detail | ||
| } // namespace LLVM | ||
| } // namespace mlir | ||
| 
     | 
||
| #endif // MLIR_TARGET_LLVMIR_TRANSFORMS_TARGETUTILS_H | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.