Skip to content

Commit b7a605c

Browse files
authored
Merge branch 'llvm:main' into main
2 parents 50dfd76 + 0570cab commit b7a605c

File tree

97 files changed

+2930
-670
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+2930
-670
lines changed

clang/include/clang/AST/VTableBuilder.h

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -246,12 +246,12 @@ class VTableLayout {
246246
// point for a given vtable index.
247247
typedef llvm::SmallVector<unsigned, 4> AddressPointsIndexMapTy;
248248

249+
using VTableIndicesTy = llvm::SmallVector<std::size_t>;
250+
249251
private:
250-
// Stores the component indices of the first component of each virtual table in
251-
// the virtual table group. To save a little memory in the common case where
252-
// the vtable group contains a single vtable, an empty vector here represents
253-
// the vector {0}.
254-
OwningArrayRef<size_t> VTableIndices;
252+
// Stores the component indices of the first component of each virtual table
253+
// in the virtual table group.
254+
VTableIndicesTy VTableIndices;
255255

256256
OwningArrayRef<VTableComponent> VTableComponents;
257257

@@ -265,7 +265,8 @@ class VTableLayout {
265265
AddressPointsIndexMapTy AddressPointIndices;
266266

267267
public:
268-
VTableLayout(ArrayRef<size_t> VTableIndices,
268+
// Requires `VTableIndices.front() == 0`
269+
VTableLayout(VTableIndicesTy VTableIndices,
269270
ArrayRef<VTableComponent> VTableComponents,
270271
ArrayRef<VTableThunkTy> VTableThunks,
271272
const AddressPointsMapTy &AddressPoints);
@@ -292,26 +293,11 @@ class VTableLayout {
292293
return AddressPointIndices;
293294
}
294295

295-
size_t getNumVTables() const {
296-
if (VTableIndices.empty())
297-
return 1;
298-
return VTableIndices.size();
299-
}
296+
size_t getNumVTables() const { return VTableIndices.size(); }
300297

301-
size_t getVTableOffset(size_t i) const {
302-
if (VTableIndices.empty()) {
303-
assert(i == 0);
304-
return 0;
305-
}
306-
return VTableIndices[i];
307-
}
298+
size_t getVTableOffset(size_t i) const { return VTableIndices[i]; }
308299

309300
size_t getVTableSize(size_t i) const {
310-
if (VTableIndices.empty()) {
311-
assert(i == 0);
312-
return vtable_components().size();
313-
}
314-
315301
size_t thisIndex = VTableIndices[i];
316302
size_t nextIndex = (i + 1 == VTableIndices.size())
317303
? vtable_components().size()

clang/lib/AST/VTableBuilder.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -999,7 +999,7 @@ class ItaniumVTableBuilder {
999999
public:
10001000
/// Component indices of the first component of each of the vtables in the
10011001
/// vtable group.
1002-
SmallVector<size_t, 4> VTableIndices;
1002+
VTableLayout::VTableIndicesTy VTableIndices;
10031003

10041004
ItaniumVTableBuilder(ItaniumVTableContext &VTables,
10051005
const CXXRecordDecl *MostDerivedClass,
@@ -2306,18 +2306,19 @@ MakeAddressPointIndices(const VTableLayout::AddressPointsMapTy &addressPoints,
23062306
return indexMap;
23072307
}
23082308

2309-
VTableLayout::VTableLayout(ArrayRef<size_t> VTableIndices,
2309+
VTableLayout::VTableLayout(VTableIndicesTy VTableIndices,
23102310
ArrayRef<VTableComponent> VTableComponents,
23112311
ArrayRef<VTableThunkTy> VTableThunks,
23122312
const AddressPointsMapTy &AddressPoints)
2313-
: VTableComponents(VTableComponents), VTableThunks(VTableThunks),
2314-
AddressPoints(AddressPoints), AddressPointIndices(MakeAddressPointIndices(
2315-
AddressPoints, VTableIndices.size())) {
2316-
if (VTableIndices.size() <= 1)
2317-
assert(VTableIndices.size() == 1 && VTableIndices[0] == 0);
2318-
else
2319-
this->VTableIndices = OwningArrayRef<size_t>(VTableIndices);
2320-
2313+
: VTableIndices(std::move(VTableIndices)),
2314+
VTableComponents(VTableComponents), VTableThunks(VTableThunks),
2315+
AddressPoints(AddressPoints),
2316+
AddressPointIndices(
2317+
MakeAddressPointIndices(AddressPoints, this->VTableIndices.size())) {
2318+
assert(!this->VTableIndices.empty() &&
2319+
"VTableLayout requires at least one index.");
2320+
assert(this->VTableIndices.front() == 0 &&
2321+
"VTableLayout requires the first index is 0.");
23212322
llvm::sort(this->VTableThunks, [](const VTableLayout::VTableThunkTy &LHS,
23222323
const VTableLayout::VTableThunkTy &RHS) {
23232324
assert((LHS.first != RHS.first || LHS.second == RHS.second) &&
@@ -3730,8 +3731,8 @@ void MicrosoftVTableContext::computeVTableRelatedInformation(
37303731
SmallVector<VTableLayout::VTableThunkTy, 1> VTableThunks(
37313732
Builder.vtable_thunks_begin(), Builder.vtable_thunks_end());
37323733
VFTableLayouts[id] = std::make_unique<VTableLayout>(
3733-
ArrayRef<size_t>{0}, Builder.vtable_components(), VTableThunks,
3734-
EmptyAddressPointsMap);
3734+
VTableLayout::VTableIndicesTy{0}, Builder.vtable_components(),
3735+
VTableThunks, EmptyAddressPointsMap);
37353736
Thunks.insert(Builder.thunks_begin(), Builder.thunks_end());
37363737

37373738
const ASTRecordLayout &Layout = Context.getASTRecordLayout(RD);

clang/lib/CIR/CodeGen/CIRGenDeclOpenACC.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -306,13 +306,15 @@ class OpenACCRoutineClauseEmitter final
306306
CIRGenModule &cgm;
307307
CIRGen::CIRGenBuilderTy &builder;
308308
mlir::acc::RoutineOp routineOp;
309+
const clang::FunctionDecl *funcDecl;
309310
llvm::SmallVector<mlir::acc::DeviceType> lastDeviceTypeValues;
310311

311312
public:
312313
OpenACCRoutineClauseEmitter(CIRGenModule &cgm,
313314
CIRGen::CIRGenBuilderTy &builder,
314-
mlir::acc::RoutineOp routineOp)
315-
: cgm(cgm), builder(builder), routineOp(routineOp) {}
315+
mlir::acc::RoutineOp routineOp,
316+
const clang::FunctionDecl *funcDecl)
317+
: cgm(cgm), builder(builder), routineOp(routineOp), funcDecl(funcDecl) {}
316318

317319
void emitClauses(ArrayRef<const OpenACCClause *> clauses) {
318320
this->VisitClauseList(clauses);
@@ -372,8 +374,12 @@ class OpenACCRoutineClauseEmitter final
372374
value);
373375
} else {
374376
assert(clause.isIdentifierArgument());
375-
cgm.errorNYI(clause.getSourceRange(),
376-
"Bind with an identifier argument is not yet supported");
377+
std::string bindName = cgm.getOpenACCBindMangledName(
378+
clause.getIdentifierArgument(), funcDecl);
379+
380+
routineOp.addBindIDName(
381+
builder.getContext(), lastDeviceTypeValues,
382+
mlir::SymbolRefAttr::get(builder.getContext(), bindName));
377383
}
378384
}
379385
};
@@ -416,6 +422,6 @@ void CIRGenModule::emitOpenACCRoutineDecl(
416422
mlir::acc::getRoutineInfoAttrName(),
417423
mlir::acc::RoutineInfoAttr::get(func.getContext(), funcRoutines));
418424

419-
OpenACCRoutineClauseEmitter emitter{*this, builder, routineOp};
425+
OpenACCRoutineClauseEmitter emitter{*this, builder, routineOp, funcDecl};
420426
emitter.emitClauses(clauses);
421427
}

clang/lib/CIR/CodeGen/CIRGenModule.cpp

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1721,6 +1721,71 @@ static std::string getMangledNameImpl(CIRGenModule &cgm, GlobalDecl gd,
17211721
return std::string(out.str());
17221722
}
17231723

1724+
static FunctionDecl *
1725+
createOpenACCBindTempFunction(ASTContext &ctx, const IdentifierInfo *bindName,
1726+
const FunctionDecl *protoFunc) {
1727+
// If this is a C no-prototype function, we can take the 'easy' way out and
1728+
// just create a function with no arguments/functions, etc.
1729+
if (!protoFunc->hasPrototype())
1730+
return FunctionDecl::Create(
1731+
ctx, /*DC=*/ctx.getTranslationUnitDecl(),
1732+
/*StartLoc=*/SourceLocation{}, /*NLoc=*/SourceLocation{}, bindName,
1733+
protoFunc->getType(), /*TInfo=*/nullptr, StorageClass::SC_None);
1734+
1735+
QualType funcTy = protoFunc->getType();
1736+
auto *fpt = cast<FunctionProtoType>(protoFunc->getType());
1737+
1738+
// If this is a member function, add an explicit 'this' to the function type.
1739+
if (auto *methodDecl = dyn_cast<CXXMethodDecl>(protoFunc);
1740+
methodDecl && methodDecl->isImplicitObjectMemberFunction()) {
1741+
llvm::SmallVector<QualType> paramTypes{fpt->getParamTypes()};
1742+
paramTypes.insert(paramTypes.begin(), methodDecl->getThisType());
1743+
1744+
funcTy = ctx.getFunctionType(fpt->getReturnType(), paramTypes,
1745+
fpt->getExtProtoInfo());
1746+
fpt = cast<FunctionProtoType>(funcTy);
1747+
}
1748+
1749+
auto *tempFunc =
1750+
FunctionDecl::Create(ctx, /*DC=*/ctx.getTranslationUnitDecl(),
1751+
/*StartLoc=*/SourceLocation{},
1752+
/*NLoc=*/SourceLocation{}, bindName, funcTy,
1753+
/*TInfo=*/nullptr, StorageClass::SC_None);
1754+
1755+
SmallVector<ParmVarDecl *> params;
1756+
params.reserve(fpt->getNumParams());
1757+
1758+
// Add all of the parameters.
1759+
for (unsigned i = 0, e = fpt->getNumParams(); i != e; ++i) {
1760+
ParmVarDecl *parm = ParmVarDecl::Create(
1761+
ctx, tempFunc, /*StartLoc=*/SourceLocation{},
1762+
/*IdLoc=*/SourceLocation{},
1763+
/*Id=*/nullptr, fpt->getParamType(i), /*TInfo=*/nullptr,
1764+
StorageClass::SC_None, /*DefArg=*/nullptr);
1765+
parm->setScopeInfo(0, i);
1766+
params.push_back(parm);
1767+
}
1768+
1769+
tempFunc->setParams(params);
1770+
1771+
return tempFunc;
1772+
}
1773+
1774+
std::string
1775+
CIRGenModule::getOpenACCBindMangledName(const IdentifierInfo *bindName,
1776+
const FunctionDecl *attachedFunction) {
1777+
FunctionDecl *tempFunc = createOpenACCBindTempFunction(
1778+
getASTContext(), bindName, attachedFunction);
1779+
1780+
std::string ret = getMangledNameImpl(*this, GlobalDecl(tempFunc), tempFunc);
1781+
1782+
// This does nothing (it is a do-nothing function), since this is a
1783+
// slab-allocator, but leave a call in to immediately destroy this in case we
1784+
// ever come up with a way of getting allocations back.
1785+
getASTContext().Deallocate(tempFunc);
1786+
return ret;
1787+
}
1788+
17241789
StringRef CIRGenModule::getMangledName(GlobalDecl gd) {
17251790
GlobalDecl canonicalGd = gd.getCanonicalDecl();
17261791

clang/lib/CIR/CodeGen/CIRGenModule.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,15 @@ class CIRGenModule : public CIRGenTypeCache {
507507
mlir::Value emitMemberPointerConstant(const UnaryOperator *e);
508508

509509
llvm::StringRef getMangledName(clang::GlobalDecl gd);
510+
// This function is to support the OpenACC 'bind' clause, which names an
511+
// alternate name for the function to be called by. This function mangles
512+
// `attachedFunction` as-if its name was actually `bindName` (that is, with
513+
// the same signature). It has some additional complications, as the 'bind'
514+
// target is always going to be a global function, so member functions need an
515+
// explicit instead of implicit 'this' parameter, and thus gets mangled
516+
// differently.
517+
std::string getOpenACCBindMangledName(const IdentifierInfo *bindName,
518+
const FunctionDecl *attachedFunction);
510519

511520
void emitTentativeDefinition(const VarDecl *d);
512521

clang/test/CIR/CodeGenOpenACC/routine-bind.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: %clang_cc1 -fopenacc -Wno-openacc-self-if-potential-conflict -emit-cir -fclangir %s -o - | FileCheck %s
2+
// FIXME: We should run this against Windows mangling as well at one point.
23

34
#pragma acc routine seq bind("BIND1")
45
void Func1(){}
@@ -18,6 +19,28 @@ void Func5(){}
1819
void Func6(){}
1920
#pragma acc routine(Func6) seq device_type(radeon) bind("BIND6_R") device_type(multicore, host) bind("BIND6_M")
2021

22+
#pragma acc routine seq bind(BIND7)
23+
void Func7(int i){}
24+
25+
void Func8(float f){}
26+
#pragma acc routine(Func8) seq bind(BIND8)
27+
28+
#pragma acc routine seq device_type(nvidia) bind(BIND9)
29+
void Func9(int i, float f, short s){}
30+
31+
struct S{};
32+
struct U{};
33+
struct V{};
34+
35+
void Func10(struct S s){}
36+
#pragma acc routine(Func10) seq device_type(radeon) bind(BIND10)
37+
38+
#pragma acc routine seq device_type(nvidia, host) bind(BIND11_NVH) device_type(multicore) bind(BIND11_MC)
39+
void Func11(struct U* u, struct V v, int i){}
40+
41+
int Func12(struct U u, struct V v, int i){ return 0; }
42+
#pragma acc routine(Func12) seq device_type(radeon) bind(BIND12_R) device_type(multicore, host) bind(BIND12_MCH)
43+
2144
// CHECK: cir.func{{.*}} @[[F1_NAME:.*Func1[^\(]*]]({{.*}}){{.*}} attributes {acc.routine_info = #acc.routine_info<[@[[F1_R_NAME:.*]]]>}
2245
// CHECK: acc.routine @[[F1_R_NAME]] func(@[[F1_NAME]]) bind("BIND1") seq
2346
//
@@ -33,7 +56,25 @@ void Func6(){}
3356
//
3457
// CHECK: cir.func{{.*}} @[[F6_NAME:.*Func6[^\(]*]]({{.*}}){{.*}} attributes {acc.routine_info = #acc.routine_info<[@[[F6_R_NAME:.*]]]>}
3558
//
59+
// CHECK: cir.func{{.*}} @[[F7_NAME:.*Func7[^\(]*]]({{.*}}){{.*}} attributes {acc.routine_info = #acc.routine_info<[@[[F7_R_NAME:.*]]]>}
60+
// CHECK: acc.routine @[[F7_R_NAME]] func(@[[F7_NAME]]) bind(@BIND7) seq
61+
//
62+
// CHECK: cir.func{{.*}} @[[F8_NAME:.*Func8[^\(]*]]({{.*}}){{.*}} attributes {acc.routine_info = #acc.routine_info<[@[[F8_R_NAME:.*]]]>}
63+
//
64+
// CHECK: cir.func{{.*}} @[[F9_NAME:.*Func9[^\(]*]]({{.*}}){{.*}} attributes {acc.routine_info = #acc.routine_info<[@[[F9_R_NAME:.*]]]>}
65+
// CHECK: acc.routine @[[F9_R_NAME]] func(@[[F9_NAME]]) bind(@BIND9 [#acc.device_type<nvidia>]) seq
66+
//
67+
// CHECK: cir.func{{.*}} @[[F10_NAME:.*Func10[^\(]*]]({{.*}}){{.*}} attributes {acc.routine_info = #acc.routine_info<[@[[F10_R_NAME:.*]]]>}
68+
//
69+
// CHECK: cir.func{{.*}} @[[F11_NAME:.*Func11[^\(]*]]({{.*}}){{.*}} attributes {acc.routine_info = #acc.routine_info<[@[[F11_R_NAME:.*]]]>}
70+
// CHECK: acc.routine @[[F11_R_NAME]] func(@[[F11_NAME]]) bind(@BIND11_NVH [#acc.device_type<nvidia>], @BIND11_NVH [#acc.device_type<host>], @BIND11_MC [#acc.device_type<multicore>])
71+
//
72+
// CHECK: cir.func{{.*}} @[[F12_NAME:.*Func12[^\(]*]]({{.*}}){{.*}} attributes {acc.routine_info = #acc.routine_info<[@[[F12_R_NAME:.*]]]>}
73+
//
3674
// CHECK: acc.routine @[[F2_R_NAME]] func(@[[F2_NAME]]) bind("BIND2") seq
3775
// CHECK: acc.routine @[[F4_R_NAME]] func(@[[F4_NAME]]) bind("BIND4" [#acc.device_type<radeon>]) seq
3876
// CHECK: acc.routine @[[F6_R_NAME]] func(@[[F6_NAME]]) bind("BIND6_R" [#acc.device_type<radeon>], "BIND6_M" [#acc.device_type<multicore>], "BIND6_M" [#acc.device_type<host>]) seq
3977

78+
// CHECK: acc.routine @[[F8_R_NAME]] func(@[[F8_NAME]]) bind(@BIND8) seq
79+
// CHECK: acc.routine @[[F10_R_NAME]] func(@[[F10_NAME]]) bind(@BIND10 [#acc.device_type<radeon>]) seq
80+
// CHECK: acc.routine @[[F12_R_NAME]] func(@[[F12_NAME]]) bind(@BIND12_R [#acc.device_type<radeon>], @BIND12_MCH [#acc.device_type<multicore>], @BIND12_MCH [#acc.device_type<host>]) seq

0 commit comments

Comments
 (0)