Skip to content

Commit f7288cf

Browse files
committed
Merge from 'main' to 'sycl-web' (29 commits)
CONFLICT (content): Merge conflict in clang/lib/Driver/ToolChains/Clang.cpp
2 parents b2181c3 + ca6bbe0 commit f7288cf

File tree

71 files changed

+1512
-508
lines changed

Some content is hidden

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

71 files changed

+1512
-508
lines changed

clang-tools-extra/include-cleaner/unittests/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ target_include_directories(ClangIncludeCleanerTests
1414

1515
clang_target_link_libraries(ClangIncludeCleanerTests
1616
PRIVATE
17+
clangAST
1718
clangBasic
19+
clangFrontend
1820
)
1921

2022
target_link_libraries(ClangIncludeCleanerTests

clang/include/clang/Driver/Action.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,9 @@ class Action {
139139
/// The Offloading architecture associated with this action.
140140
const char *OffloadingArch = nullptr;
141141

142+
/// The Offloading toolchain associated with this device action.
143+
const ToolChain *OffloadingToolChain = nullptr;
144+
142145
Action(ActionClass Kind, types::ID Type) : Action(Kind, ActionList(), Type) {}
143146
Action(ActionClass Kind, Action *Input, types::ID Type)
144147
: Action(Kind, ActionList({Input}), Type) {}
@@ -195,7 +198,8 @@ class Action {
195198

196199
/// Set the device offload info of this action and propagate it to its
197200
/// dependences.
198-
void propagateDeviceOffloadInfo(OffloadKind OKind, const char *OArch);
201+
void propagateDeviceOffloadInfo(OffloadKind OKind, const char *OArch,
202+
const ToolChain *OToolChain);
199203

200204
/// Append the host offload info of this action and propagate it to its
201205
/// dependences.
@@ -216,10 +220,13 @@ class Action {
216220

217221
OffloadKind getOffloadingDeviceKind() const { return OffloadingDeviceKind; }
218222
const char *getOffloadingArch() const { return OffloadingArch; }
223+
const ToolChain *getOffloadingToolChain() const {
224+
return OffloadingToolChain;
225+
}
219226

220227
/// Check if this action have any offload kinds. Note that host offload kinds
221228
/// are only set if the action is a dependence to a host offload action.
222-
bool isHostOffloading(OffloadKind OKind) const {
229+
bool isHostOffloading(unsigned int OKind) const {
223230
return ActiveOffloadKindMask & OKind;
224231
}
225232
bool isDeviceOffloading(OffloadKind OKind) const {

clang/lib/CodeGen/CGOpenMPRuntime.cpp

Lines changed: 1 addition & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,51 +1329,6 @@ llvm::Function *CGOpenMPRuntime::emitTaskOutlinedFunction(
13291329
return Res;
13301330
}
13311331

1332-
static void buildStructValue(ConstantStructBuilder &Fields, CodeGenModule &CGM,
1333-
const RecordDecl *RD, const CGRecordLayout &RL,
1334-
ArrayRef<llvm::Constant *> Data) {
1335-
llvm::StructType *StructTy = RL.getLLVMType();
1336-
unsigned PrevIdx = 0;
1337-
ConstantInitBuilder CIBuilder(CGM);
1338-
const auto *DI = Data.begin();
1339-
for (const FieldDecl *FD : RD->fields()) {
1340-
unsigned Idx = RL.getLLVMFieldNo(FD);
1341-
// Fill the alignment.
1342-
for (unsigned I = PrevIdx; I < Idx; ++I)
1343-
Fields.add(llvm::Constant::getNullValue(StructTy->getElementType(I)));
1344-
PrevIdx = Idx + 1;
1345-
Fields.add(*DI);
1346-
++DI;
1347-
}
1348-
}
1349-
1350-
template <class... As>
1351-
static llvm::GlobalVariable *
1352-
createGlobalStruct(CodeGenModule &CGM, QualType Ty, bool IsConstant,
1353-
ArrayRef<llvm::Constant *> Data, const Twine &Name,
1354-
As &&... Args) {
1355-
const auto *RD = cast<RecordDecl>(Ty->getAsTagDecl());
1356-
const CGRecordLayout &RL = CGM.getTypes().getCGRecordLayout(RD);
1357-
ConstantInitBuilder CIBuilder(CGM);
1358-
ConstantStructBuilder Fields = CIBuilder.beginStruct(RL.getLLVMType());
1359-
buildStructValue(Fields, CGM, RD, RL, Data);
1360-
return Fields.finishAndCreateGlobal(
1361-
Name, CGM.getContext().getAlignOfGlobalVarInChars(Ty), IsConstant,
1362-
std::forward<As>(Args)...);
1363-
}
1364-
1365-
template <typename T>
1366-
static void
1367-
createConstantGlobalStructAndAddToParent(CodeGenModule &CGM, QualType Ty,
1368-
ArrayRef<llvm::Constant *> Data,
1369-
T &Parent) {
1370-
const auto *RD = cast<RecordDecl>(Ty->getAsTagDecl());
1371-
const CGRecordLayout &RL = CGM.getTypes().getCGRecordLayout(RD);
1372-
ConstantStructBuilder Fields = Parent.beginStruct(RL.getLLVMType());
1373-
buildStructValue(Fields, CGM, RD, RL, Data);
1374-
Fields.finishAndAddTo(Parent);
1375-
}
1376-
13771332
void CGOpenMPRuntime::setLocThreadIdInsertPt(CodeGenFunction &CGF,
13781333
bool AtCurrentPoint) {
13791334
auto &Elem = OpenMPLocThreadIDMap.FindAndConstruct(CGF.CurFn);
@@ -3136,32 +3091,7 @@ void CGOpenMPRuntime::OffloadEntriesInfoManagerTy::
31363091
void CGOpenMPRuntime::createOffloadEntry(
31373092
llvm::Constant *ID, llvm::Constant *Addr, uint64_t Size, int32_t Flags,
31383093
llvm::GlobalValue::LinkageTypes Linkage) {
3139-
StringRef Name = Addr->getName();
3140-
llvm::Module &M = CGM.getModule();
3141-
llvm::LLVMContext &C = M.getContext();
3142-
3143-
// Create constant string with the name.
3144-
llvm::Constant *StrPtrInit = llvm::ConstantDataArray::getString(C, Name);
3145-
3146-
std::string StringName = getName({"omp_offloading", "entry_name"});
3147-
auto *Str = new llvm::GlobalVariable(
3148-
M, StrPtrInit->getType(), /*isConstant=*/true,
3149-
llvm::GlobalValue::InternalLinkage, StrPtrInit, StringName);
3150-
Str->setUnnamedAddr(llvm::GlobalValue::UnnamedAddr::Global);
3151-
3152-
llvm::Constant *Data[] = {
3153-
llvm::ConstantExpr::getPointerBitCastOrAddrSpaceCast(ID, CGM.VoidPtrTy),
3154-
llvm::ConstantExpr::getPointerBitCastOrAddrSpaceCast(Str, CGM.Int8PtrTy),
3155-
llvm::ConstantInt::get(CGM.SizeTy, Size),
3156-
llvm::ConstantInt::get(CGM.Int32Ty, Flags),
3157-
llvm::ConstantInt::get(CGM.Int32Ty, 0)};
3158-
std::string EntryName = getName({"omp_offloading", "entry", ""});
3159-
llvm::GlobalVariable *Entry = createGlobalStruct(
3160-
CGM, getTgtOffloadEntryQTy(), /*IsConstant=*/true, Data,
3161-
Twine(EntryName).concat(Name), llvm::GlobalValue::WeakAnyLinkage);
3162-
3163-
// The entry has to be created in the section the linker expects it to be.
3164-
Entry->setSection("omp_offloading_entries");
3094+
OMPBuilder.emitOffloadingEntry(ID, Addr->getName(), Size, Flags);
31653095
}
31663096

31673097
void CGOpenMPRuntime::createOffloadEntriesAndInfoMetadata() {
@@ -3426,35 +3356,6 @@ void CGOpenMPRuntime::emitKmpRoutineEntryT(QualType KmpInt32Ty) {
34263356
}
34273357
}
34283358

3429-
QualType CGOpenMPRuntime::getTgtOffloadEntryQTy() {
3430-
// Make sure the type of the entry is already created. This is the type we
3431-
// have to create:
3432-
// struct __tgt_offload_entry{
3433-
// void *addr; // Pointer to the offload entry info.
3434-
// // (function or global)
3435-
// char *name; // Name of the function or global.
3436-
// size_t size; // Size of the entry info (0 if it a function).
3437-
// int32_t flags; // Flags associated with the entry, e.g. 'link'.
3438-
// int32_t reserved; // Reserved, to use by the runtime library.
3439-
// };
3440-
if (TgtOffloadEntryQTy.isNull()) {
3441-
ASTContext &C = CGM.getContext();
3442-
RecordDecl *RD = C.buildImplicitRecord("__tgt_offload_entry");
3443-
RD->startDefinition();
3444-
addFieldToRecordDecl(C, RD, C.VoidPtrTy);
3445-
addFieldToRecordDecl(C, RD, C.getPointerType(C.CharTy));
3446-
addFieldToRecordDecl(C, RD, C.getSizeType());
3447-
addFieldToRecordDecl(
3448-
C, RD, C.getIntTypeForBitwidth(/*DestWidth=*/32, /*Signed=*/true));
3449-
addFieldToRecordDecl(
3450-
C, RD, C.getIntTypeForBitwidth(/*DestWidth=*/32, /*Signed=*/true));
3451-
RD->completeDefinition();
3452-
RD->addAttr(PackedAttr::CreateImplicit(C));
3453-
TgtOffloadEntryQTy = C.getRecordType(RD);
3454-
}
3455-
return TgtOffloadEntryQTy;
3456-
}
3457-
34583359
namespace {
34593360
struct PrivateHelpersTy {
34603361
PrivateHelpersTy(const Expr *OriginalRef, const VarDecl *Original,

clang/lib/CodeGen/CGOpenMPRuntime.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -518,15 +518,6 @@ class CGOpenMPRuntime {
518518
/// kmp_int64 st; // stride
519519
/// };
520520
QualType KmpDimTy;
521-
/// Type struct __tgt_offload_entry{
522-
/// void *addr; // Pointer to the offload entry info.
523-
/// // (function or global)
524-
/// char *name; // Name of the function or global.
525-
/// size_t size; // Size of the entry info (0 if it a function).
526-
/// int32_t flags;
527-
/// int32_t reserved;
528-
/// };
529-
QualType TgtOffloadEntryQTy;
530521
/// Entity that registers the offloading constants that were emitted so
531522
/// far.
532523
class OffloadEntriesInfoManagerTy {
@@ -782,9 +773,6 @@ class CGOpenMPRuntime {
782773
/// metadata.
783774
void loadOffloadInfoMetadata();
784775

785-
/// Returns __tgt_offload_entry type.
786-
QualType getTgtOffloadEntryQTy();
787-
788776
/// Start scanning from statement \a S and and emit all target regions
789777
/// found along the way.
790778
/// \param S Starting statement.

clang/lib/Driver/Action.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ const char *Action::getClassName(ActionClass AC) {
7272
llvm_unreachable("invalid class");
7373
}
7474

75-
void Action::propagateDeviceOffloadInfo(OffloadKind OKind, const char *OArch) {
75+
void Action::propagateDeviceOffloadInfo(OffloadKind OKind, const char *OArch,
76+
const ToolChain *OToolChain) {
7677
// Offload action set its own kinds on their dependences.
7778
if (Kind == OffloadClass)
7879
return;
@@ -88,9 +89,10 @@ void Action::propagateDeviceOffloadInfo(OffloadKind OKind, const char *OArch) {
8889
assert(!ActiveOffloadKindMask && "Setting a device kind in a host action??");
8990
OffloadingDeviceKind = OKind;
9091
OffloadingArch = OArch;
92+
OffloadingToolChain = OToolChain;
9193

9294
for (auto *A : Inputs)
93-
A->propagateDeviceOffloadInfo(OffloadingDeviceKind, OArch);
95+
A->propagateDeviceOffloadInfo(OffloadingDeviceKind, OArch, OToolChain);
9496
}
9597

9698
void Action::propagateHostOffloadInfo(unsigned OKinds, const char *OArch) {
@@ -112,7 +114,8 @@ void Action::propagateOffloadInfo(const Action *A) {
112114
propagateHostOffloadInfo(HK, A->getOffloadingArch());
113115
else
114116
propagateDeviceOffloadInfo(A->getOffloadingDeviceKind(),
115-
A->getOffloadingArch());
117+
A->getOffloadingArch(),
118+
A->getOffloadingToolChain());
116119
}
117120

118121
std::string Action::getOffloadingKindPrefix() const {
@@ -219,6 +222,7 @@ OffloadAction::OffloadAction(const DeviceDependences &DDeps, types::ID Ty)
219222
DevToolChains(DDeps.getToolChains()) {
220223
auto &OKinds = DDeps.getOffloadKinds();
221224
auto &BArchs = DDeps.getBoundArchs();
225+
auto &OTCs = DDeps.getToolChains();
222226

223227
// If all inputs agree on the same kind, use it also for this action.
224228
if (llvm::all_of(OKinds, [&](OffloadKind K) { return K == OKinds.front(); }))
@@ -230,7 +234,7 @@ OffloadAction::OffloadAction(const DeviceDependences &DDeps, types::ID Ty)
230234

231235
// Propagate info to the dependencies.
232236
for (unsigned i = 0, e = getInputs().size(); i != e; ++i)
233-
getInputs()[i]->propagateDeviceOffloadInfo(OKinds[i], BArchs[i]);
237+
getInputs()[i]->propagateDeviceOffloadInfo(OKinds[i], BArchs[i], OTCs[i]);
234238
}
235239

236240
OffloadAction::OffloadAction(const HostDependence &HDep,
@@ -249,7 +253,8 @@ OffloadAction::OffloadAction(const HostDependence &HDep,
249253
if (auto *A = DDeps.getActions()[i]) {
250254
getInputs().push_back(A);
251255
A->propagateDeviceOffloadInfo(DDeps.getOffloadKinds()[i],
252-
DDeps.getBoundArchs()[i]);
256+
DDeps.getBoundArchs()[i],
257+
DDeps.getToolChains()[i]);
253258
}
254259
}
255260

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4684,11 +4684,13 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
46844684
bool IsOpenMPDevice = JA.isDeviceOffloading(Action::OFK_OpenMP);
46854685
bool IsSYCLOffloadDevice = JA.isDeviceOffloading(Action::OFK_SYCL);
46864686
bool IsSYCL = JA.isOffloading(Action::OFK_SYCL);
4687-
bool IsOpenMPHost = JA.isHostOffloading(Action::OFK_OpenMP);
46884687
bool IsHeaderModulePrecompile = isa<HeaderModulePrecompileJobAction>(JA);
46894688
bool IsExtractAPI = isa<ExtractAPIJobAction>(JA);
46904689
bool IsDeviceOffloadAction = !(JA.isDeviceOffloading(Action::OFK_None) ||
46914690
JA.isDeviceOffloading(Action::OFK_Host));
4691+
bool IsHostOffloadingAction =
4692+
JA.isHostOffloading(Action::OFK_OpenMP) &&
4693+
!Args.hasArg(options::OPT_fno_openmp_new_driver);
46924694
bool IsUsingLTO = D.isUsingLTO(IsDeviceOffloadAction);
46934695
auto LTOMode = D.getLTOMode(IsDeviceOffloadAction);
46944696

@@ -4723,7 +4725,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
47234725

47244726
InputInfoList ModuleHeaderInputs;
47254727
InputInfoList ExtractAPIInputs;
4726-
InputInfoList OpenMPHostInputs;
4728+
InputInfoList HostOffloadingInputs;
47274729
const InputInfo *CudaDeviceInput = nullptr;
47284730
const InputInfo *OpenMPDeviceInput = nullptr;
47294731
const InputInfo *SYCLDeviceInput = nullptr;
@@ -4747,14 +4749,14 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
47474749
<< types::getTypeName(ExpectedInputType);
47484750
}
47494751
ExtractAPIInputs.push_back(I);
4752+
} else if (IsHostOffloadingAction) {
4753+
HostOffloadingInputs.push_back(I);
47504754
} else if ((IsCuda || IsHIP) && !CudaDeviceInput) {
47514755
CudaDeviceInput = &I;
47524756
} else if (IsOpenMPDevice && !OpenMPDeviceInput) {
47534757
OpenMPDeviceInput = &I;
47544758
} else if (IsSYCL && !SYCLDeviceInput) {
47554759
SYCLDeviceInput = &I;
4756-
} else if (IsOpenMPHost) {
4757-
OpenMPHostInputs.push_back(I);
47584760
} else {
47594761
llvm_unreachable("unexpectedly given multiple inputs");
47604762
}
@@ -7446,24 +7448,23 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
74467448
}
74477449
}
74487450

7449-
// Host-side OpenMP offloading recieves the device object files and embeds it
7450-
// in a named section including the associated target triple and architecture.
7451-
if (IsOpenMPHost && !OpenMPHostInputs.empty()) {
7452-
auto InputFile = OpenMPHostInputs.begin();
7453-
auto OpenMPTCs = C.getOffloadToolChains<Action::OFK_OpenMP>();
7454-
for (auto TI = OpenMPTCs.first, TE = OpenMPTCs.second; TI != TE;
7455-
++TI, ++InputFile) {
7456-
const ToolChain *TC = TI->second;
7457-
const ArgList &TCArgs = C.getArgsForToolChain(TC, "", Action::OFK_OpenMP);
7458-
StringRef File =
7459-
C.getArgs().MakeArgString(TC->getInputFilename(*InputFile));
7451+
// Host-side offloading recieves the device object files and embeds it in a
7452+
// named section including the associated target triple and architecture.
7453+
for (const InputInfo Input : HostOffloadingInputs) {
7454+
const Action *OffloadAction = Input.getAction();
7455+
const ToolChain *TC = OffloadAction->getOffloadingToolChain();
7456+
const ArgList &TCArgs =
7457+
C.getArgsForToolChain(TC, OffloadAction->getOffloadingArch(),
7458+
OffloadAction->getOffloadingDeviceKind());
7459+
StringRef File = C.getArgs().MakeArgString(TC->getInputFilename(Input));
7460+
StringRef Arch = (OffloadAction->getOffloadingArch())
7461+
? OffloadAction->getOffloadingArch()
7462+
: TCArgs.getLastArgValue(options::OPT_march_EQ);
74607463

7461-
CmdArgs.push_back(
7462-
Args.MakeArgString("-fembed-offload-object=" + File + "," +
7463-
Action::GetOffloadKindName(Action::OFK_OpenMP) +
7464-
"," + TC->getTripleString() + "," +
7465-
TCArgs.getLastArgValue(options::OPT_march_EQ)));
7466-
}
7464+
CmdArgs.push_back(Args.MakeArgString(
7465+
"-fembed-offload-object=" + File + "," +
7466+
Action::GetOffloadKindName(OffloadAction->getOffloadingDeviceKind()) +
7467+
"," + TC->getTripleString() + "," + Arch));
74677468
}
74687469

74697470
if (Triple.isAMDGPU()) {

flang/docs/Extensions.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ end
206206
* External unit 0 is predefined and connected to the standard error output,
207207
and defined as `ERROR_UNIT` in the intrinsic `ISO_FORTRAN_ENV` module.
208208
* Objects in blank COMMON may be initialized.
209+
* Initialization of COMMON blocks outside of BLOCK DATA subprograms.
209210
* Multiple specifications of the SAVE attribute on the same object
210211
are allowed, with a warning.
211212
* Specific intrinsic functions BABS, IIABS, JIABS, KIABS, ZABS, and CDABS.

flang/include/flang/Lower/ConvertVariable.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@ void instantiateVariable(AbstractConverter &, const pft::Variable &var,
5454
/// called.
5555
void defineModuleVariable(AbstractConverter &, const pft::Variable &var);
5656

57+
/// Create fir::GlobalOp for all common blocks, including their initial values
58+
/// if they have one. This should be called before lowering any scopes so that
59+
/// common block globals are available when a common appear in a scope.
60+
void defineCommonBlocks(
61+
AbstractConverter &,
62+
const std::vector<std::pair<semantics::SymbolRef, std::size_t>>
63+
&commonBlocks);
64+
5765
/// Lower a symbol attributes given an optional storage \p and add it to the
5866
/// provided symbol map. If \preAlloc is not provided, a temporary storage will
5967
/// be allocated. This is a low level function that should only be used if

flang/include/flang/Lower/PFTBuilder.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "flang/Parser/parse-tree.h"
2525
#include "flang/Semantics/attr.h"
2626
#include "flang/Semantics/scope.h"
27+
#include "flang/Semantics/semantics.h"
2728
#include "flang/Semantics/symbol.h"
2829
#include "llvm/Support/ErrorHandling.h"
2930
#include "llvm/Support/raw_ostream.h"
@@ -737,18 +738,23 @@ struct Program {
737738
using Units = std::variant<FunctionLikeUnit, ModuleLikeUnit, BlockDataUnit,
738739
CompilerDirectiveUnit>;
739740

740-
Program() = default;
741+
Program(semantics::CommonBlockList &&commonBlocks)
742+
: commonBlocks{std::move(commonBlocks)} {}
741743
Program(Program &&) = default;
742744
Program(const Program &) = delete;
743745

744746
const std::list<Units> &getUnits() const { return units; }
745747
std::list<Units> &getUnits() { return units; }
748+
const semantics::CommonBlockList &getCommonBlocks() const {
749+
return commonBlocks;
750+
}
746751

747752
/// LLVM dump method on a Program.
748753
LLVM_DUMP_METHOD void dump() const;
749754

750755
private:
751756
std::list<Units> units;
757+
semantics::CommonBlockList commonBlocks;
752758
};
753759

754760
/// Return the list of variables that appears in the specification expressions

0 commit comments

Comments
 (0)