Files
rocm-systems/rocclr/compiler/lib/backends/common/linker.hpp
T

93 lines
2.5 KiB
C++
Raw Normal View History

2014-07-04 16:17:05 -04:00
//
// 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<std::unique_ptr<llvm::Module>> &libs) = 0;
2014-07-04 16:17:05 -04:00
}; // 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<std::unique_ptr<llvm::Module>> &libs);
2014-07-04 16:17:05 -04:00
protected:
bool linkLLVMModules(std::vector<std::unique_ptr<llvm::Module>> &libs);
bool linkWithModule(llvm::Module* Dst, std::unique_ptr<llvm::Module> Src);
2014-07-04 16:17:05 -04:00
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_