MLIR  22.0.0git
TargetEnv.h
Go to the documentation of this file.
1 //===- TargetEnv.h - Tosa target environment utilities ----------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file declares utilities for Tosa target environment (implementation).
10 //
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef MLIR_DIALECT_TOSA_IR_TARGETENV_H
14 #define MLIR_DIALECT_TOSA_IR_TARGETENV_H
15 
17 #include "mlir/Support/LLVM.h"
18 #include "llvm/ADT/SmallSet.h"
19 
20 namespace mlir {
21 namespace tosa {
22 
23 /// This class represents the capability enabled in the target implementation
24 /// such as profile, extension, and level.
25 class TargetEnv {
26 public:
27  TargetEnv() {}
28  explicit TargetEnv(const SmallVectorImpl<Profile> &profiles,
29  const SmallVectorImpl<Extension> &extensions) {
30  enabledProfiles.insert_range(profiles);
31 
32  enabledExtensions.insert_range(extensions);
33  }
34 
35  void addProfile(Profile p) { enabledProfiles.insert(p); }
36  void addExtension(Extension e) { enabledExtensions.insert(e); }
37 
38  // TODO implement the following utilities.
39  // Version getSpecVersion() const;
40  // TosaLevel getLevel() const;
41 
42  // Returns true if the given profile is allowed.
43  bool allows(Profile prof) const { return enabledProfiles.count(prof) != 0; }
44 
45  bool allowsAnyOf(ArrayRef<Profile> profs) const {
46  return llvm::any_of(profs, [&](Profile prof) { return allows(prof); });
47  }
48 
49  bool allowsAllOf(ArrayRef<Profile> profs) const {
50  return llvm::all_of(profs, [&](Profile prof) { return allows(prof); });
51  }
52 
53  // Returns true if the given extension is allowed.
54  bool allows(Extension ext) const { return enabledExtensions.count(ext) != 0; }
55 
56  bool allowsAnyOf(ArrayRef<Extension> exts) const {
57  return llvm::any_of(exts, [&](Extension ext) { return allows(ext); });
58  }
59 
60  bool allowsAllOf(ArrayRef<Extension> exts) const {
61  return llvm::all_of(exts, [&](Extension ext) { return allows(ext); });
62  }
63 
64 private:
65  llvm::SmallSet<Profile, 3> enabledProfiles;
66  llvm::SmallSet<Extension, 8> enabledExtensions;
67 };
68 
69 } // namespace tosa
70 } // namespace mlir
71 
72 #endif // MLIR_DIALECT_TOSA_IR_TARGETENV_H
This class represents the capability enabled in the target implementation such as profile,...
Definition: TargetEnv.h:25
void addExtension(Extension e)
Definition: TargetEnv.h:36
bool allowsAllOf(ArrayRef< Extension > exts) const
Definition: TargetEnv.h:60
TargetEnv(const SmallVectorImpl< Profile > &profiles, const SmallVectorImpl< Extension > &extensions)
Definition: TargetEnv.h:28
void addProfile(Profile p)
Definition: TargetEnv.h:35
bool allowsAllOf(ArrayRef< Profile > profs) const
Definition: TargetEnv.h:49
bool allows(Profile prof) const
Definition: TargetEnv.h:43
bool allows(Extension ext) const
Definition: TargetEnv.h:54
bool allowsAnyOf(ArrayRef< Profile > profs) const
Definition: TargetEnv.h:45
bool allowsAnyOf(ArrayRef< Extension > exts) const
Definition: TargetEnv.h:56
Include the generated interface declarations.