Convert lifetime into a trivial op
MODIFY
llvm_util/llvm2alive.cpp
llvm_util/llvm2alive.cpp
#include "llvm_util/llvm2alive.h"
#include "llvm_util/known_fns.h"
#include "llvm_util/utils.h"
+#include "llvm/Analysis/ValueTracking.h"
#include "llvm/IR/GetElementPtrTypeIterator.h"
#include "llvm/IR/GlobalVariable.h"
#include "llvm/IR/InstVisitor.h"
@@ -569,6 +570,30 @@ public:
RETURN_IDENTIFIER(make_unique<TernaryOp>(*ty, value_name(i), *a, *b, *c,
op));
}
+ case llvm::Intrinsic::lifetime_start:
+ {
+ PARSE_BINOP();
+ if (!llvm::isa<llvm::AllocaInst>(llvm::GetUnderlyingObject(
+ i.getOperand(1), DL())))
+ return error(i);
+ // TODO: a dummy instruction
+ static int lifetime_start_dummy = 0;
+ string name = "__unused_ls_" + to_string(lifetime_start_dummy++);
+ RETURN_IDENTIFIER(make_unique<UnaryOp>(b->getType(), move(name), *b,
+ UnaryOp::Copy));
+ }
+ case llvm::Intrinsic::lifetime_end:
+ {
+ PARSE_BINOP();
+ if (!llvm::isa<llvm::AllocaInst>(llvm::GetUnderlyingObject(
+ i.getOperand(1), DL())))
+ return error(i);
+ // TODO: a dummy instruction
+ static int lifetime_end_dummy = 0;
+ string name = "__unused_le_" + to_string(lifetime_end_dummy++);
+ RETURN_IDENTIFIER(make_unique<UnaryOp>(b->getType(), move(name), *b,
+ UnaryOp::Copy));
+ }
// do nothing intrinsics
case llvm::Intrinsic::dbg_addr:

ADD
tests/alive-tv/memory/lifetime-1.src.ll
+define void @f1() {
+ %p = alloca i32
+ ret void
+}
+
+define i32 @f2() {
+ %p = alloca i32
+ store i32 10, i32* %p
+ %v = load i32, i32* %p
+ ret i32 %v
+}

ADD
tests/alive-tv/memory/lifetime-1.tgt.ll
+declare void @llvm.lifetime.start.p0i8(i64, i8*)
+declare void @llvm.lifetime.end.p0i8(i64, i8*)
+
+define void @f1() {
+ %p = alloca i32
+ %p0 = bitcast i32* %p to i8*
+ call void @llvm.lifetime.start.p0i8(i64 4, i8* %p0)
+ call void @llvm.lifetime.end.p0i8(i64 4, i8* %p0)
+ ret void
+}
+
+define i32 @f2() {
+ %p = alloca i32
+ %p0 = bitcast i32* %p to i8*
+ call void @llvm.lifetime.start.p0i8(i64 4, i8* %p0)
+ store i32 10, i32* %p
+ %v = load i32, i32* %p
+ call void @llvm.lifetime.end.p0i8(i64 4, i8* %p0)
+ ret i32 %v
+}
+

Convert lifetime into a trivial op (#238)