Constant *GetFrameMap(Function &F);
const Type* GetConcreteStackEntryType(Function &F);
void CollectRoots(Function &F);
- static GetElementPtrInst *CreateGEP(IRBuilder<> &B, Value *BasePtr,
+ static GetElementPtrInst *CreateGEP(LLVMContext &Context,
+ IRBuilder<> &B, Value *BasePtr,
int Idx1, const char *Name);
- static GetElementPtrInst *CreateGEP(IRBuilder<> &B, Value *BasePtr,
+ static GetElementPtrInst *CreateGEP(LLVMContext &Context,
+ IRBuilder<> &B, Value *BasePtr,
int Idx1, int Idx2, const char *Name);
};
public:
EscapeEnumerator(Function &F, const char *N = "cleanup")
- : F(F), CleanupBBName(N), State(0) {}
+ : F(F), CleanupBBName(N), State(0), Builder(F.getContext()) {}
IRBuilder<> *Next() {
switch (State) {
Constant *ShadowStackGC::GetFrameMap(Function &F) {
// doInitialization creates the abstract type of this value.
+ LLVMContext &Context = F.getContext();
Type *VoidPtr = PointerType::getUnqual(Type::Int8Ty);
}
Constant *BaseElts[] = {
- ConstantInt::get(Type::Int32Ty, Roots.size(), false),
- ConstantInt::get(Type::Int32Ty, NumMeta, false),
+ Context.getConstantInt(Type::Int32Ty, Roots.size(), false),
+ Context.getConstantInt(Type::Int32Ty, NumMeta, false),
};
Constant *DescriptorElts[] = {
- ConstantStruct::get(BaseElts, 2),
- ConstantArray::get(ArrayType::get(VoidPtr, NumMeta),
+ Context.getConstantStruct(BaseElts, 2),
+ Context.getConstantArray(Context.getArrayType(VoidPtr, NumMeta),
Metadata.begin(), NumMeta)
};
- Constant *FrameMap = ConstantStruct::get(DescriptorElts, 2);
+ Constant *FrameMap = Context.getConstantStruct(DescriptorElts, 2);
std::string TypeName("gc_map.");
TypeName += utostr(NumMeta);
GlobalVariable::InternalLinkage,
FrameMap, "__gc_" + F.getName());
- Constant *GEPIndices[2] = { ConstantInt::get(Type::Int32Ty, 0),
- ConstantInt::get(Type::Int32Ty, 0) };
- return ConstantExpr::getGetElementPtr(GV, GEPIndices, 2);
+ Constant *GEPIndices[2] = { Context.getConstantInt(Type::Int32Ty, 0),
+ Context.getConstantInt(Type::Int32Ty, 0) };
+ return Context.getConstantExprGetElementPtr(GV, GEPIndices, 2);
}
const Type* ShadowStackGC::GetConcreteStackEntryType(Function &F) {
// linkage!
Head = new GlobalVariable(M, StackEntryPtrTy, false,
GlobalValue::LinkOnceAnyLinkage,
- Constant::getNullValue(StackEntryPtrTy),
+ M.getContext().getNullValue(StackEntryPtrTy),
"llvm_gc_root_chain");
} else if (Head->hasExternalLinkage() && Head->isDeclaration()) {
- Head->setInitializer(Constant::getNullValue(StackEntryPtrTy));
+ Head->setInitializer(M.getContext().getNullValue(StackEntryPtrTy));
Head->setLinkage(GlobalValue::LinkOnceAnyLinkage);
}
}
GetElementPtrInst *
-ShadowStackGC::CreateGEP(IRBuilder<> &B, Value *BasePtr,
+ShadowStackGC::CreateGEP(LLVMContext &Context, IRBuilder<> &B, Value *BasePtr,
int Idx, int Idx2, const char *Name) {
- Value *Indices[] = { ConstantInt::get(Type::Int32Ty, 0),
- ConstantInt::get(Type::Int32Ty, Idx),
- ConstantInt::get(Type::Int32Ty, Idx2) };
+ Value *Indices[] = { Context.getConstantInt(Type::Int32Ty, 0),
+ Context.getConstantInt(Type::Int32Ty, Idx),
+ Context.getConstantInt(Type::Int32Ty, Idx2) };
Value* Val = B.CreateGEP(BasePtr, Indices, Indices + 3, Name);
assert(isa<GetElementPtrInst>(Val) && "Unexpected folded constant");
}
GetElementPtrInst *
-ShadowStackGC::CreateGEP(IRBuilder<> &B, Value *BasePtr,
+ShadowStackGC::CreateGEP(LLVMContext &Context, IRBuilder<> &B, Value *BasePtr,
int Idx, const char *Name) {
- Value *Indices[] = { ConstantInt::get(Type::Int32Ty, 0),
- ConstantInt::get(Type::Int32Ty, Idx) };
+ Value *Indices[] = { Context.getConstantInt(Type::Int32Ty, 0),
+ Context.getConstantInt(Type::Int32Ty, Idx) };
Value *Val = B.CreateGEP(BasePtr, Indices, Indices + 2, Name);
assert(isa<GetElementPtrInst>(Val) && "Unexpected folded constant");
/// runOnFunction - Insert code to maintain the shadow stack.
bool ShadowStackGC::performCustomLowering(Function &F) {
+ LLVMContext &Context = F.getContext();
+
// Find calls to llvm.gcroot.
CollectRoots(F);
// Initialize the map pointer and load the current head of the shadow stack.
Instruction *CurrentHead = AtEntry.CreateLoad(Head, "gc_currhead");
- Instruction *EntryMapPtr = CreateGEP(AtEntry, StackEntry,0,1,"gc_frame.map");
+ Instruction *EntryMapPtr = CreateGEP(Context, AtEntry, StackEntry,
+ 0,1,"gc_frame.map");
AtEntry.CreateStore(FrameMap, EntryMapPtr);
// After all the allocas...
for (unsigned I = 0, E = Roots.size(); I != E; ++I) {
// For each root, find the corresponding slot in the aggregate...
- Value *SlotPtr = CreateGEP(AtEntry, StackEntry, 1 + I, "gc_root");
+ Value *SlotPtr = CreateGEP(Context, AtEntry, StackEntry, 1 + I, "gc_root");
// And use it in lieu of the alloca.
AllocaInst *OriginalAlloca = Roots[I].second;
AtEntry.SetInsertPoint(IP->getParent(), IP);
// Push the entry onto the shadow stack.
- Instruction *EntryNextPtr = CreateGEP(AtEntry,StackEntry,0,0,"gc_frame.next");
- Instruction *NewHeadVal = CreateGEP(AtEntry,StackEntry, 0, "gc_newhead");
- AtEntry.CreateStore(CurrentHead, EntryNextPtr);
- AtEntry.CreateStore(NewHeadVal, Head);
+ Instruction *EntryNextPtr = CreateGEP(Context, AtEntry,
+ StackEntry,0,0,"gc_frame.next");
+ Instruction *NewHeadVal = CreateGEP(Context, AtEntry,
+ StackEntry, 0, "gc_newhead");
+ AtEntry.CreateStore(CurrentHead, EntryNextPtr);
+ AtEntry.CreateStore(NewHeadVal, Head);
// For each instruction that escapes...
EscapeEnumerator EE(F, "gc_cleanup");
while (IRBuilder<> *AtExit = EE.Next()) {
// Pop the entry from the shadow stack. Don't reuse CurrentHead from
// AtEntry, since that would make the value live for the entire function.
- Instruction *EntryNextPtr2 = CreateGEP(*AtExit, StackEntry, 0, 0,
+ Instruction *EntryNextPtr2 = CreateGEP(Context, *AtExit, StackEntry, 0, 0,
"gc_frame.next");
Value *SavedHead = AtExit->CreateLoad(EntryNextPtr2, "gc_savedhead");
AtExit->CreateStore(SavedHead, Head);