Auto merge of #38701 - karpinski:rustllvm-style, r=brson

Making code style consistent for src/rustllvm (#38688)

Part of #38688

r? @brson
This commit is contained in:
bors 2016-12-30 22:43:44 +00:00
commit 6dcf51aae6
4 changed files with 1326 additions and 1592 deletions

View file

@ -21,17 +21,18 @@ struct RustArchiveMember {
const char *name;
Archive::Child child;
RustArchiveMember(): filename(NULL), name(NULL),
RustArchiveMember()
: filename(nullptr), name(nullptr),
#if LLVM_VERSION_GE(3, 8)
child(NULL, NULL, NULL)
child(nullptr, nullptr, nullptr)
#else
child(NULL, NULL)
child(nullptr, nullptr)
#endif
{}
{
}
~RustArchiveMember() {}
};
struct RustArchiveIterator {
bool first;
Archive::child_iterator cur;
@ -39,9 +40,9 @@ struct RustArchiveIterator {
#if LLVM_VERSION_GE(3, 9)
Error err;
RustArchiveIterator() : first(true), err(Error::success()) { }
RustArchiveIterator() : first(true), err(Error::success()) {}
#else
RustArchiveIterator() : first(true) { }
RustArchiveIterator() : first(true) {}
#endif
};
@ -53,9 +54,7 @@ enum class LLVMRustArchiveKind {
COFF,
};
static Archive::Kind
from_rust(LLVMRustArchiveKind kind)
{
static Archive::Kind from_rust(LLVMRustArchiveKind kind) {
switch (kind) {
case LLVMRustArchiveKind::GNU:
return Archive::K_GNU;
@ -76,11 +75,9 @@ 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);
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;
@ -108,10 +105,7 @@ LLVMRustOpenArchive(char *path) {
return ret;
}
extern "C" void
LLVMRustDestroyArchive(LLVMRustArchiveRef ar) {
delete ar;
}
extern "C" void LLVMRustDestroyArchive(LLVMRustArchiveRef ar) { delete ar; }
extern "C" LLVMRustArchiveIteratorRef
LLVMRustArchiveIteratorNew(LLVMRustArchiveRef ra) {
@ -124,7 +118,7 @@ LLVMRustArchiveIteratorNew(LLVMRustArchiveRef ra) {
if (rai->err) {
LLVMRustSetLastError(toString(std::move(rai->err)).c_str());
delete rai;
return NULL;
return nullptr;
}
#endif
rai->end = ar->child_end();
@ -133,7 +127,8 @@ LLVMRustArchiveIteratorNew(LLVMRustArchiveRef ra) {
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,
@ -153,10 +148,11 @@ LLVMRustArchiveIteratorNext(LLVMRustArchiveIteratorRef rai) {
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->();
const ErrorOr<Archive::Child> *cur = rai->cur.operator->();
if (!*cur) {
LLVMRustSetLastError(cur->getError().message().c_str());
return nullptr;
@ -170,17 +166,15 @@ LLVMRustArchiveIteratorNext(LLVMRustArchiveIteratorRef rai) {
return ret;
}
extern "C" void
LLVMRustArchiveChildFree(LLVMRustArchiveChildRef child) {
extern "C" void LLVMRustArchiveChildFree(LLVMRustArchiveChildRef child) {
delete child;
}
extern "C" void
LLVMRustArchiveIteratorFree(LLVMRustArchiveIteratorRef 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();
@ -189,32 +183,32 @@ LLVMRustArchiveChildName(LLVMRustArchiveChildConstRef child, size_t *size) {
// 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;
return nullptr;
}
#else
ErrorOr<StringRef> name_or_err = child->getName();
if (name_or_err.getError())
return NULL;
return nullptr;
#endif
StringRef name = name_or_err.get();
*size = name.size();
return name.data();
}
extern "C" const char*
LLVMRustArchiveChildData(LLVMRustArchiveChildRef child, size_t *size) {
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;
return nullptr;
}
#else
ErrorOr<StringRef> buf_or_err = child->getBuffer();
if (buf_or_err.getError()) {
LLVMRustSetLastError(buf_or_err.getError().message().c_str());
return NULL;
return nullptr;
}
#endif
buf = buf_or_err.get();
@ -233,17 +227,14 @@ LLVMRustArchiveMemberNew(char *Filename, char *Name,
return Member;
}
extern "C" void
LLVMRustArchiveMemberFree(LLVMRustArchiveMemberRef 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;

View file

@ -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,9 +64,7 @@ enum class LLVMRustPassKind {
Module,
};
static LLVMRustPassKind
to_rust(PassKind kind)
{
static LLVMRustPassKind to_rust(PassKind kind) {
switch (kind) {
case PT_Function:
return LLVMRustPassKind::Function;
@ -77,8 +75,7 @@ to_rust(PassKind kind)
}
}
extern "C" LLVMPassRef
LLVMRustFindAndCreatePass(const char *PassName) {
extern "C" LLVMPassRef LLVMRustFindAndCreatePass(const char *PassName) {
StringRef SR(PassName);
PassRegistry *PR = PassRegistry::getPassRegistry();
@ -86,18 +83,16 @@ LLVMRustFindAndCreatePass(const char *PassName) {
if (PI) {
return wrap(PI->createPass());
}
return NULL;
return nullptr;
}
extern "C" LLVMRustPassKind
LLVMRustPassKind(LLVMPassRef rust_pass) {
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) {
extern "C" void LLVMRustAddPass(LLVMPassManagerRef PM, LLVMPassRef rust_pass) {
assert(rust_pass);
Pass *pass = unwrap(rust_pass);
PassManagerBase *pm = unwrap(PM);
@ -155,7 +150,8 @@ LLVMRustAddPass(LLVMPassManagerRef PM, LLVMPassRef rust_pass) {
SUBTARGET_SYSTEMZ \
SUBTARGET_MSP430
#define SUBTARGET(x) namespace llvm { \
#define SUBTARGET(x) \
namespace llvm { \
extern const SubtargetFeatureKV x##FeatureKV[]; \
extern const SubtargetFeatureKV x##SubTypeKV[]; \
}
@ -163,8 +159,7 @@ LLVMRustAddPass(LLVMPassManagerRef PM, LLVMPassRef rust_pass) {
GEN_SUBTARGETS
#undef SUBTARGET
extern "C" bool
LLVMRustHasFeature(LLVMTargetMachineRef TM,
extern "C" bool LLVMRustHasFeature(LLVMTargetMachineRef TM,
const char *feature) {
TargetMachine *Target = unwrap(TM);
const MCSubtargetInfo *MCInfo = Target->getMCSubtargetInfo();
@ -176,9 +171,7 @@ LLVMRustHasFeature(LLVMTargetMachineRef TM,
FeatureEntry = x##FeatureKV; \
} else
GEN_SUBTARGETS {
return false;
}
GEN_SUBTARGETS { return false; }
#undef SUBTARGET
while (strcmp(feature, FeatureEntry->Key) != 0)
@ -197,9 +190,7 @@ enum class LLVMRustCodeModel {
Large,
};
static CodeModel::Model
from_rust(LLVMRustCodeModel model)
{
static CodeModel::Model from_rust(LLVMRustCodeModel model) {
switch (model) {
case LLVMRustCodeModel::Default:
return CodeModel::Default;
@ -226,9 +217,7 @@ enum class LLVMRustCodeGenOptLevel {
Aggressive,
};
static CodeGenOpt::Level
from_rust(LLVMRustCodeGenOptLevel level)
{
static CodeGenOpt::Level from_rust(LLVMRustCodeGenOptLevel level) {
switch (level) {
case LLVMRustCodeGenOptLevel::None:
return CodeGenOpt::None;
@ -253,8 +242,7 @@ static size_t getLongestEntryLength(ArrayRef<SubtargetFeatureKV> Table) {
return MaxLen;
}
extern "C" void
LLVMRustPrintTargetCPUs(LLVMTargetMachineRef TM) {
extern "C" void LLVMRustPrintTargetCPUs(LLVMTargetMachineRef TM) {
const TargetMachine *Target = unwrap(TM);
const MCSubtargetInfo *MCInfo = Target->getMCSubtargetInfo();
const ArrayRef<SubtargetFeatureKV> CPUTable = MCInfo->getCPUTable();
@ -266,8 +254,7 @@ LLVMRustPrintTargetCPUs(LLVMTargetMachineRef TM) {
printf("\n");
}
extern "C" void
LLVMRustPrintTargetFeatures(LLVMTargetMachineRef TM) {
extern "C" void LLVMRustPrintTargetFeatures(LLVMTargetMachineRef TM) {
const TargetMachine *Target = unwrap(TM);
const MCSubtargetInfo *MCInfo = Target->getMCSubtargetInfo();
const ArrayRef<SubtargetFeatureKV> FeatTable = MCInfo->getFeatureTable();
@ -279,32 +266,26 @@ LLVMRustPrintTargetFeatures(LLVMTargetMachineRef TM) {
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");
"For example, rustc -C -target-cpu=mycpu -C "
"target-feature=+feature1,-feature2\n\n");
}
#else
extern "C" void
LLVMRustPrintTargetCPUs(LLVMTargetMachineRef) {
extern "C" void LLVMRustPrintTargetCPUs(LLVMTargetMachineRef) {
printf("Target CPU help is not supported by this LLVM version.\n\n");
}
extern "C" void
LLVMRustPrintTargetFeatures(LLVMTargetMachineRef) {
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,
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)
@ -315,7 +296,7 @@ LLVMRustCreateTargetMachine(const char *triple,
auto CM = from_rust(rust_CM);
auto OptLevel = from_rust(rust_OptLevel);
switch (Reloc){
switch (Reloc) {
case LLVMRelocStatic:
RM = Reloc::Static;
break;
@ -334,11 +315,11 @@ LLVMRustCreateTargetMachine(const char *triple,
std::string Error;
Triple Trip(Triple::normalize(triple));
const llvm::Target *TheTarget = TargetRegistry::lookupTarget(Trip.getTriple(),
Error);
if (TheTarget == NULL) {
const llvm::Target *TheTarget =
TargetRegistry::lookupTarget(Trip.getTriple(), Error);
if (TheTarget == nullptr) {
LLVMRustSetLastError(Error.c_str());
return NULL;
return nullptr;
}
StringRef real_cpu = cpu;
@ -358,41 +339,31 @@ LLVMRustCreateTargetMachine(const char *triple,
Options.DataSections = DataSections;
Options.FunctionSections = FunctionSections;
TargetMachine *TM = TheTarget->createTargetMachine(Trip.getTriple(),
real_cpu,
feature,
Options,
RM,
CM,
OptLevel);
TargetMachine *TM = TheTarget->createTargetMachine(
Trip.getTriple(), real_cpu, feature, Options, RM, CM, OptLevel);
return wrap(TM);
}
extern "C" void
LLVMRustDisposeTargetMachine(LLVMTargetMachineRef 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,
extern "C" void LLVMRustAddAnalysisPasses(LLVMTargetMachineRef TM,
LLVMPassManagerRef PMR,
LLVMModuleRef M) {
PassManagerBase *PM = unwrap(PMR);
PM->add(createTargetTransformInfoWrapperPass(
unwrap(TM)->getTargetIRAnalysis()));
PM->add(
createTargetTransformInfoWrapperPass(unwrap(TM)->getTargetIRAnalysis()));
}
extern "C" void
LLVMRustConfigurePassManagerBuilder(LLVMPassManagerBuilderRef PMB,
LLVMRustCodeGenOptLevel OptLevel,
bool MergeFunctions,
bool SLPVectorize,
bool 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)->MergeFunctions = MergeFunctions;
unwrap(PMB)->SLPVectorize = SLPVectorize;
unwrap(PMB)->OptLevel = from_rust(OptLevel);
unwrap(PMB)->LoopVectorize = LoopVectorize;
@ -400,8 +371,7 @@ LLVMRustConfigurePassManagerBuilder(LLVMPassManagerBuilderRef PMB,
// 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,
extern "C" void LLVMRustAddBuilderLibraryInfo(LLVMPassManagerBuilderRef PMB,
LLVMModuleRef M,
bool DisableSimplifyLibCalls) {
Triple TargetTriple(unwrap(M)->getTargetTriple());
@ -413,9 +383,7 @@ LLVMRustAddBuilderLibraryInfo(LLVMPassManagerBuilderRef PMB,
// 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,
extern "C" void LLVMRustAddLibraryInfo(LLVMPassManagerRef PMB, LLVMModuleRef M,
bool DisableSimplifyLibCalls) {
Triple TargetTriple(unwrap(M)->getTargetTriple());
TargetLibraryInfoImpl TLII(TargetTriple);
@ -427,32 +395,32 @@ LLVMRustAddLibraryInfo(LLVMPassManagerRef PMB,
// 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);
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;)
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)
for (Module::iterator I = unwrap(M)->begin(), E = unwrap(M)->end(); I != E;
++I)
if (!I->isDeclaration())
P->run(*I);
P->doFinalization();
}
extern "C" void
LLVMRustSetLLVMOptions(int Argc, char **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;
if (initialized)
return;
initialized = true;
cl::ParseCommandLineOptions(Argc, Argv);
}
@ -463,9 +431,7 @@ enum class LLVMRustFileType {
ObjectFile,
};
static TargetMachine::CodeGenFileType
from_rust(LLVMRustFileType type)
{
static TargetMachine::CodeGenFileType from_rust(LLVMRustFileType type) {
switch (type) {
case LLVMRustFileType::AssemblyFile:
return TargetMachine::CGFT_AssemblyFile;
@ -477,10 +443,8 @@ from_rust(LLVMRustFileType type)
}
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,8 +486,7 @@ LLVMRustPrintModule(LLVMPassManagerRef PMR,
PM->run(*unwrap(M));
}
extern "C" void
LLVMRustPrintPasses() {
extern "C" void LLVMRustPrintPasses() {
LLVMInitializePasses();
struct MyListener : PassRegistrationListener {
void passEnumerate(const PassInfo *info) {
@ -541,8 +502,7 @@ LLVMRustPrintPasses() {
}
#else
if (info->getPassArgument() && *info->getPassArgument()) {
printf("%15s - %s\n", info->getPassArgument(),
info->getPassName());
printf("%15s - %s\n", info->getPassArgument(), info->getPassName());
}
#endif
}
@ -552,8 +512,8 @@ LLVMRustPrintPasses() {
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);
#else
@ -561,16 +521,16 @@ LLVMRustAddAlwaysInlinePass(LLVMPassManagerBuilderRef PMB, bool AddLifetimes) {
#endif
}
extern "C" void
LLVMRustRunRestrictionPass(LLVMModuleRef M, char **symbols, size_t len) {
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);
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++) {
for (size_t i = 0; i < len; i++) {
if (GV.getName() == symbols[i]) {
return true;
}
@ -584,18 +544,16 @@ LLVMRustRunRestrictionPass(LLVMModuleRef M, char **symbols, size_t len) {
passes.run(*unwrap(M));
}
extern "C" void
LLVMRustMarkAllFunctionsNounwind(LLVMModuleRef M) {
for (Module::iterator GV = unwrap(M)->begin(),
E = unwrap(M)->end(); GV != E; ++GV) {
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)
if (F == nullptr)
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) {
for (BasicBlock::iterator I = B->begin(), IE = B->end(); I != IE; ++I) {
if (isa<InvokeInst>(I)) {
InvokeInst *CI = cast<InvokeInst>(I);
CI->setDoesNotThrow();
@ -612,13 +570,11 @@ LLVMRustSetDataLayoutFromTargetMachine(LLVMModuleRef Module,
unwrap(Module)->setDataLayout(Target->createDataLayout());
}
extern "C" LLVMTargetDataRef
LLVMRustGetModuleDataLayout(LLVMModuleRef M) {
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);
#endif

File diff suppressed because it is too large Load diff

View file

@ -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))
(LLVM_VERSION_MAJOR > (major) || \
LLVM_VERSION_MAJOR == (major) && LLVM_VERSION_MINOR >= (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))
(LLVM_VERSION_MAJOR < (major) || \
LLVM_VERSION_MAJOR == (major) && LLVM_VERSION_MINOR <= (minor))
#if LLVM_VERSION_GE(3, 7)
#include "llvm/IR/LegacyPassManager.h"
@ -66,17 +68,14 @@
#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,
@ -107,8 +106,8 @@ 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;
@ -119,13 +118,10 @@ class raw_rust_string_ostream : public llvm::raw_ostream {
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.