mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-01 15:40:55 +03:00
Removed LLVM 3.0 compatibility code.
There might be still some pieces left here and there, and there is certainly code that could be rewritten in a nicer way with the 3.0 requirement out of the picture.
This commit is contained in:
parent
84a00b3fe9
commit
c02b38fe9a
11 changed files with 6 additions and 254 deletions
|
@ -512,13 +512,11 @@ int main(int argc, char** argv)
|
|||
// FIXME: Detect O32/N32 variants (MIPS_{O32,N32}[_SoftFP,_HardFP]).
|
||||
VersionCondition::addPredefinedGlobalIdent("MIPS");
|
||||
break;
|
||||
#if LDC_LLVM_VER >= 301
|
||||
case llvm::Triple::mips64:
|
||||
case llvm::Triple::mips64el:
|
||||
// FIXME: Detect N64 variants (MIPS64_N64[_SoftFP,_HardFP]).
|
||||
VersionCondition::addPredefinedGlobalIdent("MIPS64");
|
||||
break;
|
||||
#endif
|
||||
case llvm::Triple::sparc:
|
||||
// FIXME: Detect SPARC v8+ (SPARC_V8Plus).
|
||||
// FIXME: Detect soft float (SPARC_SoftFP/SPARC_HardFP).
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "driver/target.h"
|
||||
#include "gen/llvmcompat.h"
|
||||
#include "llvm/ADT/Triple.h"
|
||||
#include "llvm/MC/SubtargetFeature.h"
|
||||
#include "llvm/Support/Host.h"
|
||||
|
@ -88,19 +87,11 @@ llvm::TargetMachine* createTargetMachine(
|
|||
std::string defaultTriple = llvm::sys::getDefaultTargetTriple();
|
||||
if (sizeof(void*) == 4 && bitness == ExplicitBitness::M64)
|
||||
{
|
||||
#if LDC_LLVM_VER >= 301
|
||||
defaultTriple = llvm::Triple(defaultTriple).get64BitArchVariant().str();
|
||||
#else
|
||||
defaultTriple = llvm::Triple__get64BitArchVariant(defaultTriple).str();
|
||||
#endif
|
||||
}
|
||||
else if (sizeof(void*) == 8 && bitness == ExplicitBitness::M32)
|
||||
{
|
||||
#if LDC_LLVM_VER >= 301
|
||||
defaultTriple = llvm::Triple(defaultTriple).get32BitArchVariant().str();
|
||||
#else
|
||||
defaultTriple = llvm::Triple__get32BitArchVariant(defaultTriple).str();
|
||||
#endif
|
||||
}
|
||||
|
||||
llvm::Triple triple;
|
||||
|
@ -182,12 +173,6 @@ llvm::TargetMachine* createTargetMachine(
|
|||
relocModel = llvm::Reloc::PIC_;
|
||||
}
|
||||
|
||||
#if LDC_LLVM_VER == 300
|
||||
llvm::NoFramePointerElim = genDebugInfo;
|
||||
|
||||
return theTarget->createTargetMachine(triple.str(), cpu, FeaturesStr,
|
||||
relocModel, codeModel);
|
||||
#else
|
||||
llvm::TargetOptions targetOptions;
|
||||
targetOptions.NoFramePointerElim = genDebugInfo;
|
||||
|
||||
|
@ -200,5 +185,4 @@ llvm::TargetMachine* createTargetMachine(
|
|||
codeModel,
|
||||
codeGenOptLevel
|
||||
);
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -16,9 +16,6 @@
|
|||
#define LDC_DRIVER_TARGET_H
|
||||
|
||||
#include "llvm/Support/CodeGen.h"
|
||||
#if LDC_LLVM_VER == 300
|
||||
#include "llvm/Target/TargetMachine.h" // For llvm::CodeGenOpt::Level.
|
||||
#endif
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
|
|
@ -1,169 +0,0 @@
|
|||
//===-- llvmcompat.cpp ----------------------------------------------------===//
|
||||
//
|
||||
// LDC – the LLVM D compiler
|
||||
//
|
||||
// This file is distributed under the BSD-style LDC license. See the LICENSE
|
||||
// file for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "gen/llvmcompat.h"
|
||||
#include "llvm/ADT/Triple.h"
|
||||
#include "llvm/Config/llvm-config.h"
|
||||
#if LDC_LLVM_VER >= 303
|
||||
#include "llvm/IR/DerivedTypes.h"
|
||||
#include "llvm/IR/Function.h"
|
||||
#include "llvm/IR/Module.h"
|
||||
#include "llvm/IR/IRBuilder.h"
|
||||
#else
|
||||
#include "llvm/DerivedTypes.h"
|
||||
#include "llvm/Function.h"
|
||||
#include "llvm/Module.h"
|
||||
#if LDC_LLVM_VER == 302
|
||||
#include "llvm/IRBuilder.h"
|
||||
#else
|
||||
#include "llvm/Support/IRBuilder.h"
|
||||
#endif
|
||||
#endif
|
||||
#include <string>
|
||||
|
||||
#if LDC_LLVM_VER == 300
|
||||
using namespace llvm;
|
||||
|
||||
std::string llvm::sys::getDefaultTargetTriple() {
|
||||
return LLVM_HOSTTRIPLE;
|
||||
}
|
||||
|
||||
Triple llvm::Triple__get32BitArchVariant(const std::string& triple) {
|
||||
Triple T(triple);
|
||||
switch (T.getArch()) {
|
||||
case Triple::UnknownArch:
|
||||
case Triple::msp430:
|
||||
#if LDC_LLVM_VER == 300
|
||||
case Triple::alpha:
|
||||
case Triple::systemz:
|
||||
#endif
|
||||
T.setArch(Triple::UnknownArch);
|
||||
break;
|
||||
|
||||
case Triple::amdil:
|
||||
case Triple::arm:
|
||||
case Triple::cellspu:
|
||||
case Triple::le32:
|
||||
case Triple::mblaze:
|
||||
case Triple::mips:
|
||||
case Triple::mipsel:
|
||||
case Triple::ppc:
|
||||
case Triple::sparc:
|
||||
case Triple::tce:
|
||||
case Triple::thumb:
|
||||
case Triple::x86:
|
||||
case Triple::xcore:
|
||||
#if LDC_LLVM_VER == 300
|
||||
case Triple::bfin:
|
||||
#endif
|
||||
// Already 32-bit.
|
||||
break;
|
||||
|
||||
case Triple::mips64: T.setArch(Triple::mips); break;
|
||||
case Triple::mips64el: T.setArch(Triple::mipsel); break;
|
||||
case Triple::ppc64: T.setArch(Triple::ppc); break;
|
||||
case Triple::sparcv9: T.setArch(Triple::sparc); break;
|
||||
case Triple::x86_64: T.setArch(Triple::x86); break;
|
||||
#if LDC_LLVM_VER == 300
|
||||
case Triple::ptx64: T.setArch(Triple::ptx32); break;
|
||||
#endif
|
||||
}
|
||||
return T;
|
||||
}
|
||||
|
||||
Triple llvm::Triple__get64BitArchVariant(const std::string& triple) {
|
||||
Triple T(triple);
|
||||
switch (T.getArch()) {
|
||||
case Triple::UnknownArch:
|
||||
case Triple::amdil:
|
||||
case Triple::arm:
|
||||
case Triple::cellspu:
|
||||
case Triple::le32:
|
||||
case Triple::mblaze:
|
||||
case Triple::msp430:
|
||||
case Triple::tce:
|
||||
case Triple::thumb:
|
||||
case Triple::xcore:
|
||||
#if LDC_LLVM_VER == 300
|
||||
case Triple::bfin:
|
||||
#endif
|
||||
T.setArch(Triple::UnknownArch);
|
||||
break;
|
||||
|
||||
#if LDC_LLVM_VER == 300
|
||||
case Triple::alpha:
|
||||
case Triple::systemz:
|
||||
#endif
|
||||
case Triple::mips64:
|
||||
case Triple::mips64el:
|
||||
case Triple::ppc64:
|
||||
case Triple::sparcv9:
|
||||
case Triple::x86_64:
|
||||
// Already 64-bit.
|
||||
break;
|
||||
|
||||
case Triple::mips: T.setArch(Triple::mips64); break;
|
||||
case Triple::mipsel: T.setArch(Triple::mips64el); break;
|
||||
case Triple::ppc: T.setArch(Triple::ppc64); break;
|
||||
case Triple::sparc: T.setArch(Triple::sparcv9); break;
|
||||
case Triple::x86: T.setArch(Triple::x86_64); break;
|
||||
#if LDC_LLVM_VER == 300
|
||||
case Triple::ptx32: T.setArch(Triple::ptx64); break;
|
||||
#endif
|
||||
}
|
||||
return T;
|
||||
}
|
||||
|
||||
static void appendToGlobalArray(const char *Array,
|
||||
Module &M, Function *F, int Priority) {
|
||||
IRBuilder<> IRB(M.getContext());
|
||||
FunctionType *FnTy = FunctionType::get(IRB.getVoidTy(), false);
|
||||
StructType *Ty = StructType::get(
|
||||
IRB.getInt32Ty(), PointerType::getUnqual(FnTy), NULL);
|
||||
|
||||
Constant *RuntimeCtorInit = ConstantStruct::get(
|
||||
Ty, IRB.getInt32(Priority), F, NULL);
|
||||
|
||||
// Get the current set of static global constructors and add the new ctor
|
||||
// to the list.
|
||||
SmallVector<Constant *, 16> CurrentCtors;
|
||||
if (GlobalVariable * GVCtor = M.getNamedGlobal(Array)) {
|
||||
if (Constant *Init = GVCtor->getInitializer()) {
|
||||
unsigned n = Init->getNumOperands();
|
||||
CurrentCtors.reserve(n + 1);
|
||||
for (unsigned i = 0; i != n; ++i)
|
||||
CurrentCtors.push_back(cast<Constant>(Init->getOperand(i)));
|
||||
}
|
||||
GVCtor->eraseFromParent();
|
||||
}
|
||||
|
||||
CurrentCtors.push_back(RuntimeCtorInit);
|
||||
|
||||
// Create a new initializer.
|
||||
ArrayType *AT = ArrayType::get(RuntimeCtorInit->getType(),
|
||||
CurrentCtors.size());
|
||||
Constant *NewInit = ConstantArray::get(AT, CurrentCtors);
|
||||
|
||||
// Create the new global variable and replace all uses of
|
||||
// the old global variable with the new one.
|
||||
(void)new GlobalVariable(M, NewInit->getType(), false,
|
||||
GlobalValue::AppendingLinkage, NewInit, Array);
|
||||
}
|
||||
|
||||
void llvm::appendToGlobalCtors(Module &M, Function *F, int Priority) {
|
||||
appendToGlobalArray("llvm.global_ctors", M, F, Priority);
|
||||
}
|
||||
|
||||
void llvm::appendToGlobalDtors(Module &M, Function *F, int Priority) {
|
||||
appendToGlobalArray("llvm.global_dtors", M, F, Priority);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
|
@ -20,31 +20,10 @@
|
|||
#ifndef LDC_LLVMCOMPAT_H
|
||||
#define LDC_LLVMCOMPAT_H
|
||||
|
||||
#include "llvm/ADT/Triple.h"
|
||||
#include <string>
|
||||
|
||||
#if !defined(LDC_LLVM_VER)
|
||||
#error "Please specify value for LDC_LLVM_VER."
|
||||
#endif
|
||||
|
||||
#if LDC_LLVM_VER == 300
|
||||
namespace llvm {
|
||||
class Module;
|
||||
class Function;
|
||||
|
||||
namespace sys {
|
||||
std::string getDefaultTargetTriple();
|
||||
}
|
||||
|
||||
Triple Triple__get32BitArchVariant(const std::string&_this);
|
||||
Triple Triple__get64BitArchVariant(const std::string& _this);
|
||||
|
||||
// From Transforms/Utils/ModuleUtils
|
||||
void appendToGlobalCtors(Module &M, Function *F, int Priority);
|
||||
void appendToGlobalDtors(Module &M, Function *F, int Priority);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if LDC_LLVM_VER >= 302
|
||||
#define ADDRESS_SPACE 0
|
||||
#define HAS_ATTRIBUTES(x) (x).hasAttributes()
|
||||
|
|
|
@ -31,9 +31,7 @@
|
|||
#include "ir/irmodule.h"
|
||||
#include "llvm/MC/MCAsmInfo.h"
|
||||
#include "llvm/Target/TargetMachine.h"
|
||||
#if LDC_LLVM_VER >= 301
|
||||
#include "llvm/Transforms/Utils/ModuleUtils.h"
|
||||
#endif
|
||||
#include <stack>
|
||||
|
||||
/****************************************************************************************/
|
||||
|
@ -1446,13 +1444,7 @@ LLConstant* DtoConstExpInit(Loc loc, Type* type, Expression* exp)
|
|||
assert(tv->basetype->ty == Tsarray);
|
||||
dinteger_t elemCount =
|
||||
static_cast<TypeSArray *>(tv->basetype)->dim->toInteger();
|
||||
|
||||
#if LDC_LLVM_VER == 300
|
||||
std::vector<LLConstant*> Elts(elemCount, val);
|
||||
return llvm::ConstantVector::get(Elts);
|
||||
#else
|
||||
return llvm::ConstantVector::getSplat(elemCount, val);
|
||||
#endif
|
||||
}
|
||||
|
||||
error(loc, "LDC internal error: cannot yet convert default initializer %s of type %s to %s",
|
||||
|
|
|
@ -196,17 +196,11 @@ static void addOptimizationPasses(PassManagerBase &mpm, FunctionPassManager &fpm
|
|||
#endif // USE_METADATA
|
||||
}
|
||||
|
||||
#if LDC_LLVM_VER >= 301
|
||||
// EP_OptimizerLast does not exist in LLVM 3.0, add it manually below.
|
||||
builder.addExtension(PassManagerBuilder::EP_OptimizerLast, addStripExternalsPass);
|
||||
#endif
|
||||
|
||||
builder.populateFunctionPassManager(fpm);
|
||||
builder.populateModulePassManager(mpm);
|
||||
|
||||
#if LDC_LLVM_VER < 301
|
||||
addStripExternalsPass(builder, mpm);
|
||||
#endif
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -16,11 +16,7 @@
|
|||
#define LDC_GEN_OPTIMIZER_H
|
||||
|
||||
// For llvm::CodeGenOpt::Level
|
||||
#if LDC_LLVM_VER == 300
|
||||
#include "llvm/Target/TargetMachine.h"
|
||||
#else
|
||||
#include "llvm/Support/CodeGen.h"
|
||||
#endif
|
||||
|
||||
namespace llvm { class Module; }
|
||||
|
||||
|
|
|
@ -200,11 +200,8 @@ namespace {
|
|||
APInt Mask = APInt::getLowBitsSet(Bits, BitsLimit);
|
||||
Mask.flipAllBits();
|
||||
APInt KnownZero(Bits, 0), KnownOne(Bits, 0);
|
||||
#if LDC_LLVM_VER >= 301
|
||||
ComputeMaskedBits(arrSize, KnownZero, KnownOne, &A.TD);
|
||||
#else
|
||||
ComputeMaskedBits(arrSize, Mask, KnownZero, KnownOne, &A.TD);
|
||||
#endif
|
||||
|
||||
if ((KnownZero & Mask) != Mask)
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -255,7 +255,6 @@ static llvm::DIType dwarfCompositeType(Type* type)
|
|||
|
||||
// set diCompositeType to handle recursive types properly
|
||||
if (!ir->diCompositeType) {
|
||||
#if LDC_LLVM_VER >= 301
|
||||
unsigned tag = (t->ty == Tstruct) ? llvm::dwarf::DW_TAG_structure_type
|
||||
: llvm::dwarf::DW_TAG_class_type;
|
||||
ir->diCompositeType = gIR->dibuilder.createForwardDecl(tag, name,
|
||||
|
@ -263,9 +262,6 @@ static llvm::DIType dwarfCompositeType(Type* type)
|
|||
llvm::DIDescriptor(file),
|
||||
#endif
|
||||
file, linnum);
|
||||
#else
|
||||
ir->diCompositeType = gIR->dibuilder.createTemporaryType();
|
||||
#endif
|
||||
}
|
||||
|
||||
if (!ir->aggrdecl->isInterfaceDeclaration()) // plain interfaces don't have one
|
||||
|
@ -542,9 +538,7 @@ llvm::DISubprogram DtoDwarfSubProgram(FuncDeclaration* fd)
|
|||
DIFnType, // type
|
||||
fd->protection == PROTprivate, // is local to unit
|
||||
gIR->dmodule == getDefinedModule(fd), // isdefinition
|
||||
#if LDC_LLVM_VER >= 301
|
||||
fd->loc.linnum, // FIXME: scope line
|
||||
#endif
|
||||
0, // Flags
|
||||
false, // isOptimized
|
||||
fd->ir.irFunc->func
|
||||
|
@ -583,10 +577,8 @@ llvm::DISubprogram DtoDwarfSubProgramInternal(const char* prettyname, const char
|
|||
0, // line no
|
||||
DIFnType, // return type. TODO: fill it up
|
||||
true, // is local to unit
|
||||
true // isdefinition
|
||||
#if LDC_LLVM_VER >= 301
|
||||
, 0 // FIXME: scope line
|
||||
#endif
|
||||
true, // isdefinition
|
||||
0 // FIXME: scope line
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -673,11 +673,7 @@ LLConstant* DtoConstFP(Type* t, longdouble value)
|
|||
LLConstant* DtoConstString(const char* str)
|
||||
{
|
||||
llvm::StringRef s(str ? str : "");
|
||||
#if LDC_LLVM_VER == 300
|
||||
LLConstant* init = LLConstantArray::get(gIR->context(), s, true);
|
||||
#else
|
||||
LLConstant* init = llvm::ConstantDataArray::getString(gIR->context(), s, true);
|
||||
#endif
|
||||
llvm::GlobalVariable* gvar = new llvm::GlobalVariable(
|
||||
*gIR->module, init->getType(), true, llvm::GlobalValue::InternalLinkage, init, ".str");
|
||||
gvar->setUnnamedAddr(true);
|
||||
|
@ -692,11 +688,7 @@ LLConstant* DtoConstString(const char* str)
|
|||
LLConstant* DtoConstStringPtr(const char* str, const char* section)
|
||||
{
|
||||
llvm::StringRef s(str);
|
||||
#if LDC_LLVM_VER == 300
|
||||
LLConstant* init = LLConstantArray::get(gIR->context(), s, true);
|
||||
#else
|
||||
LLConstant* init = llvm::ConstantDataArray::getString(gIR->context(), s, true);
|
||||
#endif
|
||||
llvm::GlobalVariable* gvar = new llvm::GlobalVariable(
|
||||
*gIR->module, init->getType(), true, llvm::GlobalValue::InternalLinkage, init, ".str");
|
||||
if (section) gvar->setSection(section);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue