Skip to content

Commit a481934

Browse files
author
anoopkg6
committed
1. Use std::optional<std::pair<unsigned, unsigned>> for getOutputoperand()
2. Change setOutputOperand() implementation by directly setting ImmRange fields Min/Max/isConstrainedlds.
1 parent 365de38 commit a481934

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

clang/include/clang/Basic/TargetInfo.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,11 +1214,15 @@ class TargetInfo : public TransferrableTargetInfo,
12141214

12151215
// Output operand bounds can be set by target.
12161216
void setOutputOperandBounds(unsigned Min, unsigned Max) {
1217-
setRequiresImmediate(Min, Max);
1217+
ImmRange.Min = Min;
1218+
ImmRange.Max = Max;
1219+
ImmRange.isConstrained = true;
12181220
}
1219-
std::pair<unsigned, unsigned> getOutputOperandBounds() const {
1220-
return ImmRange.isConstrained ? std::make_pair(ImmRange.Min, ImmRange.Max)
1221-
: std::make_pair(0, 0);
1221+
std::optional<std::pair<unsigned, unsigned>>
1222+
getOutputOperandBounds() const {
1223+
return ImmRange.isConstrained
1224+
? std::make_pair(ImmRange.Min, ImmRange.Max)
1225+
: std::optional<std::pair<unsigned, unsigned>>();
12221226
}
12231227
};
12241228

clang/lib/CodeGen/CGStmt.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2704,7 +2704,8 @@ EmitAsmStores(CodeGenFunction &CGF, const AsmStmt &S,
27042704
const llvm::ArrayRef<LValue> ResultRegDests,
27052705
const llvm::ArrayRef<QualType> ResultRegQualTys,
27062706
const llvm::BitVector &ResultTypeRequiresCast,
2707-
const std::vector<unsigned> &OutputOperandBounds) {
2707+
const std::vector<std::optional<std::pair<unsigned, unsigned>>>
2708+
&OutputOperandBounds) {
27082709
CGBuilderTy &Builder = CGF.Builder;
27092710
CodeGenModule &CGM = CGF.CGM;
27102711
llvm::LLVMContext &CTX = CGF.getLLVMContext();
@@ -2721,12 +2722,10 @@ EmitAsmStores(CodeGenFunction &CGF, const AsmStmt &S,
27212722
llvm::Value *Tmp = RegResults[i];
27222723
llvm::Type *TruncTy = ResultTruncRegTypes[i];
27232724

2724-
if ((i < OutputOperandBounds.size()) && OutputOperandBounds[i]) {
2725-
// Target must guarantee the Value `Tmp` here is lowered to a boolean
2726-
// value.
2727-
// Lowering 'Tmp' as - 'icmp ult %Tmp , CCUpperBound'.
2728-
unsigned UpperBound = OutputOperandBounds[i];
2729-
assert(UpperBound <= 4 && "Output operand out of range!");
2725+
if ((i < OutputOperandBounds.size()) &&
2726+
OutputOperandBounds[i].has_value()) {
2727+
const auto [LowerBound, UpperBound] = OutputOperandBounds[i].value();
2728+
assert(LowerBound == 0 && "Output operand lower bound is not zero.");
27302729
llvm::Constant *UpperBoundConst =
27312730
llvm::ConstantInt::get(Tmp->getType(), UpperBound);
27322731
llvm::Value *IsBooleanValue =
@@ -2859,7 +2858,7 @@ void CodeGenFunction::EmitAsmStmt(const AsmStmt &S) {
28592858
std::vector<llvm::Type *> ArgElemTypes;
28602859
std::vector<llvm::Value*> Args;
28612860
llvm::BitVector ResultTypeRequiresCast;
2862-
std::vector<unsigned> OutputOperandBounds;
2861+
std::vector<std::optional<std::pair<unsigned, unsigned>>> OutputOperandBounds;
28632862

28642863
// Keep track of inout constraints.
28652864
std::string InOutConstraints;
@@ -2917,8 +2916,7 @@ void CodeGenFunction::EmitAsmStmt(const AsmStmt &S) {
29172916
ResultRegQualTys.push_back(QTy);
29182917
ResultRegDests.push_back(Dest);
29192918

2920-
const auto [_, UpperBound] = Info.getOutputOperandBounds();
2921-
OutputOperandBounds.push_back(UpperBound);
2919+
OutputOperandBounds.emplace_back(Info.getOutputOperandBounds());
29222920

29232921
llvm::Type *Ty = ConvertTypeForMem(QTy);
29242922
const bool RequiresCast = Info.allowsRegister() &&

0 commit comments

Comments
 (0)