LLVM API Documentation

ConstantFolder.h

Go to the documentation of this file.
00001 //===-- llvm/Support/ConstantFolder.h - Constant folding helper -*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file defines the ConstantFolder class, a helper for IRBuilder.
00011 // It provides IRBuilder with a set of methods for creating constants
00012 // with minimal folding.  For general constant creation and folding,
00013 // use ConstantExpr and the routines in llvm/Analysis/ConstantFolding.h.
00014 //
00015 //===----------------------------------------------------------------------===//
00016 
00017 #ifndef LLVM_SUPPORT_CONSTANTFOLDER_H
00018 #define LLVM_SUPPORT_CONSTANTFOLDER_H
00019 
00020 #include "llvm/Constants.h"
00021 
00022 namespace llvm {
00023 
00024 /// ConstantFolder - Create constants with minimum, target independent, folding.
00025 class ConstantFolder {
00026 public:
00027 
00028   //===--------------------------------------------------------------------===//
00029   // Binary Operators
00030   //===--------------------------------------------------------------------===//
00031 
00032   Constant *CreateAdd(Constant *LHS, Constant *RHS) const {
00033     return ConstantExpr::getAdd(LHS, RHS);
00034   }
00035   Constant *CreateSub(Constant *LHS, Constant *RHS) const {
00036     return ConstantExpr::getSub(LHS, RHS);
00037   }
00038   Constant *CreateMul(Constant *LHS, Constant *RHS) const {
00039     return ConstantExpr::getMul(LHS, RHS);
00040   }
00041   Constant *CreateUDiv(Constant *LHS, Constant *RHS) const {
00042     return ConstantExpr::getUDiv(LHS, RHS);
00043   }
00044   Constant *CreateSDiv(Constant *LHS, Constant *RHS) const {
00045     return ConstantExpr::getSDiv(LHS, RHS);
00046   }
00047   Constant *CreateFDiv(Constant *LHS, Constant *RHS) const {
00048     return ConstantExpr::getFDiv(LHS, RHS);
00049   }
00050   Constant *CreateURem(Constant *LHS, Constant *RHS) const {
00051     return ConstantExpr::getURem(LHS, RHS);
00052   }
00053   Constant *CreateSRem(Constant *LHS, Constant *RHS) const {
00054     return ConstantExpr::getSRem(LHS, RHS);
00055   }
00056   Constant *CreateFRem(Constant *LHS, Constant *RHS) const {
00057     return ConstantExpr::getFRem(LHS, RHS);
00058   }
00059   Constant *CreateShl(Constant *LHS, Constant *RHS) const {
00060     return ConstantExpr::getShl(LHS, RHS);
00061   }
00062   Constant *CreateLShr(Constant *LHS, Constant *RHS) const {
00063     return ConstantExpr::getLShr(LHS, RHS);
00064   }
00065   Constant *CreateAShr(Constant *LHS, Constant *RHS) const {
00066     return ConstantExpr::getAShr(LHS, RHS);
00067   }
00068   Constant *CreateAnd(Constant *LHS, Constant *RHS) const {
00069     return ConstantExpr::getAnd(LHS, RHS);
00070   }
00071   Constant *CreateOr(Constant *LHS, Constant *RHS) const {
00072     return ConstantExpr::getOr(LHS, RHS);
00073   }
00074   Constant *CreateXor(Constant *LHS, Constant *RHS) const {
00075     return ConstantExpr::getXor(LHS, RHS);
00076   }
00077 
00078   Constant *CreateBinOp(Instruction::BinaryOps Opc,
00079                         Constant *LHS, Constant *RHS) const {
00080     return ConstantExpr::get(Opc, LHS, RHS);
00081   }
00082 
00083   //===--------------------------------------------------------------------===//
00084   // Unary Operators
00085   //===--------------------------------------------------------------------===//
00086 
00087   Constant *CreateNeg(Constant *C) const {
00088     return ConstantExpr::getNeg(C);
00089   }
00090   Constant *CreateNot(Constant *C) const {
00091     return ConstantExpr::getNot(C);
00092   }
00093 
00094   //===--------------------------------------------------------------------===//
00095   // Memory Instructions
00096   //===--------------------------------------------------------------------===//
00097 
00098   Constant *CreateGetElementPtr(Constant *C, Constant* const *IdxList,
00099                                 unsigned NumIdx) const {
00100     return ConstantExpr::getGetElementPtr(C, IdxList, NumIdx);
00101   }
00102   Constant *CreateGetElementPtr(Constant *C, Value* const *IdxList,
00103                                 unsigned NumIdx) const {
00104     return ConstantExpr::getGetElementPtr(C, IdxList, NumIdx);
00105   }
00106 
00107   //===--------------------------------------------------------------------===//
00108   // Cast/Conversion Operators
00109   //===--------------------------------------------------------------------===//
00110 
00111   Constant *CreateCast(Instruction::CastOps Op, Constant *C,
00112                        const Type *DestTy) const {
00113     return ConstantExpr::getCast(Op, C, DestTy);
00114   }
00115   Constant *CreateIntCast(Constant *C, const Type *DestTy,
00116                           bool isSigned) const {
00117     return ConstantExpr::getIntegerCast(C, DestTy, isSigned);
00118   }
00119 
00120   Constant *CreateBitCast(Constant *C, const Type *DestTy) const {
00121     return CreateCast(Instruction::BitCast, C, DestTy);
00122   }
00123   Constant *CreateIntToPtr(Constant *C, const Type *DestTy) const {
00124     return CreateCast(Instruction::IntToPtr, C, DestTy);
00125   }
00126   Constant *CreatePtrToInt(Constant *C, const Type *DestTy) const {
00127     return CreateCast(Instruction::PtrToInt, C, DestTy);
00128   }
00129   Constant *CreateTruncOrBitCast(Constant *C, const Type *DestTy) const {
00130     return ConstantExpr::getTruncOrBitCast(C, DestTy);
00131   }
00132 
00133   //===--------------------------------------------------------------------===//
00134   // Compare Instructions
00135   //===--------------------------------------------------------------------===//
00136 
00137   Constant *CreateICmp(CmpInst::Predicate P, Constant *LHS,
00138                        Constant *RHS) const {
00139     return ConstantExpr::getCompare(P, LHS, RHS);
00140   }
00141   Constant *CreateFCmp(CmpInst::Predicate P, Constant *LHS,
00142                        Constant *RHS) const {
00143     return ConstantExpr::getCompare(P, LHS, RHS);
00144   }
00145   Constant *CreateVICmp(CmpInst::Predicate P, Constant *LHS,
00146                         Constant *RHS) const {
00147     return ConstantExpr::getCompare(P, LHS, RHS);
00148   }
00149   Constant *CreateVFCmp(CmpInst::Predicate P, Constant *LHS,
00150                         Constant *RHS) const {
00151     return ConstantExpr::getCompare(P, LHS, RHS);
00152   }
00153 
00154   //===--------------------------------------------------------------------===//
00155   // Other Instructions
00156   //===--------------------------------------------------------------------===//
00157 
00158   Constant *CreateSelect(Constant *C, Constant *True, Constant *False) const {
00159     return ConstantExpr::getSelect(C, True, False);
00160   }
00161 
00162   Constant *CreateExtractElement(Constant *Vec, Constant *Idx) const {
00163     return ConstantExpr::getExtractElement(Vec, Idx);
00164   }
00165 
00166   Constant *CreateInsertElement(Constant *Vec, Constant *NewElt,
00167                                 Constant *Idx) const {
00168     return ConstantExpr::getInsertElement(Vec, NewElt, Idx);
00169   }
00170 
00171   Constant *CreateShuffleVector(Constant *V1, Constant *V2,
00172                                 Constant *Mask) const {
00173     return ConstantExpr::getShuffleVector(V1, V2, Mask);
00174   }
00175 
00176   Constant *CreateExtractValue(Constant *Agg, const unsigned *IdxList,
00177                                unsigned NumIdx) const {
00178     return ConstantExpr::getExtractValue(Agg, IdxList, NumIdx);
00179   }
00180 
00181   Constant *CreateInsertValue(Constant *Agg, Constant *Val,
00182                               const unsigned *IdxList, unsigned NumIdx) const {
00183     return ConstantExpr::getInsertValue(Agg, Val, IdxList, NumIdx);
00184   }
00185 };
00186 
00187 }
00188 
00189 #endif



This web site is hosted by the Computer Science Department at the University of Illinois at Urbana-Champaign.