mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-06 19:06:02 +03:00
Move irFty fields to backend ir classes
This commit is contained in:
parent
66a392a5c2
commit
4e2d45a409
13 changed files with 61 additions and 43 deletions
|
@ -751,8 +751,6 @@ public:
|
||||||
virtual FuncDeclaration *toAliasFunc() { return this; }
|
virtual FuncDeclaration *toAliasFunc() { return this; }
|
||||||
|
|
||||||
#if IN_LLVM
|
#if IN_LLVM
|
||||||
IrFuncTy irFty;
|
|
||||||
|
|
||||||
std::string intrinsicName;
|
std::string intrinsicName;
|
||||||
uint32_t priority;
|
uint32_t priority;
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,6 @@
|
||||||
#include "expression.h"
|
#include "expression.h"
|
||||||
//#include "visitor.h"
|
//#include "visitor.h"
|
||||||
|
|
||||||
#include "../ir/irfuncty.h"
|
|
||||||
struct Scope;
|
struct Scope;
|
||||||
class Identifier;
|
class Identifier;
|
||||||
class Expression;
|
class Expression;
|
||||||
|
@ -677,10 +676,6 @@ public:
|
||||||
|
|
||||||
Expression *defaultInit(Loc loc);
|
Expression *defaultInit(Loc loc);
|
||||||
void accept(Visitor *v) { v->visit(this); }
|
void accept(Visitor *v) { v->visit(this); }
|
||||||
|
|
||||||
#if IN_LLVM
|
|
||||||
IrFuncTy irFty;
|
|
||||||
#endif
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class TypeDelegate : public TypeNext
|
class TypeDelegate : public TypeNext
|
||||||
|
@ -703,10 +698,6 @@ public:
|
||||||
int hasPointers();
|
int hasPointers();
|
||||||
|
|
||||||
void accept(Visitor *v) { v->visit(this); }
|
void accept(Visitor *v) { v->visit(this); }
|
||||||
|
|
||||||
#if IN_LLVM
|
|
||||||
IrFuncTy irFty;
|
|
||||||
#endif
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class TypeQualified : public Type
|
class TypeQualified : public Type
|
||||||
|
|
|
@ -424,7 +424,7 @@ LLFunction* DtoInlineIRFunction(FuncDeclaration* fdecl)
|
||||||
|
|
||||||
static llvm::FunctionType* DtoVaFunctionType(FuncDeclaration* fdecl)
|
static llvm::FunctionType* DtoVaFunctionType(FuncDeclaration* fdecl)
|
||||||
{
|
{
|
||||||
IrFuncTy &irFty = fdecl->irFty;
|
IrFuncTy &irFty = getIrFunc(fdecl, true)->irFty;
|
||||||
if (irFty.funcType) return irFty.funcType;
|
if (irFty.funcType) return irFty.funcType;
|
||||||
|
|
||||||
irFty.ret = new IrFuncTyArg(Type::tvoid, false);
|
irFty.ret = new IrFuncTyArg(Type::tvoid, false);
|
||||||
|
@ -479,7 +479,7 @@ llvm::FunctionType* DtoFunctionType(FuncDeclaration* fdecl)
|
||||||
dnest = Type::tvoid->pointerTo();
|
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->isMain(), fdecl->isCtorDeclaration(),
|
||||||
fdecl->llvmInternal == LLVMintrinsic);
|
fdecl->llvmInternal == LLVMintrinsic);
|
||||||
|
|
||||||
|
@ -597,7 +597,7 @@ void DtoResolveFunction(FuncDeclaration* fdecl)
|
||||||
#if LDC_LLVM_VER >= 303
|
#if LDC_LLVM_VER >= 303
|
||||||
static void set_param_attrs(TypeFunction* f, llvm::Function* func, FuncDeclaration* fdecl)
|
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 old = func->getAttributes();
|
||||||
llvm::AttributeSet existingAttrs[] = { old.getFnAttributes(), old.getRetAttributes() };
|
llvm::AttributeSet existingAttrs[] = { old.getFnAttributes(), old.getRetAttributes() };
|
||||||
llvm::AttributeSet newAttrs = llvm::AttributeSet::get(gIR->context(), existingAttrs);
|
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
|
#else
|
||||||
static void set_param_attrs(TypeFunction* f, llvm::Function* func, FuncDeclaration* fdecl)
|
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;
|
LLSmallVector<llvm::AttributeWithIndex, 9> attrs;
|
||||||
|
|
||||||
int idx = 0;
|
int idx = 0;
|
||||||
|
@ -844,7 +844,7 @@ void DtoDeclareFunction(FuncDeclaration* fdecl)
|
||||||
AppendFunctionToLLVMGlobalCtorsDtors(func, fdecl->priority, fdecl->llvmInternal == LLVMglobal_crt_ctor);
|
AppendFunctionToLLVMGlobalCtorsDtors(func, fdecl->priority, fdecl->llvmInternal == LLVMglobal_crt_ctor);
|
||||||
}
|
}
|
||||||
|
|
||||||
IrFuncTy &irFty = fdecl->irFty;
|
IrFuncTy &irFty = irFunc->irFty;
|
||||||
|
|
||||||
// if (!declareOnly)
|
// if (!declareOnly)
|
||||||
{
|
{
|
||||||
|
@ -1039,8 +1039,8 @@ void DtoDefineFunction(FuncDeclaration* fd)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
IrFuncTy &irFty = fd->irFty;
|
|
||||||
IrFunction *irFunc = getIrFunc(fd);
|
IrFunction *irFunc = getIrFunc(fd);
|
||||||
|
IrFuncTy &irFty = irFunc->irFty;
|
||||||
|
|
||||||
// debug info
|
// debug info
|
||||||
irFunc->diSubprogram = gIR->DBuilder.EmitSubProgram(fd);
|
irFunc->diSubprogram = gIR->DBuilder.EmitSubProgram(fd);
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
#include "statement.h"
|
#include "statement.h"
|
||||||
#include "gen/dvalue.h"
|
#include "gen/dvalue.h"
|
||||||
#include "gen/llvm.h"
|
#include "gen/llvm.h"
|
||||||
|
#include "ir/irfuncty.h"
|
||||||
|
|
||||||
// this is used for tracking try-finally scopes
|
// this is used for tracking try-finally scopes
|
||||||
struct EnclosingTryFinally
|
struct EnclosingTryFinally
|
||||||
|
|
|
@ -961,13 +961,15 @@ static void LLVM_D_BuildRuntimeModule()
|
||||||
gABI->mangleForLLVM("_D9invariant12_d_invariantFC6ObjectZv", LINKd),
|
gABI->mangleForLLVM("_D9invariant12_d_invariantFC6ObjectZv", LINKd),
|
||||||
M
|
M
|
||||||
);
|
);
|
||||||
|
assert(dty->ctype);
|
||||||
|
IrFuncTy &irFty = dty->ctype->getIrFuncTy();
|
||||||
gABI->newFunctionType(dty);
|
gABI->newFunctionType(dty);
|
||||||
gABI->rewriteFunctionType(dty, dty->irFty);
|
gABI->rewriteFunctionType(dty, irFty);
|
||||||
gABI->doneWithFunctionType();
|
gABI->doneWithFunctionType();
|
||||||
#if LDC_LLVM_VER < 303
|
#if LDC_LLVM_VER < 303
|
||||||
fn->addAttribute(1, dty->irFty.args[0]->attrs);
|
fn->addAttribute(1, irFty.args[0]->attrs);
|
||||||
#else
|
#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
|
#endif
|
||||||
fn->setCallingConv(gABI->callingConv(LINKd));
|
fn->setCallingConv(gABI->callingConv(LINKd));
|
||||||
}
|
}
|
||||||
|
|
|
@ -418,7 +418,7 @@ public:
|
||||||
dval = toElemDtor(ae);
|
dval = toElemDtor(ae);
|
||||||
}
|
}
|
||||||
// do abi specific transformations on the return value
|
// 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";
|
IF_LOG Logger::cout() << "return value is '" <<*v << "'\n";
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
#include "gen/logger.h"
|
#include "gen/logger.h"
|
||||||
#include "gen/nested.h"
|
#include "gen/nested.h"
|
||||||
#include "gen/tollvm.h"
|
#include "gen/tollvm.h"
|
||||||
|
#include "ir/irtype.h"
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
@ -29,16 +30,13 @@ IrFuncTy &DtoIrTypeFunction(DValue* fnval)
|
||||||
if (DFuncValue* dfnval = fnval->isFunc())
|
if (DFuncValue* dfnval = fnval->isFunc())
|
||||||
{
|
{
|
||||||
if (dfnval->func)
|
if (dfnval->func)
|
||||||
return dfnval->func->irFty;
|
return getIrFunc(dfnval->func)->irFty;
|
||||||
}
|
}
|
||||||
|
|
||||||
Type* type = stripModifiers(fnval->getType()->toBasetype());
|
Type* type = stripModifiers(fnval->getType()->toBasetype());
|
||||||
if (type->ty == Tfunction)
|
DtoType(type);
|
||||||
return static_cast<TypeFunction*>(type)->irFty;
|
assert(type->ctype);
|
||||||
else if (type->ty == Tdelegate)
|
return type->ctype->getIrFuncTy();
|
||||||
return static_cast<TypeDelegate*>(type)->irFty;
|
|
||||||
|
|
||||||
llvm_unreachable("Cannot get IrFuncTy from non lazy/function/delegate");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TypeFunction* DtoTypeFunction(DValue* fnval)
|
TypeFunction* DtoTypeFunction(DValue* fnval)
|
||||||
|
|
|
@ -322,6 +322,7 @@ llvm::GlobalVariable * IrAggr::getInterfaceVtbl(BaseClass * b, bool new_instance
|
||||||
DtoResolveFunction(fd);
|
DtoResolveFunction(fd);
|
||||||
assert(isIrFuncCreated(fd) && "invalid vtbl function");
|
assert(isIrFuncCreated(fd) && "invalid vtbl function");
|
||||||
|
|
||||||
|
IrFunction *irFunc = getIrFunc(fd);
|
||||||
LLFunction *fn = getIrFunc(fd)->func;
|
LLFunction *fn = getIrFunc(fd)->func;
|
||||||
|
|
||||||
// If the base is a cpp interface, 'this' parameter is a pointer to
|
// 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,
|
// 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.
|
// that casts 'this' to the object and then pass it to the real function.
|
||||||
if (b->base->isCPPinterface()) {
|
if (b->base->isCPPinterface()) {
|
||||||
assert(fd->irFty.arg_this);
|
assert(irFunc->irFty.arg_this);
|
||||||
|
|
||||||
// create the thunk function
|
// create the thunk function
|
||||||
OutBuffer name;
|
OutBuffer name;
|
||||||
|
@ -351,7 +352,7 @@ llvm::GlobalVariable * IrAggr::getInterfaceVtbl(BaseClass * b, bool new_instance
|
||||||
args.push_back(iarg);
|
args.push_back(iarg);
|
||||||
|
|
||||||
// cast 'this' to Object
|
// 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();
|
LLType* thisType = thisArg->getType();
|
||||||
thisArg = DtoBitCast(thisArg, getVoidPtrType());
|
thisArg = DtoBitCast(thisArg, getVoidPtrType());
|
||||||
thisArg = DtoGEP1(thisArg, DtoConstInt(-b->offset));
|
thisArg = DtoGEP1(thisArg, DtoConstInt(-b->offset));
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
|
|
||||||
#include "gen/llvm.h"
|
#include "gen/llvm.h"
|
||||||
#include "ir/irlandingpad.h"
|
#include "ir/irlandingpad.h"
|
||||||
|
#include "ir/irfuncty.h"
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <stack>
|
#include <stack>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
@ -123,6 +124,8 @@ struct IrFunction
|
||||||
|
|
||||||
llvm::DISubprogram diSubprogram;
|
llvm::DISubprogram diSubprogram;
|
||||||
std::stack<llvm::DILexicalBlock> diLexicalBlocks;
|
std::stack<llvm::DILexicalBlock> diLexicalBlocks;
|
||||||
|
|
||||||
|
IrFuncTy irFty;
|
||||||
};
|
};
|
||||||
|
|
||||||
IrFunction *getIrFunc(FuncDeclaration *decl, bool create = false);
|
IrFunction *getIrFunc(FuncDeclaration *decl, bool create = false);
|
||||||
|
|
|
@ -35,6 +35,13 @@ IrType::IrType(Type* dt, LLType* lt)
|
||||||
assert(!dt->ctype && "already has IrType");
|
assert(!dt->ctype && "already has IrType");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
IrFuncTy &IrType::getIrFuncTy()
|
||||||
|
{
|
||||||
|
llvm_unreachable("cannot get IrFuncTy from non lazy/function/delegate");
|
||||||
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
|
@ -16,6 +16,8 @@
|
||||||
#ifndef __LDC_IR_IRTYPE_H__
|
#ifndef __LDC_IR_IRTYPE_H__
|
||||||
#define __LDC_IR_IRTYPE_H__
|
#define __LDC_IR_IRTYPE_H__
|
||||||
|
|
||||||
|
#include "ir/irfuncty.h"
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
// forward declarations
|
// forward declarations
|
||||||
|
@ -88,6 +90,9 @@ public:
|
||||||
///
|
///
|
||||||
virtual llvm::Type* getLLType() { return type; }
|
virtual llvm::Type* getLLType() { return type; }
|
||||||
|
|
||||||
|
///
|
||||||
|
virtual IrFuncTy &getIrFuncTy();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
///
|
///
|
||||||
IrType(Type* dt, llvm::Type* lt);
|
IrType(Type* dt, llvm::Type* lt);
|
||||||
|
|
|
@ -20,8 +20,8 @@
|
||||||
|
|
||||||
#include "ir/irtypefunction.h"
|
#include "ir/irtypefunction.h"
|
||||||
|
|
||||||
IrTypeFunction::IrTypeFunction(Type* dt, LLType* lt)
|
IrTypeFunction::IrTypeFunction(Type* dt, LLType* lt, const IrFuncTy &irFty_)
|
||||||
: IrType(dt, lt)
|
: IrType(dt, lt), irFty(irFty_)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,18 +30,19 @@ IrTypeFunction* IrTypeFunction::get(Type* dt, Type* nestedContextOverride)
|
||||||
assert(!dt->ctype);
|
assert(!dt->ctype);
|
||||||
assert(dt->ty == Tfunction);
|
assert(dt->ty == Tfunction);
|
||||||
|
|
||||||
|
IrFuncTy irFty;
|
||||||
TypeFunction* tf = static_cast<TypeFunction*>(dt);
|
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)
|
if (!dt->ctype)
|
||||||
dt->ctype = new IrTypeFunction(dt, lt);
|
dt->ctype = new IrTypeFunction(dt, lt, irFty);
|
||||||
return dt->ctype->isFunction();
|
return dt->ctype->isFunction();
|
||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
IrTypeDelegate::IrTypeDelegate(Type * dt, LLType* lt)
|
IrTypeDelegate::IrTypeDelegate(Type * dt, LLType* lt, const IrFuncTy &irFty_)
|
||||||
: IrType(dt, lt)
|
: IrType(dt, lt), irFty(irFty_)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,12 +57,13 @@ IrTypeDelegate* IrTypeDelegate::get(Type* t)
|
||||||
if (!dt->ctype)
|
if (!dt->ctype)
|
||||||
{
|
{
|
||||||
TypeFunction* tf = static_cast<TypeFunction*>(dt->nextOf());
|
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(),
|
llvm::Type *types[] = { getVoidPtrType(),
|
||||||
getPtrToType(ltf) };
|
getPtrToType(ltf) };
|
||||||
LLStructType* lt = LLStructType::get(gIR->context(), types, false);
|
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();
|
return dt->ctype->isDelegate();
|
||||||
|
|
|
@ -28,9 +28,14 @@ public:
|
||||||
///
|
///
|
||||||
IrTypeFunction* isFunction() { return this; }
|
IrTypeFunction* isFunction() { return this; }
|
||||||
|
|
||||||
|
///
|
||||||
|
IrFuncTy &getIrFuncTy() { return irFty; }
|
||||||
|
|
||||||
protected:
|
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; }
|
IrTypeDelegate* isDelegate() { return this; }
|
||||||
|
|
||||||
|
///
|
||||||
|
IrFuncTy &getIrFuncTy() { return irFty; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
///
|
///
|
||||||
IrTypeDelegate(Type* dt, llvm::Type* lt);
|
IrTypeDelegate(Type* dt, LLType* lt, const IrFuncTy &irFty);
|
||||||
|
///
|
||||||
|
IrFuncTy irFty;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue