update for llvm 5.0.0rc1
This commit is contained in:
181
src/zig_llvm.cpp
181
src/zig_llvm.cpp
@@ -38,7 +38,6 @@
|
||||
#include <llvm/Support/FileSystem.h>
|
||||
#include <llvm/Support/TargetParser.h>
|
||||
#include <llvm/Support/raw_ostream.h>
|
||||
#include <llvm/Support/COFF.h>
|
||||
#include <llvm/Target/TargetMachine.h>
|
||||
#include <llvm/Transforms/IPO.h>
|
||||
#include <llvm/Transforms/IPO/PassManagerBuilder.h>
|
||||
@@ -105,11 +104,9 @@ bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMM
|
||||
PMBuilder->DisableTailCalls = is_debug;
|
||||
PMBuilder->DisableUnitAtATime = is_debug;
|
||||
PMBuilder->DisableUnrollLoops = is_debug;
|
||||
PMBuilder->BBVectorize = !is_debug;
|
||||
PMBuilder->SLPVectorize = !is_debug;
|
||||
PMBuilder->LoopVectorize = !is_debug;
|
||||
PMBuilder->RerollLoops = !is_debug;
|
||||
PMBuilder->LoadCombine = !is_debug;
|
||||
PMBuilder->NewGVN = !is_debug;
|
||||
PMBuilder->DisableGVNLoadPRE = is_debug;
|
||||
PMBuilder->VerifyInput = assertions_on;
|
||||
@@ -125,13 +122,10 @@ bool ZigLLVMTargetMachineEmitToFile(LLVMTargetMachineRef targ_machine_ref, LLVMM
|
||||
if (is_debug) {
|
||||
PMBuilder->Inliner = createAlwaysInlinerLegacyPass(false);
|
||||
} else {
|
||||
PMBuilder->addExtension(PassManagerBuilder::EP_EarlyAsPossible,
|
||||
[&](const PassManagerBuilder &, legacy::PassManagerBase &PM) {
|
||||
target_machine->addEarlyAsPossiblePasses(PM);
|
||||
});
|
||||
target_machine->adjustPassManager(*PMBuilder);
|
||||
|
||||
PMBuilder->addExtension(PassManagerBuilder::EP_EarlyAsPossible, addDiscriminatorsPass);
|
||||
PMBuilder->Inliner = createFunctionInliningPass(PMBuilder->OptLevel, PMBuilder->SizeLevel);
|
||||
PMBuilder->Inliner = createFunctionInliningPass(PMBuilder->OptLevel, PMBuilder->SizeLevel, false);
|
||||
}
|
||||
|
||||
// Set up the per-function pass manager.
|
||||
@@ -182,7 +176,7 @@ LLVMValueRef ZigLLVMBuildCall(LLVMBuilderRef B, LLVMValueRef Fn, LLVMValueRef *A
|
||||
CallInst *call_inst = CallInst::Create(unwrap(Fn), makeArrayRef(unwrap(Args), NumArgs), Name);
|
||||
call_inst->setCallingConv(CC);
|
||||
if (always_inline) {
|
||||
call_inst->addAttribute(AttributeSet::FunctionIndex, Attribute::AlwaysInline);
|
||||
call_inst->addAttribute(AttributeList::FunctionIndex, Attribute::AlwaysInline);
|
||||
}
|
||||
return wrap(unwrap(B)->Insert(call_inst));
|
||||
}
|
||||
@@ -198,7 +192,7 @@ ZigLLVMDIType *ZigLLVMCreateDebugPointerType(ZigLLVMDIBuilder *dibuilder, ZigLLV
|
||||
uint64_t size_in_bits, uint64_t align_in_bits, const char *name)
|
||||
{
|
||||
DIType *di_type = reinterpret_cast<DIBuilder*>(dibuilder)->createPointerType(
|
||||
reinterpret_cast<DIType*>(pointee_type), size_in_bits, align_in_bits, name);
|
||||
reinterpret_cast<DIType*>(pointee_type), size_in_bits, align_in_bits, Optional<unsigned>(), name);
|
||||
return reinterpret_cast<ZigLLVMDIType*>(di_type);
|
||||
}
|
||||
|
||||
@@ -599,23 +593,22 @@ void ZigLLVMSetFastMath(LLVMBuilderRef builder_wrapped, bool on_state) {
|
||||
|
||||
void ZigLLVMAddFunctionAttr(LLVMValueRef fn_ref, const char *attr_name, const char *attr_value) {
|
||||
Function *func = unwrap<Function>(fn_ref);
|
||||
const AttributeSet attr_set = func->getAttributes();
|
||||
const AttributeList attr_set = func->getAttributes();
|
||||
AttrBuilder attr_builder;
|
||||
if (attr_value) {
|
||||
attr_builder.addAttribute(attr_name, attr_value);
|
||||
} else {
|
||||
attr_builder.addAttribute(attr_name);
|
||||
}
|
||||
const AttributeSet new_attr_set = attr_set.addAttributes(func->getContext(),
|
||||
AttributeSet::FunctionIndex, AttributeSet::get(func->getContext(),
|
||||
AttributeSet::FunctionIndex, attr_builder));
|
||||
const AttributeList new_attr_set = attr_set.addAttributes(func->getContext(),
|
||||
AttributeList::FunctionIndex, attr_builder);
|
||||
func->setAttributes(new_attr_set);
|
||||
}
|
||||
|
||||
void ZigLLVMAddFunctionAttrCold(LLVMValueRef fn_ref) {
|
||||
Function *func = unwrap<Function>(fn_ref);
|
||||
const AttributeSet attr_set = func->getAttributes();
|
||||
const AttributeSet new_attr_set = attr_set.addAttribute(func->getContext(), AttributeSet::FunctionIndex,
|
||||
const AttributeList attr_set = func->getAttributes();
|
||||
const AttributeList new_attr_set = attr_set.addAttribute(func->getContext(), AttributeList::FunctionIndex,
|
||||
Attribute::Cold);
|
||||
func->setAttributes(new_attr_set);
|
||||
}
|
||||
@@ -690,6 +683,8 @@ const char *ZigLLVMGetSubArchTypeName(ZigLLVM_SubArchType sub_arch) {
|
||||
return "v7s";
|
||||
case ZigLLVM_ARMSubArch_v7k:
|
||||
return "v7k";
|
||||
case ZigLLVM_ARMSubArch_v7ve:
|
||||
return "v7ve";
|
||||
case ZigLLVM_ARMSubArch_v6:
|
||||
return "v6";
|
||||
case ZigLLVM_ARMSubArch_v6m:
|
||||
@@ -741,8 +736,7 @@ LLVMValueRef ZigLLVMBuildCmpXchg(LLVMBuilderRef builder, LLVMValueRef ptr, LLVMV
|
||||
LLVMAtomicOrdering failure_ordering)
|
||||
{
|
||||
return wrap(unwrap(builder)->CreateAtomicCmpXchg(unwrap(ptr), unwrap(cmp), unwrap(new_val),
|
||||
mapFromLLVMOrdering(success_ordering), mapFromLLVMOrdering(failure_ordering),
|
||||
CrossThread));
|
||||
mapFromLLVMOrdering(success_ordering), mapFromLLVMOrdering(failure_ordering)));
|
||||
}
|
||||
|
||||
LLVMValueRef ZigLLVMBuildNSWShl(LLVMBuilderRef builder, LLVMValueRef LHS, LLVMValueRef RHS,
|
||||
@@ -802,154 +796,9 @@ bool ZigLLDLink(ZigLLVM_ObjectFormatType oformat, const char **args, size_t arg_
|
||||
|
||||
case ZigLLVM_MachO:
|
||||
return lld::mach_o::link(array_ref_args, diag);
|
||||
|
||||
case ZigLLVM_Wasm:
|
||||
zig_panic("ZigLLDLink for Wasm");
|
||||
}
|
||||
zig_unreachable();
|
||||
}
|
||||
|
||||
// workaround for LLD not exposing ability to convert .def to .lib
|
||||
|
||||
#include <set>
|
||||
|
||||
namespace lld {
|
||||
namespace coff {
|
||||
|
||||
class SymbolBody;
|
||||
class StringChunk;
|
||||
struct Symbol;
|
||||
|
||||
struct Export {
|
||||
StringRef Name; // N in /export:N or /export:E=N
|
||||
StringRef ExtName; // E in /export:E=N
|
||||
SymbolBody *Sym = nullptr;
|
||||
uint16_t Ordinal = 0;
|
||||
bool Noname = false;
|
||||
bool Data = false;
|
||||
bool Private = false;
|
||||
|
||||
// If an export is a form of /export:foo=dllname.bar, that means
|
||||
// that foo should be exported as an alias to bar in the DLL.
|
||||
// ForwardTo is set to "dllname.bar" part. Usually empty.
|
||||
StringRef ForwardTo;
|
||||
StringChunk *ForwardChunk = nullptr;
|
||||
|
||||
// True if this /export option was in .drectves section.
|
||||
bool Directives = false;
|
||||
StringRef SymbolName;
|
||||
StringRef ExportName; // Name in DLL
|
||||
|
||||
bool operator==(const Export &E) {
|
||||
return (Name == E.Name && ExtName == E.ExtName &&
|
||||
Ordinal == E.Ordinal && Noname == E.Noname &&
|
||||
Data == E.Data && Private == E.Private);
|
||||
}
|
||||
};
|
||||
|
||||
enum class DebugType {
|
||||
None = 0x0,
|
||||
CV = 0x1, /// CodeView
|
||||
PData = 0x2, /// Procedure Data
|
||||
Fixup = 0x4, /// Relocation Table
|
||||
};
|
||||
|
||||
struct Configuration {
|
||||
enum ManifestKind { SideBySide, Embed, No };
|
||||
llvm::COFF::MachineTypes Machine = llvm::COFF::IMAGE_FILE_MACHINE_UNKNOWN;
|
||||
bool Verbose = false;
|
||||
llvm::COFF::WindowsSubsystem Subsystem = llvm::COFF::IMAGE_SUBSYSTEM_UNKNOWN;
|
||||
SymbolBody *Entry = nullptr;
|
||||
bool NoEntry = false;
|
||||
std::string OutputFile;
|
||||
bool DoGC = true;
|
||||
bool DoICF = true;
|
||||
bool Relocatable = true;
|
||||
bool Force = false;
|
||||
bool Debug = false;
|
||||
bool WriteSymtab = true;
|
||||
unsigned DebugTypes = static_cast<unsigned>(DebugType::None);
|
||||
StringRef PDBPath;
|
||||
|
||||
// Symbols in this set are considered as live by the garbage collector.
|
||||
std::set<SymbolBody *> GCRoot;
|
||||
|
||||
std::set<StringRef> NoDefaultLibs;
|
||||
bool NoDefaultLibAll = false;
|
||||
|
||||
// True if we are creating a DLL.
|
||||
bool DLL = false;
|
||||
StringRef Implib;
|
||||
std::vector<Export> Exports;
|
||||
std::set<std::string> DelayLoads;
|
||||
std::map<std::string, int> DLLOrder;
|
||||
SymbolBody *DelayLoadHelper = nullptr;
|
||||
|
||||
// Used for SafeSEH.
|
||||
Symbol *SEHTable = nullptr;
|
||||
Symbol *SEHCount = nullptr;
|
||||
|
||||
// Used for /opt:lldlto=N
|
||||
unsigned LTOOptLevel = 2;
|
||||
|
||||
// Used for /opt:lldltojobs=N
|
||||
unsigned LTOJobs = 1;
|
||||
|
||||
// Used for /merge:from=to (e.g. /merge:.rdata=.text)
|
||||
std::map<StringRef, StringRef> Merge;
|
||||
|
||||
// Used for /section=.name,{DEKPRSW} to set section attributes.
|
||||
std::map<StringRef, uint32_t> Section;
|
||||
|
||||
// Options for manifest files.
|
||||
ManifestKind Manifest = SideBySide;
|
||||
int ManifestID = 1;
|
||||
StringRef ManifestDependency;
|
||||
bool ManifestUAC = true;
|
||||
std::vector<std::string> ManifestInput;
|
||||
StringRef ManifestLevel = "'asInvoker'";
|
||||
StringRef ManifestUIAccess = "'false'";
|
||||
StringRef ManifestFile;
|
||||
|
||||
// Used for /failifmismatch.
|
||||
std::map<StringRef, StringRef> MustMatch;
|
||||
|
||||
// Used for /alternatename.
|
||||
std::map<StringRef, StringRef> AlternateNames;
|
||||
|
||||
uint64_t ImageBase = -1;
|
||||
uint64_t StackReserve = 1024 * 1024;
|
||||
uint64_t StackCommit = 4096;
|
||||
uint64_t HeapReserve = 1024 * 1024;
|
||||
uint64_t HeapCommit = 4096;
|
||||
uint32_t MajorImageVersion = 0;
|
||||
uint32_t MinorImageVersion = 0;
|
||||
uint32_t MajorOSVersion = 6;
|
||||
uint32_t MinorOSVersion = 0;
|
||||
bool DynamicBase = true;
|
||||
bool AllowBind = true;
|
||||
bool NxCompat = true;
|
||||
bool AllowIsolation = true;
|
||||
bool TerminalServerAware = true;
|
||||
bool LargeAddressAware = false;
|
||||
bool HighEntropyVA = false;
|
||||
|
||||
// This is for debugging.
|
||||
bool DebugPdb = false;
|
||||
bool DumpPdb = false;
|
||||
};
|
||||
|
||||
extern Configuration *Config;
|
||||
|
||||
void writeImportLibrary();
|
||||
void parseModuleDefs(MemoryBufferRef MB);
|
||||
|
||||
} // namespace coff
|
||||
} // namespace lld
|
||||
|
||||
// writes the output to dll_path with .dll replaced with .lib
|
||||
void ZigLLDDefToLib(Buf *def_contents, Buf *dll_path) {
|
||||
lld::coff::Config = new lld::coff::Configuration;
|
||||
auto mem_buf = MemoryBuffer::getMemBuffer(buf_ptr(def_contents));
|
||||
MemoryBufferRef mbref(*mem_buf);
|
||||
lld::coff::parseModuleDefs(mbref);
|
||||
lld::coff::Config->OutputFile = buf_ptr(dll_path);
|
||||
lld::coff::writeImportLibrary();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user