1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20/*!
21 * \file intrin_rule_llvm.h
22 * \brief Common utilities for llvm intrinsics.
23 */
24#ifndef TVM_TARGET_LLVM_INTRIN_RULE_LLVM_H_
25#define TVM_TARGET_LLVM_INTRIN_RULE_LLVM_H_
26
27#ifdef TVM_LLVM_VERSION
28
29#include <tvm/runtime/registry.h>
30#include <tvm/target/codegen.h>
31#include <tvm/tir/builtin.h>
32#include <tvm/tir/expr.h>
33
34namespace tvm {
35namespace codegen {
36// num_signature means number of arguments used to query signature
37template <unsigned id, int num_signature>
38inline PrimExpr DispatchLLVMPureIntrin(const PrimExpr& e) {
39 const tir::CallNode* call = e.as<tir::CallNode>();
40 ICHECK(call != nullptr);
41 Array<PrimExpr> cargs;
42 // intrin id.
43 cargs.push_back(IntImm(DataType::UInt(32), id));
44 cargs.push_back(IntImm(DataType::UInt(32), num_signature));
45
46 for (PrimExpr arg : call->args) {
47 cargs.push_back(arg);
48 }
49 return tir::Call(call->dtype, tir::builtin::call_llvm_pure_intrin(), cargs);
50}
51
52template <unsigned id, int num_signature>
53inline PrimExpr DispatchLLVMIntrin(const PrimExpr& e) {
54 const tir::CallNode* call = e.as<tir::CallNode>();
55 ICHECK(call != nullptr);
56 Array<PrimExpr> cargs;
57 // intrin id.
58 cargs.push_back(IntImm(DataType::UInt(32), id));
59 cargs.push_back(IntImm(DataType::UInt(32), num_signature));
60 for (PrimExpr arg : call->args) {
61 cargs.push_back(arg);
62 }
63 return tir::Call(call->dtype, tir::builtin::call_llvm_intrin(), cargs);
64}
65
66} // namespace codegen
67} // namespace tvm
68
69#endif // LLVM_VERSION
70#endif // TVM_TARGET_LLVM_INTRIN_RULE_LLVM_H_
71