<p dir="ltr">I did. I'm just suggesting a version that is more stable against possible changes to the isl interface.</p>
<p dir="ltr">If you are OK with it, just use the version above.</p>
<p dir="ltr">Cheers,<br>
Andreas</p>
<div class="gmail_quot<blockquote class=" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">From: Johannes Doerfert <<a href="mailto:doerfert@cs.uni-saarland.de">doerfert@cs.uni-saarland.de</a>><br>
<br>
What do you think about this one here? A 'bit' overkill to use a map&vector<br>
here, but it should be safe against reordering in the enum and unsupported<br>
enum elements without using magic numbers.<br>
<br>
Cheers,<br>
Andreas<br>
<br>
---<br>
lib/CodeGen/IslExprBuilder.cpp | 48 +++++++++++++++++++++---------------------<br>
1 file changed, 24 insertions(+), 24 deletions(-)<br>
<br>
diff --git a/lib/CodeGen/IslExprBuilder.cpp b/lib/CodeGen/IslExprBuilder.cpp<br>
index e78b4c0..4234f4e 100644<br>
--- a/lib/CodeGen/IslExprBuilder.cpp<br>
+++ b/lib/CodeGen/IslExprBuilder.cpp<br>
@@ -255,6 +255,15 @@ Value *IslExprBuilder::createOpSelect(__isl_take isl_ast_expr *Expr) {<br>
return Builder.CreateSelect(Cond, LHS, RHS);<br>
}<br>
<br>
+<br>
+static std::map<isl_ast_op_type, std::vector<CmpInst::Predicate> > Predicates {<br>
+ { isl_ast_op_eq, { CmpInst::ICMP_EQ , CmpInst::ICMP_EQ } },<br>
+ { isl_ast_op_le, { CmpInst::ICMP_SLE, CmpInst::ICMP_ULE } },<br>
+ { isl_ast_op_lt, { CmpInst::ICMP_SLT, CmpInst::ICMP_ULT } },<br>
+ { isl_ast_op_ge, { CmpInst::ICMP_SGE, CmpInst::ICMP_UGE } },<br>
+ { isl_ast_op_gt, { CmpInst::ICMP_SGT, CmpInst::ICMP_UGT } }<br>
+};<br>
+<br>
Value *IslExprBuilder::createOpICmp(__isl_take isl_ast_expr *Expr) {<br>
assert(isl_ast_expr_get_type(Expr) == isl_ast_expr_op &&<br>
"Expected an isl_ast_expr_op expression");<br>
@@ -264,35 +273,26 @@ Value *IslExprBuilder::createOpICmp(__isl_take isl_ast_expr *Expr) {<br>
LHS = create(isl_ast_expr_get_op_arg(Expr, 0));<br>
RHS = create(isl_ast_expr_get_op_arg(Expr, 1));<br>
<br>
- Type *MaxType = LHS->getType();<br>
- MaxType = getWidestType(MaxType, RHS->getType());<br>
+ bool IsPtrType = LHS->getType()->isPointerTy();<br>
+ assert((!IsPtrType || RHS->getType()->isPointerTy()) &&<br>
+ "Both ICmp operators should be pointer types or none of them");<br>
<br>
- if (MaxType != RHS->getType())<br>
- RHS = Builder.CreateSExt(RHS, MaxType);<br>
+ if (!IsPtrType) {<br>
+ Type *MaxType = LHS->getType();<br>
+ MaxType = getWidestType(MaxType, RHS->getType());<br>
<br>
- if (MaxType != LHS->getType())<br>
- LHS = Builder.CreateSExt(LHS, MaxType);<br>
+ if (MaxType != RHS->getType())<br>
+ RHS = Builder.CreateSExt(RHS, MaxType);<br>
<br>
- switch (isl_ast_expr_get_op_type(Expr)) {<br>
- default:<br>
- llvm_unreachable("Unsupported ICmp isl ast expression");<br>
- case isl_ast_op_eq:<br>
- Res = Builder.CreateICmpEQ(LHS, RHS);<br>
- break;<br>
- case isl_ast_op_le:<br>
- Res = Builder.CreateICmpSLE(LHS, RHS);<br>
- break;<br>
- case isl_ast_op_lt:<br>
- Res = Builder.CreateICmpSLT(LHS, RHS);<br>
- break;<br>
- case isl_ast_op_ge:<br>
- Res = Builder.CreateICmpSGE(LHS, RHS);<br>
- break;<br>
- case isl_ast_op_gt:<br>
- Res = Builder.CreateICmpSGT(LHS, RHS);<br>
- break;<br>
+ if (MaxType != LHS->getType())<br>
+ LHS = Builder.CreateSExt(LHS, MaxType);<br>
}<br>
<br>
+ isl_ast_op_type OpType = isl_ast_expr_get_op_type(Expr);<br>
+ assert(Predicates.count(OpType) && "Unsupported ICmp isl ast expression");<br>
+<br>
+ Res = Builder.CreateICmp(Predicates[OpType][IsPtrType], LHS, RHS);<br>
+<br>
isl_ast_expr_free(Expr);<br>
return Res;<br>
}<br>
--<br>
2.0.4<br>
<br>
</div>