Fix build with LLVM top-of-tree

This commit is contained in:
Matt Pharr
2012-10-17 11:01:13 -07:00
parent 406fbab40e
commit 172a189c6f
8 changed files with 204 additions and 25 deletions

View File

@@ -48,6 +48,9 @@
#include <math.h>
#include <stdlib.h>
#include <llvm/LLVMContext.h>
#if !defined(LLVM_3_0) && !defined(LLVM_3_1)
#include <llvm/Attributes.h>
#endif
#include <llvm/Module.h>
#include <llvm/Type.h>
#include <llvm/DerivedTypes.h>
@@ -697,7 +700,11 @@ lDefineConstantIntFunc(const char *name, int val, llvm::Module *module,
llvm::Function *func = module->getFunction(name);
Assert(func != NULL); // it should be declared already...
#if defined(LLVM_3_0) || defined(LLVM_3_1)
func->addFnAttr(llvm::Attribute::AlwaysInline);
#else
func->addFnAttr(llvm::Attributes::AlwaysInline);
#endif
llvm::BasicBlock *bblock = llvm::BasicBlock::Create(*g->ctx, "entry", func, 0);
llvm::ReturnInst::Create(*g->ctx, LLVMInt32(val), bblock);

View File

@@ -61,7 +61,11 @@
#include "llvm/MC/MCRegisterInfo.h"
#include "llvm/MC/MCSubtargetInfo.h"
#include "llvm/MC/MCSymbol.h"
#include "llvm/Target/TargetData.h"
#if defined(LLVM_3_0) || defined(LLVM_3_1)
#include "llvm/Target/TargetData.h"
#else
#include "llvm/DataLayout.h"
#endif
#include "llvm/Support/CallSite.h"
#include "llvm/Support/CFG.h"
#include "llvm/Support/ErrorHandling.h"
@@ -71,6 +75,7 @@
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/TargetRegistry.h"
#include "llvm/Support/Host.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/Config/config.h"
#include <llvm/Transforms/IPO.h>
@@ -84,9 +89,6 @@
#define snprintf _snprintf
#endif
#include "llvm/Target/TargetMachine.h"
#include "llvm/Target/TargetData.h"
// FIXME:
namespace {
/// TypeFinder - Walk over a module, identifying all of the types that are
@@ -229,7 +231,14 @@ namespace {
const llvm::MCRegisterInfo *MRI;
const llvm::MCObjectFileInfo *MOFI;
llvm::MCContext *TCtx;
#if defined(LLVM_3_0) || 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;
#ifndef LLVM_3_0
@@ -569,12 +578,21 @@ void CWriter::printStructReturnPointerFunctionType(llvm::raw_ostream &Out,
if (PrintedType)
FunctionInnards << ", ";
llvm::Type *ArgTy = *I;
#if defined(LLVM_3_0) || defined(LLVM_3_1)
if (PAL.paramHasAttr(Idx, llvm::Attribute::ByVal)) {
#else
if (PAL.getParamAttributes(Idx).hasAttribute(llvm::Attributes::ByVal)) {
#endif
assert(ArgTy->isPointerTy());
ArgTy = llvm::cast<llvm::PointerType>(ArgTy)->getElementType();
}
printType(FunctionInnards, ArgTy,
/*isSigned=*/PAL.paramHasAttr(Idx, llvm::Attribute::SExt), "");
#if defined(LLVM_3_0) || defined(LLVM_3_1)
/*isSigned=*/PAL.paramHasAttr(Idx, llvm::Attribute::SExt),
#else
PAL.getParamAttributes(Idx).hasAttribute(llvm::Attributes::SExt),
#endif
"");
PrintedType = true;
}
if (FTy->isVarArg()) {
@@ -586,7 +604,12 @@ void CWriter::printStructReturnPointerFunctionType(llvm::raw_ostream &Out,
}
FunctionInnards << ')';
printType(Out, RetTy,
/*isSigned=*/PAL.paramHasAttr(0, llvm::Attribute::SExt), FunctionInnards.str());
#if defined(LLVM_3_0) || defined(LLVM_3_1)
/*isSigned=*/PAL.paramHasAttr(0, llvm::Attribute::SExt),
#else
PAL.getParamAttributes(0).hasAttribute(llvm::Attributes::SExt),
#endif
FunctionInnards.str());
}
llvm::raw_ostream &
@@ -696,14 +719,23 @@ 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_0) || defined(LLVM_3_1)
if (PAL.paramHasAttr(Idx, llvm::Attribute::ByVal)) {
#else
if (PAL.getParamAttributes(Idx).hasAttribute(llvm::Attributes::ByVal)) {
#endif
assert(ArgTy->isPointerTy());
ArgTy = llvm::cast<llvm::PointerType>(ArgTy)->getElementType();
}
if (I != FTy->param_begin())
FunctionInnards << ", ";
printType(FunctionInnards, ArgTy,
/*isSigned=*/PAL.paramHasAttr(Idx, llvm::Attribute::SExt), "");
#if defined(LLVM_3_0) || defined(LLVM_3_1)
/*isSigned=*/PAL.paramHasAttr(Idx, llvm::Attribute::SExt),
#else
PAL.getParamAttributes(Idx).hasAttribute(llvm::Attributes::SExt),
#endif
"");
++Idx;
}
if (FTy->isVarArg()) {
@@ -715,7 +747,12 @@ llvm::raw_ostream &CWriter::printType(llvm::raw_ostream &Out, llvm::Type *Ty,
}
FunctionInnards << ')';
printType(Out, FTy->getReturnType(),
/*isSigned=*/PAL.paramHasAttr(0, llvm::Attribute::SExt), FunctionInnards.str());
#if defined(LLVM_3_0) || defined(LLVM_3_1)
/*isSigned=*/PAL.paramHasAttr(0, llvm::Attribute::SExt),
#else
PAL.getParamAttributes(0).hasAttribute(llvm::Attributes::SExt),
#endif
FunctionInnards.str());
return Out;
}
case llvm::Type::StructTyID: {
@@ -1953,7 +1990,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_0) || 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"
@@ -2139,7 +2180,11 @@ bool CWriter::doInitialization(llvm::Module &M) {
// Initialize
TheModule = &M;
#if defined(LLVM_3_0) || defined(LLVM_3_1)
TD = new llvm::TargetData(&M);
#else
TD = new llvm::DataLayout(&M);
#endif
IL = new llvm::IntrinsicLowering(*TD);
IL->AddPrototypes(M);
@@ -2777,13 +2822,21 @@ void CWriter::printFunctionSignature(const llvm::Function *F, bool Prototype) {
else
ArgName = "";
llvm::Type *ArgTy = I->getType();
#if defined(LLVM_3_0) || defined(LLVM_3_1)
if (PAL.paramHasAttr(Idx, llvm::Attribute::ByVal)) {
#else
if (PAL.getParamAttributes(Idx).hasAttribute(llvm::Attributes::ByVal)) {
#endif
ArgTy = llvm::cast<llvm::PointerType>(ArgTy)->getElementType();
ByValParams.insert(I);
}
printType(FunctionInnards, ArgTy,
/*isSigned=*/PAL.paramHasAttr(Idx, llvm::Attribute::SExt),
ArgName);
#if defined(LLVM_3_0) || defined(LLVM_3_1)
/*isSigned=*/PAL.paramHasAttr(Idx, llvm::Attribute::SExt),
#else
PAL.getParamAttributes(Idx).hasAttribute(llvm::Attributes::SExt),
#endif
ArgName);
PrintedArg = true;
++Idx;
}
@@ -2804,12 +2857,22 @@ void CWriter::printFunctionSignature(const llvm::Function *F, bool Prototype) {
for (; I != E; ++I) {
if (PrintedArg) FunctionInnards << ", ";
llvm::Type *ArgTy = *I;
#if defined(LLVM_3_0) || defined(LLVM_3_1)
if (PAL.paramHasAttr(Idx, llvm::Attribute::ByVal)) {
#else
if (PAL.getParamAttributes(Idx).hasAttribute(llvm::Attributes::ByVal)) {
#endif
assert(ArgTy->isPointerTy());
ArgTy = llvm::cast<llvm::PointerType>(ArgTy)->getElementType();
}
printType(FunctionInnards, ArgTy,
/*isSigned=*/PAL.paramHasAttr(Idx, llvm::Attribute::SExt));
#if defined(LLVM_3_0) || defined(LLVM_3_1)
/*isSigned=*/PAL.paramHasAttr(Idx, llvm::Attribute::SExt)
#else
PAL.getParamAttributes(Idx).hasAttribute(llvm::Attributes::SExt)
#endif
);
PrintedArg = true;
++Idx;
}
@@ -2841,7 +2904,11 @@ 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_0) || defined(LLVM_3_1)
/*isSigned=*/PAL.paramHasAttr(0, llvm::Attribute::SExt),
#else
PAL.getParamAttributes(0).hasAttribute(llvm::Attributes::SExt),
#endif
FunctionInnards.str());
}
@@ -3785,11 +3852,22 @@ void CWriter::visitCallInst(llvm::CallInst &I) {
(*AI)->getType() != FTy->getParamType(ArgNo)) {
Out << '(';
printType(Out, FTy->getParamType(ArgNo),
/*isSigned=*/PAL.paramHasAttr(ArgNo+1, llvm::Attribute::SExt));
#if defined(LLVM_3_0) || defined(LLVM_3_1)
/*isSigned=*/PAL.paramHasAttr(ArgNo+1, llvm::Attribute::SExt)
#else
PAL.getParamAttributes(ArgNo+1).hasAttribute(llvm::Attributes::SExt)
#endif
);
Out << ')';
}
// Check if the argument is expected to be passed by value.
if (I.paramHasAttr(ArgNo+1, llvm::Attribute::ByVal))
if (I.paramHasAttr(ArgNo+1,
#if defined(LLVM_3_0) || defined(LLVM_3_1)
llvm::Attribute::ByVal
#else
llvm::Attributes::ByVal
#endif
))
writeOperandDeref(*AI);
else
writeOperand(*AI);
@@ -4394,8 +4472,13 @@ SmearCleanupPass::runOnBasicBlock(llvm::BasicBlock &bb) {
matchType, NULL);
smearFunc = llvm::dyn_cast<llvm::Function>(sf);
assert(smearFunc != NULL);
#if defined(LLVM_3_0) || defined(LLVM_3_1)
smearFunc->setDoesNotThrow(true);
smearFunc->setDoesNotAccessMemory(true);
#else
smearFunc->setDoesNotThrow();
smearFunc->setDoesNotAccessMemory();
#endif
}
assert(smearFunc != NULL);
@@ -4540,8 +4623,13 @@ AndCmpCleanupPass::runOnBasicBlock(llvm::BasicBlock &bb) {
LLVMTypes::MaskType, NULL);
andCmpFunc = llvm::dyn_cast<llvm::Function>(acf);
Assert(andCmpFunc != NULL);
#if defined(LLVM_3_0) || 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
@@ -4585,22 +4673,36 @@ public:
notFunc =
llvm::dyn_cast<llvm::Function>(m->getOrInsertFunction("__not", mt, mt, NULL));
assert(notFunc != NULL);
#if defined(LLVM_3_0) || defined(LLVM_3_1)
notFunc->addFnAttr(llvm::Attribute::NoUnwind);
notFunc->addFnAttr(llvm::Attribute::ReadNone);
#else
notFunc->addFnAttr(llvm::Attributes::NoUnwind);
notFunc->addFnAttr(llvm::Attributes::ReadNone);
#endif
andNotFuncs[0] =
llvm::dyn_cast<llvm::Function>(m->getOrInsertFunction("__and_not1", mt, mt, mt,
NULL));
assert(andNotFuncs[0] != NULL);
#if defined(LLVM_3_0) || defined(LLVM_3_1)
andNotFuncs[0]->addFnAttr(llvm::Attribute::NoUnwind);
andNotFuncs[0]->addFnAttr(llvm::Attribute::ReadNone);
#else
andNotFuncs[0]->addFnAttr(llvm::Attributes::NoUnwind);
andNotFuncs[0]->addFnAttr(llvm::Attributes::ReadNone);
#endif
andNotFuncs[1] =
llvm::dyn_cast<llvm::Function>(m->getOrInsertFunction("__and_not2", mt, mt, mt,
NULL));
assert(andNotFuncs[1] != NULL);
#if defined(LLVM_3_0) || defined(LLVM_3_1)
andNotFuncs[1]->addFnAttr(llvm::Attribute::NoUnwind);
andNotFuncs[1]->addFnAttr(llvm::Attribute::ReadNone);
#else
andNotFuncs[1]->addFnAttr(llvm::Attributes::NoUnwind);
andNotFuncs[1]->addFnAttr(llvm::Attributes::ReadNone);
#endif
}
const char *getPassName() const { return "MaskOps Cleanup Pass"; }

View File

@@ -63,7 +63,6 @@
#include <llvm/LLVMContext.h>
#include <llvm/Instructions.h>
#include <llvm/CallingConv.h>
#include <llvm/Target/TargetData.h>
#include <llvm/ExecutionEngine/GenericValue.h>
#include <llvm/Support/InstIterator.h>

View File

@@ -59,7 +59,6 @@
#include <llvm/Support/FileUtilities.h>
#include <llvm/Target/TargetMachine.h>
#include <llvm/Target/TargetOptions.h>
#include <llvm/Target/TargetData.h>
#include <llvm/PassManager.h>
#include <llvm/Analysis/Verifier.h>
#include <llvm/Support/CFG.h>
@@ -305,7 +304,7 @@ Function::emitCode(FunctionEmitContext *ctx, llvm::Function *function,
#if defined(LLVM_3_0) || defined(LLVM_3_1)
(function->hasFnAttr(llvm::Attribute::AlwaysInline) == false)
#else
(function->getFnAttributes().hasAlwaysInlineAttr() == false)
(function->getFnAttributes().hasAttribute(llvm::Attributes::AlwaysInline) == false)
#endif
&&
costEstimate > CHECK_MASK_AT_FUNCTION_START_COST);
@@ -443,7 +442,11 @@ Function::GenerateIR() {
functionName += std::string("_") + g->target.GetISAString();
llvm::Function *appFunction =
llvm::Function::Create(ftype, linkage, functionName.c_str(), m->module);
#if defined(LLVM_3_0) || defined(LLVM_3_1)
appFunction->setDoesNotThrow(true);
#else
appFunction->setDoesNotThrow();
#endif
if (appFunction->getName() != functionName) {
// this was a redefinition for which we already emitted an

View File

@@ -61,7 +61,11 @@
#include <llvm/Instructions.h>
#include <llvm/Target/TargetMachine.h>
#include <llvm/Target/TargetOptions.h>
#include <llvm/Target/TargetData.h>
#if defined(LLVM_3_0) || defined(LLVM_3_1)
#include <llvm/Target/TargetData.h>
#else
#include <llvm/DataLayout.h>
#endif
#include <llvm/Support/TargetRegistry.h>
#include <llvm/Support/TargetSelect.h>
#include <llvm/Support/Host.h>
@@ -407,8 +411,14 @@ Target::GetTarget(const char *arch, const char *cpu, const char *isa,
if (!error) {
llvm::TargetMachine *targetMachine = t->GetTargetMachine();
#if defined(LLVM_3_0) || defined(LLVM_3_1)
const llvm::TargetData *targetData = targetMachine->getTargetData();
t->is32Bit = (targetData->getPointerSize() == 4);
#else
int addressSpace = 0;
const llvm::DataLayout *dataLayout = targetMachine->getDataLayout();
t->is32Bit = (dataLayout->getPointerSize(addressSpace) == 4);
#endif
Assert(t->vectorWidth <= ISPC_MAX_NVEC);
}
@@ -577,9 +587,16 @@ Target::SizeOf(llvm::Type *type,
"sizeof_int", insertAtEnd);
}
#if defined(LLVM_3_0) || defined(LLVM_3_1)
const llvm::TargetData *td = GetTargetMachine()->getTargetData();
Assert(td != NULL);
uint64_t bitSize = td->getTypeSizeInBits(type);
#else
const llvm::DataLayout *dl = GetTargetMachine()->getDataLayout();
Assert(dl != NULL);
uint64_t bitSize = dl->getTypeSizeInBits(type);
#endif
Assert((bitSize % 8) == 0);
uint64_t byteSize = bitSize / 8;
if (is32Bit || g->opt.force32BitAddressing)
@@ -610,15 +627,22 @@ Target::StructOffset(llvm::Type *type, int element,
"offset_int", insertAtEnd);
}
const llvm::TargetData *td = GetTargetMachine()->getTargetData();
Assert(td != NULL);
llvm::StructType *structType =
llvm::dyn_cast<llvm::StructType>(type);
if (structType == NULL || structType->isSized() == false) {
Assert(m->errorCount > 0);
return NULL;
}
#if defined(LLVM_3_0) || defined(LLVM_3_1)
const llvm::TargetData *td = GetTargetMachine()->getTargetData();
Assert(td != NULL);
const llvm::StructLayout *sl = td->getStructLayout(structType);
#else
const llvm::DataLayout *dl = GetTargetMachine()->getDataLayout();
Assert(dl != NULL);
const llvm::StructLayout *sl = dl->getStructLayout(structType);
#endif
Assert(sl != NULL);
uint64_t offset = sl->getElementOffset(element);

View File

@@ -77,7 +77,12 @@
#include <llvm/Support/FileUtilities.h>
#include <llvm/Target/TargetMachine.h>
#include <llvm/Target/TargetOptions.h>
#include <llvm/Target/TargetData.h>
#if defined(LLVM_3_0) || defined(LLVM_3_1)
#include <llvm/Target/TargetData.h>
#else
#include <llvm/DataLayout.h>
#include <llvm/TargetTransformInfo.h>
#endif
#include <llvm/Analysis/Verifier.h>
#include <llvm/Support/CFG.h>
#include <clang/Frontend/CompilerInstance.h>
@@ -751,14 +756,22 @@ Module::AddFunctionDeclaration(const std::string &name,
module);
// Set function attributes: we never throw exceptions
function->setDoesNotThrow(true);
function->setDoesNotThrow();
if (storageClass != SC_EXTERN_C &&
!g->generateDebuggingSymbols &&
isInline)
#if defined(LLVM_3_0) || defined(LLVM_3_1)
function->addFnAttr(llvm::Attribute::AlwaysInline);
#else
function->addFnAttr(llvm::Attributes::AlwaysInline);
#endif
if (functionType->isTask)
// This also applies transitively to members I think?
#if defined(LLVM_3_0) || defined(LLVM_3_1)
function->setDoesNotAlias(1, true);
#else
function->setDoesNotAlias(1);
#endif
// Make sure that the return type isn't 'varying' or vector typed if
// the function is 'export'ed.
@@ -800,7 +813,12 @@ 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)
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));
@@ -1022,16 +1040,27 @@ Module::writeObjectFileOrAssembly(llvm::TargetMachine *targetMachine,
}
llvm::PassManager pm;
#if defined(LLVM_3_0) || defined(LLVM_3_1)
if (const llvm::TargetData *td = targetMachine->getTargetData())
pm.add(new llvm::TargetData(*td));
else
pm.add(new llvm::TargetData(module));
#else
if (const llvm::DataLayout *dl = targetMachine->getDataLayout())
pm.add(new llvm::DataLayout(*dl));
else
pm.add(new llvm::DataLayout(module));
#endif
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);
}

17
opt.cpp
View File

@@ -64,7 +64,11 @@
#include <llvm/Transforms/IPO.h>
#include <llvm/Transforms/Utils/BasicBlockUtils.h>
#include <llvm/Target/TargetOptions.h>
#include <llvm/Target/TargetData.h>
#if defined(LLVM_3_0) || defined(LLVM_3_1)
#include <llvm/Target/TargetData.h>
#else
#include <llvm/DataLayout.h>
#endif
#include <llvm/Target/TargetMachine.h>
#include <llvm/Analysis/Verifier.h>
#include <llvm/Analysis/Passes.h>
@@ -403,7 +407,18 @@ Optimize(llvm::Module *module, int optLevel) {
llvm::TargetLibraryInfo *targetLibraryInfo =
new llvm::TargetLibraryInfo(llvm::Triple(module->getTargetTriple()));
optPM.add(targetLibraryInfo);
#if defined(LLVM_3_0) || defined(LLVM_3_1)
optPM.add(new llvm::TargetData(module));
#else
llvm::TargetMachine *targetMachine = g->target.GetTargetMachine();
if (const llvm::DataLayout *dl = targetMachine->getDataLayout())
optPM.add(new llvm::DataLayout(*dl));
else
optPM.add(new llvm::DataLayout(module));
optPM.add(new llvm::TargetTransformInfo(targetMachine->getScalarTargetTransformInfo(),
targetMachine->getVectorTargetTransformInfo()));
#endif
optPM.add(llvm::createIndVarSimplifyPass());

View File

@@ -816,7 +816,7 @@ EnumType::GetDIType(llvm::DIDescriptor scope) const {
32 /* align in bits */,
elementArray
#if !defined(LLVM_3_0) && !defined(LLVM_3_1)
, llvm::DIType(), 0
, llvm::DIType()
#endif
);