[llvm-commits] [llvm] r54640 - in /llvm/trunk/include/llvm/Support: ConstantFolder.h IRBuilder.h TargetFolder.h

Chris Lattner clattner at apple.com
Mon Aug 11 14:07:59 PDT 2008


On Aug 11, 2008, at 8:29 AM, Duncan Sands wrote:
> URL: http://llvm.org/viewvc/llvm-project?rev=54640&view=rev
> Log:
> Make it possible to use different constant
> folding policies with IRBuilder.  The default,
> provided by ConstantFolder, is to do minimal
> folding like now: what ConstantExpr provides.
> An alternative is to use TargetFolder, which
> uses target information to fold constants more.

Very nice Duncan, this is something we've needed for quite awhile.   
This also gives us the ability to have an IRBuilder that does no  
constant folding.  With a folder that just returns the instructions.

> +++ llvm/trunk/include/llvm/Support/ConstantFolder.h Mon Aug 11  
> 10:29:30 2008
> @@ -0,0 +1,175 @@
> +//===-- llvm/Support/ConstantFolder.h - Constant folding helper -*-  
> C++ -*-===//
> +//
> +//                     The LLVM Compiler Infrastructure
> +//
> +// This file is distributed under the University of Illinois Open  
> Source
> +// License. See LICENSE.TXT for details.
> +//
> +// 
> = 
> = 
> = 
> ----------------------------------------------------------------------= 
> ==//
> +//
> +// This file defines the ConstantFolder class, which provides a set  
> of methods
> +// for creating constants, with minimal folding.


Because of the name of this file, I expect a lot of people to go here  
to look for the LLVM IR constant folding interfaces.  Please document  
that this file is designed for use with IRBuilder and point people to  
the ConstantExpr::get* methods and libanalysis for simple constant  
folding uses.

> +//====-- llvm/Support/TargetFolder.h - Constant folding helper -*- C 
> ++ -*-====//
> +//
> +//                     The LLVM Compiler Infrastructure
> +//
> +// This file is distributed under the University of Illinois Open  
> Source
> +// License. See LICENSE.TXT for details.
> +//
> +// 
> = 
> = 
> = 
> ----------------------------------------------------------------------= 
> ==//
> +//
> +// This file defines the TargetFolder class, which provides a set  
> of methods
> +// for creating constants, with target dependent folding.

Likewise, please say that this is for use with IRBuilder.

> +  // 
> = 
> = 
> =-------------------------------------------------------------------- 
> ===//
> +  // Compare Instructions
> +  // 
> = 
> = 
> =-------------------------------------------------------------------- 
> ===//
> +
> +  Constant *CreateCompare(CmpInst::Predicate P, Constant *LHS,  
> Constant *RHS) const {

80 columns?

> +  Constant *CreateInsertElement(Constant *Vec, Constant *NewElt,  
> Constant *Idx)const {
> +    return Fold(ConstantExpr::getInsertElement(Vec, NewElt, Idx));
> +  }
> +
> +  Constant *CreateShuffleVector(Constant *V1, Constant *V2,  
> Constant *Mask) const {
> +    return Fold(ConstantExpr::getShuffleVector(V1, V2, Mask));
> +  }

80 cols.

Overall, very nice!

-Chris




More information about the llvm-commits mailing list