Let's start with the documentation for GetElementPtrInst , since IRBuilder provides a wrapper for its constructors. If we want to add this instruction, I usually go straight ahead and call create.
GetElementPtrInst::Create(ptr, IdxList, name, insertpoint)
- Ptr: *, ptr, GetElementPtr (GEP). % arr.
- IdxList: , , GEP. 0 % .
- : IR. "% arrayidx", "arrayidx".
- insertpoint: IRBuilder , ( , ).
, :
Value* arr = ...;
Value* someValue = ...;
Value* indexList[2] = {ConstantInt::get(someValue->getType(), 0), someValue};
GetElementPtrInst* gepInst = GetElementPtrInst::Create(arr, ArrayRef<Value*>(indexList, 2), "arrayIdx", <some location to insert>);
IRBuilder, :
IRBuilder::CreateGEP(ptr, idxList, name)
IRBuilder, IRBuilder.
source
share