diff options
| author | 2012-02-13 09:57:20 -0800 | |
|---|---|---|
| committer | 2012-02-15 00:10:41 -0800 | |
| commit | 4c1f425f62a21e181a437ec45520167332344917 (patch) | |
| tree | 4b6ec8c7f84db54dd517f94b9640897dd0a47a7c /src/compiler_llvm/ir_builder.h | |
| parent | d1fec81868a3567560a3868350e0a945248e925b (diff) | |
Add pointer arithmetic helper function.
Change-Id: I735295c715564093db6d6e6aaaeb05914e0e826e
Diffstat (limited to 'src/compiler_llvm/ir_builder.h')
| -rw-r--r-- | src/compiler_llvm/ir_builder.h | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/compiler_llvm/ir_builder.h b/src/compiler_llvm/ir_builder.h index 03ca2d7be4..2b4095c190 100644 --- a/src/compiler_llvm/ir_builder.h +++ b/src/compiler_llvm/ir_builder.h @@ -46,6 +46,50 @@ class IRBuilder : public LLVMIRBuilder { //-------------------------------------------------------------------------- + // Pointer Arithmetic Helper Function + //-------------------------------------------------------------------------- + + llvm::IntegerType* getPtrEquivIntTy() { + return getInt32Ty(); + } + + size_t getSizeOfPtrEquivInt() { + return 4; + } + + llvm::ConstantInt* getSizeOfPtrEquivIntValue() { + return getPtrEquivInt(getSizeOfPtrEquivInt()); + } + + llvm::ConstantInt* getPtrEquivInt(uint64_t i) { + return llvm::ConstantInt::get(getPtrEquivIntTy(), i); + } + + llvm::Value* CreatePtrDisp(llvm::Value* base, + llvm::Value* offset, + llvm::PointerType* ret_ty) { + + llvm::Value* base_int = CreatePtrToInt(base, getPtrEquivIntTy()); + llvm::Value* result_int = CreateAdd(base_int, offset); + llvm::Value* result = CreateIntToPtr(result_int, ret_ty); + + return result; + } + + llvm::Value* CreatePtrDisp(llvm::Value* base, + llvm::Value* bs, + llvm::Value* count, + llvm::Value* offset, + llvm::PointerType* ret_ty) { + + llvm::Value* block_offset = CreateMul(bs, count); + llvm::Value* total_offset = CreateAdd(block_offset, offset); + + return CreatePtrDisp(base, total_offset, ret_ty); + } + + + //-------------------------------------------------------------------------- // Type Helper Function //-------------------------------------------------------------------------- |