mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-04 09:00:33 +03:00
Add changes for LLVM 3.2
- The Attributes class was changed again - TargetData was renamed to DataLayout Compiles again with LLVm 3.0, 3.1 and trunk(3.2).
This commit is contained in:
parent
d523be3010
commit
a7c7b514c0
23 changed files with 267 additions and 29 deletions
|
@ -2,7 +2,11 @@
|
||||||
#include "gen/cl_helpers.h"
|
#include "gen/cl_helpers.h"
|
||||||
|
|
||||||
#include "llvm/Target/TargetMachine.h"
|
#include "llvm/Target/TargetMachine.h"
|
||||||
|
#if LDC_LLVM_VER >= 302
|
||||||
|
#include "llvm/DataLayout.h"
|
||||||
|
#else
|
||||||
#include "llvm/Target/TargetData.h"
|
#include "llvm/Target/TargetData.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "gen/logger.h"
|
#include "gen/logger.h"
|
||||||
|
|
||||||
|
|
|
@ -238,7 +238,11 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
// Handle fixed-up arguments!
|
// Handle fixed-up arguments!
|
||||||
cl::SetVersionPrinter(&printVersion);
|
cl::SetVersionPrinter(&printVersion);
|
||||||
|
#if LDC_LLVM_VER >= 302
|
||||||
|
cl::ParseCommandLineOptions(final_args.size(), const_cast<char**>(&final_args[0]), "LLVM-based D Compiler\n");
|
||||||
|
#else
|
||||||
cl::ParseCommandLineOptions(final_args.size(), const_cast<char**>(&final_args[0]), "LLVM-based D Compiler\n", true);
|
cl::ParseCommandLineOptions(final_args.size(), const_cast<char**>(&final_args[0]), "LLVM-based D Compiler\n", true);
|
||||||
|
#endif
|
||||||
|
|
||||||
// Print config file path if -v was passed
|
// Print config file path if -v was passed
|
||||||
if (global.params.verbose) {
|
if (global.params.verbose) {
|
||||||
|
@ -569,11 +573,15 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
gTargetMachine = target;
|
gTargetMachine = target;
|
||||||
|
|
||||||
gTargetData = target->getTargetData();
|
#if LDC_LLVM_VER >= 302
|
||||||
|
gDataLayout = target->getDataLayout();
|
||||||
|
#else
|
||||||
|
gDataLayout = target->getTargetData();
|
||||||
|
#endif
|
||||||
|
|
||||||
global.params.isLE = gTargetData->isLittleEndian();
|
global.params.isLE = gDataLayout->isLittleEndian();
|
||||||
// Starting with LLVM 3.1 we could also use global.params.targetTriple.isArch64Bit();
|
// Starting with LLVM 3.1 we could also use global.params.targetTriple.isArch64Bit();
|
||||||
global.params.is64bit = gTargetData->getPointerSizeInBits() == 64;
|
global.params.is64bit = gDataLayout->getPointerSizeInBits() == 64;
|
||||||
global.params.cpu = static_cast<ARCH>(global.params.targetTriple.getArch());
|
global.params.cpu = static_cast<ARCH>(global.params.targetTriple.getArch());
|
||||||
global.params.os = static_cast<OS>(global.params.targetTriple.getOS());
|
global.params.os = static_cast<OS>(global.params.targetTriple.getOS());
|
||||||
|
|
||||||
|
|
|
@ -121,10 +121,17 @@ void emit_file(llvm::TargetMachine &Target, llvm::Module& m, llvm::raw_fd_ostrea
|
||||||
// Build up all of the passes that we want to do to the module.
|
// Build up all of the passes that we want to do to the module.
|
||||||
FunctionPassManager Passes(&m);
|
FunctionPassManager Passes(&m);
|
||||||
|
|
||||||
|
#if LDC_LLVM_VER >= 302
|
||||||
|
if (const DataLayout *DL = Target.getDataLayout())
|
||||||
|
Passes.add(new DataLayout(*DL));
|
||||||
|
else
|
||||||
|
Passes.add(new DataLayout(&m));
|
||||||
|
#else
|
||||||
if (const TargetData *TD = Target.getTargetData())
|
if (const TargetData *TD = Target.getTargetData())
|
||||||
Passes.add(new TargetData(*TD));
|
Passes.add(new TargetData(*TD));
|
||||||
else
|
else
|
||||||
Passes.add(new TargetData(&m));
|
Passes.add(new TargetData(&m));
|
||||||
|
#endif
|
||||||
|
|
||||||
llvm::formatted_raw_ostream fout(out);
|
llvm::formatted_raw_ostream fout(out);
|
||||||
if (Target.addPassesToEmitFile(Passes, fout, fileType, codeGenOptLevel()))
|
if (Target.addPassesToEmitFile(Passes, fout, fileType, codeGenOptLevel()))
|
||||||
|
|
|
@ -526,13 +526,21 @@ void X86_64TargetABI::rewriteFunctionType(TypeFunction* tf) {
|
||||||
if (fty.arg_this)
|
if (fty.arg_this)
|
||||||
{
|
{
|
||||||
Logger::println("Putting 'this' in register");
|
Logger::println("Putting 'this' in register");
|
||||||
|
#if LDC_LLVM_VER >= 302
|
||||||
|
fty.arg_this->attrs = llvm::Attributes::get(llvm::Attributes::Builder().addAttribute(llvm::Attributes::InReg));
|
||||||
|
#else
|
||||||
fty.arg_this->attrs = llvm::Attribute::InReg;
|
fty.arg_this->attrs = llvm::Attribute::InReg;
|
||||||
|
#endif
|
||||||
--regcount;
|
--regcount;
|
||||||
}
|
}
|
||||||
else if (fty.arg_nest)
|
else if (fty.arg_nest)
|
||||||
{
|
{
|
||||||
Logger::println("Putting context ptr in register");
|
Logger::println("Putting context ptr in register");
|
||||||
|
#if LDC_LLVM_VER >= 302
|
||||||
|
fty.arg_nest->attrs = llvm::Attributes::get(llvm::Attributes::Builder().addAttribute(llvm::Attributes::InReg));
|
||||||
|
#else
|
||||||
fty.arg_nest->attrs = llvm::Attribute::InReg;
|
fty.arg_nest->attrs = llvm::Attribute::InReg;
|
||||||
|
#endif
|
||||||
--regcount;
|
--regcount;
|
||||||
}
|
}
|
||||||
else if (IrFuncTyArg* sret = fty.arg_sret)
|
else if (IrFuncTyArg* sret = fty.arg_sret)
|
||||||
|
@ -540,8 +548,13 @@ void X86_64TargetABI::rewriteFunctionType(TypeFunction* tf) {
|
||||||
Logger::println("Putting sret ptr in register");
|
Logger::println("Putting sret ptr in register");
|
||||||
// sret and inreg are incompatible, but the ABI requires the
|
// sret and inreg are incompatible, but the ABI requires the
|
||||||
// sret parameter to be in RDI in this situation...
|
// sret parameter to be in RDI in this situation...
|
||||||
|
#if LDC_LLVM_VER >= 302
|
||||||
|
sret->attrs = llvm::Attributes::get(llvm::Attributes::Builder(sret->attrs).addAttribute(llvm::Attributes::InReg)
|
||||||
|
.removeAttribute(llvm::Attributes::StructRet));
|
||||||
|
#else
|
||||||
sret->attrs = (sret->attrs | llvm::Attribute::InReg)
|
sret->attrs = (sret->attrs | llvm::Attribute::InReg)
|
||||||
& ~llvm::Attribute::StructRet;
|
& ~llvm::Attribute::StructRet;
|
||||||
|
#endif
|
||||||
--regcount;
|
--regcount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -558,7 +571,11 @@ void X86_64TargetABI::rewriteFunctionType(TypeFunction* tf) {
|
||||||
{
|
{
|
||||||
if (xmmcount > 0) {
|
if (xmmcount > 0) {
|
||||||
Logger::println("Putting float parameter in register");
|
Logger::println("Putting float parameter in register");
|
||||||
|
#if LDC_LLVM_VER >= 302
|
||||||
|
arg.attrs = llvm::Attributes::get(llvm::Attributes::Builder(arg.attrs).addAttribute(llvm::Attributes::InReg));
|
||||||
|
#else
|
||||||
arg.attrs |= llvm::Attribute::InReg;
|
arg.attrs |= llvm::Attribute::InReg;
|
||||||
|
#endif
|
||||||
--xmmcount;
|
--xmmcount;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -569,19 +586,31 @@ void X86_64TargetABI::rewriteFunctionType(TypeFunction* tf) {
|
||||||
else if (arg.byref && !arg.isByVal())
|
else if (arg.byref && !arg.isByVal())
|
||||||
{
|
{
|
||||||
Logger::println("Putting byref parameter in register");
|
Logger::println("Putting byref parameter in register");
|
||||||
|
#if LDC_LLVM_VER >= 302
|
||||||
|
arg.attrs = llvm::Attributes::get(llvm::Attributes::Builder(arg.attrs).addAttribute(llvm::Attributes::InReg));
|
||||||
|
#else
|
||||||
arg.attrs |= llvm::Attribute::InReg;
|
arg.attrs |= llvm::Attribute::InReg;
|
||||||
|
#endif
|
||||||
--regcount;
|
--regcount;
|
||||||
}
|
}
|
||||||
else if (ty->ty == Tpointer)
|
else if (ty->ty == Tpointer)
|
||||||
{
|
{
|
||||||
Logger::println("Putting pointer parameter in register");
|
Logger::println("Putting pointer parameter in register");
|
||||||
|
#if LDC_LLVM_VER >= 302
|
||||||
|
arg.attrs = llvm::Attributes::get(llvm::Attributes::Builder(arg.attrs).addAttribute(llvm::Attributes::InReg));
|
||||||
|
#else
|
||||||
arg.attrs |= llvm::Attribute::InReg;
|
arg.attrs |= llvm::Attribute::InReg;
|
||||||
|
#endif
|
||||||
--regcount;
|
--regcount;
|
||||||
}
|
}
|
||||||
else if (ty->isintegral() && sz <= 8)
|
else if (ty->isintegral() && sz <= 8)
|
||||||
{
|
{
|
||||||
Logger::println("Putting integral parameter in register");
|
Logger::println("Putting integral parameter in register");
|
||||||
|
#if LDC_LLVM_VER >= 302
|
||||||
|
arg.attrs = llvm::Attributes::get(llvm::Attributes::Builder(arg.attrs).addAttribute(llvm::Attributes::InReg));
|
||||||
|
#else
|
||||||
arg.attrs |= llvm::Attribute::InReg;
|
arg.attrs |= llvm::Attribute::InReg;
|
||||||
|
#endif
|
||||||
--regcount;
|
--regcount;
|
||||||
}
|
}
|
||||||
else if ((ty->ty == Tstruct || ty->ty == Tsarray) &&
|
else if ((ty->ty == Tstruct || ty->ty == Tsarray) &&
|
||||||
|
@ -591,7 +620,11 @@ void X86_64TargetABI::rewriteFunctionType(TypeFunction* tf) {
|
||||||
arg.rewrite = &compositeToInt;
|
arg.rewrite = &compositeToInt;
|
||||||
arg.ltype = compositeToInt.type(arg.type, arg.ltype);
|
arg.ltype = compositeToInt.type(arg.type, arg.ltype);
|
||||||
arg.byref = false;
|
arg.byref = false;
|
||||||
|
#if LDC_LLVM_VER >= 302
|
||||||
|
arg.attrs = llvm::Attributes::get(llvm::Attributes::Builder().addAttribute(llvm::Attributes::InReg));
|
||||||
|
#else
|
||||||
arg.attrs = llvm::Attribute::InReg;
|
arg.attrs = llvm::Attribute::InReg;
|
||||||
|
#endif
|
||||||
--regcount;
|
--regcount;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -115,20 +115,33 @@ struct X86TargetABI : TargetABI
|
||||||
if (fty.arg_this)
|
if (fty.arg_this)
|
||||||
{
|
{
|
||||||
Logger::println("Putting 'this' in register");
|
Logger::println("Putting 'this' in register");
|
||||||
|
#if LDC_LLVM_VER >= 302
|
||||||
|
fty.arg_this->attrs = llvm::Attributes::get(llvm::Attributes::Builder().addAttribute(llvm::Attributes::InReg));
|
||||||
|
#else
|
||||||
fty.arg_this->attrs = llvm::Attribute::InReg;
|
fty.arg_this->attrs = llvm::Attribute::InReg;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
else if (fty.arg_nest)
|
else if (fty.arg_nest)
|
||||||
{
|
{
|
||||||
Logger::println("Putting context ptr in register");
|
Logger::println("Putting context ptr in register");
|
||||||
|
#if LDC_LLVM_VER >= 302
|
||||||
|
fty.arg_nest->attrs = llvm::Attributes::get(llvm::Attributes::Builder().addAttribute(llvm::Attributes::InReg));
|
||||||
|
#else
|
||||||
fty.arg_nest->attrs = llvm::Attribute::InReg;
|
fty.arg_nest->attrs = llvm::Attribute::InReg;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
else if (IrFuncTyArg* sret = fty.arg_sret)
|
else if (IrFuncTyArg* sret = fty.arg_sret)
|
||||||
{
|
{
|
||||||
Logger::println("Putting sret ptr in register");
|
Logger::println("Putting sret ptr in register");
|
||||||
// sret and inreg are incompatible, but the ABI requires the
|
// sret and inreg are incompatible, but the ABI requires the
|
||||||
// sret parameter to be in EAX in this situation...
|
// sret parameter to be in EAX in this situation...
|
||||||
|
#if LDC_LLVM_VER >= 302
|
||||||
|
sret->attrs = llvm::Attributes::get(llvm::Attributes::Builder(sret->attrs).addAttribute(llvm::Attributes::InReg)
|
||||||
|
.removeAttribute(llvm::Attributes::StructRet));
|
||||||
|
#else
|
||||||
sret->attrs = (sret->attrs | llvm::Attribute::InReg)
|
sret->attrs = (sret->attrs | llvm::Attribute::InReg)
|
||||||
& ~llvm::Attribute::StructRet;
|
& ~llvm::Attribute::StructRet;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
// otherwise try to mark the last param inreg
|
// otherwise try to mark the last param inreg
|
||||||
else if (!fty.args.empty())
|
else if (!fty.args.empty())
|
||||||
|
@ -145,7 +158,11 @@ struct X86TargetABI : TargetABI
|
||||||
if (last->byref && !last->isByVal())
|
if (last->byref && !last->isByVal())
|
||||||
{
|
{
|
||||||
Logger::println("Putting last (byref) parameter in register");
|
Logger::println("Putting last (byref) parameter in register");
|
||||||
|
#if LDC_LLVM_VER >= 302
|
||||||
|
last->attrs = llvm::Attributes::get(llvm::Attributes::Builder(last->attrs).addAttribute(llvm::Attributes::InReg));
|
||||||
|
#else
|
||||||
last->attrs |= llvm::Attribute::InReg;
|
last->attrs |= llvm::Attribute::InReg;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
else if (!lastTy->isfloating() && (sz == 1 || sz == 2 || sz == 4)) // right?
|
else if (!lastTy->isfloating() && (sz == 1 || sz == 2 || sz == 4)) // right?
|
||||||
{
|
{
|
||||||
|
@ -156,9 +173,17 @@ struct X86TargetABI : TargetABI
|
||||||
last->ltype = compositeToInt.type(last->type, last->ltype);
|
last->ltype = compositeToInt.type(last->type, last->ltype);
|
||||||
last->byref = false;
|
last->byref = false;
|
||||||
// erase previous attributes
|
// erase previous attributes
|
||||||
|
#if LDC_LLVM_VER >= 302
|
||||||
|
last->attrs = llvm::Attributes();
|
||||||
|
#else
|
||||||
last->attrs = llvm::Attribute::None;
|
last->attrs = llvm::Attribute::None;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
#if LDC_LLVM_VER >= 302
|
||||||
|
last->attrs = llvm::Attributes::get(llvm::Attributes::Builder(last->attrs).addAttribute(llvm::Attributes::InReg));
|
||||||
|
#else
|
||||||
last->attrs |= llvm::Attribute::InReg;
|
last->attrs |= llvm::Attribute::InReg;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -558,7 +558,7 @@ static LLConstant* build_offti_entry(ClassDeclaration* cd, VarDeclaration* vd)
|
||||||
//
|
//
|
||||||
assert(vd->ir.irField);
|
assert(vd->ir.irField);
|
||||||
// grab the offset from llvm and the formal class type
|
// grab the offset from llvm and the formal class type
|
||||||
size_t offset = gTargetData->getStructLayout(isaStruct(cd->type->ir.type->get()))->getElementOffset(vd->ir.irField->index);
|
size_t offset = gDataLayout->getStructLayout(isaStruct(cd->type->ir.type->get()))->getElementOffset(vd->ir.irField->index);
|
||||||
// offset nested struct/union fields
|
// offset nested struct/union fields
|
||||||
offset += vd->ir.irField->unionOffset;
|
offset += vd->ir.irField->unionOffset;
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,9 @@
|
||||||
#include "gen/nested.h"
|
#include "gen/nested.h"
|
||||||
#include "gen/pragma.h"
|
#include "gen/pragma.h"
|
||||||
|
|
||||||
|
#if LDC_LLVM_VER < 302
|
||||||
using namespace llvm::Attribute;
|
using namespace llvm::Attribute;
|
||||||
|
#endif
|
||||||
|
|
||||||
llvm::FunctionType* DtoFunctionType(Type* type, Type* thistype, Type* nesttype, bool ismain)
|
llvm::FunctionType* DtoFunctionType(Type* type, Type* thistype, Type* nesttype, bool ismain)
|
||||||
{
|
{
|
||||||
|
@ -57,12 +59,22 @@ llvm::FunctionType* DtoFunctionType(Type* type, Type* thistype, Type* nesttype,
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Type* rt = f->next;
|
Type* rt = f->next;
|
||||||
|
#if LDC_LLVM_VER >= 302
|
||||||
|
llvm::Attributes a;
|
||||||
|
#else
|
||||||
llvm::Attributes a = None;
|
llvm::Attributes a = None;
|
||||||
|
#endif
|
||||||
|
|
||||||
// sret return
|
// sret return
|
||||||
if (abi->returnInArg(f))
|
if (abi->returnInArg(f))
|
||||||
{
|
{
|
||||||
|
#if LDC_LLVM_VER >= 302
|
||||||
|
fty.arg_sret = new IrFuncTyArg(rt, true, llvm::Attributes::get(llvm::Attributes::Builder().addAttribute(llvm::Attributes::StructRet)
|
||||||
|
.addAttribute(llvm::Attributes::NoAlias)
|
||||||
|
.addAttribute(llvm::Attributes::NoCapture)));
|
||||||
|
#else
|
||||||
fty.arg_sret = new IrFuncTyArg(rt, true, StructRet | NoAlias | NoCapture);
|
fty.arg_sret = new IrFuncTyArg(rt, true, StructRet | NoAlias | NoCapture);
|
||||||
|
#endif
|
||||||
rt = Type::tvoid;
|
rt = Type::tvoid;
|
||||||
lidx++;
|
lidx++;
|
||||||
}
|
}
|
||||||
|
@ -112,7 +124,13 @@ llvm::FunctionType* DtoFunctionType(Type* type, Type* thistype, Type* nesttype,
|
||||||
fty.arg_arguments = new IrFuncTyArg(Type::typeinfo->type->arrayOf(), false);
|
fty.arg_arguments = new IrFuncTyArg(Type::typeinfo->type->arrayOf(), false);
|
||||||
lidx++;
|
lidx++;
|
||||||
// _argptr
|
// _argptr
|
||||||
|
#if LDC_LLVM_VER >= 302
|
||||||
|
fty.arg_argptr = new IrFuncTyArg(Type::tvoid->pointerTo(), false,
|
||||||
|
llvm::Attributes::get(llvm::Attributes::Builder().addAttribute(llvm::Attributes::NoAlias)
|
||||||
|
.addAttribute(llvm::Attributes::NoCapture)));
|
||||||
|
#else
|
||||||
fty.arg_argptr = new IrFuncTyArg(Type::tvoid->pointerTo(), false, NoAlias | NoCapture);
|
fty.arg_argptr = new IrFuncTyArg(Type::tvoid->pointerTo(), false, NoAlias | NoCapture);
|
||||||
|
#endif
|
||||||
lidx++;
|
lidx++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -146,7 +164,11 @@ llvm::FunctionType* DtoFunctionType(Type* type, Type* thistype, Type* nesttype,
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Type* argtype = arg->type;
|
Type* argtype = arg->type;
|
||||||
|
#if LDC_LLVM_VER >= 302
|
||||||
|
llvm::Attributes a;
|
||||||
|
#else
|
||||||
llvm::Attributes a = None;
|
llvm::Attributes a = None;
|
||||||
|
#endif
|
||||||
|
|
||||||
// handle lazy args
|
// handle lazy args
|
||||||
if (arg->storageClass & STClazy)
|
if (arg->storageClass & STClazy)
|
||||||
|
@ -159,7 +181,11 @@ llvm::FunctionType* DtoFunctionType(Type* type, Type* thistype, Type* nesttype,
|
||||||
// byval
|
// byval
|
||||||
else if (abi->passByVal(byref ? argtype->pointerTo() : argtype))
|
else if (abi->passByVal(byref ? argtype->pointerTo() : argtype))
|
||||||
{
|
{
|
||||||
|
#if LDC_LLVM_VER >= 302
|
||||||
|
if (!byref) a = llvm::Attributes::get(llvm::Attributes::Builder(a).addAttribute(llvm::Attributes::ByVal));
|
||||||
|
#else
|
||||||
if (!byref) a |= llvm::Attribute::ByVal;
|
if (!byref) a |= llvm::Attribute::ByVal;
|
||||||
|
#endif
|
||||||
// set byref, because byval requires a pointed LLVM type
|
// set byref, because byval requires a pointed LLVM type
|
||||||
byref = true;
|
byref = true;
|
||||||
}
|
}
|
||||||
|
@ -409,7 +435,11 @@ static void set_param_attrs(TypeFunction* f, llvm::Function* func, FuncDeclarati
|
||||||
|
|
||||||
// set attrs on the rest of the arguments
|
// set attrs on the rest of the arguments
|
||||||
size_t n = Parameter::dim(f->parameters);
|
size_t n = Parameter::dim(f->parameters);
|
||||||
|
#if LDC_LLVM_VER >= 302
|
||||||
|
LLSmallVector<llvm::Attributes, 8> attrptr(n, llvm::Attributes());
|
||||||
|
#else
|
||||||
LLSmallVector<llvm::Attributes, 8> attrptr(n, None);
|
LLSmallVector<llvm::Attributes, 8> attrptr(n, None);
|
||||||
|
#endif
|
||||||
|
|
||||||
for (size_t k = 0; k < n; ++k)
|
for (size_t k = 0; k < n; ++k)
|
||||||
{
|
{
|
||||||
|
@ -513,7 +543,11 @@ void DtoDeclareFunction(FuncDeclaration* fdecl)
|
||||||
if (!fdecl->isIntrinsic()) {
|
if (!fdecl->isIntrinsic()) {
|
||||||
set_param_attrs(f, func, fdecl);
|
set_param_attrs(f, func, fdecl);
|
||||||
if (global.params.disableRedZone) {
|
if (global.params.disableRedZone) {
|
||||||
|
#if LDC_LLVM_VER >= 302
|
||||||
|
func->addFnAttr(llvm::Attributes::NoRedZone);
|
||||||
|
#else
|
||||||
func->addFnAttr(NoRedZone);
|
func->addFnAttr(NoRedZone);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,11 @@
|
||||||
|
|
||||||
IRState* gIR = 0;
|
IRState* gIR = 0;
|
||||||
llvm::TargetMachine* gTargetMachine = 0;
|
llvm::TargetMachine* gTargetMachine = 0;
|
||||||
const llvm::TargetData* gTargetData = 0;
|
#if LDC_LLVM_VER >= 302
|
||||||
|
const llvm::DataLayout* gDataLayout = 0;
|
||||||
|
#else
|
||||||
|
const llvm::TargetData* gDataLayout = 0;
|
||||||
|
#endif
|
||||||
TargetABI* gABI = 0;
|
TargetABI* gABI = 0;
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -31,7 +31,11 @@ struct TargetABI;
|
||||||
|
|
||||||
extern IRState* gIR;
|
extern IRState* gIR;
|
||||||
extern llvm::TargetMachine* gTargetMachine;
|
extern llvm::TargetMachine* gTargetMachine;
|
||||||
extern const llvm::TargetData* gTargetData;
|
#if LDC_LLVM_VER >= 302
|
||||||
|
extern const llvm::DataLayout* gDataLayout;
|
||||||
|
#else
|
||||||
|
extern const llvm::TargetData* gDataLayout;
|
||||||
|
#endif
|
||||||
extern TargetABI* gABI;
|
extern TargetABI* gABI;
|
||||||
|
|
||||||
struct TypeFunction;
|
struct TypeFunction;
|
||||||
|
|
|
@ -12,12 +12,12 @@
|
||||||
#include "llvm/Value.h"
|
#include "llvm/Value.h"
|
||||||
#include "llvm/Attributes.h"
|
#include "llvm/Attributes.h"
|
||||||
|
|
||||||
#include "llvm/Target/TargetData.h"
|
|
||||||
|
|
||||||
#if LDC_LLVM_VER >= 302
|
#if LDC_LLVM_VER >= 302
|
||||||
|
#include "llvm/DataLayout.h"
|
||||||
#include "llvm/DebugInfo.h"
|
#include "llvm/DebugInfo.h"
|
||||||
#include "llvm/IRBuilder.h"
|
#include "llvm/IRBuilder.h"
|
||||||
#else
|
#else
|
||||||
|
#include "llvm/Target/TargetData.h"
|
||||||
#include "llvm/Analysis/DebugInfo.h"
|
#include "llvm/Analysis/DebugInfo.h"
|
||||||
#include "llvm/Support/IRBuilder.h"
|
#include "llvm/Support/IRBuilder.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1114,7 +1114,7 @@ void DtoVarDeclaration(VarDeclaration* vd)
|
||||||
LLType* lltype = DtoType(type);
|
LLType* lltype = DtoType(type);
|
||||||
|
|
||||||
llvm::Value* allocainst;
|
llvm::Value* allocainst;
|
||||||
if(gTargetData->getTypeSizeInBits(lltype) == 0)
|
if(gDataLayout->getTypeSizeInBits(lltype) == 0)
|
||||||
allocainst = llvm::ConstantPointerNull::get(getPtrToType(lltype));
|
allocainst = llvm::ConstantPointerNull::get(getPtrToType(lltype));
|
||||||
else
|
else
|
||||||
allocainst = DtoAlloca(type, vd->toChars());
|
allocainst = DtoAlloca(type, vd->toChars());
|
||||||
|
@ -1595,7 +1595,7 @@ void DtoOverloadedIntrinsicName(TemplateInstance* ti, TemplateDeclaration* td, s
|
||||||
}
|
}
|
||||||
|
|
||||||
char tmp[21]; // probably excessive, but covers a uint64_t
|
char tmp[21]; // probably excessive, but covers a uint64_t
|
||||||
sprintf(tmp, "%lu", static_cast<unsigned long>(gTargetData->getTypeSizeInBits(DtoType(T))));
|
sprintf(tmp, "%lu", static_cast<unsigned long>(gDataLayout->getTypeSizeInBits(DtoType(T))));
|
||||||
|
|
||||||
// replace # in name with bitsize
|
// replace # in name with bitsize
|
||||||
name = td->intrinsicName;
|
name = td->intrinsicName;
|
||||||
|
@ -1770,7 +1770,7 @@ size_t realignOffset(size_t offset, Type* type)
|
||||||
}
|
}
|
||||||
|
|
||||||
// then we check against the llvm alignment
|
// then we check against the llvm alignment
|
||||||
size_t alignsize2 = gTargetData->getABITypeAlignment(T);
|
size_t alignsize2 = gDataLayout->getABITypeAlignment(T);
|
||||||
|
|
||||||
// if it differs we need to insert manual padding as well
|
// if it differs we need to insert manual padding as well
|
||||||
if (alignsize != alignsize2)
|
if (alignsize != alignsize2)
|
||||||
|
|
|
@ -2,7 +2,11 @@
|
||||||
#include "llvm/Analysis/Verifier.h"
|
#include "llvm/Analysis/Verifier.h"
|
||||||
#include "llvm/Module.h"
|
#include "llvm/Module.h"
|
||||||
#include "llvm/LinkAllPasses.h"
|
#include "llvm/LinkAllPasses.h"
|
||||||
|
#if LDC_LLVM_VER >= 302
|
||||||
|
#include "llvm/DataLayout.h"
|
||||||
|
#else
|
||||||
#include "llvm/Target/TargetData.h"
|
#include "llvm/Target/TargetData.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "mars.h"
|
#include "mars.h"
|
||||||
#include "module.h"
|
#include "module.h"
|
||||||
|
@ -245,7 +249,7 @@ llvm::Module* Module::genLLVMModule(llvm::LLVMContext& context, Ir* sir)
|
||||||
ir.module->setTargetTriple(global.params.targetTriple.str());
|
ir.module->setTargetTriple(global.params.targetTriple.str());
|
||||||
|
|
||||||
// set final data layout
|
// set final data layout
|
||||||
ir.module->setDataLayout(gTargetData->getStringRepresentation());
|
ir.module->setDataLayout(gDataLayout->getStringRepresentation());
|
||||||
if (Logger::enabled())
|
if (Logger::enabled())
|
||||||
Logger::cout() << "Final data layout: " << ir.module->getDataLayout() << '\n';
|
Logger::cout() << "Final data layout: " << ir.module->getDataLayout() << '\n';
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,11 @@
|
||||||
#include "llvm/LinkAllPasses.h"
|
#include "llvm/LinkAllPasses.h"
|
||||||
#include "llvm/Analysis/LoopPass.h"
|
#include "llvm/Analysis/LoopPass.h"
|
||||||
#include "llvm/Analysis/Verifier.h"
|
#include "llvm/Analysis/Verifier.h"
|
||||||
|
#if LDC_LLVM_VER >= 302
|
||||||
|
#include "llvm/DataLayout.h"
|
||||||
|
#else
|
||||||
#include "llvm/Target/TargetData.h"
|
#include "llvm/Target/TargetData.h"
|
||||||
|
#endif
|
||||||
#include "llvm/Support/CommandLine.h"
|
#include "llvm/Support/CommandLine.h"
|
||||||
#include "llvm/Support/PassNameParser.h"
|
#include "llvm/Support/PassNameParser.h"
|
||||||
#include "llvm/Transforms/IPO.h"
|
#include "llvm/Transforms/IPO.h"
|
||||||
|
@ -274,7 +278,11 @@ bool ldc_optimize_module(llvm::Module* m)
|
||||||
|
|
||||||
if (verifyEach) pm.add(createVerifierPass());
|
if (verifyEach) pm.add(createVerifierPass());
|
||||||
|
|
||||||
|
#if LDC_LLVM_VER >= 302
|
||||||
|
addPass(pm, new DataLayout(m));
|
||||||
|
#else
|
||||||
addPass(pm, new TargetData(m));
|
addPass(pm, new TargetData(m));
|
||||||
|
#endif
|
||||||
|
|
||||||
bool optimize = optimizeLevel != 0 || doInline();
|
bool optimize = optimizeLevel != 0 || doInline();
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,11 @@
|
||||||
#endif
|
#endif
|
||||||
#include "llvm/Analysis/AliasAnalysis.h"
|
#include "llvm/Analysis/AliasAnalysis.h"
|
||||||
#include "llvm/Analysis/ValueTracking.h"
|
#include "llvm/Analysis/ValueTracking.h"
|
||||||
|
#if LDC_LLVM_VER >= 302
|
||||||
|
#include "llvm/DataLayout.h"
|
||||||
|
#else
|
||||||
#include "llvm/Target/TargetData.h"
|
#include "llvm/Target/TargetData.h"
|
||||||
|
#endif
|
||||||
#include "llvm/ADT/StringMap.h"
|
#include "llvm/ADT/StringMap.h"
|
||||||
#include "llvm/ADT/Statistic.h"
|
#include "llvm/ADT/Statistic.h"
|
||||||
#include "llvm/Support/Compiler.h"
|
#include "llvm/Support/Compiler.h"
|
||||||
|
@ -52,7 +56,11 @@ namespace {
|
||||||
protected:
|
protected:
|
||||||
Function *Caller;
|
Function *Caller;
|
||||||
bool* Changed;
|
bool* Changed;
|
||||||
|
#if LDC_LLVM_VER >= 302
|
||||||
|
const DataLayout *TD;
|
||||||
|
#else
|
||||||
const TargetData *TD;
|
const TargetData *TD;
|
||||||
|
#endif
|
||||||
AliasAnalysis *AA;
|
AliasAnalysis *AA;
|
||||||
LLVMContext *Context;
|
LLVMContext *Context;
|
||||||
|
|
||||||
|
@ -74,8 +82,13 @@ namespace {
|
||||||
/// delete CI.
|
/// delete CI.
|
||||||
virtual Value *CallOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B)=0;
|
virtual Value *CallOptimizer(Function *Callee, CallInst *CI, IRBuilder<> &B)=0;
|
||||||
|
|
||||||
|
#if LDC_LLVM_VER >= 302
|
||||||
|
Value *OptimizeCall(CallInst *CI, bool& Changed, const DataLayout &TD,
|
||||||
|
AliasAnalysis& AA, IRBuilder<> &B) {
|
||||||
|
#else
|
||||||
Value *OptimizeCall(CallInst *CI, bool& Changed, const TargetData &TD,
|
Value *OptimizeCall(CallInst *CI, bool& Changed, const TargetData &TD,
|
||||||
AliasAnalysis& AA, IRBuilder<> &B) {
|
AliasAnalysis& AA, IRBuilder<> &B) {
|
||||||
|
#endif
|
||||||
Caller = CI->getParent()->getParent();
|
Caller = CI->getParent()->getParent();
|
||||||
this->Changed = &Changed;
|
this->Changed = &Changed;
|
||||||
this->TD = &TD;
|
this->TD = &TD;
|
||||||
|
@ -101,7 +114,7 @@ Value *LibCallOptimization::EmitMemCpy(Value *Dst, Value *Src, Value *Len,
|
||||||
Type *VoidPtrTy = PointerType::getUnqual(B.getInt8Ty());
|
Type *VoidPtrTy = PointerType::getUnqual(B.getInt8Ty());
|
||||||
Type *Tys[3] ={VoidPtrTy, VoidPtrTy, intTy};
|
Type *Tys[3] ={VoidPtrTy, VoidPtrTy, intTy};
|
||||||
Value *MemCpy = Intrinsic::getDeclaration(M, Intrinsic::memcpy, llvm::makeArrayRef(Tys, 3));
|
Value *MemCpy = Intrinsic::getDeclaration(M, Intrinsic::memcpy, llvm::makeArrayRef(Tys, 3));
|
||||||
|
|
||||||
return B.CreateCall5(MemCpy, CastToCStr(Dst, B), CastToCStr(Src, B), Len,
|
return B.CreateCall5(MemCpy, CastToCStr(Dst, B), CastToCStr(Src, B), Len,
|
||||||
ConstantInt::get(B.getInt32Ty(), Align), B.getFalse());
|
ConstantInt::get(B.getInt32Ty(), Align), B.getFalse());
|
||||||
}
|
}
|
||||||
|
@ -296,10 +309,18 @@ namespace {
|
||||||
void InitOptimizations();
|
void InitOptimizations();
|
||||||
bool runOnFunction(Function &F);
|
bool runOnFunction(Function &F);
|
||||||
|
|
||||||
|
#if LDC_LLVM_VER >= 302
|
||||||
|
bool runOnce(Function &F, const DataLayout& DL, AliasAnalysis& AA);
|
||||||
|
#else
|
||||||
bool runOnce(Function &F, const TargetData& TD, AliasAnalysis& AA);
|
bool runOnce(Function &F, const TargetData& TD, AliasAnalysis& AA);
|
||||||
|
#endif
|
||||||
|
|
||||||
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
|
virtual void getAnalysisUsage(AnalysisUsage &AU) const {
|
||||||
|
#if LDC_LLVM_VER >= 302
|
||||||
|
AU.addRequired<DataLayout>();
|
||||||
|
#else
|
||||||
AU.addRequired<TargetData>();
|
AU.addRequired<TargetData>();
|
||||||
|
#endif
|
||||||
AU.addRequired<AliasAnalysis>();
|
AU.addRequired<AliasAnalysis>();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -349,7 +370,11 @@ bool SimplifyDRuntimeCalls::runOnFunction(Function &F) {
|
||||||
if (Optimizations.empty())
|
if (Optimizations.empty())
|
||||||
InitOptimizations();
|
InitOptimizations();
|
||||||
|
|
||||||
|
#if LDC_LLVM_VER >= 302
|
||||||
|
const DataLayout &TD = getAnalysis<DataLayout>();
|
||||||
|
#else
|
||||||
const TargetData &TD = getAnalysis<TargetData>();
|
const TargetData &TD = getAnalysis<TargetData>();
|
||||||
|
#endif
|
||||||
AliasAnalysis &AA = getAnalysis<AliasAnalysis>();
|
AliasAnalysis &AA = getAnalysis<AliasAnalysis>();
|
||||||
|
|
||||||
// Iterate to catch opportunities opened up by other optimizations,
|
// Iterate to catch opportunities opened up by other optimizations,
|
||||||
|
@ -367,7 +392,11 @@ bool SimplifyDRuntimeCalls::runOnFunction(Function &F) {
|
||||||
return EverChanged;
|
return EverChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if LDC_LLVM_VER >= 302
|
||||||
|
bool SimplifyDRuntimeCalls::runOnce(Function &F, const DataLayout& TD, AliasAnalysis& AA) {
|
||||||
|
#else
|
||||||
bool SimplifyDRuntimeCalls::runOnce(Function &F, const TargetData& TD, AliasAnalysis& AA) {
|
bool SimplifyDRuntimeCalls::runOnce(Function &F, const TargetData& TD, AliasAnalysis& AA) {
|
||||||
|
#endif
|
||||||
IRBuilder<> Builder(F.getContext());
|
IRBuilder<> Builder(F.getContext());
|
||||||
|
|
||||||
bool Changed = false;
|
bool Changed = false;
|
||||||
|
|
|
@ -19,7 +19,9 @@
|
||||||
#include "gen/irstate.h"
|
#include "gen/irstate.h"
|
||||||
#include "ir/irtype.h"
|
#include "ir/irtype.h"
|
||||||
|
|
||||||
|
#if LDC_LLVM_VER < 302
|
||||||
using namespace llvm::Attribute;
|
using namespace llvm::Attribute;
|
||||||
|
#endif
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
@ -217,6 +219,40 @@ static void LLVM_D_BuildRuntimeModule()
|
||||||
/////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
// Construct some attribute lists used below (possibly multiple times)
|
// Construct some attribute lists used below (possibly multiple times)
|
||||||
|
#if LDC_LLVM_VER >= 302
|
||||||
|
llvm::AttrListPtr
|
||||||
|
NoAttrs,
|
||||||
|
Attr_NoAlias
|
||||||
|
= NoAttrs.addAttr(0, llvm::Attributes::get(llvm::Attributes::Builder().addAttribute(llvm::Attributes::NoAlias))),
|
||||||
|
Attr_NoUnwind
|
||||||
|
= NoAttrs.addAttr(~0U, llvm::Attributes::get(llvm::Attributes::Builder().addAttribute(llvm::Attributes::NoUnwind))),
|
||||||
|
Attr_ReadOnly
|
||||||
|
= NoAttrs.addAttr(~0U, llvm::Attributes::get(llvm::Attributes::Builder().addAttribute(llvm::Attributes::ReadOnly))),
|
||||||
|
Attr_ReadOnly_NoUnwind
|
||||||
|
= Attr_ReadOnly.addAttr(~0U, llvm::Attributes::get(llvm::Attributes::Builder().addAttribute(llvm::Attributes::NoUnwind))),
|
||||||
|
Attr_ReadOnly_1_NoCapture
|
||||||
|
= Attr_ReadOnly.addAttr(1, llvm::Attributes::get(llvm::Attributes::Builder().addAttribute(llvm::Attributes::NoCapture))),
|
||||||
|
Attr_ReadOnly_1_3_NoCapture
|
||||||
|
= Attr_ReadOnly_1_NoCapture.addAttr(3, llvm::Attributes::get(llvm::Attributes::Builder().addAttribute(llvm::Attributes::NoCapture))),
|
||||||
|
Attr_ReadOnly_1_4_NoCapture
|
||||||
|
= Attr_ReadOnly_1_NoCapture.addAttr(4, llvm::Attributes::get(llvm::Attributes::Builder().addAttribute(llvm::Attributes::NoCapture))),
|
||||||
|
Attr_ReadOnly_NoUnwind_1_NoCapture
|
||||||
|
= Attr_ReadOnly_1_NoCapture.addAttr(~0U, llvm::Attributes::get(llvm::Attributes::Builder().addAttribute(llvm::Attributes::NoUnwind))),
|
||||||
|
Attr_ReadNone
|
||||||
|
= NoAttrs.addAttr(~0U, llvm::Attributes::get(llvm::Attributes::Builder().addAttribute(llvm::Attributes::ReadNone))),
|
||||||
|
Attr_1_NoCapture
|
||||||
|
= NoAttrs.addAttr(1, llvm::Attributes::get(llvm::Attributes::Builder().addAttribute(llvm::Attributes::NoCapture))),
|
||||||
|
Attr_NoAlias_1_NoCapture
|
||||||
|
= Attr_1_NoCapture.addAttr(0, llvm::Attributes::get(llvm::Attributes::Builder().addAttribute(llvm::Attributes::NoAlias))),
|
||||||
|
Attr_NoAlias_3_NoCapture
|
||||||
|
= Attr_NoAlias.addAttr(3, llvm::Attributes::get(llvm::Attributes::Builder().addAttribute(llvm::Attributes::NoCapture))),
|
||||||
|
Attr_1_2_NoCapture
|
||||||
|
= Attr_1_NoCapture.addAttr(2, llvm::Attributes::get(llvm::Attributes::Builder().addAttribute(llvm::Attributes::NoCapture))),
|
||||||
|
Attr_1_3_NoCapture
|
||||||
|
= Attr_1_NoCapture.addAttr(3, llvm::Attributes::get(llvm::Attributes::Builder().addAttribute(llvm::Attributes::NoCapture))),
|
||||||
|
Attr_1_4_NoCapture
|
||||||
|
= Attr_1_NoCapture.addAttr(4, llvm::Attributes::get(llvm::Attributes::Builder().addAttribute(llvm::Attributes::NoCapture)));
|
||||||
|
#else
|
||||||
llvm::AttrListPtr
|
llvm::AttrListPtr
|
||||||
NoAttrs,
|
NoAttrs,
|
||||||
Attr_NoAlias
|
Attr_NoAlias
|
||||||
|
@ -249,6 +285,7 @@ static void LLVM_D_BuildRuntimeModule()
|
||||||
= Attr_1_NoCapture.addAttr(3, NoCapture),
|
= Attr_1_NoCapture.addAttr(3, NoCapture),
|
||||||
Attr_1_4_NoCapture
|
Attr_1_4_NoCapture
|
||||||
= Attr_1_NoCapture.addAttr(4, NoCapture);
|
= Attr_1_NoCapture.addAttr(4, NoCapture);
|
||||||
|
#endif
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////
|
||||||
/////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -275,7 +275,7 @@ std::vector<llvm::Value*> DtoStructLiteralValues(const StructDeclaration* sd,
|
||||||
// sometimes size of the initializer is less than size of the variable,
|
// sometimes size of the initializer is less than size of the variable,
|
||||||
// so make sure that lastsize is correct
|
// so make sure that lastsize is correct
|
||||||
if (inits[i]->getType()->isSized())
|
if (inits[i]->getType()->isSized())
|
||||||
lastsize = ceil(gTargetData->getTypeSizeInBits(inits[i]->getType()) / 8.0);
|
lastsize = ceil(gDataLayout->getTypeSizeInBits(inits[i]->getType()) / 8.0);
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
lastsize = sz;
|
lastsize = sz;
|
||||||
|
|
|
@ -397,8 +397,13 @@ DValue* DtoCallFunction(Loc& loc, Type* resulttype, DValue* fnval, Expressions*
|
||||||
// add attrs for hidden ptr
|
// add attrs for hidden ptr
|
||||||
Attr.Index = 1;
|
Attr.Index = 1;
|
||||||
Attr.Attrs = tf->fty.arg_sret->attrs;
|
Attr.Attrs = tf->fty.arg_sret->attrs;
|
||||||
|
#if LDC_LLVM_VER >= 302
|
||||||
|
assert((Attr.Attrs.hasAttribute(llvm::Attributes::StructRet) || Attr.Attrs.hasAttribute(llvm::Attributes::InReg))
|
||||||
|
&& "Sret arg not sret or inreg?");
|
||||||
|
#else
|
||||||
assert((Attr.Attrs & (llvm::Attribute::StructRet | llvm::Attribute::InReg))
|
assert((Attr.Attrs & (llvm::Attribute::StructRet | llvm::Attribute::InReg))
|
||||||
&& "Sret arg not sret or inreg?");
|
&& "Sret arg not sret or inreg?");
|
||||||
|
#endif
|
||||||
attrs.push_back(Attr);
|
attrs.push_back(Attr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -510,7 +515,11 @@ DValue* DtoCallFunction(Loc& loc, Type* resulttype, DValue* fnval, Expressions*
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t n = Parameter::dim(tf->parameters);
|
size_t n = Parameter::dim(tf->parameters);
|
||||||
|
#if LDC_LLVM_VER >= 302
|
||||||
|
LLSmallVector<llvm::Attributes, 10> attrptr(n, llvm::Attributes());
|
||||||
|
#else
|
||||||
LLSmallVector<llvm::Attributes, 10> attrptr(n, llvm::Attribute::None);
|
LLSmallVector<llvm::Attributes, 10> attrptr(n, llvm::Attribute::None);
|
||||||
|
#endif
|
||||||
std::vector<DValue*> argvals;
|
std::vector<DValue*> argvals;
|
||||||
if (dfnval && dfnval->func->isArrayOp) {
|
if (dfnval && dfnval->func->isArrayOp) {
|
||||||
// slightly different approach for array operators
|
// slightly different approach for array operators
|
||||||
|
|
|
@ -60,7 +60,7 @@ void dwarfOpOffset(T &addr, LLStructType *type, int index)
|
||||||
if (!global.params.symdebug)
|
if (!global.params.symdebug)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
uint64_t offset = gTargetData->getStructLayout(type)->getElementOffset(index);
|
uint64_t offset = gDataLayout->getStructLayout(type)->getElementOffset(index);
|
||||||
LLType *int64Ty = LLType::getInt64Ty(gIR->context());
|
LLType *int64Ty = LLType::getInt64Ty(gIR->context());
|
||||||
addr.push_back(LLConstantInt::get(int64Ty, llvm::DIBuilder::OpPlus));
|
addr.push_back(LLConstantInt::get(int64Ty, llvm::DIBuilder::OpPlus));
|
||||||
addr.push_back(LLConstantInt::get(int64Ty, offset));
|
addr.push_back(LLConstantInt::get(int64Ty, offset));
|
||||||
|
|
|
@ -43,14 +43,26 @@ llvm::Attributes DtoShouldExtend(Type* type)
|
||||||
{
|
{
|
||||||
case Tint8:
|
case Tint8:
|
||||||
case Tint16:
|
case Tint16:
|
||||||
|
#if LDC_LLVM_VER >= 302
|
||||||
|
return llvm::Attributes::get(llvm::Attributes::Builder().addAttribute(llvm::Attributes::SExt));
|
||||||
|
#else
|
||||||
return llvm::Attribute::SExt;
|
return llvm::Attribute::SExt;
|
||||||
|
#endif
|
||||||
|
|
||||||
case Tuns8:
|
case Tuns8:
|
||||||
case Tuns16:
|
case Tuns16:
|
||||||
|
#if LDC_LLVM_VER >= 302
|
||||||
|
return llvm::Attributes::get(llvm::Attributes::Builder().addAttribute(llvm::Attributes::ZExt));
|
||||||
|
#else
|
||||||
return llvm::Attribute::ZExt;
|
return llvm::Attribute::ZExt;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#if LDC_LLVM_VER >= 302
|
||||||
|
return llvm::Attributes();
|
||||||
|
#else
|
||||||
return llvm::Attribute::None;
|
return llvm::Attribute::None;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
LLType* DtoType(Type* t)
|
LLType* DtoType(Type* t)
|
||||||
|
@ -864,34 +876,34 @@ LLConstant* getNullValue(LLType* t)
|
||||||
|
|
||||||
size_t getTypeBitSize(LLType* t)
|
size_t getTypeBitSize(LLType* t)
|
||||||
{
|
{
|
||||||
return gTargetData->getTypeSizeInBits(t);
|
return gDataLayout->getTypeSizeInBits(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t getTypeStoreSize(LLType* t)
|
size_t getTypeStoreSize(LLType* t)
|
||||||
{
|
{
|
||||||
return gTargetData->getTypeStoreSize(t);
|
return gDataLayout->getTypeStoreSize(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t getTypePaddedSize(LLType* t)
|
size_t getTypePaddedSize(LLType* t)
|
||||||
{
|
{
|
||||||
size_t sz = gTargetData->getTypeAllocSize(t);
|
size_t sz = gDataLayout->getTypeAllocSize(t);
|
||||||
//Logger::cout() << "abi type size of: " << *t << " == " << sz << '\n';
|
//Logger::cout() << "abi type size of: " << *t << " == " << sz << '\n';
|
||||||
return sz;
|
return sz;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t getTypeAllocSize(LLType* t)
|
size_t getTypeAllocSize(LLType* t)
|
||||||
{
|
{
|
||||||
return gTargetData->getTypeAllocSize(t);
|
return gDataLayout->getTypeAllocSize(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char getABITypeAlign(LLType* t)
|
unsigned char getABITypeAlign(LLType* t)
|
||||||
{
|
{
|
||||||
return gTargetData->getABITypeAlignment(t);
|
return gDataLayout->getABITypeAlignment(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned char getPrefTypeAlign(LLType* t)
|
unsigned char getPrefTypeAlign(LLType* t)
|
||||||
{
|
{
|
||||||
return gTargetData->getPrefTypeAlignment(t);
|
return gDataLayout->getPrefTypeAlignment(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
LLType* getBiggestType(LLType** begin, size_t n)
|
LLType* getBiggestType(LLType** begin, size_t n)
|
||||||
|
|
12
ir/ir.cpp
12
ir/ir.cpp
|
@ -1,4 +1,8 @@
|
||||||
|
#if LDC_LLVM_VER >= 302
|
||||||
|
#include "llvm/DataLayout.h"
|
||||||
|
#else
|
||||||
#include "llvm/Target/TargetData.h"
|
#include "llvm/Target/TargetData.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "gen/irstate.h"
|
#include "gen/irstate.h"
|
||||||
#include "gen/tollvm.h"
|
#include "gen/tollvm.h"
|
||||||
|
@ -10,22 +14,22 @@
|
||||||
|
|
||||||
unsigned GetTypeAlignment(Ir* ir, Type* t)
|
unsigned GetTypeAlignment(Ir* ir, Type* t)
|
||||||
{
|
{
|
||||||
return gTargetData->getABITypeAlignment(DtoType(t));
|
return gDataLayout->getABITypeAlignment(DtoType(t));
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned GetPointerSize(Ir* ir)
|
unsigned GetPointerSize(Ir* ir)
|
||||||
{
|
{
|
||||||
return gTargetData->getPointerSize();
|
return gDataLayout->getPointerSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned GetTypeStoreSize(Ir* ir, Type* t)
|
unsigned GetTypeStoreSize(Ir* ir, Type* t)
|
||||||
{
|
{
|
||||||
return gTargetData->getTypeStoreSize(DtoType(t));
|
return gDataLayout->getTypeStoreSize(DtoType(t));
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned GetTypeAllocSize(Ir* ir, Type* t)
|
unsigned GetTypeAllocSize(Ir* ir, Type* t)
|
||||||
{
|
{
|
||||||
return gTargetData->getTypeAllocSize(DtoType(t));
|
return gDataLayout->getTypeAllocSize(DtoType(t));
|
||||||
}
|
}
|
||||||
|
|
||||||
Ir::Ir()
|
Ir::Ir()
|
||||||
|
|
|
@ -33,7 +33,11 @@ namespace llvm
|
||||||
class Constant;
|
class Constant;
|
||||||
class ConstantStruct;
|
class ConstantStruct;
|
||||||
class ConstantArray;
|
class ConstantArray;
|
||||||
|
#if LDC_LLVM_VER >= 302
|
||||||
|
class DataLayout;
|
||||||
|
#else
|
||||||
class TargetData;
|
class TargetData;
|
||||||
|
#endif
|
||||||
class Type;
|
class Type;
|
||||||
class StructType;
|
class StructType;
|
||||||
class ArrayType;
|
class ArrayType;
|
||||||
|
|
|
@ -21,9 +21,15 @@ IrFuncTyArg::IrFuncTyArg(Type* t, bool bref, llvm::Attributes a) : type(t)
|
||||||
rewrite = NULL;
|
rewrite = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if LDC_LLVM_VER >= 302
|
||||||
|
bool IrFuncTyArg::isInReg() const { return attrs.hasAttribute(llvm::Attributes::InReg); }
|
||||||
|
bool IrFuncTyArg::isSRet() const { return attrs.hasAttribute(llvm::Attributes::StructRet); }
|
||||||
|
bool IrFuncTyArg::isByVal() const { return attrs.hasAttribute(llvm::Attributes::ByVal); }
|
||||||
|
#else
|
||||||
bool IrFuncTyArg::isInReg() const { return (attrs & llvm::Attribute::InReg) != 0; }
|
bool IrFuncTyArg::isInReg() const { return (attrs & llvm::Attribute::InReg) != 0; }
|
||||||
bool IrFuncTyArg::isSRet() const { return (attrs & llvm::Attribute::StructRet) != 0; }
|
bool IrFuncTyArg::isSRet() const { return (attrs & llvm::Attribute::StructRet) != 0; }
|
||||||
bool IrFuncTyArg::isByVal() const { return (attrs & llvm::Attribute::ByVal) != 0; }
|
bool IrFuncTyArg::isByVal() const { return (attrs & llvm::Attribute::ByVal) != 0; }
|
||||||
|
#endif
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -152,19 +158,21 @@ IrFunction::IrFunction(FuncDeclaration* fd)
|
||||||
void IrFunction::setNeverInline()
|
void IrFunction::setNeverInline()
|
||||||
{
|
{
|
||||||
#if LDC_LLVM_VER >= 302
|
#if LDC_LLVM_VER >= 302
|
||||||
assert(!func->getFnAttributes().hasAlwaysInlineAttr() && "function can't be never- and always-inline at the same time");
|
assert(!func->getFnAttributes().hasAttribute(llvm::Attributes::AlwaysInline) && "function can't be never- and always-inline at the same time");
|
||||||
|
func->addFnAttr(llvm::Attributes::NoInline);
|
||||||
#else
|
#else
|
||||||
assert(!func->hasFnAttr(llvm::Attribute::AlwaysInline) && "function can't be never- and always-inline at the same time");
|
assert(!func->hasFnAttr(llvm::Attribute::AlwaysInline) && "function can't be never- and always-inline at the same time");
|
||||||
#endif
|
|
||||||
func->addFnAttr(llvm::Attribute::NoInline);
|
func->addFnAttr(llvm::Attribute::NoInline);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void IrFunction::setAlwaysInline()
|
void IrFunction::setAlwaysInline()
|
||||||
{
|
{
|
||||||
#if LDC_LLVM_VER >= 302
|
#if LDC_LLVM_VER >= 302
|
||||||
assert(!func->getFnAttributes().hasNoInlineAttr() && "function can't be never- and always-inline at the same time");
|
assert(!func->getFnAttributes().hasAttribute(llvm::Attributes::NoInline) && "function can't be never- and always-inline at the same time");
|
||||||
|
func->addFnAttr(llvm::Attributes::AlwaysInline);
|
||||||
#else
|
#else
|
||||||
assert(!func->hasFnAttr(llvm::Attribute::NoInline) && "function can't be never- and always-inline at the same time");
|
assert(!func->hasFnAttr(llvm::Attribute::NoInline) && "function can't be never- and always-inline at the same time");
|
||||||
#endif
|
|
||||||
func->addFnAttr(llvm::Attribute::AlwaysInline);
|
func->addFnAttr(llvm::Attribute::AlwaysInline);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,7 +51,11 @@ struct IrFuncTyArg : IrBase
|
||||||
* @param byref Initial value for the 'byref' field. If true the initial
|
* @param byref Initial value for the 'byref' field. If true the initial
|
||||||
* LLVM Type will be of DtoType(type->pointerTo()), instead
|
* LLVM Type will be of DtoType(type->pointerTo()), instead
|
||||||
* of just DtoType(type) */
|
* of just DtoType(type) */
|
||||||
|
#if LDC_LLVM_VER >= 302
|
||||||
|
IrFuncTyArg(Type* t, bool byref, llvm::Attributes a = llvm::Attributes());
|
||||||
|
#else
|
||||||
IrFuncTyArg(Type* t, bool byref, llvm::Attributes a = llvm::Attribute::None);
|
IrFuncTyArg(Type* t, bool byref, llvm::Attributes a = llvm::Attribute::None);
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
// represents a function type
|
// represents a function type
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue