mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-11-02 07:11:49 +00:00
Add CreateLifetimeStart and CreateLifetimeEnd to the IRBuilder, with plans to
use these soon. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@131812 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
d22920aae8
commit
0cf51561ed
@ -107,6 +107,10 @@ public:
|
||||
I->setDebugLoc(CurDbgLocation);
|
||||
}
|
||||
|
||||
/// getCurrentFunctionReturnType - Get the return type of the current function
|
||||
/// that we're emitting into.
|
||||
const Type *getCurrentFunctionReturnType() const;
|
||||
|
||||
/// InsertPoint - A saved insertion point.
|
||||
class InsertPoint {
|
||||
BasicBlock *Block;
|
||||
@ -195,6 +199,7 @@ public:
|
||||
return ConstantInt::get(getInt64Ty(), C);
|
||||
}
|
||||
|
||||
/// getInt - Get a constant integer value.
|
||||
ConstantInt *getInt(const APInt &AI) {
|
||||
return ConstantInt::get(Context, AI);
|
||||
}
|
||||
@ -247,10 +252,10 @@ public:
|
||||
return Type::getInt8PtrTy(Context, AddrSpace);
|
||||
}
|
||||
|
||||
/// getCurrentFunctionReturnType - Get the return type of the current function
|
||||
/// that we're emitting into.
|
||||
const Type *getCurrentFunctionReturnType() const;
|
||||
|
||||
//===--------------------------------------------------------------------===//
|
||||
// Intrinsic creation methods
|
||||
//===--------------------------------------------------------------------===//
|
||||
|
||||
/// CreateMemSet - Create and insert a memset to the specified pointer and the
|
||||
/// specified value. If the pointer isn't an i8*, it will be converted. If a
|
||||
/// TBAA tag is specified, it will be added to the instruction.
|
||||
@ -283,6 +288,15 @@ public:
|
||||
|
||||
CallInst *CreateMemMove(Value *Dst, Value *Src, Value *Size, unsigned Align,
|
||||
bool isVolatile = false, MDNode *TBAATag = 0);
|
||||
|
||||
/// CreateLifetimeStart - Create a lifetime.start intrinsic. If the pointer
|
||||
/// isn't i8* it will be converted.
|
||||
CallInst *CreateLifetimeStart(Value *Ptr, ConstantInt *Size = 0);
|
||||
|
||||
/// CreateLifetimeEnd - Create a lifetime.end intrinsic. If the pointer isn't
|
||||
/// i8* it will be converted.
|
||||
CallInst *CreateLifetimeEnd(Value *Ptr, ConstantInt *Size = 0);
|
||||
|
||||
private:
|
||||
Value *getCastedInt8PtrValue(Value *Ptr);
|
||||
};
|
||||
|
@ -60,7 +60,6 @@ static CallInst *createCallHelper(Value *Callee, Value *const* Ops,
|
||||
return CI;
|
||||
}
|
||||
|
||||
|
||||
CallInst *IRBuilderBase::
|
||||
CreateMemSet(Value *Ptr, Value *Val, Value *Size, unsigned Align,
|
||||
bool isVolatile, MDNode *TBAATag) {
|
||||
@ -118,3 +117,33 @@ CreateMemMove(Value *Dst, Value *Src, Value *Size, unsigned Align,
|
||||
|
||||
return CI;
|
||||
}
|
||||
|
||||
CallInst *IRBuilderBase::CreateLifetimeStart(Value *Ptr, ConstantInt *Size) {
|
||||
assert(isa<PointerType>(Ptr->getType()) &&
|
||||
"lifetime.start only applies to pointers.");
|
||||
Ptr = getCastedInt8PtrValue(Ptr);
|
||||
if (!Size)
|
||||
Size = getInt64(-1);
|
||||
else
|
||||
assert(Size->getType() == getInt64Ty() &&
|
||||
"lifetime.start requires the size to be an i64");
|
||||
Value *Ops[] = { Size, Ptr };
|
||||
Module *M = BB->getParent()->getParent();
|
||||
Value *TheFn = Intrinsic::getDeclaration(M, Intrinsic::lifetime_start);
|
||||
return createCallHelper(TheFn, Ops, 2, this);
|
||||
}
|
||||
|
||||
CallInst *IRBuilderBase::CreateLifetimeEnd(Value *Ptr, ConstantInt *Size) {
|
||||
assert(isa<PointerType>(Ptr->getType()) &&
|
||||
"lifetime.end only applies to pointers.");
|
||||
Ptr = getCastedInt8PtrValue(Ptr);
|
||||
if (!Size)
|
||||
Size = getInt64(-1);
|
||||
else
|
||||
assert(Size->getType() == getInt64Ty() &&
|
||||
"lifetime.end requires the size to be an i64");
|
||||
Value *Ops[] = { Size, Ptr };
|
||||
Module *M = BB->getParent()->getParent();
|
||||
Value *TheFn = Intrinsic::getDeclaration(M, Intrinsic::lifetime_end);
|
||||
return createCallHelper(TheFn, Ops, 2, this);
|
||||
}
|
||||
|
70
unittests/Support/IRBuilderTest.cpp
Normal file
70
unittests/Support/IRBuilderTest.cpp
Normal file
@ -0,0 +1,70 @@
|
||||
//===- llvm/unittest/Support/IRBuilderTest.cpp - IRBuilder tests ----------===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "llvm/Support/IRBuilder.h"
|
||||
#include "llvm/BasicBlock.h"
|
||||
#include "llvm/Function.h"
|
||||
#include "llvm/IntrinsicInst.h"
|
||||
#include "llvm/LLVMContext.h"
|
||||
#include "llvm/Module.h"
|
||||
#include "llvm/ADT/OwningPtr.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace llvm;
|
||||
|
||||
class IRBuilderTest : public testing::Test {
|
||||
protected:
|
||||
virtual void SetUp() {
|
||||
M.reset(new Module("MyModule", getGlobalContext()));
|
||||
FunctionType *FTy = FunctionType::get(Type::getVoidTy(getGlobalContext()),
|
||||
/*isVarArg=*/false);
|
||||
Function *F = Function::Create(FTy, Function::ExternalLinkage, "", M.get());
|
||||
BB = BasicBlock::Create(getGlobalContext(), "", F);
|
||||
}
|
||||
|
||||
virtual void TearDown() {
|
||||
BB = 0;
|
||||
M.reset();
|
||||
}
|
||||
|
||||
OwningPtr<Module> M;
|
||||
BasicBlock *BB;
|
||||
};
|
||||
|
||||
TEST_F(IRBuilderTest, Lifetime) {
|
||||
IRBuilder<> Builder(BB);
|
||||
AllocaInst *Var1 = Builder.CreateAlloca(Builder.getInt8Ty());
|
||||
AllocaInst *Var2 = Builder.CreateAlloca(Builder.getInt32Ty());
|
||||
AllocaInst *Var3 = Builder.CreateAlloca(Builder.getInt8Ty(),
|
||||
Builder.getInt32(123));
|
||||
|
||||
CallInst *Start1 = Builder.CreateLifetimeStart(Var1);
|
||||
CallInst *Start2 = Builder.CreateLifetimeStart(Var2);
|
||||
CallInst *Start3 = Builder.CreateLifetimeStart(Var3, Builder.getInt64(100));
|
||||
|
||||
EXPECT_EQ(Start1->getArgOperand(0), Builder.getInt64(-1));
|
||||
EXPECT_EQ(Start2->getArgOperand(0), Builder.getInt64(-1));
|
||||
EXPECT_EQ(Start3->getArgOperand(0), Builder.getInt64(100));
|
||||
|
||||
EXPECT_EQ(Start1->getArgOperand(1), Var1);
|
||||
EXPECT_NE(Start2->getArgOperand(1), Var2);
|
||||
EXPECT_EQ(Start3->getArgOperand(1), Var3);
|
||||
|
||||
Value *End1 = Builder.CreateLifetimeEnd(Var1);
|
||||
Builder.CreateLifetimeEnd(Var2);
|
||||
Builder.CreateLifetimeEnd(Var3);
|
||||
|
||||
IntrinsicInst *II_Start1 = dyn_cast<IntrinsicInst>(Start1);
|
||||
IntrinsicInst *II_End1 = dyn_cast<IntrinsicInst>(End1);
|
||||
ASSERT_TRUE(II_Start1 != NULL);
|
||||
EXPECT_EQ(II_Start1->getIntrinsicID(), Intrinsic::lifetime_start);
|
||||
ASSERT_TRUE(II_End1 != NULL);
|
||||
EXPECT_EQ(II_End1->getIntrinsicID(), Intrinsic::lifetime_end);
|
||||
}
|
Loading…
Reference in New Issue
Block a user