Permalink
Browse files

Added IrTypeFunction and IrTypeDelegate and eliminated IrDType. This …

…means the Type::ir field can be removed. It's the final part needed for the move to a slightly more sane type system. Now the whole thing just needs to be cleaned up :P

Added -v-cg switch, which right now just prints "codegen: module.name (module/name.d)" to stdout, this can really help figuring out where, in some complex build command, things go wrong.
  • Loading branch information...
1 parent 6151456 commit c0f2af5afd0411f0a54068f190471f9ccd6b97b9 @lindquist lindquist committed May 16, 2009
Showing with 148 additions and 129 deletions.
  1. +2 −3 dmd/dsymbol.h
  2. +1 −0 dmd/mars.h
  3. +1 −1 dmd/module.h
  4. +1 −7 dmd/mtype.h
  5. +5 −0 gen/cl_options.cpp
  6. +7 −45 gen/functions.cpp
  7. +13 −1 gen/functions.h
  8. +2 −3 gen/tocall.cpp
  9. +6 −30 gen/tollvm.cpp
  10. +0 −1 gen/tollvm.h
  11. +5 −3 gen/toobj.cpp
  12. +8 −7 gen/typinf.cpp
  13. +2 −1 ir/ir.h
  14. +0 −8 ir/irdtype.cpp
  15. +0 −16 ir/irdtype.h
  16. +2 −1 ir/irsymbol.h
  17. +1 −2 ir/irtype.cpp
  18. +3 −0 ir/irtype.h
  19. +47 −0 ir/irtypefunction.cpp
  20. +42 −0 ir/irtypefunction.h
View
@@ -82,10 +82,9 @@ typedef union tree_node TYPE;
struct TYPE;
#endif
-// llvm
#if IN_LLVM
-struct Ir;
-struct IrSymbol;
+class Ir;
+class IrSymbol;
namespace llvm
{
class Value;
View
@@ -219,6 +219,7 @@ struct Param
OUTPUTFLAG output_o;
bool llvmAnnotate;
bool useInlineAsm;
+ bool verbose_cg;
// target stuff
const char* llvmArch;
View
@@ -28,7 +28,7 @@ struct Library;
// Back end
#if IN_LLVM
-struct Ir;
+class Ir;
struct DValue;
typedef DValue elem;
namespace llvm { class Module; }
View
@@ -22,12 +22,9 @@
#include "expression.h"
#if IN_LLVM
-// llvm
-#include "../ir/irdtype.h"
#include "../ir/irfuncty.h"
namespace llvm { class Type; }
-struct Ir;
-
+class Ir;
class IrType;
#endif
@@ -284,10 +281,7 @@ struct Type : Object
virtual TypeBasic *isTypeBasic();
#if IN_LLVM
- // LDC
- IrDType ir;
static Ir* sir;
-
IrType* irtype;
#endif
};
View
@@ -44,6 +44,11 @@ static cl::opt<bool, true> verbose("v",
cl::ZeroOrMore,
cl::location(global.params.verbose));
+static cl::opt<bool, true> verbose_cg("v-cg",
+ cl::desc("Verbose codegen"),
+ cl::ZeroOrMore,
+ cl::location(global.params.verbose_cg));
+
static cl::opt<bool, true> warnings("w",
cl::desc("Enable warnings"),
cl::ZeroOrMore,
View
@@ -27,15 +27,10 @@ using namespace llvm::Attribute;
const llvm::FunctionType* DtoFunctionType(Type* type, Type* thistype, Type* nesttype, bool ismain)
{
- // already built ?
- if (type->ir.type != NULL) {
- //assert(f->fty != NULL);
- return llvm::cast<llvm::FunctionType>(type->ir.type->get());
- }
-
if (Logger::enabled())
Logger::println("DtoFunctionType(%s)", type->toChars());
LOG_SCOPE
+
// sanity check
assert(type->ty == Tfunction);
TypeFunction* f = (TypeFunction*)type;
@@ -165,27 +160,6 @@ const llvm::FunctionType* DtoFunctionType(Type* type, Type* thistype, Type* nest
lidx++;
}
- // If the function type was forward referenced by one of the parameter types,
- // it has now been set.
- if (f->ir.type) {
- // Notify ABI that we won't be needing it for this function type anymore.
- abi->doneWithFunctionType();
-
- // Some cleanup of memory we won't use
- delete fty.ret;
- delete fty.arg_sret;
- delete fty.arg_this;
- delete fty.arg_nest;
- delete fty.arg_arguments;
- delete fty.arg_argptr;
- for (IrFuncTy::ArgIter It = fty.args.begin(), E = fty.args.end(); It != E; ++It) {
- delete *It;
- }
-
- Logger::cout() << "Final function type: " << **f->ir.type << '\n';
- return llvm::cast<LLFunctionType>(*f->ir.type);
- }
-
// Now we can modify f->fty safely.
f->fty = fty;
@@ -219,7 +193,6 @@ const llvm::FunctionType* DtoFunctionType(Type* type, Type* thistype, Type* nest
}
llvm::FunctionType* functype = llvm::FunctionType::get(f->fty.ret->ltype, argtypes, f->fty.c_vararg);
- f->ir.type = new llvm::PATypeHolder(functype);
#if 0
Logger::cout() << "Final function type: " << *functype << "\n";
@@ -232,11 +205,6 @@ const llvm::FunctionType* DtoFunctionType(Type* type, Type* thistype, Type* nest
static const llvm::FunctionType* DtoVaFunctionType(FuncDeclaration* fdecl)
{
- // type has already been resolved
- if (fdecl->type->ir.type != 0) {
- return llvm::cast<llvm::FunctionType>(fdecl->type->ir.type->get());
- }
-
TypeFunction* f = (TypeFunction*)fdecl->type;
const llvm::FunctionType* fty = 0;
@@ -256,18 +224,13 @@ static const llvm::FunctionType* DtoVaFunctionType(FuncDeclaration* fdecl)
fty = GET_INTRINSIC_DECL(vaend)->getFunctionType();
assert(fty);
- f->ir.type = new llvm::PATypeHolder(fty);
return fty;
}
//////////////////////////////////////////////////////////////////////////////////////////
const llvm::FunctionType* DtoFunctionType(FuncDeclaration* fdecl)
{
- // type has already been resolved
- if (fdecl->type->ir.type != 0)
- return llvm::cast<llvm::FunctionType>(fdecl->type->ir.type->get());
-
// handle for C vararg intrinsics
if (fdecl->isVaIntrinsic())
return DtoVaFunctionType(fdecl);
@@ -280,7 +243,7 @@ const llvm::FunctionType* DtoFunctionType(FuncDeclaration* fdecl)
dthis = ad->type;
const LLType* thisty = DtoType(dthis);
//Logger::cout() << "this llvm type: " << *thisty << '\n';
- if (isaStruct(thisty) || (!gIR->structs.empty() && thisty == gIR->topstruct()->type->ir.type->get()))
+ if (ad->isStructDeclaration())
thisty = getPtrToType(thisty);
}
else {
@@ -326,6 +289,9 @@ void DtoResolveFunction(FuncDeclaration* fdecl)
return; // ignore declaration completely
}
+ if (fdecl->ir.resolved) return;
+ fdecl->ir.resolved = true;
+
//printf("resolve function: %s\n", fdecl->toPrettyChars());
if (fdecl->parent)
@@ -373,10 +339,7 @@ void DtoResolveFunction(FuncDeclaration* fdecl)
}
}
- DtoFunctionType(fdecl);
-
- if (fdecl->ir.resolved) return;
- fdecl->ir.resolved = true;
+ DtoType(fdecl->type);
Logger::println("DtoResolveFunction(%s): %s", fdecl->toPrettyChars(), fdecl->loc.toChars());
LOG_SCOPE;
@@ -515,7 +478,6 @@ void DtoDeclareFunction(FuncDeclaration* fdecl)
func->setCallingConv(llvm::CallingConv::C);
fdecl->ir.irFunc->func = func;
- assert(llvm::isa<llvm::FunctionType>(f->ir.type->get()));
// parameter attributes
if (!fdecl->isIntrinsic()) {
@@ -646,7 +608,7 @@ void DtoDefineFunction(FuncDeclaration* fd)
Type* t = fd->type->toBasetype();
TypeFunction* f = (TypeFunction*)t;
- assert(f->ir.type);
+ assert(f->irtype);
llvm::Function* func = fd->ir.irFunc->func;
const llvm::FunctionType* functype = func->getFunctionType();
View
@@ -1,6 +1,18 @@
#ifndef LDC_GEN_FUNCTIONS_H
#define LDC_GEN_FUNCTIONS_H
+#include "mars.h"
+
+struct FuncDeclaration;
+struct Type;
+
+struct IRAsmBlock;
+
+namespace llvm
+{
+ class Value;
+}
+
const llvm::FunctionType* DtoFunctionType(Type* t, Type* thistype, Type* nesttype, bool ismain = false);
const llvm::FunctionType* DtoFunctionType(FuncDeclaration* fdecl);
@@ -14,6 +26,6 @@ void DtoDefineNakedFunction(FuncDeclaration* fd);
void emitABIReturnAsmStmt(IRAsmBlock* asmblock, Loc loc, FuncDeclaration* fdecl);
DValue* DtoArgument(Argument* fnarg, Expression* argexp);
-void DtoVariadicArgument(Expression* argexp, LLValue* dst);
+void DtoVariadicArgument(Expression* argexp, llvm::Value* dst);
#endif
View
@@ -260,9 +260,8 @@ DValue* DtoCallFunction(Loc& loc, Type* resulttype, DValue* fnval, Expressions*
// the callee D type
Type* calleeType = fnval->getType();
- // if the type has not yet been processed, do so now
- if (calleeType->ir.type == NULL)
- DtoType(calleeType);
+ // make sure the callee type has been processed
+ DtoType(calleeType);
// get func value if any
DFuncValue* dfnval = fnval->isFunc();
View
@@ -24,6 +24,7 @@
#include "ir/irtype.h"
#include "ir/irtypeclass.h"
+#include "ir/irtypefunction.h"
bool DtoIsPassedByRef(Type* type)
{
@@ -131,27 +132,15 @@ const LLType* DtoType(Type* t)
// functions
case Tfunction:
{
- if (!t->ir.type || *t->ir.type == NULL) {
- TypeFunction* tf = (TypeFunction*)t;
- if (tf->funcdecl)
- return DtoFunctionType(tf->funcdecl);
- else
- return DtoFunctionType(tf,NULL,NULL);
- }
- else {
- return t->ir.type->get();
- }
+ t->irtype = new IrTypeFunction(t);
+ return t->irtype->buildType();
}
// delegates
case Tdelegate:
{
- if (!t->ir.type || *t->ir.type == NULL) {
- return DtoDelegateType(t);
- }
- else {
- return t->ir.type->get();
- }
+ t->irtype = new IrTypeDelegate(t);
+ return t->irtype->buildType();
}
// typedefs
@@ -220,19 +209,6 @@ const LLType* DtoTypeNotVoid(Type* t)
//////////////////////////////////////////////////////////////////////////////////////////
-const LLStructType* DtoDelegateType(Type* t)
-{
- assert(t->ty == Tdelegate);
- const LLType* i8ptr = getVoidPtrType();
- const LLType* func = DtoFunctionType(t->nextOf(), NULL, Type::tvoid->pointerTo());
- const LLType* funcptr = getPtrToType(func);
- const LLStructType* dgtype = LLStructType::get(i8ptr, funcptr, NULL);
- gIR->module->addTypeName(t->toChars(), dgtype);
- return dgtype;
-}
-
-//////////////////////////////////////////////////////////////////////////////////////////
-
LLValue* DtoDelegateEquals(TOK op, LLValue* lhs, LLValue* rhs)
{
Logger::println("Doing delegate equality");
@@ -799,7 +775,7 @@ const LLStructType* DtoInterfaceInfoType()
// ClassInfo classinfo
ClassDeclaration* cd2 = ClassDeclaration::classinfo;
DtoResolveClass(cd2);
- types.push_back(getPtrToType(cd2->type->ir.type->get()));
+ types.push_back(DtoType(cd2->type));
// void*[] vtbl
std::vector<const LLType*> vtbltypes;
vtbltypes.push_back(DtoSize_t());
View
@@ -26,7 +26,6 @@ unsigned DtoShouldExtend(Type* type);
//const LLType* DtoStructTypeFromArguments(Arguments* arguments);
// delegate helpers
-const LLStructType* DtoDelegateType(Type* t);
LLValue* DtoDelegateEquals(TOK op, LLValue* lhs, LLValue* rhs);
// return linkage type for symbol using the current ir state for context
View
@@ -54,6 +54,7 @@
#include "ir/irvar.h"
#include "ir/irmodule.h"
+#include "ir/irtype.h"
//////////////////////////////////////////////////////////////////////////////////////////
@@ -80,7 +81,8 @@ llvm::Module* Module::genLLVMModule(Ir* sir)
Logger::println("Generating module: %s\n", (md ? md->toChars() : toChars()));
LOG_SCOPE;
- //printf("codegen: %s\n", srcfile->toChars());
+ if (global.params.verbose_cg)
+ printf("codegen: %s (%s)\n", toPrettyChars(), srcfile->toChars());
assert(!global.errors);
@@ -609,9 +611,9 @@ void Module::genmoduleinfo()
}
// moduleinfo llvm struct type
- const llvm::StructType* moduleinfoTy = isaStruct(moduleinfo->type->ir.type->get());
+ const llvm::StructType* moduleinfoTy = isaStruct(moduleinfo->type->irtype->getPA());
// classinfo llvm struct type
- const llvm::StructType* classinfoTy = isaStruct(ClassDeclaration::classinfo->type->ir.type->get());
+ const llvm::StructType* classinfoTy = isaStruct(ClassDeclaration::classinfo->type->irtype->getPA());
// initializer vector
std::vector<LLConstant*> initVec;
Oops, something went wrong.

0 comments on commit c0f2af5

Please sign in to comment.