#define LLVM_SUPPORT_TARGETFOLDER_H
#include "llvm/Constants.h"
+#include "llvm/InstrTypes.h"
#include "llvm/Analysis/ConstantFolding.h"
namespace llvm {
class TargetData;
-struct LLVMContext;
/// TargetFolder - Create constants with target dependent folding.
class TargetFolder {
const TargetData *TD;
- LLVMContext &Context;
/// Fold - Fold the constant using target specific information.
Constant *Fold(Constant *C) const {
if (ConstantExpr *CE = dyn_cast<ConstantExpr>(C))
- if (Constant *CF = ConstantFoldConstantExpression(CE, Context, TD))
+ if (Constant *CF = ConstantFoldConstantExpression(CE, TD))
return CF;
return C;
}
public:
- explicit TargetFolder(const TargetData *TheTD, LLVMContext &C) :
- TD(TheTD), Context(C) {}
+ explicit TargetFolder(const TargetData *TheTD) : TD(TheTD) {}
//===--------------------------------------------------------------------===//
// Binary Operators
//===--------------------------------------------------------------------===//
- Constant *CreateAdd(Constant *LHS, Constant *RHS) const {
- return Fold(ConstantExpr::getAdd(LHS, RHS));
+ Constant *CreateAdd(Constant *LHS, Constant *RHS,
+ bool HasNUW = false, bool HasNSW = false) const {
+ return Fold(ConstantExpr::getAdd(LHS, RHS, HasNUW, HasNSW));
}
Constant *CreateFAdd(Constant *LHS, Constant *RHS) const {
return Fold(ConstantExpr::getFAdd(LHS, RHS));
}
- Constant *CreateSub(Constant *LHS, Constant *RHS) const {
- return Fold(ConstantExpr::getSub(LHS, RHS));
+ Constant *CreateSub(Constant *LHS, Constant *RHS,
+ bool HasNUW = false, bool HasNSW = false) const {
+ return Fold(ConstantExpr::getSub(LHS, RHS, HasNUW, HasNSW));
}
Constant *CreateFSub(Constant *LHS, Constant *RHS) const {
return Fold(ConstantExpr::getFSub(LHS, RHS));
}
- Constant *CreateMul(Constant *LHS, Constant *RHS) const {
- return Fold(ConstantExpr::getMul(LHS, RHS));
+ Constant *CreateMul(Constant *LHS, Constant *RHS,
+ bool HasNUW = false, bool HasNSW = false) const {
+ return Fold(ConstantExpr::getMul(LHS, RHS, HasNUW, HasNSW));
}
Constant *CreateFMul(Constant *LHS, Constant *RHS) const {
return Fold(ConstantExpr::getFMul(LHS, RHS));
}
- Constant *CreateUDiv(Constant *LHS, Constant *RHS) const {
- return Fold(ConstantExpr::getUDiv(LHS, RHS));
+ Constant *CreateUDiv(Constant *LHS, Constant *RHS, bool isExact = false)const{
+ return Fold(ConstantExpr::getUDiv(LHS, RHS, isExact));
}
- Constant *CreateSDiv(Constant *LHS, Constant *RHS) const {
- return Fold(ConstantExpr::getSDiv(LHS, RHS));
- }
- Constant *CreateExactSDiv(Constant *LHS, Constant *RHS) const {
- return Fold(ConstantExpr::getExactSDiv(LHS, RHS));
+ Constant *CreateSDiv(Constant *LHS, Constant *RHS, bool isExact = false)const{
+ return Fold(ConstantExpr::getSDiv(LHS, RHS, isExact));
}
Constant *CreateFDiv(Constant *LHS, Constant *RHS) const {
return Fold(ConstantExpr::getFDiv(LHS, RHS));
Constant *CreateFRem(Constant *LHS, Constant *RHS) const {
return Fold(ConstantExpr::getFRem(LHS, RHS));
}
- Constant *CreateShl(Constant *LHS, Constant *RHS) const {
- return Fold(ConstantExpr::getShl(LHS, RHS));
+ Constant *CreateShl(Constant *LHS, Constant *RHS,
+ bool HasNUW = false, bool HasNSW = false) const {
+ return Fold(ConstantExpr::getShl(LHS, RHS, HasNUW, HasNSW));
}
- Constant *CreateLShr(Constant *LHS, Constant *RHS) const {
- return Fold(ConstantExpr::getLShr(LHS, RHS));
+ Constant *CreateLShr(Constant *LHS, Constant *RHS, bool isExact = false)const{
+ return Fold(ConstantExpr::getLShr(LHS, RHS, isExact));
}
- Constant *CreateAShr(Constant *LHS, Constant *RHS) const {
- return Fold(ConstantExpr::getAShr(LHS, RHS));
+ Constant *CreateAShr(Constant *LHS, Constant *RHS, bool isExact = false)const{
+ return Fold(ConstantExpr::getAShr(LHS, RHS, isExact));
}
Constant *CreateAnd(Constant *LHS, Constant *RHS) const {
return Fold(ConstantExpr::getAnd(LHS, RHS));
// Unary Operators
//===--------------------------------------------------------------------===//
- Constant *CreateNeg(Constant *C) const {
- return Fold(ConstantExpr::getNeg(C));
+ Constant *CreateNeg(Constant *C,
+ bool HasNUW = false, bool HasNSW = false) const {
+ return Fold(ConstantExpr::getNeg(C, HasNUW, HasNSW));
}
Constant *CreateFNeg(Constant *C) const {
return Fold(ConstantExpr::getFNeg(C));
return Fold(ConstantExpr::getGetElementPtr(C, IdxList, NumIdx));
}
+ Constant *CreateInBoundsGetElementPtr(Constant *C, Constant* const *IdxList,
+ unsigned NumIdx) const {
+ return Fold(ConstantExpr::getInBoundsGetElementPtr(C, IdxList, NumIdx));
+ }
+ Constant *CreateInBoundsGetElementPtr(Constant *C, Value* const *IdxList,
+ unsigned NumIdx) const {
+ return Fold(ConstantExpr::getInBoundsGetElementPtr(C, IdxList, NumIdx));
+ }
+
//===--------------------------------------------------------------------===//
// Cast/Conversion Operators
//===--------------------------------------------------------------------===//
return C; // avoid calling Fold
return Fold(ConstantExpr::getIntegerCast(C, DestTy, isSigned));
}
-
+ Constant *CreatePointerCast(Constant *C, const Type *DestTy) const {
+ return ConstantExpr::getPointerCast(C, DestTy);
+ }
Constant *CreateBitCast(Constant *C, const Type *DestTy) const {
return CreateCast(Instruction::BitCast, C, DestTy);
}
Constant *CreatePtrToInt(Constant *C, const Type *DestTy) const {
return CreateCast(Instruction::PtrToInt, C, DestTy);
}
+ Constant *CreateZExtOrBitCast(Constant *C, const Type *DestTy) const {
+ if (C->getType() == DestTy)
+ return C; // avoid calling Fold
+ return Fold(ConstantExpr::getZExtOrBitCast(C, DestTy));
+ }
+ Constant *CreateSExtOrBitCast(Constant *C, const Type *DestTy) const {
+ if (C->getType() == DestTy)
+ return C; // avoid calling Fold
+ return Fold(ConstantExpr::getSExtOrBitCast(C, DestTy));
+ }
Constant *CreateTruncOrBitCast(Constant *C, const Type *DestTy) const {
if (C->getType() == DestTy)
return C; // avoid calling Fold