Ran clang-format on src/rustllvm with llvm as the coding style.
This commit is contained in:
parent
7f2d2afa91
commit
c72d859e4f
@ -21,52 +21,51 @@ struct RustArchiveMember {
|
||||
const char *name;
|
||||
Archive::Child child;
|
||||
|
||||
RustArchiveMember(): filename(NULL), name(NULL),
|
||||
RustArchiveMember()
|
||||
: filename(NULL), name(NULL),
|
||||
#if LLVM_VERSION_GE(3, 8)
|
||||
child(NULL, NULL, NULL)
|
||||
child(NULL, NULL, NULL)
|
||||
#else
|
||||
child(NULL, NULL)
|
||||
child(NULL, NULL)
|
||||
#endif
|
||||
{}
|
||||
{
|
||||
}
|
||||
~RustArchiveMember() {}
|
||||
};
|
||||
|
||||
|
||||
struct RustArchiveIterator {
|
||||
bool first;
|
||||
Archive::child_iterator cur;
|
||||
Archive::child_iterator end;
|
||||
bool first;
|
||||
Archive::child_iterator cur;
|
||||
Archive::child_iterator end;
|
||||
#if LLVM_VERSION_GE(3, 9)
|
||||
Error err;
|
||||
Error err;
|
||||
|
||||
RustArchiveIterator() : first(true), err(Error::success()) { }
|
||||
RustArchiveIterator() : first(true), err(Error::success()) {}
|
||||
#else
|
||||
RustArchiveIterator() : first(true) { }
|
||||
RustArchiveIterator() : first(true) {}
|
||||
#endif
|
||||
};
|
||||
|
||||
enum class LLVMRustArchiveKind {
|
||||
Other,
|
||||
GNU,
|
||||
MIPS64,
|
||||
BSD,
|
||||
COFF,
|
||||
Other,
|
||||
GNU,
|
||||
MIPS64,
|
||||
BSD,
|
||||
COFF,
|
||||
};
|
||||
|
||||
static Archive::Kind
|
||||
from_rust(LLVMRustArchiveKind kind)
|
||||
{
|
||||
switch (kind) {
|
||||
case LLVMRustArchiveKind::GNU:
|
||||
return Archive::K_GNU;
|
||||
case LLVMRustArchiveKind::MIPS64:
|
||||
return Archive::K_MIPS64;
|
||||
case LLVMRustArchiveKind::BSD:
|
||||
return Archive::K_BSD;
|
||||
case LLVMRustArchiveKind::COFF:
|
||||
return Archive::K_COFF;
|
||||
default:
|
||||
llvm_unreachable("Bad ArchiveKind.");
|
||||
static Archive::Kind from_rust(LLVMRustArchiveKind kind) {
|
||||
switch (kind) {
|
||||
case LLVMRustArchiveKind::GNU:
|
||||
return Archive::K_GNU;
|
||||
case LLVMRustArchiveKind::MIPS64:
|
||||
return Archive::K_MIPS64;
|
||||
case LLVMRustArchiveKind::BSD:
|
||||
return Archive::K_BSD;
|
||||
case LLVMRustArchiveKind::COFF:
|
||||
return Archive::K_COFF;
|
||||
default:
|
||||
llvm_unreachable("Bad ArchiveKind.");
|
||||
}
|
||||
}
|
||||
|
||||
@ -76,174 +75,166 @@ typedef Archive::Child *LLVMRustArchiveChildRef;
|
||||
typedef Archive::Child const *LLVMRustArchiveChildConstRef;
|
||||
typedef RustArchiveIterator *LLVMRustArchiveIteratorRef;
|
||||
|
||||
extern "C" LLVMRustArchiveRef
|
||||
LLVMRustOpenArchive(char *path) {
|
||||
ErrorOr<std::unique_ptr<MemoryBuffer>> buf_or = MemoryBuffer::getFile(path,
|
||||
-1,
|
||||
false);
|
||||
if (!buf_or) {
|
||||
LLVMRustSetLastError(buf_or.getError().message().c_str());
|
||||
return nullptr;
|
||||
}
|
||||
extern "C" LLVMRustArchiveRef LLVMRustOpenArchive(char *path) {
|
||||
ErrorOr<std::unique_ptr<MemoryBuffer>> buf_or =
|
||||
MemoryBuffer::getFile(path, -1, false);
|
||||
if (!buf_or) {
|
||||
LLVMRustSetLastError(buf_or.getError().message().c_str());
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
#if LLVM_VERSION_LE(3, 8)
|
||||
ErrorOr<std::unique_ptr<Archive>> archive_or =
|
||||
ErrorOr<std::unique_ptr<Archive>> archive_or =
|
||||
#else
|
||||
Expected<std::unique_ptr<Archive>> archive_or =
|
||||
Expected<std::unique_ptr<Archive>> archive_or =
|
||||
#endif
|
||||
Archive::create(buf_or.get()->getMemBufferRef());
|
||||
Archive::create(buf_or.get()->getMemBufferRef());
|
||||
|
||||
if (!archive_or) {
|
||||
if (!archive_or) {
|
||||
#if LLVM_VERSION_LE(3, 8)
|
||||
LLVMRustSetLastError(archive_or.getError().message().c_str());
|
||||
LLVMRustSetLastError(archive_or.getError().message().c_str());
|
||||
#else
|
||||
LLVMRustSetLastError(toString(archive_or.takeError()).c_str());
|
||||
LLVMRustSetLastError(toString(archive_or.takeError()).c_str());
|
||||
#endif
|
||||
return nullptr;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
OwningBinary<Archive> *ret = new OwningBinary<Archive>(
|
||||
std::move(archive_or.get()), std::move(buf_or.get()));
|
||||
OwningBinary<Archive> *ret = new OwningBinary<Archive>(
|
||||
std::move(archive_or.get()), std::move(buf_or.get()));
|
||||
|
||||
return ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
extern "C" void
|
||||
LLVMRustDestroyArchive(LLVMRustArchiveRef ar) {
|
||||
delete ar;
|
||||
}
|
||||
extern "C" void LLVMRustDestroyArchive(LLVMRustArchiveRef ar) { delete ar; }
|
||||
|
||||
extern "C" LLVMRustArchiveIteratorRef
|
||||
LLVMRustArchiveIteratorNew(LLVMRustArchiveRef ra) {
|
||||
Archive *ar = ra->getBinary();
|
||||
RustArchiveIterator *rai = new RustArchiveIterator();
|
||||
Archive *ar = ra->getBinary();
|
||||
RustArchiveIterator *rai = new RustArchiveIterator();
|
||||
#if LLVM_VERSION_LE(3, 8)
|
||||
rai->cur = ar->child_begin();
|
||||
rai->cur = ar->child_begin();
|
||||
#else
|
||||
rai->cur = ar->child_begin(rai->err);
|
||||
if (rai->err) {
|
||||
LLVMRustSetLastError(toString(std::move(rai->err)).c_str());
|
||||
delete rai;
|
||||
return NULL;
|
||||
}
|
||||
rai->cur = ar->child_begin(rai->err);
|
||||
if (rai->err) {
|
||||
LLVMRustSetLastError(toString(std::move(rai->err)).c_str());
|
||||
delete rai;
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
rai->end = ar->child_end();
|
||||
return rai;
|
||||
rai->end = ar->child_end();
|
||||
return rai;
|
||||
}
|
||||
|
||||
extern "C" LLVMRustArchiveChildConstRef
|
||||
LLVMRustArchiveIteratorNext(LLVMRustArchiveIteratorRef rai) {
|
||||
if (rai->cur == rai->end) return nullptr;
|
||||
if (rai->cur == rai->end)
|
||||
return nullptr;
|
||||
|
||||
// Advancing the iterator validates the next child, and this can
|
||||
// uncover an error. LLVM requires that we check all Errors,
|
||||
// so we only advance the iterator if we actually need to fetch
|
||||
// the next child.
|
||||
// This means we must not advance the iterator in the *first* call,
|
||||
// but instead advance it *before* fetching the child in all later calls.
|
||||
if (!rai->first) {
|
||||
++rai->cur;
|
||||
// Advancing the iterator validates the next child, and this can
|
||||
// uncover an error. LLVM requires that we check all Errors,
|
||||
// so we only advance the iterator if we actually need to fetch
|
||||
// the next child.
|
||||
// This means we must not advance the iterator in the *first* call,
|
||||
// but instead advance it *before* fetching the child in all later calls.
|
||||
if (!rai->first) {
|
||||
++rai->cur;
|
||||
#if LLVM_VERSION_GE(3, 9)
|
||||
if (rai->err) {
|
||||
LLVMRustSetLastError(toString(std::move(rai->err)).c_str());
|
||||
return nullptr;
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
rai->first = false;
|
||||
if (rai->err) {
|
||||
LLVMRustSetLastError(toString(std::move(rai->err)).c_str());
|
||||
return nullptr;
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
rai->first = false;
|
||||
}
|
||||
|
||||
if (rai->cur == rai->end) return nullptr;
|
||||
if (rai->cur == rai->end)
|
||||
return nullptr;
|
||||
|
||||
#if LLVM_VERSION_EQ(3, 8)
|
||||
const ErrorOr<Archive::Child>* cur = rai->cur.operator->();
|
||||
if (!*cur) {
|
||||
LLVMRustSetLastError(cur->getError().message().c_str());
|
||||
return nullptr;
|
||||
}
|
||||
const Archive::Child &child = cur->get();
|
||||
const ErrorOr<Archive::Child> *cur = rai->cur.operator->();
|
||||
if (!*cur) {
|
||||
LLVMRustSetLastError(cur->getError().message().c_str());
|
||||
return nullptr;
|
||||
}
|
||||
const Archive::Child &child = cur->get();
|
||||
#else
|
||||
const Archive::Child &child = *rai->cur.operator->();
|
||||
const Archive::Child &child = *rai->cur.operator->();
|
||||
#endif
|
||||
Archive::Child *ret = new Archive::Child(child);
|
||||
Archive::Child *ret = new Archive::Child(child);
|
||||
|
||||
return ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
extern "C" void
|
||||
LLVMRustArchiveChildFree(LLVMRustArchiveChildRef child) {
|
||||
delete child;
|
||||
extern "C" void LLVMRustArchiveChildFree(LLVMRustArchiveChildRef child) {
|
||||
delete child;
|
||||
}
|
||||
|
||||
extern "C" void
|
||||
LLVMRustArchiveIteratorFree(LLVMRustArchiveIteratorRef rai) {
|
||||
delete rai;
|
||||
extern "C" void LLVMRustArchiveIteratorFree(LLVMRustArchiveIteratorRef rai) {
|
||||
delete rai;
|
||||
}
|
||||
|
||||
extern "C" const char*
|
||||
extern "C" const char *
|
||||
LLVMRustArchiveChildName(LLVMRustArchiveChildConstRef child, size_t *size) {
|
||||
#if LLVM_VERSION_GE(4, 0)
|
||||
Expected<StringRef> name_or_err = child->getName();
|
||||
if (!name_or_err) {
|
||||
// rustc_llvm currently doesn't use this error string, but it might be useful
|
||||
// in the future, and in the mean time this tells LLVM that the error was
|
||||
// not ignored and that it shouldn't abort the process.
|
||||
LLVMRustSetLastError(toString(name_or_err.takeError()).c_str());
|
||||
return NULL;
|
||||
}
|
||||
Expected<StringRef> name_or_err = child->getName();
|
||||
if (!name_or_err) {
|
||||
// rustc_llvm currently doesn't use this error string, but it might be useful
|
||||
// in the future, and in the mean time this tells LLVM that the error was
|
||||
// not ignored and that it shouldn't abort the process.
|
||||
LLVMRustSetLastError(toString(name_or_err.takeError()).c_str());
|
||||
return NULL;
|
||||
}
|
||||
#else
|
||||
ErrorOr<StringRef> name_or_err = child->getName();
|
||||
if (name_or_err.getError())
|
||||
return NULL;
|
||||
ErrorOr<StringRef> name_or_err = child->getName();
|
||||
if (name_or_err.getError())
|
||||
return NULL;
|
||||
#endif
|
||||
StringRef name = name_or_err.get();
|
||||
*size = name.size();
|
||||
return name.data();
|
||||
StringRef name = name_or_err.get();
|
||||
*size = name.size();
|
||||
return name.data();
|
||||
}
|
||||
|
||||
extern "C" const char*
|
||||
LLVMRustArchiveChildData(LLVMRustArchiveChildRef child, size_t *size) {
|
||||
StringRef buf;
|
||||
extern "C" const char *LLVMRustArchiveChildData(LLVMRustArchiveChildRef child,
|
||||
size_t *size) {
|
||||
StringRef buf;
|
||||
#if LLVM_VERSION_GE(4, 0)
|
||||
Expected<StringRef> buf_or_err = child->getBuffer();
|
||||
if (!buf_or_err) {
|
||||
LLVMRustSetLastError(toString(buf_or_err.takeError()).c_str());
|
||||
return NULL;
|
||||
}
|
||||
Expected<StringRef> buf_or_err = child->getBuffer();
|
||||
if (!buf_or_err) {
|
||||
LLVMRustSetLastError(toString(buf_or_err.takeError()).c_str());
|
||||
return NULL;
|
||||
}
|
||||
#else
|
||||
ErrorOr<StringRef> buf_or_err = child->getBuffer();
|
||||
if (buf_or_err.getError()) {
|
||||
LLVMRustSetLastError(buf_or_err.getError().message().c_str());
|
||||
return NULL;
|
||||
}
|
||||
ErrorOr<StringRef> buf_or_err = child->getBuffer();
|
||||
if (buf_or_err.getError()) {
|
||||
LLVMRustSetLastError(buf_or_err.getError().message().c_str());
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
buf = buf_or_err.get();
|
||||
*size = buf.size();
|
||||
return buf.data();
|
||||
buf = buf_or_err.get();
|
||||
*size = buf.size();
|
||||
return buf.data();
|
||||
}
|
||||
|
||||
extern "C" LLVMRustArchiveMemberRef
|
||||
LLVMRustArchiveMemberNew(char *Filename, char *Name,
|
||||
LLVMRustArchiveChildRef child) {
|
||||
RustArchiveMember *Member = new RustArchiveMember;
|
||||
Member->filename = Filename;
|
||||
Member->name = Name;
|
||||
if (child)
|
||||
Member->child = *child;
|
||||
return Member;
|
||||
LLVMRustArchiveChildRef child) {
|
||||
RustArchiveMember *Member = new RustArchiveMember;
|
||||
Member->filename = Filename;
|
||||
Member->name = Name;
|
||||
if (child)
|
||||
Member->child = *child;
|
||||
return Member;
|
||||
}
|
||||
|
||||
extern "C" void
|
||||
LLVMRustArchiveMemberFree(LLVMRustArchiveMemberRef Member) {
|
||||
delete Member;
|
||||
extern "C" void LLVMRustArchiveMemberFree(LLVMRustArchiveMemberRef Member) {
|
||||
delete Member;
|
||||
}
|
||||
|
||||
extern "C" LLVMRustResult
|
||||
LLVMRustWriteArchive(char *Dst,
|
||||
size_t NumMembers,
|
||||
LLVMRustWriteArchive(char *Dst, size_t NumMembers,
|
||||
const LLVMRustArchiveMemberRef *NewMembers,
|
||||
bool WriteSymbtab,
|
||||
LLVMRustArchiveKind rust_kind) {
|
||||
bool WriteSymbtab, LLVMRustArchiveKind rust_kind) {
|
||||
|
||||
#if LLVM_VERSION_LE(3, 8)
|
||||
std::vector<NewArchiveIterator> Members;
|
||||
@ -257,7 +248,8 @@ LLVMRustWriteArchive(char *Dst,
|
||||
assert(Member->name);
|
||||
if (Member->filename) {
|
||||
#if LLVM_VERSION_GE(3, 9)
|
||||
Expected<NewArchiveMember> MOrErr = NewArchiveMember::getFile(Member->filename, true);
|
||||
Expected<NewArchiveMember> MOrErr =
|
||||
NewArchiveMember::getFile(Member->filename, true);
|
||||
if (!MOrErr) {
|
||||
LLVMRustSetLastError(toString(MOrErr.takeError()).c_str());
|
||||
return LLVMRustResult::Failure;
|
||||
@ -272,7 +264,8 @@ LLVMRustWriteArchive(char *Dst,
|
||||
#if LLVM_VERSION_LE(3, 8)
|
||||
Members.push_back(NewArchiveIterator(Member->child, Member->name));
|
||||
#else
|
||||
Expected<NewArchiveMember> MOrErr = NewArchiveMember::getOldMember(Member->child, true);
|
||||
Expected<NewArchiveMember> MOrErr =
|
||||
NewArchiveMember::getOldMember(Member->child, true);
|
||||
if (!MOrErr) {
|
||||
LLVMRustSetLastError(toString(MOrErr.takeError()).c_str());
|
||||
return LLVMRustResult::Failure;
|
||||
|
@ -12,12 +12,12 @@
|
||||
|
||||
#include "rustllvm.h"
|
||||
|
||||
#include "llvm/Support/CBindingWrapping.h"
|
||||
#include "llvm/Support/FileSystem.h"
|
||||
#include "llvm/Support/Host.h"
|
||||
#include "llvm/Analysis/TargetLibraryInfo.h"
|
||||
#include "llvm/Analysis/TargetTransformInfo.h"
|
||||
#include "llvm/IR/AutoUpgrade.h"
|
||||
#include "llvm/Support/CBindingWrapping.h"
|
||||
#include "llvm/Support/FileSystem.h"
|
||||
#include "llvm/Support/Host.h"
|
||||
#include "llvm/Target/TargetMachine.h"
|
||||
#include "llvm/Target/TargetSubtargetInfo.h"
|
||||
#include "llvm/Transforms/IPO/PassManagerBuilder.h"
|
||||
@ -38,10 +38,10 @@ typedef struct LLVMOpaqueTargetMachine *LLVMTargetMachineRef;
|
||||
|
||||
DEFINE_STDCXX_CONVERSION_FUNCTIONS(Pass, LLVMPassRef)
|
||||
DEFINE_STDCXX_CONVERSION_FUNCTIONS(TargetMachine, LLVMTargetMachineRef)
|
||||
DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassManagerBuilder, LLVMPassManagerBuilderRef)
|
||||
DEFINE_STDCXX_CONVERSION_FUNCTIONS(PassManagerBuilder,
|
||||
LLVMPassManagerBuilderRef)
|
||||
|
||||
extern "C" void
|
||||
LLVMInitializePasses() {
|
||||
extern "C" void LLVMInitializePasses() {
|
||||
PassRegistry &Registry = *PassRegistry::getPassRegistry();
|
||||
initializeCore(Registry);
|
||||
initializeCodeGen(Registry);
|
||||
@ -64,44 +64,39 @@ enum class LLVMRustPassKind {
|
||||
Module,
|
||||
};
|
||||
|
||||
static LLVMRustPassKind
|
||||
to_rust(PassKind kind)
|
||||
{
|
||||
static LLVMRustPassKind to_rust(PassKind kind) {
|
||||
switch (kind) {
|
||||
case PT_Function:
|
||||
return LLVMRustPassKind::Function;
|
||||
return LLVMRustPassKind::Function;
|
||||
case PT_Module:
|
||||
return LLVMRustPassKind::Module;
|
||||
return LLVMRustPassKind::Module;
|
||||
default:
|
||||
return LLVMRustPassKind::Other;
|
||||
return LLVMRustPassKind::Other;
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" LLVMPassRef
|
||||
LLVMRustFindAndCreatePass(const char *PassName) {
|
||||
StringRef SR(PassName);
|
||||
PassRegistry *PR = PassRegistry::getPassRegistry();
|
||||
extern "C" LLVMPassRef LLVMRustFindAndCreatePass(const char *PassName) {
|
||||
StringRef SR(PassName);
|
||||
PassRegistry *PR = PassRegistry::getPassRegistry();
|
||||
|
||||
const PassInfo *PI = PR->getPassInfo(SR);
|
||||
if (PI) {
|
||||
return wrap(PI->createPass());
|
||||
}
|
||||
return NULL;
|
||||
const PassInfo *PI = PR->getPassInfo(SR);
|
||||
if (PI) {
|
||||
return wrap(PI->createPass());
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
extern "C" LLVMRustPassKind
|
||||
LLVMRustPassKind(LLVMPassRef rust_pass) {
|
||||
assert(rust_pass);
|
||||
Pass *pass = unwrap(rust_pass);
|
||||
return to_rust(pass->getPassKind());
|
||||
extern "C" LLVMRustPassKind LLVMRustPassKind(LLVMPassRef rust_pass) {
|
||||
assert(rust_pass);
|
||||
Pass *pass = unwrap(rust_pass);
|
||||
return to_rust(pass->getPassKind());
|
||||
}
|
||||
|
||||
extern "C" void
|
||||
LLVMRustAddPass(LLVMPassManagerRef PM, LLVMPassRef rust_pass) {
|
||||
assert(rust_pass);
|
||||
Pass *pass = unwrap(rust_pass);
|
||||
PassManagerBase *pm = unwrap(PM);
|
||||
pm->add(pass);
|
||||
extern "C" void LLVMRustAddPass(LLVMPassManagerRef PM, LLVMPassRef rust_pass) {
|
||||
assert(rust_pass);
|
||||
Pass *pass = unwrap(rust_pass);
|
||||
PassManagerBase *pm = unwrap(PM);
|
||||
pm->add(pass);
|
||||
}
|
||||
|
||||
#ifdef LLVM_COMPONENT_X86
|
||||
@ -146,100 +141,94 @@ LLVMRustAddPass(LLVMPassManagerRef PM, LLVMPassRef rust_pass) {
|
||||
#define SUBTARGET_MSP430
|
||||
#endif
|
||||
|
||||
#define GEN_SUBTARGETS \
|
||||
SUBTARGET_X86 \
|
||||
SUBTARGET_ARM \
|
||||
SUBTARGET_AARCH64 \
|
||||
SUBTARGET_MIPS \
|
||||
SUBTARGET_PPC \
|
||||
SUBTARGET_SYSTEMZ \
|
||||
SUBTARGET_MSP430
|
||||
#define GEN_SUBTARGETS \
|
||||
SUBTARGET_X86 \
|
||||
SUBTARGET_ARM \
|
||||
SUBTARGET_AARCH64 \
|
||||
SUBTARGET_MIPS \
|
||||
SUBTARGET_PPC \
|
||||
SUBTARGET_SYSTEMZ \
|
||||
SUBTARGET_MSP430
|
||||
|
||||
#define SUBTARGET(x) namespace llvm { \
|
||||
extern const SubtargetFeatureKV x##FeatureKV[]; \
|
||||
extern const SubtargetFeatureKV x##SubTypeKV[]; \
|
||||
#define SUBTARGET(x) \
|
||||
namespace llvm { \
|
||||
extern const SubtargetFeatureKV x##FeatureKV[]; \
|
||||
extern const SubtargetFeatureKV x##SubTypeKV[]; \
|
||||
}
|
||||
|
||||
GEN_SUBTARGETS
|
||||
#undef SUBTARGET
|
||||
|
||||
extern "C" bool
|
||||
LLVMRustHasFeature(LLVMTargetMachineRef TM,
|
||||
const char *feature) {
|
||||
TargetMachine *Target = unwrap(TM);
|
||||
const MCSubtargetInfo *MCInfo = Target->getMCSubtargetInfo();
|
||||
const FeatureBitset &Bits = MCInfo->getFeatureBits();
|
||||
const llvm::SubtargetFeatureKV *FeatureEntry;
|
||||
extern "C" bool LLVMRustHasFeature(LLVMTargetMachineRef TM,
|
||||
const char *feature) {
|
||||
TargetMachine *Target = unwrap(TM);
|
||||
const MCSubtargetInfo *MCInfo = Target->getMCSubtargetInfo();
|
||||
const FeatureBitset &Bits = MCInfo->getFeatureBits();
|
||||
const llvm::SubtargetFeatureKV *FeatureEntry;
|
||||
|
||||
#define SUBTARGET(x) \
|
||||
if (MCInfo->isCPUStringValid(x##SubTypeKV[0].Key)) { \
|
||||
FeatureEntry = x##FeatureKV; \
|
||||
} else
|
||||
#define SUBTARGET(x) \
|
||||
if (MCInfo->isCPUStringValid(x##SubTypeKV[0].Key)) { \
|
||||
FeatureEntry = x##FeatureKV; \
|
||||
} else
|
||||
|
||||
GEN_SUBTARGETS {
|
||||
return false;
|
||||
}
|
||||
GEN_SUBTARGETS { return false; }
|
||||
#undef SUBTARGET
|
||||
|
||||
while (strcmp(feature, FeatureEntry->Key) != 0)
|
||||
FeatureEntry++;
|
||||
while (strcmp(feature, FeatureEntry->Key) != 0)
|
||||
FeatureEntry++;
|
||||
|
||||
return (Bits & FeatureEntry->Value) == FeatureEntry->Value;
|
||||
return (Bits & FeatureEntry->Value) == FeatureEntry->Value;
|
||||
}
|
||||
|
||||
enum class LLVMRustCodeModel {
|
||||
Other,
|
||||
Default,
|
||||
JITDefault,
|
||||
Small,
|
||||
Kernel,
|
||||
Medium,
|
||||
Large,
|
||||
Other,
|
||||
Default,
|
||||
JITDefault,
|
||||
Small,
|
||||
Kernel,
|
||||
Medium,
|
||||
Large,
|
||||
};
|
||||
|
||||
static CodeModel::Model
|
||||
from_rust(LLVMRustCodeModel model)
|
||||
{
|
||||
switch (model) {
|
||||
case LLVMRustCodeModel::Default:
|
||||
return CodeModel::Default;
|
||||
case LLVMRustCodeModel::JITDefault:
|
||||
return CodeModel::JITDefault;
|
||||
case LLVMRustCodeModel::Small:
|
||||
return CodeModel::Small;
|
||||
case LLVMRustCodeModel::Kernel:
|
||||
return CodeModel::Kernel;
|
||||
case LLVMRustCodeModel::Medium:
|
||||
return CodeModel::Medium;
|
||||
case LLVMRustCodeModel::Large:
|
||||
return CodeModel::Large;
|
||||
default:
|
||||
llvm_unreachable("Bad CodeModel.");
|
||||
static CodeModel::Model from_rust(LLVMRustCodeModel model) {
|
||||
switch (model) {
|
||||
case LLVMRustCodeModel::Default:
|
||||
return CodeModel::Default;
|
||||
case LLVMRustCodeModel::JITDefault:
|
||||
return CodeModel::JITDefault;
|
||||
case LLVMRustCodeModel::Small:
|
||||
return CodeModel::Small;
|
||||
case LLVMRustCodeModel::Kernel:
|
||||
return CodeModel::Kernel;
|
||||
case LLVMRustCodeModel::Medium:
|
||||
return CodeModel::Medium;
|
||||
case LLVMRustCodeModel::Large:
|
||||
return CodeModel::Large;
|
||||
default:
|
||||
llvm_unreachable("Bad CodeModel.");
|
||||
}
|
||||
}
|
||||
|
||||
enum class LLVMRustCodeGenOptLevel {
|
||||
Other,
|
||||
None,
|
||||
Less,
|
||||
Default,
|
||||
Aggressive,
|
||||
Other,
|
||||
None,
|
||||
Less,
|
||||
Default,
|
||||
Aggressive,
|
||||
};
|
||||
|
||||
static CodeGenOpt::Level
|
||||
from_rust(LLVMRustCodeGenOptLevel level)
|
||||
{
|
||||
switch (level) {
|
||||
case LLVMRustCodeGenOptLevel::None:
|
||||
return CodeGenOpt::None;
|
||||
case LLVMRustCodeGenOptLevel::Less:
|
||||
return CodeGenOpt::Less;
|
||||
case LLVMRustCodeGenOptLevel::Default:
|
||||
return CodeGenOpt::Default;
|
||||
case LLVMRustCodeGenOptLevel::Aggressive:
|
||||
return CodeGenOpt::Aggressive;
|
||||
default:
|
||||
llvm_unreachable("Bad CodeGenOptLevel.");
|
||||
static CodeGenOpt::Level from_rust(LLVMRustCodeGenOptLevel level) {
|
||||
switch (level) {
|
||||
case LLVMRustCodeGenOptLevel::None:
|
||||
return CodeGenOpt::None;
|
||||
case LLVMRustCodeGenOptLevel::Less:
|
||||
return CodeGenOpt::Less;
|
||||
case LLVMRustCodeGenOptLevel::Default:
|
||||
return CodeGenOpt::Default;
|
||||
case LLVMRustCodeGenOptLevel::Aggressive:
|
||||
return CodeGenOpt::Aggressive;
|
||||
default:
|
||||
llvm_unreachable("Bad CodeGenOptLevel.");
|
||||
}
|
||||
}
|
||||
|
||||
@ -253,234 +242,209 @@ static size_t getLongestEntryLength(ArrayRef<SubtargetFeatureKV> Table) {
|
||||
return MaxLen;
|
||||
}
|
||||
|
||||
extern "C" void
|
||||
LLVMRustPrintTargetCPUs(LLVMTargetMachineRef TM) {
|
||||
const TargetMachine *Target = unwrap(TM);
|
||||
const MCSubtargetInfo *MCInfo = Target->getMCSubtargetInfo();
|
||||
const ArrayRef<SubtargetFeatureKV> CPUTable = MCInfo->getCPUTable();
|
||||
unsigned MaxCPULen = getLongestEntryLength(CPUTable);
|
||||
extern "C" void LLVMRustPrintTargetCPUs(LLVMTargetMachineRef TM) {
|
||||
const TargetMachine *Target = unwrap(TM);
|
||||
const MCSubtargetInfo *MCInfo = Target->getMCSubtargetInfo();
|
||||
const ArrayRef<SubtargetFeatureKV> CPUTable = MCInfo->getCPUTable();
|
||||
unsigned MaxCPULen = getLongestEntryLength(CPUTable);
|
||||
|
||||
printf("Available CPUs for this target:\n");
|
||||
for (auto &CPU : CPUTable)
|
||||
printf(" %-*s - %s.\n", MaxCPULen, CPU.Key, CPU.Desc);
|
||||
printf("\n");
|
||||
printf("Available CPUs for this target:\n");
|
||||
for (auto &CPU : CPUTable)
|
||||
printf(" %-*s - %s.\n", MaxCPULen, CPU.Key, CPU.Desc);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
extern "C" void
|
||||
LLVMRustPrintTargetFeatures(LLVMTargetMachineRef TM) {
|
||||
const TargetMachine *Target = unwrap(TM);
|
||||
const MCSubtargetInfo *MCInfo = Target->getMCSubtargetInfo();
|
||||
const ArrayRef<SubtargetFeatureKV> FeatTable = MCInfo->getFeatureTable();
|
||||
unsigned MaxFeatLen = getLongestEntryLength(FeatTable);
|
||||
extern "C" void LLVMRustPrintTargetFeatures(LLVMTargetMachineRef TM) {
|
||||
const TargetMachine *Target = unwrap(TM);
|
||||
const MCSubtargetInfo *MCInfo = Target->getMCSubtargetInfo();
|
||||
const ArrayRef<SubtargetFeatureKV> FeatTable = MCInfo->getFeatureTable();
|
||||
unsigned MaxFeatLen = getLongestEntryLength(FeatTable);
|
||||
|
||||
printf("Available features for this target:\n");
|
||||
for (auto &Feature : FeatTable)
|
||||
printf(" %-*s - %s.\n", MaxFeatLen, Feature.Key, Feature.Desc);
|
||||
printf("\n");
|
||||
printf("Available features for this target:\n");
|
||||
for (auto &Feature : FeatTable)
|
||||
printf(" %-*s - %s.\n", MaxFeatLen, Feature.Key, Feature.Desc);
|
||||
printf("\n");
|
||||
|
||||
printf("Use +feature to enable a feature, or -feature to disable it.\n"
|
||||
"For example, rustc -C -target-cpu=mycpu -C target-feature=+feature1,-feature2\n\n");
|
||||
printf("Use +feature to enable a feature, or -feature to disable it.\n"
|
||||
"For example, rustc -C -target-cpu=mycpu -C "
|
||||
"target-feature=+feature1,-feature2\n\n");
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
extern "C" void
|
||||
LLVMRustPrintTargetCPUs(LLVMTargetMachineRef) {
|
||||
printf("Target CPU help is not supported by this LLVM version.\n\n");
|
||||
extern "C" void LLVMRustPrintTargetCPUs(LLVMTargetMachineRef) {
|
||||
printf("Target CPU help is not supported by this LLVM version.\n\n");
|
||||
}
|
||||
|
||||
extern "C" void
|
||||
LLVMRustPrintTargetFeatures(LLVMTargetMachineRef) {
|
||||
printf("Target features help is not supported by this LLVM version.\n\n");
|
||||
extern "C" void LLVMRustPrintTargetFeatures(LLVMTargetMachineRef) {
|
||||
printf("Target features help is not supported by this LLVM version.\n\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
extern "C" LLVMTargetMachineRef
|
||||
LLVMRustCreateTargetMachine(const char *triple,
|
||||
const char *cpu,
|
||||
const char *feature,
|
||||
LLVMRustCodeModel rust_CM,
|
||||
LLVMRelocMode Reloc,
|
||||
LLVMRustCodeGenOptLevel rust_OptLevel,
|
||||
bool UseSoftFloat,
|
||||
bool PositionIndependentExecutable,
|
||||
bool FunctionSections,
|
||||
bool DataSections) {
|
||||
extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine(
|
||||
const char *triple, const char *cpu, const char *feature,
|
||||
LLVMRustCodeModel rust_CM, LLVMRelocMode Reloc,
|
||||
LLVMRustCodeGenOptLevel rust_OptLevel, bool UseSoftFloat,
|
||||
bool PositionIndependentExecutable, bool FunctionSections,
|
||||
bool DataSections) {
|
||||
|
||||
#if LLVM_VERSION_LE(3, 8)
|
||||
Reloc::Model RM;
|
||||
Reloc::Model RM;
|
||||
#else
|
||||
Optional<Reloc::Model> RM;
|
||||
Optional<Reloc::Model> RM;
|
||||
#endif
|
||||
auto CM = from_rust(rust_CM);
|
||||
auto OptLevel = from_rust(rust_OptLevel);
|
||||
auto CM = from_rust(rust_CM);
|
||||
auto OptLevel = from_rust(rust_OptLevel);
|
||||
|
||||
switch (Reloc){
|
||||
case LLVMRelocStatic:
|
||||
RM = Reloc::Static;
|
||||
break;
|
||||
case LLVMRelocPIC:
|
||||
RM = Reloc::PIC_;
|
||||
break;
|
||||
case LLVMRelocDynamicNoPic:
|
||||
RM = Reloc::DynamicNoPIC;
|
||||
break;
|
||||
default:
|
||||
switch (Reloc) {
|
||||
case LLVMRelocStatic:
|
||||
RM = Reloc::Static;
|
||||
break;
|
||||
case LLVMRelocPIC:
|
||||
RM = Reloc::PIC_;
|
||||
break;
|
||||
case LLVMRelocDynamicNoPic:
|
||||
RM = Reloc::DynamicNoPIC;
|
||||
break;
|
||||
default:
|
||||
#if LLVM_VERSION_LE(3, 8)
|
||||
RM = Reloc::Default;
|
||||
RM = Reloc::Default;
|
||||
#endif
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
std::string Error;
|
||||
Triple Trip(Triple::normalize(triple));
|
||||
const llvm::Target *TheTarget = TargetRegistry::lookupTarget(Trip.getTriple(),
|
||||
Error);
|
||||
if (TheTarget == NULL) {
|
||||
LLVMRustSetLastError(Error.c_str());
|
||||
return NULL;
|
||||
}
|
||||
std::string Error;
|
||||
Triple Trip(Triple::normalize(triple));
|
||||
const llvm::Target *TheTarget =
|
||||
TargetRegistry::lookupTarget(Trip.getTriple(), Error);
|
||||
if (TheTarget == NULL) {
|
||||
LLVMRustSetLastError(Error.c_str());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
StringRef real_cpu = cpu;
|
||||
if (real_cpu == "native") {
|
||||
real_cpu = sys::getHostCPUName();
|
||||
}
|
||||
StringRef real_cpu = cpu;
|
||||
if (real_cpu == "native") {
|
||||
real_cpu = sys::getHostCPUName();
|
||||
}
|
||||
|
||||
TargetOptions Options;
|
||||
TargetOptions Options;
|
||||
#if LLVM_VERSION_LE(3, 8)
|
||||
Options.PositionIndependentExecutable = PositionIndependentExecutable;
|
||||
Options.PositionIndependentExecutable = PositionIndependentExecutable;
|
||||
#endif
|
||||
|
||||
Options.FloatABIType = FloatABI::Default;
|
||||
if (UseSoftFloat) {
|
||||
Options.FloatABIType = FloatABI::Soft;
|
||||
}
|
||||
Options.DataSections = DataSections;
|
||||
Options.FunctionSections = FunctionSections;
|
||||
Options.FloatABIType = FloatABI::Default;
|
||||
if (UseSoftFloat) {
|
||||
Options.FloatABIType = FloatABI::Soft;
|
||||
}
|
||||
Options.DataSections = DataSections;
|
||||
Options.FunctionSections = FunctionSections;
|
||||
|
||||
TargetMachine *TM = TheTarget->createTargetMachine(Trip.getTriple(),
|
||||
real_cpu,
|
||||
feature,
|
||||
Options,
|
||||
RM,
|
||||
CM,
|
||||
OptLevel);
|
||||
return wrap(TM);
|
||||
TargetMachine *TM = TheTarget->createTargetMachine(
|
||||
Trip.getTriple(), real_cpu, feature, Options, RM, CM, OptLevel);
|
||||
return wrap(TM);
|
||||
}
|
||||
|
||||
extern "C" void
|
||||
LLVMRustDisposeTargetMachine(LLVMTargetMachineRef TM) {
|
||||
delete unwrap(TM);
|
||||
extern "C" void LLVMRustDisposeTargetMachine(LLVMTargetMachineRef TM) {
|
||||
delete unwrap(TM);
|
||||
}
|
||||
|
||||
// Unfortunately, LLVM doesn't expose a C API to add the corresponding analysis
|
||||
// passes for a target to a pass manager. We export that functionality through
|
||||
// this function.
|
||||
extern "C" void
|
||||
LLVMRustAddAnalysisPasses(LLVMTargetMachineRef TM,
|
||||
LLVMPassManagerRef PMR,
|
||||
LLVMModuleRef M) {
|
||||
PassManagerBase *PM = unwrap(PMR);
|
||||
PM->add(createTargetTransformInfoWrapperPass(
|
||||
unwrap(TM)->getTargetIRAnalysis()));
|
||||
extern "C" void LLVMRustAddAnalysisPasses(LLVMTargetMachineRef TM,
|
||||
LLVMPassManagerRef PMR,
|
||||
LLVMModuleRef M) {
|
||||
PassManagerBase *PM = unwrap(PMR);
|
||||
PM->add(
|
||||
createTargetTransformInfoWrapperPass(unwrap(TM)->getTargetIRAnalysis()));
|
||||
}
|
||||
|
||||
extern "C" void
|
||||
LLVMRustConfigurePassManagerBuilder(LLVMPassManagerBuilderRef PMB,
|
||||
LLVMRustCodeGenOptLevel OptLevel,
|
||||
bool MergeFunctions,
|
||||
bool SLPVectorize,
|
||||
bool LoopVectorize) {
|
||||
// Ignore mergefunc for now as enabling it causes crashes.
|
||||
//unwrap(PMB)->MergeFunctions = MergeFunctions;
|
||||
unwrap(PMB)->SLPVectorize = SLPVectorize;
|
||||
unwrap(PMB)->OptLevel = from_rust(OptLevel);
|
||||
unwrap(PMB)->LoopVectorize = LoopVectorize;
|
||||
extern "C" void LLVMRustConfigurePassManagerBuilder(
|
||||
LLVMPassManagerBuilderRef PMB, LLVMRustCodeGenOptLevel OptLevel,
|
||||
bool MergeFunctions, bool SLPVectorize, bool LoopVectorize) {
|
||||
// Ignore mergefunc for now as enabling it causes crashes.
|
||||
// unwrap(PMB)->MergeFunctions = MergeFunctions;
|
||||
unwrap(PMB)->SLPVectorize = SLPVectorize;
|
||||
unwrap(PMB)->OptLevel = from_rust(OptLevel);
|
||||
unwrap(PMB)->LoopVectorize = LoopVectorize;
|
||||
}
|
||||
|
||||
// Unfortunately, the LLVM C API doesn't provide a way to set the `LibraryInfo`
|
||||
// field of a PassManagerBuilder, we expose our own method of doing so.
|
||||
extern "C" void
|
||||
LLVMRustAddBuilderLibraryInfo(LLVMPassManagerBuilderRef PMB,
|
||||
LLVMModuleRef M,
|
||||
bool DisableSimplifyLibCalls) {
|
||||
Triple TargetTriple(unwrap(M)->getTargetTriple());
|
||||
TargetLibraryInfoImpl *TLI = new TargetLibraryInfoImpl(TargetTriple);
|
||||
if (DisableSimplifyLibCalls)
|
||||
TLI->disableAllFunctions();
|
||||
unwrap(PMB)->LibraryInfo = TLI;
|
||||
extern "C" void LLVMRustAddBuilderLibraryInfo(LLVMPassManagerBuilderRef PMB,
|
||||
LLVMModuleRef M,
|
||||
bool DisableSimplifyLibCalls) {
|
||||
Triple TargetTriple(unwrap(M)->getTargetTriple());
|
||||
TargetLibraryInfoImpl *TLI = new TargetLibraryInfoImpl(TargetTriple);
|
||||
if (DisableSimplifyLibCalls)
|
||||
TLI->disableAllFunctions();
|
||||
unwrap(PMB)->LibraryInfo = TLI;
|
||||
}
|
||||
|
||||
// Unfortunately, the LLVM C API doesn't provide a way to create the
|
||||
// TargetLibraryInfo pass, so we use this method to do so.
|
||||
extern "C" void
|
||||
LLVMRustAddLibraryInfo(LLVMPassManagerRef PMB,
|
||||
LLVMModuleRef M,
|
||||
bool DisableSimplifyLibCalls) {
|
||||
Triple TargetTriple(unwrap(M)->getTargetTriple());
|
||||
TargetLibraryInfoImpl TLII(TargetTriple);
|
||||
if (DisableSimplifyLibCalls)
|
||||
TLII.disableAllFunctions();
|
||||
unwrap(PMB)->add(new TargetLibraryInfoWrapperPass(TLII));
|
||||
extern "C" void LLVMRustAddLibraryInfo(LLVMPassManagerRef PMB, LLVMModuleRef M,
|
||||
bool DisableSimplifyLibCalls) {
|
||||
Triple TargetTriple(unwrap(M)->getTargetTriple());
|
||||
TargetLibraryInfoImpl TLII(TargetTriple);
|
||||
if (DisableSimplifyLibCalls)
|
||||
TLII.disableAllFunctions();
|
||||
unwrap(PMB)->add(new TargetLibraryInfoWrapperPass(TLII));
|
||||
}
|
||||
|
||||
// Unfortunately, the LLVM C API doesn't provide an easy way of iterating over
|
||||
// all the functions in a module, so we do that manually here. You'll find
|
||||
// similar code in clang's BackendUtil.cpp file.
|
||||
extern "C" void
|
||||
LLVMRustRunFunctionPassManager(LLVMPassManagerRef PM, LLVMModuleRef M) {
|
||||
llvm::legacy::FunctionPassManager *P = unwrap<llvm::legacy::FunctionPassManager>(PM);
|
||||
P->doInitialization();
|
||||
extern "C" void LLVMRustRunFunctionPassManager(LLVMPassManagerRef PM,
|
||||
LLVMModuleRef M) {
|
||||
llvm::legacy::FunctionPassManager *P =
|
||||
unwrap<llvm::legacy::FunctionPassManager>(PM);
|
||||
P->doInitialization();
|
||||
|
||||
// Upgrade all calls to old intrinsics first.
|
||||
for (Module::iterator I = unwrap(M)->begin(),
|
||||
E = unwrap(M)->end(); I != E;)
|
||||
UpgradeCallsToIntrinsic(&*I++); // must be post-increment, as we remove
|
||||
// Upgrade all calls to old intrinsics first.
|
||||
for (Module::iterator I = unwrap(M)->begin(), E = unwrap(M)->end(); I != E;)
|
||||
UpgradeCallsToIntrinsic(&*I++); // must be post-increment, as we remove
|
||||
|
||||
for (Module::iterator I = unwrap(M)->begin(),
|
||||
E = unwrap(M)->end(); I != E; ++I)
|
||||
if (!I->isDeclaration())
|
||||
P->run(*I);
|
||||
for (Module::iterator I = unwrap(M)->begin(), E = unwrap(M)->end(); I != E;
|
||||
++I)
|
||||
if (!I->isDeclaration())
|
||||
P->run(*I);
|
||||
|
||||
P->doFinalization();
|
||||
P->doFinalization();
|
||||
}
|
||||
|
||||
extern "C" void
|
||||
LLVMRustSetLLVMOptions(int Argc, char **Argv) {
|
||||
// Initializing the command-line options more than once is not allowed. So,
|
||||
// check if they've already been initialized. (This could happen if we're
|
||||
// being called from rustpkg, for example). If the arguments change, then
|
||||
// that's just kinda unfortunate.
|
||||
static bool initialized = false;
|
||||
if (initialized) return;
|
||||
initialized = true;
|
||||
cl::ParseCommandLineOptions(Argc, Argv);
|
||||
extern "C" void LLVMRustSetLLVMOptions(int Argc, char **Argv) {
|
||||
// Initializing the command-line options more than once is not allowed. So,
|
||||
// check if they've already been initialized. (This could happen if we're
|
||||
// being called from rustpkg, for example). If the arguments change, then
|
||||
// that's just kinda unfortunate.
|
||||
static bool initialized = false;
|
||||
if (initialized)
|
||||
return;
|
||||
initialized = true;
|
||||
cl::ParseCommandLineOptions(Argc, Argv);
|
||||
}
|
||||
|
||||
enum class LLVMRustFileType {
|
||||
Other,
|
||||
AssemblyFile,
|
||||
ObjectFile,
|
||||
Other,
|
||||
AssemblyFile,
|
||||
ObjectFile,
|
||||
};
|
||||
|
||||
static TargetMachine::CodeGenFileType
|
||||
from_rust(LLVMRustFileType type)
|
||||
{
|
||||
switch (type) {
|
||||
case LLVMRustFileType::AssemblyFile:
|
||||
return TargetMachine::CGFT_AssemblyFile;
|
||||
case LLVMRustFileType::ObjectFile:
|
||||
return TargetMachine::CGFT_ObjectFile;
|
||||
default:
|
||||
llvm_unreachable("Bad FileType.");
|
||||
static TargetMachine::CodeGenFileType from_rust(LLVMRustFileType type) {
|
||||
switch (type) {
|
||||
case LLVMRustFileType::AssemblyFile:
|
||||
return TargetMachine::CGFT_AssemblyFile;
|
||||
case LLVMRustFileType::ObjectFile:
|
||||
return TargetMachine::CGFT_ObjectFile;
|
||||
default:
|
||||
llvm_unreachable("Bad FileType.");
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" LLVMRustResult
|
||||
LLVMRustWriteOutputFile(LLVMTargetMachineRef Target,
|
||||
LLVMPassManagerRef PMR,
|
||||
LLVMModuleRef M,
|
||||
const char *path,
|
||||
LLVMRustWriteOutputFile(LLVMTargetMachineRef Target, LLVMPassManagerRef PMR,
|
||||
LLVMModuleRef M, const char *path,
|
||||
LLVMRustFileType rust_FileType) {
|
||||
llvm::legacy::PassManager *PM = unwrap<llvm::legacy::PassManager>(PMR);
|
||||
auto FileType = from_rust(rust_FileType);
|
||||
@ -505,10 +469,8 @@ LLVMRustWriteOutputFile(LLVMTargetMachineRef Target,
|
||||
return LLVMRustResult::Success;
|
||||
}
|
||||
|
||||
extern "C" void
|
||||
LLVMRustPrintModule(LLVMPassManagerRef PMR,
|
||||
LLVMModuleRef M,
|
||||
const char* path) {
|
||||
extern "C" void LLVMRustPrintModule(LLVMPassManagerRef PMR, LLVMModuleRef M,
|
||||
const char *path) {
|
||||
llvm::legacy::PassManager *PM = unwrap<llvm::legacy::PassManager>(PMR);
|
||||
std::string ErrorInfo;
|
||||
|
||||
@ -524,102 +486,96 @@ LLVMRustPrintModule(LLVMPassManagerRef PMR,
|
||||
PM->run(*unwrap(M));
|
||||
}
|
||||
|
||||
extern "C" void
|
||||
LLVMRustPrintPasses() {
|
||||
LLVMInitializePasses();
|
||||
struct MyListener : PassRegistrationListener {
|
||||
void passEnumerate(const PassInfo *info) {
|
||||
extern "C" void LLVMRustPrintPasses() {
|
||||
LLVMInitializePasses();
|
||||
struct MyListener : PassRegistrationListener {
|
||||
void passEnumerate(const PassInfo *info) {
|
||||
#if LLVM_VERSION_GE(4, 0)
|
||||
StringRef PassArg = info->getPassArgument();
|
||||
StringRef PassName = info->getPassName();
|
||||
if (!PassArg.empty()) {
|
||||
// These unsigned->signed casts could theoretically overflow, but
|
||||
// realistically never will (and even if, the result is implementation
|
||||
// defined rather plain UB).
|
||||
printf("%15.*s - %.*s\n", (int)PassArg.size(), PassArg.data(),
|
||||
(int)PassName.size(), PassName.data());
|
||||
}
|
||||
StringRef PassArg = info->getPassArgument();
|
||||
StringRef PassName = info->getPassName();
|
||||
if (!PassArg.empty()) {
|
||||
// These unsigned->signed casts could theoretically overflow, but
|
||||
// realistically never will (and even if, the result is implementation
|
||||
// defined rather plain UB).
|
||||
printf("%15.*s - %.*s\n", (int)PassArg.size(), PassArg.data(),
|
||||
(int)PassName.size(), PassName.data());
|
||||
}
|
||||
#else
|
||||
if (info->getPassArgument() && *info->getPassArgument()) {
|
||||
printf("%15s - %s\n", info->getPassArgument(),
|
||||
info->getPassName());
|
||||
}
|
||||
if (info->getPassArgument() && *info->getPassArgument()) {
|
||||
printf("%15s - %s\n", info->getPassArgument(), info->getPassName());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
} listener;
|
||||
}
|
||||
} listener;
|
||||
|
||||
PassRegistry *PR = PassRegistry::getPassRegistry();
|
||||
PR->enumerateWith(&listener);
|
||||
PassRegistry *PR = PassRegistry::getPassRegistry();
|
||||
PR->enumerateWith(&listener);
|
||||
}
|
||||
|
||||
extern "C" void
|
||||
LLVMRustAddAlwaysInlinePass(LLVMPassManagerBuilderRef PMB, bool AddLifetimes) {
|
||||
extern "C" void LLVMRustAddAlwaysInlinePass(LLVMPassManagerBuilderRef PMB,
|
||||
bool AddLifetimes) {
|
||||
#if LLVM_VERSION_GE(4, 0)
|
||||
unwrap(PMB)->Inliner = llvm::createAlwaysInlinerLegacyPass(AddLifetimes);
|
||||
unwrap(PMB)->Inliner = llvm::createAlwaysInlinerLegacyPass(AddLifetimes);
|
||||
#else
|
||||
unwrap(PMB)->Inliner = createAlwaysInlinerPass(AddLifetimes);
|
||||
unwrap(PMB)->Inliner = createAlwaysInlinerPass(AddLifetimes);
|
||||
#endif
|
||||
}
|
||||
|
||||
extern "C" void
|
||||
LLVMRustRunRestrictionPass(LLVMModuleRef M, char **symbols, size_t len) {
|
||||
llvm::legacy::PassManager passes;
|
||||
extern "C" void LLVMRustRunRestrictionPass(LLVMModuleRef M, char **symbols,
|
||||
size_t len) {
|
||||
llvm::legacy::PassManager passes;
|
||||
|
||||
#if LLVM_VERSION_LE(3, 8)
|
||||
ArrayRef<const char*> ref(symbols, len);
|
||||
passes.add(llvm::createInternalizePass(ref));
|
||||
ArrayRef<const char *> ref(symbols, len);
|
||||
passes.add(llvm::createInternalizePass(ref));
|
||||
#else
|
||||
auto PreserveFunctions = [=](const GlobalValue &GV) {
|
||||
for (size_t i=0; i<len; i++) {
|
||||
if (GV.getName() == symbols[i]) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
auto PreserveFunctions = [=](const GlobalValue &GV) {
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
if (GV.getName() == symbols[i]) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
passes.add(llvm::createInternalizePass(PreserveFunctions));
|
||||
passes.add(llvm::createInternalizePass(PreserveFunctions));
|
||||
#endif
|
||||
|
||||
passes.run(*unwrap(M));
|
||||
passes.run(*unwrap(M));
|
||||
}
|
||||
|
||||
extern "C" void
|
||||
LLVMRustMarkAllFunctionsNounwind(LLVMModuleRef M) {
|
||||
for (Module::iterator GV = unwrap(M)->begin(),
|
||||
E = unwrap(M)->end(); GV != E; ++GV) {
|
||||
GV->setDoesNotThrow();
|
||||
Function *F = dyn_cast<Function>(GV);
|
||||
if (F == NULL)
|
||||
continue;
|
||||
extern "C" void LLVMRustMarkAllFunctionsNounwind(LLVMModuleRef M) {
|
||||
for (Module::iterator GV = unwrap(M)->begin(), E = unwrap(M)->end(); GV != E;
|
||||
++GV) {
|
||||
GV->setDoesNotThrow();
|
||||
Function *F = dyn_cast<Function>(GV);
|
||||
if (F == NULL)
|
||||
continue;
|
||||
|
||||
for (Function::iterator B = F->begin(), BE = F->end(); B != BE; ++B) {
|
||||
for (BasicBlock::iterator I = B->begin(), IE = B->end();
|
||||
I != IE; ++I) {
|
||||
if (isa<InvokeInst>(I)) {
|
||||
InvokeInst *CI = cast<InvokeInst>(I);
|
||||
CI->setDoesNotThrow();
|
||||
}
|
||||
}
|
||||
for (Function::iterator B = F->begin(), BE = F->end(); B != BE; ++B) {
|
||||
for (BasicBlock::iterator I = B->begin(), IE = B->end(); I != IE; ++I) {
|
||||
if (isa<InvokeInst>(I)) {
|
||||
InvokeInst *CI = cast<InvokeInst>(I);
|
||||
CI->setDoesNotThrow();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" void
|
||||
LLVMRustSetDataLayoutFromTargetMachine(LLVMModuleRef Module,
|
||||
LLVMTargetMachineRef TMR) {
|
||||
TargetMachine *Target = unwrap(TMR);
|
||||
unwrap(Module)->setDataLayout(Target->createDataLayout());
|
||||
TargetMachine *Target = unwrap(TMR);
|
||||
unwrap(Module)->setDataLayout(Target->createDataLayout());
|
||||
}
|
||||
|
||||
extern "C" LLVMTargetDataRef
|
||||
LLVMRustGetModuleDataLayout(LLVMModuleRef M) {
|
||||
return wrap(&unwrap(M)->getDataLayout());
|
||||
extern "C" LLVMTargetDataRef LLVMRustGetModuleDataLayout(LLVMModuleRef M) {
|
||||
return wrap(&unwrap(M)->getDataLayout());
|
||||
}
|
||||
|
||||
extern "C" void
|
||||
LLVMRustSetModulePIELevel(LLVMModuleRef M) {
|
||||
extern "C" void LLVMRustSetModulePIELevel(LLVMModuleRef M) {
|
||||
#if LLVM_VERSION_GE(3, 9)
|
||||
unwrap(M)->setPIELevel(PIELevel::Level::Large);
|
||||
unwrap(M)->setPIELevel(PIELevel::Level::Large);
|
||||
#endif
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -8,50 +8,52 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#include "llvm/IR/IRBuilder.h"
|
||||
#include "llvm/IR/InlineAsm.h"
|
||||
#include "llvm/IR/LLVMContext.h"
|
||||
#include "llvm/IR/Module.h"
|
||||
#include "llvm/IR/InlineAsm.h"
|
||||
#include "llvm/IR/LLVMContext.h"
|
||||
#include "llvm/Analysis/Passes.h"
|
||||
#include "llvm/Analysis/Lint.h"
|
||||
#include "llvm/ADT/ArrayRef.h"
|
||||
#include "llvm/ADT/Triple.h"
|
||||
#include "llvm/ADT/DenseSet.h"
|
||||
#include "llvm/Support/CommandLine.h"
|
||||
#include "llvm/Support/FormattedStream.h"
|
||||
#include "llvm/Support/Timer.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
#include "llvm/Support/TargetSelect.h"
|
||||
#include "llvm/Support/TargetRegistry.h"
|
||||
#include "llvm/Support/SourceMgr.h"
|
||||
#include "llvm/Support/Host.h"
|
||||
#include "llvm/Support/Debug.h"
|
||||
#include "llvm/Support/DynamicLibrary.h"
|
||||
#include "llvm/Support/Memory.h"
|
||||
#include "llvm/ExecutionEngine/ExecutionEngine.h"
|
||||
#include "llvm/ExecutionEngine/MCJIT.h"
|
||||
#include "llvm/ExecutionEngine/Interpreter.h"
|
||||
#include "llvm/Target/TargetMachine.h"
|
||||
#include "llvm/Target/TargetOptions.h"
|
||||
#include "llvm/Transforms/Scalar.h"
|
||||
#include "llvm/Transforms/IPO.h"
|
||||
#include "llvm/Transforms/Instrumentation.h"
|
||||
#include "llvm/Transforms/Vectorize.h"
|
||||
#include "llvm-c/Core.h"
|
||||
#include "llvm-c/BitReader.h"
|
||||
#include "llvm-c/Core.h"
|
||||
#include "llvm-c/ExecutionEngine.h"
|
||||
#include "llvm-c/Object.h"
|
||||
#include "llvm/ADT/ArrayRef.h"
|
||||
#include "llvm/ADT/DenseSet.h"
|
||||
#include "llvm/ADT/Triple.h"
|
||||
#include "llvm/Analysis/Lint.h"
|
||||
#include "llvm/Analysis/Passes.h"
|
||||
#include "llvm/ExecutionEngine/ExecutionEngine.h"
|
||||
#include "llvm/ExecutionEngine/Interpreter.h"
|
||||
#include "llvm/ExecutionEngine/MCJIT.h"
|
||||
#include "llvm/IR/IRBuilder.h"
|
||||
#include "llvm/IR/InlineAsm.h"
|
||||
#include "llvm/IR/InlineAsm.h"
|
||||
#include "llvm/IR/LLVMContext.h"
|
||||
#include "llvm/IR/LLVMContext.h"
|
||||
#include "llvm/IR/Module.h"
|
||||
#include "llvm/Support/CommandLine.h"
|
||||
#include "llvm/Support/Debug.h"
|
||||
#include "llvm/Support/DynamicLibrary.h"
|
||||
#include "llvm/Support/FormattedStream.h"
|
||||
#include "llvm/Support/Host.h"
|
||||
#include "llvm/Support/Memory.h"
|
||||
#include "llvm/Support/SourceMgr.h"
|
||||
#include "llvm/Support/TargetRegistry.h"
|
||||
#include "llvm/Support/TargetSelect.h"
|
||||
#include "llvm/Support/Timer.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
#include "llvm/Target/TargetMachine.h"
|
||||
#include "llvm/Target/TargetOptions.h"
|
||||
#include "llvm/Transforms/IPO.h"
|
||||
#include "llvm/Transforms/Instrumentation.h"
|
||||
#include "llvm/Transforms/Scalar.h"
|
||||
#include "llvm/Transforms/Vectorize.h"
|
||||
|
||||
#define LLVM_VERSION_GE(major, minor) \
|
||||
(LLVM_VERSION_MAJOR > (major) || LLVM_VERSION_MAJOR == (major) && LLVM_VERSION_MINOR >= (minor))
|
||||
#define LLVM_VERSION_GE(major, minor) \
|
||||
(LLVM_VERSION_MAJOR > (major) || \
|
||||
LLVM_VERSION_MAJOR == (major) && LLVM_VERSION_MINOR >= (minor))
|
||||
|
||||
#define LLVM_VERSION_EQ(major, minor) \
|
||||
#define LLVM_VERSION_EQ(major, minor) \
|
||||
(LLVM_VERSION_MAJOR == (major) && LLVM_VERSION_MINOR == (minor))
|
||||
|
||||
#define LLVM_VERSION_LE(major, minor) \
|
||||
(LLVM_VERSION_MAJOR < (major) || LLVM_VERSION_MAJOR == (major) && LLVM_VERSION_MINOR <= (minor))
|
||||
#define LLVM_VERSION_LE(major, minor) \
|
||||
(LLVM_VERSION_MAJOR < (major) || \
|
||||
LLVM_VERSION_MAJOR == (major) && LLVM_VERSION_MINOR <= (minor))
|
||||
|
||||
#if LLVM_VERSION_GE(3, 7)
|
||||
#include "llvm/IR/LegacyPassManager.h"
|
||||
@ -66,39 +68,36 @@
|
||||
#include "llvm/Bitcode/ReaderWriter.h"
|
||||
#endif
|
||||
|
||||
#include "llvm/IR/IRPrintingPasses.h"
|
||||
#include "llvm/IR/DebugInfo.h"
|
||||
#include "llvm/IR/DIBuilder.h"
|
||||
#include "llvm/IR/DebugInfo.h"
|
||||
#include "llvm/IR/IRPrintingPasses.h"
|
||||
#include "llvm/Linker/Linker.h"
|
||||
|
||||
void LLVMRustSetLastError(const char*);
|
||||
void LLVMRustSetLastError(const char *);
|
||||
|
||||
enum class LLVMRustResult {
|
||||
Success,
|
||||
Failure
|
||||
};
|
||||
enum class LLVMRustResult { Success, Failure };
|
||||
|
||||
enum LLVMRustAttribute {
|
||||
AlwaysInline = 0,
|
||||
ByVal = 1,
|
||||
Cold = 2,
|
||||
InlineHint = 3,
|
||||
MinSize = 4,
|
||||
Naked = 5,
|
||||
NoAlias = 6,
|
||||
NoCapture = 7,
|
||||
NoInline = 8,
|
||||
NonNull = 9,
|
||||
NoRedZone = 10,
|
||||
NoReturn = 11,
|
||||
NoUnwind = 12,
|
||||
OptimizeForSize = 13,
|
||||
ReadOnly = 14,
|
||||
SExt = 15,
|
||||
StructRet = 16,
|
||||
UWTable = 17,
|
||||
ZExt = 18,
|
||||
InReg = 19,
|
||||
AlwaysInline = 0,
|
||||
ByVal = 1,
|
||||
Cold = 2,
|
||||
InlineHint = 3,
|
||||
MinSize = 4,
|
||||
Naked = 5,
|
||||
NoAlias = 6,
|
||||
NoCapture = 7,
|
||||
NoInline = 8,
|
||||
NonNull = 9,
|
||||
NoRedZone = 10,
|
||||
NoReturn = 11,
|
||||
NoUnwind = 12,
|
||||
OptimizeForSize = 13,
|
||||
ReadOnly = 14,
|
||||
SExt = 15,
|
||||
StructRet = 16,
|
||||
UWTable = 17,
|
||||
ZExt = 18,
|
||||
InReg = 19,
|
||||
};
|
||||
|
||||
typedef struct OpaqueRustString *RustStringRef;
|
||||
@ -107,28 +106,25 @@ typedef struct LLVMOpaqueDebugLoc *LLVMDebugLocRef;
|
||||
typedef struct LLVMOpaqueSMDiagnostic *LLVMSMDiagnosticRef;
|
||||
typedef struct LLVMOpaqueRustJITMemoryManager *LLVMRustJITMemoryManagerRef;
|
||||
|
||||
extern "C" void
|
||||
rust_llvm_string_write_impl(RustStringRef str, const char *ptr, size_t size);
|
||||
extern "C" void rust_llvm_string_write_impl(RustStringRef str, const char *ptr,
|
||||
size_t size);
|
||||
|
||||
class raw_rust_string_ostream : public llvm::raw_ostream {
|
||||
RustStringRef str;
|
||||
uint64_t pos;
|
||||
class raw_rust_string_ostream : public llvm::raw_ostream {
|
||||
RustStringRef str;
|
||||
uint64_t pos;
|
||||
|
||||
void write_impl(const char *ptr, size_t size) override {
|
||||
rust_llvm_string_write_impl(str, ptr, size);
|
||||
pos += size;
|
||||
}
|
||||
void write_impl(const char *ptr, size_t size) override {
|
||||
rust_llvm_string_write_impl(str, ptr, size);
|
||||
pos += size;
|
||||
}
|
||||
|
||||
uint64_t current_pos() const override {
|
||||
return pos;
|
||||
}
|
||||
uint64_t current_pos() const override { return pos; }
|
||||
|
||||
public:
|
||||
explicit raw_rust_string_ostream(RustStringRef str)
|
||||
: str(str), pos(0) { }
|
||||
explicit raw_rust_string_ostream(RustStringRef str) : str(str), pos(0) {}
|
||||
|
||||
~raw_rust_string_ostream() {
|
||||
// LLVM requires this.
|
||||
flush();
|
||||
}
|
||||
~raw_rust_string_ostream() {
|
||||
// LLVM requires this.
|
||||
flush();
|
||||
}
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user