Skip to content

Commit d787c8b

Browse files
author
anoopkg6
committed
Incorporated changes for code review feedback.
1 parent 7ea0c5f commit d787c8b

File tree

8 files changed

+190
-222
lines changed

8 files changed

+190
-222
lines changed

clang/include/clang/Basic/TargetInfo.h

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,12 +1114,11 @@ class TargetInfo : public TransferrableTargetInfo,
11141114

11151115
std::string ConstraintStr; // constraint: "=rm"
11161116
std::string Name; // Operand name: [foo] with no []'s.
1117-
unsigned FlagOutputCCUpperBound;
11181117

11191118
public:
11201119
ConstraintInfo(StringRef ConstraintStr, StringRef Name)
11211120
: Flags(0), TiedOperand(-1), ConstraintStr(ConstraintStr.str()),
1122-
Name(Name.str()), FlagOutputCCUpperBound(0) {
1121+
Name(Name.str()) {
11231122
ImmRange.Min = ImmRange.Max = 0;
11241123
ImmRange.isConstrained = false;
11251124
}
@@ -1191,13 +1190,13 @@ class TargetInfo : public TransferrableTargetInfo,
11911190
// Don't copy Name or constraint string.
11921191
}
11931192

1194-
// CC range can be set by target. SystemZ sets it to 4. It is 2 by default.
1193+
// CC range can be set by targets supporting flag output operand.
11951194
void setFlagOutputCCUpperBound(unsigned CCBound) {
1196-
FlagOutputCCUpperBound = CCBound;
1197-
}
1198-
unsigned getFlagOutputCCUpperBound() const {
1199-
return FlagOutputCCUpperBound;
1195+
// Using ImmRange.Max to store CC upper bound. Interval [0, CCBound).
1196+
ImmRange.Max = CCBound;
1197+
ImmRange.isConstrained = true;
12001198
}
1199+
unsigned getFlagOutputCCUpperBound() const { return ImmRange.Max; }
12011200
};
12021201

12031202
/// Validate register name used for global register variables.
@@ -1238,7 +1237,6 @@ class TargetInfo : public TransferrableTargetInfo,
12381237
std::string &/*SuggestedModifier*/) const {
12391238
return true;
12401239
}
1241-
12421240
virtual bool
12431241
validateAsmConstraint(const char *&Name,
12441242
TargetInfo::ConstraintInfo &info) const = 0;

clang/lib/Basic/Targets/SystemZ.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ bool SystemZTargetInfo::validateAsmConstraint(
103103
if (StringRef(Name) == "@cc") {
104104
Name += 2;
105105
Info.setAllowsRegister();
106+
// SystemZ has 2-bits CC, and hence Interval [0, 4).
106107
Info.setFlagOutputCCUpperBound(4);
107108
return true;
108109
}

clang/lib/Basic/Targets/SystemZ.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,13 @@ class LLVM_LIBRARY_VISIBILITY SystemZTargetInfo : public TargetInfo {
119119
TargetInfo::ConstraintInfo &info) const override;
120120

121121
std::string convertConstraint(const char *&Constraint) const override {
122-
if (llvm::StringRef(Constraint) == "@cc") {
123-
Constraint += 2;
124-
return std::string("{@cc}");
125-
}
126122
switch (Constraint[0]) {
123+
case '@': // Flag output operand.
124+
if (llvm::StringRef(Constraint) == "@cc") {
125+
Constraint += 2;
126+
return std::string("{@cc}");
127+
}
128+
break;
127129
case 'p': // Keep 'p' constraint.
128130
return std::string("p");
129131
case 'Z':

clang/lib/CodeGen/CGStmt.cpp

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2601,7 +2601,7 @@ EmitAsmStores(CodeGenFunction &CGF, const AsmStmt &S,
26012601
const llvm::ArrayRef<LValue> ResultRegDests,
26022602
const llvm::ArrayRef<QualType> ResultRegQualTys,
26032603
const llvm::BitVector &ResultTypeRequiresCast,
2604-
const std::vector<unsigned> &ResultRegIsFlagReg) {
2604+
const std::vector<unsigned> &ResultFlagRegCCBound) {
26052605
CGBuilderTy &Builder = CGF.Builder;
26062606
CodeGenModule &CGM = CGF.CGM;
26072607
llvm::LLVMContext &CTX = CGF.getLLVMContext();
@@ -2612,23 +2612,19 @@ EmitAsmStores(CodeGenFunction &CGF, const AsmStmt &S,
26122612
// ResultRegDests can be also populated by addReturnRegisterOutputs() above,
26132613
// in which case its size may grow.
26142614
assert(ResultTypeRequiresCast.size() <= ResultRegDests.size());
2615-
assert(ResultRegIsFlagReg.size() <= ResultRegDests.size());
2615+
assert(ResultFlagRegCCBound.size() <= ResultRegDests.size());
26162616

26172617
for (unsigned i = 0, e = RegResults.size(); i != e; ++i) {
26182618
llvm::Value *Tmp = RegResults[i];
26192619
llvm::Type *TruncTy = ResultTruncRegTypes[i];
26202620

2621-
if ((i < ResultRegIsFlagReg.size()) && ResultRegIsFlagReg[i]) {
2621+
if ((i < ResultFlagRegCCBound.size()) && ResultFlagRegCCBound[i]) {
26222622
// Target must guarantee the Value `Tmp` here is lowered to a boolean
26232623
// value.
2624-
// Lowering 'Tmp' as - 'icmp ult %Tmp , CCUpperBound'. On some targets
2625-
// CCUpperBound is not binary. CCUpperBound is 4 for SystemZ,
2626-
// interval [0, 4). With this range known, llvm.assume intrinsic guides
2627-
// optimizer to generate more optimized IR in most of the cases as
2628-
// observed for select_cc on SystemZ unit tests for flag output operands.
2629-
// For some cases for br_cc, generated IR was weird. e.g. switch table
2630-
// for simple simple comparison terms for br_cc.
2631-
unsigned CCUpperBound = ResultRegIsFlagReg[i];
2624+
// Lowering 'Tmp' as - 'icmp ult %Tmp , CCUpperBound'.
2625+
unsigned CCUpperBound = ResultFlagRegCCBound[i];
2626+
assert((CCUpperBound == 2 || CCUpperBound == 4) &&
2627+
"CC upper bound out of range!");
26322628
llvm::Constant *CCUpperBoundConst =
26332629
llvm::ConstantInt::get(Tmp->getType(), CCUpperBound);
26342630
llvm::Value *IsBooleanValue =
@@ -2759,7 +2755,7 @@ void CodeGenFunction::EmitAsmStmt(const AsmStmt &S) {
27592755
std::vector<llvm::Type *> ArgElemTypes;
27602756
std::vector<llvm::Value*> Args;
27612757
llvm::BitVector ResultTypeRequiresCast;
2762-
std::vector<unsigned> ResultRegIsFlagReg;
2758+
std::vector<unsigned> ResultFlagRegCCBound;
27632759

27642760
// Keep track of inout constraints.
27652761
std::string InOutConstraints;
@@ -2817,7 +2813,7 @@ void CodeGenFunction::EmitAsmStmt(const AsmStmt &S) {
28172813
ResultRegQualTys.push_back(QTy);
28182814
ResultRegDests.push_back(Dest);
28192815

2820-
ResultRegIsFlagReg.push_back(Info.getFlagOutputCCUpperBound());
2816+
ResultFlagRegCCBound.push_back(Info.getFlagOutputCCUpperBound());
28212817

28222818
llvm::Type *Ty = ConvertTypeForMem(QTy);
28232819
const bool RequiresCast = Info.allowsRegister() &&
@@ -3164,7 +3160,7 @@ void CodeGenFunction::EmitAsmStmt(const AsmStmt &S) {
31643160

31653161
EmitAsmStores(*this, S, RegResults, ResultRegTypes, ResultTruncRegTypes,
31663162
ResultRegDests, ResultRegQualTys, ResultTypeRequiresCast,
3167-
ResultRegIsFlagReg);
3163+
ResultFlagRegCCBound);
31683164

31693165
// If this is an asm goto with outputs, repeat EmitAsmStores, but with a
31703166
// different insertion point; one for each indirect destination and with
@@ -3175,7 +3171,7 @@ void CodeGenFunction::EmitAsmStmt(const AsmStmt &S) {
31753171
Builder.SetInsertPoint(Succ, --(Succ->end()));
31763172
EmitAsmStores(*this, S, CBRRegResults[Succ], ResultRegTypes,
31773173
ResultTruncRegTypes, ResultRegDests, ResultRegQualTys,
3178-
ResultTypeRequiresCast, ResultRegIsFlagReg);
3174+
ResultTypeRequiresCast, ResultFlagRegCCBound);
31793175
}
31803176
}
31813177
}

llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12117,13 +12117,12 @@ void SelectionDAGBuilder::lowerWorkItem(SwitchWorkListItem W, Value *Cond,
1211712117
SDValue CondLHS = getValue(Cond);
1211812118
EVT VT = CondLHS.getValueType();
1211912119
SDLoc DL = getCurSDLoc();
12120-
SDValue Cond;
1212112120

1212212121
SDValue Or = DAG.getNode(ISD::OR, DL, VT, CondLHS,
1212312122
DAG.getConstant(CommonBit, DL, VT));
12124-
Cond = DAG.getSetCC(DL, MVT::i1, Or,
12125-
DAG.getConstant(BigValue | SmallValue, DL, VT),
12126-
ISD::SETEQ);
12123+
SDValue Cond = DAG.getSetCC(
12124+
DL, MVT::i1, Or, DAG.getConstant(BigValue | SmallValue, DL, VT),
12125+
ISD::SETEQ);
1212712126

1212812127
// Update successor info.
1212912128
// Both Small and Big will jump to Small.BB, so we sum up the

0 commit comments

Comments
 (0)