Pragma llvm_inline_ir

Adding pragma llvm_inline_ir.

Improved the error messages.

Append "ret void" when the return type is void

Improved the error message

in case when the string passed as llvm inline ir isn't valid llvm
assembly language.

LLVM 3.2 fix.

Add attribute AlwaysInline inside DtoInlineIRFunction.

Always generate a body for llvm_inline_ir

Also, always make llvm_inline_ir functions linkonce_odr. Because
the body is always generated when a module uses a llvm_inline_ir
function, the fact that the linker removes the function shouldn't
cause problems.
This commit is contained in:
Jernej Krempuš
2012-10-22 02:25:56 +02:00
parent 7708d2e27a
commit 7bbe782615
6 changed files with 154 additions and 3 deletions

View File

@@ -257,6 +257,17 @@ Pragma DtoGetPragma(Scope *sc, PragmaDeclaration *decl, std::string &arg1str)
return LLVMinline_asm;
}
// pragma(llvm_inline_ir) { templdecl(s) }
else if (ident == Id::llvm_inline_ir)
{
if (args && args->dim > 0)
{
error("takes no parameters");
fatal();
}
return LLVMinline_ir;
}
return LLVMnone;
}
@@ -421,6 +432,49 @@ void DtoCheckPragma(PragmaDeclaration *decl, Dsymbol *s,
}
break;
case LLVMinline_ir:
if (TemplateDeclaration* td = s->isTemplateDeclaration())
{
Dsymbol* member = td->onemember;
if (!member)
{
error("the '%s' pragma template must have exactly one member", ident->toChars());
fatal();
}
FuncDeclaration* fun = member->isFuncDeclaration();
if (!fun)
{
error("the '%s' pragma template's member must be a function declaration", ident->toChars());
fatal();
}
TemplateParameters& params = *td->parameters;
bool valid_params =
params.dim == 3 && params[1]->isTemplateTypeParameter() &&
params[2]->isTemplateTupleParameter();
if(valid_params)
{
TemplateValueParameter* p0 = params[0]->isTemplateValueParameter();
valid_params = valid_params && p0 && p0->valType == Type::tstring;
}
if(!valid_params)
{
error("the '%s' pragma template must have exactly three parameters: a string, a type and a type tuple",
ident->toChars());
fatal();
}
td->llvmInternal = llvm_internal;
}
else
{
error("the '%s' pragma is only allowed on template declarations", ident->toChars());
fatal();
}
break;
default:
warning(Loc(), "the LDC specific pragma '%s' is not yet implemented, ignoring", ident->toChars());
}