1 /* Copyright 2021 The TensorFlow Authors. All Rights Reserved.
2
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6
7 http://www.apache.org/licenses/LICENSE-2.0
8
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ==============================================================================*/
15
16 #include "tensorflow/compiler/mlir/xla/transforms/utils.h"
17
18 #include "tensorflow/compiler/xla/mlir_hlo/include/mlir-hlo/utils/hlo_utils.h"
19
20 namespace mlir {
21 namespace mhlo {
22
GetScalarConstOfType(Type ty,Location loc,int64_t raw_value,OpBuilder * builder)23 ConstantOp GetScalarConstOfType(Type ty, Location loc, int64_t raw_value,
24 OpBuilder* builder) {
25 return builder->create<ConstantOp>(loc, hlo::getScalarOfType(ty, raw_value));
26 }
27
GetScalarNegZeroOfType(Type ty,Location loc,OpBuilder * builder)28 ConstantOp GetScalarNegZeroOfType(Type ty, Location loc, OpBuilder* builder) {
29 return builder->create<ConstantOp>(loc, hlo::getScalarNegZeroOfType(ty));
30 }
31
GetI64ElementsAttr(ArrayAttr attr)32 DenseIntElementsAttr GetI64ElementsAttr(ArrayAttr attr) {
33 RankedTensorType ty =
34 RankedTensorType::get(static_cast<int64_t>(attr.size()),
35 IntegerType::get(attr.getContext(), 64));
36 return DenseIntElementsAttr::get(ty, attr.getValue());
37 }
38
GetI64ElementsAttr(ArrayRef<int64_t> values,Builder * builder)39 DenseIntElementsAttr GetI64ElementsAttr(ArrayRef<int64_t> values,
40 Builder* builder) {
41 RankedTensorType ty = RankedTensorType::get(
42 {static_cast<int64_t>(values.size())}, builder->getIntegerType(64));
43 return DenseIntElementsAttr::get(ty, values);
44 }
45
46 } // namespace mhlo
47 } // namespace mlir
48