Move irFty fields to backend ir classes

This commit is contained in:
Alexey Prokhin 2014-09-22 18:31:57 +04:00
parent 66a392a5c2
commit 4e2d45a409
13 changed files with 61 additions and 43 deletions

View file

@ -751,8 +751,6 @@ public:
virtual FuncDeclaration *toAliasFunc() { return this; }
#if IN_LLVM
IrFuncTy irFty;
std::string intrinsicName;
uint32_t priority;

View file

@ -23,7 +23,6 @@
#include "expression.h"
//#include "visitor.h"
#include "../ir/irfuncty.h"
struct Scope;
class Identifier;
class Expression;
@ -677,10 +676,6 @@ public:
Expression *defaultInit(Loc loc);
void accept(Visitor *v) { v->visit(this); }
#if IN_LLVM
IrFuncTy irFty;
#endif
};
class TypeDelegate : public TypeNext
@ -703,10 +698,6 @@ public:
int hasPointers();
void accept(Visitor *v) { v->visit(this); }
#if IN_LLVM
IrFuncTy irFty;
#endif
};
class TypeQualified : public Type

View file

@ -424,7 +424,7 @@ LLFunction* DtoInlineIRFunction(FuncDeclaration* fdecl)
static llvm::FunctionType* DtoVaFunctionType(FuncDeclaration* fdecl)
{
IrFuncTy &irFty = fdecl->irFty;
IrFuncTy &irFty = getIrFunc(fdecl, true)->irFty;
if (irFty.funcType) return irFty.funcType;
irFty.ret = new IrFuncTyArg(Type::tvoid, false);
@ -479,7 +479,7 @@ llvm::FunctionType* DtoFunctionType(FuncDeclaration* fdecl)
dnest = Type::tvoid->pointerTo();
}
LLFunctionType* functype = DtoFunctionType(fdecl->type, fdecl->irFty, dthis, dnest,
LLFunctionType* functype = DtoFunctionType(fdecl->type, getIrFunc(fdecl, true)->irFty, dthis, dnest,
fdecl->isMain(), fdecl->isCtorDeclaration(),
fdecl->llvmInternal == LLVMintrinsic);
@ -597,7 +597,7 @@ void DtoResolveFunction(FuncDeclaration* fdecl)
#if LDC_LLVM_VER >= 303
static void set_param_attrs(TypeFunction* f, llvm::Function* func, FuncDeclaration* fdecl)
{
IrFuncTy &irFty = fdecl->irFty;
IrFuncTy &irFty = getIrFunc(fdecl)->irFty;
llvm::AttributeSet old = func->getAttributes();
llvm::AttributeSet existingAttrs[] = { old.getFnAttributes(), old.getRetAttributes() };
llvm::AttributeSet newAttrs = llvm::AttributeSet::get(gIR->context(), existingAttrs);
@ -645,7 +645,7 @@ static void set_param_attrs(TypeFunction* f, llvm::Function* func, FuncDeclarati
#else
static void set_param_attrs(TypeFunction* f, llvm::Function* func, FuncDeclaration* fdecl)
{
IrFuncTy &irFty = fdecl->irFty;
IrFuncTy &irFty = getIrFunc(fdecl)->irFty;
LLSmallVector<llvm::AttributeWithIndex, 9> attrs;
int idx = 0;
@ -844,7 +844,7 @@ void DtoDeclareFunction(FuncDeclaration* fdecl)
AppendFunctionToLLVMGlobalCtorsDtors(func, fdecl->priority, fdecl->llvmInternal == LLVMglobal_crt_ctor);
}
IrFuncTy &irFty = fdecl->irFty;
IrFuncTy &irFty = irFunc->irFty;
// if (!declareOnly)
{
@ -1039,8 +1039,8 @@ void DtoDefineFunction(FuncDeclaration* fd)
return;
}
IrFuncTy &irFty = fd->irFty;
IrFunction *irFunc = getIrFunc(fd);
IrFuncTy &irFty = irFunc->irFty;
// debug info
irFunc->diSubprogram = gIR->DBuilder.EmitSubProgram(fd);

View file

@ -20,6 +20,7 @@
#include "statement.h"
#include "gen/dvalue.h"
#include "gen/llvm.h"
#include "ir/irfuncty.h"
// this is used for tracking try-finally scopes
struct EnclosingTryFinally

View file

@ -961,13 +961,15 @@ static void LLVM_D_BuildRuntimeModule()
gABI->mangleForLLVM("_D9invariant12_d_invariantFC6ObjectZv", LINKd),
M
);
assert(dty->ctype);
IrFuncTy &irFty = dty->ctype->getIrFuncTy();
gABI->newFunctionType(dty);
gABI->rewriteFunctionType(dty, dty->irFty);
gABI->rewriteFunctionType(dty, irFty);
gABI->doneWithFunctionType();
#if LDC_LLVM_VER < 303
fn->addAttribute(1, dty->irFty.args[0]->attrs);
fn->addAttribute(1, irFty.args[0]->attrs);
#else
fn->addAttributes(1, llvm::AttributeSet::get(gIR->context(), 1, dty->irFty.args[0]->attrs));
fn->addAttributes(1, llvm::AttributeSet::get(gIR->context(), 1, irFty.args[0]->attrs));
#endif
fn->setCallingConv(gABI->callingConv(LINKd));
}

View file

@ -418,7 +418,7 @@ public:
dval = toElemDtor(ae);
}
// do abi specific transformations on the return value
v = irs->func()->decl->irFty.putRet(stmt->exp->type, dval);
v = getIrFunc(irs->func()->decl)->irFty.putRet(stmt->exp->type, dval);
}
IF_LOG Logger::cout() << "return value is '" <<*v << "'\n";

View file

@ -21,6 +21,7 @@
#include "gen/logger.h"
#include "gen/nested.h"
#include "gen/tollvm.h"
#include "ir/irtype.h"
//////////////////////////////////////////////////////////////////////////////////////////
@ -29,16 +30,13 @@ IrFuncTy &DtoIrTypeFunction(DValue* fnval)
if (DFuncValue* dfnval = fnval->isFunc())
{
if (dfnval->func)
return dfnval->func->irFty;
return getIrFunc(dfnval->func)->irFty;
}
Type* type = stripModifiers(fnval->getType()->toBasetype());
if (type->ty == Tfunction)
return static_cast<TypeFunction*>(type)->irFty;
else if (type->ty == Tdelegate)
return static_cast<TypeDelegate*>(type)->irFty;
llvm_unreachable("Cannot get IrFuncTy from non lazy/function/delegate");
DtoType(type);
assert(type->ctype);
return type->ctype->getIrFuncTy();
}
TypeFunction* DtoTypeFunction(DValue* fnval)

View file

@ -322,6 +322,7 @@ llvm::GlobalVariable * IrAggr::getInterfaceVtbl(BaseClass * b, bool new_instance
DtoResolveFunction(fd);
assert(isIrFuncCreated(fd) && "invalid vtbl function");
IrFunction *irFunc = getIrFunc(fd);
LLFunction *fn = getIrFunc(fd)->func;
// If the base is a cpp interface, 'this' parameter is a pointer to
@ -329,7 +330,7 @@ llvm::GlobalVariable * IrAggr::getInterfaceVtbl(BaseClass * b, bool new_instance
// the function, we place into the vtable a small wrapper, called thunk,
// that casts 'this' to the object and then pass it to the real function.
if (b->base->isCPPinterface()) {
assert(fd->irFty.arg_this);
assert(irFunc->irFty.arg_this);
// create the thunk function
OutBuffer name;
@ -351,7 +352,7 @@ llvm::GlobalVariable * IrAggr::getInterfaceVtbl(BaseClass * b, bool new_instance
args.push_back(iarg);
// cast 'this' to Object
LLValue* &thisArg = args[(fd->irFty.arg_sret == 0) ? 0 : 1];
LLValue* &thisArg = args[(irFunc->irFty.arg_sret == 0) ? 0 : 1];
LLType* thisType = thisArg->getType();
thisArg = DtoBitCast(thisArg, getVoidPtrType());
thisArg = DtoGEP1(thisArg, DtoConstInt(-b->offset));

View file

@ -18,6 +18,7 @@
#include "gen/llvm.h"
#include "ir/irlandingpad.h"
#include "ir/irfuncty.h"
#include <map>
#include <stack>
#include <vector>
@ -123,6 +124,8 @@ struct IrFunction
llvm::DISubprogram diSubprogram;
std::stack<llvm::DILexicalBlock> diLexicalBlocks;
IrFuncTy irFty;
};
IrFunction *getIrFunc(FuncDeclaration *decl, bool create = false);

View file

@ -35,6 +35,13 @@ IrType::IrType(Type* dt, LLType* lt)
assert(!dt->ctype && "already has IrType");
}
//////////////////////////////////////////////////////////////////////////////
IrFuncTy &IrType::getIrFuncTy()
{
llvm_unreachable("cannot get IrFuncTy from non lazy/function/delegate");
}
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////

View file

@ -16,6 +16,8 @@
#ifndef __LDC_IR_IRTYPE_H__
#define __LDC_IR_IRTYPE_H__
#include "ir/irfuncty.h"
//////////////////////////////////////////////////////////////////////////////
// forward declarations
@ -88,6 +90,9 @@ public:
///
virtual llvm::Type* getLLType() { return type; }
///
virtual IrFuncTy &getIrFuncTy();
protected:
///
IrType(Type* dt, llvm::Type* lt);

View file

@ -20,8 +20,8 @@
#include "ir/irtypefunction.h"
IrTypeFunction::IrTypeFunction(Type* dt, LLType* lt)
: IrType(dt, lt)
IrTypeFunction::IrTypeFunction(Type* dt, LLType* lt, const IrFuncTy &irFty_)
: IrType(dt, lt), irFty(irFty_)
{
}
@ -30,18 +30,19 @@ IrTypeFunction* IrTypeFunction::get(Type* dt, Type* nestedContextOverride)
assert(!dt->ctype);
assert(dt->ty == Tfunction);
IrFuncTy irFty;
TypeFunction* tf = static_cast<TypeFunction*>(dt);
llvm::Type* lt = DtoFunctionType(tf, tf->irFty, NULL, nestedContextOverride);
llvm::Type* lt = DtoFunctionType(tf, irFty, NULL, nestedContextOverride);
if (!dt->irtype)
dt->ctype = new IrTypeFunction(dt, lt);
if (!dt->ctype)
dt->ctype = new IrTypeFunction(dt, lt, irFty);
return dt->ctype->isFunction();
}
//////////////////////////////////////////////////////////////////////////////
IrTypeDelegate::IrTypeDelegate(Type * dt, LLType* lt)
: IrType(dt, lt)
IrTypeDelegate::IrTypeDelegate(Type * dt, LLType* lt, const IrFuncTy &irFty_)
: IrType(dt, lt), irFty(irFty_)
{
}
@ -56,12 +57,13 @@ IrTypeDelegate* IrTypeDelegate::get(Type* t)
if (!dt->ctype)
{
TypeFunction* tf = static_cast<TypeFunction*>(dt->nextOf());
llvm::Type* ltf = DtoFunctionType(tf, dt->irFty, NULL, Type::tvoid->pointerTo());
IrFuncTy irFty;
llvm::Type* ltf = DtoFunctionType(tf, irFty, NULL, Type::tvoid->pointerTo());
llvm::Type *types[] = { getVoidPtrType(),
getPtrToType(ltf) };
LLStructType* lt = LLStructType::get(gIR->context(), types, false);
dt->ctype = new IrTypeDelegate(dt, lt);
dt->ctype = new IrTypeDelegate(dt, lt, irFty);
}
return dt->ctype->isDelegate();

View file

@ -28,9 +28,14 @@ public:
///
IrTypeFunction* isFunction() { return this; }
///
IrFuncTy &getIrFuncTy() { return irFty; }
protected:
///
IrTypeFunction(Type* dt, llvm::Type* lt);
IrTypeFunction(Type* dt, llvm::Type* lt, const IrFuncTy &irFty);
///
IrFuncTy irFty;
};
///
@ -43,9 +48,14 @@ public:
///
IrTypeDelegate* isDelegate() { return this; }
///
IrFuncTy &getIrFuncTy() { return irFty; }
protected:
///
IrTypeDelegate(Type* dt, llvm::Type* lt);
IrTypeDelegate(Type* dt, LLType* lt, const IrFuncTy &irFty);
///
IrFuncTy irFty;
};
#endif