From 89f6d88db334ba088672ae0753deb7d7b7509bac Mon Sep 17 00:00:00 2001 From: Duncan Sands Date: Sun, 13 Apr 2008 06:22:09 +0000 Subject: Merge LLVMBuilder and FoldingBuilder, calling the result IRBuilder. Patch by Dominic Hamon. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@49604 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/ShadowStackCollector.cpp | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) (limited to 'lib/CodeGen/ShadowStackCollector.cpp') diff --git a/lib/CodeGen/ShadowStackCollector.cpp b/lib/CodeGen/ShadowStackCollector.cpp index 2a703d8e44..d41e83c712 100644 --- a/lib/CodeGen/ShadowStackCollector.cpp +++ b/lib/CodeGen/ShadowStackCollector.cpp @@ -31,7 +31,7 @@ #include "llvm/CodeGen/Collector.h" #include "llvm/IntrinsicInst.h" #include "llvm/Module.h" -#include "llvm/Support/LLVMBuilder.h" +#include "llvm/Support/IRBuilder.h" using namespace llvm; @@ -61,9 +61,9 @@ namespace { Constant *GetFrameMap(Function &F); const Type* GetConcreteStackEntryType(Function &F); void CollectRoots(Function &F); - static GetElementPtrInst *CreateGEP(LLVMBuilder &B, Value *BasePtr, + static GetElementPtrInst *CreateGEP(IRBuilder &B, Value *BasePtr, int Idx1, const char *Name); - static GetElementPtrInst *CreateGEP(LLVMBuilder &B, Value *BasePtr, + static GetElementPtrInst *CreateGEP(IRBuilder &B, Value *BasePtr, int Idx1, int Idx2, const char *Name); }; @@ -86,13 +86,13 @@ namespace { // State. int State; Function::iterator StateBB, StateE; - LLVMBuilder Builder; + IRBuilder Builder; public: EscapeEnumerator(Function &F, const char *N = "cleanup") : F(F), CleanupBBName(N), State(0) {} - LLVMBuilder *Next() { + IRBuilder *Next() { switch (State) { default: return 0; @@ -339,20 +339,28 @@ void ShadowStackCollector::CollectRoots(Function &F) { } GetElementPtrInst * -ShadowStackCollector::CreateGEP(LLVMBuilder &B, Value *BasePtr, +ShadowStackCollector::CreateGEP(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) }; - return B.CreateGEP(BasePtr, Indices, Indices + 3, Name); + Value* Val = B.CreateGEP(BasePtr, Indices, Indices + 3, Name); + + assert(isa(Val) && "Unexpected folded constant"); + + return dyn_cast(Val); } GetElementPtrInst * -ShadowStackCollector::CreateGEP(LLVMBuilder &B, Value *BasePtr, +ShadowStackCollector::CreateGEP(IRBuilder &B, Value *BasePtr, int Idx, const char *Name) { Value *Indices[] = { ConstantInt::get(Type::Int32Ty, 0), ConstantInt::get(Type::Int32Ty, Idx) }; - return B.CreateGEP(BasePtr, Indices, Indices + 2, Name); + Value *Val = B.CreateGEP(BasePtr, Indices, Indices + 2, Name); + + assert(isa(Val) && "Unexpected folded constant"); + + return dyn_cast(Val); } /// runOnFunction - Insert code to maintain the shadow stack. @@ -371,7 +379,7 @@ bool ShadowStackCollector::performCustomLowering(Function &F) { // Build the shadow stack entry at the very start of the function. BasicBlock::iterator IP = F.getEntryBlock().begin(); - LLVMBuilder AtEntry(IP->getParent(), IP); + IRBuilder AtEntry(IP->getParent(), IP); Instruction *StackEntry = AtEntry.CreateAlloca(ConcreteStackEntryTy, 0, "gc_frame"); @@ -409,7 +417,7 @@ bool ShadowStackCollector::performCustomLowering(Function &F) { // For each instruction that escapes... EscapeEnumerator EE(F, "gc_cleanup"); - while (LLVMBuilder *AtExit = EE.Next()) { + 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, -- cgit v1.2.3