[cfe-commits] r70114 - in /cfe/trunk: include/clang/Basic/TargetInfo.h lib/Basic/TargetInfo.cpp lib/Basic/Targets.cpp lib/CodeGen/CGStmt.cpp lib/Sema/SemaStmt.cpp

Chris Lattner sabre at nondot.org
Sun Apr 26 00:16:31 PDT 2009


Author: lattner
Date: Sun Apr 26 02:16:29 2009
New Revision: 70114

URL: http://llvm.org/viewvc/llvm-project?rev=70114&view=rev
Log:
change TargetInfo::ConstraintInfo to be a struct that contains
the enum along with some other data.

Modified:
    cfe/trunk/include/clang/Basic/TargetInfo.h
    cfe/trunk/lib/Basic/TargetInfo.cpp
    cfe/trunk/lib/Basic/Targets.cpp
    cfe/trunk/lib/CodeGen/CGStmt.cpp
    cfe/trunk/lib/Sema/SemaStmt.cpp

Modified: cfe/trunk/include/clang/Basic/TargetInfo.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TargetInfo.h?rev=70114&r1=70113&r2=70114&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/TargetInfo.h (original)
+++ cfe/trunk/include/clang/Basic/TargetInfo.h Sun Apr 26 02:16:29 2009
@@ -198,11 +198,31 @@
   // For example, on x86 it will return "ax" when "eax" is passed in.
   const char *getNormalizedGCCRegisterName(const char *Name) const;
   
-  enum ConstraintInfo {
-    CI_None = 0x00,
-    CI_AllowsMemory = 0x01,
-    CI_AllowsRegister = 0x02,
-    CI_ReadWrite = 0x04
+  struct ConstraintInfo {
+    enum {
+      CI_None = 0x00,
+      CI_AllowsMemory = 0x01,
+      CI_AllowsRegister = 0x02,
+      CI_ReadWrite = 0x04   // "+r" output constraint (read and write).
+    };
+    unsigned Flags;
+    int TiedOperand;
+  public:
+    ConstraintInfo() : Flags(0), TiedOperand(-1) {}
+    
+    bool isReadWrite() const { return (Flags & CI_ReadWrite) != 0; }
+    bool allowsRegister() const { return (Flags & CI_AllowsRegister) != 0; }
+    bool allowsMemory() const { return (Flags & CI_AllowsMemory) != 0; }
+    bool hasTiedOperand() const { return TiedOperand != -1; }
+    unsigned getTiedOperand() const {
+      assert(hasTiedOperand() && "Has no tied operand!");
+      return (unsigned)TiedOperand;
+    }
+    
+    void setIsReadWrite() { Flags |= CI_ReadWrite; }
+    void setAllowsMemory() { Flags |= CI_AllowsMemory; }
+    void setAllowsRegister() { Flags |= CI_AllowsRegister; }
+    void setTiedOperand(unsigned N) { TiedOperand = N; }
   };
 
   // validateOutputConstraint, validateInputConstraint - Checks that

Modified: cfe/trunk/lib/Basic/TargetInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/TargetInfo.cpp?rev=70114&r1=70113&r2=70114&view=diff

==============================================================================
--- cfe/trunk/lib/Basic/TargetInfo.cpp (original)
+++ cfe/trunk/lib/Basic/TargetInfo.cpp Sun Apr 26 02:16:29 2009
@@ -164,24 +164,19 @@
 }
 
 bool TargetInfo::validateOutputConstraint(const char *Name, 
-                                          ConstraintInfo &info) const
-{
-  info = CI_None;
-
+                                          ConstraintInfo &Info) const {
   // An output constraint must start with '=' or '+'
   if (*Name != '=' && *Name != '+')
     return false;
 
   if (*Name == '+')
-    info = CI_ReadWrite;
-  else
-    info = CI_None;
+    Info.setIsReadWrite();
 
   Name++;
   while (*Name) {
     switch (*Name) {
     default:
-      if (!validateAsmConstraint(Name, info)) {
+      if (!validateAsmConstraint(Name, Info)) {
         // FIXME: We temporarily return false
         // so we can add more constraints as we hit it.
         // Eventually, an unknown constraint should just be treated as 'g'.
@@ -190,14 +185,15 @@
     case '&': // early clobber.
       break;
     case 'r': // general register.
-      info = (ConstraintInfo)(info|CI_AllowsRegister);
+      Info.setAllowsRegister();
       break;
     case 'm': // memory operand.
-      info = (ConstraintInfo)(info|CI_AllowsMemory);
+      Info.setAllowsMemory();
       break;
     case 'g': // general register, memory operand or immediate integer.
     case 'X': // any operand.
-      info = (ConstraintInfo)(info|CI_AllowsMemory|CI_AllowsRegister);
+      Info.setAllowsRegister();
+      Info.setAllowsMemory();
       break;
     }
     
@@ -210,10 +206,8 @@
 bool TargetInfo::resolveSymbolicName(const char *&Name,
                                      const std::string *OutputNamesBegin,
                                      const std::string *OutputNamesEnd,
-                                     unsigned &Index) const
-{
+                                     unsigned &Index) const {
   assert(*Name == '[' && "Symbolic name did not start with '['");
-
   Name++;
   const char *Start = Name;
   while (*Name && *Name != ']')
@@ -240,10 +234,8 @@
 bool TargetInfo::validateInputConstraint(const char *Name,
                                          const std::string *OutputNamesBegin,
                                          const std::string *OutputNamesEnd,
-                                         ConstraintInfo* OutputConstraints,
-                                         ConstraintInfo &info) const {
-  info = CI_None;
-
+                                         ConstraintInfo *OutputConstraints,
+                                         ConstraintInfo &Info) const {
   while (*Name) {
     switch (*Name) {
     default:
@@ -258,8 +250,9 @@
         
         // The constraint should have the same info as the respective 
         // output constraint.
-        info = (ConstraintInfo)(info|OutputConstraints[i]);
-      } else if (!validateAsmConstraint(Name, info)) {
+        Info = OutputConstraints[i];
+        Info.setTiedOperand(i);
+      } else if (!validateAsmConstraint(Name, Info)) {
         // FIXME: This error return is in place temporarily so we can
         // add more constraints as we hit it.  Eventually, an unknown
         // constraint should just be treated as 'g'.
@@ -281,14 +274,15 @@
     case 'n': // immediate integer with a known value.
       break;
     case 'r': // general register.
-      info = (ConstraintInfo)(info|CI_AllowsRegister);
+      Info.setAllowsRegister();
       break;
     case 'm': // memory operand.
-      info = (ConstraintInfo)(info|CI_AllowsMemory);
+      Info.setAllowsMemory();
       break;
     case 'g': // general register, memory operand or immediate integer.
     case 'X': // any operand.
-      info = (ConstraintInfo)(info|CI_AllowsMemory|CI_AllowsRegister);
+      Info.setAllowsRegister();
+      Info.setAllowsMemory();
       break;
     }
     

Modified: cfe/trunk/lib/Basic/Targets.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=70114&r1=70113&r2=70114&view=diff

==============================================================================
--- cfe/trunk/lib/Basic/Targets.cpp (original)
+++ cfe/trunk/lib/Basic/Targets.cpp Sun Apr 26 02:16:29 2009
@@ -280,14 +280,14 @@
   virtual void getGCCRegAliases(const GCCRegAlias *&Aliases, 
                                 unsigned &NumAliases) const;
   virtual bool validateAsmConstraint(const char *&Name,
-                                     TargetInfo::ConstraintInfo &info) const {
+                                     TargetInfo::ConstraintInfo &Info) const {
     switch (*Name) {
     default: return false;
     case 'O': // Zero
       return true;
     case 'b': // Base register
     case 'f': // Floating point register
-      info = (TargetInfo::ConstraintInfo)(info|TargetInfo::CI_AllowsRegister);
+      Info.setAllowsRegister();
       return true;
     }
   }
@@ -638,7 +638,7 @@
   
 bool
 X86TargetInfo::validateAsmConstraint(const char *&Name,
-                                     TargetInfo::ConstraintInfo &info) const {
+                                     TargetInfo::ConstraintInfo &Info) const {
   switch (*Name) {
   default: return false;
   case 'a': // eax.
@@ -660,7 +660,7 @@
             // x86_64 instructions.
   case 'N': // unsigned 8-bit integer constant for use with in and out
             // instructions.
-    info = (TargetInfo::ConstraintInfo)(info|TargetInfo::CI_AllowsRegister);
+    Info.setAllowsRegister();
     return true;
   }
 }
@@ -997,7 +997,7 @@
     NumAliases = 0;
   }
   virtual bool validateAsmConstraint(const char *&Name,
-                                     TargetInfo::ConstraintInfo &info) const {
+                                     TargetInfo::ConstraintInfo &Info) const {
     // FIXME: Check if this is complete
     switch (*Name) {
     default:
@@ -1005,7 +1005,7 @@
     case 'h': // r8-r15
     case 'w': // VFP Floating point register single precision
     case 'P': // VFP Floating point register double precision
-      info = (TargetInfo::ConstraintInfo)(info|TargetInfo::CI_AllowsRegister);
+      Info.setAllowsRegister();
       return true;
     }
     return false;

Modified: cfe/trunk/lib/CodeGen/CGStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGStmt.cpp?rev=70114&r1=70113&r2=70114&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/CGStmt.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGStmt.cpp Sun Apr 26 02:16:29 2009
@@ -731,8 +731,7 @@
                                            const Expr *InputExpr,
                                            std::string &ConstraintStr) {
   llvm::Value *Arg;
-  if ((Info & TargetInfo::CI_AllowsRegister) ||
-      !(Info & TargetInfo::CI_AllowsMemory)) { 
+  if (Info.allowsRegister() || !Info.allowsMemory()) { 
     const llvm::Type *Ty = ConvertType(InputExpr->getType());
     
     if (Ty->isSingleValueType()) {
@@ -818,8 +817,7 @@
     
     // If the first output operand is not a memory dest, we'll
     // make it the return value.
-    if (i == 0 && !(Info & TargetInfo::CI_AllowsMemory) &&
-        DestValueType->isSingleValueType()) {
+    if (i == 0 && !Info.allowsMemory() && DestValueType->isSingleValueType()) {
       ResultAddr = Dest.getAddress();
       ResultType = DestValueType;
       Constraints += "=" + OutputConstraint;
@@ -832,13 +830,13 @@
       Constraints += OutputConstraint;
     }
     
-    if (Info & TargetInfo::CI_ReadWrite) {
+    if (Info.isReadWrite()) {
       InOutConstraints += ',';
 
       const Expr *InputExpr = S.getOutputExpr(i);
       llvm::Value *Arg = EmitAsmInput(S, Info, InputExpr, InOutConstraints);
       
-      if (Info & TargetInfo::CI_AllowsRegister)
+      if (Info.allowsRegister())
         InOutConstraints += llvm::utostr(i);
       else
         InOutConstraints += OutputConstraint;

Modified: cfe/trunk/lib/Sema/SemaStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=70114&r1=70113&r2=70114&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Sun Apr 26 02:16:29 2009
@@ -925,8 +925,8 @@
     std::string OutputConstraint(Literal->getStrData(), 
                                  Literal->getByteLength());
 
-    TargetInfo::ConstraintInfo info;
-    if (!Context.Target.validateOutputConstraint(OutputConstraint.c_str(),info))
+    TargetInfo::ConstraintInfo Info;
+    if (!Context.Target.validateOutputConstraint(OutputConstraint.c_str(),Info))
       return StmtError(Diag(Literal->getLocStart(),
                   diag::err_asm_invalid_output_constraint) << OutputConstraint);
 
@@ -938,7 +938,7 @@
         << OutputExpr->getSubExpr()->getSourceRange());
     }
     
-    OutputConstraintInfos.push_back(info);
+    OutputConstraintInfos.push_back(Info);
   }
 
   for (unsigned i = NumOutputs, e = NumOutputs + NumInputs; i != e; i++) {
@@ -950,12 +950,12 @@
     std::string InputConstraint(Literal->getStrData(),
                                 Literal->getByteLength());
 
-    TargetInfo::ConstraintInfo info;
+    TargetInfo::ConstraintInfo Info;
     if (!Context.Target.validateInputConstraint(InputConstraint.c_str(),
                                                 &Names[0],
                                                 &Names[0] + NumOutputs, 
                                                 &OutputConstraintInfos[0],
-                                                info)) {
+                                                Info)) {
       return StmtError(Diag(Literal->getLocStart(),
                   diag::err_asm_invalid_input_constraint) << InputConstraint);
     }
@@ -963,15 +963,14 @@
     ParenExpr *InputExpr = cast<ParenExpr>(Exprs[i]);
 
     // Only allow void types for memory constraints.
-    if ((info & TargetInfo::CI_AllowsMemory) 
-        && !(info & TargetInfo::CI_AllowsRegister)) {
+    if (Info.allowsMemory() && !Info.allowsRegister()) {
       if (CheckAsmLValue(InputExpr, *this))
         return StmtError(Diag(InputExpr->getSubExpr()->getLocStart(),
                               diag::err_asm_invalid_lvalue_in_input)
-          << InputConstraint << InputExpr->getSubExpr()->getSourceRange());
+             << InputConstraint << InputExpr->getSubExpr()->getSourceRange());
     }
 
-    if (info & TargetInfo::CI_AllowsRegister) {
+    if (Info.allowsRegister()) {
       if (InputExpr->getType()->isVoidType()) {
         return StmtError(Diag(InputExpr->getSubExpr()->getLocStart(),
                               diag::err_asm_invalid_type_in_input)





More information about the cfe-commits mailing list