Fix build to work with LLVM top-of-tree again
This commit is contained in:
154
cbackend.cpp
154
cbackend.cpp
@@ -29,16 +29,27 @@
|
||||
|
||||
#include "llvmutil.h"
|
||||
|
||||
#include "llvm/CallingConv.h"
|
||||
#include "llvm/Constants.h"
|
||||
#include "llvm/DerivedTypes.h"
|
||||
#include "llvm/Module.h"
|
||||
#include "llvm/Instructions.h"
|
||||
#if defined(LLVM_3_0) || defined(LLVM_3_1) || defined(LLVM_3_2)
|
||||
#include "llvm/Constants.h"
|
||||
#include "llvm/DerivedTypes.h"
|
||||
#include "llvm/CallingConv.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/PassManager.h"
|
||||
#include "llvm/Intrinsics.h"
|
||||
#include "llvm/IntrinsicInst.h"
|
||||
#include "llvm/InlineAsm.h"
|
||||
#if !defined(LLVM_3_0) && !defined(LLVM_3_1)
|
||||
#include "llvm/TypeFinder.h"
|
||||
#endif // LLVM_3_2 +
|
||||
@@ -63,8 +74,10 @@
|
||||
#include "llvm/MC/MCSymbol.h"
|
||||
#if defined(LLVM_3_0) || defined(LLVM_3_1)
|
||||
#include "llvm/Target/TargetData.h"
|
||||
#else
|
||||
#elif defined(LLVM_3_2)
|
||||
#include "llvm/DataLayout.h"
|
||||
#else // LLVM 3.3+
|
||||
#include "llvm/IR/DataLayout.h"
|
||||
#endif
|
||||
#include "llvm/Support/CallSite.h"
|
||||
#include "llvm/Support/CFG.h"
|
||||
@@ -335,13 +348,22 @@ namespace {
|
||||
bool isSigned = false,
|
||||
const std::string &VariableName = "",
|
||||
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,
|
||||
bool isSigned,
|
||||
const std::string &NameSoFar = "");
|
||||
|
||||
void printStructReturnPointerFunctionType(llvm::raw_ostream &Out,
|
||||
#if defined(LLVM_3_0) || defined(LLVM_3_1) || defined(LLVM_3_2)
|
||||
const llvm::AttrListPtr &PAL,
|
||||
#else
|
||||
const llvm::AttributeSet &PAL,
|
||||
#endif
|
||||
llvm::PointerType *Ty);
|
||||
|
||||
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*, ...)
|
||||
/// print it as "Struct (*)(...)", for struct return functions.
|
||||
void CWriter::printStructReturnPointerFunctionType(llvm::raw_ostream &Out,
|
||||
#if defined(LLVM_3_0) || defined(LLVM_3_1) || defined(LLVM_3_2)
|
||||
const llvm::AttrListPtr &PAL,
|
||||
#else
|
||||
const llvm::AttributeSet &PAL,
|
||||
#endif
|
||||
llvm::PointerType *TheTy) {
|
||||
llvm::FunctionType *FTy = llvm::cast<llvm::FunctionType>(TheTy->getElementType());
|
||||
std::string tstr;
|
||||
@@ -584,8 +610,10 @@ void CWriter::printStructReturnPointerFunctionType(llvm::raw_ostream &Out,
|
||||
llvm::Type *ArgTy = *I;
|
||||
#if defined(LLVM_3_0) || defined(LLVM_3_1)
|
||||
if (PAL.paramHasAttr(Idx, llvm::Attribute::ByVal)) {
|
||||
#else
|
||||
#elif defined(LLVM_3_2)
|
||||
if (PAL.getParamAttributes(Idx).hasAttribute(llvm::Attributes::ByVal)) {
|
||||
#else
|
||||
if (PAL.getParamAttributes(Idx).hasAttribute(llvm::Attribute::ByVal)) {
|
||||
#endif
|
||||
assert(ArgTy->isPointerTy());
|
||||
ArgTy = llvm::cast<llvm::PointerType>(ArgTy)->getElementType();
|
||||
@@ -593,8 +621,10 @@ void CWriter::printStructReturnPointerFunctionType(llvm::raw_ostream &Out,
|
||||
printType(FunctionInnards, ArgTy,
|
||||
#if defined(LLVM_3_0) || defined(LLVM_3_1)
|
||||
/*isSigned=*/PAL.paramHasAttr(Idx, llvm::Attribute::SExt),
|
||||
#else
|
||||
#elif defined(LLVM_3_2)
|
||||
PAL.getParamAttributes(Idx).hasAttribute(llvm::Attributes::SExt),
|
||||
#else
|
||||
PAL.getParamAttributes(Idx).hasAttribute(llvm::Attribute::SExt),
|
||||
#endif
|
||||
"");
|
||||
PrintedType = true;
|
||||
@@ -610,8 +640,10 @@ void CWriter::printStructReturnPointerFunctionType(llvm::raw_ostream &Out,
|
||||
printType(Out, RetTy,
|
||||
#if defined(LLVM_3_0) || defined(LLVM_3_1)
|
||||
/*isSigned=*/PAL.paramHasAttr(0, llvm::Attribute::SExt),
|
||||
#else
|
||||
#elif defined(LLVM_3_2)
|
||||
PAL.getParamAttributes(0).hasAttribute(llvm::Attributes::SExt),
|
||||
#else
|
||||
PAL.getParamAttributes(0).hasAttribute(llvm::Attribute::SExt),
|
||||
#endif
|
||||
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,
|
||||
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()) {
|
||||
printSimpleType(Out, Ty, isSigned, NameSoFar);
|
||||
return Out;
|
||||
@@ -725,8 +764,10 @@ llvm::raw_ostream &CWriter::printType(llvm::raw_ostream &Out, llvm::Type *Ty,
|
||||
llvm::Type *ArgTy = *I;
|
||||
#if defined(LLVM_3_0) || defined(LLVM_3_1)
|
||||
if (PAL.paramHasAttr(Idx, llvm::Attribute::ByVal)) {
|
||||
#else
|
||||
#elif defined(LLVM_3_2)
|
||||
if (PAL.getParamAttributes(Idx).hasAttribute(llvm::Attributes::ByVal)) {
|
||||
#else
|
||||
if (PAL.getParamAttributes(Idx).hasAttribute(llvm::Attribute::ByVal)) {
|
||||
#endif
|
||||
assert(ArgTy->isPointerTy());
|
||||
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,
|
||||
#if defined(LLVM_3_0) || defined(LLVM_3_1)
|
||||
/*isSigned=*/PAL.paramHasAttr(Idx, llvm::Attribute::SExt),
|
||||
#else
|
||||
#elif defined(LLVM_3_2)
|
||||
PAL.getParamAttributes(Idx).hasAttribute(llvm::Attributes::SExt),
|
||||
#else
|
||||
PAL.getParamAttributes(Idx).hasAttribute(llvm::Attribute::SExt),
|
||||
#endif
|
||||
"");
|
||||
++Idx;
|
||||
@@ -753,8 +796,10 @@ llvm::raw_ostream &CWriter::printType(llvm::raw_ostream &Out, llvm::Type *Ty,
|
||||
printType(Out, FTy->getReturnType(),
|
||||
#if defined(LLVM_3_0) || defined(LLVM_3_1)
|
||||
/*isSigned=*/PAL.paramHasAttr(0, llvm::Attribute::SExt),
|
||||
#else
|
||||
#elif defined(LLVM_3_2)
|
||||
PAL.getParamAttributes(0).hasAttribute(llvm::Attributes::SExt),
|
||||
#else
|
||||
PAL.getParamAttributes(0).hasAttribute(llvm::Attribute::SExt),
|
||||
#endif
|
||||
FunctionInnards.str());
|
||||
return Out;
|
||||
@@ -2796,7 +2841,11 @@ 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_0) || defined(LLVM_3_1) || defined(LLVM_3_2)
|
||||
const llvm::AttrListPtr &PAL = F->getAttributes();
|
||||
#else
|
||||
const llvm::AttributeSet &PAL = F->getAttributes();
|
||||
#endif
|
||||
|
||||
std::string 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();
|
||||
#if defined(LLVM_3_0) || defined(LLVM_3_1)
|
||||
if (PAL.paramHasAttr(Idx, llvm::Attribute::ByVal)) {
|
||||
#else
|
||||
#elif defined(LLVM_3_2)
|
||||
if (PAL.getParamAttributes(Idx).hasAttribute(llvm::Attributes::ByVal)) {
|
||||
#else
|
||||
if (PAL.getParamAttributes(Idx).hasAttribute(llvm::Attribute::ByVal)) {
|
||||
#endif
|
||||
ArgTy = llvm::cast<llvm::PointerType>(ArgTy)->getElementType();
|
||||
ByValParams.insert(I);
|
||||
@@ -2837,8 +2888,10 @@ void CWriter::printFunctionSignature(const llvm::Function *F, bool Prototype) {
|
||||
printType(FunctionInnards, ArgTy,
|
||||
#if defined(LLVM_3_0) || defined(LLVM_3_1)
|
||||
/*isSigned=*/PAL.paramHasAttr(Idx, llvm::Attribute::SExt),
|
||||
#else
|
||||
#elif defined(LLVM_3_2)
|
||||
PAL.getParamAttributes(Idx).hasAttribute(llvm::Attributes::SExt),
|
||||
#else
|
||||
PAL.getParamAttributes(Idx).hasAttribute(llvm::Attribute::SExt),
|
||||
#endif
|
||||
ArgName);
|
||||
PrintedArg = true;
|
||||
@@ -2863,8 +2916,10 @@ void CWriter::printFunctionSignature(const llvm::Function *F, bool Prototype) {
|
||||
llvm::Type *ArgTy = *I;
|
||||
#if defined(LLVM_3_0) || defined(LLVM_3_1)
|
||||
if (PAL.paramHasAttr(Idx, llvm::Attribute::ByVal)) {
|
||||
#else
|
||||
#elif defined(LLVM_3_2)
|
||||
if (PAL.getParamAttributes(Idx).hasAttribute(llvm::Attributes::ByVal)) {
|
||||
#else
|
||||
if (PAL.getParamAttributes(Idx).hasAttribute(llvm::Attribute::ByVal)) {
|
||||
#endif
|
||||
assert(ArgTy->isPointerTy());
|
||||
ArgTy = llvm::cast<llvm::PointerType>(ArgTy)->getElementType();
|
||||
@@ -2872,9 +2927,10 @@ void CWriter::printFunctionSignature(const llvm::Function *F, bool Prototype) {
|
||||
printType(FunctionInnards, ArgTy,
|
||||
#if defined(LLVM_3_0) || defined(LLVM_3_1)
|
||||
/*isSigned=*/PAL.paramHasAttr(Idx, llvm::Attribute::SExt)
|
||||
#else
|
||||
#elif defined(LLVM_3_2)
|
||||
PAL.getParamAttributes(Idx).hasAttribute(llvm::Attributes::SExt)
|
||||
|
||||
#else
|
||||
PAL.getParamAttributes(Idx).hasAttribute(llvm::Attribute::SExt)
|
||||
#endif
|
||||
);
|
||||
PrintedArg = true;
|
||||
@@ -2910,8 +2966,10 @@ void CWriter::printFunctionSignature(const llvm::Function *F, bool Prototype) {
|
||||
printType(Out, RetTy,
|
||||
#if defined(LLVM_3_0) || defined(LLVM_3_1)
|
||||
/*isSigned=*/PAL.paramHasAttr(0, llvm::Attribute::SExt),
|
||||
#else
|
||||
#elif defined(LLVM_3_2)
|
||||
PAL.getParamAttributes(0).hasAttribute(llvm::Attributes::SExt),
|
||||
#else
|
||||
PAL.getParamAttributes(0).hasAttribute(llvm::Attribute::SExt),
|
||||
#endif
|
||||
FunctionInnards.str());
|
||||
}
|
||||
@@ -3718,7 +3776,11 @@ void CWriter::lowerIntrinsics(llvm::Function &F) {
|
||||
const char *BuiltinName = "";
|
||||
#define GET_GCC_BUILTIN_NAME
|
||||
#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 GET_GCC_BUILTIN_NAME
|
||||
// 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
|
||||
// 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();
|
||||
#else
|
||||
const llvm::AttributeSet &PAL = I.getAttributes();
|
||||
#endif
|
||||
bool hasByVal = I.hasByValArgument();
|
||||
bool isStructRet = I.hasStructRetAttr();
|
||||
if (isStructRet) {
|
||||
@@ -3858,18 +3924,20 @@ void CWriter::visitCallInst(llvm::CallInst &I) {
|
||||
printType(Out, FTy->getParamType(ArgNo),
|
||||
#if defined(LLVM_3_0) || defined(LLVM_3_1)
|
||||
/*isSigned=*/PAL.paramHasAttr(ArgNo+1, llvm::Attribute::SExt)
|
||||
#else
|
||||
#elif defined(LLVM_3_2)
|
||||
PAL.getParamAttributes(ArgNo+1).hasAttribute(llvm::Attributes::SExt)
|
||||
#else
|
||||
PAL.getParamAttributes(ArgNo+1).hasAttribute(llvm::Attribute::SExt)
|
||||
#endif
|
||||
);
|
||||
Out << ')';
|
||||
}
|
||||
// Check if the argument is expected to be passed by value.
|
||||
if (I.paramHasAttr(ArgNo+1,
|
||||
#if defined(LLVM_3_0) || defined(LLVM_3_1)
|
||||
llvm::Attribute::ByVal
|
||||
#else
|
||||
#if defined(LLVM_3_2)
|
||||
llvm::Attributes::ByVal
|
||||
#else
|
||||
llvm::Attribute::ByVal
|
||||
#endif
|
||||
))
|
||||
writeOperandDeref(*AI);
|
||||
@@ -3895,7 +3963,11 @@ bool CWriter::visitBuiltinCall(llvm::CallInst &I, llvm::Intrinsic::ID ID,
|
||||
#endif // LLVM_3_0
|
||||
#define GET_GCC_BUILTIN_NAME
|
||||
#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 GET_GCC_BUILTIN_NAME
|
||||
assert(BuiltinName[0] && "Unknown LLVM intrinsic!");
|
||||
@@ -4677,35 +4749,35 @@ 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
|
||||
#if defined(LLVM_3_2)
|
||||
notFunc->addFnAttr(llvm::Attributes::NoUnwind);
|
||||
notFunc->addFnAttr(llvm::Attributes::ReadNone);
|
||||
#else
|
||||
notFunc->addFnAttr(llvm::Attribute::NoUnwind);
|
||||
notFunc->addFnAttr(llvm::Attribute::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
|
||||
#if defined(LLVM_3_2)
|
||||
andNotFuncs[0]->addFnAttr(llvm::Attributes::NoUnwind);
|
||||
andNotFuncs[0]->addFnAttr(llvm::Attributes::ReadNone);
|
||||
#else
|
||||
andNotFuncs[0]->addFnAttr(llvm::Attribute::NoUnwind);
|
||||
andNotFuncs[0]->addFnAttr(llvm::Attribute::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
|
||||
#if defined(LLVM_3_2)
|
||||
andNotFuncs[1]->addFnAttr(llvm::Attributes::NoUnwind);
|
||||
andNotFuncs[1]->addFnAttr(llvm::Attributes::ReadNone);
|
||||
#else
|
||||
andNotFuncs[1]->addFnAttr(llvm::Attribute::NoUnwind);
|
||||
andNotFuncs[1]->addFnAttr(llvm::Attribute::ReadNone);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user