@@ -1685,6 +1685,32 @@ static int map_from_llvmopcode(LLVMOpcode code)
1685
1685
llvm_unreachable (" Unhandled Opcode." );
1686
1686
}
1687
1687
1688
+ /* -- GEP wrap flag conversions*/
1689
+
1690
+ static GEPNoWrapFlags mapFromLLVMGEPNoWrapFlags (LLVMGEPNoWrapFlags GEPFlags) {
1691
+ GEPNoWrapFlags NewGEPFlags;
1692
+ if ((GEPFlags & LLVMGEPFlagInBounds) != 0 )
1693
+ NewGEPFlags |= GEPNoWrapFlags::inBounds ();
1694
+ if ((GEPFlags & LLVMGEPFlagNUSW) != 0 )
1695
+ NewGEPFlags |= GEPNoWrapFlags::noUnsignedSignedWrap ();
1696
+ if ((GEPFlags & LLVMGEPFlagNUW) != 0 )
1697
+ NewGEPFlags |= GEPNoWrapFlags::noUnsignedWrap ();
1698
+
1699
+ return NewGEPFlags;
1700
+ }
1701
+
1702
+ static LLVMGEPNoWrapFlags mapToLLVMGEPNoWrapFlags (GEPNoWrapFlags GEPFlags) {
1703
+ LLVMGEPNoWrapFlags NewGEPFlags = 0 ;
1704
+ if (GEPFlags.isInBounds ())
1705
+ NewGEPFlags |= LLVMGEPFlagInBounds;
1706
+ if (GEPFlags.hasNoUnsignedSignedWrap ())
1707
+ NewGEPFlags |= LLVMGEPFlagNUSW;
1708
+ if (GEPFlags.hasNoUnsignedWrap ())
1709
+ NewGEPFlags |= LLVMGEPFlagNUW;
1710
+
1711
+ return NewGEPFlags;
1712
+ }
1713
+
1688
1714
/* --.. Constant expressions ................................................--*/
1689
1715
1690
1716
LLVMOpcode LLVMGetConstOpcode (LLVMValueRef ConstantVal) {
@@ -1789,6 +1815,17 @@ LLVMValueRef LLVMConstInBoundsGEP2(LLVMTypeRef Ty, LLVMValueRef ConstantVal,
1789
1815
return wrap (ConstantExpr::getInBoundsGetElementPtr (unwrap (Ty), Val, IdxList));
1790
1816
}
1791
1817
1818
+ LLVMValueRef LLVMConstGEPWithWrapFlags (LLVMTypeRef Ty, LLVMValueRef ConstantVal,
1819
+ LLVMValueRef *ConstantIndices,
1820
+ unsigned NumIndices,
1821
+ LLVMGEPNoWrapFlags WrapFlags) {
1822
+ ArrayRef<Constant *> IdxList (unwrap<Constant>(ConstantIndices, NumIndices),
1823
+ NumIndices);
1824
+ Constant *Val = unwrap<Constant>(ConstantVal);
1825
+ return wrap (ConstantExpr::getGetElementPtr (
1826
+ unwrap (Ty), Val, IdxList, mapFromLLVMGEPNoWrapFlags (WrapFlags)));
1827
+ }
1828
+
1792
1829
LLVMValueRef LLVMConstTrunc (LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
1793
1830
return wrap (ConstantExpr::getTrunc (unwrap<Constant>(ConstantVal),
1794
1831
unwrap (ToType)));
@@ -3090,30 +3127,6 @@ LLVMTypeRef LLVMGetAllocatedType(LLVMValueRef Alloca) {
3090
3127
3091
3128
/* --.. Operations on gep instructions (only) ...............................--*/
3092
3129
3093
- static GEPNoWrapFlags mapFromLLVMGEPNoWrapFlags (LLVMGEPNoWrapFlags GEPFlags) {
3094
- GEPNoWrapFlags NewGEPFlags;
3095
- if ((GEPFlags & LLVMGEPFlagInBounds) != 0 )
3096
- NewGEPFlags |= GEPNoWrapFlags::inBounds ();
3097
- if ((GEPFlags & LLVMGEPFlagNUSW) != 0 )
3098
- NewGEPFlags |= GEPNoWrapFlags::noUnsignedSignedWrap ();
3099
- if ((GEPFlags & LLVMGEPFlagNUW) != 0 )
3100
- NewGEPFlags |= GEPNoWrapFlags::noUnsignedWrap ();
3101
-
3102
- return NewGEPFlags;
3103
- }
3104
-
3105
- static LLVMGEPNoWrapFlags mapToLLVMGEPNoWrapFlags (GEPNoWrapFlags GEPFlags) {
3106
- LLVMGEPNoWrapFlags NewGEPFlags = 0 ;
3107
- if (GEPFlags.isInBounds ())
3108
- NewGEPFlags |= LLVMGEPFlagInBounds;
3109
- if (GEPFlags.hasNoUnsignedSignedWrap ())
3110
- NewGEPFlags |= LLVMGEPFlagNUSW;
3111
- if (GEPFlags.hasNoUnsignedWrap ())
3112
- NewGEPFlags |= LLVMGEPFlagNUW;
3113
-
3114
- return NewGEPFlags;
3115
- }
3116
-
3117
3130
LLVMBool LLVMIsInBounds (LLVMValueRef GEP) {
3118
3131
return unwrap<GEPOperator>(GEP)->isInBounds ();
3119
3132
}
@@ -3936,6 +3949,16 @@ LLVMValueRef LLVMBuildInBoundsGEP2(LLVMBuilderRef B, LLVMTypeRef Ty,
3936
3949
unwrap (B)->CreateInBoundsGEP (unwrap (Ty), unwrap (Pointer), IdxList, Name));
3937
3950
}
3938
3951
3952
+ LLVMValueRef LLVMBuildGEPWithWrapFlags (LLVMBuilderRef B, LLVMTypeRef Ty,
3953
+ LLVMValueRef Pointer,
3954
+ LLVMValueRef *Indices,
3955
+ unsigned NumIndices, const char *Name,
3956
+ LLVMGEPNoWrapFlags WrapFlags) {
3957
+ ArrayRef<Value *> IdxList (unwrap (Indices), NumIndices);
3958
+ return wrap (unwrap (B)->CreateGEP (unwrap (Ty), unwrap (Pointer), IdxList, Name,
3959
+ mapFromLLVMGEPNoWrapFlags (WrapFlags)));
3960
+ }
3961
+
3939
3962
LLVMValueRef LLVMBuildStructGEP2 (LLVMBuilderRef B, LLVMTypeRef Ty,
3940
3963
LLVMValueRef Pointer, unsigned Idx,
3941
3964
const char *Name) {
0 commit comments