Index: clang/lib/CodeGen/BackendUtil.cpp =================================================================== --- clang/lib/CodeGen/BackendUtil.cpp +++ clang/lib/CodeGen/BackendUtil.cpp @@ -77,6 +77,7 @@ #include "llvm/Transforms/Scalar/EarlyCSE.h" #include "llvm/Transforms/Scalar/GVN.h" #include "llvm/Transforms/Scalar/JumpThreading.h" +#include "llvm/Transforms/StdPar/StdPar.h" #include "llvm/Transforms/Utils/Debugify.h" #include "llvm/Transforms/Utils/EntryExitInstrumenter.h" #include "llvm/Transforms/Utils/ModuleUtils.h" @@ -1093,6 +1094,13 @@ TheModule->addModuleFlag(Module::Error, "UnifiedLTO", uint32_t(1)); } + if (LangOpts.HIPStdPar) { + if (LangOpts.CUDAIsDevice) + MPM.addPass(StdParAcceleratorCodeSelectionPass()); + else if (LangOpts.HIPStdParInterposeAlloc) + MPM.addPass(StdParAllocationInterpositionPass()); + } + // Now that we have all of the passes ready, run them. { PrettyStackTraceString CrashInfo("Optimizer"); Index: clang/lib/CodeGen/CGBuiltin.cpp =================================================================== --- clang/lib/CodeGen/CGBuiltin.cpp +++ clang/lib/CodeGen/CGBuiltin.cpp @@ -5538,7 +5538,8 @@ llvm_unreachable("Bad evaluation kind in EmitBuiltinExpr"); } - ErrorUnsupported(E, "builtin function"); + if (!getLangOpts().HIPStdPar) + ErrorUnsupported(E, "builtin function"); // Unknown builtin, for now just dump it out and return undef. return GetUndefRValue(E->getType()); Index: clang/lib/CodeGen/CodeGenModule.cpp =================================================================== --- clang/lib/CodeGen/CodeGenModule.cpp +++ clang/lib/CodeGen/CodeGenModule.cpp @@ -3545,7 +3545,12 @@ !Global->hasAttr() && !Global->hasAttr() && !Global->getType()->isCUDADeviceBuiltinSurfaceType() && - !Global->getType()->isCUDADeviceBuiltinTextureType()) + !Global->getType()->isCUDADeviceBuiltinTextureType() && + !(LangOpts.HIPStdPar && + isa(Global) && + !cast(Global)->getBuiltinID() && + !Global->hasAttr() && + !cast(Global)->isVariadic())) return; } else { // We need to emit host-side 'shadows' for all global @@ -5310,7 +5315,9 @@ setNonAliasAttributes(D, GV); - if (D->getTLSKind() && !GV->isThreadLocal()) { + if (D->getTLSKind() && + !GV->isThreadLocal() && + !(getLangOpts().HIPStdPar && getLangOpts().CUDAIsDevice)) { if (D->getTLSKind() == VarDecl::TLS_Dynamic) CXXThreadLocals.push_back(D); setTLSMode(GV, *D); Index: clang/test/CodeGenStdPar/unannotated-functions-get-emitted.cpp =================================================================== --- /dev/null +++ clang/test/CodeGenStdPar/unannotated-functions-get-emitted.cpp @@ -0,0 +1,19 @@ +// RUN: %clang_cc1 -x hip -emit-llvm -fcuda-is-device \ +// RUN: -o - %s | FileCheck --check-prefix=NO-STDPAR-DEV %s + +// RUN: %clang_cc1 --stdpar -emit-llvm -fcuda-is-device \ +// RUN: -o - %s | FileCheck --check-prefix=STDPAR-DEV %s + +#define __device__ __attribute__((device)) + +// NO-STDPAR-DEV-NOT: define {{.*}} void @_Z3fooPff({{.*}}) +// STDPAR-DEV: define {{.*}} void @_Z3fooPff({{.*}}) +void foo(float *a, float b) { + *a = b; +} + +// NO-STDPAR-DEV: define {{.*}} void @_Z3barPff({{.*}}) +// STDPAR-DEV: define {{.*}} void @_Z3barPff({{.*}}) +__device__ void bar(float *a, float b) { + *a = b; +} \ No newline at end of file