Skip to content

Commit

Permalink
Added pragma extractelement
Browse files Browse the repository at this point in the history
  • Loading branch information
jkrempus committed Oct 2, 2012
1 parent d5d649b commit 2cf5d8c
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
1 change: 1 addition & 0 deletions dmd2/idgen.c
Expand Up @@ -274,6 +274,7 @@ Msgtable msgtable[] =
{ "no_moduleinfo" },
{ "Alloca", "alloca" },
{ "Shufflevector", "shufflevector" },
{ "Extractelement", "extractelement" },
{ "vastart", "va_start" },
{ "vacopy", "va_copy" },
{ "vaend", "va_end" },
Expand Down
23 changes: 23 additions & 0 deletions gen/pragma.cpp
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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())
{
Expand Down
1 change: 1 addition & 0 deletions gen/pragma.h
Expand Up @@ -15,6 +15,7 @@ enum Pragma
LLVMno_moduleinfo,
LLVMalloca,
LLVMshufflevector,
LLVMextractelement,
LLVMva_start,
LLVMva_copy,
LLVMva_end,
Expand Down
14 changes: 13 additions & 1 deletion gen/toir.cpp
Expand Up @@ -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) {
Expand Down

0 comments on commit 2cf5d8c

Please sign in to comment.