Fix build to work with LLVM top-of-tree again

This commit is contained in:
Matt Pharr
2013-01-06 12:02:08 -08:00
parent 2063d34f3e
commit 63dd7d9859
15 changed files with 306 additions and 111 deletions

View File

@@ -47,15 +47,25 @@
#include <math.h> #include <math.h>
#include <stdlib.h> #include <stdlib.h>
#include <llvm/LLVMContext.h> #if defined(LLVM_3_2)
#if !defined(LLVM_3_0) && !defined(LLVM_3_1)
#include <llvm/Attributes.h> #include <llvm/Attributes.h>
#endif #endif
#include <llvm/Module.h> #if defined(LLVM_3_0) || defined(LLVM_3_1) || defined(LLVM_3_2)
#include <llvm/Type.h> #include <llvm/LLVMContext.h>
#include <llvm/DerivedTypes.h> #include <llvm/Module.h>
#include <llvm/Instructions.h> #include <llvm/Type.h>
#include <llvm/Intrinsics.h> #include <llvm/Instructions.h>
#include <llvm/Intrinsics.h>
#include <llvm/DerivedTypes.h>
#else
#include <llvm/IR/Attributes.h>
#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/Linker.h> #include <llvm/Linker.h>
#include <llvm/Target/TargetMachine.h> #include <llvm/Target/TargetMachine.h>
#include <llvm/ADT/Triple.h> #include <llvm/ADT/Triple.h>
@@ -700,10 +710,10 @@ lDefineConstantIntFunc(const char *name, int val, llvm::Module *module,
llvm::Function *func = module->getFunction(name); llvm::Function *func = module->getFunction(name);
Assert(func != NULL); // it should be declared already... Assert(func != NULL); // it should be declared already...
#if defined(LLVM_3_0) || defined(LLVM_3_1) #if defined(LLVM_3_2)
func->addFnAttr(llvm::Attribute::AlwaysInline);
#else
func->addFnAttr(llvm::Attributes::AlwaysInline); func->addFnAttr(llvm::Attributes::AlwaysInline);
#else
func->addFnAttr(llvm::Attribute::AlwaysInline);
#endif #endif
llvm::BasicBlock *bblock = llvm::BasicBlock::Create(*g->ctx, "entry", func, 0); llvm::BasicBlock *bblock = llvm::BasicBlock::Create(*g->ctx, "entry", func, 0);
llvm::ReturnInst::Create(*g->ctx, LLVMInt32(val), bblock); llvm::ReturnInst::Create(*g->ctx, LLVMInt32(val), bblock);

View File

@@ -29,16 +29,27 @@
#include "llvmutil.h" #include "llvmutil.h"
#include "llvm/CallingConv.h" #if defined(LLVM_3_0) || defined(LLVM_3_1) || defined(LLVM_3_2)
#include "llvm/Constants.h" #include "llvm/Constants.h"
#include "llvm/DerivedTypes.h" #include "llvm/DerivedTypes.h"
#include "llvm/Module.h" #include "llvm/CallingConv.h"
#include "llvm/Instructions.h" #include "llvm/Module.h"
#include "llvm/Instructions.h"
#include "llvm/Intrinsics.h"
#include "llvm/IntrinsicInst.h"
#include "llvm/InlineAsm.h"
#else
#include "llvm/IR/Constants.h"
#include "llvm/IR/DerivedTypes.h"
#include "llvm/IR/CallingConv.h"
#include "llvm/IR/Module.h"
#include "llvm/IR/Instructions.h"
#include "llvm/IR/Intrinsics.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/InlineAsm.h"
#endif
#include "llvm/Pass.h" #include "llvm/Pass.h"
#include "llvm/PassManager.h" #include "llvm/PassManager.h"
#include "llvm/Intrinsics.h"
#include "llvm/IntrinsicInst.h"
#include "llvm/InlineAsm.h"
#if !defined(LLVM_3_0) && !defined(LLVM_3_1) #if !defined(LLVM_3_0) && !defined(LLVM_3_1)
#include "llvm/TypeFinder.h" #include "llvm/TypeFinder.h"
#endif // LLVM_3_2 + #endif // LLVM_3_2 +
@@ -63,8 +74,10 @@
#include "llvm/MC/MCSymbol.h" #include "llvm/MC/MCSymbol.h"
#if defined(LLVM_3_0) || defined(LLVM_3_1) #if defined(LLVM_3_0) || defined(LLVM_3_1)
#include "llvm/Target/TargetData.h" #include "llvm/Target/TargetData.h"
#else #elif defined(LLVM_3_2)
#include "llvm/DataLayout.h" #include "llvm/DataLayout.h"
#else // LLVM 3.3+
#include "llvm/IR/DataLayout.h"
#endif #endif
#include "llvm/Support/CallSite.h" #include "llvm/Support/CallSite.h"
#include "llvm/Support/CFG.h" #include "llvm/Support/CFG.h"
@@ -335,13 +348,22 @@ namespace {
bool isSigned = false, bool isSigned = false,
const std::string &VariableName = "", const std::string &VariableName = "",
bool IgnoreName = false, bool IgnoreName = false,
const llvm::AttrListPtr &PAL = llvm::AttrListPtr()); #if defined(LLVM_3_0) || defined(LLVM_3_1) || defined(LLVM_3_2)
const llvm::AttrListPtr &PAL = llvm::AttrListPtr()
#else
const llvm::AttributeSet &PAL = llvm::AttributeSet()
#endif
);
llvm::raw_ostream &printSimpleType(llvm::raw_ostream &Out, llvm::Type *Ty, llvm::raw_ostream &printSimpleType(llvm::raw_ostream &Out, llvm::Type *Ty,
bool isSigned, bool isSigned,
const std::string &NameSoFar = ""); const std::string &NameSoFar = "");
void printStructReturnPointerFunctionType(llvm::raw_ostream &Out, void printStructReturnPointerFunctionType(llvm::raw_ostream &Out,
#if defined(LLVM_3_0) || defined(LLVM_3_1) || defined(LLVM_3_2)
const llvm::AttrListPtr &PAL, const llvm::AttrListPtr &PAL,
#else
const llvm::AttributeSet &PAL,
#endif
llvm::PointerType *Ty); llvm::PointerType *Ty);
std::string getStructName(llvm::StructType *ST); std::string getStructName(llvm::StructType *ST);
@@ -567,7 +589,11 @@ std::string CWriter::getArrayName(llvm::ArrayType *AT) {
/// return type, except, instead of printing the type as void (*)(Struct*, ...) /// return type, except, instead of printing the type as void (*)(Struct*, ...)
/// print it as "Struct (*)(...)", for struct return functions. /// print it as "Struct (*)(...)", for struct return functions.
void CWriter::printStructReturnPointerFunctionType(llvm::raw_ostream &Out, void CWriter::printStructReturnPointerFunctionType(llvm::raw_ostream &Out,
#if defined(LLVM_3_0) || defined(LLVM_3_1) || defined(LLVM_3_2)
const llvm::AttrListPtr &PAL, const llvm::AttrListPtr &PAL,
#else
const llvm::AttributeSet &PAL,
#endif
llvm::PointerType *TheTy) { llvm::PointerType *TheTy) {
llvm::FunctionType *FTy = llvm::cast<llvm::FunctionType>(TheTy->getElementType()); llvm::FunctionType *FTy = llvm::cast<llvm::FunctionType>(TheTy->getElementType());
std::string tstr; std::string tstr;
@@ -584,8 +610,10 @@ void CWriter::printStructReturnPointerFunctionType(llvm::raw_ostream &Out,
llvm::Type *ArgTy = *I; llvm::Type *ArgTy = *I;
#if defined(LLVM_3_0) || defined(LLVM_3_1) #if defined(LLVM_3_0) || defined(LLVM_3_1)
if (PAL.paramHasAttr(Idx, llvm::Attribute::ByVal)) { if (PAL.paramHasAttr(Idx, llvm::Attribute::ByVal)) {
#else #elif defined(LLVM_3_2)
if (PAL.getParamAttributes(Idx).hasAttribute(llvm::Attributes::ByVal)) { if (PAL.getParamAttributes(Idx).hasAttribute(llvm::Attributes::ByVal)) {
#else
if (PAL.getParamAttributes(Idx).hasAttribute(llvm::Attribute::ByVal)) {
#endif #endif
assert(ArgTy->isPointerTy()); assert(ArgTy->isPointerTy());
ArgTy = llvm::cast<llvm::PointerType>(ArgTy)->getElementType(); ArgTy = llvm::cast<llvm::PointerType>(ArgTy)->getElementType();
@@ -593,8 +621,10 @@ void CWriter::printStructReturnPointerFunctionType(llvm::raw_ostream &Out,
printType(FunctionInnards, ArgTy, printType(FunctionInnards, ArgTy,
#if defined(LLVM_3_0) || defined(LLVM_3_1) #if defined(LLVM_3_0) || defined(LLVM_3_1)
/*isSigned=*/PAL.paramHasAttr(Idx, llvm::Attribute::SExt), /*isSigned=*/PAL.paramHasAttr(Idx, llvm::Attribute::SExt),
#else #elif defined(LLVM_3_2)
PAL.getParamAttributes(Idx).hasAttribute(llvm::Attributes::SExt), PAL.getParamAttributes(Idx).hasAttribute(llvm::Attributes::SExt),
#else
PAL.getParamAttributes(Idx).hasAttribute(llvm::Attribute::SExt),
#endif #endif
""); "");
PrintedType = true; PrintedType = true;
@@ -610,8 +640,10 @@ void CWriter::printStructReturnPointerFunctionType(llvm::raw_ostream &Out,
printType(Out, RetTy, printType(Out, RetTy,
#if defined(LLVM_3_0) || defined(LLVM_3_1) #if defined(LLVM_3_0) || defined(LLVM_3_1)
/*isSigned=*/PAL.paramHasAttr(0, llvm::Attribute::SExt), /*isSigned=*/PAL.paramHasAttr(0, llvm::Attribute::SExt),
#else #elif defined(LLVM_3_2)
PAL.getParamAttributes(0).hasAttribute(llvm::Attributes::SExt), PAL.getParamAttributes(0).hasAttribute(llvm::Attributes::SExt),
#else
PAL.getParamAttributes(0).hasAttribute(llvm::Attribute::SExt),
#endif #endif
FunctionInnards.str()); FunctionInnards.str());
} }
@@ -707,7 +739,14 @@ CWriter::printSimpleType(llvm::raw_ostream &Out, llvm::Type *Ty, bool isSigned,
// //
llvm::raw_ostream &CWriter::printType(llvm::raw_ostream &Out, llvm::Type *Ty, llvm::raw_ostream &CWriter::printType(llvm::raw_ostream &Out, llvm::Type *Ty,
bool isSigned, const std::string &NameSoFar, bool isSigned, const std::string &NameSoFar,
bool IgnoreName, const llvm::AttrListPtr &PAL) { bool IgnoreName,
#if defined(LLVM_3_0) || defined(LLVM_3_1) || defined(LLVM_3_2)
const llvm::AttrListPtr &PAL
#else
const llvm::AttributeSet &PAL
#endif
) {
if (Ty->isPrimitiveType() || Ty->isIntegerTy() || Ty->isVectorTy()) { if (Ty->isPrimitiveType() || Ty->isIntegerTy() || Ty->isVectorTy()) {
printSimpleType(Out, Ty, isSigned, NameSoFar); printSimpleType(Out, Ty, isSigned, NameSoFar);
return Out; return Out;
@@ -725,8 +764,10 @@ llvm::raw_ostream &CWriter::printType(llvm::raw_ostream &Out, llvm::Type *Ty,
llvm::Type *ArgTy = *I; llvm::Type *ArgTy = *I;
#if defined(LLVM_3_0) || defined(LLVM_3_1) #if defined(LLVM_3_0) || defined(LLVM_3_1)
if (PAL.paramHasAttr(Idx, llvm::Attribute::ByVal)) { if (PAL.paramHasAttr(Idx, llvm::Attribute::ByVal)) {
#else #elif defined(LLVM_3_2)
if (PAL.getParamAttributes(Idx).hasAttribute(llvm::Attributes::ByVal)) { if (PAL.getParamAttributes(Idx).hasAttribute(llvm::Attributes::ByVal)) {
#else
if (PAL.getParamAttributes(Idx).hasAttribute(llvm::Attribute::ByVal)) {
#endif #endif
assert(ArgTy->isPointerTy()); assert(ArgTy->isPointerTy());
ArgTy = llvm::cast<llvm::PointerType>(ArgTy)->getElementType(); ArgTy = llvm::cast<llvm::PointerType>(ArgTy)->getElementType();
@@ -736,8 +777,10 @@ llvm::raw_ostream &CWriter::printType(llvm::raw_ostream &Out, llvm::Type *Ty,
printType(FunctionInnards, ArgTy, printType(FunctionInnards, ArgTy,
#if defined(LLVM_3_0) || defined(LLVM_3_1) #if defined(LLVM_3_0) || defined(LLVM_3_1)
/*isSigned=*/PAL.paramHasAttr(Idx, llvm::Attribute::SExt), /*isSigned=*/PAL.paramHasAttr(Idx, llvm::Attribute::SExt),
#else #elif defined(LLVM_3_2)
PAL.getParamAttributes(Idx).hasAttribute(llvm::Attributes::SExt), PAL.getParamAttributes(Idx).hasAttribute(llvm::Attributes::SExt),
#else
PAL.getParamAttributes(Idx).hasAttribute(llvm::Attribute::SExt),
#endif #endif
""); "");
++Idx; ++Idx;
@@ -753,8 +796,10 @@ llvm::raw_ostream &CWriter::printType(llvm::raw_ostream &Out, llvm::Type *Ty,
printType(Out, FTy->getReturnType(), printType(Out, FTy->getReturnType(),
#if defined(LLVM_3_0) || defined(LLVM_3_1) #if defined(LLVM_3_0) || defined(LLVM_3_1)
/*isSigned=*/PAL.paramHasAttr(0, llvm::Attribute::SExt), /*isSigned=*/PAL.paramHasAttr(0, llvm::Attribute::SExt),
#else #elif defined(LLVM_3_2)
PAL.getParamAttributes(0).hasAttribute(llvm::Attributes::SExt), PAL.getParamAttributes(0).hasAttribute(llvm::Attributes::SExt),
#else
PAL.getParamAttributes(0).hasAttribute(llvm::Attribute::SExt),
#endif #endif
FunctionInnards.str()); FunctionInnards.str());
return Out; return Out;
@@ -2796,7 +2841,11 @@ void CWriter::printFunctionSignature(const llvm::Function *F, bool Prototype) {
// Loop over the arguments, printing them... // Loop over the arguments, printing them...
llvm::FunctionType *FT = llvm::cast<llvm::FunctionType>(F->getFunctionType()); llvm::FunctionType *FT = llvm::cast<llvm::FunctionType>(F->getFunctionType());
#if defined(LLVM_3_0) || defined(LLVM_3_1) || defined(LLVM_3_2)
const llvm::AttrListPtr &PAL = F->getAttributes(); const llvm::AttrListPtr &PAL = F->getAttributes();
#else
const llvm::AttributeSet &PAL = F->getAttributes();
#endif
std::string tstr; std::string tstr;
llvm::raw_string_ostream FunctionInnards(tstr); llvm::raw_string_ostream FunctionInnards(tstr);
@@ -2828,8 +2877,10 @@ void CWriter::printFunctionSignature(const llvm::Function *F, bool Prototype) {
llvm::Type *ArgTy = I->getType(); llvm::Type *ArgTy = I->getType();
#if defined(LLVM_3_0) || defined(LLVM_3_1) #if defined(LLVM_3_0) || defined(LLVM_3_1)
if (PAL.paramHasAttr(Idx, llvm::Attribute::ByVal)) { if (PAL.paramHasAttr(Idx, llvm::Attribute::ByVal)) {
#else #elif defined(LLVM_3_2)
if (PAL.getParamAttributes(Idx).hasAttribute(llvm::Attributes::ByVal)) { if (PAL.getParamAttributes(Idx).hasAttribute(llvm::Attributes::ByVal)) {
#else
if (PAL.getParamAttributes(Idx).hasAttribute(llvm::Attribute::ByVal)) {
#endif #endif
ArgTy = llvm::cast<llvm::PointerType>(ArgTy)->getElementType(); ArgTy = llvm::cast<llvm::PointerType>(ArgTy)->getElementType();
ByValParams.insert(I); ByValParams.insert(I);
@@ -2837,8 +2888,10 @@ void CWriter::printFunctionSignature(const llvm::Function *F, bool Prototype) {
printType(FunctionInnards, ArgTy, printType(FunctionInnards, ArgTy,
#if defined(LLVM_3_0) || defined(LLVM_3_1) #if defined(LLVM_3_0) || defined(LLVM_3_1)
/*isSigned=*/PAL.paramHasAttr(Idx, llvm::Attribute::SExt), /*isSigned=*/PAL.paramHasAttr(Idx, llvm::Attribute::SExt),
#else #elif defined(LLVM_3_2)
PAL.getParamAttributes(Idx).hasAttribute(llvm::Attributes::SExt), PAL.getParamAttributes(Idx).hasAttribute(llvm::Attributes::SExt),
#else
PAL.getParamAttributes(Idx).hasAttribute(llvm::Attribute::SExt),
#endif #endif
ArgName); ArgName);
PrintedArg = true; PrintedArg = true;
@@ -2863,8 +2916,10 @@ void CWriter::printFunctionSignature(const llvm::Function *F, bool Prototype) {
llvm::Type *ArgTy = *I; llvm::Type *ArgTy = *I;
#if defined(LLVM_3_0) || defined(LLVM_3_1) #if defined(LLVM_3_0) || defined(LLVM_3_1)
if (PAL.paramHasAttr(Idx, llvm::Attribute::ByVal)) { if (PAL.paramHasAttr(Idx, llvm::Attribute::ByVal)) {
#else #elif defined(LLVM_3_2)
if (PAL.getParamAttributes(Idx).hasAttribute(llvm::Attributes::ByVal)) { if (PAL.getParamAttributes(Idx).hasAttribute(llvm::Attributes::ByVal)) {
#else
if (PAL.getParamAttributes(Idx).hasAttribute(llvm::Attribute::ByVal)) {
#endif #endif
assert(ArgTy->isPointerTy()); assert(ArgTy->isPointerTy());
ArgTy = llvm::cast<llvm::PointerType>(ArgTy)->getElementType(); ArgTy = llvm::cast<llvm::PointerType>(ArgTy)->getElementType();
@@ -2872,9 +2927,10 @@ void CWriter::printFunctionSignature(const llvm::Function *F, bool Prototype) {
printType(FunctionInnards, ArgTy, printType(FunctionInnards, ArgTy,
#if defined(LLVM_3_0) || defined(LLVM_3_1) #if defined(LLVM_3_0) || defined(LLVM_3_1)
/*isSigned=*/PAL.paramHasAttr(Idx, llvm::Attribute::SExt) /*isSigned=*/PAL.paramHasAttr(Idx, llvm::Attribute::SExt)
#else #elif defined(LLVM_3_2)
PAL.getParamAttributes(Idx).hasAttribute(llvm::Attributes::SExt) PAL.getParamAttributes(Idx).hasAttribute(llvm::Attributes::SExt)
#else
PAL.getParamAttributes(Idx).hasAttribute(llvm::Attribute::SExt)
#endif #endif
); );
PrintedArg = true; PrintedArg = true;
@@ -2910,8 +2966,10 @@ void CWriter::printFunctionSignature(const llvm::Function *F, bool Prototype) {
printType(Out, RetTy, printType(Out, RetTy,
#if defined(LLVM_3_0) || defined(LLVM_3_1) #if defined(LLVM_3_0) || defined(LLVM_3_1)
/*isSigned=*/PAL.paramHasAttr(0, llvm::Attribute::SExt), /*isSigned=*/PAL.paramHasAttr(0, llvm::Attribute::SExt),
#else #elif defined(LLVM_3_2)
PAL.getParamAttributes(0).hasAttribute(llvm::Attributes::SExt), PAL.getParamAttributes(0).hasAttribute(llvm::Attributes::SExt),
#else
PAL.getParamAttributes(0).hasAttribute(llvm::Attribute::SExt),
#endif #endif
FunctionInnards.str()); FunctionInnards.str());
} }
@@ -3718,7 +3776,11 @@ void CWriter::lowerIntrinsics(llvm::Function &F) {
const char *BuiltinName = ""; const char *BuiltinName = "";
#define GET_GCC_BUILTIN_NAME #define GET_GCC_BUILTIN_NAME
#define Intrinsic llvm::Intrinsic #define Intrinsic llvm::Intrinsic
#include "llvm/Intrinsics.gen" #if defined(LLVM_3_0) || defined(LLVM_3_1) || defined(LLVM_3_2)
#include "llvm/Intrinsics.gen"
#else
#include "llvm/IR/Intrinsics.gen"
#endif
#undef Intrinsic #undef Intrinsic
#undef GET_GCC_BUILTIN_NAME #undef GET_GCC_BUILTIN_NAME
// If we handle it, don't lower it. // If we handle it, don't lower it.
@@ -3779,7 +3841,11 @@ void CWriter::visitCallInst(llvm::CallInst &I) {
// If this is a call to a struct-return function, assign to the first // If this is a call to a struct-return function, assign to the first
// parameter instead of passing it to the call. // parameter instead of passing it to the call.
#if defined(LLVM_3_0) || defined(LLVM_3_1) || defined(LLVM_3_2)
const llvm::AttrListPtr &PAL = I.getAttributes(); const llvm::AttrListPtr &PAL = I.getAttributes();
#else
const llvm::AttributeSet &PAL = I.getAttributes();
#endif
bool hasByVal = I.hasByValArgument(); bool hasByVal = I.hasByValArgument();
bool isStructRet = I.hasStructRetAttr(); bool isStructRet = I.hasStructRetAttr();
if (isStructRet) { if (isStructRet) {
@@ -3858,18 +3924,20 @@ void CWriter::visitCallInst(llvm::CallInst &I) {
printType(Out, FTy->getParamType(ArgNo), printType(Out, FTy->getParamType(ArgNo),
#if defined(LLVM_3_0) || defined(LLVM_3_1) #if defined(LLVM_3_0) || defined(LLVM_3_1)
/*isSigned=*/PAL.paramHasAttr(ArgNo+1, llvm::Attribute::SExt) /*isSigned=*/PAL.paramHasAttr(ArgNo+1, llvm::Attribute::SExt)
#else #elif defined(LLVM_3_2)
PAL.getParamAttributes(ArgNo+1).hasAttribute(llvm::Attributes::SExt) PAL.getParamAttributes(ArgNo+1).hasAttribute(llvm::Attributes::SExt)
#else
PAL.getParamAttributes(ArgNo+1).hasAttribute(llvm::Attribute::SExt)
#endif #endif
); );
Out << ')'; Out << ')';
} }
// Check if the argument is expected to be passed by value. // Check if the argument is expected to be passed by value.
if (I.paramHasAttr(ArgNo+1, if (I.paramHasAttr(ArgNo+1,
#if defined(LLVM_3_0) || defined(LLVM_3_1) #if defined(LLVM_3_2)
llvm::Attribute::ByVal
#else
llvm::Attributes::ByVal llvm::Attributes::ByVal
#else
llvm::Attribute::ByVal
#endif #endif
)) ))
writeOperandDeref(*AI); writeOperandDeref(*AI);
@@ -3895,7 +3963,11 @@ bool CWriter::visitBuiltinCall(llvm::CallInst &I, llvm::Intrinsic::ID ID,
#endif // LLVM_3_0 #endif // LLVM_3_0
#define GET_GCC_BUILTIN_NAME #define GET_GCC_BUILTIN_NAME
#define Intrinsic llvm::Intrinsic #define Intrinsic llvm::Intrinsic
#include "llvm/Intrinsics.gen" #if defined(LLVM_3_0) || defined(LLVM_3_1) || defined(LLVM_3_2)
#include "llvm/Intrinsics.gen"
#else
#include "llvm/IR/Intrinsics.gen"
#endif
#undef Intrinsic #undef Intrinsic
#undef GET_GCC_BUILTIN_NAME #undef GET_GCC_BUILTIN_NAME
assert(BuiltinName[0] && "Unknown LLVM intrinsic!"); assert(BuiltinName[0] && "Unknown LLVM intrinsic!");
@@ -4677,35 +4749,35 @@ public:
notFunc = notFunc =
llvm::dyn_cast<llvm::Function>(m->getOrInsertFunction("__not", mt, mt, NULL)); llvm::dyn_cast<llvm::Function>(m->getOrInsertFunction("__not", mt, mt, NULL));
assert(notFunc != NULL); assert(notFunc != NULL);
#if defined(LLVM_3_0) || defined(LLVM_3_1) #if defined(LLVM_3_2)
notFunc->addFnAttr(llvm::Attribute::NoUnwind);
notFunc->addFnAttr(llvm::Attribute::ReadNone);
#else
notFunc->addFnAttr(llvm::Attributes::NoUnwind); notFunc->addFnAttr(llvm::Attributes::NoUnwind);
notFunc->addFnAttr(llvm::Attributes::ReadNone); notFunc->addFnAttr(llvm::Attributes::ReadNone);
#else
notFunc->addFnAttr(llvm::Attribute::NoUnwind);
notFunc->addFnAttr(llvm::Attribute::ReadNone);
#endif #endif
andNotFuncs[0] = andNotFuncs[0] =
llvm::dyn_cast<llvm::Function>(m->getOrInsertFunction("__and_not1", mt, mt, mt, llvm::dyn_cast<llvm::Function>(m->getOrInsertFunction("__and_not1", mt, mt, mt,
NULL)); NULL));
assert(andNotFuncs[0] != NULL); assert(andNotFuncs[0] != NULL);
#if defined(LLVM_3_0) || defined(LLVM_3_1) #if defined(LLVM_3_2)
andNotFuncs[0]->addFnAttr(llvm::Attribute::NoUnwind);
andNotFuncs[0]->addFnAttr(llvm::Attribute::ReadNone);
#else
andNotFuncs[0]->addFnAttr(llvm::Attributes::NoUnwind); andNotFuncs[0]->addFnAttr(llvm::Attributes::NoUnwind);
andNotFuncs[0]->addFnAttr(llvm::Attributes::ReadNone); andNotFuncs[0]->addFnAttr(llvm::Attributes::ReadNone);
#else
andNotFuncs[0]->addFnAttr(llvm::Attribute::NoUnwind);
andNotFuncs[0]->addFnAttr(llvm::Attribute::ReadNone);
#endif #endif
andNotFuncs[1] = andNotFuncs[1] =
llvm::dyn_cast<llvm::Function>(m->getOrInsertFunction("__and_not2", mt, mt, mt, llvm::dyn_cast<llvm::Function>(m->getOrInsertFunction("__and_not2", mt, mt, mt,
NULL)); NULL));
assert(andNotFuncs[1] != NULL); assert(andNotFuncs[1] != NULL);
#if defined(LLVM_3_0) || defined(LLVM_3_1) #if defined(LLVM_3_2)
andNotFuncs[1]->addFnAttr(llvm::Attribute::NoUnwind);
andNotFuncs[1]->addFnAttr(llvm::Attribute::ReadNone);
#else
andNotFuncs[1]->addFnAttr(llvm::Attributes::NoUnwind); andNotFuncs[1]->addFnAttr(llvm::Attributes::NoUnwind);
andNotFuncs[1]->addFnAttr(llvm::Attributes::ReadNone); andNotFuncs[1]->addFnAttr(llvm::Attributes::ReadNone);
#else
andNotFuncs[1]->addFnAttr(llvm::Attribute::NoUnwind);
andNotFuncs[1]->addFnAttr(llvm::Attribute::ReadNone);
#endif #endif
} }

15
ctx.cpp
View File

@@ -45,11 +45,18 @@
#include "module.h" #include "module.h"
#include "sym.h" #include "sym.h"
#include <map> #include <map>
#include <llvm/DerivedTypes.h>
#include <llvm/Instructions.h>
#include <llvm/Support/Dwarf.h> #include <llvm/Support/Dwarf.h>
#include <llvm/Metadata.h> #if defined(LLVM_3_0) || defined(LLVM_3_1) || defined(LLVM_3_2)
#include <llvm/Module.h> #include <llvm/Metadata.h>
#include <llvm/Module.h>
#include <llvm/Instructions.h>
#include <llvm/DerivedTypes.h>
#else
#include <llvm/IR/Metadata.h>
#include <llvm/IR/Module.h>
#include <llvm/IR/Instructions.h>
#include <llvm/IR/DerivedTypes.h>
#endif
/** This is a small utility structure that records information related to one /** This is a small utility structure that records information related to one
level of nested control flow. It's mostly used in correctly restoring level of nested control flow. It's mostly used in correctly restoring

9
ctx.h
View File

@@ -40,8 +40,13 @@
#include "ispc.h" #include "ispc.h"
#include <map> #include <map>
#include <llvm/InstrTypes.h> #if defined(LLVM_3_0) || defined(LLVM_3_1) || defined(LLVM_3_2)
#include <llvm/Instructions.h> #include <llvm/InstrTypes.h>
#include <llvm/Instructions.h>
#else
#include <llvm/IR/InstrTypes.h>
#include <llvm/IR/Instructions.h>
#endif
#if defined(LLVM_3_0) || defined(LLVM_3_1) #if defined(LLVM_3_0) || defined(LLVM_3_1)
#include <llvm/Analysis/DebugInfo.h> #include <llvm/Analysis/DebugInfo.h>
#include <llvm/Analysis/DIBuilder.h> #include <llvm/Analysis/DIBuilder.h>

View File

@@ -56,13 +56,23 @@
#include <list> #include <list>
#include <set> #include <set>
#include <stdio.h> #include <stdio.h>
#include <llvm/Module.h> #if defined(LLVM_3_0) || defined(LLVM_3_1) || defined(LLVM_3_2)
#include <llvm/Function.h> #include <llvm/Module.h>
#include <llvm/Type.h> #include <llvm/Type.h>
#include <llvm/DerivedTypes.h> #include <llvm/Instructions.h>
#include <llvm/LLVMContext.h> #include <llvm/Function.h>
#include <llvm/Instructions.h> #include <llvm/DerivedTypes.h>
#include <llvm/CallingConv.h> #include <llvm/LLVMContext.h>
#include <llvm/CallingConv.h>
#else
#include <llvm/IR/Module.h>
#include <llvm/IR/Type.h>
#include <llvm/IR/Instructions.h>
#include <llvm/IR/Function.h>
#include <llvm/IR/DerivedTypes.h>
#include <llvm/IR/LLVMContext.h>
#include <llvm/IR/CallingConv.h>
#endif
#include <llvm/ExecutionEngine/GenericValue.h> #include <llvm/ExecutionEngine/GenericValue.h>
#include <llvm/Support/InstIterator.h> #include <llvm/Support/InstIterator.h>

View File

@@ -46,12 +46,21 @@
#include "util.h" #include "util.h"
#include <stdio.h> #include <stdio.h>
#include <llvm/LLVMContext.h> #if defined(LLVM_3_0) || defined(LLVM_3_1) || defined(LLVM_3_2)
#include <llvm/Module.h> #include <llvm/LLVMContext.h>
#include <llvm/Type.h> #include <llvm/Module.h>
#include <llvm/DerivedTypes.h> #include <llvm/Type.h>
#include <llvm/Instructions.h> #include <llvm/Instructions.h>
#include <llvm/Intrinsics.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/PassManager.h>
#include <llvm/PassRegistry.h> #include <llvm/PassRegistry.h>
#include <llvm/Transforms/IPO.h> #include <llvm/Transforms/IPO.h>
@@ -303,8 +312,10 @@ Function::emitCode(FunctionEmitContext *ctx, llvm::Function *function,
( (
#if defined(LLVM_3_0) || defined(LLVM_3_1) #if defined(LLVM_3_0) || defined(LLVM_3_1)
(function->hasFnAttr(llvm::Attribute::AlwaysInline) == false) (function->hasFnAttr(llvm::Attribute::AlwaysInline) == false)
#else #elif defined(LLVM_3_2)
(function->getFnAttributes().hasAttribute(llvm::Attributes::AlwaysInline) == false) (function->getFnAttributes().hasAttribute(llvm::Attributes::AlwaysInline) == false)
#else // LLVM 3.3+
(function->getAttributes().getFnAttributes().hasAttribute(llvm::Attribute::AlwaysInline) == false)
#endif #endif
&& &&
costEstimate > CHECK_MASK_AT_FUNCTION_START_COST); costEstimate > CHECK_MASK_AT_FUNCTION_START_COST);

View File

@@ -48,8 +48,15 @@
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h> #include <unistd.h>
#endif #endif
#include <llvm/LLVMContext.h> #if defined(LLVM_3_0) || defined(LLVM_3_1) || defined(LLVM_3_2)
#include <llvm/Module.h> #include <llvm/LLVMContext.h>
#include <llvm/Module.h>
#include <llvm/Instructions.h>
#else
#include <llvm/IR/LLVMContext.h>
#include <llvm/IR/Module.h>
#include <llvm/IR/Instructions.h>
#endif
#if defined(LLVM_3_0) || defined(LLVM_3_1) #if defined(LLVM_3_0) || defined(LLVM_3_1)
#include <llvm/Analysis/DebugInfo.h> #include <llvm/Analysis/DebugInfo.h>
#include <llvm/Analysis/DIBuilder.h> #include <llvm/Analysis/DIBuilder.h>
@@ -58,13 +65,14 @@
#include <llvm/DIBuilder.h> #include <llvm/DIBuilder.h>
#endif #endif
#include <llvm/Support/Dwarf.h> #include <llvm/Support/Dwarf.h>
#include <llvm/Instructions.h>
#include <llvm/Target/TargetMachine.h> #include <llvm/Target/TargetMachine.h>
#include <llvm/Target/TargetOptions.h> #include <llvm/Target/TargetOptions.h>
#if defined(LLVM_3_0) || defined(LLVM_3_1) #if defined(LLVM_3_0) || defined(LLVM_3_1)
#include <llvm/Target/TargetData.h> #include <llvm/Target/TargetData.h>
#else #elif defined(LLVM_3_2)
#include <llvm/DataLayout.h> #include <llvm/DataLayout.h>
#else // LLVM 3.3+
#include <llvm/IR/DataLayout.h>
#endif #endif
#include <llvm/Support/TargetRegistry.h> #include <llvm/Support/TargetRegistry.h>
#include <llvm/Support/TargetSelect.h> #include <llvm/Support/TargetSelect.h>

View File

@@ -38,8 +38,13 @@
#include "llvmutil.h" #include "llvmutil.h"
#include "ispc.h" #include "ispc.h"
#include "type.h" #include "type.h"
#include <llvm/Instructions.h> #if defined(LLVM_3_0) || defined(LLVM_3_1) || defined(LLVM_3_2)
#include <llvm/BasicBlock.h> #include <llvm/Instructions.h>
#include <llvm/BasicBlock.h>
#else
#include <llvm/IR/Instructions.h>
#include <llvm/IR/BasicBlock.h>
#endif
#include <set> #include <set>
#include <map> #include <map>

View File

@@ -38,10 +38,17 @@
#ifndef ISPC_LLVMUTIL_H #ifndef ISPC_LLVMUTIL_H
#define ISPC_LLVMUTIL_H 1 #define ISPC_LLVMUTIL_H 1
#include <llvm/LLVMContext.h> #if defined(LLVM_3_0) || defined(LLVM_3_1) || defined(LLVM_3_2)
#include <llvm/Type.h> #include <llvm/LLVMContext.h>
#include <llvm/DerivedTypes.h> #include <llvm/Type.h>
#include <llvm/Constants.h> #include <llvm/DerivedTypes.h>
#include <llvm/Constants.h>
#else
#include <llvm/IR/LLVMContext.h>
#include <llvm/IR/Type.h>
#include <llvm/IR/DerivedTypes.h>
#include <llvm/IR/Constants.h>
#endif
namespace llvm { namespace llvm {
class PHINode; class PHINode;

View File

@@ -64,12 +64,21 @@
#define strcasecmp stricmp #define strcasecmp stricmp
#endif #endif
#include <llvm/LLVMContext.h> #if defined(LLVM_3_0) || defined(LLVM_3_1) || defined(LLVM_3_2)
#include <llvm/Module.h> #include <llvm/LLVMContext.h>
#include <llvm/Type.h> #include <llvm/Module.h>
#include <llvm/DerivedTypes.h> #include <llvm/Type.h>
#include <llvm/Instructions.h> #include <llvm/Instructions.h>
#include <llvm/Intrinsics.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/PassManager.h>
#include <llvm/PassRegistry.h> #include <llvm/PassRegistry.h>
#include <llvm/Transforms/IPO.h> #include <llvm/Transforms/IPO.h>
@@ -80,7 +89,11 @@
#if defined(LLVM_3_0) || defined(LLVM_3_1) #if defined(LLVM_3_0) || defined(LLVM_3_1)
#include <llvm/Target/TargetData.h> #include <llvm/Target/TargetData.h>
#else #else
#if defined(LLVM_3_2)
#include <llvm/DataLayout.h> #include <llvm/DataLayout.h>
#else // LLVM 3.3+
#include <llvm/IR/DataLayout.h>
#endif
#include <llvm/TargetTransformInfo.h> #include <llvm/TargetTransformInfo.h>
#endif #endif
#include <llvm/Analysis/Verifier.h> #include <llvm/Analysis/Verifier.h>
@@ -760,10 +773,10 @@ Module::AddFunctionDeclaration(const std::string &name,
if (storageClass != SC_EXTERN_C && if (storageClass != SC_EXTERN_C &&
!g->generateDebuggingSymbols && !g->generateDebuggingSymbols &&
isInline) isInline)
#if defined(LLVM_3_0) || defined(LLVM_3_1) #ifdef LLVM_3_2
function->addFnAttr(llvm::Attribute::AlwaysInline);
#else
function->addFnAttr(llvm::Attributes::AlwaysInline); function->addFnAttr(llvm::Attributes::AlwaysInline);
#else
function->addFnAttr(llvm::Attribute::AlwaysInline);
#endif #endif
if (functionType->isTask) if (functionType->isTask)
// This also applies transitively to members I think? // This also applies transitively to members I think?
@@ -1799,8 +1812,13 @@ Module::execPreprocessor(const char *infilename, llvm::raw_string_ostream *ostre
} }
options.Triple = triple.getTriple(); options.Triple = triple.getTriple();
#if defined(LLVM_3_0) || defined(LLVM_3_1) || defined(LLVM_3_2)
clang::TargetInfo *target = clang::TargetInfo *target =
clang::TargetInfo::CreateTargetInfo(inst.getDiagnostics(), options); clang::TargetInfo::CreateTargetInfo(inst.getDiagnostics(), options);
#else // LLVM 3.3+
clang::TargetInfo *target =
clang::TargetInfo::CreateTargetInfo(inst.getDiagnostics(), &options);
#endif
inst.setTarget(target); inst.setTarget(target);
inst.createSourceManager(inst.getFileManager()); inst.createSourceManager(inst.getFileManager());

31
opt.cpp
View File

@@ -48,15 +48,24 @@
#include <set> #include <set>
#include <llvm/Pass.h> #include <llvm/Pass.h>
#include <llvm/Module.h> #if defined(LLVM_3_0) || defined(LLVM_3_1) || defined(LLVM_3_2)
#include <llvm/Module.h>
#include <llvm/Instructions.h>
#include <llvm/Intrinsics.h>
#include <llvm/Function.h>
#include <llvm/BasicBlock.h>
#include <llvm/Constants.h>
#else
#include <llvm/IR/Module.h>
#include <llvm/IR/Instructions.h>
#include <llvm/IR/Intrinsics.h>
#include <llvm/IR/Function.h>
#include <llvm/IR/BasicBlock.h>
#include <llvm/IR/Constants.h>
#endif
#include <llvm/PassManager.h> #include <llvm/PassManager.h>
#include <llvm/PassRegistry.h> #include <llvm/PassRegistry.h>
#include <llvm/Assembly/PrintModulePass.h> #include <llvm/Assembly/PrintModulePass.h>
#include <llvm/Function.h>
#include <llvm/BasicBlock.h>
#include <llvm/Instructions.h>
#include <llvm/Intrinsics.h>
#include <llvm/Constants.h>
#include <llvm/Analysis/ConstantFolding.h> #include <llvm/Analysis/ConstantFolding.h>
#include <llvm/Target/TargetLibraryInfo.h> #include <llvm/Target/TargetLibraryInfo.h>
#include <llvm/ADT/Triple.h> #include <llvm/ADT/Triple.h>
@@ -66,8 +75,11 @@
#include <llvm/Target/TargetOptions.h> #include <llvm/Target/TargetOptions.h>
#if defined(LLVM_3_0) || defined(LLVM_3_1) #if defined(LLVM_3_0) || defined(LLVM_3_1)
#include <llvm/Target/TargetData.h> #include <llvm/Target/TargetData.h>
#else #elif defined(LLVM_3_2)
#include <llvm/DataLayout.h> #include <llvm/DataLayout.h>
#else // LLVM 3.3+
#include <llvm/IR/DataLayout.h>
#include <llvm/TargetTransformInfo.h>
#endif #endif
#include <llvm/Target/TargetMachine.h> #include <llvm/Target/TargetMachine.h>
#include <llvm/Analysis/Verifier.h> #include <llvm/Analysis/Verifier.h>
@@ -416,8 +428,13 @@ Optimize(llvm::Module *module, int optLevel) {
optPM.add(new llvm::DataLayout(*dl)); optPM.add(new llvm::DataLayout(*dl));
else else
optPM.add(new llvm::DataLayout(module)); optPM.add(new llvm::DataLayout(module));
#ifdef LLVM_3_2
optPM.add(new llvm::TargetTransformInfo(targetMachine->getScalarTargetTransformInfo(), optPM.add(new llvm::TargetTransformInfo(targetMachine->getScalarTargetTransformInfo(),
targetMachine->getVectorTargetTransformInfo())); targetMachine->getVectorTargetTransformInfo()));
#else // LLVM 3.3+
optPM.add(llvm::createNoTTIPass(targetMachine->getScalarTargetTransformInfo(),
targetMachine->getVectorTargetTransformInfo()));
#endif
#endif #endif
optPM.add(llvm::createIndVarSimplifyPass()); optPM.add(llvm::createIndVarSimplifyPass());

View File

@@ -83,7 +83,11 @@ struct ForeachDimension;
#include "util.h" #include "util.h"
#include <stdio.h> #include <stdio.h>
#include <llvm/Constants.h> #if !defined(LLVM_3_0) && !defined(LLVM_3_1) && !defined(LLVM_3_2)
#include <llvm/IR/Constants.h>
#else
#include <llvm/Constants.h>
#endif
#define UNIMPLEMENTED \ #define UNIMPLEMENTED \
Error(yylloc, "Unimplemented parser functionality %s:%d", \ Error(yylloc, "Unimplemented parser functionality %s:%d", \

View File

@@ -48,14 +48,25 @@
#include <stdio.h> #include <stdio.h>
#include <map> #include <map>
#include <llvm/Module.h> #if defined(LLVM_3_0) || defined(LLVM_3_1) || defined(LLVM_3_2)
#include <llvm/Function.h> #include <llvm/Module.h>
#include <llvm/Type.h> #include <llvm/Type.h>
#include <llvm/DerivedTypes.h> #include <llvm/Instructions.h>
#include <llvm/LLVMContext.h> #include <llvm/Function.h>
#include <llvm/Metadata.h> #include <llvm/DerivedTypes.h>
#include <llvm/Instructions.h> #include <llvm/LLVMContext.h>
#include <llvm/CallingConv.h> #include <llvm/Metadata.h>
#include <llvm/CallingConv.h>
#else
#include <llvm/IR/Module.h>
#include <llvm/IR/Type.h>
#include <llvm/IR/Instructions.h>
#include <llvm/IR/Function.h>
#include <llvm/IR/DerivedTypes.h>
#include <llvm/IR/LLVMContext.h>
#include <llvm/IR/Metadata.h>
#include <llvm/IR/CallingConv.h>
#endif
#include <llvm/Support/raw_ostream.h> #include <llvm/Support/raw_ostream.h>
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////

View File

@@ -43,8 +43,13 @@
#include <stdio.h> #include <stdio.h>
#include <map> #include <map>
#include <llvm/Value.h> #if defined(LLVM_3_0) || defined(LLVM_3_1) || defined(LLVM_3_2)
#include <llvm/Module.h> #include <llvm/Value.h>
#include <llvm/Module.h>
#else
#include <llvm/IR/Value.h>
#include <llvm/IR/Module.h>
#endif
#if defined(LLVM_3_0) || defined(LLVM_3_1) #if defined(LLVM_3_0) || defined(LLVM_3_1)
#include <llvm/Analysis/DebugInfo.h> #include <llvm/Analysis/DebugInfo.h>
#include <llvm/Analysis/DIBuilder.h> #include <llvm/Analysis/DIBuilder.h>

9
type.h
View File

@@ -40,8 +40,13 @@
#include "ispc.h" #include "ispc.h"
#include "util.h" #include "util.h"
#include <llvm/Type.h> #if defined(LLVM_3_0) || defined(LLVM_3_1) || defined(LLVM_3_2)
#include <llvm/DerivedTypes.h> #include <llvm/Type.h>
#include <llvm/DerivedTypes.h>
#else
#include <llvm/IR/Type.h>
#include <llvm/IR/DerivedTypes.h>
#endif
#include <llvm/ADT/SmallVector.h> #include <llvm/ADT/SmallVector.h>
class ConstExpr; class ConstExpr;