Adapt to free functions in dmd C++ namespace now

This commit is contained in:
Martin Kinkelin 2024-03-03 19:14:00 +01:00
parent 217888ff47
commit 9041c0bf67
37 changed files with 132 additions and 64 deletions

View file

@ -35,6 +35,8 @@ enum class AsanDetectStackUseAfterReturnMode { Never, Runtime, Always };
} }
#endif #endif
using namespace dmd;
namespace { namespace {
using namespace opts; using namespace opts;

View file

@ -91,6 +91,7 @@ void gendocfile(Module *m);
// In dmd/mars.d // In dmd/mars.d
void generateJson(Modules *modules); void generateJson(Modules *modules);
using namespace dmd;
using namespace opts; using namespace opts;
static StringsAdapter impPathsStore("I", global.params.imppath); static StringsAdapter impPathsStore("I", global.params.imppath);

View file

@ -24,6 +24,8 @@
#include "ir/irfunction.h" #include "ir/irfunction.h"
#include "ir/irmodule.h" #include "ir/irmodule.h"
using namespace dmd;
// returns the keytype typeinfo // returns the keytype typeinfo
static LLConstant *to_keyti(const Loc &loc, DValue *aa, LLType *targetType) { static LLConstant *to_keyti(const Loc &loc, DValue *aa, LLType *targetType) {
// keyti param // keyti param
@ -60,8 +62,8 @@ DLValue *DtoAAIndex(const Loc &loc, Type *type, DValue *aa, DValue *key,
// call runtime // call runtime
LLValue *ret; LLValue *ret;
if (lvalue) { if (lvalue) {
LLValue *rawAATI = auto t = mutableOf(unSharedOf(aa->type));
DtoTypeInfoOf(loc, aa->type->unSharedOf()->mutableOf(), /*base=*/false); LLValue *rawAATI = DtoTypeInfoOf(loc, t, /*base=*/false);
LLValue *castedAATI = DtoBitCast(rawAATI, funcTy->getParamType(1)); LLValue *castedAATI = DtoBitCast(rawAATI, funcTy->getParamType(1));
LLValue *valsize = DtoConstSize_t(getTypeAllocSize(DtoType(type))); LLValue *valsize = DtoConstSize_t(getTypeAllocSize(DtoType(type)));
ret = gIR->CreateCallOrInvoke(func, aaval, castedAATI, valsize, pkey, ret = gIR->CreateCallOrInvoke(func, aaval, castedAATI, valsize, pkey,

View file

@ -25,6 +25,8 @@
#include "ir/irfuncty.h" #include "ir/irfuncty.h"
#include <algorithm> #include <algorithm>
using namespace dmd;
// in dmd/argtypes_aarch64.d: // in dmd/argtypes_aarch64.d:
bool isHFVA(Type *t, int maxNumElements, Type **rewriteType); bool isHFVA(Type *t, int maxNumElements, Type **rewriteType);
@ -89,7 +91,7 @@ TypeTuple *TargetABI::getArgTypes(Type *t) {
LLType *TargetABI::getRewrittenArgType(Type *t, TypeTuple *argTypes) { LLType *TargetABI::getRewrittenArgType(Type *t, TypeTuple *argTypes) {
if (!argTypes || argTypes->arguments->empty() || if (!argTypes || argTypes->arguments->empty() ||
(argTypes->arguments->length == 1 && (argTypes->arguments->length == 1 &&
argTypes->arguments->front()->type->equivalent(t))) { equivalent(argTypes->arguments->front()->type, t))) {
return nullptr; // don't rewrite return nullptr; // don't rewrite
} }
@ -217,7 +219,7 @@ LLValue *TargetABI::prepareVaArg(DLValue *ap) {
Type *TargetABI::vaListType() { Type *TargetABI::vaListType() {
// char* is used by default in druntime. // char* is used by default in druntime.
return Type::tchar->pointerTo(); return pointerTo(Type::tchar);
} }
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////

View file

@ -19,6 +19,8 @@
#include "gen/llvmhelpers.h" #include "gen/llvmhelpers.h"
#include "gen/tollvm.h" #include "gen/tollvm.h"
using namespace dmd;
namespace { namespace {
struct Integer2Rewrite : BaseBitcastABIRewrite { struct Integer2Rewrite : BaseBitcastABIRewrite {
LLType *type(Type *t) override { LLType *type(Type *t) override {
@ -57,15 +59,15 @@ FlattenedFields visitStructFields(Type *ty, unsigned baseOffset) {
} }
switch (ty->toBasetype()->ty) { switch (ty->toBasetype()->ty) {
case TY::Tcomplex32: // treat it as {float32, float32} case TY::Tcomplex32: // treat it as {float32, float32}
result.fields[0].ty = Type::tfloat32->pointerTo(); result.fields[0].ty = pointerTo(Type::tfloat32);
result.fields[1].ty = Type::tfloat32->pointerTo(); result.fields[1].ty = pointerTo(Type::tfloat32);
result.fields[0].offset = baseOffset; result.fields[0].offset = baseOffset;
result.fields[1].offset = baseOffset + 4; result.fields[1].offset = baseOffset + 4;
result.length = 2; result.length = 2;
break; break;
case TY::Tcomplex64: // treat it as {float64, float64} case TY::Tcomplex64: // treat it as {float64, float64}
result.fields[0].ty = Type::tfloat64->pointerTo(); result.fields[0].ty = pointerTo(Type::tfloat64);
result.fields[1].ty = Type::tfloat64->pointerTo(); result.fields[1].ty = pointerTo(Type::tfloat64);
result.fields[0].offset = baseOffset; result.fields[0].offset = baseOffset;
result.fields[1].offset = baseOffset + 8; result.fields[1].offset = baseOffset + 8;
result.length = 2; result.length = 2;
@ -160,7 +162,7 @@ private:
public: public:
Type *vaListType() override { Type *vaListType() override {
// va_list is void* // va_list is void*
return Type::tvoid->pointerTo(); return pointerTo(Type::tvoid);
} }
bool returnInArg(TypeFunction *tf, bool) override { bool returnInArg(TypeFunction *tf, bool) override {
if (tf->isref()) { if (tf->isref()) {

View file

@ -46,6 +46,8 @@
#include <string> #include <string>
#include <utility> #include <utility>
using namespace dmd;
namespace { namespace {
struct RegCount { struct RegCount {
char int_regs, sse_regs; char int_regs, sse_regs;
@ -382,8 +384,8 @@ Type *X86_64TargetABI::vaListType() {
// using TypeIdentifier here is a bit wonky but works, as long as the name // using TypeIdentifier here is a bit wonky but works, as long as the name
// is actually available in the scope (this is what DMD does, so if a better // is actually available in the scope (this is what DMD does, so if a better
// solution is found there, this should be adapted). // solution is found there, this should be adapted).
return TypeIdentifier::create(Loc(), Identifier::idPool("__va_list_tag")) return pointerTo(
->pointerTo(); TypeIdentifier::create(Loc(), Identifier::idPool("__va_list_tag")));
} }
const char *X86_64TargetABI::objcMsgSendFunc(Type *ret, const char *X86_64TargetABI::objcMsgSendFunc(Type *ret,

View file

@ -28,6 +28,8 @@
#include "ir/irfunction.h" #include "ir/irfunction.h"
#include "ir/irmodule.h" #include "ir/irmodule.h"
using namespace dmd;
static void DtoSetArray(DValue *array, DValue *rhs); static void DtoSetArray(DValue *array, DValue *rhs);
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -805,7 +807,7 @@ bool validCompareWithMemcmp(DValue *l, DValue *r) {
// Only memcmp equivalent element types (memcmp should be used for // Only memcmp equivalent element types (memcmp should be used for
// `const int[3] == int[]`, but not for `int[3] == short[3]`). // `const int[3] == int[]`, but not for `int[3] == short[3]`).
if (!lElemType->equivalent(rElemType)) if (!equivalent(lElemType, rElemType))
return false; return false;
return validCompareWithMemcmpType(lElemType); return validCompareWithMemcmpType(lElemType);

View file

@ -2337,6 +2337,8 @@ struct AsmProcessor {
void addOperand(const char *fmt, AsmArgType type, Expression *e, void addOperand(const char *fmt, AsmArgType type, Expression *e,
AsmCode *asmcode, AsmArgMode mode = Mode_Input) { AsmCode *asmcode, AsmArgMode mode = Mode_Input) {
using namespace dmd;
if (sc->func->isNaked()) { if (sc->func->isNaked()) {
switch (type) { switch (type) {
case Arg_Integer: case Arg_Integer:
@ -2579,6 +2581,8 @@ struct AsmProcessor {
// also set impl clobbers // also set impl clobbers
bool formatInstruction(int nOperands, AsmCode *asmcode) { bool formatInstruction(int nOperands, AsmCode *asmcode) {
using namespace dmd;
const char *fmt; const char *fmt;
const char *mnemonic; const char *mnemonic;
std::string type_suffix; std::string type_suffix;
@ -3004,7 +3008,7 @@ struct AsmProcessor {
{ {
e = createAddrExp(Loc(), e); e = createAddrExp(Loc(), e);
e->type = decl->type->pointerTo(); e->type = pointerTo(decl->type);
operand->constDisplacement = 0; operand->constDisplacement = 0;
operand->baseReg = Reg_Invalid; operand->baseReg = Reg_Invalid;
@ -3059,7 +3063,7 @@ struct AsmProcessor {
if (!sc->func->isNaked()) // no addrexp in naked asm please :) if (!sc->func->isNaked()) // no addrexp in naked asm please :)
{ {
Type *tt = e->type->pointerTo(); Type *tt = pointerTo(e->type);
e = createAddrExp(Loc(), e); e = createAddrExp(Loc(), e);
e->type = tt; e->type = tt;
} }
@ -3231,6 +3235,8 @@ struct AsmProcessor {
} }
Expression *intOp(TOK op, Expression *e1, Expression *e2) { Expression *intOp(TOK op, Expression *e1, Expression *e2) {
using namespace dmd;
if (isIntExp(e1) && (!e2 || isIntExp(e2))) { if (isIntExp(e1) && (!e2 || isIntExp(e2))) {
Expression *e = createExpressionForIntOp(stmt->loc, op, e1, e2); Expression *e = createExpressionForIntOp(stmt->loc, op, e1, e2);
e = expressionSemantic(e, sc); e = expressionSemantic(e, sc);
@ -3629,6 +3635,8 @@ struct AsmProcessor {
} }
Expression *parsePrimaryExp() { Expression *parsePrimaryExp() {
using namespace dmd;
Expression *e; Expression *e;
Identifier *ident = nullptr; Identifier *ident = nullptr;
@ -3789,6 +3797,8 @@ struct AsmProcessor {
} }
void doAlign() { void doAlign() {
using namespace dmd;
// .align bits vs. bytes... // .align bits vs. bytes...
// apparently a.out platforms use bits instead of bytes... // apparently a.out platforms use bits instead of bytes...

View file

@ -75,6 +75,8 @@ AsmParserCommon *asmparser = nullptr;
#include "asm-x86.h" // x86_64 assembly parser #include "asm-x86.h" // x86_64 assembly parser
#undef ASM_X86_64 #undef ASM_X86_64
using namespace dmd;
/** /**
* Replaces <<func>> with the name of the currently codegen'd function. * Replaces <<func>> with the name of the currently codegen'd function.
* *
@ -95,8 +97,6 @@ static void replace_func_name(IRState *p, std::string &insnt) {
} }
} }
Statement *gccAsmSemantic(GccAsmStatement *s, Scope *sc);
Statement *asmSemantic(AsmStatement *s, Scope *sc) { Statement *asmSemantic(AsmStatement *s, Scope *sc) {
if (!s->tokens) { if (!s->tokens) {
return nullptr; return nullptr;

View file

@ -18,6 +18,8 @@
#include "dmd/module.h" #include "dmd/module.h"
#include "dmd/template.h" #include "dmd/template.h"
using namespace dmd;
bool isFromLDC_Mod(Dsymbol *sym, Identifier* id) { bool isFromLDC_Mod(Dsymbol *sym, Identifier* id) {
auto mod = sym->getModule(); auto mod = sym->getModule();
if (!mod) if (!mod)

View file

@ -34,6 +34,8 @@
#include "ir/irvar.h" #include "ir/irvar.h"
#include "llvm/ADT/SmallString.h" #include "llvm/ADT/SmallString.h"
using namespace dmd;
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
class CodegenVisitor : public Visitor { class CodegenVisitor : public Visitor {

View file

@ -39,6 +39,8 @@
#include "llvm/Support/Path.h" #include "llvm/Support/Path.h"
#include <functional> #include <functional>
using namespace dmd;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
namespace cl = llvm::cl; namespace cl = llvm::cl;
@ -648,7 +650,7 @@ DIType DIBuilder::CreateArrayType(TypeArray *type) {
LLMetadata *elems[] = {CreateMemberType(0, Type::tsize_t, file, "length", 0, LLMetadata *elems[] = {CreateMemberType(0, Type::tsize_t, file, "length", 0,
Visibility::public_), Visibility::public_),
CreateMemberType(0, type->nextOf()->pointerTo(), file, CreateMemberType(0, pointerTo(type->nextOf()), file,
"ptr", target.ptrsize, "ptr", target.ptrsize,
Visibility::public_)}; Visibility::public_)};
@ -743,7 +745,7 @@ DIType DIBuilder::CreateDelegateType(TypeDelegate *type) {
LLMetadata *elems[] = { LLMetadata *elems[] = {
CreateMemberType(0, Type::tvoidptr, file, "ptr", 0, CreateMemberType(0, Type::tvoidptr, file, "ptr", 0,
Visibility::public_), Visibility::public_),
CreateMemberType(0, type->next->pointerTo(), file, "funcptr", CreateMemberType(0, pointerTo(type->next), file, "funcptr",
target.ptrsize, Visibility::public_)}; target.ptrsize, Visibility::public_)};
return DBuilder.createStructType(scope, name, file, return DBuilder.createStructType(scope, name, file,

View file

@ -23,6 +23,8 @@
#include "gen/recursivevisitor.h" #include "gen/recursivevisitor.h"
#include "gen/uda.h" #include "gen/uda.h"
using namespace dmd;
namespace { namespace {
/// An ASTVisitor that checks whether the number of statements is larger than a /// An ASTVisitor that checks whether the number of statements is larger than a
@ -166,7 +168,7 @@ bool defineAsExternallyAvailable(FuncDeclaration &fdecl) {
global.gaggedForInlining = true; global.gaggedForInlining = true;
bool semantic_error = false; bool semantic_error = false;
if (fdecl.functionSemantic3()) { if (functionSemantic3(&fdecl)) {
Module::runDeferredSemantic3(); Module::runDeferredSemantic3();
} else { } else {
IF_LOG Logger::println("Failed functionSemantic3."); IF_LOG Logger::println("Failed functionSemantic3.");

View file

@ -60,6 +60,8 @@
#include "llvm/Transforms/Utils/Cloning.h" #include "llvm/Transforms/Utils/Cloning.h"
#include <iostream> #include <iostream>
using namespace dmd;
bool isAnyMainFunction(FuncDeclaration *fd) { bool isAnyMainFunction(FuncDeclaration *fd) {
return fd->isMain() || fd->isCMain(); return fd->isMain() || fd->isCMain();
} }
@ -123,7 +125,7 @@ llvm::FunctionType *DtoFunctionType(Type *type, IrFuncTy &irFty, Type *thistype,
++nextLLArgIdx; ++nextLLArgIdx;
} else { } else {
// sext/zext return // sext/zext return
DtoAddExtendAttr(byref ? rt->pointerTo() : rt, attrs); DtoAddExtendAttr(byref ? pointerTo(rt) : rt, attrs);
} }
newIrFty.ret = new IrFuncTyArg(rt, byref, std::move(attrs)); newIrFty.ret = new IrFuncTyArg(rt, byref, std::move(attrs));
} }
@ -299,13 +301,13 @@ static llvm::FunctionType *DtoVaFunctionType(FuncDeclaration *fdecl) {
irFty.ret = new IrFuncTyArg(Type::tvoid, false); irFty.ret = new IrFuncTyArg(Type::tvoid, false);
irFty.args.push_back(new IrFuncTyArg(Type::tvoid->pointerTo(), false)); irFty.args.push_back(new IrFuncTyArg(pointerTo(Type::tvoid), false));
if (fdecl->llvmInternal == LLVMva_start) { if (fdecl->llvmInternal == LLVMva_start) {
irFty.funcType = GET_INTRINSIC_DECL(vastart)->getFunctionType(); irFty.funcType = GET_INTRINSIC_DECL(vastart)->getFunctionType();
} else if (fdecl->llvmInternal == LLVMva_copy) { } else if (fdecl->llvmInternal == LLVMva_copy) {
irFty.funcType = GET_INTRINSIC_DECL(vacopy)->getFunctionType(); irFty.funcType = GET_INTRINSIC_DECL(vacopy)->getFunctionType();
irFty.args.push_back(new IrFuncTyArg(Type::tvoid->pointerTo(), false)); irFty.args.push_back(new IrFuncTyArg(pointerTo(Type::tvoid), false));
} else if (fdecl->llvmInternal == LLVMva_end) { } else if (fdecl->llvmInternal == LLVMva_end) {
irFty.funcType = GET_INTRINSIC_DECL(vaend)->getFunctionType(); irFty.funcType = GET_INTRINSIC_DECL(vaend)->getFunctionType();
} }
@ -330,7 +332,7 @@ llvm::FunctionType *DtoFunctionType(FuncDeclaration *fdecl) {
AggregateDeclaration *ad = p->isMember2(); AggregateDeclaration *ad = p->isMember2();
(void)ad; (void)ad;
assert(ad); assert(ad);
dnest = Type::tvoid->pointerTo(); dnest = pointerTo(Type::tvoid);
} else if (fdecl->needThis()) { } else if (fdecl->needThis()) {
if (AggregateDeclaration *ad = fdecl->isMember2()) { if (AggregateDeclaration *ad = fdecl->isMember2()) {
IF_LOG Logger::println("isMember = this is: %s", ad->type->toChars()); IF_LOG Logger::println("isMember = this is: %s", ad->type->toChars());
@ -353,7 +355,7 @@ llvm::FunctionType *DtoFunctionType(FuncDeclaration *fdecl) {
/*isVarArg=*/false); /*isVarArg=*/false);
} }
} else if (fdecl->isNested()) { } else if (fdecl->isNested()) {
dnest = Type::tvoid->pointerTo(); dnest = pointerTo(Type::tvoid);
} }
LLFunctionType *functype = DtoFunctionType( LLFunctionType *functype = DtoFunctionType(
@ -588,7 +590,7 @@ void DtoDeclareFunction(FuncDeclaration *fdecl, const bool willDefine) {
"defined after declaration."); "defined after declaration.");
if (fdecl->semanticRun < PASS::semantic3done) { if (fdecl->semanticRun < PASS::semantic3done) {
Logger::println("Function hasn't had sema3 run yet, running it now."); Logger::println("Function hasn't had sema3 run yet, running it now.");
const bool semaSuccess = fdecl->functionSemantic3(); const bool semaSuccess = functionSemantic3(fdecl);
(void)semaSuccess; (void)semaSuccess;
assert(semaSuccess); assert(semaSuccess);
Module::runDeferredSemantic3(); Module::runDeferredSemantic3();

View file

@ -17,6 +17,8 @@
#include "llvm/Support/raw_ostream.h" #include "llvm/Support/raw_ostream.h"
#include "llvm/Support/SourceMgr.h" #include "llvm/Support/SourceMgr.h"
using namespace dmd;
namespace { namespace {
/// Sets LLVMContext::setDiscardValueNames(false) upon construction and restores /// Sets LLVMContext::setDiscardValueNames(false) upon construction and restores

View file

@ -47,6 +47,8 @@
#include "llvm/Transforms/Utils/ModuleUtils.h" #include "llvm/Transforms/Utils/ModuleUtils.h"
#include <stack> #include <stack>
using namespace dmd;
llvm::cl::opt<llvm::GlobalVariable::ThreadLocalMode> clThreadModel( llvm::cl::opt<llvm::GlobalVariable::ThreadLocalMode> clThreadModel(
"fthread-model", llvm::cl::ZeroOrMore, llvm::cl::desc("Thread model"), "fthread-model", llvm::cl::ZeroOrMore, llvm::cl::desc("Thread model"),
llvm::cl::init(llvm::GlobalVariable::GeneralDynamicTLSModel), llvm::cl::init(llvm::GlobalVariable::GeneralDynamicTLSModel),
@ -907,7 +909,7 @@ void DtoVarDeclaration(VarDeclaration *vd) {
// already been done // already been done
IrLocal *irLocal = getIrLocal(vd, true); IrLocal *irLocal = getIrLocal(vd, true);
Type *type = isSpecialRefVar(vd) ? vd->type->pointerTo() : vd->type; Type *type = isSpecialRefVar(vd) ? pointerTo(vd->type) : vd->type;
llvm::Value *allocainst; llvm::Value *allocainst;
bool isRealAlloca = false; bool isRealAlloca = false;
@ -1326,9 +1328,9 @@ Type *stripModifiers(Type *type, bool transitive) {
} }
if (transitive) { if (transitive) {
return type->unqualify(MODimmutable | MODconst | MODwild); return unqualify(type, MODimmutable | MODconst | MODwild);
} }
return type->castMod(0); return castMod(type, 0);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////

View file

@ -23,6 +23,8 @@
#include "gen/to_string.h" #include "gen/to_string.h"
#include "llvm/Support/MD5.h" #include "llvm/Support/MD5.h"
using namespace dmd;
namespace { namespace {
// TODO: Disable hashing of symbols that are defined in libdruntime and // TODO: Disable hashing of symbols that are defined in libdruntime and

View file

@ -37,6 +37,8 @@
#define MIlocalClasses 0x800 #define MIlocalClasses 0x800
#define MInew 0x80000000 // it's the "new" layout #define MInew 0x80000000 // it's the "new" layout
using namespace dmd;
namespace { namespace {
/// Creates a function in the current llvm::Module that dispatches to the given /// Creates a function in the current llvm::Module that dispatches to the given
/// functions one after each other and then increments the gate variables, if /// functions one after each other and then increments the gate variables, if

View file

@ -58,6 +58,8 @@
#include <alloca.h> #include <alloca.h>
#endif #endif
using namespace dmd;
static llvm::cl::opt<bool, true> static llvm::cl::opt<bool, true>
preservePaths("op", llvm::cl::ZeroOrMore, preservePaths("op", llvm::cl::ZeroOrMore,
llvm::cl::desc("Preserve source path for output files"), llvm::cl::desc("Preserve source path for output files"),

View file

@ -25,6 +25,8 @@
#include "llvm/IR/InlineAsm.h" #include "llvm/IR/InlineAsm.h"
#include <cassert> #include <cassert>
using namespace dmd;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// FIXME: Integrate these functions // FIXME: Integrate these functions
void AsmStatement_toNakedIR(InlineAsmStatement *stmt, IRState *irs); void AsmStatement_toNakedIR(InlineAsmStatement *stmt, IRState *irs);

View file

@ -23,6 +23,8 @@
#include "ir/irtypeaggr.h" #include "ir/irtypeaggr.h"
#include "llvm/Analysis/ValueTracking.h" #include "llvm/Analysis/ValueTracking.h"
using namespace dmd;
namespace { namespace {
unsigned getVthisIdx(AggregateDeclaration *ad) { unsigned getVthisIdx(AggregateDeclaration *ad) {
return getFieldGEPIndex(ad, ad->vthis); return getFieldGEPIndex(ad, ad->vthis);
@ -437,7 +439,7 @@ static void DtoCreateNestedContextType(FuncDeclaration *fd) {
LLType *t = nullptr; LLType *t = nullptr;
unsigned alignment = 0; unsigned alignment = 0;
if (captureByRef(vd)) { if (captureByRef(vd)) {
t = DtoType(vd->type->pointerTo()); t = DtoType(pointerTo(vd->type));
alignment = target.ptrsize; alignment = target.ptrsize;
} else if (isParam && (vd->storage_class & STClazy)) { } else if (isParam && (vd->storage_class & STClazy)) {
// the type is a delegate (LL struct) // the type is a delegate (LL struct)

View file

@ -22,6 +22,8 @@
#include "gen/llvmhelpers.h" #include "gen/llvmhelpers.h"
#include "llvm/Support/CommandLine.h" #include "llvm/Support/CommandLine.h"
using namespace dmd;
namespace { namespace {
bool parseStringExp(Expression *e, const char *&res) { bool parseStringExp(Expression *e, const char *&res) {
e = optimize(e, WANTvalue); e = optimize(e, WANTvalue);

View file

@ -22,8 +22,7 @@
#include "ir/iraggr.h" #include "ir/iraggr.h"
#include "ir/irfunction.h" #include "ir/irfunction.h"
// in dmd/opover.d: using namespace dmd;
AggregateDeclaration *isAggregate(Type *t);
RTTIBuilder::RTTIBuilder(Type *baseType) { RTTIBuilder::RTTIBuilder(Type *baseType) {
const auto ad = isAggregate(baseType); const auto ad = isAggregate(baseType);
@ -114,7 +113,7 @@ void RTTIBuilder::push_array(llvm::Constant *CI, uint64_t dim, Type *valtype,
setLinkage(lwc, G); setLinkage(lwc, G);
G->setAlignment(llvm::MaybeAlign(DtoAlignment(valtype))); G->setAlignment(llvm::MaybeAlign(DtoAlignment(valtype)));
push_array(dim, DtoBitCast(G, DtoType(valtype->pointerTo()))); push_array(dim, DtoBitCast(G, DtoType(pointerTo(valtype))));
} }
void RTTIBuilder::push_array(uint64_t dim, llvm::Constant *ptr) { void RTTIBuilder::push_array(uint64_t dim, llvm::Constant *ptr) {

View file

@ -40,6 +40,8 @@
#include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/MemoryBuffer.h"
#include <algorithm> #include <algorithm>
using namespace dmd;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
static llvm::cl::opt<bool> nogc( static llvm::cl::opt<bool> nogc(
@ -221,7 +223,7 @@ public:
} }
for (int i = 0; i < numIndirections; ++i) for (int i = 0; i < numIndirections; ++i)
ty = ty->pointerTo(); ty = ::dmd::pointerTo(ty);
return ty; return ty;
} }
@ -491,7 +493,7 @@ static void buildRuntimeModule() {
Type *voidPtrTy = Type::tvoidptr; Type *voidPtrTy = Type::tvoidptr;
Type *voidArrayTy = Type::tvoid->arrayOf(); Type *voidArrayTy = Type::tvoid->arrayOf();
Type *voidArrayPtrTy = voidArrayTy->pointerTo(); Type *voidArrayPtrTy = pointerTo(voidArrayTy);
Type *stringTy = Type::tchar->arrayOf(); Type *stringTy = Type::tchar->arrayOf();
Type *wstringTy = Type::twchar->arrayOf(); Type *wstringTy = Type::twchar->arrayOf();
Type *dstringTy = Type::tdchar->arrayOf(); Type *dstringTy = Type::tdchar->arrayOf();
@ -620,7 +622,7 @@ static void buildRuntimeModule() {
// void _d_delmemory(void** p) // void _d_delmemory(void** p)
// void _d_delinterface(void** p) // void _d_delinterface(void** p)
createFwdDecl(LINK::c, voidTy, {"_d_delmemory", "_d_delinterface"}, createFwdDecl(LINK::c, voidTy, {"_d_delmemory", "_d_delinterface"},
{voidPtrTy->pointerTo()}); {pointerTo(voidPtrTy)});
// void _d_callfinalizer(void* p) // void _d_callfinalizer(void* p)
createFwdDecl(LINK::c, voidTy, {"_d_callfinalizer"}, {voidPtrTy}); createFwdDecl(LINK::c, voidTy, {"_d_callfinalizer"}, {voidPtrTy});
@ -630,7 +632,7 @@ static void buildRuntimeModule() {
// void _d_delstruct(void** p, TypeInfo_Struct inf) // void _d_delstruct(void** p, TypeInfo_Struct inf)
createFwdDecl(LINK::c, voidTy, {"_d_delstruct"}, createFwdDecl(LINK::c, voidTy, {"_d_delstruct"},
{voidPtrTy->pointerTo(), structTypeInfoTy}); {pointerTo(voidPtrTy), structTypeInfoTy});
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
@ -717,7 +719,7 @@ static void buildRuntimeModule() {
// void* _aaGetY(AA* aa, const TypeInfo aati, in size_t valuesize, // void* _aaGetY(AA* aa, const TypeInfo aati, in size_t valuesize,
// in void* pkey) // in void* pkey)
createFwdDecl(LINK::c, voidPtrTy, {"_aaGetY"}, createFwdDecl(LINK::c, voidPtrTy, {"_aaGetY"},
{aaTy->pointerTo(), aaTypeInfoTy, sizeTy, voidPtrTy}, {pointerTo(aaTy), aaTypeInfoTy, sizeTy, voidPtrTy},
{0, STCconst, STCin, STCin}, Attr_1_4_NoCapture); {0, STCconst, STCin, STCin}, Attr_1_4_NoCapture);
// inout(void)* _aaInX(inout AA aa, in TypeInfo keyti, in void* pkey) // inout(void)* _aaInX(inout AA aa, in TypeInfo keyti, in void* pkey)

View file

@ -41,6 +41,8 @@
#include <math.h> #include <math.h>
#include <stdio.h> #include <stdio.h>
using namespace dmd;
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
// FIXME: Integrate these functions // FIXME: Integrate these functions
void GccAsmStatement_toIR(GccAsmStatement *stmt, IRState *irs); void GccAsmStatement_toIR(GccAsmStatement *stmt, IRState *irs);

View file

@ -22,6 +22,7 @@
#include "gen/llvmhelpers.h" #include "gen/llvmhelpers.h"
#include <assert.h> #include <assert.h>
using namespace dmd;
using llvm::APFloat; using llvm::APFloat;
// in dmd/argtypes_x86.d: // in dmd/argtypes_x86.d:

View file

@ -32,6 +32,8 @@
#include "ir/irtype.h" #include "ir/irtype.h"
#include "llvm/IR/LLVMContext.h" #include "llvm/IR/LLVMContext.h"
using namespace dmd;
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
IrFuncTy &DtoIrTypeFunction(DValue *fnval) { IrFuncTy &DtoIrTypeFunction(DValue *fnval) {
@ -963,7 +965,7 @@ DValue *DtoCallFunction(const Loc &loc, Type *resulttype, DValue *fnval,
switch (rbase->ty) { switch (rbase->ty) {
case TY::Tarray: case TY::Tarray:
if (tf->isref()) { if (tf->isref()) {
retllval = DtoBitCast(retllval, DtoType(rbase->pointerTo())); retllval = DtoBitCast(retllval, DtoType(pointerTo(rbase)));
} else { } else {
retllval = DtoSlicePaint(retllval, DtoType(rbase)); retllval = DtoSlicePaint(retllval, DtoType(rbase));
} }
@ -972,7 +974,7 @@ DValue *DtoCallFunction(const Loc &loc, Type *resulttype, DValue *fnval,
case TY::Tsarray: case TY::Tsarray:
if (nextbase->ty == TY::Tvector && !tf->isref()) { if (nextbase->ty == TY::Tvector && !tf->isref()) {
if (retValIsLVal) { if (retValIsLVal) {
retllval = DtoBitCast(retllval, DtoType(rbase->pointerTo())); retllval = DtoBitCast(retllval, DtoType(pointerTo(rbase)));
} else { } else {
// static arrays need to be dumped to memory; use vector alignment // static arrays need to be dumped to memory; use vector alignment
retllval = retllval =
@ -988,7 +990,7 @@ DValue *DtoCallFunction(const Loc &loc, Type *resulttype, DValue *fnval,
case TY::Taarray: case TY::Taarray:
case TY::Tpointer: case TY::Tpointer:
if (tf->isref()) { if (tf->isref()) {
retllval = DtoBitCast(retllval, DtoType(rbase->pointerTo())); retllval = DtoBitCast(retllval, DtoType(pointerTo(rbase)));
} else { } else {
retllval = DtoBitCast(retllval, DtoType(rbase)); retllval = DtoBitCast(retllval, DtoType(rbase));
} }

View file

@ -25,6 +25,8 @@
#include "ir/irtypeclass.h" #include "ir/irtypeclass.h"
#include "ir/irtypestruct.h" #include "ir/irtypestruct.h"
using namespace dmd;
/// Emits an LLVM constant corresponding to the expression (or an error if /// Emits an LLVM constant corresponding to the expression (or an error if
/// impossible). /// impossible).
class ToConstElemVisitor : public Visitor { class ToConstElemVisitor : public Visitor {
@ -253,7 +255,7 @@ public:
e->type->toChars()); e->type->toChars());
LOG_SCOPE; LOG_SCOPE;
if (e->type->equivalent(e->e1->type)) { if (equivalent(e->type, e->e1->type)) {
if (!e->lwr && !e->upr) { if (!e->lwr && !e->upr) {
result = toConstElem(e->e1, p); result = toConstElem(e->e1, p);
return; return;
@ -425,7 +427,7 @@ public:
// gep // gep
LLConstant *idxs[2] = {DtoConstSize_t(0), index}; LLConstant *idxs[2] = {DtoConstSize_t(0), index};
LLConstant *val = isaConstant(getIrGlobal(vd)->value); LLConstant *val = isaConstant(getIrGlobal(vd)->value);
val = DtoBitCast(val, DtoType(vd->type->pointerTo())); val = DtoBitCast(val, DtoType(pointerTo(vd->type)));
LLConstant *gep = llvm::ConstantExpr::getGetElementPtr( LLConstant *gep = llvm::ConstantExpr::getGetElementPtr(
DtoType(vd->type), val, idxs, true); DtoType(vd->type), val, idxs, true);

View file

@ -56,6 +56,8 @@
#include <stack> #include <stack>
#include <stdio.h> #include <stdio.h>
using namespace dmd;
llvm::cl::opt<bool> checkPrintf( llvm::cl::opt<bool> checkPrintf(
"check-printf-calls", llvm::cl::ZeroOrMore, llvm::cl::ReallyHidden, "check-printf-calls", llvm::cl::ZeroOrMore, llvm::cl::ReallyHidden,
llvm::cl::desc("Validate printf call format strings against arguments")); llvm::cl::desc("Validate printf call format strings against arguments"));
@ -1249,7 +1251,7 @@ public:
// in this case, we also need to make sure the pointer is cast to the // in this case, we also need to make sure the pointer is cast to the
// innermost element type // innermost element type
eptr = DtoBitCast(eptr, DtoType(tsa->nextOf()->pointerTo())); eptr = DtoBitCast(eptr, DtoType(pointerTo(tsa->nextOf())));
} }
} }
@ -2074,7 +2076,7 @@ public:
LLValue *retPtr = nullptr; LLValue *retPtr = nullptr;
if (!(dtype->ty == TY::Tvoid || dtype->ty == TY::Tnoreturn)) { if (!(dtype->ty == TY::Tvoid || dtype->ty == TY::Tnoreturn)) {
// allocate a temporary for pointer to the final result. // allocate a temporary for pointer to the final result.
retPtr = DtoAlloca(dtype->pointerTo(), "condtmp"); retPtr = DtoAlloca(pointerTo(dtype), "condtmp");
} }
llvm::BasicBlock *condtrue = p->insertBB("condtrue"); llvm::BasicBlock *condtrue = p->insertBB("condtrue");
@ -2376,7 +2378,7 @@ public:
DtoMemSetZero(DtoType(e->type), dstMem); DtoMemSetZero(DtoType(e->type), dstMem);
} else { } else {
LLValue *initsym = getIrAggr(sd)->getInitSymbol(); LLValue *initsym = getIrAggr(sd)->getInitSymbol();
initsym = DtoBitCast(initsym, DtoType(e->type->pointerTo())); initsym = DtoBitCast(initsym, DtoType(pointerTo(e->type)));
assert(dstMem->getType() == initsym->getType()); assert(dstMem->getType() == initsym->getType());
DtoMemCpy(DtoType(e->type), dstMem, initsym); DtoMemCpy(DtoType(e->type), dstMem, initsym);
} }
@ -2811,11 +2813,11 @@ public:
// to an Interface instance, which has the type info as its first // to an Interface instance, which has the type info as its first
// member, so we have to add an extra layer of indirection. // member, so we have to add an extra layer of indirection.
resultType = getInterfaceTypeInfoType(); resultType = getInterfaceTypeInfoType();
LLType *pres = DtoType(resultType->pointerTo()); LLType *pres = DtoType(pointerTo(resultType));
typinf = DtoLoad(pres, DtoBitCast(typinf, pres->getPointerTo())); typinf = DtoLoad(pres, DtoBitCast(typinf, pres->getPointerTo()));
} else { } else {
resultType = getClassInfoType(); resultType = getClassInfoType();
typinf = DtoBitCast(typinf, DtoType(resultType->pointerTo())); typinf = DtoBitCast(typinf, DtoType(pointerTo(resultType)));
} }
result = new DLValue(resultType, typinf); result = new DLValue(resultType, typinf);

View file

@ -58,6 +58,8 @@
#include <cassert> #include <cassert>
#include <cstdio> #include <cstdio>
using namespace dmd;
TypeInfoDeclaration *getOrCreateTypeInfoDeclaration(const Loc &loc, Type *forType) { TypeInfoDeclaration *getOrCreateTypeInfoDeclaration(const Loc &loc, Type *forType) {
IF_LOG Logger::println("getOrCreateTypeInfoDeclaration(): %s", IF_LOG Logger::println("getOrCreateTypeInfoDeclaration(): %s",
forType->toChars()); forType->toChars());
@ -343,7 +345,7 @@ public:
RTTIBuilder b(getConstTypeInfoType()); RTTIBuilder b(getConstTypeInfoType());
// TypeInfo base // TypeInfo base
b.push_typeinfo(merge(decl->tinfo->mutableOf())); b.push_typeinfo(merge(mutableOf(decl->tinfo)));
// finish // finish
b.finalize(gvar); b.finalize(gvar);
} }
@ -357,7 +359,7 @@ public:
RTTIBuilder b(getInvariantTypeInfoType()); RTTIBuilder b(getInvariantTypeInfoType());
// TypeInfo base // TypeInfo base
b.push_typeinfo(merge(decl->tinfo->mutableOf())); b.push_typeinfo(merge(mutableOf(decl->tinfo)));
// finish // finish
b.finalize(gvar); b.finalize(gvar);
} }
@ -371,7 +373,7 @@ public:
RTTIBuilder b(getSharedTypeInfoType()); RTTIBuilder b(getSharedTypeInfoType());
// TypeInfo base // TypeInfo base
b.push_typeinfo(merge(decl->tinfo->unSharedOf())); b.push_typeinfo(merge(unSharedOf(decl->tinfo)));
// finish // finish
b.finalize(gvar); b.finalize(gvar);
} }
@ -385,7 +387,7 @@ public:
RTTIBuilder b(getInoutTypeInfoType()); RTTIBuilder b(getInoutTypeInfoType());
// TypeInfo base // TypeInfo base
b.push_typeinfo(merge(decl->tinfo->mutableOf())); b.push_typeinfo(merge(mutableOf(decl->tinfo)));
// finish // finish
b.finalize(gvar); b.finalize(gvar);
} }

View file

@ -18,8 +18,6 @@ struct Loc;
class Type; class Type;
class TypeInfoDeclaration; class TypeInfoDeclaration;
bool builtinTypeInfo(Type *t); // in dmd/typinf.d
namespace llvm { namespace llvm {
class GlobalVariable; class GlobalVariable;
} }

View file

@ -17,6 +17,8 @@
#include "llvm/ADT/StringExtras.h" #include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringSwitch.h" #include "llvm/ADT/StringSwitch.h"
using namespace dmd;
namespace { namespace {
/// Checks whether `moduleDecl` is in the ldc package and it's identifier is /// Checks whether `moduleDecl` is in the ldc package and it's identifier is

View file

@ -28,6 +28,8 @@
#include "ir/irtypestruct.h" #include "ir/irtypestruct.h"
#include <algorithm> #include <algorithm>
using namespace dmd;
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
llvm::StructType *IrAggr::getLLStructType() { llvm::StructType *IrAggr::getLLStructType() {

View file

@ -40,6 +40,8 @@
#include "llvm/Support/raw_ostream.h" #include "llvm/Support/raw_ostream.h"
#endif #endif
using namespace dmd;
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
IrClass::IrClass(ClassDeclaration *cd) : IrAggr(cd) { IrClass::IrClass(ClassDeclaration *cd) : IrAggr(cd) {
@ -217,7 +219,7 @@ LLConstant *IrClass::getVtblInit() {
// it is probably a bug that it still occurs that late. // it is probably a bug that it still occurs that late.
if (fd->inferRetType() && !fd->type->nextOf()) { if (fd->inferRetType() && !fd->type->nextOf()) {
Logger::println("Running late functionSemantic to infer return type."); Logger::println("Running late functionSemantic to infer return type.");
if (!fd->functionSemantic()) { if (!functionSemantic(fd)) {
if (fd->hasSemantic3Errors()) { if (fd->hasSemantic3Errors()) {
Logger::println( Logger::println(
"functionSemantic failed; using null for vtbl entry."); "functionSemantic failed; using null for vtbl entry.");
@ -247,8 +249,8 @@ LLConstant *IrClass::getVtblInit() {
if (fd2->isFuture()) { if (fd2->isFuture()) {
continue; continue;
} }
if (fd->leastAsSpecialized(fd2, nullptr) != MATCH::nomatch || if (FuncDeclaration::leastAsSpecialized(fd, fd2, nullptr) != MATCH::nomatch ||
fd2->leastAsSpecialized(fd, nullptr) != MATCH::nomatch) { FuncDeclaration::leastAsSpecialized(fd2, fd, nullptr) != MATCH::nomatch) {
TypeFunction *tf = static_cast<TypeFunction *>(fd->type); TypeFunction *tf = static_cast<TypeFunction *>(fd->type);
if (tf->ty == TY::Tfunction) { if (tf->ty == TY::Tfunction) {
error(cd->loc, error(cd->loc,
@ -705,7 +707,7 @@ LLConstant *IrClass::getClassInfoInterfaces() {
constants.reserve(cd->vtblInterfaces->length); constants.reserve(cd->vtblInterfaces->length);
LLType *classinfo_type = DtoType(getClassInfoType()); LLType *classinfo_type = DtoType(getClassInfoType());
LLType *voidptrptr_type = DtoType(Type::tvoid->pointerTo()->pointerTo()); LLType *voidptrptr_type = DtoType(pointerTo(pointerTo(Type::tvoid)));
LLStructType *interface_type = LLStructType *interface_type =
isaStruct(DtoType(interfacesArrayType->nextOf())); isaStruct(DtoType(interfacesArrayType->nextOf()));
assert(interface_type); assert(interface_type);

View file

@ -17,9 +17,11 @@
#include "gen/logger.h" #include "gen/logger.h"
#include "gen/tollvm.h" #include "gen/tollvm.h"
using namespace dmd;
IrFuncTyArg::IrFuncTyArg(Type *t, bool bref) IrFuncTyArg::IrFuncTyArg(Type *t, bool bref)
: type(t), : type(t),
ltype(t != Type::tvoid && bref ? DtoType(t->pointerTo()) : DtoType(t)), ltype(t != Type::tvoid && bref ? DtoType(pointerTo(t)) : DtoType(t)),
#if LDC_LLVM_VER >= 1400 #if LDC_LLVM_VER >= 1400
attrs(getGlobalContext()), attrs(getGlobalContext()),
#endif #endif
@ -29,7 +31,7 @@ IrFuncTyArg::IrFuncTyArg(Type *t, bool bref)
IrFuncTyArg::IrFuncTyArg(Type *t, bool bref, llvm::AttrBuilder a) IrFuncTyArg::IrFuncTyArg(Type *t, bool bref, llvm::AttrBuilder a)
: type(t), : type(t),
ltype(t != Type::tvoid && bref ? DtoType(t->pointerTo()) : DtoType(t)), ltype(t != Type::tvoid && bref ? DtoType(pointerTo(t)) : DtoType(t)),
attrs(std::move(a)), byref(bref) { attrs(std::move(a)), byref(bref) {
mem.addRange(&type, sizeof(type)); mem.addRange(&type, sizeof(type));

View file

@ -23,8 +23,7 @@
#include "ir/iraggr.h" #include "ir/iraggr.h"
#include "ir/irtypeclass.h" #include "ir/irtypeclass.h"
// in semantic3.d using namespace dmd;
void semanticTypeInfoMembers(StructDeclaration *sd);
namespace { namespace {
LLStructType* getTypeInfoStructMemType() { LLStructType* getTypeInfoStructMemType() {
@ -156,7 +155,7 @@ LLConstant *IrStruct::getTypeInfoInit() {
b.push_funcptr(isOpaque ? nullptr : search_toString(sd)); b.push_funcptr(isOpaque ? nullptr : search_toString(sd));
// StructFlags m_flags // StructFlags m_flags
b.push_uint(!isOpaque && ts->hasPointers() ? 1 : 0); b.push_uint(!isOpaque && hasPointers(ts) ? 1 : 0);
// function xdtor/xdtorti // function xdtor/xdtorti
b.push_funcptr(isOpaque ? nullptr : sd->tidtor); b.push_funcptr(isOpaque ? nullptr : sd->tidtor);
@ -188,7 +187,7 @@ LLConstant *IrStruct::getTypeInfoInit() {
if (!isOpaque && sd->getRTInfo) { if (!isOpaque && sd->getRTInfo) {
b.push(toConstElem(sd->getRTInfo, gIR)); b.push(toConstElem(sd->getRTInfo, gIR));
} else { } else {
b.push_size_as_vp(!isOpaque && ts->hasPointers() ? 1 : 0); b.push_size_as_vp(!isOpaque && hasPointers(ts) ? 1 : 0);
} }
constTypeInfo = b.get_constant(getTypeInfoStructMemType()); constTypeInfo = b.get_constant(getTypeInfoStructMemType());

View file

@ -15,6 +15,8 @@
#include "gen/tollvm.h" #include "gen/tollvm.h"
#include "llvm/IR/DerivedTypes.h" #include "llvm/IR/DerivedTypes.h"
using namespace dmd;
IrTypeFunction::IrTypeFunction(Type *dt, llvm::Type *lt, IrFuncTy irFty_) IrTypeFunction::IrTypeFunction(Type *dt, llvm::Type *lt, IrFuncTy irFty_)
: IrType(dt, lt), irFty(std::move(irFty_)) {} : IrType(dt, lt), irFty(std::move(irFty_)) {}
@ -52,7 +54,7 @@ IrTypeDelegate *IrTypeDelegate::get(Type *t) {
IrFuncTy irFty(tf); IrFuncTy irFty(tf);
llvm::Type *ltf = llvm::Type *ltf =
DtoFunctionType(tf, irFty, nullptr, Type::tvoid->pointerTo()); DtoFunctionType(tf, irFty, nullptr, pointerTo(Type::tvoid));
llvm::Type *fptr = ltf->getPointerTo(gDataLayout->getProgramAddressSpace()); llvm::Type *fptr = ltf->getPointerTo(gDataLayout->getProgramAddressSpace());
llvm::Type *types[] = {getVoidPtrType(), fptr}; llvm::Type *types[] = {getVoidPtrType(), fptr};
LLStructType *lt = LLStructType::get(gIR->context(), types, false); LLStructType *lt = LLStructType::get(gIR->context(), types, false);