llvm_common.h 3.58 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 24 25 26 27 28 29
/*!
 * \file llvm_common.h
 * \brief Common utilities for llvm initialization.
 */
#ifndef TVM_CODEGEN_LLVM_LLVM_COMMON_H_
#define TVM_CODEGEN_LLVM_LLVM_COMMON_H_
#ifdef TVM_LLVM_VERSION

#include <llvm/ExecutionEngine/MCJIT.h>

30
#include <llvm/Analysis/TargetTransformInfo.h>
31
#include <llvm/Bitcode/BitcodeWriter.h>
32
#include <llvm/Support/SourceMgr.h>
33

34
#include <llvm/IR/Value.h>
35
#include <llvm/IR/Intrinsics.h>
36 37 38 39 40 41
#if TVM_LLVM_VERSION >= 100
#include <llvm/IR/IntrinsicsAMDGPU.h>
#include <llvm/IR/IntrinsicsARM.h>
#include <llvm/IR/IntrinsicsNVPTX.h>
#include <llvm/IR/IntrinsicsX86.h>
#endif
42 43 44 45
#include <llvm/IR/Argument.h>
#include <llvm/IR/BasicBlock.h>
#include <llvm/IR/Constants.h>
#include <llvm/IR/DerivedTypes.h>
46
#include <llvm/IR/DIBuilder.h>
47 48 49 50 51 52 53
#include <llvm/IR/Function.h>
#include <llvm/IR/IRBuilder.h>
#include <llvm/IR/Instructions.h>
#include <llvm/IR/LLVMContext.h>
#include <llvm/IR/Module.h>
#include <llvm/IR/Type.h>
#include <llvm/IR/MDBuilder.h>
54
#include <llvm/IR/Verifier.h>
55 56

#include <llvm/IR/LegacyPassManager.h>
57
#include <llvm/Transforms/Utils/Cloning.h>
58
#include <llvm/Transforms/Utils/ModuleUtils.h>
59 60 61
#include <llvm/Transforms/IPO/PassManagerBuilder.h>
#include <llvm/Transforms/IPO.h>

62 63 64
#if TVM_LLVM_VERSION >= 100
#include <llvm/Support/Alignment.h>
#endif
65
#include <llvm/Support/FileSystem.h>
66
#include <llvm/Support/MemoryBuffer.h>
67
#include <llvm/Support/raw_ostream.h>
68
#include <llvm/Support/Casting.h>
69
#include <llvm/Support/TargetRegistry.h>
70
#include <llvm/Support/TargetSelect.h>
71 72
#include <llvm/Target/TargetMachine.h>
#include <llvm/Target/TargetOptions.h>
73
#include <llvm/IRReader/IRReader.h>
Hu Shiwen committed
74
#include <llvm/CodeGen/TargetLoweringObjectFileImpl.h>
75

76 77
#include <llvm/Linker/Linker.h>

78 79
#include <utility>
#include <string>
80
#include <memory>
81 82 83 84 85 86 87 88 89 90

namespace tvm {
namespace codegen {

/*!
 * \brief Initialize LLVM on this process,
 *  can be called multiple times.
 */
void InitializeLLVM();

91
/*!
92 93 94 95 96 97 98 99 100 101 102 103 104 105
 * \brief Parse target options
 * \param target_str Target string, in format "llvm -target=xxx -mcpu=xxx"
 * \param triple Target triple
 * \param mcpu cpu info
 * \param options the options
 * \param mattr The attributes
 */
void ParseLLVMTargetOptions(const std::string& target_str,
                            std::string* triple,
                            std::string* mcpu,
                            std::string* mattr,
                            llvm::TargetOptions* options);

/*!
106
 * \brief Get target machine from target_str string.
107
 * \param target_str Target string, in format "llvm -target=xxx -mcpu=xxx"
108
 * \param allow_null Whether allow null to be returned.
109
 * \return target machine
110
 */
111
std::unique_ptr<llvm::TargetMachine>
112
GetLLVMTargetMachine(const std::string& target_str, bool allow_null = false);
113

114 115 116 117
}  // namespace codegen
}  // namespace tvm
#endif  // TVM_LLVM_VERSION
#endif  // TVM_CODEGEN_LLVM_LLVM_COMMON_H_