mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-04-07 01:38:26 +00:00
- Introduces versioning macro LLVM_LTO_VERSION
- Communicate symbol visibility - Communicate code generation model git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@46033 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
6e0a529218
commit
5e563c3264
@ -20,6 +20,8 @@
|
||||
#include <set>
|
||||
#include <llvm/ADT/hash_map>
|
||||
|
||||
#define LLVM_LTO_VERSION 2
|
||||
|
||||
namespace llvm {
|
||||
|
||||
class Module;
|
||||
@ -45,6 +47,19 @@ namespace llvm {
|
||||
LTOInternalLinkage // Rename collisions when linking (static functions)
|
||||
};
|
||||
|
||||
enum LTOVisibilityTypes {
|
||||
LTODefaultVisibility = 0, ///< The GV is visible
|
||||
LTOHiddenVisibility, ///< The GV is hidden
|
||||
LTOProtectedVisibility ///< The GV is protected
|
||||
};
|
||||
|
||||
|
||||
enum LTOCodeGenModel {
|
||||
LTO_CGM_Static,
|
||||
LTO_CGM_Dynamic,
|
||||
LTO_CGM_DynamicNoPIC
|
||||
};
|
||||
|
||||
/// This class represents LLVM symbol information without exposing details
|
||||
/// of LLVM global values. It encapsulates symbol linkage information. This
|
||||
/// is typically used in hash_map where associated name identifies the
|
||||
@ -54,10 +69,13 @@ namespace llvm {
|
||||
public:
|
||||
|
||||
LTOLinkageTypes getLinkage() const { return linkage; }
|
||||
LTOVisibilityTypes getVisibility() const { return visibility; }
|
||||
void mayBeNotUsed();
|
||||
|
||||
LLVMSymbol (enum LTOLinkageTypes lt, GlobalValue *g, const std::string &n,
|
||||
const std::string &m, int a) : linkage(lt), gv(g), name(n),
|
||||
LLVMSymbol (enum LTOLinkageTypes lt, enum LTOVisibilityTypes vis,
|
||||
GlobalValue *g, const std::string &n,
|
||||
const std::string &m, int a) : linkage(lt), visibility(vis),
|
||||
gv(g), name(n),
|
||||
mangledName(m), alignment(a) {}
|
||||
|
||||
const char *getName() { return name.c_str(); }
|
||||
@ -66,6 +84,7 @@ namespace llvm {
|
||||
|
||||
private:
|
||||
enum LTOLinkageTypes linkage;
|
||||
enum LTOVisibilityTypes visibility;
|
||||
GlobalValue *gv;
|
||||
std::string name;
|
||||
std::string mangledName;
|
||||
@ -91,11 +110,12 @@ namespace llvm {
|
||||
NameToSymbolMap &,
|
||||
std::set<std::string> &) = 0;
|
||||
virtual enum LTOStatus optimizeModules(const std::string &,
|
||||
std::vector<const char*> &,
|
||||
std::string &, bool,
|
||||
const char *) = 0;
|
||||
std::vector<const char*> &exportList,
|
||||
std::string &targetTriple,
|
||||
bool saveTemps, const char *) = 0;
|
||||
virtual void getTargetTriple(const std::string &, std::string &) = 0;
|
||||
virtual void removeModule (const std::string &InputFilename) = 0;
|
||||
virtual void setCodeGenModel(LTOCodeGenModel CGM) = 0;
|
||||
virtual void printVersion () = 0;
|
||||
virtual ~LinkTimeOptimizer() = 0;
|
||||
};
|
||||
@ -115,17 +135,20 @@ namespace llvm {
|
||||
std::set<std::string> &references);
|
||||
enum LTOStatus optimizeModules(const std::string &OutputFilename,
|
||||
std::vector<const char*> &exportList,
|
||||
std::string &targetTriple, bool saveTemps,
|
||||
const char *);
|
||||
std::string &targetTriple,
|
||||
bool saveTemps, const char *);
|
||||
void getTargetTriple(const std::string &InputFilename,
|
||||
std::string &targetTriple);
|
||||
void removeModule (const std::string &InputFilename);
|
||||
void printVersion();
|
||||
|
||||
void setCodeGenModel(LTOCodeGenModel CGM) {
|
||||
CGModel = CGM;
|
||||
}
|
||||
|
||||
// Constructors and destructors
|
||||
LTO() {
|
||||
LTO() : Target(NULL), CGModel(LTO_CGM_Dynamic) {
|
||||
/// TODO: Use Target info, it is available at this time.
|
||||
Target = NULL;
|
||||
}
|
||||
~LTO();
|
||||
|
||||
@ -140,6 +163,7 @@ namespace llvm {
|
||||
NameToSymbolMap allSymbols;
|
||||
NameToModuleMap allModules;
|
||||
TargetMachine *Target;
|
||||
LTOCodeGenModel CGModel;
|
||||
};
|
||||
|
||||
} // End llvm namespace
|
||||
@ -148,6 +172,6 @@ namespace llvm {
|
||||
/// linker to use dlopen() interface to dynamically load LinkTimeOptimizer.
|
||||
/// extern "C" helps, because dlopen() interface uses name to find the symbol.
|
||||
extern "C"
|
||||
llvm::LinkTimeOptimizer *createLLVMOptimizer();
|
||||
llvm::LinkTimeOptimizer *createLLVMOptimizer(unsigned VERSION = LLVM_LTO_VERSION);
|
||||
|
||||
#endif
|
||||
|
@ -45,8 +45,15 @@
|
||||
using namespace llvm;
|
||||
|
||||
extern "C"
|
||||
llvm::LinkTimeOptimizer *createLLVMOptimizer()
|
||||
llvm::LinkTimeOptimizer *createLLVMOptimizer(unsigned VERSION)
|
||||
{
|
||||
// Linker records LLVM_LTO_VERSION based on llvm optimizer available
|
||||
// during linker build. Match linker's recorded LTO VERSION number
|
||||
// with installed llvm optimizer version. If these numbers do not match
|
||||
// then linker may not be able to use llvm optimizer dynamically.
|
||||
if (VERSION != LLVM_LTO_VERSION)
|
||||
return NULL;
|
||||
|
||||
llvm::LTO *l = new llvm::LTO();
|
||||
return l;
|
||||
}
|
||||
@ -74,6 +81,20 @@ getLTOLinkageType(GlobalValue *v)
|
||||
return lt;
|
||||
}
|
||||
|
||||
// MAP LLVM VisibilityType to LTO VisibilityType
|
||||
static LTOVisibilityTypes
|
||||
getLTOVisibilityType(GlobalValue *v)
|
||||
{
|
||||
LTOVisibilityTypes vis;
|
||||
if (v->hasHiddenVisibility())
|
||||
vis = LTOHiddenVisibility;
|
||||
else if (v->hasProtectedVisibility())
|
||||
vis = LTOProtectedVisibility;
|
||||
else
|
||||
vis = LTODefaultVisibility;
|
||||
return vis;
|
||||
}
|
||||
|
||||
// Find exeternal symbols referenced by VALUE. This is a recursive function.
|
||||
static void
|
||||
findExternalRefs(Value *value, std::set<std::string> &references,
|
||||
@ -164,13 +185,12 @@ LTO::readLLVMObjectFile(const std::string &InputFilename,
|
||||
modules.push_back(m);
|
||||
|
||||
for (Module::iterator f = m->begin(), e = m->end(); f != e; ++f) {
|
||||
|
||||
LTOLinkageTypes lt = getLTOLinkageType(f);
|
||||
|
||||
LTOVisibilityTypes vis = getLTOVisibilityType(f);
|
||||
if (!f->isDeclaration() && lt != LTOInternalLinkage
|
||||
&& strncmp (f->getName().c_str(), "llvm.", 5)) {
|
||||
int alignment = ( 16 > f->getAlignment() ? 16 : f->getAlignment());
|
||||
LLVMSymbol *newSymbol = new LLVMSymbol(lt, f, f->getName(),
|
||||
LLVMSymbol *newSymbol = new LLVMSymbol(lt, vis, f, f->getName(),
|
||||
mangler.getValueName(f),
|
||||
Log2_32(alignment));
|
||||
symbols[newSymbol->getMangledName()] = newSymbol;
|
||||
@ -180,19 +200,21 @@ LTO::readLLVMObjectFile(const std::string &InputFilename,
|
||||
// Collect external symbols referenced by this function.
|
||||
for (Function::iterator b = f->begin(), fe = f->end(); b != fe; ++b)
|
||||
for (BasicBlock::iterator i = b->begin(), be = b->end();
|
||||
i != be; ++i)
|
||||
i != be; ++i) {
|
||||
for (unsigned count = 0, total = i->getNumOperands();
|
||||
count != total; ++count)
|
||||
findExternalRefs(i->getOperand(count), references, mangler);
|
||||
}
|
||||
}
|
||||
|
||||
for (Module::global_iterator v = m->global_begin(), e = m->global_end();
|
||||
v != e; ++v) {
|
||||
LTOLinkageTypes lt = getLTOLinkageType(v);
|
||||
LTOVisibilityTypes vis = getLTOVisibilityType(v);
|
||||
if (!v->isDeclaration() && lt != LTOInternalLinkage
|
||||
&& strncmp (v->getName().c_str(), "llvm.", 5)) {
|
||||
const TargetData *TD = Target->getTargetData();
|
||||
LLVMSymbol *newSymbol = new LLVMSymbol(lt, v, v->getName(),
|
||||
LLVMSymbol *newSymbol = new LLVMSymbol(lt, vis, v, v->getName(),
|
||||
mangler.getValueName(v),
|
||||
TD->getPreferredAlignmentLog(v));
|
||||
symbols[newSymbol->getMangledName()] = newSymbol;
|
||||
@ -354,8 +376,7 @@ enum LTOStatus
|
||||
LTO::optimizeModules(const std::string &OutputFilename,
|
||||
std::vector<const char *> &exportList,
|
||||
std::string &targetTriple,
|
||||
bool saveTemps,
|
||||
const char *FinalOutputFilename)
|
||||
bool saveTemps, const char *FinalOutputFilename)
|
||||
{
|
||||
if (modules.empty())
|
||||
return LTO_NO_WORK;
|
||||
@ -374,6 +395,18 @@ LTO::optimizeModules(const std::string &OutputFilename,
|
||||
sys::Path FinalOutputPath(FinalOutputFilename);
|
||||
FinalOutputPath.eraseSuffix();
|
||||
|
||||
switch(CGModel) {
|
||||
case LTO_CGM_Dynamic:
|
||||
Target->setRelocationModel(Reloc::PIC_);
|
||||
break;
|
||||
case LTO_CGM_DynamicNoPIC:
|
||||
Target->setRelocationModel(Reloc::DynamicNoPIC);
|
||||
break;
|
||||
case LTO_CGM_Static:
|
||||
Target->setRelocationModel(Reloc::Static);
|
||||
break;
|
||||
}
|
||||
|
||||
if (saveTemps) {
|
||||
std::string tempFileName(FinalOutputPath.c_str());
|
||||
tempFileName += "0.bc";
|
||||
|
Loading…
x
Reference in New Issue
Block a user