Added pragma extractelement

This commit is contained in:
Jernej Krempuš
2012-10-02 21:37:27 +02:00
parent d5d649b9c9
commit 2cf5d8c2a0
4 changed files with 38 additions and 1 deletions

View File

@@ -274,6 +274,7 @@ Msgtable msgtable[] =
{ "no_moduleinfo" },
{ "Alloca", "alloca" },
{ "Shufflevector", "shufflevector" },
{ "Extractelement", "extractelement" },
{ "vastart", "va_start" },
{ "vacopy", "va_copy" },
{ "vaend", "va_end" },

View File

@@ -116,6 +116,17 @@ Pragma DtoGetPragma(Scope *sc, PragmaDeclaration *decl, std::string &arg1str)
return LLVMshufflevector;
}
// pragma(extractelement) { funcdecl(s) }
else if (ident == Id::Extractelement)
{
if (args && args->dim > 0)
{
error("takes no parameters");
fatal();
}
return LLVMextractelement;
}
// pragma(va_start) { templdecl(s) }
else if (ident == Id::vastart)
{
@@ -375,6 +386,18 @@ void DtoCheckPragma(PragmaDeclaration *decl, Dsymbol *s,
}
break;
case LLVMextractelement:
if (FuncDeclaration* fd = s->isFuncDeclaration())
{
fd->llvmInternal = llvm_internal;
}
else
{
error("the '%s' pragma must only be used on function declarations.", ident->toChars());
fatal();
}
break;
case LLVMinline_asm:
if (TemplateDeclaration* td = s->isTemplateDeclaration())
{

View File

@@ -15,6 +15,7 @@ enum Pragma
LLVMno_moduleinfo,
LLVMalloca,
LLVMshufflevector,
LLVMextractelement,
LLVMva_start,
LLVMva_copy,
LLVMva_end,

View File

@@ -1007,7 +1007,19 @@ DValue* CallExp::toElem(IRState* p)
LLValue* v1 = exp1->toElem(p)->getRVal();
LLValue* v2 = exp2->toElem(p)->getRVal();
return new DImValue(type, p->ir->CreateShuffleVector(v1, v2, maskVal));
}
}
// extractelement
else if(fndecl->llvmInternal == LLVMextractelement) {
Expression* exp2 = static_cast<Expression*>(arguments->data[1]);
if(exp2->op != TOKint64){
error("Function %s was declared with pragma extractelement. Because of that its second argument must be an integer literal.", fndecl->toChars());
fatal();
}
LLConstant* idx = static_cast<IntegerExp*>(arguments->data[1])->toConstElem(p);
Expression* exp1 = static_cast<Expression*>(arguments->data[0]);
LLValue* vec = exp1->toElem(p)->getRVal();
return new DImValue(type, p->ir->CreateExtractElement(vec, idx));
}
// fence instruction
else if (fndecl->llvmInternal == LLVMfence) {
if (arguments->dim != 1) {