llvm_common.h 3.37 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/*
 * 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
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * 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 30
/*!
 *  Copyright (c) 2017 by Contributors
 * \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>

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

35
#include <llvm/IR/Value.h>
36
#include <llvm/IR/Intrinsics.h>
37 38 39 40 41 42 43 44 45 46 47 48
#include <llvm/IR/Argument.h>
#include <llvm/IR/BasicBlock.h>
#include <llvm/IR/Constants.h>
#include <llvm/IR/DerivedTypes.h>
#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/Intrinsics.h>
#include <llvm/IR/MDBuilder.h>
49
#include <llvm/IR/Verifier.h>
50 51

#include <llvm/IR/LegacyPassManager.h>
52
#include <llvm/Transforms/Utils/Cloning.h>
53
#include <llvm/Transforms/Utils/ModuleUtils.h>
54 55 56
#include <llvm/Transforms/IPO/PassManagerBuilder.h>
#include <llvm/Transforms/IPO.h>

57
#include <llvm/Support/FileSystem.h>
58
#include <llvm/Support/MemoryBuffer.h>
59
#include <llvm/Support/raw_ostream.h>
60
#include <llvm/Support/Casting.h>
61
#include <llvm/Support/TargetRegistry.h>
62
#include <llvm/Support/TargetSelect.h>
63 64
#include <llvm/Target/TargetMachine.h>
#include <llvm/Target/TargetOptions.h>
65
#include <llvm/IRReader/IRReader.h>
Hu Shiwen committed
66
#include <llvm/CodeGen/TargetLoweringObjectFileImpl.h>
67

68 69
#include <llvm/Linker/Linker.h>

70 71
#include <utility>
#include <string>
72
#include <memory>
73 74 75 76 77 78 79 80 81 82

namespace tvm {
namespace codegen {

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

83
/*!
84 85 86 87 88 89 90 91 92 93 94 95 96 97
 * \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);

/*!
98
 * \brief Get target machine from target_str string.
99
 * \param target_str Target string, in format "llvm -target=xxx -mcpu=xxx"
100
 * \param allow_null Whether allow null to be returned.
101
 * \return target machine
102
 */
103
std::unique_ptr<llvm::TargetMachine>
104
GetLLVMTargetMachine(const std::string& target_str, bool allow_null = false);
105

106 107 108 109
}  // namespace codegen
}  // namespace tvm
#endif  // TVM_LLVM_VERSION
#endif  // TVM_CODEGEN_LLVM_LLVM_COMMON_H_