merged with master
This commit is contained in:
68
module.cpp
68
module.cpp
@@ -67,7 +67,7 @@
|
||||
#define strcasecmp stricmp
|
||||
#endif
|
||||
|
||||
#if defined(LLVM_3_1) || defined(LLVM_3_2)
|
||||
#if defined(LLVM_3_2)
|
||||
#include <llvm/LLVMContext.h>
|
||||
#include <llvm/Module.h>
|
||||
#include <llvm/Type.h>
|
||||
@@ -102,7 +102,7 @@
|
||||
#include <llvm/IR/DataLayout.h>
|
||||
#include <llvm/Analysis/TargetTransformInfo.h>
|
||||
#endif
|
||||
#if defined(LLVM_3_5)
|
||||
#if !defined(LLVM_3_2) && !defined(LLVM_3_3) && !defined(LLVM_3_4) // LLVM 3.5+
|
||||
#include <llvm/IR/Verifier.h>
|
||||
#include <llvm/IR/IRPrintingPasses.h>
|
||||
#include <llvm/IR/CFG.h>
|
||||
@@ -215,7 +215,7 @@ lStripUnusedDebugInfo(llvm::Module *module) {
|
||||
// stuff and remove it later on. Removing it is useful, as it
|
||||
// reduces size of the binary significantly (manyfold for small
|
||||
// programs).
|
||||
#if defined(LLVM_3_1) || defined(LLVM_3_2)
|
||||
#if defined(LLVM_3_2)
|
||||
llvm::MDNode *nodeSPMD =
|
||||
llvm::dyn_cast<llvm::MDNode>(cuNode->getOperand(12));
|
||||
Assert(nodeSPMD != NULL);
|
||||
@@ -320,7 +320,7 @@ Module::Module(const char *fn) {
|
||||
sprintf(producerString, "ispc version %s (built on %s)",
|
||||
ISPC_VERSION, __DATE__);
|
||||
#endif
|
||||
#if !defined(LLVM_3_1) && !defined(LLVM_3_2) && !defined(LLVM_3_3)
|
||||
#if !defined(LLVM_3_2) && !defined(LLVM_3_3)
|
||||
diCompileUnit =
|
||||
#endif // LLVM_3_4+
|
||||
diBuilder->createCompileUnit(llvm::dwarf::DW_LANG_C99, /* lang */
|
||||
@@ -854,7 +854,7 @@ Module::AddFunctionDeclaration(const std::string &name,
|
||||
isInline)
|
||||
#ifdef LLVM_3_2
|
||||
function->addFnAttr(llvm::Attributes::AlwaysInline);
|
||||
#else // LLVM 3.1 and 3.3+
|
||||
#else // LLVM 3.3+
|
||||
function->addFnAttr(llvm::Attribute::AlwaysInline);
|
||||
#endif
|
||||
|
||||
@@ -864,11 +864,7 @@ Module::AddFunctionDeclaration(const std::string &name,
|
||||
if (g->target->getISA() != Target::NVPTX)
|
||||
#endif /* ISPC_NVPTX_ENABLED */
|
||||
// This also applies transitively to members I think?
|
||||
#if defined(LLVM_3_1)
|
||||
function->setDoesNotAlias(1, true);
|
||||
#else // LLVM 3.2+
|
||||
function->setDoesNotAlias(1);
|
||||
#endif
|
||||
|
||||
g->target->markFuncWithTargetAttr(function);
|
||||
|
||||
@@ -934,12 +930,7 @@ Module::AddFunctionDeclaration(const std::string &name,
|
||||
|
||||
// NOTE: LLVM indexes function parameters starting from 1.
|
||||
// This is unintuitive.
|
||||
#if defined(LLVM_3_1)
|
||||
function->setDoesNotAlias(i+1, true);
|
||||
#else
|
||||
function->setDoesNotAlias(i+1);
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
int align = 4 * RoundUpPow2(g->target->nativeVectorWidth);
|
||||
function->addAttribute(i+1, llvm::Attribute::constructAlignmentFromInt(align));
|
||||
@@ -1026,7 +1017,7 @@ Module::writeOutput(OutputType outputType, const char *outFileName,
|
||||
lStripUnusedDebugInfo(module);
|
||||
}
|
||||
|
||||
#if defined (LLVM_3_4) || defined (LLVM_3_5)
|
||||
#if !defined(LLVM_3_2) && !defined(LLVM_3_3) // LLVM 3.4+
|
||||
// In LLVM_3_4 after r195494 and r195504 revisions we should pass
|
||||
// "Debug Info Version" constant to the module. LLVM will ignore
|
||||
// our Debug Info metadata without it.
|
||||
@@ -1285,7 +1276,7 @@ Module::writeObjectFileOrAssembly(llvm::TargetMachine *targetMachine,
|
||||
llvm::TargetMachine::CodeGenFileType fileType = (outputType == Object) ?
|
||||
llvm::TargetMachine::CGFT_ObjectFile : llvm::TargetMachine::CGFT_AssemblyFile;
|
||||
bool binary = (fileType == llvm::TargetMachine::CGFT_ObjectFile);
|
||||
#if defined(LLVM_3_1) || defined(LLVM_3_2) || defined(LLVM_3_3)
|
||||
#if defined(LLVM_3_2) || defined(LLVM_3_3)
|
||||
unsigned int flags = binary ? llvm::raw_fd_ostream::F_Binary : 0;
|
||||
#elif defined(LLVM_3_4)
|
||||
llvm::sys::fs::OpenFlags flags = binary ? llvm::sys::fs::F_Binary :
|
||||
@@ -1304,7 +1295,7 @@ Module::writeObjectFileOrAssembly(llvm::TargetMachine *targetMachine,
|
||||
}
|
||||
|
||||
llvm::PassManager pm;
|
||||
#if defined(LLVM_3_5)
|
||||
#if !defined(LLVM_3_2) && !defined(LLVM_3_3) && !defined(LLVM_3_4) // LLVM 3.5+
|
||||
pm.add(new llvm::DataLayoutPass(*g->target->getDataLayout()));
|
||||
#else
|
||||
pm.add(new llvm::DataLayout(*g->target->getDataLayout()));
|
||||
@@ -2185,53 +2176,55 @@ Module::execPreprocessor(const char *infilename, llvm::raw_string_ostream *ostre
|
||||
|
||||
llvm::raw_fd_ostream stderrRaw(2, false);
|
||||
|
||||
#if defined(LLVM_3_1)
|
||||
clang::TextDiagnosticPrinter *diagPrinter =
|
||||
new clang::TextDiagnosticPrinter(stderrRaw, clang::DiagnosticOptions());
|
||||
#else
|
||||
clang::DiagnosticOptions *diagOptions = new clang::DiagnosticOptions();
|
||||
clang::TextDiagnosticPrinter *diagPrinter =
|
||||
new clang::TextDiagnosticPrinter(stderrRaw, diagOptions);
|
||||
#endif
|
||||
|
||||
llvm::IntrusiveRefCntPtr<clang::DiagnosticIDs> diagIDs(new clang::DiagnosticIDs);
|
||||
#if defined(LLVM_3_1)
|
||||
clang::DiagnosticsEngine *diagEngine =
|
||||
new clang::DiagnosticsEngine(diagIDs, diagPrinter);
|
||||
#else
|
||||
clang::DiagnosticsEngine *diagEngine =
|
||||
new clang::DiagnosticsEngine(diagIDs, diagOptions, diagPrinter);
|
||||
#endif
|
||||
|
||||
inst.setDiagnostics(diagEngine);
|
||||
|
||||
#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4)
|
||||
clang::TargetOptions &options = inst.getTargetOpts();
|
||||
#else // LLVM 3.5+
|
||||
const std::shared_ptr< clang::TargetOptions > &options =
|
||||
std::make_shared< clang::TargetOptions >(inst.getTargetOpts());
|
||||
#endif
|
||||
|
||||
llvm::Triple triple(module->getTargetTriple());
|
||||
if (triple.getTriple().empty()) {
|
||||
triple.setTriple(llvm::sys::getDefaultTargetTriple());
|
||||
}
|
||||
options.Triple = triple.getTriple();
|
||||
|
||||
#if defined(LLVM_3_1) || defined(LLVM_3_2)
|
||||
#if defined(LLVM_3_2) || defined(LLVM_3_3) || defined(LLVM_3_4)
|
||||
options.Triple = triple.getTriple();
|
||||
#else // LLVM 3.5+
|
||||
options->Triple = triple.getTriple();
|
||||
#endif
|
||||
|
||||
#if defined(LLVM_3_2)
|
||||
clang::TargetInfo *target =
|
||||
clang::TargetInfo::CreateTargetInfo(inst.getDiagnostics(), options);
|
||||
#else // LLVM 3.3+
|
||||
#elif defined(LLVM_3_3) || defined(LLVM_3_4)
|
||||
clang::TargetInfo *target =
|
||||
clang::TargetInfo::CreateTargetInfo(inst.getDiagnostics(), &options);
|
||||
#else // LLVM 3.5+
|
||||
clang::TargetInfo *target =
|
||||
clang::TargetInfo::CreateTargetInfo(inst.getDiagnostics(), options);
|
||||
#endif
|
||||
|
||||
inst.setTarget(target);
|
||||
inst.createSourceManager(inst.getFileManager());
|
||||
#if defined(LLVM_3_1)
|
||||
inst.InitializeSourceManager(infilename);
|
||||
#else
|
||||
clang::FrontendInputFile inputFile(infilename, clang::IK_None);
|
||||
inst.InitializeSourceManager(inputFile);
|
||||
#endif
|
||||
|
||||
// Don't remove comments in the preprocessor, so that we can accurately
|
||||
// track the source file position by handling them ourselves.
|
||||
inst.getPreprocessorOutputOpts().ShowComments = 1;
|
||||
|
||||
#if !defined(LLVM_3_1) && !defined(LLVM_3_2) // LLVM 3.3+
|
||||
#if !defined(LLVM_3_2) // LLVM 3.3+
|
||||
inst.getPreprocessorOutputOpts().ShowCPP = 1;
|
||||
#endif
|
||||
|
||||
@@ -2243,7 +2236,7 @@ Module::execPreprocessor(const char *infilename, llvm::raw_string_ostream *ostre
|
||||
headerOpts.Verbose = 1;
|
||||
for (int i = 0; i < (int)g->includePath.size(); ++i) {
|
||||
headerOpts.AddPath(g->includePath[i], clang::frontend::Angled,
|
||||
#if defined(LLVM_3_1) || defined(LLVM_3_2)
|
||||
#if defined(LLVM_3_2)
|
||||
true /* is user supplied */,
|
||||
#endif
|
||||
false /* not a framework */,
|
||||
@@ -2321,7 +2314,8 @@ Module::execPreprocessor(const char *infilename, llvm::raw_string_ostream *ostre
|
||||
#endif /* ISPC_NVPTX_ENABLED */
|
||||
|
||||
inst.getLangOpts().LineComment = 1;
|
||||
#if defined(LLVM_3_5)
|
||||
|
||||
#if !defined(LLVM_3_2) && !defined(LLVM_3_3) && !defined(LLVM_3_4) // LLVM 3.5+
|
||||
inst.createPreprocessor(clang::TU_Complete);
|
||||
#else
|
||||
inst.createPreprocessor();
|
||||
|
||||
Reference in New Issue
Block a user