aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-04-26 17:57:12 +0000
committerChris Lattner <sabre@nondot.org>2009-04-26 17:57:12 +0000
commit2819fa85651526d59ade4fdc9da2cadd7b132973 (patch)
tree0ffafc21c13b3f5fe30c7b282a89522337775e13
parent432c86969eced2ce658b3f3f2aa7407c8864f21b (diff)
pull operands names "[foo]" into ConstraintInfo.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@70136 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/Basic/TargetInfo.h22
-rw-r--r--lib/Basic/TargetInfo.cpp20
-rw-r--r--lib/CodeGen/CGStmt.cpp25
-rw-r--r--lib/Sema/SemaStmt.cpp12
4 files changed, 35 insertions, 44 deletions
diff --git a/include/clang/Basic/TargetInfo.h b/include/clang/Basic/TargetInfo.h
index e01e9da066..acd64f3dbc 100644
--- a/include/clang/Basic/TargetInfo.h
+++ b/include/clang/Basic/TargetInfo.h
@@ -209,14 +209,16 @@ public:
unsigned Flags;
int TiedOperand;
- std::string ConstraintStr;
+ std::string ConstraintStr; // constraint: "=rm"
+ std::string Name; // Operand name: [foo] with no []'s.
public:
- ConstraintInfo(const char *str, unsigned strlen)
- : Flags(0), TiedOperand(-1), ConstraintStr(str, str+strlen) {}
- explicit ConstraintInfo(const std::string &Str)
- : Flags(0), TiedOperand(-1), ConstraintStr(Str) {}
+ ConstraintInfo(const char *str, unsigned strlen, const std::string &name)
+ : Flags(0), TiedOperand(-1), ConstraintStr(str, str+strlen), Name(name) {}
+ explicit ConstraintInfo(const std::string &Str, const std::string &name)
+ : Flags(0), TiedOperand(-1), ConstraintStr(Str), Name(name) {}
const std::string &getConstraintStr() const { return ConstraintStr; }
+ const std::string &getName() const { return Name; }
bool isReadWrite() const { return (Flags & CI_ReadWrite) != 0; }
bool allowsRegister() const { return (Flags & CI_AllowsRegister) != 0; }
bool allowsMemory() const { return (Flags & CI_AllowsMemory) != 0; }
@@ -236,14 +238,12 @@ public:
// a constraint is valid and provides information about it.
// FIXME: These should return a real error instead of just true/false.
bool validateOutputConstraint(ConstraintInfo &Info) const;
- bool validateInputConstraint(const std::string *OutputNamesBegin,
- const std::string *OutputNamesEnd,
- ConstraintInfo* OutputConstraints,
+ bool validateInputConstraint(ConstraintInfo *OutputConstraints,
+ unsigned NumOutputs,
ConstraintInfo &info) const;
bool resolveSymbolicName(const char *&Name,
- const std::string *OutputNamesBegin,
- const std::string *OutputNamesEnd,
- unsigned &Index) const;
+ ConstraintInfo *OutputConstraints,
+ unsigned NumOutputs, unsigned &Index) const;
virtual std::string convertConstraint(const char Constraint) const {
return std::string(1, Constraint);
diff --git a/lib/Basic/TargetInfo.cpp b/lib/Basic/TargetInfo.cpp
index b8aa535329..a7241f2864 100644
--- a/lib/Basic/TargetInfo.cpp
+++ b/lib/Basic/TargetInfo.cpp
@@ -204,8 +204,8 @@ bool TargetInfo::validateOutputConstraint(ConstraintInfo &Info) const {
}
bool TargetInfo::resolveSymbolicName(const char *&Name,
- const std::string *OutputNamesBegin,
- const std::string *OutputNamesEnd,
+ ConstraintInfo *OutputConstraints,
+ unsigned NumOutputs,
unsigned &Index) const {
assert(*Name == '[' && "Symbolic name did not start with '['");
Name++;
@@ -220,20 +220,15 @@ bool TargetInfo::resolveSymbolicName(const char *&Name,
std::string SymbolicName(Start, Name - Start);
- Index = 0;
- for (const std::string *it = OutputNamesBegin;
- it != OutputNamesEnd;
- ++it, Index++) {
- if (SymbolicName == *it)
+ for (Index = 0; Index != NumOutputs; ++Index)
+ if (SymbolicName == OutputConstraints[Index].getName())
return true;
- }
return false;
}
-bool TargetInfo::validateInputConstraint(const std::string *OutputNamesBegin,
- const std::string *OutputNamesEnd,
- ConstraintInfo *OutputConstraints,
+bool TargetInfo::validateInputConstraint(ConstraintInfo *OutputConstraints,
+ unsigned NumOutputs,
ConstraintInfo &Info) const {
const char *Name = Info.ConstraintStr.c_str();
@@ -242,7 +237,6 @@ bool TargetInfo::validateInputConstraint(const std::string *OutputNamesBegin,
default:
// Check if we have a matching constraint
if (*Name >= '0' && *Name <= '9') {
- unsigned NumOutputs = OutputNamesEnd - OutputNamesBegin;
unsigned i = *Name - '0';
// Check if matching constraint is out of bounds.
@@ -262,7 +256,7 @@ bool TargetInfo::validateInputConstraint(const std::string *OutputNamesBegin,
break;
case '[': {
unsigned Index = 0;
- if (!resolveSymbolicName(Name, OutputNamesBegin, OutputNamesEnd, Index))
+ if (!resolveSymbolicName(Name, OutputConstraints, NumOutputs, Index))
return false;
break;
diff --git a/lib/CodeGen/CGStmt.cpp b/lib/CodeGen/CGStmt.cpp
index 4d36207b54..0837dd0489 100644
--- a/lib/CodeGen/CGStmt.cpp
+++ b/lib/CodeGen/CGStmt.cpp
@@ -688,10 +688,9 @@ void CodeGenFunction::EmitSwitchStmt(const SwitchStmt &S) {
CaseRangeBlock = SavedCRBlock;
}
-static std::string SimplifyConstraint(const char* Constraint,
- TargetInfo &Target,
- const std::string *OutputNamesBegin = 0,
- const std::string *OutputNamesEnd = 0) {
+static std::string
+SimplifyConstraint(const char *Constraint, TargetInfo &Target,
+ llvm::SmallVectorImpl<TargetInfo::ConstraintInfo> *OutCons=0) {
std::string Result;
while (*Constraint) {
@@ -708,12 +707,12 @@ static std::string SimplifyConstraint(const char* Constraint,
Result += "imr";
break;
case '[': {
- assert(OutputNamesBegin && OutputNamesEnd &&
+ assert(OutCons &&
"Must pass output names to constraints with a symbolic name");
unsigned Index;
bool result = Target.resolveSymbolicName(Constraint,
- OutputNamesBegin,
- OutputNamesEnd, Index);
+ &(*OutCons)[0],
+ OutCons->size(), Index);
assert(result && "Could not resolve symbolic name"); result=result;
Result += llvm::utostr(Index);
break;
@@ -798,7 +797,7 @@ void CodeGenFunction::EmitAsmStmt(const AsmStmt &S) {
for (unsigned i = 0, e = S.getNumOutputs(); i != e; i++) {
std::string OutputConstraint(S.getOutputConstraint(i));
- TargetInfo::ConstraintInfo Info(OutputConstraint);
+ TargetInfo::ConstraintInfo Info(OutputConstraint, S.getOutputName(i));
bool result = Target.validateOutputConstraint(Info);
assert(result && "Failed to parse output constraint"); result=result;
@@ -852,10 +851,9 @@ void CodeGenFunction::EmitAsmStmt(const AsmStmt &S) {
std::string InputConstraint(S.getInputConstraint(i));
- TargetInfo::ConstraintInfo Info(InputConstraint);
- bool result = Target.validateInputConstraint(S.begin_output_names(),
- S.end_output_names(),
- &OutputConstraintInfos[0],
+ TargetInfo::ConstraintInfo Info(InputConstraint, S.getInputName(i));
+ bool result = Target.validateInputConstraint(&OutputConstraintInfos[0],
+ S.getNumOutputs(),
Info); result=result;
assert(result && "Failed to parse input constraint");
@@ -864,8 +862,7 @@ void CodeGenFunction::EmitAsmStmt(const AsmStmt &S) {
// Simplify the input constraint.
InputConstraint = SimplifyConstraint(InputConstraint.c_str(), Target,
- S.begin_output_names(),
- S.end_output_names());
+ &OutputConstraintInfos);
llvm::Value *Arg = EmitAsmInput(S, Info, InputExpr, Constraints);
diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp
index ed5692c311..13d24c36a0 100644
--- a/lib/Sema/SemaStmt.cpp
+++ b/lib/Sema/SemaStmt.cpp
@@ -923,7 +923,8 @@ Sema::OwningStmtResult Sema::ActOnAsmStmt(SourceLocation AsmLoc,
<< Literal->getSourceRange());
TargetInfo::ConstraintInfo Info(Literal->getStrData(),
- Literal->getByteLength());
+ Literal->getByteLength(),
+ Names[i]);
if (!Context.Target.validateOutputConstraint(Info))
return StmtError(Diag(Literal->getLocStart(),
diag::err_asm_invalid_output_constraint)
@@ -948,11 +949,10 @@ Sema::OwningStmtResult Sema::ActOnAsmStmt(SourceLocation AsmLoc,
<< Literal->getSourceRange());
TargetInfo::ConstraintInfo Info(Literal->getStrData(),
- Literal->getByteLength());
- if (!Context.Target.validateInputConstraint(&Names[0],
- &Names[0] + NumOutputs,
- &OutputConstraintInfos[0],
- Info)) {
+ Literal->getByteLength(),
+ Names[i]);
+ if (!Context.Target.validateInputConstraint(&OutputConstraintInfos[0],
+ NumOutputs, Info)) {
return StmtError(Diag(Literal->getLocStart(),
diag::err_asm_invalid_input_constraint)
<< Info.getConstraintStr());