Skip to content
1 change: 1 addition & 0 deletions clang/lib/DPCT/ASTTraversal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ REGISTER_RULE(EventAPICallRule, PassKind::PK_Migration)
REGISTER_RULE(ProfilingEnableOnDemandRule, PassKind::PK_Analysis)
REGISTER_RULE(StreamAPICallRule, PassKind::PK_Migration)
REGISTER_RULE(KernelCallRule, PassKind::PK_Analysis)
REGISTER_RULE(KernelCallRefRule, PassKind::PK_Migration)
REGISTER_RULE(DeviceFunctionDeclRule, PassKind::PK_Analysis)
REGISTER_RULE(MemVarRefMigrationRule, PassKind::PK_Migration)
REGISTER_RULE(ConstantMemVarMigrationRule, PassKind::PK_Migration)
Expand Down
333 changes: 242 additions & 91 deletions clang/lib/DPCT/AnalysisInfo.cpp

Large diffs are not rendered by default.

69 changes: 36 additions & 33 deletions clang/lib/DPCT/AnalysisInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ class KernelCallExpr;
class DeviceFunctionInfo;
class CallFunctionExpr;
class DeviceFunctionDecl;
class DeviceFunctionDeclInModule;
class MemVarInfo;
class VarInfo;
class ExplicitInstantiationDecl;
Expand Down Expand Up @@ -239,6 +238,12 @@ struct RnnBackwardFuncInfo {
std::vector<std::string> FuncArgs;
};

struct DeviceFunctionInfoForWrapper {
std::vector<std::pair<std::string, std::string>> ParametersInfo;
std::vector<std::pair<std::string, std::string>> TemplateParametersInfo;
std::shared_ptr<KernelCallExpr> KernelForWrapper;
};

// <function name, Info>
using HDFuncInfoMap = std::unordered_map<std::string, HostDeviceFuncInfo>;
// <file path, <Offset, Info>>
Expand Down Expand Up @@ -1136,8 +1141,6 @@ class DpctGlobalInfo {
std::shared_ptr<DeviceFunctionDecl> insertDeviceFunctionDecl(
const FunctionDecl *Specialization, const FunctionTypeLoc &FTL,
const ParsedAttributes &Attrs, const TemplateArgumentListInfo &TAList);
std::shared_ptr<DeviceFunctionDecl>
insertDeviceFunctionDeclInModule(const FunctionDecl *FD);

// Build kernel and device function declaration replacements and store
// them.
Expand Down Expand Up @@ -1340,6 +1343,8 @@ class DpctGlobalInfo {
static bool useNoQueueDevice() {
return getHelperFuncPreference(HelperFuncPreference::NoQueueDevice);
}
static void setCVersionCUDALaunchUsed() { CVersionCUDALaunchUsedFlag = true; }
static bool isCVersionCUDALaunchUsed() { return CVersionCUDALaunchUsedFlag; }
static void setUseSYCLCompat(bool Flag = true) { UseSYCLCompatFlag = Flag; }
static bool useSYCLCompat() { return UseSYCLCompatFlag; }
static bool useEnqueueBarrier() {
Expand Down Expand Up @@ -1461,6 +1466,7 @@ class DpctGlobalInfo {
return ConstantReplProcessedFlagMap;
}
static IncludeMapSetTy &getIncludeMapSet() { return IncludeMapSet; }
static auto &getWrapperRegisterMap() { return WrapperRegisterMap; }
static auto &getCodePinTypeInfoVec() { return CodePinTypeInfoMap; }
static auto &getCodePinTemplateTypeInfoVec() {
return CodePinTemplateTypeInfoMap;
Expand Down Expand Up @@ -1662,6 +1668,7 @@ class DpctGlobalInfo {
static unsigned HelperFuncPreferenceFlag;
static bool AnalysisModeFlag;
static bool UseSYCLCompatFlag;
static bool CVersionCUDALaunchUsedFlag;
static unsigned int ColorOption;
static std::unordered_map<int, std::shared_ptr<DeviceFunctionInfo>>
CubPlaceholderIndexMap;
Expand All @@ -1684,6 +1691,10 @@ class DpctGlobalInfo {
static std::map<std::shared_ptr<TextModification>, bool>
ConstantReplProcessedFlagMap;
static IncludeMapSetTy IncludeMapSet;
static std::unordered_map<std::string,
std::pair<std::shared_ptr<ExtReplacement>,
std::shared_ptr<ExtReplacement>>>
WrapperRegisterMap;
static std::vector<std::pair<std::string, VarInfoForCodePin>>
CodePinTypeInfoMap;
static std::vector<std::pair<std::string, VarInfoForCodePin>>
Expand Down Expand Up @@ -2565,7 +2576,8 @@ class DeviceFunctionDecl {
LinkDecl(D, List, Info);
}
void setFuncInfo(std::shared_ptr<DeviceFunctionInfo> Info);

void insertWrapper();
void collectInfoForWrapper(const FunctionDecl *FD);
virtual ~DeviceFunctionDecl() = default;

protected:
Expand All @@ -2588,7 +2600,10 @@ class DeviceFunctionDecl {
bool IsDefFilePathNeeded = false;
std::vector<std::shared_ptr<TextureObjectInfo>> TextureObjectList;
FormatInfo FormatInformation;

bool HasBody = false;
size_t DeclEnd;
std::map<int, std::string> TemplateParameterDefaultValueMap;
std::map<int, std::string> ParameterDefaultValueMap;
static std::shared_ptr<DeviceFunctionInfo> &getFuncInfo(const FunctionDecl *);
static std::unordered_map<std::string, std::shared_ptr<DeviceFunctionInfo>>
FuncInfoMap;
Expand Down Expand Up @@ -2619,32 +2634,6 @@ class ExplicitInstantiationDecl : public DeviceFunctionDecl {
std::string getExtraParameters(LocInfo LI) override;
};

class DeviceFunctionDeclInModule : public DeviceFunctionDecl {
void insertWrapper();
bool HasBody = false;
size_t DeclEnd;
std::string FuncName;
std::vector<std::pair<std::string, std::string>> ParametersInfo;
std::shared_ptr<KernelCallExpr> Kernel;
void buildParameterInfo(const FunctionDecl *FD);
void buildWrapperInfo(const FunctionDecl *FD);
void buildCallInfo(const FunctionDecl *FD);
std::vector<std::pair<std::string, std::string>> &getParametersInfo() {
return ParametersInfo;
}

public:
DeviceFunctionDeclInModule(unsigned Offset,
const clang::tooling::UnifiedPath &FilePathIn,
const FunctionTypeLoc &FTL,
const ParsedAttributes &Attrs,
const FunctionDecl *FD);
DeviceFunctionDeclInModule(unsigned Offset,
const clang::tooling::UnifiedPath &FilePathIn,
const FunctionDecl *FD);
void emplaceReplacement() override;
};

// device function info includes parameters num, memory variable and call
// expression in the function.
class DeviceFunctionInfo {
Expand Down Expand Up @@ -2744,6 +2733,13 @@ class DeviceFunctionInfo {
bool isParameterReferenced(unsigned int Index);
void setParameterReferencedStatus(unsigned int Index, bool IsReferenced);
std::string getFunctionName() { return FunctionName; }
void collectInfoForWrapper(const FunctionDecl *FD);
void setModuleUsed() { ModuleUsed = true; }
bool isModuleUsed() { return ModuleUsed; }
std::shared_ptr<DeviceFunctionInfoForWrapper>
getDeviceFunctionInfoForWrapper() {
return DFInfoForWrapper;
}

private:
void mergeCalledTexObj(
Expand Down Expand Up @@ -2776,12 +2772,16 @@ class DeviceFunctionInfo {
bool CallGroupFunctionInControlFlow = false;
bool HasCheckedCallGroupFunctionInControlFlow = false;
OverloadedOperatorKind OO_Kind = OverloadedOperatorKind::OO_None;
bool WrapperInfoCollected = false;
bool ModuleUsed = false;
std::shared_ptr<DeviceFunctionInfoForWrapper> DFInfoForWrapper;
};

class KernelCallExpr : public CallFunctionExpr {
public:
bool IsInMacroDefine = false;
bool NeedLambda = false;
bool IsForWrapper = false;
bool NeedDefaultRetValue = false;

private:
Expand Down Expand Up @@ -2854,8 +2854,10 @@ class KernelCallExpr : public CallFunctionExpr {
const std::pair<clang::tooling::UnifiedPath, unsigned> &LocInfo,
const CallExpr *, bool IsAssigned = false);
static std::shared_ptr<KernelCallExpr>
buildForWrapper(clang::tooling::UnifiedPath, const FunctionDecl *,
std::shared_ptr<DeviceFunctionInfo>);
buildForWrapper(clang::tooling::UnifiedPath, const FunctionDecl *);
void setTemplateArgsStrForWrapper(std::string Str) {
TemplateArgsStrForWrapper = Str;
Comment thread
intwanghao marked this conversation as resolved.
Outdated
}
unsigned int GridDim = 3;
unsigned int BlockDim = 3;
void setEmitSizeofWarningFlag(bool Flag) { EmitSizeofWarning = Flag; }
Expand Down Expand Up @@ -2959,6 +2961,7 @@ class KernelCallExpr : public CallFunctionExpr {
OuterStmtsList OuterStmts;
StmtList KernelStmts;
std::string KernelArgs;
std::string TemplateArgsStrForWrapper;
int TotalArgsSize = 0;
bool EmitSizeofWarning = false;
unsigned int SizeOfHighestDimension = 0;
Expand Down
Loading