mirror of
https://github.com/ldc-developers/ldc.git
synced 2025-05-06 19:06:02 +03:00
[svn r250] Fixed the warning about dropping arguments to _Dmain when optimizing.
Did a few cleanups in inline asm code.
This commit is contained in:
parent
68d7827d35
commit
28382e3567
8 changed files with 45 additions and 135 deletions
|
@ -15,15 +15,20 @@
|
|||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
const llvm::StructType* DtoArrayType(Type* t)
|
||||
const llvm::StructType* DtoArrayType(Type* arrayTy)
|
||||
{
|
||||
assert(t->next);
|
||||
const LLType* elemty = DtoType(t->next);
|
||||
assert(arrayTy->next);
|
||||
const LLType* elemty = DtoType(arrayTy->next);
|
||||
if (elemty == llvm::Type::VoidTy)
|
||||
elemty = llvm::Type::Int8Ty;
|
||||
return llvm::StructType::get(DtoSize_t(), getPtrToType(elemty), 0);
|
||||
}
|
||||
|
||||
const llvm::StructType* DtoArrayType(const LLType* t)
|
||||
{
|
||||
return llvm::StructType::get(DtoSize_t(), getPtrToType(t), 0);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
const llvm::ArrayType* DtoStaticArrayType(Type* t)
|
||||
|
|
|
@ -3,8 +3,9 @@
|
|||
|
||||
struct DSliceValue;
|
||||
|
||||
const llvm::StructType* DtoArrayType(Type* t);
|
||||
const llvm::ArrayType* DtoStaticArrayType(Type* t);
|
||||
const llvm::StructType* DtoArrayType(Type* arrayTy);
|
||||
const llvm::StructType* DtoArrayType(const LLType* elemTy);
|
||||
const llvm::ArrayType* DtoStaticArrayType(Type* sarrayTy);
|
||||
|
||||
LLConstant* DtoConstArrayInitializer(ArrayInitializer* si);
|
||||
LLConstant* DtoConstSlice(LLConstant* dim, LLConstant* ptr);
|
||||
|
|
|
@ -157,6 +157,7 @@ static unsigned d_priv_asm_label_serial = 0;
|
|||
static void d_format_priv_asm_label(char * buf, unsigned n)
|
||||
{
|
||||
//ASM_GENERATE_INTERNAL_LABEL(buf, "LDASM", n);//inserts a '*' for use with assemble_name
|
||||
assert(0);
|
||||
sprintf(buf, ".LDASM%u", n);
|
||||
}
|
||||
|
||||
|
@ -270,42 +271,13 @@ std::cout << std::endl;
|
|||
cns = i_cns;
|
||||
break;
|
||||
case Arg_Pointer:
|
||||
// FIXME
|
||||
std::cout << "asm fixme Arg_Pointer" << std::endl;
|
||||
if (arg->expr->op == TOKdsymbol)
|
||||
{
|
||||
assert(0);
|
||||
DsymbolExp* dse = (DsymbolExp*)arg->expr;
|
||||
LabelDsymbol* lbl = dse->s->isLabel();
|
||||
assert(lbl);
|
||||
arg_val = lbl->statement->llvmBB;
|
||||
if (!arg_val)
|
||||
{
|
||||
arg_val = lbl->statement->llvmBB = llvm::BasicBlock::Create("label", irs->topfunc());
|
||||
}
|
||||
cns = l_cns;
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(arg->expr->op == TOKvar);
|
||||
arg_val = arg->expr->toElem(irs)->getRVal();
|
||||
cns = p_cns;
|
||||
}
|
||||
/*if (arg->expr->op == TOKvar)
|
||||
arg_val = arg->expr->toElem(irs);
|
||||
else if (arg->expr->op == TOKdsymbol)
|
||||
arg_val = arg->expr->toElem(irs);
|
||||
else
|
||||
assert(0);*/
|
||||
|
||||
break;
|
||||
case Arg_Memory:
|
||||
// FIXME
|
||||
std::cout << "asm fixme Arg_Memory" << std::endl;
|
||||
arg_val = arg->expr->toElem(irs)->getRVal();
|
||||
// if (arg->expr->op == TOKvar)
|
||||
// arg_val = arg->expr->toElem(irs);
|
||||
// else
|
||||
// arg_val = arg->expr->toElem(irs);
|
||||
|
||||
switch (arg->mode) {
|
||||
case Mode_Input: cns = m_cns; break;
|
||||
|
@ -471,8 +443,8 @@ static void remap_outargs(std::string& insnt, size_t nargs, size_t& idx)
|
|||
};
|
||||
assert(nargs <= 10);
|
||||
|
||||
static const std::string prefix("<<<out");
|
||||
static const std::string suffix(">>>");
|
||||
static const std::string prefix("<<out");
|
||||
static const std::string suffix(">>");
|
||||
std::string argnum;
|
||||
std::string needle;
|
||||
char buf[10];
|
||||
|
@ -493,8 +465,8 @@ static void remap_inargs(std::string& insnt, size_t nargs, size_t& idx)
|
|||
};
|
||||
assert(nargs <= 10);
|
||||
|
||||
static const std::string prefix("<<<in");
|
||||
static const std::string suffix(">>>");
|
||||
static const std::string prefix("<<in");
|
||||
static const std::string suffix(">>");
|
||||
std::string argnum;
|
||||
std::string needle;
|
||||
char buf[10];
|
||||
|
|
|
@ -1408,12 +1408,12 @@ struct AsmProcessor
|
|||
|
||||
void addOperand(const char * fmt, AsmArgType type, Expression * e, AsmCode * asmcode, AsmArgMode mode = Mode_Input) {
|
||||
insnTemplate->writestring((char*) fmt);
|
||||
insnTemplate->printf("<<<%s%d>>>", (mode==Mode_Input)?"in":"out", asmcode->args.dim);
|
||||
insnTemplate->printf("<<%s%d>>", (mode==Mode_Input)?"in":"out", asmcode->args.dim);
|
||||
asmcode->args.push( new AsmArg(type, e, mode) );
|
||||
}
|
||||
void addOperand2(const char * fmtpre, const char * fmtpost, AsmArgType type, Expression * e, AsmCode * asmcode, AsmArgMode mode = Mode_Input) {
|
||||
insnTemplate->writestring((char*) fmtpre);
|
||||
insnTemplate->printf("<<<%s%d>>>", (mode==Mode_Input)?"in":"out", asmcode->args.dim);
|
||||
insnTemplate->printf("<<%s%d>>", (mode==Mode_Input)?"in":"out", asmcode->args.dim);
|
||||
insnTemplate->writestring((char*) fmtpost);
|
||||
asmcode->args.push( new AsmArg(type, e, mode) );
|
||||
}
|
||||
|
@ -1427,7 +1427,7 @@ struct AsmProcessor
|
|||
}
|
||||
|
||||
void addLabel(char* id) {
|
||||
insnTemplate->writestring(".LDASM");
|
||||
insnTemplate->writestring(".LDASM_");
|
||||
insnTemplate->writestring(id);
|
||||
}
|
||||
|
||||
|
|
|
@ -44,9 +44,19 @@ const llvm::FunctionType* DtoFunctionType(Type* type, const LLType* thistype, bo
|
|||
bool retinptr = false;
|
||||
bool usesthis = false;
|
||||
|
||||
if (ismain) {
|
||||
// parameter types
|
||||
std::vector<const LLType*> paramvec;
|
||||
|
||||
if (ismain)
|
||||
{
|
||||
rettype = llvm::Type::Int32Ty;
|
||||
actualRettype = rettype;
|
||||
if (Argument::dim(f->parameters) == 0)
|
||||
{
|
||||
const LLType* arrTy = DtoArrayType(LLType::Int8Ty);
|
||||
const LLType* arrArrTy = DtoArrayType(arrTy);
|
||||
paramvec.push_back(getPtrToType(arrArrTy));
|
||||
}
|
||||
}
|
||||
else{
|
||||
assert(rt);
|
||||
|
@ -62,9 +72,6 @@ const llvm::FunctionType* DtoFunctionType(Type* type, const LLType* thistype, bo
|
|||
}
|
||||
}
|
||||
|
||||
// parameter types
|
||||
std::vector<const LLType*> paramvec;
|
||||
|
||||
if (retinptr) {
|
||||
//Logger::cout() << "returning through pointer parameter: " << *rettype << '\n';
|
||||
paramvec.push_back(rettype);
|
||||
|
@ -403,6 +410,16 @@ void DtoDeclareFunction(FuncDeclaration* fdecl)
|
|||
|
||||
int nbyval = 0;
|
||||
|
||||
if (fdecl->isMain() && Argument::dim(f->parameters) == 0)
|
||||
{
|
||||
llvm::ParamAttrsWithIndex PAWI;
|
||||
PAWI.Index = llidx;
|
||||
PAWI.Attrs = llvm::ParamAttr::ByVal;
|
||||
attrs.push_back(PAWI);
|
||||
llidx++;
|
||||
nbyval++;
|
||||
}
|
||||
|
||||
for (; llidx <= funcNumArgs && f->parameters->dim > k; ++llidx,++k)
|
||||
{
|
||||
Argument* fnarg = (Argument*)f->parameters->data[k];
|
||||
|
@ -714,84 +731,6 @@ void DtoDefineFunc(FuncDeclaration* fd)
|
|||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void DtoMain()
|
||||
{
|
||||
// emit main function llvm style
|
||||
// int main(int argc, char**argv, char**env);
|
||||
|
||||
assert(gIR != 0);
|
||||
IRState& ir = *gIR;
|
||||
|
||||
assert(ir.emitMain && ir.mainFunc);
|
||||
|
||||
// parameter types
|
||||
std::vector<const LLType*> pvec;
|
||||
pvec.push_back((const LLType*)llvm::Type::Int32Ty);
|
||||
const LLType* chPtrType = (const LLType*)getPtrToType(llvm::Type::Int8Ty);
|
||||
pvec.push_back((const LLType*)getPtrToType(chPtrType));
|
||||
pvec.push_back((const LLType*)getPtrToType(chPtrType));
|
||||
const LLType* rettype = (const LLType*)llvm::Type::Int32Ty;
|
||||
|
||||
llvm::FunctionType* functype = llvm::FunctionType::get(rettype, pvec, false);
|
||||
llvm::Function* func = llvm::Function::Create(functype,llvm::GlobalValue::ExternalLinkage,"main",ir.module);
|
||||
|
||||
llvm::BasicBlock* bb = llvm::BasicBlock::Create("entry",func);
|
||||
|
||||
// call static ctors
|
||||
llvm::Function* fn = LLVM_D_GetRuntimeFunction(ir.module,"_moduleCtor");
|
||||
llvm::Instruction* apt = llvm::CallInst::Create(fn,"",bb);
|
||||
|
||||
// run unit tests if -unittest is provided
|
||||
if (global.params.useUnitTests) {
|
||||
fn = LLVM_D_GetRuntimeFunction(ir.module,"_moduleUnitTests");
|
||||
llvm::Instruction* apt = llvm::CallInst::Create(fn,"",bb);
|
||||
}
|
||||
|
||||
// call user main function
|
||||
const llvm::FunctionType* mainty = ir.mainFunc->getFunctionType();
|
||||
llvm::CallInst* call;
|
||||
if (mainty->getNumParams() > 0)
|
||||
{
|
||||
// main with arguments
|
||||
assert(mainty->getNumParams() == 1);
|
||||
std::vector<LLValue*> args;
|
||||
llvm::Function* mfn = LLVM_D_GetRuntimeFunction(ir.module,"_d_main_args");
|
||||
|
||||
llvm::Function::arg_iterator argi = func->arg_begin();
|
||||
args.push_back(argi++);
|
||||
args.push_back(argi++);
|
||||
|
||||
const LLType* at = mainty->getParamType(0)->getContainedType(0);
|
||||
LLValue* arr = new llvm::AllocaInst(at->getContainedType(1)->getContainedType(0), func->arg_begin(), "argstorage", apt);
|
||||
LLValue* a = new llvm::AllocaInst(at, "argarray", apt);
|
||||
LLValue* ptr = DtoGEPi(a,0,0,"tmp",bb);
|
||||
LLValue* v = args[0];
|
||||
if (v->getType() != DtoSize_t())
|
||||
v = new llvm::ZExtInst(v, DtoSize_t(), "tmp", bb);
|
||||
new llvm::StoreInst(v,ptr,bb);
|
||||
ptr = DtoGEPi(a,0,1,"tmp",bb);
|
||||
new llvm::StoreInst(arr,ptr,bb);
|
||||
args.push_back(a);
|
||||
llvm::CallInst::Create(mfn, args.begin(), args.end(), "", bb);
|
||||
call = llvm::CallInst::Create(ir.mainFunc,a,"ret",bb);
|
||||
}
|
||||
else
|
||||
{
|
||||
// main with no arguments
|
||||
call = llvm::CallInst::Create(ir.mainFunc,"ret",bb);
|
||||
}
|
||||
call->setCallingConv(ir.mainFunc->getCallingConv());
|
||||
|
||||
// call static dtors
|
||||
fn = LLVM_D_GetRuntimeFunction(ir.module,"_moduleDtor");
|
||||
llvm::CallInst::Create(fn,"",bb);
|
||||
|
||||
// return
|
||||
llvm::ReturnInst::Create(call,bb);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
const llvm::FunctionType* DtoBaseFunctionType(FuncDeclaration* fdecl)
|
||||
{
|
||||
Dsymbol* parent = fdecl->toParent();
|
||||
|
|
|
@ -13,6 +13,4 @@ void DtoDefineFunc(FuncDeclaration* fd);
|
|||
DValue* DtoArgument(Argument* fnarg, Expression* argexp);
|
||||
void DtoVariadicArgument(Expression* argexp, LLValue* dst);
|
||||
|
||||
void DtoMain();
|
||||
|
||||
#endif
|
||||
|
|
|
@ -996,7 +996,7 @@ void LabelStatement::toIR(IRState* p)
|
|||
if (p->asmBlock)
|
||||
{
|
||||
IRAsmStmt* a = new IRAsmStmt;
|
||||
a->code = ".LDASM";
|
||||
a->code = ".LDASM_";
|
||||
a->code += ident->toChars();
|
||||
a->code += ":";
|
||||
p->asmBlock->s.push_back(a);
|
||||
|
|
|
@ -129,11 +129,6 @@ void Module::genobjfile()
|
|||
// do this again as moduleinfo might have pulled something in!
|
||||
DtoEmptyAllLists();
|
||||
|
||||
// emit the llvm main function if necessary
|
||||
if (ir.emitMain) {
|
||||
//DtoMain();
|
||||
}
|
||||
|
||||
// verify the llvm
|
||||
if (!global.params.novalidate) {
|
||||
std::string verifyErr;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue