Skip to content

Commit ddfbfd6

Browse files
el-evandykaylor
andauthored
[NFC][clang] Move simplifyConstraint to TargetInfo.cpp (#154905)
Co-authored-by: Andy Kaylor <[email protected]>
1 parent 1ab4113 commit ddfbfd6

File tree

3 files changed

+57
-54
lines changed

3 files changed

+57
-54
lines changed

clang/include/clang/Basic/TargetInfo.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,6 +1259,10 @@ class TargetInfo : public TransferrableTargetInfo,
12591259
ArrayRef<ConstraintInfo> OutputConstraints,
12601260
unsigned &Index) const;
12611261

1262+
std::string
1263+
simplifyConstraint(StringRef Constraint,
1264+
SmallVectorImpl<ConstraintInfo> *OutCons = nullptr) const;
1265+
12621266
// Constraint parm will be left pointing at the last character of
12631267
// the constraint. In practice, it won't be changed unless the
12641268
// constraint is longer than one character.

clang/lib/Basic/TargetInfo.cpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "clang/Basic/LangOptions.h"
1919
#include "llvm/ADT/APFloat.h"
2020
#include "llvm/ADT/STLExtras.h"
21+
#include "llvm/ADT/StringExtras.h"
2122
#include "llvm/Support/ErrorHandling.h"
2223
#include "llvm/TargetParser/TargetParser.h"
2324
#include <cstdlib>
@@ -1042,3 +1043,51 @@ void TargetInfo::copyAuxTarget(const TargetInfo *Aux) {
10421043
auto *Src = static_cast<const TransferrableTargetInfo*>(Aux);
10431044
*Target = *Src;
10441045
}
1046+
1047+
std::string
1048+
TargetInfo::simplifyConstraint(StringRef Constraint,
1049+
SmallVectorImpl<ConstraintInfo> *OutCons) const {
1050+
std::string Result;
1051+
1052+
for (const char *I = Constraint.begin(), *E = Constraint.end(); I < E; I++) {
1053+
switch (*I) {
1054+
default:
1055+
Result += convertConstraint(I);
1056+
break;
1057+
// Ignore these
1058+
case '*':
1059+
case '?':
1060+
case '!':
1061+
case '=': // Will see this and the following in mult-alt constraints.
1062+
case '+':
1063+
break;
1064+
case '#': // Ignore the rest of the constraint alternative.
1065+
while (I + 1 != E && I[1] != ',')
1066+
I++;
1067+
break;
1068+
case '&':
1069+
case '%':
1070+
Result += *I;
1071+
while (I + 1 != E && I[1] == *I)
1072+
I++;
1073+
break;
1074+
case ',':
1075+
Result += "|";
1076+
break;
1077+
case 'g':
1078+
Result += "imr";
1079+
break;
1080+
case '[': {
1081+
assert(OutCons &&
1082+
"Must pass output names to constraints with a symbolic name");
1083+
unsigned Index;
1084+
bool ResolveResult = resolveSymbolicName(I, *OutCons, Index);
1085+
assert(ResolveResult && "Could not resolve symbolic name");
1086+
(void)ResolveResult;
1087+
Result += llvm::utostr(Index);
1088+
break;
1089+
}
1090+
}
1091+
}
1092+
return Result;
1093+
}

clang/lib/CodeGen/CGStmt.cpp

Lines changed: 4 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -2471,56 +2471,6 @@ void CodeGenFunction::EmitSwitchStmt(const SwitchStmt &S) {
24712471
CaseRangeBlock = SavedCRBlock;
24722472
}
24732473

2474-
static std::string
2475-
SimplifyConstraint(const char *Constraint, const TargetInfo &Target,
2476-
SmallVectorImpl<TargetInfo::ConstraintInfo> *OutCons=nullptr) {
2477-
std::string Result;
2478-
2479-
while (*Constraint) {
2480-
switch (*Constraint) {
2481-
default:
2482-
Result += Target.convertConstraint(Constraint);
2483-
break;
2484-
// Ignore these
2485-
case '*':
2486-
case '?':
2487-
case '!':
2488-
case '=': // Will see this and the following in mult-alt constraints.
2489-
case '+':
2490-
break;
2491-
case '#': // Ignore the rest of the constraint alternative.
2492-
while (Constraint[1] && Constraint[1] != ',')
2493-
Constraint++;
2494-
break;
2495-
case '&':
2496-
case '%':
2497-
Result += *Constraint;
2498-
while (Constraint[1] && Constraint[1] == *Constraint)
2499-
Constraint++;
2500-
break;
2501-
case ',':
2502-
Result += "|";
2503-
break;
2504-
case 'g':
2505-
Result += "imr";
2506-
break;
2507-
case '[': {
2508-
assert(OutCons &&
2509-
"Must pass output names to constraints with a symbolic name");
2510-
unsigned Index;
2511-
bool result = Target.resolveSymbolicName(Constraint, *OutCons, Index);
2512-
assert(result && "Could not resolve symbolic name"); (void)result;
2513-
Result += llvm::utostr(Index);
2514-
break;
2515-
}
2516-
}
2517-
2518-
Constraint++;
2519-
}
2520-
2521-
return Result;
2522-
}
2523-
25242474
/// AddVariableConstraints - Look at AsmExpr and if it is a variable declared
25252475
/// as using a particular register add that as a constraint that will be used
25262476
/// in this asm stmt.
@@ -2899,8 +2849,8 @@ void CodeGenFunction::EmitAsmStmt(const AsmStmt &S) {
28992849

29002850
// Simplify the output constraint.
29012851
std::string OutputConstraint(S.getOutputConstraint(i));
2902-
OutputConstraint = SimplifyConstraint(OutputConstraint.c_str() + 1,
2903-
getTarget(), &OutputConstraintInfos);
2852+
OutputConstraint = getTarget().simplifyConstraint(
2853+
StringRef(OutputConstraint).substr(1), &OutputConstraintInfos);
29042854

29052855
const Expr *OutExpr = S.getOutputExpr(i);
29062856
OutExpr = OutExpr->IgnoreParenNoopCasts(getContext());
@@ -3062,8 +3012,8 @@ void CodeGenFunction::EmitAsmStmt(const AsmStmt &S) {
30623012

30633013
// Simplify the input constraint.
30643014
std::string InputConstraint(S.getInputConstraint(i));
3065-
InputConstraint = SimplifyConstraint(InputConstraint.c_str(), getTarget(),
3066-
&OutputConstraintInfos);
3015+
InputConstraint =
3016+
getTarget().simplifyConstraint(InputConstraint, &OutputConstraintInfos);
30673017

30683018
InputConstraint = AddVariableConstraints(
30693019
InputConstraint, *InputExpr->IgnoreParenNoopCasts(getContext()),

0 commit comments

Comments
 (0)