mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-23 19:23:23 +01:00
[opaque pointer type] IRBuilder gep migration progress
llvm-svn: 232294
This commit is contained in:
parent
24b00ca753
commit
441e94fa44
@ -1017,6 +1017,10 @@ public:
|
|||||||
}
|
}
|
||||||
Value *CreateGEP(Value *Ptr, ArrayRef<Value *> IdxList,
|
Value *CreateGEP(Value *Ptr, ArrayRef<Value *> IdxList,
|
||||||
const Twine &Name = "") {
|
const Twine &Name = "") {
|
||||||
|
return CreateGEP(nullptr, Ptr, IdxList, Name);
|
||||||
|
}
|
||||||
|
Value *CreateGEP(Type *Ty, Value *Ptr, ArrayRef<Value *> IdxList,
|
||||||
|
const Twine &Name = "") {
|
||||||
if (Constant *PC = dyn_cast<Constant>(Ptr)) {
|
if (Constant *PC = dyn_cast<Constant>(Ptr)) {
|
||||||
// Every index must be constant.
|
// Every index must be constant.
|
||||||
size_t i, e;
|
size_t i, e;
|
||||||
@ -1026,7 +1030,7 @@ public:
|
|||||||
if (i == e)
|
if (i == e)
|
||||||
return Insert(Folder.CreateGetElementPtr(PC, IdxList), Name);
|
return Insert(Folder.CreateGetElementPtr(PC, IdxList), Name);
|
||||||
}
|
}
|
||||||
return Insert(GetElementPtrInst::Create(nullptr, Ptr, IdxList), Name);
|
return Insert(GetElementPtrInst::Create(Ty, Ptr, IdxList), Name);
|
||||||
}
|
}
|
||||||
Value *CreateInBoundsGEP(Value *Ptr, ArrayRef<Value *> IdxList,
|
Value *CreateInBoundsGEP(Value *Ptr, ArrayRef<Value *> IdxList,
|
||||||
const Twine &Name = "") {
|
const Twine &Name = "") {
|
||||||
|
@ -53,10 +53,10 @@ private:
|
|||||||
Type *GetConcreteStackEntryType(Function &F);
|
Type *GetConcreteStackEntryType(Function &F);
|
||||||
void CollectRoots(Function &F);
|
void CollectRoots(Function &F);
|
||||||
static GetElementPtrInst *CreateGEP(LLVMContext &Context, IRBuilder<> &B,
|
static GetElementPtrInst *CreateGEP(LLVMContext &Context, IRBuilder<> &B,
|
||||||
Value *BasePtr, int Idx1,
|
Type *Ty, Value *BasePtr, int Idx1,
|
||||||
const char *Name);
|
const char *Name);
|
||||||
static GetElementPtrInst *CreateGEP(LLVMContext &Context, IRBuilder<> &B,
|
static GetElementPtrInst *CreateGEP(LLVMContext &Context, IRBuilder<> &B,
|
||||||
Value *BasePtr, int Idx1, int Idx2,
|
Type *Ty, Value *BasePtr, int Idx1, int Idx2,
|
||||||
const char *Name);
|
const char *Name);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -343,13 +343,14 @@ void ShadowStackGCLowering::CollectRoots(Function &F) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
GetElementPtrInst *ShadowStackGCLowering::CreateGEP(LLVMContext &Context,
|
GetElementPtrInst *ShadowStackGCLowering::CreateGEP(LLVMContext &Context,
|
||||||
IRBuilder<> &B, Value *BasePtr,
|
IRBuilder<> &B, Type *Ty,
|
||||||
int Idx, int Idx2,
|
Value *BasePtr, int Idx,
|
||||||
|
int Idx2,
|
||||||
const char *Name) {
|
const char *Name) {
|
||||||
Value *Indices[] = {ConstantInt::get(Type::getInt32Ty(Context), 0),
|
Value *Indices[] = {ConstantInt::get(Type::getInt32Ty(Context), 0),
|
||||||
ConstantInt::get(Type::getInt32Ty(Context), Idx),
|
ConstantInt::get(Type::getInt32Ty(Context), Idx),
|
||||||
ConstantInt::get(Type::getInt32Ty(Context), Idx2)};
|
ConstantInt::get(Type::getInt32Ty(Context), Idx2)};
|
||||||
Value *Val = B.CreateGEP(BasePtr, Indices, Name);
|
Value *Val = B.CreateGEP(Ty, BasePtr, Indices, Name);
|
||||||
|
|
||||||
assert(isa<GetElementPtrInst>(Val) && "Unexpected folded constant");
|
assert(isa<GetElementPtrInst>(Val) && "Unexpected folded constant");
|
||||||
|
|
||||||
@ -357,11 +358,11 @@ GetElementPtrInst *ShadowStackGCLowering::CreateGEP(LLVMContext &Context,
|
|||||||
}
|
}
|
||||||
|
|
||||||
GetElementPtrInst *ShadowStackGCLowering::CreateGEP(LLVMContext &Context,
|
GetElementPtrInst *ShadowStackGCLowering::CreateGEP(LLVMContext &Context,
|
||||||
IRBuilder<> &B, Value *BasePtr,
|
IRBuilder<> &B, Type *Ty, Value *BasePtr,
|
||||||
int Idx, const char *Name) {
|
int Idx, const char *Name) {
|
||||||
Value *Indices[] = {ConstantInt::get(Type::getInt32Ty(Context), 0),
|
Value *Indices[] = {ConstantInt::get(Type::getInt32Ty(Context), 0),
|
||||||
ConstantInt::get(Type::getInt32Ty(Context), Idx)};
|
ConstantInt::get(Type::getInt32Ty(Context), Idx)};
|
||||||
Value *Val = B.CreateGEP(BasePtr, Indices, Name);
|
Value *Val = B.CreateGEP(Ty, BasePtr, Indices, Name);
|
||||||
|
|
||||||
assert(isa<GetElementPtrInst>(Val) && "Unexpected folded constant");
|
assert(isa<GetElementPtrInst>(Val) && "Unexpected folded constant");
|
||||||
|
|
||||||
@ -402,14 +403,15 @@ bool ShadowStackGCLowering::runOnFunction(Function &F) {
|
|||||||
|
|
||||||
// Initialize the map pointer and load the current head of the shadow stack.
|
// Initialize the map pointer and load the current head of the shadow stack.
|
||||||
Instruction *CurrentHead = AtEntry.CreateLoad(Head, "gc_currhead");
|
Instruction *CurrentHead = AtEntry.CreateLoad(Head, "gc_currhead");
|
||||||
Instruction *EntryMapPtr =
|
Instruction *EntryMapPtr = CreateGEP(Context, AtEntry, ConcreteStackEntryTy,
|
||||||
CreateGEP(Context, AtEntry, StackEntry, 0, 1, "gc_frame.map");
|
StackEntry, 0, 1, "gc_frame.map");
|
||||||
AtEntry.CreateStore(FrameMap, EntryMapPtr);
|
AtEntry.CreateStore(FrameMap, EntryMapPtr);
|
||||||
|
|
||||||
// After all the allocas...
|
// After all the allocas...
|
||||||
for (unsigned I = 0, E = Roots.size(); I != E; ++I) {
|
for (unsigned I = 0, E = Roots.size(); I != E; ++I) {
|
||||||
// For each root, find the corresponding slot in the aggregate...
|
// For each root, find the corresponding slot in the aggregate...
|
||||||
Value *SlotPtr = CreateGEP(Context, AtEntry, StackEntry, 1 + I, "gc_root");
|
Value *SlotPtr = CreateGEP(Context, AtEntry, ConcreteStackEntryTy,
|
||||||
|
StackEntry, 1 + I, "gc_root");
|
||||||
|
|
||||||
// And use it in lieu of the alloca.
|
// And use it in lieu of the alloca.
|
||||||
AllocaInst *OriginalAlloca = Roots[I].second;
|
AllocaInst *OriginalAlloca = Roots[I].second;
|
||||||
@ -426,10 +428,10 @@ bool ShadowStackGCLowering::runOnFunction(Function &F) {
|
|||||||
AtEntry.SetInsertPoint(IP->getParent(), IP);
|
AtEntry.SetInsertPoint(IP->getParent(), IP);
|
||||||
|
|
||||||
// Push the entry onto the shadow stack.
|
// Push the entry onto the shadow stack.
|
||||||
Instruction *EntryNextPtr =
|
Instruction *EntryNextPtr = CreateGEP(Context, AtEntry, ConcreteStackEntryTy,
|
||||||
CreateGEP(Context, AtEntry, StackEntry, 0, 0, "gc_frame.next");
|
StackEntry, 0, 0, "gc_frame.next");
|
||||||
Instruction *NewHeadVal =
|
Instruction *NewHeadVal = CreateGEP(Context, AtEntry, ConcreteStackEntryTy,
|
||||||
CreateGEP(Context, AtEntry, StackEntry, 0, "gc_newhead");
|
StackEntry, 0, "gc_newhead");
|
||||||
AtEntry.CreateStore(CurrentHead, EntryNextPtr);
|
AtEntry.CreateStore(CurrentHead, EntryNextPtr);
|
||||||
AtEntry.CreateStore(NewHeadVal, Head);
|
AtEntry.CreateStore(NewHeadVal, Head);
|
||||||
|
|
||||||
@ -439,7 +441,8 @@ bool ShadowStackGCLowering::runOnFunction(Function &F) {
|
|||||||
// Pop the entry from the shadow stack. Don't reuse CurrentHead from
|
// Pop the entry from the shadow stack. Don't reuse CurrentHead from
|
||||||
// AtEntry, since that would make the value live for the entire function.
|
// AtEntry, since that would make the value live for the entire function.
|
||||||
Instruction *EntryNextPtr2 =
|
Instruction *EntryNextPtr2 =
|
||||||
CreateGEP(Context, *AtExit, StackEntry, 0, 0, "gc_frame.next");
|
CreateGEP(Context, *AtExit, ConcreteStackEntryTy, StackEntry, 0, 0,
|
||||||
|
"gc_frame.next");
|
||||||
Value *SavedHead = AtExit->CreateLoad(EntryNextPtr2, "gc_savedhead");
|
Value *SavedHead = AtExit->CreateLoad(EntryNextPtr2, "gc_savedhead");
|
||||||
AtExit->CreateStore(SavedHead, Head);
|
AtExit->CreateStore(SavedHead, Head);
|
||||||
}
|
}
|
||||||
|
@ -2506,7 +2506,7 @@ LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
|
|||||||
LLVMValueRef *Indices, unsigned NumIndices,
|
LLVMValueRef *Indices, unsigned NumIndices,
|
||||||
const char *Name) {
|
const char *Name) {
|
||||||
ArrayRef<Value *> IdxList(unwrap(Indices), NumIndices);
|
ArrayRef<Value *> IdxList(unwrap(Indices), NumIndices);
|
||||||
return wrap(unwrap(B)->CreateGEP(unwrap(Pointer), IdxList, Name));
|
return wrap(unwrap(B)->CreateGEP(nullptr, unwrap(Pointer), IdxList, Name));
|
||||||
}
|
}
|
||||||
|
|
||||||
LLVMValueRef LLVMBuildInBoundsGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
|
LLVMValueRef LLVMBuildInBoundsGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
|
||||||
|
@ -1460,11 +1460,16 @@ Instruction *InstCombiner::commonPointerCastTransforms(CastInst &CI) {
|
|||||||
APInt Offset(OffsetBits, 0);
|
APInt Offset(OffsetBits, 0);
|
||||||
BitCastInst *BCI = dyn_cast<BitCastInst>(GEP->getOperand(0));
|
BitCastInst *BCI = dyn_cast<BitCastInst>(GEP->getOperand(0));
|
||||||
if (GEP->hasOneUse() && BCI && GEP->accumulateConstantOffset(DL, Offset)) {
|
if (GEP->hasOneUse() && BCI && GEP->accumulateConstantOffset(DL, Offset)) {
|
||||||
|
// FIXME: This is insufficiently tested - just a no-crash test
|
||||||
|
// (test/Transforms/InstCombine/2007-05-14-Crash.ll)
|
||||||
|
//
|
||||||
// Get the base pointer input of the bitcast, and the type it points to.
|
// Get the base pointer input of the bitcast, and the type it points to.
|
||||||
Value *OrigBase = BCI->getOperand(0);
|
Value *OrigBase = BCI->getOperand(0);
|
||||||
SmallVector<Value*, 8> NewIndices;
|
SmallVector<Value*, 8> NewIndices;
|
||||||
if (FindElementAtOffset(OrigBase->getType(), Offset.getSExtValue(),
|
if (FindElementAtOffset(OrigBase->getType(), Offset.getSExtValue(),
|
||||||
NewIndices)) {
|
NewIndices)) {
|
||||||
|
// FIXME: This codepath is completely untested - could be unreachable
|
||||||
|
// for all I know.
|
||||||
// If we were able to index down into an element, create the GEP
|
// If we were able to index down into an element, create the GEP
|
||||||
// and bitcast the result. This eliminates one bitcast, potentially
|
// and bitcast the result. This eliminates one bitcast, potentially
|
||||||
// two.
|
// two.
|
||||||
|
Loading…
Reference in New Issue
Block a user