ldc/ir/irtypefunction.cpp
Martin Kinkelin 3f716ff75e Refactoring: Introduce getIrType()
As *the* way to access the IrType associated with a Type via its `ctype`
field. Most importantly, it makes sure all access is redirected to the
*unqualified* type's `ctype`, which allows to get rid of the 'multiple
types' workaround for aggregates in DtoType(). Those were e.g. hit for
`shared struct SpinLock`, where the struct's type includes the `shared`
modifier...
2020-11-13 15:43:18 +01:00

66 lines
1.9 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//===-- irtypefunction.cpp ------------------------------------------------===//
//
// LDC the LLVM D compiler
//
// This file is distributed under the BSD-style LDC license. See the LICENSE
// file for details.
//
//===----------------------------------------------------------------------===//
#include "ir/irtypefunction.h"
#include "dmd/mtype.h"
#include "gen/functions.h"
#include "gen/irstate.h"
#include "gen/tollvm.h"
#include "llvm/IR/DerivedTypes.h"
IrTypeFunction::IrTypeFunction(Type *dt, llvm::Type *lt, IrFuncTy irFty_)
: IrType(dt, lt), irFty(std::move(irFty_)) {}
IrTypeFunction *IrTypeFunction::get(Type *dt) {
TypeFunction *tf = dt->isTypeFunction();
assert(tf);
auto &ctype = getIrType(tf);
assert(!ctype);
IrFuncTy irFty(tf);
llvm::Type *lt = DtoFunctionType(tf, irFty, nullptr, nullptr);
// Could have already built the type as part of a struct forward reference,
// just as for pointers and arrays.
if (!ctype) {
ctype = new IrTypeFunction(dt, lt, irFty);
}
return ctype->isFunction();
}
//////////////////////////////////////////////////////////////////////////////
IrTypeDelegate::IrTypeDelegate(Type *dt, llvm::Type *lt, IrFuncTy irFty_)
: IrType(dt, lt), irFty(std::move(irFty_)) {}
IrTypeDelegate *IrTypeDelegate::get(Type *t) {
assert(t->ty == Tdelegate);
TypeFunction *tf = t->nextOf()->isTypeFunction();
assert(tf);
auto &ctype = getIrType(t);
assert(!ctype);
IrFuncTy irFty(tf);
llvm::Type *ltf =
DtoFunctionType(tf, irFty, nullptr, Type::tvoid->pointerTo());
llvm::Type *types[] = {getVoidPtrType(), getPtrToType(ltf)};
LLStructType *lt = LLStructType::get(gIR->context(), types, false);
// Could have already built the type as part of a struct forward reference,
// just as for pointers and arrays.
if (!ctype) {
ctype = new IrTypeDelegate(t, lt, irFty);
}
return ctype->isDelegate();
}