Commit a56fcc84 authored by lwesiers's avatar lwesiers Committed by Paige, Alexander

This change prepares compiler to work with llvm7.

Change-Id: I9f0da6f65cf9ff8dfce1e1179552cac59eecd887
parent e353f254
......@@ -35,7 +35,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "common/LLVMWarningsPush.hpp"
#include "llvm/ADT/SCCIterator.h"
#include <llvm/IR/Module.h>
#include <llvm/IR/Function.h>
#include <llvmWrapper/IR/Function.h>
#include <llvm/IR/Instructions.h>
#include <llvm/IR/DerivedTypes.h>
#include "llvm/IR/DIBuilder.h"
......@@ -355,10 +355,8 @@ void AddImplicitArgs::replaceAllUsesWithNewOCLBuiltinFunction(CodeGenContext* ct
// let 's prepare argument list on new call function
llvm::Function::arg_iterator new_arg_iter = new_func->arg_begin();
llvm::Function::arg_iterator new_arg_end = new_func->arg_end();
llvm::Function::arg_iterator parent_func_arg_iter = parent_func->arg_begin();
llvm::Function::arg_iterator parent_func_arg_end = parent_func->arg_end();
assert(new_func->arg_size() >= numArgOperands);
assert(IGCLLVM::GetFuncArgSize(new_func) >= numArgOperands);
// basic arguments
for (unsigned int i = 0; i < numArgOperands; ++i, ++new_arg_iter)
......
......@@ -29,7 +29,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "common/LLVMWarningsPush.hpp"
#include <llvm/IR/DerivedTypes.h>
#include <llvm/IR/Function.h>
#include <llvmWrapper/IR/Function.h>
#include <llvm/IR/Metadata.h>
#include <llvm/IR/Module.h>
#include "common/LLVMWarningsPop.hpp"
......@@ -389,7 +389,7 @@ void ImplicitArgs::addBufferOffsetArgs(llvm::Function& F, IGCMD::MetaDataUtils*
ImplicitArg::ArgMap OffsetArgs;
FunctionInfoMetaDataHandle funcInfoMD =
pMdUtils->getFunctionsInfoItem(const_cast<Function*>(&F));
for (auto& Arg : F.getArgumentList() )
for (auto& Arg : F.args() )
{
Value* AV = &Arg;
PointerType* PTy = dyn_cast<PointerType>(AV->getType());
......@@ -465,10 +465,10 @@ int32_t ImplicitArgs::getStructArgOffset(unsigned int index) const
TODO("Refactor code to avoid code triplication for getArgInFunc(), getImplicitArg() and WIFuncResolution::getImplicitArg()")
Argument* ImplicitArgs::getArgInFunc(llvm::Function& F, ImplicitArg::ArgType argType) {
assert(F.getArgumentList().size() >= size() && "Invalid number of argumnents in the function!");
assert(IGCLLVM::GetFuncArgSize(F) >= size() && "Invalid number of argumnents in the function!");
unsigned int argIndex = getArgIndex(argType);
unsigned int argIndexInFunc = F.getArgumentList().size() - size() + argIndex;
unsigned int argIndexInFunc = IGCLLVM::GetFuncArgSize(F) - size() + argIndex;
Function::arg_iterator arg = F.arg_begin();
for (unsigned int i = 0; i < argIndexInFunc; ++i, ++arg);
......@@ -482,7 +482,7 @@ Argument* ImplicitArgs::getImplicitArg(llvm::Function& F, ImplicitArg::ArgType a
return nullptr;
unsigned int implicitArgIndex = this->getArgIndex(argType);
unsigned int implicitArgIndexInFunc = F.getArgumentList().size() - numImplicitArgs + implicitArgIndex;
unsigned int implicitArgIndexInFunc = IGCLLVM::GetFuncArgSize(F) - numImplicitArgs + implicitArgIndex;
Function::arg_iterator arg = F.arg_begin();
for (unsigned int i = 0; i < implicitArgIndexInFunc; ++i, ++arg);
......@@ -492,14 +492,14 @@ Argument* ImplicitArgs::getImplicitArg(llvm::Function& F, ImplicitArg::ArgType a
Argument* ImplicitArgs::getNumberedImplicitArg(llvm::Function& F, ImplicitArg::ArgType argType, int argNum)
{
assert(F.getArgumentList().size() >= size() && "Invalid number of arguments in the function!");
assert(IGCLLVM::GetFuncArgSize(F) >= size() && "Invalid number of arguments in the function!");
unsigned int numImplicitArgs = size();
unsigned int implicitArgIndex = this->getNumberedArgIndex(argType, argNum);
if (implicitArgIndex == numImplicitArgs)
return nullptr;
unsigned int implicitArgIndexInFunc = F.getArgumentList().size() - numImplicitArgs + implicitArgIndex;
unsigned int implicitArgIndexInFunc = IGCLLVM::GetFuncArgSize(F) - numImplicitArgs + implicitArgIndex;
Function::arg_iterator arg = F.arg_begin();
for (unsigned int i = 0; i < implicitArgIndexInFunc; ++i, ++arg);
......
......@@ -34,6 +34,9 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "SPIRV/SPIRVInternal.h"
#include "common/LLVMWarningsPush.hpp"
#include "llvmWrapper/IR/Attributes.h"
#include <llvm/Pass.h>
#include <llvm/IR/Module.h>
#include <llvm/IR/Function.h>
......@@ -233,7 +236,7 @@ bool ProcessFuncAttributes::runOnModule(Module& M)
for (auto I : F->users()) {
if (CallInst* callInst = dyn_cast<CallInst>(&*I)) {
if (callInst->hasFnAttr(llvm::Attribute::NoInline)) {
callInst->removeAttribute(llvm::AttributeSet::FunctionIndex, llvm::Attribute::NoInline);
callInst->removeAttribute(IGCLLVM::AttributeSet::FunctionIndex, llvm::Attribute::NoInline);
}
}
}
......@@ -293,7 +296,7 @@ bool ProcessFuncAttributes::runOnModule(Module& M)
if (!keepAlwaysInline)
{
for (auto &arg : F->getArgumentList())
for (auto &arg : F->args())
{
// If argument contains an opaque type e.g. image, then always inline it.
// If argument is a pointer to GAS, always inline it for perf reason.
......
......@@ -7,11 +7,12 @@ include_directories("${CMAKE_CURRENT_SOURCE_DIR}")
#include_directories("${CMAKE_CURRENT_SOURCE_DIR}/ocl_igc_shared/executable_format")
set(IGC_BUILD__SRC__AdaptorOCL
"${CMAKE_CURRENT_SOURCE_DIR}/Upgrader/Upgrader.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/Upgrader/BitcodeReader.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/Upgrader/llvm${LLVM_VERSION_MAJOR}/Upgrader.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/Upgrader/llvm${LLVM_VERSION_MAJOR}/BitcodeReader.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/UnifyIROCL.cpp"
"${CMAKE_CURRENT_SOURCE_DIR}/MoveStaticAllocas.cpp"
)
if(IGC_BUILD__SPIRV_ENABLED)
list(APPEND IGC_BUILD__SRC__AdaptorOCL
SPIRV/libSPIRV/OpenCL.std.h
......
......@@ -72,7 +72,7 @@ MemoryBuffer *llvm::LoadBufferFromResource(const char *pResName,
#endif
#ifdef LLVM_ON_WIN32
#ifdef WIN32
#include <Windows.h>
// Windows.h defines MemoryFence as _mm_mfence, but this conflicts with llvm::sys::MemoryFence
#undef MemoryFence
......
......@@ -24,6 +24,11 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
======================= end_copyright_notice ==================================*/
#include "common/LLVMWarningsPush.hpp"
#include <llvm/Support/ScaledNumber.h>
#include "common/LLVMWarningsPop.hpp"
#include "sp_g8.h"
#include "sp_convert_g8.h"
#include "sp_debug.h"
......@@ -41,6 +46,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "common/secure_mem.h"
#include "common/debug/Dump.hpp"
#include "common/debug/Debug.hpp"
#include <iStdLib/MemCopy.h>
#include "patch_list.h"
......@@ -60,6 +66,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <algorithm>
#include <cstring>
using namespace IGC;
using namespace IGC::IGCMD;
using namespace IGC::Debug;
......
......@@ -73,6 +73,8 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "common/LLVMWarningsPush.hpp"
#include "llvmWrapper/IR/Attributes.h"
#include "llvm/ADT/StringSwitch.h"
#include <llvm/Bitcode/BitcodeReader.h>
#include <llvm/Bitcode/BitcodeWriter.h>
......@@ -85,7 +87,6 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "llvm/IR/GlobalValue.h"
#include "llvm/IR/Module.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/Dwarf.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/ToolOutputFile.h"
......@@ -837,7 +838,7 @@ void getFunctionTypeParameterTypes(llvm::FunctionType* FT,
std::vector<Type*>& ArgTys);
Function *getOrCreateFunction(Module *M, Type *RetTy,
ArrayRef<Type *> ArgTypes, StringRef Name, bool Mangle = false,
AttributeSet *Attrs = nullptr, bool takeName = true);
IGCLLVM::AttributeSet *Attrs = nullptr, bool takeName = true);
std::vector<Value *> getArguments(CallInst* CI);
void decorateSPIRVBuiltin(std::string &S);
......@@ -855,17 +856,17 @@ std::string getSPIRVBuiltinName(Op OC, SPIRVInstruction *BI, std::vector<Type*>
/// \return mutated call instruction.
CallInst *mutateCallInst(Module *M, CallInst *CI,
std::function<std::string (CallInst *, std::vector<Value *> &)>ArgMutate,
bool Mangle = false, AttributeSet *Attrs = nullptr, bool takeName = true);
bool Mangle = false, IGCLLVM::AttributeSet *Attrs = nullptr, bool takeName = true);
/// Mutate function by change the arguments.
/// \param ArgMutate mutates the function arguments.
void mutateFunction(Function *F,
std::function<std::string (CallInst *, std::vector<Value *> &)>ArgMutate,
bool Builtin , AttributeSet *Attrs = nullptr, bool takeName = true);
bool Builtin , IGCLLVM::AttributeSet *Attrs = nullptr, bool takeName = true);
/// Add a call instruction at \p Pos.
CallInst *addCallInst(Module *M, StringRef FuncName, Type *RetTy,
ArrayRef<Value *> Args, AttributeSet *Attrs, Instruction *Pos,
ArrayRef<Value *> Args, IGCLLVM::AttributeSet *Attrs, Instruction *Pos,
bool Builtin, StringRef InstName, bool TakeFuncName = true);
/// Get a 64 bit integer constant.
......
......@@ -62,19 +62,24 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
///
//===----------------------------------------------------------------------===//
#include "libSPIRV/SPIRVFunction.h"
#include "libSPIRV/SPIRVInstruction.h"
#include "SPIRVInternal.h"
#include "common/MDFrameWork.h"
#include "../../AdaptorCommon/TypesLegalizationPass.hpp"
#include "common/LLVMWarningsPush.hpp"
#include "llvmWrapper/IR/IRBuilder.h"
#include "llvmWrapper/IR/DIBuilder.h"
#include <llvm/Support/ScaledNumber.h>
#include <llvm/IR/LegacyPassManager.h>
#include <llvm/IR/IntrinsicInst.h>
#include "libSPIRV/SPIRVDebugInfoExt.h"
#include <llvm/Support/Dwarf.h>
#include "llvm/Transforms/Utils/Cloning.h"
#include "common/LLVMWarningsPop.hpp"
#include "libSPIRV/SPIRVFunction.h"
#include "libSPIRV/SPIRVInstruction.h"
#include "SPIRVInternal.h"
#include "common/MDFrameWork.h"
#include "../../AdaptorCommon/TypesLegalizationPass.hpp"
#include <iostream>
#include <fstream>
......@@ -760,11 +765,11 @@ public:
{
OpDebugValue dbgValue(inst);
auto dbgValueInst = Builder.insertDbgValueIntrinsic(localVar, 0,
createLocalVar(BM->get<SPIRVExtInst>(dbgValue.getVar())),
createExpression(BM->get<SPIRVExtInst>(dbgValue.getExpression())),
createLocation(inst->getLine()->getLine(), inst->getLine()->getColumn(), createScope(inst->getDIScope())),
insertAtEnd);
auto dbgValueInst = Builder.insertDbgValueIntrinsic(localVar, 0,
createLocalVar(BM->get<SPIRVExtInst>(dbgValue.getVar())),
createExpression(BM->get<SPIRVExtInst>(dbgValue.getExpression())),
createLocation(inst->getLine()->getLine(), inst->getLine()->getColumn(), createScope(inst->getDIScope())),
insertAtEnd);
return dbgValueInst;
}
......@@ -810,7 +815,7 @@ private:
SPIRVModule *BM;
Module *M;
SPIRVDbgInfo SpDbg;
DIBuilder Builder;
IGCLLVM::DIBuilder Builder;
bool Enable;
DICompileUnit* cu = nullptr;
SPIRVToLLVM* SPIRVTranslator = nullptr;
......@@ -1671,7 +1676,7 @@ SPIRVToLLVM::postProcessFunctionsReturnStruct(Function *F) {
for (auto RetInst : Returns) {
Value* ReturnedValPtr = cast<LoadInst>(RetInst->getReturnValue())->getPointerOperand();
IRBuilder<> builder(RetInst);
IGCLLVM::IRBuilder<> builder(RetInst);
auto size = DL.getTypeAllocSize(RetInst->getReturnValue()->getType());
builder.CreateMemCpy(&*NewF->arg_begin(), ReturnedValPtr, size, ptrSize);
builder.CreateRetVoid();
......@@ -1682,7 +1687,9 @@ SPIRVToLLVM::postProcessFunctionsReturnStruct(Function *F) {
for (auto I = F->user_begin(), E = F->user_end(); I != E;) {
if (auto CI = dyn_cast<CallInst>(*I++)) {
auto Args = getArguments(CI);
auto Alloca = new AllocaInst(CI->getType(), "", CI);
IGCLLVM::IRBuilder<> builder(CI);
//auto Alloca = new AllocaInst(CI->getType(), "", CI);
auto Alloca = builder.CreateAlloca(CI->getType());
Args.insert(Args.begin(), Alloca);
auto NewCI = CallInst::Create(NewF, Args, "", CI);
NewCI->setCallingConv(CI->getCallingConv());
......@@ -1705,6 +1712,7 @@ SPIRVToLLVM::postProcessFunctionsWithAggregateArguments(Function* F) {
mutateFunction (F, [=](CallInst *CI, std::vector<Value *> &Args) {
auto FBegin = CI->getParent()->getParent()->begin()->getFirstInsertionPt();
IGCLLVM::IRBuilder<> builder_begin(&(*FBegin));
for (auto &I:Args) {
auto T = I->getType();
if (!T->isAggregateType())
......@@ -1716,9 +1724,11 @@ SPIRVToLLVM::postProcessFunctionsWithAggregateArguments(Function* F) {
I = loadInst->getPointerOperand();
}
auto Alloca = new AllocaInst(T, "", &(*FBegin));
//auto Alloca = new AllocaInst(T, &(*FBegin));
auto Alloca = builder_begin.CreateAlloca(T);
Alloca->setAlignment(ptrSize);
IRBuilder<> builder(CI);
IGCLLVM::IRBuilder<> builder(CI);
auto size = DL.getTypeAllocSize(T);
builder.CreateMemCpy(Alloca, I, size, ptrSize);
if (T->isArrayTy()) {
......@@ -2068,7 +2078,9 @@ SPIRVToLLVM::transValueWithoutDecoration(SPIRVValue *BV, Function *F,
if (BS == StorageClassFunction && !Init) {
assert (BB && "Invalid BB");
return mapValue(BV, new AllocaInst(Ty, BV->getName(), BB));
IGCLLVM::IRBuilder<> builder(BB);
//return mapValue(BV, new AllocaInst(Ty, BV->getName(), BB));
return mapValue(BV, builder.CreateAlloca(Ty, nullptr, BV->getName()));
}
auto AddrSpace = SPIRSPIRVAddrSpaceMap::rmap(BS);
auto LVar = new GlobalVariable(*M, Ty, IsConst, LinkageTy, Initializer,
......@@ -2218,7 +2230,7 @@ SPIRVToLLVM::transValueWithoutDecoration(SPIRVValue *BV, Function *F,
// %5 = bitcast %0* %CS.tmpstore to i8*
// call void @llvm.memcpy.p1i8.p0i8.i64(i8 addrspace(1)* %4, i8* %5, i64 16, i32 0, i1 false)
// So we emit this store in a similar fashion as clang would.
IRBuilder<> IRB(&F->getEntryBlock(), F->getEntryBlock().begin());
IGCLLVM::IRBuilder<> IRB(&F->getEntryBlock(), F->getEntryBlock().begin());
auto DL = M->getDataLayout();
std::function<void(ConstantStruct*, Value*)>
LowerConstantStructStore = [&](ConstantStruct *CS, Value *pointer)
......@@ -2273,7 +2285,7 @@ SPIRVToLLVM::transValueWithoutDecoration(SPIRVValue *BV, Function *F,
unsigned Align = BC->getAlignment();
llvm::Value *Size = transValue(BC->getSize(), F, BB);
bool IsVolatile = BC->SPIRVMemoryAccess::getVolatile();
IRBuilder<> Builder(BB);
IGCLLVM::IRBuilder<> Builder(BB);
// If we copy from zero-initialized array, we can optimize it to llvm.memset
if (BC->getSource()->getOpCode() == OpBitcast) {
......@@ -2665,7 +2677,7 @@ SPIRVToLLVM::transFunction(SPIRVFunction *BF) {
BF->foreachReturnValueAttr([&](SPIRVFuncParamAttrKind Kind){
if (Kind == FunctionParameterAttributeCount)
return;
F->addAttribute(AttributeSet::ReturnIndex,
F->addAttribute(IGCLLVM::AttributeSet::ReturnIndex,
SPIRSPIRVFuncParamAttrMap::rmap(Kind));
});
......@@ -3470,7 +3482,7 @@ SPIRVToLLVM::transOCLBuiltinFromExtInst(SPIRVExtInst *BC, BasicBlock *BB) {
BC->getName(),
BB);
setCallingConv(Call);
Call->addAttribute(AttributeSet::FunctionIndex, Attribute::NoUnwind);
Call->addAttribute(IGCLLVM::AttributeSet::FunctionIndex, Attribute::NoUnwind);
return Call;
}
......
......@@ -63,27 +63,33 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
///
//===----------------------------------------------------------------------===//
#include "libSPIRV/SPIRVInstruction.h"
#include "SPIRVInternal.h"
#include "Mangler/ParameterType.h"
#include "common/LLVMWarningsPush.hpp"
#include "llvmWrapper/Bitcode/BitcodeWriter.h"
#include "llvmWrapper/IR/Attributes.h"
#include "llvmWrapper/Support/ToolOutputFile.h"
#include <llvm/Support/ScaledNumber.h>
#include "llvm/ADT/StringExtras.h"
#include "llvm/Transforms/Utils/Cloning.h"
#include "common/LLVMWarningsPop.hpp"
#include "libSPIRV/SPIRVInstruction.h"
#include "SPIRVInternal.h"
#include "Mangler/ParameterType.h"
namespace spv{
void
saveLLVMModule(Module *M, const std::string &OutputFile) {
std::error_code EC;
tool_output_file Out(OutputFile.c_str(), EC, sys::fs::F_None);
IGCLLVM::tool_output_file Out(OutputFile.c_str(), EC, sys::fs::F_None);
if (EC) {
spirv_assert(0 && "Failed to open file");
return;
}
WriteBitcodeToFile(M, Out.os());
IGCLLVM::WriteBitcodeToFile(M, Out.os());
Out.keep();
}
......@@ -106,7 +112,7 @@ getFunctionTypeParameterTypes(llvm::FunctionType* FT,
Function *
getOrCreateFunction(Module *M, Type *RetTy, ArrayRef<Type *> ArgTypes,
StringRef Name, bool builtin, AttributeSet *Attrs, bool takeName) {
StringRef Name, bool builtin, IGCLLVM::AttributeSet *Attrs, bool takeName) {
std::string FuncName(Name);
if (builtin)
decorateSPIRVBuiltin(FuncName, ArgTypes);
......@@ -300,8 +306,8 @@ getSPIRVBuiltinName(Op OC, SPIRVInstruction *BI, std::vector<Type*> ArgTypes, st
CallInst *
mutateCallInst(Module *M, CallInst *CI,
std::function<std::string(CallInst *, std::vector<Value *> &)>ArgMutate,
bool Mangle, AttributeSet *Attrs, bool TakeFuncName) {
std::function<std::string (CallInst *, std::vector<Value *> &)>ArgMutate,
bool Mangle, IGCLLVM::AttributeSet *Attrs, bool TakeFuncName) {
auto Args = getArguments(CI);
auto NewName = ArgMutate(CI, Args);
......@@ -355,7 +361,7 @@ mutateCallInst(Module *M, CallInst *CI,
void
mutateFunction(Function *F,
std::function<std::string (CallInst *, std::vector<Value *> &)>ArgMutate,
bool Mangle, AttributeSet *Attrs, bool TakeFuncName) {
bool Mangle, IGCLLVM::AttributeSet *Attrs, bool TakeFuncName) {
auto M = F->getParent();
for (auto I = F->user_begin(), E = F->user_end(); I != E;) {
if (auto CI = dyn_cast<CallInst>(*I++))
......@@ -369,7 +375,7 @@ mutateFunction(Function *F,
CallInst *
addCallInst(Module *M, StringRef FuncName, Type *RetTy, ArrayRef<Value *> Args,
AttributeSet *Attrs, Instruction *Pos, bool Mangle, StringRef InstName,
IGCLLVM::AttributeSet *Attrs, Instruction *Pos, bool Mangle, StringRef InstName,
bool TakeFuncName) {
auto F = getOrCreateFunction(M, RetTy, getTypes(Args),
FuncName, Mangle, Attrs, TakeFuncName);
......
......@@ -24,6 +24,28 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
======================= end_copyright_notice ==================================*/
#include "common/LLVMWarningsPush.hpp"
#include <llvm/Support/ScaledNumber.h>
#include "llvm/ADT/PostOrderIterator.h"
#include <llvm/IR/LLVMContext.h>
#include <llvm/IR/Verifier.h>
#include <llvm/Analysis/CFGPrinter.h>
#include <llvm/Analysis/Passes.h>
#include <llvm/Pass.h>
#include <llvm/IR/PassManager.h>
#include <llvm/Transforms/IPO.h>
#include <llvm/Transforms/IPO/AlwaysInliner.h>
#include <llvm/Transforms/Scalar.h>
#include <llvm/IR/Module.h>
#include <llvm/IR/Function.h>
#include <llvm/Analysis/TargetLibraryInfo.h>
#include <llvm/Transforms/InstCombine/InstCombineWorklist.h>
#include <llvm/Transforms/InstCombine/InstCombine.h>
#include <llvmWrapper/Transforms/Utils.h>
#include "common/LLVMWarningsPop.hpp"
#include "AdaptorCommon/AddImplicitArgs.hpp"
#include "AdaptorCommon/ProcessFuncAttributes.h"
#include "common/LLVMUtils.h"
......@@ -98,26 +120,12 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <iStdLib/utility.h>
#include "common/LLVMWarningsPush.hpp"
#include "llvm/ADT/PostOrderIterator.h"
#include <llvm/IR/LLVMContext.h>
#include <llvm/IR/Verifier.h>
#include <llvm/Analysis/CFGPrinter.h>
#include <llvm/Analysis/Passes.h>
#include <llvm/Pass.h>
#include <llvm/IR/PassManager.h>
#include <llvm/Transforms/IPO.h>
#include <llvm/Transforms/IPO/AlwaysInliner.h>
#include <llvm/Transforms/Scalar.h>
#include <llvm/IR/Module.h>
#include <llvm/IR/Function.h>
#include <llvm/Analysis/TargetLibraryInfo.h>
#include "common/LLVMWarningsPop.hpp"
#include <sstream>
#include "Compiler/DebugInfo/VISADebugEmitter.hpp"
#include <algorithm>
using namespace llvm;
using namespace IGC::IGCMD;
using namespace IGC::Debug;
......
/*===================== begin_copyright_notice ==================================
Copyright (c) 2017 Intel Corporation
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
======================= end_copyright_notice ==================================*/
//===-- Bitcode/Reader/MetadataLoader.h - Load Metadatas -------*- C++ -*-====//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This class handles loading Metadatas.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_LIB_BITCODE_READER_METADATALOADER_H
#define LLVM_LIB_BITCODE_READER_METADATALOADER_H
#include "llvm/ADT/SmallVector.h"
#include "llvm/Support/Error.h"
#include <functional>
#include <memory>
namespace llvm {
class BitcodeReaderValueList;
class BitstreamCursor;
class DISubprogram;
class Error;
class Function;
class Instruction;
class Metadata;
class MDNode;
class Module;
class Type;
/// Helper class that handles loading Metadatas and keeping them available.
class MetadataLoader {
class MetadataLoaderImpl;
std::unique_ptr<MetadataLoaderImpl> Pimpl;
Error parseMetadata(bool ModuleLevel);
public:
~MetadataLoader();
MetadataLoader(BitstreamCursor &Stream, Module &TheModule,
BitcodeReaderValueList &ValueList, bool IsImporting,
std::function<Type *(unsigned)> getTypeByID);
MetadataLoader &operator=(MetadataLoader &&);
MetadataLoader(MetadataLoader &&);
// Parse a module metadata block
Error parseModuleMetadata() { return parseMetadata(true); }
// Parse a function metadata block
Error parseFunctionMetadata() { return parseMetadata(false); }
/// Set the mode to strip TBAA metadata on load.
void setStripTBAA(bool StripTBAA = true);
/// Return true if the Loader is stripping TBAA metadata.
bool isStrippingTBAA();
// Return true there are remaining unresolved forward references.
bool hasFwdRefs() const;
/// Return the given metadata, creating a replaceable forward reference if
/// necessary.
Metadata *getMetadataFwdRefOrLoad(unsigned Idx);
MDNode *getMDNodeFwdRefOrNull(unsigned Idx);
/// Return the DISubprogra metadata for a Function if any, null otherwise.
DISubprogram *lookupSubprogramForFunction(Function *F);
/// Parse a `METADATA_ATTACHMENT` block for a function.
Error parseMetadataAttachment(
Function &F, const SmallVectorImpl<Instruction *> &InstructionList);
/// Parse a `METADATA_KIND` block for the current module.
Error parseMetadataKinds();
unsigned size() const;
void shrinkTo(unsigned N);
};
}
#endif // LLVM_LIB_BITCODE_READER_METADATALOADER_H
/*===================== begin_copyright_notice ==================================
Copyright (c) 2017 Intel Corporation
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be included
in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
======================= end_copyright_notice ==================================*/
//===-- Bitcode/Reader/MetadataLoader.h - Load Metadatas -------*- C++ -*-====//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This class handles loading Metadatas.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_LIB_BITCODE_READER_METADATALOADER_H
#define LLVM_LIB_BITCODE_READER_METADATALOADER_H
#include "llvm/ADT/SmallVector.h"
#include "llvm/Support/Error.h"
#include <functional>
#include <memory>
namespace llvm {
class BitcodeReaderValueList;
class BitstreamCursor;
class DISubprogram;
class Error;
class Function;
class Instruction;
class Metadata;
class MDNode;
class Module;
class Type;
/// Helper class that handles loading Metadatas and keeping them available.
class MetadataLoader {
class MetadataLoaderImpl;