LLVM API Documentation

NoFolder.h

Go to the documentation of this file.
00001 //======-- llvm/Support/NoFolder.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 NoFolder class, a helper for IRBuilder.  It provides
00011 // IRBuilder with a set of methods for creating unfolded constants.  This is
00012 // useful for learners trying to understand how LLVM IR works, and who don't
00013 // want details to be hidden by the constant folder.  For general constant
00014 // creation and folding, use ConstantExpr and the routines in
00015 // llvm/Analysis/ConstantFolding.h.
00016 //
00017 // Note: since it is not actually possible to create unfolded constants, this
00018 // class returns values rather than constants.  The values do not have names,
00019 // even if names were provided to IRBuilder, which may be confusing.
00020 //
00021 //===----------------------------------------------------------------------===//
00022 
00023 #ifndef LLVM_SUPPORT_NOFOLDER_H
00024 #define LLVM_SUPPORT_NOFOLDER_H
00025 
00026 #include "llvm/Constants.h"
00027 #include "llvm/Instructions.h"
00028 
00029 namespace llvm {
00030 
00031 /// NoFolder - Create "constants" (actually, values) with no folding.
00032 class NoFolder {
00033 public:
00034 
00035   //===--------------------------------------------------------------------===//
00036   // Binary Operators
00037   //===--------------------------------------------------------------------===//
00038 
00039   Value *CreateAdd(Constant *LHS, Constant *RHS) const {
00040     return BinaryOperator::CreateAdd(LHS, RHS);
00041   }
00042   Value *CreateSub(Constant *LHS, Constant *RHS) const {
00043     return BinaryOperator::CreateSub(LHS, RHS);
00044   }
00045   Value *CreateMul(Constant *LHS, Constant *RHS) const {
00046     return BinaryOperator::CreateMul(LHS, RHS);
00047   }
00048   Value *CreateUDiv(Constant *LHS, Constant *RHS) const {
00049     return BinaryOperator::CreateUDiv(LHS, RHS);
00050   }
00051   Value *CreateSDiv(Constant *LHS, Constant *RHS) const {
00052     return BinaryOperator::CreateSDiv(LHS, RHS);
00053   }
00054   Value *CreateFDiv(Constant *LHS, Constant *RHS) const {
00055     return BinaryOperator::CreateFDiv(LHS, RHS);
00056   }
00057   Value *CreateURem(Constant *LHS, Constant *RHS) const {
00058     return BinaryOperator::CreateURem(LHS, RHS);
00059   }
00060   Value *CreateSRem(Constant *LHS, Constant *RHS) const {
00061     return BinaryOperator::CreateSRem(LHS, RHS);
00062   }
00063   Value *CreateFRem(Constant *LHS, Constant *RHS) const {
00064     return BinaryOperator::CreateFRem(LHS, RHS);
00065   }
00066   Value *CreateShl(Constant *LHS, Constant *RHS) const {
00067     return BinaryOperator::CreateShl(LHS, RHS);
00068   }
00069   Value *CreateLShr(Constant *LHS, Constant *RHS) const {
00070     return BinaryOperator::CreateLShr(LHS, RHS);
00071   }
00072   Value *CreateAShr(Constant *LHS, Constant *RHS) const {
00073     return BinaryOperator::CreateAShr(LHS, RHS);
00074   }
00075   Value *CreateAnd(Constant *LHS, Constant *RHS) const {
00076     return BinaryOperator::CreateAnd(LHS, RHS);
00077   }
00078   Value *CreateOr(Constant *LHS, Constant *RHS) const {
00079     return BinaryOperator::CreateOr(LHS, RHS);
00080   }
00081   Value *CreateXor(Constant *LHS, Constant *RHS) const {
00082     return BinaryOperator::CreateXor(LHS, RHS);
00083   }
00084 
00085   Value *CreateBinOp(Instruction::BinaryOps Opc,
00086                      Constant *LHS, Constant *RHS) const {
00087     return BinaryOperator::Create(Opc, LHS, RHS);
00088   }
00089 
00090   //===--------------------------------------------------------------------===//
00091   // Unary Operators
00092   //===--------------------------------------------------------------------===//
00093 
00094   Value *CreateNeg(Constant *C) const {
00095     return BinaryOperator::CreateNeg(C);
00096   }
00097   Value *CreateNot(Constant *C) const {
00098     return BinaryOperator::CreateNot(C);
00099   }
00100 
00101   //===--------------------------------------------------------------------===//
00102   // Memory Instructions
00103   //===--------------------------------------------------------------------===//
00104 
00105   Constant *CreateGetElementPtr(Constant *C, Constant* const *IdxList,
00106                                 unsigned NumIdx) const {
00107     return ConstantExpr::getGetElementPtr(C, IdxList, NumIdx);
00108   }
00109   Value *CreateGetElementPtr(Constant *C, Value* const *IdxList,
00110                              unsigned NumIdx) const {
00111     return GetElementPtrInst::Create(C, IdxList, IdxList+NumIdx);
00112   }
00113 
00114   //===--------------------------------------------------------------------===//
00115   // Cast/Conversion Operators
00116   //===--------------------------------------------------------------------===//
00117 
00118   Value *CreateCast(Instruction::CastOps Op, Constant *C,
00119                     const Type *DestTy) const {
00120     return CastInst::Create(Op, C, DestTy);
00121   }
00122   Value *CreateIntCast(Constant *C, const Type *DestTy,
00123                        bool isSigned) const {
00124     return CastInst::CreateIntegerCast(C, DestTy, isSigned);
00125   }
00126 
00127   //===--------------------------------------------------------------------===//
00128   // Compare Instructions
00129   //===--------------------------------------------------------------------===//
00130 
00131   Value *CreateICmp(CmpInst::Predicate P, Constant *LHS, Constant *RHS) const {
00132     return new ICmpInst(P, LHS, RHS);
00133   }
00134   Value *CreateFCmp(CmpInst::Predicate P, Constant *LHS, Constant *RHS) const {
00135     return new FCmpInst(P, LHS, RHS);
00136   }
00137   Value *CreateVICmp(CmpInst::Predicate P, Constant *LHS, Constant *RHS) const {
00138     return new VICmpInst(P, LHS, RHS);
00139   }
00140   Value *CreateVFCmp(CmpInst::Predicate P, Constant *LHS, Constant *RHS) const {
00141     return new VFCmpInst(P, LHS, RHS);
00142   }
00143 
00144   //===--------------------------------------------------------------------===//
00145   // Other Instructions
00146   //===--------------------------------------------------------------------===//
00147 
00148   Value *CreateSelect(Constant *C, Constant *True, Constant *False) const {
00149     return SelectInst::Create(C, True, False);
00150   }
00151 
00152   Value *CreateExtractElement(Constant *Vec, Constant *Idx) const {
00153     return new ExtractElementInst(Vec, Idx);
00154   }
00155 
00156   Value *CreateInsertElement(Constant *Vec, Constant *NewElt,
00157                              Constant *Idx) const {
00158     return InsertElementInst::Create(Vec, NewElt, Idx);
00159   }
00160 
00161   Value *CreateShuffleVector(Constant *V1, Constant *V2, Constant *Mask) const {
00162     return new ShuffleVectorInst(V1, V2, Mask);
00163   }
00164 
00165   Value *CreateExtractValue(Constant *Agg, const unsigned *IdxList,
00166                             unsigned NumIdx) const {
00167     return ExtractValueInst::Create(Agg, IdxList, IdxList+NumIdx);
00168   }
00169 
00170   Value *CreateInsertValue(Constant *Agg, Constant *Val,
00171                            const unsigned *IdxList, unsigned NumIdx) const {
00172     return InsertValueInst::Create(Agg, Val, IdxList, IdxList+NumIdx);
00173   }
00174 };
00175 
00176 }
00177 
00178 #endif



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