intrin_rule_llvm.h 2.39 KB
Newer Older
1 2 3 4 5 6 7 8
/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
9
 *
10
 *   http://www.apache.org/licenses/LICENSE-2.0
11
 *
12 13 14 15 16 17 18 19
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

20 21 22 23
/*!
 * \file intrin_rule_llvm.h
 * \brief Common utilities for llvm intrinsics.
 */
24 25
#ifndef TVM_TARGET_LLVM_INTRIN_RULE_LLVM_H_
#define TVM_TARGET_LLVM_INTRIN_RULE_LLVM_H_
26 27
#ifdef TVM_LLVM_VERSION

28
#include <tvm/tir/expr.h>
29 30
#include <tvm/runtime/registry.h>

31
#include <tvm/target/codegen.h>
32
#include <string>
33
#include "llvm_common.h"
34 35 36 37 38 39

namespace tvm {
namespace codegen {
// num_signature means number of arguments used to query signature
template<unsigned id, int num_signature>
inline void DispatchLLVMPureIntrin(const TVMArgs& targs, TVMRetValue* rv) {
40
  PrimExpr e = targs[0];
41
  const tir::CallNode* call = e.as<tir::CallNode>();
42
  CHECK(call != nullptr);
43
  Array<PrimExpr> cargs;
44
  // intrin id.
45 46
  cargs.push_back(IntImm(DataType::UInt(32), id));
  cargs.push_back(IntImm(DataType::UInt(32), num_signature));
47

48
  for (PrimExpr arg : call->args) {
49 50
    cargs.push_back(arg);
  }
51 52
  *rv = tir::CallNode::make(
      call->dtype, "llvm_intrin", cargs, tir::CallNode::PureIntrinsic);
53 54 55 56
}

template<unsigned id, int num_signature>
inline void DispatchLLVMIntrin(const TVMArgs& targs, TVMRetValue* rv) {
57
  PrimExpr e = targs[0];
58
  const tir::CallNode* call = e.as<tir::CallNode>();
59
  CHECK(call != nullptr);
60
  Array<PrimExpr> cargs;
61
  // intrin id.
62 63
  cargs.push_back(IntImm(DataType::UInt(32), id));
  cargs.push_back(IntImm(DataType::UInt(32), num_signature));
64
  for (PrimExpr arg : call->args) {
65 66
    cargs.push_back(arg);
  }
67 68
  *rv = tir::CallNode::make(
      call->dtype, "llvm_intrin", cargs, tir::CallNode::Intrinsic);
69 70 71 72 73 74
}

}  // namespace codegen
}  // namespace tvm

#endif  // LLVM_VERSION
75
#endif  // TVM_TARGET_LLVM_INTRIN_RULE_LLVM_H_