2020#include " clang/AST/ExprCXX.h"
2121#include " clang/AST/OperationKinds.h"
2222#include " clang/ASTMatchers/ASTMatchers.h"
23+ #include " clang/Tooling/Core/UnifiedPath.h"
2324#include " clang/Tooling/Tooling.h"
2425#include < algorithm>
2526#include < deque>
@@ -829,6 +830,19 @@ void DpctFileInfo::setFirstIncludeOffset(unsigned Offset) {
829830 HasInclusionDirectiveSet.insert (std::move (MF ));
830831 }
831832}
833+ void DpctFileInfo::setHeaderInserted (HeaderType Header) {
834+ DpctGlobalInfo::getHeaderInsertedBitMap ()[FilePath][Header] = true ;
835+ }
836+ void DpctFileInfo::setMathHeaderInserted (bool B) {
837+ DpctGlobalInfo::getHeaderInsertedBitMap ()[FilePath][HeaderType::HT_Math] = B;
838+ }
839+ void DpctFileInfo::setAlgorithmHeaderInserted (bool B) {
840+ DpctGlobalInfo::getHeaderInsertedBitMap ()[FilePath]
841+ [HeaderType::HT_Algorithm] = B;
842+ }
843+ void DpctFileInfo::setTimeHeaderInserted (bool B) {
844+ DpctGlobalInfo::getHeaderInsertedBitMap ()[FilePath][HeaderType::HT_Time] = B;
845+ }
832846void DpctFileInfo::concatHeader (llvm::raw_string_ostream &OS ) {}
833847template <class FirstT , class ... Args>
834848void DpctFileInfo::concatHeader (llvm::raw_string_ostream &OS , FirstT &&First,
@@ -862,9 +876,9 @@ void DpctFileInfo::insertHeader(HeaderType Type, unsigned Offset,
862876 Type, FirstIncludeOffset.at (MF ));
863877 }
864878 }
865- if (HeaderInsertedBitMap [Type])
879+ if (DpctGlobalInfo::getHeaderInsertedBitMap ()[FilePath] [Type])
866880 return ;
867- HeaderInsertedBitMap [Type] = true ;
881+ DpctGlobalInfo::getHeaderInsertedBitMap ()[FilePath] [Type] = true ;
868882 std::string ReplStr;
869883 llvm::raw_string_ostream OS (ReplStr);
870884 std::string MigratedMacroDefinitionStr;
@@ -898,10 +912,11 @@ void DpctFileInfo::insertHeader(HeaderType Type, unsigned Offset,
898912 concatHeader (OS , getHeaderSpelling (Type));
899913 if (DpctGlobalInfo::useSYCLCompat ()) {
900914 concatHeader (OS , getHeaderSpelling (HT_COMPAT_SYCLcompat));
901- HeaderInsertedBitMap[HT_COMPAT_SYCLcompat] = true ;
915+ DpctGlobalInfo::getHeaderInsertedBitMap ()[FilePath]
916+ [HT_COMPAT_SYCLcompat] = true ;
902917 } else {
903918 concatHeader (OS , getHeaderSpelling (HT_DPCT_Dpct));
904- HeaderInsertedBitMap [HT_DPCT_Dpct] = true ;
919+ DpctGlobalInfo::getHeaderInsertedBitMap ()[FilePath] [HT_DPCT_Dpct] = true ;
905920 }
906921 DpctGlobalInfo::printUsingNamespace (OS );
907922 if (DpctGlobalInfo::useNoQueueDevice ()) {
@@ -1456,8 +1471,8 @@ std::string DpctGlobalInfo::getStringForRegexReplacement(StringRef MatchedStr) {
14561471 return getStringForRegexDefaultQueueAndDevice (
14571472 HelperFuncType::HFT_DefaultQueuePtr, Index);
14581473 case ' E' : {
1459- auto &Vec = DpctGlobalInfo::getInstance ().getCSourceFileInfo ();
1460- return Vec[Index]-> hasCUDASyntax ( )
1474+ auto &Vec = DpctGlobalInfo::getInstance ().getCSourceFileList ();
1475+ return DpctGlobalInfo::hasCUDASyntax ( Vec[Index])
14611476 ? (" c" + DpctGlobalInfo::getSYCLSourceExtension ())
14621477 : " c" ;
14631478 }
@@ -2493,7 +2508,7 @@ bool DpctGlobalInfo::CVersionCUDALaunchUsedFlag = false;
24932508unsigned int DpctGlobalInfo::ColorOption = 1 ;
24942509std::unordered_map<int , std::shared_ptr<DeviceFunctionInfo>>
24952510 DpctGlobalInfo::CubPlaceholderIndexMap;
2496- std::vector<std::shared_ptr<DpctFileInfo>> DpctGlobalInfo::CSourceFileInfo ;
2511+ std::vector<tooling::UnifiedPath> DpctGlobalInfo::CSourceFileList ;
24972512bool DpctGlobalInfo::OptimizeMigrationFlag = false ;
24982513std::unordered_map<std::string, std::shared_ptr<PriorityReplInfo>>
24992514 DpctGlobalInfo::PriorityReplInfoMap;
@@ -2520,6 +2535,8 @@ std::vector<std::pair<std::string, std::vector<std::string>>>
25202535std::unordered_set<std::string> DpctGlobalInfo::NeedParenAPISet = {};
25212536std::unordered_set<std::string>
25222537 DpctGlobalInfo::CustomHelperFunctionAddtionalIncludes = {};
2538+ std::unordered_map<clang::tooling::UnifiedPath, std::bitset<32 >>
2539+ DpctGlobalInfo::HeaderInsertedBitMap = {};
25232540// /// class DpctNameGenerator /////
25242541void DpctNameGenerator::printName (const FunctionDecl *FD ,
25252542 llvm::raw_ostream &OS ) {
@@ -2608,6 +2625,9 @@ CtTypeInfo::CtTypeInfo(const VarDecl *D, bool NeedSizeFold) : CtTypeInfo() {
26082625 auto TL = D->getTypeSourceInfo ()->getTypeLoc ();
26092626 IsConstantQualified = D->hasAttr <CUDAConstantAttr>();
26102627 setTypeInfo (TL , NeedSizeFold);
2628+ if (IsAutoSpecified) {
2629+ DeducedTypeStr = DpctGlobalInfo::getReplacedTypeName (D->getType ());
2630+ }
26112631 if (TL .getTypeLocClass () == TypeLoc::IncompleteArray) {
26122632 if (auto CAT = dyn_cast<ConstantArrayType>(D->getType ())) {
26132633 Range[0 ] = std::to_string (CAT ->getSize ().getZExtValue ());
@@ -2805,6 +2825,12 @@ void CtTypeInfo::setArrayInfo(const IncompleteArrayTypeLoc &TL,
28052825}
28062826void CtTypeInfo::setName (const TypeLoc &TL ) {
28072827 ExprAnalysis EA ;
2828+ QualType QT = TL .getType ();
2829+ if (const Type *TP = QT .getTypePtr ()) {
2830+ if (isa<AutoType>(TP )) {
2831+ IsAutoSpecified = true ;
2832+ }
2833+ }
28082834 EA .analyze (TL );
28092835 TDSI = EA .getTemplateDependentStringInfo ();
28102836 auto SetFromTL = EA .getHelperFeatureSet ();
@@ -2921,7 +2947,7 @@ void MemVarInfo::migrateToDeviceGlobal(const VarDecl *MemVar) {
29212947 auto &Ctx = DpctGlobalInfo::getContext ();
29222948 auto &MacroArgMap = DpctGlobalInfo::getMacroArgRecordMap ();
29232949 auto TSI = MemVar->getTypeSourceInfo ();
2924- auto OriginTL = TSI ->getTypeLoc ();
2950+ auto OriginTL = TSI ->getTypeLoc (). getUnqualifiedLoc (). getAs <TypeLoc>() ;
29252951 auto TL = OriginTL;
29262952 auto BegLoc = MemVar->getBeginLoc ();
29272953 if (BegLoc.isMacroID ()) {
@@ -3002,7 +3028,11 @@ void MemVarInfo::migrateToDeviceGlobal(const VarDecl *MemVar) {
30023028 }
30033029 }
30043030 if (BaseTypeStr.empty ()) {
3005- BaseTypeStr = getType ()->getBaseNameWithoutQualifiers ();
3031+ if (getType ()->isAutoSpecified ()) {
3032+ BaseTypeStr = getType ()->getDeducedTypeStr ();
3033+ } else {
3034+ BaseTypeStr = getType ()->getBaseNameWithoutQualifiers ();
3035+ }
30063036 TypeReplLoc = TL .getBeginLoc ();
30073037 TypeReplLen =
30083038 SM .getFileOffset (TL .getEndLoc ()) - SM .getFileOffset (TL .getBeginLoc ()) +
@@ -4806,6 +4836,8 @@ DeviceFunctionDecl::DeviceFunctionDecl(
48064836 FuncInfo(getFuncInfo(FD )) {
48074837 if (FD ->isFunctionTemplateSpecialization ()) {
48084838 SourceRange ReturnTypeRange = FD ->getReturnTypeSourceRange ();
4839+ ReturnTypeRange = clang::dpct::getDefinitionRange (
4840+ ReturnTypeRange.getBegin (), ReturnTypeRange.getEnd ());
48094841 OffsetForAttr =
48104842 DpctGlobalInfo::getLocInfo (ReturnTypeRange.getBegin ()).second ;
48114843 }
@@ -4842,6 +4874,11 @@ DeviceFunctionDecl::DeviceFunctionDecl(
48424874 FuncInfo(getFuncInfo(Specialization)) {
48434875 IsDefFilePathNeeded = false ;
48444876
4877+ auto ReturnLoc = FTL .getReturnLoc ();
4878+ auto ReturnRange = clang::dpct::getDefinitionRange (ReturnLoc.getBeginLoc (),
4879+ ReturnLoc.getEndLoc ());
4880+ OffsetForAttr = DpctGlobalInfo::getLocInfo (ReturnRange.getBegin ()).second ;
4881+
48454882 buildReplaceLocInfo (FTL , Attrs);
48464883 buildTextureObjectParamsInfo (FTL .getParams ());
48474884 if (Specialization->hasAttr <CUDAGlobalAttr>()) {
@@ -5232,7 +5269,9 @@ void DeviceFunctionDecl::insertWrapper() {
52325269 Printer << " >" ;
52335270 Printer.newLine ();
52345271 }
5235- Printer << " void " << FuncName << " _wrapper(" ;
5272+ Printer << (IsStaticSpecified ? " static " : " " )
5273+ << (IsInlineSpecified ? " inline " : " " ) << " void " << FuncName
5274+ << " _wrapper(" ;
52365275 for (size_t i = 0 ; i < ParamsInfo.size (); i++) {
52375276 Printer << (i == 0 ? " " : " ," ) << ParamsInfo[i].first << " "
52385277 << ParamsInfo[i].second << ParameterDefaultValueMap[i];
@@ -5312,7 +5351,8 @@ void DeviceFunctionDecl::collectInfoForWrapper(const FunctionDecl *FD) {
53125351 if (HasBody && FD != Def) {
53135352 HasBody = false ;
53145353 }
5315-
5354+ IsInlineSpecified = FD ->isInlineSpecified ();
5355+ IsStaticSpecified = FD ->isStatic ();
53165356 if (auto FTD = FD ->getDescribedFunctionTemplate ()) {
53175357 if (auto TemplateParmsList = FTD ->getTemplateParameters ()) {
53185358 for (size_t i = 0 ; i < TemplateParmsList->size (); ++i) {
@@ -6073,9 +6113,14 @@ void KernelCallExpr::addAccessorDecl() {
60736113 Tex.second ->addDecl (OuterStmts.InitList , SubmitStmts.TextureList ,
60746114 SubmitStmts.SamplerList , getQueueStr ());
60756115 }
6076- for (auto &Tmp : VM .getTempStorageMap ()) {
6077- Tmp.second ->addAccessorDecl (SubmitStmts.AccessorList ,
6078- ExecutionConfig.LocalSize );
6116+ if (!VM .getTempStorageMap ().empty ()) {
6117+ DpctGlobalInfo::getInstance ()
6118+ .insertFile (getFilePath ())
6119+ ->insertHeader (HT_DPCT_GROUP_Utils, RT_ForSYCLMigration);
6120+ for (auto &Tmp : VM .getTempStorageMap ()) {
6121+ Tmp.second ->addAccessorDecl (SubmitStmts.AccessorList ,
6122+ ExecutionConfig.LocalSize );
6123+ }
60796124 }
60806125}
60816126void KernelCallExpr::buildInfo () {
0 commit comments