Skip to content

Commit a36da76

Browse files
committed
Merge from 'main' to 'sycl-web' (#2)
CONFLICT (content): Merge conflict in clang/lib/Frontend/CompilerInvocation.cpp
2 parents 6c8cad8 + 7df405e commit a36da76

File tree

215 files changed

+9051
-3544
lines changed

Some content is hidden

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

215 files changed

+9051
-3544
lines changed

clang/include/clang/Basic/LangOptions.h

+6
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,9 @@ class LangOptions : public LangOptionsBase {
373373
/// A list of all -fno-builtin-* function names (e.g., memset).
374374
std::vector<std::string> NoBuiltinFuncs;
375375

376+
/// A prefix map for __FILE__, __BASE_FILE__ and __builtin_FILE().
377+
std::map<std::string, std::string, std::greater<std::string>> MacroPrefixMap;
378+
376379
/// Triples of the OpenMP targets that the host code codegen should
377380
/// take into account in order to generate accurate offloading descriptors.
378381
std::vector<llvm::Triple> OMPTargetTriples;
@@ -491,6 +494,9 @@ class LangOptions : public LangOptionsBase {
491494
}
492495

493496
bool isSYCL() const { return SYCLIsDevice || SYCLIsHost; }
497+
498+
/// Remap path prefix according to -fmacro-prefix-path option.
499+
void remapPathPrefix(SmallString<256> &Path) const;
494500
};
495501

496502
/// Floating point control options

clang/include/clang/Driver/Options.td

+3-3
Original file line numberDiff line numberDiff line change
@@ -2939,10 +2939,10 @@ def fcoverage_prefix_map_EQ
29392939
HelpText<"remap file source paths in coverage mapping">;
29402940
def ffile_prefix_map_EQ
29412941
: Joined<["-"], "ffile-prefix-map=">, Group<f_Group>,
2942-
HelpText<"remap file source paths in debug info and predefined preprocessor macros">;
2942+
HelpText<"remap file source paths in debug info, predefined preprocessor macros and __builtin_FILE()">;
29432943
def fmacro_prefix_map_EQ
2944-
: Joined<["-"], "fmacro-prefix-map=">, Group<Preprocessor_Group>, Flags<[CC1Option]>,
2945-
HelpText<"remap file source paths in predefined preprocessor macros">;
2944+
: Joined<["-"], "fmacro-prefix-map=">, Group<f_Group>, Flags<[CC1Option]>,
2945+
HelpText<"remap file source paths in predefined preprocessor macros and __builtin_FILE()">;
29462946
defm force_dwarf_frame : BoolFOption<"force-dwarf-frame",
29472947
CodeGenOpts<"ForceDwarfFrameSection">, DefaultFalse,
29482948
PosFlag<SetTrue, [CC1Option], "Always emit a debug frame section">, NegFlag<SetFalse>>;

clang/include/clang/Lex/PreprocessorOptions.h

-3
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,6 @@ class PreprocessorOptions {
202202
/// build it again.
203203
std::shared_ptr<FailedModulesSet> FailedModules;
204204

205-
/// A prefix map for __FILE__ and __BASE_FILE__.
206-
std::map<std::string, std::string, std::greater<std::string>> MacroPrefixMap;
207-
208205
/// Contains the currently active skipped range mappings for skipping excluded
209206
/// conditional directives.
210207
///

clang/lib/AST/Expr.cpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -2288,8 +2288,11 @@ APValue SourceLocExpr::EvaluateInContext(const ASTContext &Ctx,
22882288
};
22892289

22902290
switch (getIdentKind()) {
2291-
case SourceLocExpr::File:
2292-
return MakeStringLiteral(PLoc.getFilename());
2291+
case SourceLocExpr::File: {
2292+
SmallString<256> Path(PLoc.getFilename());
2293+
Ctx.getLangOpts().remapPathPrefix(Path);
2294+
return MakeStringLiteral(Path);
2295+
}
22932296
case SourceLocExpr::Function: {
22942297
const Decl *CurDecl = dyn_cast_or_null<Decl>(Context);
22952298
return MakeStringLiteral(

clang/lib/AST/RecordLayoutBuilder.cpp

+12-5
Original file line numberDiff line numberDiff line change
@@ -1775,11 +1775,18 @@ void ItaniumRecordLayoutBuilder::LayoutBitField(const FieldDecl *D) {
17751775
!D->getIdentifier())
17761776
FieldAlign = UnpackedFieldAlign = 1;
17771777

1778-
// On AIX, zero-width bitfields pad out to the alignment boundary, but then
1779-
// do not affect overall record alignment if there is a pragma pack or
1780-
// pragma align(packed).
1781-
if (isAIXLayout(Context) && !MaxFieldAlignment.isZero() && !FieldSize)
1782-
FieldAlign = std::min(FieldAlign, MaxFieldAlignmentInBits);
1778+
// On AIX, zero-width bitfields pad out to the natural alignment boundary,
1779+
// but do not increase the alignment greater than the MaxFieldAlignment, or 1
1780+
// if packed.
1781+
if (isAIXLayout(Context) && !FieldSize) {
1782+
if (FieldPacked)
1783+
FieldAlign = 1;
1784+
if (!MaxFieldAlignment.isZero()) {
1785+
UnpackedFieldAlign =
1786+
std::min(UnpackedFieldAlign, MaxFieldAlignmentInBits);
1787+
FieldAlign = std::min(FieldAlign, MaxFieldAlignmentInBits);
1788+
}
1789+
}
17831790

17841791
// Diagnose differences in layout due to padding or packing.
17851792
if (!UseExternalLayout)

clang/lib/Basic/LangOptions.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#include "clang/Basic/LangOptions.h"
14+
#include "llvm/ADT/SmallString.h"
15+
#include "llvm/Support/Path.h"
1416

1517
using namespace clang;
1618

@@ -48,6 +50,12 @@ VersionTuple LangOptions::getOpenCLVersionTuple() const {
4850
return VersionTuple(Ver / 100, (Ver % 100) / 10);
4951
}
5052

53+
void LangOptions::remapPathPrefix(SmallString<256> &Path) const {
54+
for (const auto &Entry : MacroPrefixMap)
55+
if (llvm::sys::path::replace_path_prefix(Path, Entry.first, Entry.second))
56+
break;
57+
}
58+
5159
FPOptions FPOptions::defaultWithoutTrailingStorage(const LangOptions &LO) {
5260
FPOptions result(LO);
5361
return result;

clang/lib/CodeGen/CGCall.cpp

+26-3
Original file line numberDiff line numberDiff line change
@@ -1278,12 +1278,26 @@ static llvm::Value *CreateCoercedLoad(Address Src, llvm::Type *Ty,
12781278
// perform the conversion.
12791279
if (auto *ScalableDst = dyn_cast<llvm::ScalableVectorType>(Ty)) {
12801280
if (auto *FixedSrc = dyn_cast<llvm::FixedVectorType>(SrcTy)) {
1281+
// If we are casting a fixed i8 vector to a scalable 16 x i1 predicate
1282+
// vector, use a vector insert and bitcast the result.
1283+
bool NeedsBitcast = false;
1284+
auto PredType =
1285+
llvm::ScalableVectorType::get(CGF.Builder.getInt1Ty(), 16);
1286+
llvm::Type *OrigType = Ty;
1287+
if (ScalableDst == PredType &&
1288+
FixedSrc->getElementType() == CGF.Builder.getInt8Ty()) {
1289+
ScalableDst = llvm::ScalableVectorType::get(CGF.Builder.getInt8Ty(), 2);
1290+
NeedsBitcast = true;
1291+
}
12811292
if (ScalableDst->getElementType() == FixedSrc->getElementType()) {
12821293
auto *Load = CGF.Builder.CreateLoad(Src);
12831294
auto *UndefVec = llvm::UndefValue::get(ScalableDst);
12841295
auto *Zero = llvm::Constant::getNullValue(CGF.CGM.Int64Ty);
1285-
return CGF.Builder.CreateInsertVector(ScalableDst, UndefVec, Load, Zero,
1286-
"castScalableSve");
1296+
llvm::Value *Result = CGF.Builder.CreateInsertVector(
1297+
ScalableDst, UndefVec, Load, Zero, "castScalableSve");
1298+
if (NeedsBitcast)
1299+
Result = CGF.Builder.CreateBitCast(Result, OrigType);
1300+
return Result;
12871301
}
12881302
}
12891303
}
@@ -2871,9 +2885,18 @@ void CodeGenFunction::EmitFunctionProlog(const CGFunctionInfo &FI,
28712885
// llvm.experimental.vector.extract to convert back to the original
28722886
// VLST.
28732887
if (auto *VecTyTo = dyn_cast<llvm::FixedVectorType>(ConvertType(Ty))) {
2874-
auto *Coerced = Fn->getArg(FirstIRArg);
2888+
llvm::Value *Coerced = Fn->getArg(FirstIRArg);
28752889
if (auto *VecTyFrom =
28762890
dyn_cast<llvm::ScalableVectorType>(Coerced->getType())) {
2891+
// If we are casting a scalable 16 x i1 predicate vector to a fixed i8
2892+
// vector, bitcast the source and use a vector extract.
2893+
auto PredType =
2894+
llvm::ScalableVectorType::get(Builder.getInt1Ty(), 16);
2895+
if (VecTyFrom == PredType &&
2896+
VecTyTo->getElementType() == Builder.getInt8Ty()) {
2897+
VecTyFrom = llvm::ScalableVectorType::get(Builder.getInt8Ty(), 2);
2898+
Coerced = Builder.CreateBitCast(Coerced, VecTyFrom);
2899+
}
28772900
if (VecTyFrom->getElementType() == VecTyTo->getElementType()) {
28782901
llvm::Value *Zero = llvm::Constant::getNullValue(CGM.Int64Ty);
28792902

clang/lib/CodeGen/CGExprScalar.cpp

+28-6
Original file line numberDiff line numberDiff line change
@@ -2084,11 +2084,25 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) {
20842084
// perform the bitcast.
20852085
if (const auto *FixedSrc = dyn_cast<llvm::FixedVectorType>(SrcTy)) {
20862086
if (const auto *ScalableDst = dyn_cast<llvm::ScalableVectorType>(DstTy)) {
2087+
// If we are casting a fixed i8 vector to a scalable 16 x i1 predicate
2088+
// vector, use a vector insert and bitcast the result.
2089+
bool NeedsBitCast = false;
2090+
auto PredType = llvm::ScalableVectorType::get(Builder.getInt1Ty(), 16);
2091+
llvm::Type *OrigType = DstTy;
2092+
if (ScalableDst == PredType &&
2093+
FixedSrc->getElementType() == Builder.getInt8Ty()) {
2094+
DstTy = llvm::ScalableVectorType::get(Builder.getInt8Ty(), 2);
2095+
ScalableDst = dyn_cast<llvm::ScalableVectorType>(DstTy);
2096+
NeedsBitCast = true;
2097+
}
20872098
if (FixedSrc->getElementType() == ScalableDst->getElementType()) {
20882099
llvm::Value *UndefVec = llvm::UndefValue::get(DstTy);
20892100
llvm::Value *Zero = llvm::Constant::getNullValue(CGF.CGM.Int64Ty);
2090-
return Builder.CreateInsertVector(DstTy, UndefVec, Src, Zero,
2091-
"castScalableSve");
2101+
llvm::Value *Result = Builder.CreateInsertVector(
2102+
DstTy, UndefVec, Src, Zero, "castScalableSve");
2103+
if (NeedsBitCast)
2104+
Result = Builder.CreateBitCast(Result, OrigType);
2105+
return Result;
20922106
}
20932107
}
20942108
}
@@ -2098,6 +2112,15 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) {
20982112
// perform the bitcast.
20992113
if (const auto *ScalableSrc = dyn_cast<llvm::ScalableVectorType>(SrcTy)) {
21002114
if (const auto *FixedDst = dyn_cast<llvm::FixedVectorType>(DstTy)) {
2115+
// If we are casting a scalable 16 x i1 predicate vector to a fixed i8
2116+
// vector, bitcast the source and use a vector extract.
2117+
auto PredType = llvm::ScalableVectorType::get(Builder.getInt1Ty(), 16);
2118+
if (ScalableSrc == PredType &&
2119+
FixedDst->getElementType() == Builder.getInt8Ty()) {
2120+
SrcTy = llvm::ScalableVectorType::get(Builder.getInt8Ty(), 2);
2121+
ScalableSrc = dyn_cast<llvm::ScalableVectorType>(SrcTy);
2122+
Src = Builder.CreateBitCast(Src, SrcTy);
2123+
}
21012124
if (ScalableSrc->getElementType() == FixedDst->getElementType()) {
21022125
llvm::Value *Zero = llvm::Constant::getNullValue(CGF.CGM.Int64Ty);
21032126
return Builder.CreateExtractVector(DstTy, Src, Zero, "castFixedSve");
@@ -2108,10 +2131,9 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) {
21082131
// Perform VLAT <-> VLST bitcast through memory.
21092132
// TODO: since the llvm.experimental.vector.{insert,extract} intrinsics
21102133
// require the element types of the vectors to be the same, we
2111-
// need to keep this around for casting between predicates, or more
2112-
// generally for bitcasts between VLAT <-> VLST where the element
2113-
// types of the vectors are not the same, until we figure out a better
2114-
// way of doing these casts.
2134+
// need to keep this around for bitcasts between VLAT <-> VLST where
2135+
// the element types of the vectors are not the same, until we figure
2136+
// out a better way of doing these casts.
21152137
if ((isa<llvm::FixedVectorType>(SrcTy) &&
21162138
isa<llvm::ScalableVectorType>(DstTy)) ||
21172139
(isa<llvm::ScalableVectorType>(SrcTy) &&

clang/lib/CodeGen/CodeGenModule.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ CodeGenModule::CodeGenModule(ASTContext &C, const HeaderSearchOptions &HSO,
189189
!getModule().getSourceFileName().empty()) {
190190
std::string Path = getModule().getSourceFileName();
191191
// Check if a path substitution is needed from the MacroPrefixMap.
192-
for (const auto &Entry : PPO.MacroPrefixMap)
192+
for (const auto &Entry : LangOpts.MacroPrefixMap)
193193
if (Path.rfind(Entry.first, 0) != std::string::npos) {
194194
Path = Entry.second + Path.substr(Entry.first.size());
195195
break;

clang/lib/Frontend/CompilerInvocation.cpp

+9-9
Original file line numberDiff line numberDiff line change
@@ -3561,6 +3561,9 @@ void CompilerInvocation::GenerateLangArgs(const LangOptions &Opts,
35613561
break;
35623562
}
35633563
}
3564+
3565+
for (const auto &MP : Opts.MacroPrefixMap)
3566+
GenerateArg(Args, OPT_fmacro_prefix_map_EQ, MP.first + "=" + MP.second, SA);
35643567
}
35653568

35663569
bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args,
@@ -4105,6 +4108,12 @@ bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args,
41054108
options::OPT_fno_experimental_relative_cxx_abi_vtables,
41064109
TargetCXXABI::usesRelativeVTables(T));
41074110

4111+
for (const auto &A : Args.getAllArgValues(OPT_fmacro_prefix_map_EQ)) {
4112+
auto Split = StringRef(A).split('=');
4113+
Opts.MacroPrefixMap.insert(
4114+
{std::string(Split.first), std::string(Split.second)});
4115+
}
4116+
41084117
return Diags.getNumErrors() == NumErrorsBefore;
41094118
}
41104119

@@ -4177,9 +4186,6 @@ static void GeneratePreprocessorArgs(PreprocessorOptions &Opts,
41774186
for (const auto &D : Opts.DeserializedPCHDeclsToErrorOn)
41784187
GenerateArg(Args, OPT_error_on_deserialized_pch_decl, D, SA);
41794188

4180-
for (const auto &MP : Opts.MacroPrefixMap)
4181-
GenerateArg(Args, OPT_fmacro_prefix_map_EQ, MP.first + "=" + MP.second, SA);
4182-
41834189
if (Opts.PrecompiledPreambleBytes != std::make_pair(0u, false))
41844190
GenerateArg(Args, OPT_preamble_bytes_EQ,
41854191
Twine(Opts.PrecompiledPreambleBytes.first) + "," +
@@ -4248,12 +4254,6 @@ static bool ParsePreprocessorArgs(PreprocessorOptions &Opts, ArgList &Args,
42484254
for (const auto *A : Args.filtered(OPT_error_on_deserialized_pch_decl))
42494255
Opts.DeserializedPCHDeclsToErrorOn.insert(A->getValue());
42504256

4251-
for (const auto &A : Args.getAllArgValues(OPT_fmacro_prefix_map_EQ)) {
4252-
auto Split = StringRef(A).split('=');
4253-
Opts.MacroPrefixMap.insert(
4254-
{std::string(Split.first), std::string(Split.second)});
4255-
}
4256-
42574257
if (const Arg *A = Args.getLastArg(OPT_preamble_bytes_EQ)) {
42584258
StringRef Value(A->getValue());
42594259
size_t Comma = Value.find(',');

0 commit comments

Comments
 (0)