Skip to content

Commit 2da6e65

Browse files
committed
[NFC][clang] Move simplifyConstraint to TargetInfo.cpp
1 parent d6fae7f commit 2da6e65

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>
@@ -1034,3 +1035,51 @@ void TargetInfo::copyAuxTarget(const TargetInfo *Aux) {
10341035
auto *Src = static_cast<const TransferrableTargetInfo*>(Aux);
10351036
*Target = *Src;
10361037
}
1038+
1039+
std::string
1040+
TargetInfo::simplifyConstraint(StringRef Constraint,
1041+
SmallVectorImpl<ConstraintInfo> *OutCons) const {
1042+
std::string Result;
1043+
1044+
for (const char *I = Constraint.begin(), *E = Constraint.end(); I < E; I++) {
1045+
switch (*I) {
1046+
default:
1047+
Result += convertConstraint(I);
1048+
break;
1049+
// Ignore these
1050+
case '*':
1051+
case '?':
1052+
case '!':
1053+
case '=': // Will see this and the following in mult-alt constraints.
1054+
case '+':
1055+
break;
1056+
case '#': // Ignore the rest of the constraint alternative.
1057+
while (I + 1 != E && I[1] != ',')
1058+
I++;
1059+
break;
1060+
case '&':
1061+
case '%':
1062+
Result += *I;
1063+
while (I + 1 != E && I[1] == *I)
1064+
I++;
1065+
break;
1066+
case ',':
1067+
Result += "|";
1068+
break;
1069+
case 'g':
1070+
Result += "imr";
1071+
break;
1072+
case '[': {
1073+
assert(OutCons &&
1074+
"Must pass output names to constraints with a symbolic name");
1075+
unsigned Index;
1076+
bool ResolveResult = resolveSymbolicName(I, *OutCons, Index);
1077+
assert(ResolveResult && "Could not resolve symbolic name");
1078+
(void)ResolveResult;
1079+
Result += llvm::utostr(Index);
1080+
break;
1081+
}
1082+
}
1083+
}
1084+
return Result;
1085+
}

clang/lib/CodeGen/CGStmt.cpp

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

2457-
static std::string
2458-
SimplifyConstraint(const char *Constraint, const TargetInfo &Target,
2459-
SmallVectorImpl<TargetInfo::ConstraintInfo> *OutCons=nullptr) {
2460-
std::string Result;
2461-
2462-
while (*Constraint) {
2463-
switch (*Constraint) {
2464-
default:
2465-
Result += Target.convertConstraint(Constraint);
2466-
break;
2467-
// Ignore these
2468-
case '*':
2469-
case '?':
2470-
case '!':
2471-
case '=': // Will see this and the following in mult-alt constraints.
2472-
case '+':
2473-
break;
2474-
case '#': // Ignore the rest of the constraint alternative.
2475-
while (Constraint[1] && Constraint[1] != ',')
2476-
Constraint++;
2477-
break;
2478-
case '&':
2479-
case '%':
2480-
Result += *Constraint;
2481-
while (Constraint[1] && Constraint[1] == *Constraint)
2482-
Constraint++;
2483-
break;
2484-
case ',':
2485-
Result += "|";
2486-
break;
2487-
case 'g':
2488-
Result += "imr";
2489-
break;
2490-
case '[': {
2491-
assert(OutCons &&
2492-
"Must pass output names to constraints with a symbolic name");
2493-
unsigned Index;
2494-
bool result = Target.resolveSymbolicName(Constraint, *OutCons, Index);
2495-
assert(result && "Could not resolve symbolic name"); (void)result;
2496-
Result += llvm::utostr(Index);
2497-
break;
2498-
}
2499-
}
2500-
2501-
Constraint++;
2502-
}
2503-
2504-
return Result;
2505-
}
2506-
25072457
/// AddVariableConstraints - Look at AsmExpr and if it is a variable declared
25082458
/// as using a particular register add that as a constraint that will be used
25092459
/// in this asm stmt.
@@ -2882,8 +2832,8 @@ void CodeGenFunction::EmitAsmStmt(const AsmStmt &S) {
28822832

28832833
// Simplify the output constraint.
28842834
std::string OutputConstraint(S.getOutputConstraint(i));
2885-
OutputConstraint = SimplifyConstraint(OutputConstraint.c_str() + 1,
2886-
getTarget(), &OutputConstraintInfos);
2835+
OutputConstraint = getTarget().simplifyConstraint(
2836+
OutputConstraint.c_str() + 1, &OutputConstraintInfos);
28872837

28882838
const Expr *OutExpr = S.getOutputExpr(i);
28892839
OutExpr = OutExpr->IgnoreParenNoopCasts(getContext());
@@ -3045,8 +2995,8 @@ void CodeGenFunction::EmitAsmStmt(const AsmStmt &S) {
30452995

30462996
// Simplify the input constraint.
30472997
std::string InputConstraint(S.getInputConstraint(i));
3048-
InputConstraint = SimplifyConstraint(InputConstraint.c_str(), getTarget(),
3049-
&OutputConstraintInfos);
2998+
InputConstraint = getTarget().simplifyConstraint(InputConstraint.c_str(),
2999+
&OutputConstraintInfos);
30503000

30513001
InputConstraint = AddVariableConstraints(
30523002
InputConstraint, *InputExpr->IgnoreParenNoopCasts(getContext()),

0 commit comments

Comments
 (0)