Revert "Remove support for building with LLVM 3.1"

This reverts commit d3c567503b.

Conflicts:
	opt.cpp
This commit is contained in:
Matt Pharr
2013-08-06 17:00:35 -07:00
parent ccdbddd388
commit 1276ea9844
21 changed files with 320 additions and 84 deletions

View File

@@ -29,7 +29,7 @@
#include "llvmutil.h"
#if defined(LLVM_3_2)
#if defined(LLVM_3_1) || defined(LLVM_3_2)
#include "llvm/Constants.h"
#include "llvm/DerivedTypes.h"
#include "llvm/CallingConv.h"
@@ -38,7 +38,6 @@
#include "llvm/Intrinsics.h"
#include "llvm/IntrinsicInst.h"
#include "llvm/InlineAsm.h"
#include "llvm/TypeFinder.h"
#else
#include "llvm/IR/Constants.h"
#include "llvm/IR/DerivedTypes.h"
@@ -48,10 +47,16 @@
#include "llvm/IR/Intrinsics.h"
#include "llvm/IR/IntrinsicInst.h"
#include "llvm/IR/InlineAsm.h"
#include "llvm/IR/TypeFinder.h"
#endif
#include "llvm/Pass.h"
#include "llvm/PassManager.h"
#if !defined(LLVM_3_1)
#if defined(LLVM_3_2)
#include "llvm/TypeFinder.h"
#else // LLVM_3_3 +
#include "llvm/IR/TypeFinder.h"
#endif
#endif // LLVM_3_2 +
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/STLExtras.h"
@@ -71,7 +76,9 @@
#include "llvm/MC/MCRegisterInfo.h"
#include "llvm/MC/MCSubtargetInfo.h"
#include "llvm/MC/MCSymbol.h"
#if defined(LLVM_3_2)
#if defined(LLVM_3_1)
#include "llvm/Target/TargetData.h"
#elif defined(LLVM_3_2)
#include "llvm/DataLayout.h"
#else // LLVM 3.3+
#include "llvm/IR/DataLayout.h"
@@ -81,7 +88,7 @@
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/FormattedStream.h"
#include "llvm/Support/GetElementPtrTypeIterator.h"
#if defined(LLVM_3_2)
#if defined(LLVM_3_1) || defined(LLVM_3_2)
#include "llvm/Support/InstVisitor.h"
#else // LLVM 3.3+
#include "llvm/InstVisitor.h"
@@ -251,10 +258,14 @@ namespace {
const llvm::MCRegisterInfo *MRI;
const llvm::MCObjectFileInfo *MOFI;
llvm::MCContext *TCtx;
#if defined(LLVM_3_1)
const llvm::TargetData* TD;
#else
// FIXME: it's ugly to have the name be "TD" here, but it saves us
// lots of ifdefs in the below since the new DataLayout and the old
// TargetData have generally similar interfaces...
const llvm::DataLayout* TD;
#endif
std::map<const llvm::ConstantFP *, unsigned> FPConstantMap;
std::map<const llvm::ConstantDataVector *, unsigned> VectorConstantMap;
@@ -341,7 +352,7 @@ namespace {
bool isSigned = false,
const std::string &VariableName = "",
bool IgnoreName = false,
#if defined(LLVM_3_2)
#if defined(LLVM_3_1) || defined(LLVM_3_2)
const llvm::AttrListPtr &PAL = llvm::AttrListPtr()
#else
const llvm::AttributeSet &PAL = llvm::AttributeSet()
@@ -352,7 +363,7 @@ namespace {
const std::string &NameSoFar = "");
void printStructReturnPointerFunctionType(llvm::raw_ostream &Out,
#if defined(LLVM_3_2)
#if defined(LLVM_3_1) || defined(LLVM_3_2)
const llvm::AttrListPtr &PAL,
#else
const llvm::AttributeSet &PAL,
@@ -575,7 +586,7 @@ std::string CWriter::getArrayName(llvm::ArrayType *AT) {
/// return type, except, instead of printing the type as void (*)(Struct*, ...)
/// print it as "Struct (*)(...)", for struct return functions.
void CWriter::printStructReturnPointerFunctionType(llvm::raw_ostream &Out,
#if defined(LLVM_3_2)
#if defined(LLVM_3_1) || defined(LLVM_3_2)
const llvm::AttrListPtr &PAL,
#else
const llvm::AttributeSet &PAL,
@@ -594,16 +605,20 @@ void CWriter::printStructReturnPointerFunctionType(llvm::raw_ostream &Out,
if (PrintedType)
FunctionInnards << ", ";
llvm::Type *ArgTy = *I;
#if defined(LLVM_3_2)
#if defined(LLVM_3_1)
if (PAL.paramHasAttr(Idx, llvm::Attribute::ByVal)) {
#elif defined(LLVM_3_2)
if (PAL.getParamAttributes(Idx).hasAttribute(llvm::Attributes::ByVal)) {
#else
if (PAL.getParamAttributes(Idx).hasAttribute(llvm::AttributeSet::FunctionIndex, llvm::Attribute::ByVal)) {
if (PAL.getParamAttributes(Idx).hasAttribute(llvm::AttributeSet::FunctionIndex, llvm::Attribute::ByVal)) {
#endif
assert(ArgTy->isPointerTy());
ArgTy = llvm::cast<llvm::PointerType>(ArgTy)->getElementType();
}
printType(FunctionInnards, ArgTy,
#if defined(LLVM_3_2)
#if defined(LLVM_3_1)
/*isSigned=*/PAL.paramHasAttr(Idx, llvm::Attribute::SExt),
#elif defined(LLVM_3_2)
PAL.getParamAttributes(Idx).hasAttribute(llvm::Attributes::SExt),
#else
PAL.getParamAttributes(Idx).hasAttribute(llvm::AttributeSet::FunctionIndex, llvm::Attribute::SExt),
@@ -620,7 +635,9 @@ void CWriter::printStructReturnPointerFunctionType(llvm::raw_ostream &Out,
}
FunctionInnards << ')';
printType(Out, RetTy,
#if defined(LLVM_3_2)
#if defined(LLVM_3_1)
/*isSigned=*/PAL.paramHasAttr(0, llvm::Attribute::SExt),
#elif defined(LLVM_3_2)
PAL.getParamAttributes(0).hasAttribute(llvm::Attributes::SExt),
#else
PAL.getParamAttributes(0).hasAttribute(llvm::AttributeSet::ReturnIndex, llvm::Attribute::SExt),
@@ -720,7 +737,7 @@ CWriter::printSimpleType(llvm::raw_ostream &Out, llvm::Type *Ty, bool isSigned,
llvm::raw_ostream &CWriter::printType(llvm::raw_ostream &Out, llvm::Type *Ty,
bool isSigned, const std::string &NameSoFar,
bool IgnoreName,
#if defined(LLVM_3_2)
#if defined(LLVM_3_1) || defined(LLVM_3_2)
const llvm::AttrListPtr &PAL
#else
const llvm::AttributeSet &PAL
@@ -742,7 +759,9 @@ llvm::raw_ostream &CWriter::printType(llvm::raw_ostream &Out, llvm::Type *Ty,
for (llvm::FunctionType::param_iterator I = FTy->param_begin(),
E = FTy->param_end(); I != E; ++I) {
llvm::Type *ArgTy = *I;
#if defined(LLVM_3_2)
#if defined(LLVM_3_1)
if (PAL.paramHasAttr(Idx, llvm::Attribute::ByVal)) {
#elif defined(LLVM_3_2)
if (PAL.getParamAttributes(Idx).hasAttribute(llvm::Attributes::ByVal)) {
#else
if (PAL.getParamAttributes(Idx).hasAttribute(llvm::AttributeSet::FunctionIndex, llvm::Attribute::ByVal)) {
@@ -753,7 +772,9 @@ llvm::raw_ostream &CWriter::printType(llvm::raw_ostream &Out, llvm::Type *Ty,
if (I != FTy->param_begin())
FunctionInnards << ", ";
printType(FunctionInnards, ArgTy,
#if defined(LLVM_3_2)
#if defined(LLVM_3_1)
/*isSigned=*/PAL.paramHasAttr(Idx, llvm::Attribute::SExt),
#elif defined(LLVM_3_2)
PAL.getParamAttributes(Idx).hasAttribute(llvm::Attributes::SExt),
#else
PAL.getParamAttributes(Idx).hasAttribute(llvm::AttributeSet::FunctionIndex, llvm::Attribute::SExt),
@@ -770,7 +791,9 @@ llvm::raw_ostream &CWriter::printType(llvm::raw_ostream &Out, llvm::Type *Ty,
}
FunctionInnards << ')';
printType(Out, FTy->getReturnType(),
#if defined(LLVM_3_2)
#if defined(LLVM_3_1)
/*isSigned=*/PAL.paramHasAttr(0, llvm::Attribute::SExt),
#elif defined(LLVM_3_2)
PAL.getParamAttributes(0).hasAttribute(llvm::Attributes::SExt),
#else
PAL.getParamAttributes(0).hasAttribute(llvm::AttributeSet::ReturnIndex, llvm::Attribute::SExt),
@@ -1949,7 +1972,11 @@ void CWriter::writeOperandWithCast(llvm::Value* Operand, const llvm::ICmpInst &C
// directives to cater to specific compilers as need be.
//
static void generateCompilerSpecificCode(llvm::formatted_raw_ostream& Out,
#if defined(LLVM_3_1)
const llvm::TargetData *TD) {
#else
const llvm::DataLayout *TD) {
#endif
// We output GCC specific attributes to preserve 'linkonce'ness on globals.
// If we aren't being compiled with GCC, just drop these attributes.
Out << "#ifndef __GNUC__ /* Can only support \"linkonce\" vars with GCC */\n"
@@ -2142,7 +2169,11 @@ bool CWriter::doInitialization(llvm::Module &M) {
// Initialize
TheModule = &M;
#if defined(LLVM_3_1)
TD = new llvm::TargetData(&M);
#else
TD = new llvm::DataLayout(&M);
#endif
IL = new llvm::IntrinsicLowering(*TD);
IL->AddPrototypes(M);
@@ -2625,11 +2656,15 @@ void CWriter::printModuleTypes() {
// Get all of the struct types used in the module.
std::vector<llvm::StructType*> StructTypes;
#if defined(LLVM_3_1)
TheModule->findUsedStructTypes(StructTypes);
#else
llvm::TypeFinder typeFinder;
typeFinder.run(*TheModule, false);
for (llvm::TypeFinder::iterator iter = typeFinder.begin();
iter != typeFinder.end(); ++iter)
StructTypes.push_back(*iter);
#endif
// Get all of the array types used in the module
std::vector<llvm::ArrayType*> ArrayTypes;
@@ -2750,7 +2785,7 @@ void CWriter::printFunctionSignature(const llvm::Function *F, bool Prototype) {
// Loop over the arguments, printing them...
llvm::FunctionType *FT = llvm::cast<llvm::FunctionType>(F->getFunctionType());
#if defined(LLVM_3_2)
#if defined(LLVM_3_1) || defined(LLVM_3_2)
const llvm::AttrListPtr &PAL = F->getAttributes();
#else
const llvm::AttributeSet &PAL = F->getAttributes();
@@ -2784,16 +2819,20 @@ void CWriter::printFunctionSignature(const llvm::Function *F, bool Prototype) {
else
ArgName = "";
llvm::Type *ArgTy = I->getType();
#if defined(LLVM_3_2)
#if defined(LLVM_3_1)
if (PAL.paramHasAttr(Idx, llvm::Attribute::ByVal)) {
#elif defined(LLVM_3_2)
if (PAL.getParamAttributes(Idx).hasAttribute(llvm::Attributes::ByVal)) {
#else
if (PAL.getParamAttributes(Idx).hasAttribute(llvm::AttributeSet::FunctionIndex, llvm::Attribute::ByVal)) {
if (PAL.getParamAttributes(Idx).hasAttribute(llvm::AttributeSet::FunctionIndex, llvm::Attribute::ByVal)) {
#endif
ArgTy = llvm::cast<llvm::PointerType>(ArgTy)->getElementType();
ByValParams.insert(I);
}
printType(FunctionInnards, ArgTy,
#if defined(LLVM_3_2)
#if defined(LLVM_3_1)
/*isSigned=*/PAL.paramHasAttr(Idx, llvm::Attribute::SExt),
#elif defined(LLVM_3_2)
PAL.getParamAttributes(Idx).hasAttribute(llvm::Attributes::SExt),
#else
PAL.getParamAttributes(Idx).hasAttribute(llvm::AttributeSet::FunctionIndex, llvm::Attribute::SExt),
@@ -2819,7 +2858,9 @@ void CWriter::printFunctionSignature(const llvm::Function *F, bool Prototype) {
for (; I != E; ++I) {
if (PrintedArg) FunctionInnards << ", ";
llvm::Type *ArgTy = *I;
#if defined(LLVM_3_2)
#if defined(LLVM_3_1)
if (PAL.paramHasAttr(Idx, llvm::Attribute::ByVal)) {
#elif defined(LLVM_3_2)
if (PAL.getParamAttributes(Idx).hasAttribute(llvm::Attributes::ByVal)) {
#else
if (PAL.getParamAttributes(Idx).hasAttribute(llvm::AttributeSet::FunctionIndex, llvm::Attribute::ByVal)) {
@@ -2828,7 +2869,9 @@ void CWriter::printFunctionSignature(const llvm::Function *F, bool Prototype) {
ArgTy = llvm::cast<llvm::PointerType>(ArgTy)->getElementType();
}
printType(FunctionInnards, ArgTy,
#if defined(LLVM_3_2)
#if defined(LLVM_3_1)
/*isSigned=*/PAL.paramHasAttr(Idx, llvm::Attribute::SExt)
#elif defined(LLVM_3_2)
PAL.getParamAttributes(Idx).hasAttribute(llvm::Attributes::SExt)
#else
PAL.getParamAttributes(Idx).hasAttribute(llvm::AttributeSet::FunctionIndex, llvm::Attribute::SExt)
@@ -2865,7 +2908,9 @@ void CWriter::printFunctionSignature(const llvm::Function *F, bool Prototype) {
// Print out the return type and the signature built above.
printType(Out, RetTy,
#if defined(LLVM_3_2)
#if defined(LLVM_3_1)
/*isSigned=*/PAL.paramHasAttr(0, llvm::Attribute::SExt),
#elif defined(LLVM_3_2)
PAL.getParamAttributes(0).hasAttribute(llvm::Attributes::SExt),
#else
PAL.getParamAttributes(0).hasAttribute(llvm::AttributeSet::ReturnIndex, llvm::Attribute::SExt),
@@ -3667,7 +3712,7 @@ void CWriter::lowerIntrinsics(llvm::Function &F) {
const char *BuiltinName = "";
#define GET_GCC_BUILTIN_NAME
#define Intrinsic llvm::Intrinsic
#if defined(LLVM_3_2)
#if defined(LLVM_3_1) || defined(LLVM_3_2)
#include "llvm/Intrinsics.gen"
#else
#include "llvm/IR/Intrinsics.gen"
@@ -3732,7 +3777,7 @@ void CWriter::visitCallInst(llvm::CallInst &I) {
// If this is a call to a struct-return function, assign to the first
// parameter instead of passing it to the call.
#if defined(LLVM_3_2)
#if defined(LLVM_3_1) || defined(LLVM_3_2)
const llvm::AttrListPtr &PAL = I.getAttributes();
#else
const llvm::AttributeSet &PAL = I.getAttributes();
@@ -3820,7 +3865,9 @@ void CWriter::visitCallInst(llvm::CallInst &I) {
(*AI)->getType() != FTy->getParamType(ArgNo)) {
Out << '(';
printType(Out, FTy->getParamType(ArgNo),
#if defined(LLVM_3_2)
#if defined(LLVM_3_1)
/*isSigned=*/PAL.paramHasAttr(ArgNo+1, llvm::Attribute::SExt)
#elif defined(LLVM_3_2)
PAL.getParamAttributes(ArgNo+1).hasAttribute(llvm::Attributes::SExt)
#else
PAL.getParamAttributes(ArgNo+1).hasAttribute(llvm::AttributeSet::FunctionIndex, llvm::Attribute::SExt)
@@ -3858,7 +3905,7 @@ bool CWriter::visitBuiltinCall(llvm::CallInst &I, llvm::Intrinsic::ID ID,
const char *BuiltinName = "";
#define GET_GCC_BUILTIN_NAME
#define Intrinsic llvm::Intrinsic
#if defined(LLVM_3_2)
#if defined(LLVM_3_1) || defined(LLVM_3_2)
#include "llvm/Intrinsics.gen"
#else
#include "llvm/IR/Intrinsics.gen"
@@ -4508,8 +4555,13 @@ SmearCleanupPass::runOnBasicBlock(llvm::BasicBlock &bb) {
smearType, NULL);
smearFunc = llvm::dyn_cast<llvm::Function>(sf);
assert(smearFunc != NULL);
#if defined(LLVM_3_1)
smearFunc->setDoesNotThrow(true);
smearFunc->setDoesNotAccessMemory(true);
#else
smearFunc->setDoesNotThrow();
smearFunc->setDoesNotAccessMemory();
#endif
}
assert(smearFunc != NULL);
@@ -4651,8 +4703,13 @@ AndCmpCleanupPass::runOnBasicBlock(llvm::BasicBlock &bb) {
LLVMTypes::MaskType, NULL);
andCmpFunc = llvm::dyn_cast<llvm::Function>(acf);
Assert(andCmpFunc != NULL);
#if defined(LLVM_3_1)
andCmpFunc->setDoesNotThrow(true);
andCmpFunc->setDoesNotAccessMemory(true);
#else
andCmpFunc->setDoesNotThrow();
andCmpFunc->setDoesNotAccessMemory();
#endif
}
// Set up the function call to the *_and_mask function; the
@@ -4857,7 +4914,7 @@ WriteCXXFile(llvm::Module *module, const char *fn, int vectorWidth,
pm.add(new llvm::TargetData(module));
#endif
#if defined(LLVM_3_2) || defined(LLVM_3_3)
#if defined(LLVM_3_1) || defined(LLVM_3_2) || defined(LLVM_3_3)
int flags = 0;
#else
llvm::sys::fs::OpenFlags flags = llvm::sys::fs::F_None;
@@ -4882,7 +4939,7 @@ WriteCXXFile(llvm::Module *module, const char *fn, int vectorWidth,
pm.add(llvm::createDeadCodeEliminationPass()); // clean up after smear pass
//CO pm.add(llvm::createPrintModulePass(&fos));
pm.add(new CWriter(fos, includeName, vectorWidth));
#if defined(LLVM_3_2)
#if defined(LLVM_3_1) || defined(LLVM_3_2)
// This interface is depricated for 3.3+
pm.add(llvm::createGCInfoDeleter());
#endif