a10cfef5e7
SWDEV-85602 - switch to use of linkonce_odr for library and obsolete linkWithModule patches The linkonce_odr linkage is set to any non-local functions in the library during library build. Libraries are linked left to right and never back resolved. For that reason clp on the fly library is moved to the end of the library list. Otherwise by the time clp would like to use the scalar version of a builtin function for vector expansion this scalar function will not be available anymore. With the linkonce_odr linkage the linker includes any referenced function from a linked in module. That is true even for unused declarations. Therefor after every module my new code drops all unused declarations from the composite. If we do not do it a wrapper library such as builtins-hsail would reference all symbols from the wrapping library such as ocml and the wrapping library would be linked in almost as a whole. Dropping unused declarations solves it. Testing: smoke, pecheckin, conformance 2.0 with and w/o optimization Reviewed by Nikolay Haustov, Daniil Fukalov and Evgeny Mankov Affected files ... ... //depot/stg/opencl/drivers/opencl/compiler/lib/backends/common/linker.cpp#144 edit ... //depot/stg/opencl/drivers/opencl/compiler/lib/backends/common/linker.hpp#17 edit ... //depot/stg/opencl/drivers/opencl/compiler/lib/linker/include/AMDResolveLinker.h#4 edit ... //depot/stg/opencl/drivers/opencl/compiler/lib/linker/lib/AMDResolveLinker.cpp#4 edit ... //depot/stg/opencl/drivers/opencl/compiler/lib/linker/tools/opencl-link/opencl-link.cpp#6 edit ... //depot/stg/opencl/drivers/opencl/compiler/llvm/include/llvm/Linker/Linker.h#3 edit ... //depot/stg/opencl/drivers/opencl/compiler/llvm/lib/Linker/LinkModules.cpp#51 edit ... //depot/stg/opencl/drivers/opencl/library/x86/common/src/amdrt/build/Makefile.amdrt#24 edit ... //depot/stg/opencl/drivers/opencl/opencldefs#169 edit
93 rivejä
2.5 KiB
C++
93 rivejä
2.5 KiB
C++
//
|
|
// Copyright (c) 2008 Advanced Micro Devices, Inc. All rights reserved.
|
|
//
|
|
#ifndef _BE_LINKER_HPP_
|
|
#define _BE_LINKER_HPP_
|
|
#include "compiler_stage.hpp"
|
|
#include "aclTypes.h"
|
|
#include <string>
|
|
#include <map>
|
|
|
|
|
|
namespace llvm {
|
|
class Module;
|
|
class Value;
|
|
}; // namespace llvm
|
|
|
|
namespace amdcl
|
|
{
|
|
/*! \addtogroup Compiler Library
|
|
*
|
|
* \copydoc amdcl::Linker
|
|
*
|
|
* @{
|
|
*/
|
|
class Linker : public LLVMCompilerStage{
|
|
Linker(Linker&); // DO NOT IMPLEMENT.
|
|
Linker(); // DO NOT IMPLEMENT.
|
|
|
|
public:
|
|
Linker(aclCompiler *cl, aclBinary* elf, aclLogFunction log)
|
|
: LLVMCompilerStage(cl, elf, log) {}
|
|
|
|
virtual ~Linker() {}
|
|
|
|
|
|
|
|
/*! Function that takes as in a llvm::Module that contains LLVM-IR
|
|
* binary and links in a vector of libraries.
|
|
* Returns 0 on success, non-zero on failure.
|
|
*/
|
|
virtual int link(llvm::Module* input, std::vector<llvm::Module*> &libs) = 0;
|
|
|
|
}; // class Linker
|
|
/*@}*/
|
|
|
|
/*! \addtogroup Compiler Library
|
|
*
|
|
* \copydoc amdcl::OCLLinker
|
|
*
|
|
* @{
|
|
* \brief Linker that is unique to OpenCL.
|
|
*/
|
|
class OCLLinker : public Linker {
|
|
public:
|
|
OCLLinker(aclCompiler* cl, aclBinary* bin, aclLogFunction log)
|
|
: Linker(cl, bin, log) {}
|
|
|
|
virtual ~OCLLinker() {
|
|
for (unsigned j = 0, i = (unsigned)mathLibs_.size(); j < i; ++j) {
|
|
if (mathLibs_[j]) {
|
|
delete mathLibs_[j];
|
|
}
|
|
}
|
|
};
|
|
void setPreLinkOpt(bool Val) { hookup_.amdoptions.IsPreLinkOpt = Val; }
|
|
void setUnrollScratchThreshold(uint32_t ust) { hookup_.amdoptions.UnrollScratchThreshold = ust; }
|
|
|
|
bool getWholeProgram() { return hookup_.amdoptions.WholeProgram; }
|
|
uint32_t getUnrollScratchThreshold() { return hookup_.amdoptions.UnrollScratchThreshold; }
|
|
|
|
|
|
/*! Function that takes as input a std::string which
|
|
* contains LLVM-IR binary and links in a vector of libraries.
|
|
* This version also links in the OpenCL math libraries along with
|
|
* the list of libraries that are passed in.
|
|
*/
|
|
int link(llvm::Module* input, std::vector<llvm::Module*> &libs);
|
|
protected:
|
|
bool linkLLVMModules(std::vector<llvm::Module*> &libs);
|
|
bool linkWithModule(llvm::Module* Dst, llvm::Module* Src);
|
|
|
|
|
|
private:
|
|
static void fixupOldTriple(llvm::Module* module);
|
|
/*! Vector of modules that stores the math libraries.
|
|
*/
|
|
std::vector<llvm::Module*> mathLibs_;
|
|
}; // class OCLLinker
|
|
/*@}*/
|
|
|
|
}; // namespace amdcl
|
|
#endif // _BE_LINKER_HPP_
|