b607f5194c
ECR #333753 - Compiler Lib/ORCA RT: JIT refactoring Purpose: Make JIT work with different LLVMs - LLVM 3.6 pre-merge task. Synopsis: After splitting of Compiler Lib, JIT appeared to be apart from Compiler Lib's infrastructure and without any wrapping, hence working only with statically linked LLVM from amdocl library (HSAIL), which is unacceptable in the light of 2 LLVMs after upcoming LLVM 3.6 merge. CPU should work on LLVM 3.2. Finally JIT folder is totally removed from the Compiler Lib sources and make system as unneeded laterally from the Compiler Libs infrastructure solution. Testing: pre check-in, smoke, ocl_conformance 1.2 CPU (selectively) Reviewers: Stanislav Mekhanoshin, Brian Sumner, Jan Sjodin, Artem Tamazov, Daniil Fukalov Affected files ... ... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/build/Makefile.api#109 edit ... //depot/stg/opencl/drivers/opencl/compiler/lib/Makefile#33 edit ... //depot/stg/opencl/drivers/opencl/compiler/lib/api/v0_8/acl.cpp#29 edit ... //depot/stg/opencl/drivers/opencl/compiler/lib/api/v0_8/aclLoaders.cpp#12 edit ... //depot/stg/opencl/drivers/opencl/compiler/lib/backends/common/Disassembler.cpp#1 move/add ... //depot/stg/opencl/drivers/opencl/compiler/lib/backends/common/Disassembler.h#1 move/add ... //depot/stg/opencl/drivers/opencl/compiler/lib/backends/common/build/Makefile.common#29 edit ... //depot/stg/opencl/drivers/opencl/compiler/lib/backends/common/codegen.cpp#61 edit ... //depot/stg/opencl/drivers/opencl/compiler/lib/backends/common/codegen.hpp#3 edit ... //depot/stg/opencl/drivers/opencl/compiler/lib/backends/common/v0_8/if_acl.cpp#66 edit ... //depot/stg/opencl/drivers/opencl/compiler/lib/backends/common/v0_8/if_acl.h#3 edit ... //depot/stg/opencl/drivers/opencl/compiler/lib/backends/cpu/x86_be.cpp#29 edit ... //depot/stg/opencl/drivers/opencl/compiler/lib/build/Makefile.complib#80 edit ... //depot/stg/opencl/drivers/opencl/compiler/lib/include/v0_8/acl.h#9 edit ... //depot/stg/opencl/drivers/opencl/compiler/lib/include/v0_8/aclFunctors.h#5 edit ... //depot/stg/opencl/drivers/opencl/compiler/lib/include/v0_8/aclStructs.h#16 edit ... //depot/stg/opencl/drivers/opencl/compiler/lib/include/v0_8/aclTypes.h#6 edit ... //depot/stg/opencl/drivers/opencl/compiler/lib/jit/Makefile#2 delete ... //depot/stg/opencl/drivers/opencl/compiler/lib/jit/include/jit.h#3 delete ... //depot/stg/opencl/drivers/opencl/compiler/lib/jit/src/Disassembler.cpp#4 move/delete ... //depot/stg/opencl/drivers/opencl/compiler/lib/jit/src/Disassembler.h#2 move/delete ... //depot/stg/opencl/drivers/opencl/compiler/lib/jit/src/Makefile#2 delete ... //depot/stg/opencl/drivers/opencl/compiler/lib/jit/src/build/Makefile#2 delete ... //depot/stg/opencl/drivers/opencl/compiler/lib/jit/src/build/Makefile.src#5 delete ... //depot/stg/opencl/drivers/opencl/compiler/lib/jit/src/jit.cpp#15 delete ... //depot/stg/opencl/drivers/opencl/compiler/lib/jit/src/jit.hpp#3 delete ... //depot/stg/opencl/drivers/opencl/compiler/llvm/linux/include/llvm/Config/config.h#27 edit ... //depot/stg/opencl/drivers/opencl/compiler/llvm32/linux/include/llvm/Config/config.h#2 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/cpu/cpubinary.cpp#10 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/cpu/cpuprogram.cpp#64 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/cpu/cpuprogram.hpp#12 edit ... //depot/stg/opencl/drivers/opencl/tests/ocltst/module/complib/CLAssumptionCheck.cpp#41 edit
162 baris
5.2 KiB
C++
162 baris
5.2 KiB
C++
//
|
|
// Copyright (c) 2008 Advanced Micro Devices, Inc. All rights reserved.
|
|
//
|
|
#ifndef _BE_CODEGEN_HPP_
|
|
#define _BE_CODEGEN_HPP_
|
|
#include "compiler_stage.hpp"
|
|
#include "llvm/ExecutionEngine/JITMemoryManager.h"
|
|
|
|
namespace amdcl
|
|
{
|
|
/*! \addtogroup Compiler Library
|
|
*
|
|
* \copydoc amdcl::CodeGen
|
|
*
|
|
* @{
|
|
*/
|
|
class CodeGen : public LLVMCompilerStage {
|
|
CodeGen(CodeGen&); // DO NOT IMPLEMENT.
|
|
CodeGen(); // DO NOT IMPLEMENT.
|
|
public:
|
|
CodeGen(aclCompiler *cl, aclBinary *elf, aclLogFunction log)
|
|
: LLVMCompilerStage(cl, elf, log) {}
|
|
|
|
virtual ~CodeGen() {}
|
|
|
|
/*! Function that takes in an LLVM module as input
|
|
* and generates code for it based on the target
|
|
* device.
|
|
* Returns 0 on success and non-zero on failure.
|
|
*/
|
|
virtual int codegen(llvm::Module *input) = 0;
|
|
|
|
}; // class CodeGen
|
|
/*@}*/
|
|
|
|
/*! \addtogroup Compiler Library
|
|
*
|
|
* \copydoc amdcl::CLCodeGen
|
|
*
|
|
* @{
|
|
*/
|
|
class CLCodeGen : public CodeGen {
|
|
CLCodeGen(CLCodeGen&); // DO NOT IMPLEMENT.
|
|
CLCodeGen(); // DO NOT IMPLEMENT.
|
|
public:
|
|
CLCodeGen(aclCompiler *cl, aclBinary *elf, aclLogFunction log)
|
|
: CodeGen(cl, elf, log) {}
|
|
|
|
virtual ~CLCodeGen() {}
|
|
|
|
/*! Function that takes in an LLVM module as input
|
|
* and generates code for it based on the target
|
|
* device.
|
|
* Returns 0 on success and non-zero on failure.
|
|
*/
|
|
virtual int codegen(llvm::Module *input);
|
|
|
|
}; // class CLCodeGen
|
|
/*@}*/
|
|
|
|
#if 0
|
|
/*! \addtogroup Compiler Library
|
|
*
|
|
* \copydoc amdcl::AMDILCodeGen
|
|
*
|
|
* @{
|
|
*/
|
|
class AMDILCodeGen : public CodeGen {
|
|
AMDILCodeGen(AMDILCodeGen&); // DO NOT IMPLEMENT.
|
|
AMDILCodeGen(); // DO NOT IMPLEMENT.
|
|
public:
|
|
AMDILCodeGen(aclCompiler *cl, aclBinary *elf, llvm::LLVMContext *ctx)
|
|
: CLCodeGen(cl, elf, ctx) {}
|
|
|
|
virtual ~AMDILCodeGen() {}
|
|
|
|
/*! Function that takes in an LLVM module as input
|
|
* and generates code for it based on the target
|
|
* device.
|
|
* Returns 0 on success and non-zero on failure.
|
|
*/
|
|
int codegen(llvm::Module *input) = 0;
|
|
|
|
}; // class AMDILCodeGen
|
|
/*@}*/
|
|
#endif
|
|
} // amdcl namespace
|
|
|
|
//!--------------------------------------------------------------------------!//
|
|
// JIT Memory manager
|
|
//!--------------------------------------------------------------------------!//
|
|
class OCLMCJITMemoryManager : public llvm::JITMemoryManager {
|
|
public:
|
|
typedef std::pair<llvm::sys::MemoryBlock, unsigned> Allocation;
|
|
|
|
private:
|
|
llvm::SmallVector<Allocation, 16> AllocatedDataMem;
|
|
llvm::SmallVector<Allocation, 16> AllocatedCodeMem;
|
|
|
|
// FIXME: This is part of a work around to keep sections near one another
|
|
// when MCJIT performs relocations after code emission but before
|
|
// the generated code is moved to the remote target.
|
|
llvm::sys::MemoryBlock Near;
|
|
uint8_t * reservedAlloc(uintptr_t Size, unsigned Alignment);
|
|
llvm::sys::MemoryBlock allocateSection(uintptr_t Size);
|
|
|
|
uint8_t *allocPtr;
|
|
uint8_t *allocMaxPtr;
|
|
|
|
public:
|
|
OCLMCJITMemoryManager() : allocPtr(NULL), allocMaxPtr(NULL) {}
|
|
virtual ~OCLMCJITMemoryManager();
|
|
|
|
typedef llvm::SmallVectorImpl<Allocation>::const_iterator const_data_iterator;
|
|
typedef llvm::SmallVectorImpl<Allocation>::const_iterator const_code_iterator;
|
|
|
|
const_data_iterator data_begin() const { return AllocatedDataMem.begin(); }
|
|
const_data_iterator data_end() const { return AllocatedDataMem.end(); }
|
|
const_code_iterator code_begin() const { return AllocatedCodeMem.begin(); }
|
|
const_code_iterator code_end() const { return AllocatedCodeMem.end(); }
|
|
|
|
virtual void reserveMemory(uint64_t size);
|
|
|
|
uint8_t *allocateCodeSection(uintptr_t Size, unsigned Alignment,
|
|
unsigned SectionID);
|
|
|
|
uint8_t *allocateDataSection(uintptr_t Size, unsigned Alignment,
|
|
unsigned SectionID, bool isReadOnly);
|
|
|
|
void *getPointerToNamedFunction(const std::string &Name,
|
|
bool AbortOnFailure = true);
|
|
|
|
bool applyPermissions(std::string *ErrMsg) { return false; }
|
|
|
|
// The following obsolete JITMemoryManager calls are stubbed out for
|
|
// this model.
|
|
void setMemoryWritable();
|
|
void setMemoryExecutable();
|
|
void setPoisonMemory(bool poison);
|
|
void AllocateGOT();
|
|
uint8_t *getGOTBase() const;
|
|
uint8_t *startFunctionBody(const llvm::Function *F, uintptr_t &ActualSize);
|
|
uint8_t *allocateStub(const llvm::GlobalValue* F, unsigned StubSize,
|
|
unsigned Alignment);
|
|
void endFunctionBody(const llvm::Function *F, uint8_t *FunctionStart,
|
|
uint8_t *FunctionEnd);
|
|
uint8_t *allocateSpace(intptr_t Size, unsigned Alignment);
|
|
uint8_t *allocateGlobal(uintptr_t Size, unsigned Alignment);
|
|
void deallocateFunctionBody(void *Body);
|
|
uint8_t* startExceptionTable(const llvm::Function* F, uintptr_t &ActualSize);
|
|
void endExceptionTable(const llvm::Function *F, uint8_t *TableStart,
|
|
uint8_t *TableEnd, uint8_t* FrameRegister);
|
|
void deallocateExceptionTable(void *ET);
|
|
void deallocateSection(uint8_t* BasePtr);
|
|
};
|
|
|
|
// The jitCodeGen function creates a string where the '\0' characters
|
|
// have been encoded. decodeObjectImage puts the '\0' characters back.
|
|
void decodeObjectImage(std::string encodedObjectImage, std::string &decodedObjectImage);
|
|
|
|
#endif // _BE_CODEGEN_HPP_
|