Skip to content

Commit

Permalink
Merge pull request #1089 from kinke/intrinsic
Browse files Browse the repository at this point in the history
Treat atomic instructions as intrinsics
  • Loading branch information
redstar committed Sep 18, 2015
2 parents ab8f817 + 1a42358 commit 82de92c
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion dmd2/expression.c
Original file line number Diff line number Diff line change
Expand Up @@ -1743,7 +1743,7 @@ bool functionParameters(Loc loc, Scope *sc, TypeFunction *tf,
// If not D linkage, do promotions
#if IN_LLVM
// LDC: don't do promotions on intrinsics
if (tf->linkage != LINKd && (!fd || fd->llvmInternal != LLVMintrinsic))
if (tf->linkage != LINKd && (!fd || !DtoIsIntrinsic(fd)))
#else
if (tf->linkage != LINKd)
#endif
Expand Down
8 changes: 4 additions & 4 deletions gen/functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ llvm::FunctionType* DtoFunctionType(FuncDeclaration* fdecl)

LLFunctionType* functype = DtoFunctionType(fdecl->type, getIrFunc(fdecl, true)->irFty, dthis, dnest,
fdecl->isMain(), fdecl->isCtorDeclaration(),
fdecl->llvmInternal == LLVMintrinsic);
DtoIsIntrinsic(fdecl));

return functype;
}
Expand Down Expand Up @@ -456,7 +456,7 @@ void DtoDeclareFunction(FuncDeclaration* fdecl)
//printf("declare function: %s\n", fdecl->toPrettyChars());

// intrinsic sanity check
if (fdecl->llvmInternal == LLVMintrinsic && fdecl->fbody) {
if (DtoIsIntrinsic(fdecl) && fdecl->fbody) {
error(fdecl->loc, "intrinsics cannot have function bodies");
fatal();
}
Expand All @@ -474,7 +474,7 @@ void DtoDeclareFunction(FuncDeclaration* fdecl)

// calling convention
LINK link = f->linkage;
if (vafunc || fdecl->llvmInternal == LLVMintrinsic
if (vafunc || DtoIsIntrinsic(fdecl)
// DMD treats _Dmain as having C calling convention and this has been
// hardcoded into druntime, even if the frontend type has D linkage.
// See Bugzilla issue 9028.
Expand Down Expand Up @@ -616,7 +616,7 @@ void DtoDeclareFunction(FuncDeclaration* fdecl)
static LinkageWithCOMDAT lowerFuncLinkage(FuncDeclaration* fdecl)
{
// Intrinsics are always external.
if (fdecl->llvmInternal == LLVMintrinsic)
if (DtoIsIntrinsic(fdecl))
return LinkageWithCOMDAT(llvm::GlobalValue::ExternalLinkage, false);

// Generated array op functions behave like templates in that they might be
Expand Down
13 changes: 12 additions & 1 deletion gen/pragma.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,18 @@ void DtoCheckPragma(PragmaDeclaration *decl, Dsymbol *s,

bool DtoIsIntrinsic(FuncDeclaration *fd)
{
return (fd->llvmInternal == LLVMintrinsic || DtoIsVaIntrinsic(fd));
switch (fd->llvmInternal)
{
case LLVMintrinsic:
case LLVMatomic_store:
case LLVMatomic_load:
case LLVMatomic_cmp_xchg:
case LLVMatomic_rmw:
return true;

default:
return DtoIsVaIntrinsic(fd);
}
}

bool DtoIsVaIntrinsic(FuncDeclaration *fd)
Expand Down
2 changes: 1 addition & 1 deletion gen/tocall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,7 @@ DValue* DtoCallFunction(Loc& loc, Type* resulttype, DValue* fnval, Expressions*
DFuncValue* dfnval = fnval->isFunc();

// handle intrinsics
bool intrinsic = (dfnval && dfnval->func && dfnval->func->llvmInternal == LLVMintrinsic);
bool intrinsic = (dfnval && dfnval->func && DtoIsIntrinsic(dfnval->func));

// get function type info
IrFuncTy &irFty = DtoIrTypeFunction(fnval);
Expand Down
2 changes: 1 addition & 1 deletion gen/tollvm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ RET retStyle(TypeFunction *tf)
bool DtoIsReturnInArg(CallExp *ce)
{
TypeFunction *tf = static_cast<TypeFunction *>(ce->e1->type->toBasetype());
if (tf->ty == Tfunction && (!ce->f || ce->f->llvmInternal != LLVMintrinsic))
if (tf->ty == Tfunction && (!ce->f || !DtoIsIntrinsic(ce->f)))
return retStyle(tf) == RETstack;
return false;
}
Expand Down

0 comments on commit 82de92c

Please sign in to comment.