mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-24 06:30:19 +00:00
9a4584b54b
functions and initializers, just report the declarations present in the module. The motivation is to open the way for using the lazy module parsing, which should speed up clients that just want a symbol list (nm, ar). This is slightly less precise, but since both -strip-dead-prototypes and -globaldce are part of the standard pipeline, this shouldn't change the result for clang/dragonegg produced binaries. Any decl in an IL file was also put there because a FE expected it to be necessary, so this should not be a problem for "-O0 -emit-llvm". As a sanity check, I have bootstrapped clang on linux and built firefox on both linux and darwin. A clang bootstrap on darwin with LTO fails with or without this patch because, ironically, the linker doesn't like the combination of dead_strip and LTO when building libLTO.so :-) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@127870 91177308-0d34-0410-b5e6-96231b3b80d8
124 lines
5.0 KiB
C++
124 lines
5.0 KiB
C++
//===-LTOModule.h - LLVM Link Time Optimizer ------------------------------===//
|
|
//
|
|
// The LLVM Compiler Infrastructure
|
|
//
|
|
// This file is distributed under the University of Illinois Open Source
|
|
// License. See LICENSE.TXT for details.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
//
|
|
// This file declares the LTOModule class.
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef LTO_MODULE_H
|
|
#define LTO_MODULE_H
|
|
|
|
#include "llvm/Module.h"
|
|
#include "llvm/ADT/OwningPtr.h"
|
|
#include "llvm/Target/TargetMachine.h"
|
|
#include "llvm/ADT/StringMap.h"
|
|
|
|
#include "llvm-c/lto.h"
|
|
|
|
#include <vector>
|
|
#include <string>
|
|
|
|
|
|
// forward references to llvm classes
|
|
namespace llvm {
|
|
class Mangler;
|
|
class MemoryBuffer;
|
|
class GlobalValue;
|
|
class Value;
|
|
class Function;
|
|
}
|
|
|
|
|
|
//
|
|
// C++ class which implements the opaque lto_module_t
|
|
//
|
|
struct LTOModule {
|
|
|
|
static bool isBitcodeFile(const void* mem, size_t length);
|
|
static bool isBitcodeFile(const char* path);
|
|
|
|
static bool isBitcodeFileForTarget(const void* mem,
|
|
size_t length, const char* triplePrefix);
|
|
|
|
static bool isBitcodeFileForTarget(const char* path,
|
|
const char* triplePrefix);
|
|
|
|
static LTOModule* makeLTOModule(const char* path,
|
|
std::string& errMsg);
|
|
static LTOModule* makeLTOModule(int fd, const char *path,
|
|
size_t size,
|
|
std::string& errMsg);
|
|
static LTOModule* makeLTOModule(int fd, const char *path,
|
|
size_t file_size,
|
|
size_t map_size,
|
|
off_t offset,
|
|
std::string& errMsg);
|
|
static LTOModule* makeLTOModule(const void* mem, size_t length,
|
|
std::string& errMsg);
|
|
|
|
const char* getTargetTriple();
|
|
void setTargetTriple(const char*);
|
|
uint32_t getSymbolCount();
|
|
lto_symbol_attributes getSymbolAttributes(uint32_t index);
|
|
const char* getSymbolName(uint32_t index);
|
|
|
|
llvm::Module * getLLVVMModule() { return _module.get(); }
|
|
const std::vector<const char*> &getAsmUndefinedRefs() {
|
|
return _asm_undefines;
|
|
}
|
|
|
|
private:
|
|
LTOModule(llvm::Module* m, llvm::TargetMachine* t);
|
|
|
|
bool ParseSymbols();
|
|
void addDefinedSymbol(llvm::GlobalValue* def,
|
|
llvm::Mangler& mangler,
|
|
bool isFunction);
|
|
void addPotentialUndefinedSymbol(llvm::GlobalValue* decl,
|
|
llvm::Mangler &mangler);
|
|
void addDefinedFunctionSymbol(llvm::Function* f,
|
|
llvm::Mangler &mangler);
|
|
void addDefinedDataSymbol(llvm::GlobalValue* v,
|
|
llvm::Mangler &mangler);
|
|
bool addAsmGlobalSymbols(llvm::MCContext &Context);
|
|
void addAsmGlobalSymbol(const char *,
|
|
lto_symbol_attributes scope);
|
|
void addAsmGlobalSymbolUndef(const char *);
|
|
void addObjCClass(llvm::GlobalVariable* clgv);
|
|
void addObjCCategory(llvm::GlobalVariable* clgv);
|
|
void addObjCClassRef(llvm::GlobalVariable* clgv);
|
|
bool objcClassNameFromExpression(llvm::Constant* c,
|
|
std::string& name);
|
|
|
|
static bool isTargetMatch(llvm::MemoryBuffer* memBuffer,
|
|
const char* triplePrefix);
|
|
|
|
static LTOModule* makeLTOModule(llvm::MemoryBuffer* buffer,
|
|
std::string& errMsg);
|
|
static llvm::MemoryBuffer* makeBuffer(const void* mem, size_t length);
|
|
|
|
typedef llvm::StringMap<uint8_t> StringSet;
|
|
|
|
struct NameAndAttributes {
|
|
const char* name;
|
|
lto_symbol_attributes attributes;
|
|
};
|
|
|
|
llvm::OwningPtr<llvm::Module> _module;
|
|
llvm::OwningPtr<llvm::TargetMachine> _target;
|
|
std::vector<NameAndAttributes> _symbols;
|
|
// _defines and _undefines only needed to disambiguate tentative definitions
|
|
StringSet _defines;
|
|
llvm::StringMap<NameAndAttributes> _undefines;
|
|
std::vector<const char*> _asm_undefines;
|
|
};
|
|
|
|
#endif // LTO_MODULE_H
|
|
|