Remove boolean values cannot cross their definition basic block restrict.
authorYang Rong <rong.r.yang@intel.com>
Thu, 14 Nov 2013 03:14:33 +0000 (11:14 +0800)
committerZhigang Gong <zhigang.gong@intel.com>
Thu, 14 Nov 2013 02:49:45 +0000 (10:49 +0800)
Add mov bool support.

Signed-off-by: Yang Rong <rong.r.yang@intel.com>
Reviewed-by: "Xing, Homer" <homer.xing@intel.com>
Reviewed-by: Zhigang Gong <zhigang.gong@linux.intel.com>
backend/src/backend/gen_insn_selection.cpp
backend/src/ir/instruction.cpp
backend/src/llvm/llvm_gen_backend.cpp
utests/compiler_bool_cross_basic_block.cpp

index f6f7961..5a6b9fd 100644 (file)
@@ -1458,6 +1458,7 @@ namespace gbe
       case TYPE_U8:  return GenRegister::immuw(imm.data.u8);
       case TYPE_S8:  return GenRegister::immw(imm.data.s8);
       case TYPE_DOUBLE: return GenRegister::immdf(imm.data.f64);
+      case TYPE_BOOL: return GenRegister::immuw(-imm.data.b);  //return 0xffff when true
       default: NOT_SUPPORTED; return GenRegister::immuw(0);
     }
   }
@@ -1502,6 +1503,8 @@ namespace gbe
         return ir::TYPE_U32;
       if (insnType == ir::TYPE_S16 || insnType == ir::TYPE_U16)
         return insnType;
+      if (insnType == ir::TYPE_BOOL)
+        return ir::TYPE_U16;
       return ir::TYPE_FLOAT;
     }
 
@@ -1522,7 +1525,25 @@ namespace gbe
           }
           break;
         case ir::OP_MOV:
-          if (dst.isdf()) {
+          if(insn.getType() == ir::TYPE_BOOL) {
+            GenRegister flagReg;
+            uint32_t predicate = sel.curr.predicate;
+            sel.push();
+              sel.curr.execWidth = 1;
+              sel.curr.predicate = GEN_PREDICATE_NONE;
+              sel.curr.noMask = 1;
+              if(predicate == GEN_PREDICATE_NONE)
+                sel.MOV(dst, src);
+              else {
+                if(sel.curr.physicalFlag)
+                  flagReg = GenRegister::flag(sel.curr.flag, sel.curr.subFlag);
+                else
+                  flagReg = sel.selReg(ir::Register(sel.curr.flagIndex), ir::TYPE_U16);
+
+                sel.AND(dst, flagReg, src);
+              }
+            sel.pop();
+          } else if (dst.isdf()) {
             ir::Register r = sel.reg(ir::RegisterFamily::FAMILY_QWORD);
             sel.MOV_DF(dst, src, sel.selReg(r));
           } else
index 61dcd49..da20d43 100644 (file)
@@ -784,6 +784,8 @@ namespace ir {
         default:
           CHECK_TYPE(this->type, allButBool);
           break;
+        case OP_MOV:
+          break;
         case OP_POW:
         case OP_COS:
         case OP_SIN:
index b2aabc4..83e6d8b 100644 (file)
@@ -1026,8 +1026,6 @@ namespace gbe
       Value *IV = PN->getIncomingValueForBlock(curr);
       if (!isa<UndefValue>(IV)) {
         Type *llvmType = PN->getType();
-        GBE_ASSERTM(llvmType != Type::getInt1Ty(llvmType->getContext()),
-          "TODO Boolean values cannot escape their definition basic block");
         const ir::Type type = getType(ctx, llvmType);
 
         // Emit the MOV required by the PHI function. We do it simple and do not
index 4dd5bc7..908edc0 100644 (file)
@@ -52,4 +52,4 @@ void compiler_bool_cross_basic_block(void){
 
 }
 
-MAKE_UTEST_FROM_FUNCTION_WITH_ISSUE(compiler_bool_cross_basic_block)
+MAKE_UTEST_FROM_FUNCTION(compiler_bool_cross_basic_block)