OSDN Git Service

Various improvements related to legalization code.
authorMatt Wala <wala@chromium.org>
Tue, 15 Jul 2014 00:37:37 +0000 (17:37 -0700)
committerMatt Wala <wala@chromium.org>
Tue, 15 Jul 2014 00:37:37 +0000 (17:37 -0700)
1) In makeHelperCall(), function pointers that are created should have
type IceType_i32, not the functions' own return type.

2) In legalize(), change the name of WillHaveRegister to
MustHaveRegister. Add a comment to clarify the condition being computed.

3) In legalize(), add an assert to make sure that vector "constants"
don't get legalized (other than undef). There should be no constants of
vector type.

4) In copyToReg(), replace an unnecessary use of Src->getType().

BUG=none
R=stichnot@chromium.org

Review URL: https://codereview.chromium.org/385133006

src/IceTargetLoweringX8632.cpp
src/IceTargetLoweringX8632.h

index e459e2c..38b6fc6 100644 (file)
@@ -2756,7 +2756,7 @@ void TargetX8632::lowerUnreachable(const InstUnreachable * /*Inst*/) {
 Variable *TargetX8632::copyToReg(Operand *Src, int32_t RegNum) {
   Type Ty = Src->getType();
   Variable *Reg = makeReg(Ty, RegNum);
-  if (isVectorType(Src->getType())) {
+  if (isVectorType(Ty)) {
     _movp(Reg, Src);
   } else {
     _mov(Reg, Src);
@@ -2827,6 +2827,8 @@ Operand *TargetX8632::legalize(Operand *From, LegalMask Allowed,
         From = Ctx->getConstantZero(From->getType());
       }
     }
+    // There should be no constants of vector type (other than undef).
+    assert(!isVectorType(From->getType()));
     bool NeedsReg = false;
     if (!(Allowed & Legal_Imm))
       // Immediate specifically not allowed
@@ -2846,13 +2848,16 @@ Operand *TargetX8632::legalize(Operand *From, LegalMask Allowed,
     return From;
   }
   if (Variable *Var = llvm::dyn_cast<Variable>(From)) {
+    // Check if the variable is guaranteed a physical register.  This
+    // can happen either when the variable is pre-colored or when it is
+    // assigned infinite weight.
+    bool MustHaveRegister =
+        (Var->hasReg() || Var->getWeight() == RegWeight::Inf);
     // We need a new physical register for the operand if:
     //   Mem is not allowed and Var isn't guaranteed a physical
     //   register, or
     //   RegNum is required and Var->getRegNum() doesn't match.
-    bool WillHaveRegister =
-        (Var->hasReg() || Var->getWeight() == RegWeight::Inf);
-    if ((!(Allowed & Legal_Mem) && !WillHaveRegister) ||
+    if ((!(Allowed & Legal_Mem) && !MustHaveRegister) ||
         (RegNum != Variable::NoRegister && RegNum != Var->getRegNum())) {
       Variable *Reg = copyToReg(From, RegNum);
       if (RegNum == Variable::NoRegister) {
index 4953ffc..1408873 100644 (file)
@@ -136,8 +136,9 @@ protected:
   InstCall *makeHelperCall(const IceString &Name, Variable *Dest,
                            SizeT MaxSrcs) {
     bool SuppressMangling = true;
-    Type Ty = Dest ? Dest->getType() : IceType_void;
-    Constant *CallTarget = Ctx->getConstantSym(Ty, 0, Name, SuppressMangling);
+    const Type FunctionPointerType = IceType_i32;
+    Constant *CallTarget =
+        Ctx->getConstantSym(FunctionPointerType, 0, Name, SuppressMangling);
     InstCall *Call = InstCall::create(Func, MaxSrcs, Dest, CallTarget);
     return Call;
   }