[PATCH] Allow the IslExprBuilder to compare pointers

Johannes Doerfert doerfert at cs.uni-saarland.de
Wed Aug 13 10:07:15 PDT 2014


On 08/13, Andreas Simbuerger wrote:
> From: Johannes Doerfert <doerfert at cs.uni-saarland.de>
> 
> What do you think about this one here? A 'bit' overkill to use a map&vector
> here, but it should be safe against reordering in the enum and unsupported
> enum elements without using magic numbers.
Check the first version of the patch (a switch and conditionals) and
suggest an implementation.

I don't really care how we implement this, just that we do it.

> 
> ---
>  lib/CodeGen/IslExprBuilder.cpp | 48 +++++++++++++++++++++---------------------
>  1 file changed, 24 insertions(+), 24 deletions(-)
> 
> diff --git a/lib/CodeGen/IslExprBuilder.cpp b/lib/CodeGen/IslExprBuilder.cpp
> index e78b4c0..4234f4e 100644
> --- a/lib/CodeGen/IslExprBuilder.cpp
> +++ b/lib/CodeGen/IslExprBuilder.cpp
> @@ -255,6 +255,15 @@ Value *IslExprBuilder::createOpSelect(__isl_take isl_ast_expr *Expr) {
>    return Builder.CreateSelect(Cond, LHS, RHS);
>  }
>  
> +
> +static std::map<isl_ast_op_type, std::vector<CmpInst::Predicate> > Predicates {
> +  { isl_ast_op_eq, { CmpInst::ICMP_EQ , CmpInst::ICMP_EQ  } },
> +  { isl_ast_op_le, { CmpInst::ICMP_SLE, CmpInst::ICMP_ULE } },
> +  { isl_ast_op_lt, { CmpInst::ICMP_SLT, CmpInst::ICMP_ULT } },
> +  { isl_ast_op_ge, { CmpInst::ICMP_SGE, CmpInst::ICMP_UGE } },
> +  { isl_ast_op_gt, { CmpInst::ICMP_SGT, CmpInst::ICMP_UGT } }
> +};
> +
>  Value *IslExprBuilder::createOpICmp(__isl_take isl_ast_expr *Expr) {
>    assert(isl_ast_expr_get_type(Expr) == isl_ast_expr_op &&
>           "Expected an isl_ast_expr_op expression");
> @@ -264,35 +273,26 @@ Value *IslExprBuilder::createOpICmp(__isl_take isl_ast_expr *Expr) {
>    LHS = create(isl_ast_expr_get_op_arg(Expr, 0));
>    RHS = create(isl_ast_expr_get_op_arg(Expr, 1));
>  
> -  Type *MaxType = LHS->getType();
> -  MaxType = getWidestType(MaxType, RHS->getType());
> +  bool IsPtrType = LHS->getType()->isPointerTy();
> +  assert((!IsPtrType || RHS->getType()->isPointerTy()) &&
> +         "Both ICmp operators should be pointer types or none of them");
>  
> -  if (MaxType != RHS->getType())
> -    RHS = Builder.CreateSExt(RHS, MaxType);
> +  if (!IsPtrType) {
> +    Type *MaxType = LHS->getType();
> +    MaxType = getWidestType(MaxType, RHS->getType());
>  
> -  if (MaxType != LHS->getType())
> -    LHS = Builder.CreateSExt(LHS, MaxType);
> +    if (MaxType != RHS->getType())
> +      RHS = Builder.CreateSExt(RHS, MaxType);
>  
> -  switch (isl_ast_expr_get_op_type(Expr)) {
> -  default:
> -    llvm_unreachable("Unsupported ICmp isl ast expression");
> -  case isl_ast_op_eq:
> -    Res = Builder.CreateICmpEQ(LHS, RHS);
> -    break;
> -  case isl_ast_op_le:
> -    Res = Builder.CreateICmpSLE(LHS, RHS);
> -    break;
> -  case isl_ast_op_lt:
> -    Res = Builder.CreateICmpSLT(LHS, RHS);
> -    break;
> -  case isl_ast_op_ge:
> -    Res = Builder.CreateICmpSGE(LHS, RHS);
> -    break;
> -  case isl_ast_op_gt:
> -    Res = Builder.CreateICmpSGT(LHS, RHS);
> -    break;
> +    if (MaxType != LHS->getType())
> +      LHS = Builder.CreateSExt(LHS, MaxType);
>    }
>  
> +  isl_ast_op_type OpType = isl_ast_expr_get_op_type(Expr);
> +  assert(Predicates.count(OpType) && "Unsupported ICmp isl ast expression");
> +
> +  Res = Builder.CreateICmp(Predicates[OpType][IsPtrType], LHS, RHS);
> +
>    isl_ast_expr_free(Expr);
>    return Res;
>  }
> -- 
> 2.0.4
> 

-- 

Johannes Doerfert
Researcher / PhD Student

Compiler Design Lab (Prof. Hack)
Saarland University, Computer Science
Building E1.3, Room 4.26

Tel. +49 (0)681 302-57521 : doerfert at cs.uni-saarland.de
Fax. +49 (0)681 302-3065  : http://www.cdl.uni-saarland.de/people/doerfert
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 213 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140813/1d92688f/attachment.sig>


More information about the llvm-commits mailing list