Skip to content

Commit 870d50b

Browse files
authored
Merge branch 'main' into new-feature
2 parents c1e7132 + 6712e20 commit 870d50b

File tree

58 files changed

+4424
-821
lines changed

Some content is hidden

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

58 files changed

+4424
-821
lines changed

bolt/lib/Passes/FrameAnalysis.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ class FrameAccessAnalysis {
198198
if (CFIStack.empty())
199199
dbgs() << "Assertion is about to fail: " << BF.getPrintName() << "\n";
200200
assert(!CFIStack.empty() && "Corrupt CFI stack");
201-
std::pair<int64_t, uint16_t> &Elem = CFIStack.top();
201+
std::pair<int64_t, uint16_t> Elem = CFIStack.top();
202202
CFIStack.pop();
203203
CfaOffset = Elem.first;
204204
CfaReg = Elem.second;

bolt/lib/Passes/ShrinkWrapping.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ void StackLayoutModifier::classifyCFIs() {
402402
break;
403403
case MCCFIInstruction::OpRestoreState: {
404404
assert(!CFIStack.empty() && "Corrupt CFI stack");
405-
std::pair<int64_t, uint16_t> &Elem = CFIStack.top();
405+
std::pair<int64_t, uint16_t> Elem = CFIStack.top();
406406
CFIStack.pop();
407407
CfaOffset = Elem.first;
408408
CfaReg = Elem.second;

clang/include/clang/Basic/TargetInfo.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,6 +1211,25 @@ class TargetInfo : public TransferrableTargetInfo,
12111211
TiedOperand = N;
12121212
// Don't copy Name or constraint string.
12131213
}
1214+
1215+
// For output operand constraints, the target can set bounds to indicate
1216+
// that the result value is guaranteed to fall within a certain range.
1217+
// This will cause corresponding assertions to be emitted that will allow
1218+
// for potential optimization based of that guarantee.
1219+
//
1220+
// NOTE: This re-uses the `ImmRange` fields to store the range, which are
1221+
// otherwise unused for constraint types used for output operands.
1222+
void setOutputOperandBounds(unsigned Min, unsigned Max) {
1223+
ImmRange.Min = Min;
1224+
ImmRange.Max = Max;
1225+
ImmRange.isConstrained = true;
1226+
}
1227+
std::optional<std::pair<unsigned, unsigned>>
1228+
getOutputOperandBounds() const {
1229+
return ImmRange.isConstrained
1230+
? std::make_pair(ImmRange.Min, ImmRange.Max)
1231+
: std::optional<std::pair<unsigned, unsigned>>();
1232+
}
12141233
};
12151234

12161235
/// Validate register name used for global register variables.

clang/lib/Basic/Targets/AArch64.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1568,6 +1568,7 @@ bool AArch64TargetInfo::validateAsmConstraint(
15681568
if (const unsigned Len = matchAsmCCConstraint(Name)) {
15691569
Name += Len - 1;
15701570
Info.setAllowsRegister();
1571+
Info.setOutputOperandBounds(0, 2);
15711572
return true;
15721573
}
15731574
}

clang/lib/Basic/Targets/SystemZ.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,16 @@ bool SystemZTargetInfo::validateAsmConstraint(
9999
case 'T': // Likewise, plus an index
100100
Info.setAllowsMemory();
101101
return true;
102+
case '@':
103+
// CC condition changes.
104+
if (StringRef(Name) == "@cc") {
105+
Name += 2;
106+
Info.setAllowsRegister();
107+
// SystemZ has 2-bits CC, and hence Interval [0, 4).
108+
Info.setOutputOperandBounds(0, 4);
109+
return true;
110+
}
111+
return false;
102112
}
103113
}
104114

@@ -161,6 +171,9 @@ unsigned SystemZTargetInfo::getMinGlobalAlign(uint64_t Size,
161171

162172
void SystemZTargetInfo::getTargetDefines(const LangOptions &Opts,
163173
MacroBuilder &Builder) const {
174+
// Inline assembly supports SystemZ flag outputs.
175+
Builder.defineMacro("__GCC_ASM_FLAG_OUTPUTS__");
176+
164177
Builder.defineMacro("__s390__");
165178
Builder.defineMacro("__s390x__");
166179
Builder.defineMacro("__zarch__");

clang/lib/Basic/Targets/SystemZ.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,12 @@ class LLVM_LIBRARY_VISIBILITY SystemZTargetInfo : public TargetInfo {
136136

137137
std::string convertConstraint(const char *&Constraint) const override {
138138
switch (Constraint[0]) {
139+
case '@': // Flag output operand.
140+
if (llvm::StringRef(Constraint) == "@cc") {
141+
Constraint += 2;
142+
return std::string("{@cc}");
143+
}
144+
break;
139145
case 'p': // Keep 'p' constraint.
140146
return std::string("p");
141147
case 'Z':

clang/lib/Basic/Targets/X86.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1516,6 +1516,7 @@ bool X86TargetInfo::validateAsmConstraint(
15161516
if (auto Len = matchAsmCCConstraint(Name)) {
15171517
Name += Len - 1;
15181518
Info.setAllowsRegister();
1519+
Info.setOutputOperandBounds(0, 2);
15191520
return true;
15201521
}
15211522
return false;

clang/lib/CodeGen/CGStmt.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2674,7 +2674,8 @@ EmitAsmStores(CodeGenFunction &CGF, const AsmStmt &S,
26742674
const llvm::ArrayRef<LValue> ResultRegDests,
26752675
const llvm::ArrayRef<QualType> ResultRegQualTys,
26762676
const llvm::BitVector &ResultTypeRequiresCast,
2677-
const llvm::BitVector &ResultRegIsFlagReg) {
2677+
const std::vector<std::optional<std::pair<unsigned, unsigned>>>
2678+
&ResultBounds) {
26782679
CGBuilderTy &Builder = CGF.Builder;
26792680
CodeGenModule &CGM = CGF.CGM;
26802681
llvm::LLVMContext &CTX = CGF.getLLVMContext();
@@ -2685,18 +2686,20 @@ EmitAsmStores(CodeGenFunction &CGF, const AsmStmt &S,
26852686
// ResultRegDests can be also populated by addReturnRegisterOutputs() above,
26862687
// in which case its size may grow.
26872688
assert(ResultTypeRequiresCast.size() <= ResultRegDests.size());
2688-
assert(ResultRegIsFlagReg.size() <= ResultRegDests.size());
2689+
assert(ResultBounds.size() <= ResultRegDests.size());
26892690

26902691
for (unsigned i = 0, e = RegResults.size(); i != e; ++i) {
26912692
llvm::Value *Tmp = RegResults[i];
26922693
llvm::Type *TruncTy = ResultTruncRegTypes[i];
26932694

2694-
if ((i < ResultRegIsFlagReg.size()) && ResultRegIsFlagReg[i]) {
2695-
// Target must guarantee the Value `Tmp` here is lowered to a boolean
2696-
// value.
2697-
llvm::Constant *Two = llvm::ConstantInt::get(Tmp->getType(), 2);
2695+
if ((i < ResultBounds.size()) && ResultBounds[i].has_value()) {
2696+
const auto [LowerBound, UpperBound] = ResultBounds[i].value();
2697+
// FIXME: Support for nonzero lower bounds not yet implemented.
2698+
assert(LowerBound == 0 && "Output operand lower bound is not zero.");
2699+
llvm::Constant *UpperBoundConst =
2700+
llvm::ConstantInt::get(Tmp->getType(), UpperBound);
26982701
llvm::Value *IsBooleanValue =
2699-
Builder.CreateCmp(llvm::CmpInst::ICMP_ULT, Tmp, Two);
2702+
Builder.CreateCmp(llvm::CmpInst::ICMP_ULT, Tmp, UpperBoundConst);
27002703
llvm::Function *FnAssume = CGM.getIntrinsic(llvm::Intrinsic::assume);
27012704
Builder.CreateCall(FnAssume, IsBooleanValue);
27022705
}
@@ -2825,7 +2828,7 @@ void CodeGenFunction::EmitAsmStmt(const AsmStmt &S) {
28252828
std::vector<llvm::Type *> ArgElemTypes;
28262829
std::vector<llvm::Value*> Args;
28272830
llvm::BitVector ResultTypeRequiresCast;
2828-
llvm::BitVector ResultRegIsFlagReg;
2831+
std::vector<std::optional<std::pair<unsigned, unsigned>>> ResultBounds;
28292832

28302833
// Keep track of inout constraints.
28312834
std::string InOutConstraints;
@@ -2883,8 +2886,7 @@ void CodeGenFunction::EmitAsmStmt(const AsmStmt &S) {
28832886
ResultRegQualTys.push_back(QTy);
28842887
ResultRegDests.push_back(Dest);
28852888

2886-
bool IsFlagReg = llvm::StringRef(OutputConstraint).starts_with("{@cc");
2887-
ResultRegIsFlagReg.push_back(IsFlagReg);
2889+
ResultBounds.emplace_back(Info.getOutputOperandBounds());
28882890

28892891
llvm::Type *Ty = ConvertTypeForMem(QTy);
28902892
const bool RequiresCast = Info.allowsRegister() &&
@@ -3231,7 +3233,7 @@ void CodeGenFunction::EmitAsmStmt(const AsmStmt &S) {
32313233

32323234
EmitAsmStores(*this, S, RegResults, ResultRegTypes, ResultTruncRegTypes,
32333235
ResultRegDests, ResultRegQualTys, ResultTypeRequiresCast,
3234-
ResultRegIsFlagReg);
3236+
ResultBounds);
32353237

32363238
// If this is an asm goto with outputs, repeat EmitAsmStores, but with a
32373239
// different insertion point; one for each indirect destination and with
@@ -3242,7 +3244,7 @@ void CodeGenFunction::EmitAsmStmt(const AsmStmt &S) {
32423244
Builder.SetInsertPoint(Succ, --(Succ->end()));
32433245
EmitAsmStores(*this, S, CBRRegResults[Succ], ResultRegTypes,
32443246
ResultTruncRegTypes, ResultRegDests, ResultRegQualTys,
3245-
ResultTypeRequiresCast, ResultRegIsFlagReg);
3247+
ResultTypeRequiresCast, ResultBounds);
32463248
}
32473249
}
32483250
}

clang/lib/CodeGen/Targets/RISCV.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -680,22 +680,22 @@ ABIArgInfo RISCVABIInfo::classifyArgumentType(QualType Ty, bool IsFixed,
680680
if (const auto *ED = Ty->getAsEnumDecl())
681681
Ty = ED->getIntegerType();
682682

683-
// All integral types are promoted to XLen width
684-
if (Size < XLen && Ty->isIntegralOrEnumerationType()) {
685-
return extendType(Ty, CGT.ConvertType(Ty));
686-
}
687-
688683
if (const auto *EIT = Ty->getAs<BitIntType>()) {
689-
if (EIT->getNumBits() < XLen)
684+
685+
if (XLen == 64 && EIT->getNumBits() == 32)
690686
return extendType(Ty, CGT.ConvertType(Ty));
691-
if (EIT->getNumBits() > 128 ||
692-
(!getContext().getTargetInfo().hasInt128Type() &&
693-
EIT->getNumBits() > 64))
694-
return getNaturalAlignIndirect(
695-
Ty, /*AddrSpace=*/getDataLayout().getAllocaAddrSpace(),
696-
/*ByVal=*/false);
687+
688+
if (EIT->getNumBits() <= 2 * XLen)
689+
return ABIArgInfo::getExtend(Ty, CGT.ConvertType(Ty));
690+
return getNaturalAlignIndirect(
691+
Ty, /*AddrSpace=*/getDataLayout().getAllocaAddrSpace(),
692+
/*ByVal=*/false);
697693
}
698694

695+
// All integral types are promoted to XLen width
696+
if (Size < XLen && Ty->isIntegralOrEnumerationType())
697+
return extendType(Ty, CGT.ConvertType(Ty));
698+
699699
return ABIArgInfo::getDirect();
700700
}
701701

clang/lib/Sema/SemaConcept.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,8 @@ ConstraintSatisfactionChecker::SubstitutionInTemplateArguments(
614614
for (unsigned I = 0, MappedIndex = 0; I < Used.size(); I++) {
615615
TemplateArgument Arg;
616616
if (Used[I])
617-
Arg = CTAI.SugaredConverted[MappedIndex++];
617+
Arg = S.Context.getCanonicalTemplateArgument(
618+
CTAI.SugaredConverted[MappedIndex++]);
618619
if (I < SubstitutedOuterMost.size()) {
619620
SubstitutedOuterMost[I] = Arg;
620621
Offset = I + 1;

0 commit comments

Comments
 (0)