[PATCH] D35471: [Polly] [RFC] Calculate AST expression type

Philip Pfaffe via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 29 08:31:15 PDT 2017


philip.pfaffe added inline comments.


================
Comment at: lib/CodeGen/PPCGCodeGeneration.cpp:1029
 
+    ExprBuilder.setFixedSizeMode(true);
     Value *NumElements = ExprBuilder.create(Res);
----------------
bollu wrote:
> Can we create a wrapper that does this? Example,
> 
> ```lang=cpp
> template<typename FTy>
> auto scopeFixedSizeMode(FTy F, IslExprBuilder &ExprBuilder) -> decltype(FTy()) typename std::enable_if<!std::is_same<decltype(std::declval<FTy>()()), void>::value,
>                  decltype(std::declval<FTy>()())>::type
> scopedFixedSizeMode(FTy F) {
>     ExprBuilder.setBuildMode(true);
>     auto Ret = F();
>     ExprBuilder.setBuildMode(false);
>     return Ret;
> }
> 
> template <typename FTy>
> typename std::enable_if<std::is_same<decltype(std::declval<FTy>()()), void>::value, void>::type
> scopedFixedSizeMode(FTy F) {
>     ExprBuilder.setBuildMode(true);
>     F();
>     ExprBuilder.setBuildMode(false);
> }
> ```
> 
> The wrapper right now is crazy, but there has to be a way for this to be more "canonical".
Here's a way to express the same thing more nicely:

```lang=c++
template<typename T> T Foo(std::function<T()> F) {                              
  auto R = F();                                                                 
  return R;                                                                     
}                                                                               
                                                                                
void Foo(std::function<void()> F) {                                             
  F();                                                                          
}
```


https://reviews.llvm.org/D35471





More information about the llvm-commits mailing list