Merge pull request #418 from mmp/master

Fix build with LLVM top-of-tree, fix warnings, remove LLVM 3.0 support
This commit is contained in:
jbrodman
2013-01-08 10:28:02 -08:00
17 changed files with 358 additions and 369 deletions

View File

@@ -64,12 +64,21 @@
#define strcasecmp stricmp
#endif
#include <llvm/LLVMContext.h>
#include <llvm/Module.h>
#include <llvm/Type.h>
#include <llvm/DerivedTypes.h>
#include <llvm/Instructions.h>
#include <llvm/Intrinsics.h>
#if defined(LLVM_3_1) || defined(LLVM_3_2)
#include <llvm/LLVMContext.h>
#include <llvm/Module.h>
#include <llvm/Type.h>
#include <llvm/Instructions.h>
#include <llvm/Intrinsics.h>
#include <llvm/DerivedTypes.h>
#else
#include <llvm/IR/LLVMContext.h>
#include <llvm/IR/Module.h>
#include <llvm/IR/Type.h>
#include <llvm/IR/Instructions.h>
#include <llvm/IR/Intrinsics.h>
#include <llvm/IR/DerivedTypes.h>
#endif
#include <llvm/PassManager.h>
#include <llvm/PassRegistry.h>
#include <llvm/Transforms/IPO.h>
@@ -77,10 +86,14 @@
#include <llvm/Support/FileUtilities.h>
#include <llvm/Target/TargetMachine.h>
#include <llvm/Target/TargetOptions.h>
#if defined(LLVM_3_0) || defined(LLVM_3_1)
#if defined(LLVM_3_1)
#include <llvm/Target/TargetData.h>
#else
#include <llvm/DataLayout.h>
#if defined(LLVM_3_2)
#include <llvm/DataLayout.h>
#else // LLVM 3.3+
#include <llvm/IR/DataLayout.h>
#endif
#include <llvm/TargetTransformInfo.h>
#endif
#include <llvm/Analysis/Verifier.h>
@@ -136,7 +149,6 @@ lStripUnusedDebugInfo(llvm::Module *module) {
if (g->generateDebuggingSymbols == false)
return;
#ifndef LLVM_3_0
// loop over the compile units that contributed to the final module
if (llvm::NamedMDNode *cuNodes = module->getNamedMetadata("llvm.dbg.cu")) {
for (unsigned i = 0, ie = cuNodes->getNumOperands(); i != ie; ++i) {
@@ -215,7 +227,6 @@ lStripUnusedDebugInfo(llvm::Module *module) {
}
for (int i = 0; i < (int)toErase.size(); ++i)
module->eraseNamedMetadata(toErase[i]);
#endif // !LLVM_3_0
// Wrap up by running the LLVM pass to remove anything left that's
// unused.
@@ -760,14 +771,14 @@ Module::AddFunctionDeclaration(const std::string &name,
if (storageClass != SC_EXTERN_C &&
!g->generateDebuggingSymbols &&
isInline)
#if defined(LLVM_3_0) || defined(LLVM_3_1)
function->addFnAttr(llvm::Attribute::AlwaysInline);
#else
#ifdef LLVM_3_2
function->addFnAttr(llvm::Attributes::AlwaysInline);
#else
function->addFnAttr(llvm::Attribute::AlwaysInline);
#endif
if (functionType->isTask)
// This also applies transitively to members I think?
#if defined(LLVM_3_0) || defined(LLVM_3_1)
#if defined(LLVM_3_1)
function->setDoesNotAlias(1, true);
#else
function->setDoesNotAlias(1);
@@ -818,7 +829,7 @@ Module::AddFunctionDeclaration(const std::string &name,
// NOTE: LLVM indexes function parameters starting from 1.
// This is unintuitive.
#if defined(LLVM_3_0) || defined(LLVM_3_1)
#if defined(LLVM_3_1)
function->setDoesNotAlias(i+1, true);
#else
function->setDoesNotAlias(i+1);
@@ -1045,7 +1056,7 @@ Module::writeObjectFileOrAssembly(llvm::TargetMachine *targetMachine,
}
llvm::PassManager pm;
#if defined(LLVM_3_0) || defined(LLVM_3_1)
#if defined(LLVM_3_1)
if (const llvm::TargetData *td = targetMachine->getTargetData())
pm.add(new llvm::TargetData(*td));
else
@@ -1059,13 +1070,7 @@ Module::writeObjectFileOrAssembly(llvm::TargetMachine *targetMachine,
llvm::formatted_raw_ostream fos(of->os());
#ifdef LLVM_3_0
llvm::CodeGenOpt::Level optLevel =
(g->opt.level > 0) ? llvm::CodeGenOpt::Aggressive : llvm::CodeGenOpt::None;
if (targetMachine->addPassesToEmitFile(pm, fos, fileType, optLevel)) {
#else
if (targetMachine->addPassesToEmitFile(pm, fos, fileType)) {
#endif
fprintf(stderr, "Fatal error adding passes to emit object file!");
exit(1);
}
@@ -1775,7 +1780,7 @@ Module::execPreprocessor(const char *infilename, llvm::raw_string_ostream *ostre
llvm::raw_fd_ostream stderrRaw(2, false);
#if defined(LLVM_3_0) || defined(LLVM_3_1)
#if defined(LLVM_3_1)
clang::TextDiagnosticPrinter *diagPrinter =
new clang::TextDiagnosticPrinter(stderrRaw, clang::DiagnosticOptions());
#else
@@ -1784,7 +1789,7 @@ Module::execPreprocessor(const char *infilename, llvm::raw_string_ostream *ostre
new clang::TextDiagnosticPrinter(stderrRaw, diagOptions);
#endif
llvm::IntrusiveRefCntPtr<clang::DiagnosticIDs> diagIDs(new clang::DiagnosticIDs);
#if defined(LLVM_3_0) || defined(LLVM_3_1)
#if defined(LLVM_3_1)
clang::DiagnosticsEngine *diagEngine =
new clang::DiagnosticsEngine(diagIDs, diagPrinter);
#else
@@ -1796,20 +1801,21 @@ Module::execPreprocessor(const char *infilename, llvm::raw_string_ostream *ostre
clang::TargetOptions &options = inst.getTargetOpts();
llvm::Triple triple(module->getTargetTriple());
if (triple.getTriple().empty()) {
#ifdef LLVM_3_0
triple.setTriple(llvm::sys::getHostTriple());
#else
triple.setTriple(llvm::sys::getDefaultTargetTriple());
#endif
}
options.Triple = triple.getTriple();
#if defined(LLVM_3_1) || defined(LLVM_3_2)
clang::TargetInfo *target =
clang::TargetInfo::CreateTargetInfo(inst.getDiagnostics(), options);
#else // LLVM 3.3+
clang::TargetInfo *target =
clang::TargetInfo::CreateTargetInfo(inst.getDiagnostics(), &options);
#endif
inst.setTarget(target);
inst.createSourceManager(inst.getFileManager());
#if defined(LLVM_3_0) || defined(LLVM_3_1)
#if defined(LLVM_3_1)
inst.InitializeSourceManager(infilename);
#else
clang::FrontendInputFile inputFile(infilename, clang::IK_None);