MLIR  22.0.0git
TargetEnv.cpp
Go to the documentation of this file.
1 //===-------------- TosaTarget.cpp - TOSA Target utilities ----------------===//
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 
10 
11 namespace mlir {
12 namespace tosa {
13 
14 TargetEnvAttr lookupTargetEnv(Operation *op) {
15  while (op) {
17  if (!op)
18  break;
19 
20  if (auto attr = op->getAttrOfType<TargetEnvAttr>(TargetEnvAttr::name))
21  return attr;
22 
23  op = op->getParentOp();
24  }
25 
26  return {};
27 }
28 
29 TargetEnvAttr getDefaultTargetEnv(MLIRContext *context) {
30  return TargetEnvAttr::get(context, Level::eightK,
31  {Profile::pro_int, Profile::pro_fp}, {});
32 }
33 
34 TargetEnvAttr lookupTargetEnvOrDefault(Operation *op) {
35  if (auto attr = lookupTargetEnv(op))
36  return attr;
37 
38  return getDefaultTargetEnv(op->getContext());
39 }
40 
41 } // namespace tosa
42 } // namespace mlir
MLIRContext is the top-level object for a collection of MLIR operations.
Definition: MLIRContext.h:63
Operation is the basic unit of execution within MLIR.
Definition: Operation.h:88
AttrClass getAttrOfType(StringAttr name)
Definition: Operation.h:550
MLIRContext * getContext()
Return the context this operation is associated with.
Definition: Operation.h:216
Operation * getParentOp()
Returns the closest surrounding operation that contains this operation or nullptr if this is a top-le...
Definition: Operation.h:234
static Operation * getNearestSymbolTable(Operation *from)
Returns the nearest symbol table from a given operation from.
TargetEnvAttr getDefaultTargetEnv(MLIRContext *context)
Definition: TargetEnv.cpp:29
TargetEnvAttr lookupTargetEnv(Operation *op)
Definition: TargetEnv.cpp:14
TargetEnvAttr lookupTargetEnvOrDefault(Operation *op)
Queries the target environment recursively from enclosing symbol table ops containing the given op or...
Definition: TargetEnv.cpp:34
Include the generated interface declarations.
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...