@@ -1829,63 +1829,60 @@ void CGOpenMPRuntime::registerVTableOffloadEntry(llvm::GlobalVariable *VTable,
18291829 llvm::GlobalValue::WeakODRLinkage);
18301830}
18311831
1832- // Register VTable by scanning through the map clause of OpenMP target region.
1833- void CGOpenMPRuntime::registerVTable(const OMPExecutableDirective &D) {
1834- // Get CXXRecordDecl and VarDecl from Expr.
1835- auto getVTableDecl = [](const Expr *E) {
1836- QualType VDTy = E->getType();
1837- CXXRecordDecl *CXXRecord = nullptr;
1838- if (const auto *RefType = VDTy->getAs<LValueReferenceType>())
1839- VDTy = RefType->getPointeeType();
1840- if (VDTy->isPointerType())
1841- CXXRecord = VDTy->getPointeeType()->getAsCXXRecordDecl();
1842- else
1843- CXXRecord = VDTy->getAsCXXRecordDecl();
1844-
1845- const VarDecl *VD = nullptr;
1846- if (auto *DRE = dyn_cast<DeclRefExpr>(E))
1847- VD = cast<VarDecl>(DRE->getDecl());
1848- return std::pair<CXXRecordDecl *, const VarDecl *>(CXXRecord, VD);
1849- };
1850-
1851- // Emit VTable and register the VTable to OpenMP offload entry recursively.
1852- std::function<void(CodeGenModule &, CXXRecordDecl *, const VarDecl *)>
1853- emitAndRegisterVTable = [&emitAndRegisterVTable](CodeGenModule &CGM,
1854- CXXRecordDecl *CXXRecord,
1855- const VarDecl *VD) {
1832+ void CGOpenMPRuntime::emitAndRegisterVTable(CodeGenModule &CGM,
1833+ CXXRecordDecl *CXXRecord,
1834+ const VarDecl *VD) {
18561835 // Register C++ VTable to OpenMP Offload Entry if it's a new
18571836 // CXXRecordDecl.
18581837 if (CXXRecord && CXXRecord->isDynamicClass() &&
18591838 CGM.getOpenMPRuntime().VTableDeclMap.find(CXXRecord) ==
18601839 CGM.getOpenMPRuntime().VTableDeclMap.end()) {
18611840 CGM.getOpenMPRuntime().VTableDeclMap.try_emplace(CXXRecord, VD);
18621841 CGM.EmitVTable(CXXRecord);
1863- auto VTables = CGM.getVTables();
1864- auto *VTablesAddr = VTables.GetAddrOfVTable(CXXRecord);
1865- if (VTablesAddr) {
1842+ CodeGenVTables VTables = CGM.getVTables();
1843+ llvm::GlobalVariable *VTablesAddr = VTables.GetAddrOfVTable(CXXRecord);
1844+ if (VTablesAddr)
18661845 CGM.getOpenMPRuntime().registerVTableOffloadEntry(VTablesAddr, VD);
1867- }
18681846 // Emit VTable for all the fields containing dynamic CXXRecord
18691847 for (const FieldDecl *Field : CXXRecord->fields()) {
18701848 if (CXXRecordDecl *RecordDecl =
1871- Field->getType()->getAsCXXRecordDecl()) {
1849+ Field->getType()->getAsCXXRecordDecl())
18721850 emitAndRegisterVTable(CGM, RecordDecl, VD);
1873- }
1851+
18741852 }
18751853 // Emit VTable for all dynamic parent class
18761854 for (CXXBaseSpecifier &Base : CXXRecord->bases()) {
18771855 if (CXXRecordDecl *BaseDecl =
1878- Base.getType()->getAsCXXRecordDecl()) {
1856+ Base.getType()->getAsCXXRecordDecl())
18791857 emitAndRegisterVTable(CGM, BaseDecl, VD);
1880- }
1858+
18811859 }
18821860 }
18831861 };
18841862
1863+
1864+ void CGOpenMPRuntime::registerVTable(const OMPExecutableDirective &D) {
1865+ // Register VTable by scanning through the map clause of OpenMP target region.
1866+ // Get CXXRecordDecl and VarDecl from Expr.
1867+ auto GetVTableDecl = [](const Expr *E) {
1868+ QualType VDTy = E->getType();
1869+ CXXRecordDecl *CXXRecord = nullptr;
1870+ if (const auto *RefType = VDTy->getAs<LValueReferenceType>())
1871+ VDTy = RefType->getPointeeType();
1872+ if (VDTy->isPointerType())
1873+ CXXRecord = VDTy->getPointeeType()->getAsCXXRecordDecl();
1874+ else
1875+ CXXRecord = VDTy->getAsCXXRecordDecl();
1876+
1877+ const VarDecl *VD = nullptr;
1878+ if (auto *DRE = dyn_cast<DeclRefExpr>(E))
1879+ VD = cast<VarDecl>(DRE->getDecl());
1880+ return std::pair<CXXRecordDecl *, const VarDecl *>(CXXRecord, VD);
1881+ };
18851882 // Collect VTable from OpenMP map clause.
18861883 for (const auto *C : D.getClausesOfKind<OMPMapClause>()) {
18871884 for (const auto *E : C->varlist()) {
1888- auto DeclPair = getVTableDecl (E);
1885+ auto DeclPair = GetVTableDecl (E);
18891886 emitAndRegisterVTable(CGM, DeclPair.first, DeclPair.second);
18901887 }
18911888 }
@@ -10075,8 +10072,8 @@ void CGOpenMPRuntime::scanForTargetRegionsFunctions(const Stmt *S,
1007510072 // target data by checking if S is a executable directive (target).
1007610073 if (isa<OMPExecutableDirective>(S) &&
1007710074 isOpenMPTargetDataManagementDirective(
10078- cast <OMPExecutableDirective>(S)->getDirectiveKind())) {
10079- auto &E = *cast <OMPExecutableDirective>(S);
10075+ dyn_cast <OMPExecutableDirective>(S)->getDirectiveKind())) {
10076+ auto &E = *dyn_cast <OMPExecutableDirective>(S);
1008010077 // Don't need to check if it's device compile
1008110078 // since scanForTargetRegionsFunctions currently only called
1008210079 // in device compilation.
0 commit comments