Skip to content

Commit c437ed3

Browse files
committed
Merge from 'main' to 'sycl-web' (#3)
CONFLICT (content): Merge conflict in clang/lib/Frontend/CompilerInvocation.cpp CONFLICT (content): Merge conflict in clang/include/clang/Driver/Options.td
2 parents ed6b605 + 67a4c67 commit c437ed3

File tree

15 files changed

+765
-31
lines changed

15 files changed

+765
-31
lines changed

clang/include/clang/Driver/Options.td

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4162,7 +4162,9 @@ defm sycl : BoolOption<"sycl",
41624162
BothFlags<[CoreOption], " SYCL kernels compilation for device">, "f">,
41634163
Group<sycl_Group>;
41644164
def sycl_std_EQ : Joined<["-"], "sycl-std=">, Group<sycl_Group>, Flags<[CC1Option, NoArgumentUnused, CoreOption]>,
4165-
HelpText<"SYCL language standard to compile for.">, Values<"2017, 121, 1.2.1, sycl-1.2.1">;
4165+
HelpText<"SYCL language standard to compile for.">, Values<"2020,2017,121,1.2.1,sycl-1.2.1">,
4166+
NormalizedValues<["SYCL_2020", "SYCL_2017", "SYCL_2017", "SYCL_2017", "SYCL_2017"]>, NormalizedValuesScope<"LangOptions">,
4167+
MarshallingInfoString<"LangOpts->SYCLVersion", "SYCL_None">, ShouldParseIf<fsycl.KeyPath>, AutoNormalizeEnum;
41664168
def fsycl_esimd : Flag<["-"], "fsycl-explicit-simd">, Group<sycl_Group>, Flags<[CC1Option, NoArgumentUnused, CoreOption]>,
41674169
HelpText<"Enable SYCL explicit SIMD extension">;
41684170
def fno_sycl_esimd : Flag<["-"], "fno-sycl-explicit-simd">, Group<sycl_Group>,

clang/lib/Frontend/CompilerInvocation.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2306,6 +2306,7 @@ static void ParseLangArgs(LangOptions &Opts, ArgList &Args, InputKind IK,
23062306
llvm::StringSwitch<LangOptions::SYCLMajorVersion>(A->getValue())
23072307
.Cases("2017", "1.2.1", "121", "sycl-1.2.1",
23082308
LangOptions::SYCL_2017)
2309+
.Case("2020", LangOptions::SYCL_2020)
23092310
.Default(LangOptions::SYCL_None));
23102311

23112312
if (Opts.getSYCLVersion() == LangOptions::SYCL_None) {
@@ -3028,16 +3029,17 @@ bool CompilerInvocation::parseSimpleArgs(const ArgList &Args,
30283029
DiagnosticsEngine &Diags) {
30293030
#define OPTION_WITH_MARSHALLING( \
30303031
PREFIX_TYPE, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \
3031-
HELPTEXT, METAVAR, VALUES, SPELLING, ALWAYS_EMIT, KEYPATH, DEFAULT_VALUE, \
3032-
IMPLIED_CHECK, IMPLIED_VALUE, NORMALIZER, DENORMALIZER, MERGER, EXTRACTOR, \
3033-
TABLE_INDEX) \
3032+
HELPTEXT, METAVAR, VALUES, SPELLING, SHOULD_PARSE, ALWAYS_EMIT, KEYPATH, \
3033+
DEFAULT_VALUE, IMPLIED_CHECK, IMPLIED_VALUE, NORMALIZER, DENORMALIZER, \
3034+
MERGER, EXTRACTOR, TABLE_INDEX) \
30343035
if ((FLAGS)&options::CC1Option) { \
30353036
this->KEYPATH = MERGER(this->KEYPATH, DEFAULT_VALUE); \
30363037
if (IMPLIED_CHECK) \
30373038
this->KEYPATH = MERGER(this->KEYPATH, IMPLIED_VALUE); \
3038-
if (auto MaybeValue = NORMALIZER(OPT_##ID, TABLE_INDEX, Args, Diags)) \
3039-
this->KEYPATH = MERGER( \
3040-
this->KEYPATH, static_cast<decltype(this->KEYPATH)>(*MaybeValue)); \
3039+
if (SHOULD_PARSE) \
3040+
if (auto MaybeValue = NORMALIZER(OPT_##ID, TABLE_INDEX, Args, Diags)) \
3041+
this->KEYPATH = MERGER( \
3042+
this->KEYPATH, static_cast<decltype(this->KEYPATH)>(*MaybeValue)); \
30413043
}
30423044

30433045
#include "clang/Driver/Options.inc"
@@ -3294,9 +3296,9 @@ void CompilerInvocation::generateCC1CommandLine(
32943296
// with lifetime extension of the reference.
32953297
#define OPTION_WITH_MARSHALLING( \
32963298
PREFIX_TYPE, NAME, ID, KIND, GROUP, ALIAS, ALIASARGS, FLAGS, PARAM, \
3297-
HELPTEXT, METAVAR, VALUES, SPELLING, ALWAYS_EMIT, KEYPATH, DEFAULT_VALUE, \
3298-
IMPLIED_CHECK, IMPLIED_VALUE, NORMALIZER, DENORMALIZER, MERGER, EXTRACTOR, \
3299-
TABLE_INDEX) \
3299+
HELPTEXT, METAVAR, VALUES, SPELLING, SHOULD_PARSE, ALWAYS_EMIT, KEYPATH, \
3300+
DEFAULT_VALUE, IMPLIED_CHECK, IMPLIED_VALUE, NORMALIZER, DENORMALIZER, \
3301+
MERGER, EXTRACTOR, TABLE_INDEX) \
33003302
if ((FLAGS)&options::CC1Option) { \
33013303
[&](const auto &Extracted) { \
33023304
if (ALWAYS_EMIT || \

clang/unittests/Frontend/CompilerInvocationTest.cpp

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,68 @@ TEST_F(CommandLineTest, StringVectorMultiple) {
508508
ASSERT_THAT(GeneratedArgs, ContainsN(HasSubstr("-fmodule-map-file"), 2));
509509
}
510510

511+
// A flag that should be parsed only if a condition is met.
512+
513+
TEST_F(CommandLineTest, ConditionalParsingIfFalseFlagNotPresent) {
514+
const char *Args[] = {""};
515+
516+
CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
517+
518+
ASSERT_FALSE(Diags->hasErrorOccurred());
519+
ASSERT_FALSE(Invocation.getLangOpts()->SYCL);
520+
ASSERT_EQ(Invocation.getLangOpts()->getSYCLVersion(), LangOptions::SYCL_None);
521+
522+
Invocation.generateCC1CommandLine(GeneratedArgs, *this);
523+
524+
ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-fsycl"))));
525+
ASSERT_THAT(GeneratedArgs, Not(Contains(HasSubstr("-sycl-std="))));
526+
}
527+
528+
TEST_F(CommandLineTest, ConditionalParsingIfFalseFlagPresent) {
529+
const char *Args[] = {"-sycl-std=2017"};
530+
531+
CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
532+
533+
ASSERT_FALSE(Diags->hasErrorOccurred());
534+
ASSERT_FALSE(Invocation.getLangOpts()->SYCL);
535+
ASSERT_EQ(Invocation.getLangOpts()->getSYCLVersion(), LangOptions::SYCL_None);
536+
537+
Invocation.generateCC1CommandLine(GeneratedArgs, *this);
538+
539+
ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-fsycl"))));
540+
ASSERT_THAT(GeneratedArgs, Not(Contains(HasSubstr("-sycl-std="))));
541+
}
542+
543+
TEST_F(CommandLineTest, ConditionalParsingIfTrueFlagNotPresent) {
544+
const char *Args[] = {"-fsycl"};
545+
546+
CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
547+
548+
ASSERT_FALSE(Diags->hasErrorOccurred());
549+
ASSERT_TRUE(Invocation.getLangOpts()->SYCL);
550+
ASSERT_EQ(Invocation.getLangOpts()->getSYCLVersion(), LangOptions::SYCL_None);
551+
552+
Invocation.generateCC1CommandLine(GeneratedArgs, *this);
553+
554+
ASSERT_THAT(GeneratedArgs, Contains(StrEq("-fsycl")));
555+
ASSERT_THAT(GeneratedArgs, Not(Contains(HasSubstr("-sycl-std="))));
556+
}
557+
558+
TEST_F(CommandLineTest, ConditionalParsingIfTrueFlagPresent) {
559+
const char *Args[] = {"-fsycl", "-sycl-std=2017"};
560+
561+
CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
562+
563+
ASSERT_FALSE(Diags->hasErrorOccurred());
564+
ASSERT_TRUE(Invocation.getLangOpts()->SYCL);
565+
ASSERT_EQ(Invocation.getLangOpts()->getSYCLVersion(), LangOptions::SYCL_2017);
566+
567+
Invocation.generateCC1CommandLine(GeneratedArgs, *this);
568+
569+
ASSERT_THAT(GeneratedArgs, Contains(StrEq("-fsycl")));
570+
ASSERT_THAT(GeneratedArgs, Contains(StrEq("-sycl-std=2017")));
571+
}
572+
511573
// Wide integer option.
512574

513575
TEST_F(CommandLineTest, WideIntegerHighValue) {

llvm/include/llvm/Option/OptParser.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ class Option<list<string> prefixes, string name, OptionKind kind> {
101101
code DefaultValue = ?;
102102
code ImpliedValue = ?;
103103
code ImpliedCheck = "false";
104+
code ShouldParse = "true";
104105
bit ShouldAlwaysEmit = false;
105106
code NormalizerRetTy = ?;
106107
code NormalizedValuesScope = "";
@@ -202,6 +203,7 @@ class MarshallingInfoBooleanFlag<code keypath, code defaultvalue, code value, co
202203

203204
// Mixins for additional marshalling attributes.
204205

206+
class ShouldParseIf<code condition> { code ShouldParse = condition; }
205207
class AlwaysEmit { bit ShouldAlwaysEmit = true; }
206208
class Normalizer<code normalizer> { code Normalizer = normalizer; }
207209
class Denormalizer<code denormalizer> { code Denormalizer = denormalizer; }

llvm/lib/IR/BasicBlock.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -440,8 +440,12 @@ BasicBlock *BasicBlock::splitBasicBlockBefore(iterator I, const Twine &BBName) {
440440
void BasicBlock::replacePhiUsesWith(BasicBlock *Old, BasicBlock *New) {
441441
// N.B. This might not be a complete BasicBlock, so don't assume
442442
// that it ends with a non-phi instruction.
443-
for (PHINode &PN : phis())
444-
PN.replaceIncomingBlockWith(Old, New);
443+
for (iterator II = begin(), IE = end(); II != IE; ++II) {
444+
PHINode *PN = dyn_cast<PHINode>(II);
445+
if (!PN)
446+
break;
447+
PN->replaceIncomingBlockWith(Old, New);
448+
}
445449
}
446450

447451
void BasicBlock::replaceSuccessorsPhiUsesWith(BasicBlock *Old,

llvm/lib/Target/Hexagon/HexagonLoopIdiomRecognition.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2199,10 +2199,13 @@ bool HexagonLoopIdiomRecognize::processCopyingStore(Loop *CurLoop,
21992199
if (ParentL)
22002200
ParentL->addBasicBlockToLoop(NewPreheader, *LF);
22012201
IRBuilder<>(NewPreheader).CreateBr(Header);
2202-
for (PHINode &PN : Header->phis()) {
2203-
int bx = PN.getBasicBlockIndex(Preheader);
2202+
for (auto &In : *Header) {
2203+
PHINode *PN = dyn_cast<PHINode>(&In);
2204+
if (!PN)
2205+
break;
2206+
int bx = PN->getBasicBlockIndex(Preheader);
22042207
if (bx >= 0)
2205-
PN.setIncomingBlock(bx, NewPreheader);
2208+
PN->setIncomingBlock(bx, NewPreheader);
22062209
}
22072210
DT->addNewBlock(NewPreheader, Preheader);
22082211
DT->changeImmediateDominator(Header, NewPreheader);

llvm/lib/Target/RISCV/RISCVInstrInfoVSDPatterns.td

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ def SplatPat : ComplexPattern<vAny, 1, "selectVSplat", [], [], 1>;
3535
def SplatPat_simm5 : ComplexPattern<vAny, 1, "selectVSplatSimm5", []>;
3636
def SplatPat_uimm5 : ComplexPattern<vAny, 1, "selectVSplatUimm5", []>;
3737

38+
// A mask-vector version of the standard 'vnot' fragment but using splat_vector
39+
// rather than (the implicit) build_vector
40+
def riscv_m_vnot : PatFrag<(ops node:$in),
41+
(xor node:$in, (splat_vector (XLenVT 1)))>;
42+
3843
multiclass VPatUSLoadStoreSDNode<LLVMType type,
3944
LLVMType mask_type,
4045
int sew,
@@ -181,6 +186,36 @@ defm "" : VPatBinarySDNode_VV_VX<udiv, "PseudoVDIV">;
181186
defm "" : VPatBinarySDNode_VV_VX<urem, "PseudoVREMU">;
182187
defm "" : VPatBinarySDNode_VV_VX<srem, "PseudoVREM">;
183188

189+
// 16.1. Vector Mask-Register Logical Instructions
190+
foreach mti = AllMasks in {
191+
def : Pat<(mti.Mask (and VR:$rs1, VR:$rs2)),
192+
(!cast<Instruction>("PseudoVMAND_MM_"#mti.LMul.MX)
193+
VR:$rs1, VR:$rs2, VLMax, mti.SEW)>;
194+
def : Pat<(mti.Mask (or VR:$rs1, VR:$rs2)),
195+
(!cast<Instruction>("PseudoVMOR_MM_"#mti.LMul.MX)
196+
VR:$rs1, VR:$rs2, VLMax, mti.SEW)>;
197+
def : Pat<(mti.Mask (xor VR:$rs1, VR:$rs2)),
198+
(!cast<Instruction>("PseudoVMXOR_MM_"#mti.LMul.MX)
199+
VR:$rs1, VR:$rs2, VLMax, mti.SEW)>;
200+
201+
def : Pat<(mti.Mask (riscv_m_vnot (and VR:$rs1, VR:$rs2))),
202+
(!cast<Instruction>("PseudoVMNAND_MM_"#mti.LMul.MX)
203+
VR:$rs1, VR:$rs2, VLMax, mti.SEW)>;
204+
def : Pat<(mti.Mask (riscv_m_vnot (or VR:$rs1, VR:$rs2))),
205+
(!cast<Instruction>("PseudoVMNOR_MM_"#mti.LMul.MX)
206+
VR:$rs1, VR:$rs2, VLMax, mti.SEW)>;
207+
def : Pat<(mti.Mask (riscv_m_vnot (xor VR:$rs1, VR:$rs2))),
208+
(!cast<Instruction>("PseudoVMXNOR_MM_"#mti.LMul.MX)
209+
VR:$rs1, VR:$rs2, VLMax, mti.SEW)>;
210+
211+
def : Pat<(mti.Mask (and VR:$rs1, (riscv_m_vnot VR:$rs2))),
212+
(!cast<Instruction>("PseudoVMANDNOT_MM_"#mti.LMul.MX)
213+
VR:$rs1, VR:$rs2, VLMax, mti.SEW)>;
214+
def : Pat<(mti.Mask (or VR:$rs1, (riscv_m_vnot VR:$rs2))),
215+
(!cast<Instruction>("PseudoVMORNOT_MM_"#mti.LMul.MX)
216+
VR:$rs1, VR:$rs2, VLMax, mti.SEW)>;
217+
}
218+
184219
} // Predicates = [HasStdExtV]
185220

186221
//===----------------------------------------------------------------------===//
@@ -196,6 +231,13 @@ foreach vti = AllIntegerVectors in {
196231
(!cast<Instruction>("PseudoVMV_V_I_" # vti.LMul.MX)
197232
simm5:$rs1, VLMax, vti.SEW)>;
198233
}
234+
235+
foreach mti = AllMasks in {
236+
def : Pat<(mti.Mask (splat_vector (XLenVT 1))),
237+
(!cast<Instruction>("PseudoVMSET_M_"#mti.BX) VLMax, mti.SEW)>;
238+
def : Pat<(mti.Mask (splat_vector (XLenVT 0))),
239+
(!cast<Instruction>("PseudoVMCLR_M_"#mti.BX) VLMax, mti.SEW)>;
240+
}
199241
} // Predicates = [HasStdExtV]
200242

201243
let Predicates = [HasStdExtV, IsRV32] in {

llvm/lib/Transforms/Scalar/LoopUnrollPass.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -483,20 +483,24 @@ static Optional<EstimatedUnrollCost> analyzeLoopUnrollCost(
483483

484484
// Prepare for the iteration by collecting any simplified entry or backedge
485485
// inputs.
486-
for (PHINode &PHI : L->getHeader()->phis()) {
486+
for (Instruction &I : *L->getHeader()) {
487+
auto *PHI = dyn_cast<PHINode>(&I);
488+
if (!PHI)
489+
break;
490+
487491
// The loop header PHI nodes must have exactly two input: one from the
488492
// loop preheader and one from the loop latch.
489493
assert(
490-
PHI.getNumIncomingValues() == 2 &&
494+
PHI->getNumIncomingValues() == 2 &&
491495
"Must have an incoming value only for the preheader and the latch.");
492496

493-
Value *V = PHI.getIncomingValueForBlock(
497+
Value *V = PHI->getIncomingValueForBlock(
494498
Iteration == 0 ? L->getLoopPreheader() : L->getLoopLatch());
495499
Constant *C = dyn_cast<Constant>(V);
496500
if (Iteration != 0 && !C)
497501
C = SimplifiedValues.lookup(V);
498502
if (C)
499-
SimplifiedInputValues.push_back({&PHI, C});
503+
SimplifiedInputValues.push_back({PHI, C});
500504
}
501505

502506
// Now clear and re-populate the map for the next iteration.
@@ -621,8 +625,12 @@ static Optional<EstimatedUnrollCost> analyzeLoopUnrollCost(
621625
BasicBlock *ExitingBB, *ExitBB;
622626
std::tie(ExitingBB, ExitBB) = ExitWorklist.pop_back_val();
623627

624-
for (PHINode &PN : ExitBB->phis()) {
625-
Value *Op = PN.getIncomingValueForBlock(ExitingBB);
628+
for (Instruction &I : *ExitBB) {
629+
auto *PN = dyn_cast<PHINode>(&I);
630+
if (!PN)
631+
break;
632+
633+
Value *Op = PN->getIncomingValueForBlock(ExitingBB);
626634
if (auto *OpI = dyn_cast<Instruction>(Op))
627635
if (L->contains(OpI))
628636
AddCostRecursively(*OpI, TripCount - 1);

llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2843,8 +2843,12 @@ static void computeLiveInValues(BasicBlock::reverse_iterator Begin,
28432843

28442844
static void computeLiveOutSeed(BasicBlock *BB, SetVector<Value *> &LiveTmp) {
28452845
for (BasicBlock *Succ : successors(BB)) {
2846-
for (PHINode &PN : Succ->phis()) {
2847-
Value *V = PN.getIncomingValueForBlock(BB);
2846+
for (auto &I : *Succ) {
2847+
PHINode *PN = dyn_cast<PHINode>(&I);
2848+
if (!PN)
2849+
break;
2850+
2851+
Value *V = PN->getIncomingValueForBlock(BB);
28482852
assert(!isUnhandledGCPointerType(V->getType()) &&
28492853
"support for FCA unimplemented");
28502854
if (isHandledGCPointerType(V->getType()) && !isa<Constant>(V))

llvm/lib/Transforms/Utils/InlineFunction.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -657,9 +657,13 @@ static void HandleInlinedEHPad(InvokeInst *II, BasicBlock *FirstNewBlock,
657657
// edge from this block.
658658
SmallVector<Value *, 8> UnwindDestPHIValues;
659659
BasicBlock *InvokeBB = II->getParent();
660-
for (PHINode &PHI : UnwindDest->phis())
660+
for (Instruction &I : *UnwindDest) {
661661
// Save the value to use for this edge.
662-
UnwindDestPHIValues.push_back(PHI.getIncomingValueForBlock(InvokeBB));
662+
PHINode *PHI = dyn_cast<PHINode>(&I);
663+
if (!PHI)
664+
break;
665+
UnwindDestPHIValues.push_back(PHI->getIncomingValueForBlock(InvokeBB));
666+
}
663667

664668
// Add incoming-PHI values to the unwind destination block for the given basic
665669
// block, using the values for the original invoke's source block.

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7529,9 +7529,14 @@ bool SLPVectorizerPass::vectorizeChainsInBlock(BasicBlock *BB, BoUpSLP &R) {
75297529

75307530
// Collect the incoming values from the PHIs.
75317531
Incoming.clear();
7532-
for (PHINode &P : BB->phis())
7533-
if (!VisitedInstrs.count(&P) && !R.isDeleted(&P))
7534-
Incoming.push_back(&P);
7532+
for (Instruction &I : *BB) {
7533+
PHINode *P = dyn_cast<PHINode>(&I);
7534+
if (!P)
7535+
break;
7536+
7537+
if (!VisitedInstrs.count(P) && !R.isDeleted(P))
7538+
Incoming.push_back(P);
7539+
}
75357540

75367541
// Sort by type.
75377542
llvm::stable_sort(Incoming, PhiTypeSorterFunc);

0 commit comments

Comments
 (0)