mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-06 11:19:09 +00:00
Improve llvm.dbg.declare intrinsic by referring directly to the storage in its first argument, via function-local metadata (instead of via a bitcast).
This patch also cleans up code that expects there to be a bitcast in the first argument and testcases that call llvm.dbg.declare. llvm-svn: 93504
This commit is contained in:
parent
b4484a2bab
commit
aee71b4e81
@ -491,7 +491,6 @@ namespace llvm {
|
|||||||
Module &M;
|
Module &M;
|
||||||
LLVMContext& VMContext;
|
LLVMContext& VMContext;
|
||||||
|
|
||||||
const Type *EmptyStructPtr; // "{}*".
|
|
||||||
Function *DeclareFn; // llvm.dbg.declare
|
Function *DeclareFn; // llvm.dbg.declare
|
||||||
Function *ValueFn; // llvm.dbg.value
|
Function *ValueFn; // llvm.dbg.value
|
||||||
|
|
||||||
@ -659,7 +658,7 @@ namespace llvm {
|
|||||||
|
|
||||||
/// Finds the dbg.declare intrinsic corresponding to this value if any.
|
/// Finds the dbg.declare intrinsic corresponding to this value if any.
|
||||||
/// It looks through pointer casts too.
|
/// It looks through pointer casts too.
|
||||||
const DbgDeclareInst *findDbgDeclare(const Value *V, bool stripCasts = true);
|
const DbgDeclareInst *findDbgDeclare(const Value *V);
|
||||||
|
|
||||||
/// Find the debug info descriptor corresponding to this global variable.
|
/// Find the debug info descriptor corresponding to this global variable.
|
||||||
Value *findDbgGlobalDeclare(GlobalVariable *V);
|
Value *findDbgGlobalDeclare(GlobalVariable *V);
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
#define LLVM_INTRINSICINST_H
|
#define LLVM_INTRINSICINST_H
|
||||||
|
|
||||||
#include "llvm/Constants.h"
|
#include "llvm/Constants.h"
|
||||||
|
#include "llvm/Metadata.h"
|
||||||
#include "llvm/Function.h"
|
#include "llvm/Function.h"
|
||||||
#include "llvm/Instructions.h"
|
#include "llvm/Instructions.h"
|
||||||
#include "llvm/Intrinsics.h"
|
#include "llvm/Intrinsics.h"
|
||||||
@ -82,7 +83,12 @@ namespace llvm {
|
|||||||
///
|
///
|
||||||
class DbgDeclareInst : public DbgInfoIntrinsic {
|
class DbgDeclareInst : public DbgInfoIntrinsic {
|
||||||
public:
|
public:
|
||||||
Value *getAddress() const { return getOperand(1); }
|
Value *getAddress() const {
|
||||||
|
if (MDNode* MD = dyn_cast<MDNode>(getOperand(1)))
|
||||||
|
return MD->getOperand(0);
|
||||||
|
else
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
MDNode *getVariable() const { return cast<MDNode>(getOperand(2)); }
|
MDNode *getVariable() const { return cast<MDNode>(getOperand(2)); }
|
||||||
|
|
||||||
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
// Methods for support type inquiry through isa, cast, and dyn_cast:
|
||||||
|
@ -283,7 +283,7 @@ let Properties = [IntrNoMem] in {
|
|||||||
// places.
|
// places.
|
||||||
let Properties = [IntrNoMem] in {
|
let Properties = [IntrNoMem] in {
|
||||||
def int_dbg_declare : Intrinsic<[llvm_void_ty],
|
def int_dbg_declare : Intrinsic<[llvm_void_ty],
|
||||||
[llvm_descriptor_ty, llvm_metadata_ty]>;
|
[llvm_metadata_ty, llvm_metadata_ty]>;
|
||||||
def int_dbg_value : Intrinsic<[llvm_void_ty],
|
def int_dbg_value : Intrinsic<[llvm_void_ty],
|
||||||
[llvm_metadata_ty, llvm_i64_ty,
|
[llvm_metadata_ty, llvm_i64_ty,
|
||||||
llvm_metadata_ty]>;
|
llvm_metadata_ty]>;
|
||||||
|
@ -599,9 +599,7 @@ void DIVariable::dump() const {
|
|||||||
//===----------------------------------------------------------------------===//
|
//===----------------------------------------------------------------------===//
|
||||||
|
|
||||||
DIFactory::DIFactory(Module &m)
|
DIFactory::DIFactory(Module &m)
|
||||||
: M(m), VMContext(M.getContext()), DeclareFn(0) {
|
: M(m), VMContext(M.getContext()), DeclareFn(0) {}
|
||||||
EmptyStructPtr = PointerType::getUnqual(StructType::get(VMContext));
|
|
||||||
}
|
|
||||||
|
|
||||||
Constant *DIFactory::GetTagConstant(unsigned TAG) {
|
Constant *DIFactory::GetTagConstant(unsigned TAG) {
|
||||||
assert((TAG & LLVMDebugVersionMask) == 0 &&
|
assert((TAG & LLVMDebugVersionMask) == 0 &&
|
||||||
@ -1034,26 +1032,22 @@ DILocation DIFactory::CreateLocation(unsigned LineNo, unsigned ColumnNo,
|
|||||||
/// InsertDeclare - Insert a new llvm.dbg.declare intrinsic call.
|
/// InsertDeclare - Insert a new llvm.dbg.declare intrinsic call.
|
||||||
Instruction *DIFactory::InsertDeclare(Value *Storage, DIVariable D,
|
Instruction *DIFactory::InsertDeclare(Value *Storage, DIVariable D,
|
||||||
Instruction *InsertBefore) {
|
Instruction *InsertBefore) {
|
||||||
// Cast the storage to a {}* for the call to llvm.dbg.declare.
|
|
||||||
Storage = new BitCastInst(Storage, EmptyStructPtr, "", InsertBefore);
|
|
||||||
|
|
||||||
if (!DeclareFn)
|
if (!DeclareFn)
|
||||||
DeclareFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_declare);
|
DeclareFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_declare);
|
||||||
|
|
||||||
Value *Args[] = { Storage, D.getNode() };
|
Value *Elts[] = { Storage };
|
||||||
|
Value *Args[] = { MDNode::get(Storage->getContext(), Elts, 1), D.getNode() };
|
||||||
return CallInst::Create(DeclareFn, Args, Args+2, "", InsertBefore);
|
return CallInst::Create(DeclareFn, Args, Args+2, "", InsertBefore);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// InsertDeclare - Insert a new llvm.dbg.declare intrinsic call.
|
/// InsertDeclare - Insert a new llvm.dbg.declare intrinsic call.
|
||||||
Instruction *DIFactory::InsertDeclare(Value *Storage, DIVariable D,
|
Instruction *DIFactory::InsertDeclare(Value *Storage, DIVariable D,
|
||||||
BasicBlock *InsertAtEnd) {
|
BasicBlock *InsertAtEnd) {
|
||||||
// Cast the storage to a {}* for the call to llvm.dbg.declare.
|
|
||||||
Storage = new BitCastInst(Storage, EmptyStructPtr, "", InsertAtEnd);
|
|
||||||
|
|
||||||
if (!DeclareFn)
|
if (!DeclareFn)
|
||||||
DeclareFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_declare);
|
DeclareFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_declare);
|
||||||
|
|
||||||
Value *Args[] = { Storage, D.getNode() };
|
Value *Elts[] = { Storage };
|
||||||
|
Value *Args[] = { MDNode::get(Storage->getContext(), Elts, 1), D.getNode() };
|
||||||
return CallInst::Create(DeclareFn, Args, Args+2, "", InsertAtEnd);
|
return CallInst::Create(DeclareFn, Args, Args+2, "", InsertAtEnd);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1258,25 +1252,24 @@ Value *llvm::findDbgGlobalDeclare(GlobalVariable *V) {
|
|||||||
|
|
||||||
/// Finds the llvm.dbg.declare intrinsic corresponding to this value if any.
|
/// Finds the llvm.dbg.declare intrinsic corresponding to this value if any.
|
||||||
/// It looks through pointer casts too.
|
/// It looks through pointer casts too.
|
||||||
const DbgDeclareInst *llvm::findDbgDeclare(const Value *V, bool stripCasts) {
|
const DbgDeclareInst *llvm::findDbgDeclare(const Value *V) {
|
||||||
if (stripCasts) {
|
V = V->stripPointerCasts();
|
||||||
V = V->stripPointerCasts();
|
|
||||||
|
|
||||||
// Look for the bitcast.
|
if (!isa<Instruction>(V) && !isa<Argument>(V))
|
||||||
for (Value::use_const_iterator I = V->use_begin(), E =V->use_end();
|
|
||||||
I != E; ++I)
|
|
||||||
if (isa<BitCastInst>(I)) {
|
|
||||||
const DbgDeclareInst *DDI = findDbgDeclare(*I, false);
|
|
||||||
if (DDI) return DDI;
|
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
|
|
||||||
// Find llvm.dbg.declare among uses of the instruction.
|
const Function *F = NULL;
|
||||||
for (Value::use_const_iterator I = V->use_begin(), E =V->use_end();
|
if (const Instruction *I = dyn_cast<Instruction>(V))
|
||||||
I != E; ++I)
|
F = I->getParent()->getParent();
|
||||||
if (const DbgDeclareInst *DDI = dyn_cast<DbgDeclareInst>(I))
|
else if (const Argument *A = dyn_cast<Argument>(V))
|
||||||
return DDI;
|
F = A->getParent();
|
||||||
|
|
||||||
|
for (Function::const_iterator FI = F->begin(), FE = F->end(); FI != FE; ++FI)
|
||||||
|
for (BasicBlock::const_iterator BI = (*FI).begin(), BE = (*FI).end();
|
||||||
|
BI != BE; ++BI)
|
||||||
|
if (const DbgDeclareInst *DDI = dyn_cast<DbgDeclareInst>(BI))
|
||||||
|
if (DDI->getAddress() == V)
|
||||||
|
return DDI;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -332,8 +332,6 @@ bool FastISel::SelectCall(User *I) {
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
Value *Address = DI->getAddress();
|
Value *Address = DI->getAddress();
|
||||||
if (BitCastInst *BCI = dyn_cast<BitCastInst>(Address))
|
|
||||||
Address = BCI->getOperand(0);
|
|
||||||
AllocaInst *AI = dyn_cast<AllocaInst>(Address);
|
AllocaInst *AI = dyn_cast<AllocaInst>(Address);
|
||||||
// Don't handle byval struct arguments or VLAs, for example.
|
// Don't handle byval struct arguments or VLAs, for example.
|
||||||
if (!AI) break;
|
if (!AI) break;
|
||||||
|
@ -1590,9 +1590,10 @@ void Verifier::visitIntrinsicFunctionCall(Intrinsic::ID ID, CallInst &CI) {
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
case Intrinsic::dbg_declare: // llvm.dbg.declare
|
case Intrinsic::dbg_declare: // llvm.dbg.declare
|
||||||
if (Constant *C = dyn_cast<Constant>(CI.getOperand(1)))
|
if (MDNode *MD = dyn_cast<MDNode>(CI.getOperand(1)))
|
||||||
Assert1(C && !isa<ConstantPointerNull>(C),
|
if (Constant *C = dyn_cast<Constant>(MD->getOperand(0)))
|
||||||
"invalid llvm.dbg.declare intrinsic call", &CI);
|
Assert1(C && !isa<ConstantPointerNull>(C),
|
||||||
|
"invalid llvm.dbg.declare intrinsic call", &CI);
|
||||||
break;
|
break;
|
||||||
case Intrinsic::memcpy:
|
case Intrinsic::memcpy:
|
||||||
case Intrinsic::memmove:
|
case Intrinsic::memmove:
|
||||||
|
@ -5,23 +5,21 @@ entry:
|
|||||||
%0 = add i32 %a, 1 ; <i32> [#uses=1]
|
%0 = add i32 %a, 1 ; <i32> [#uses=1]
|
||||||
%two = add i32 %b, %0 ; <i32> [#uses=0]
|
%two = add i32 %b, %0 ; <i32> [#uses=0]
|
||||||
%1 = alloca i32 ; <i32*> [#uses=1]
|
%1 = alloca i32 ; <i32*> [#uses=1]
|
||||||
%three = bitcast i32* %1 to { }* ; <{ }*> [#uses=6]
|
|
||||||
|
|
||||||
call void @llvm.dbg.declare({ }* %three, metadata !{i32* %1})
|
call void @llvm.dbg.declare(metadata !{i32* %1}, metadata !{i32* %1})
|
||||||
; CHECK: metadata !{i32* %1}
|
; CHECK: metadata !{i32* %1}, metadata !{i32* %1}
|
||||||
call void @llvm.dbg.declare({ }* %three, metadata !{{ }* %three})
|
call void @llvm.dbg.declare(metadata !{i32 %two}, metadata !{i32 %0})
|
||||||
call void @llvm.dbg.declare({ }* %three, metadata !{i32 %0})
|
call void @llvm.dbg.declare(metadata !{i32 %0}, metadata !{i32* %1, i32 %0})
|
||||||
call void @llvm.dbg.declare({ }* %three, metadata !{{ }* %three, i32 %0})
|
call void @llvm.dbg.declare(metadata !{i32* %1}, metadata !{i32 %b, i32 %0})
|
||||||
call void @llvm.dbg.declare({ }* %three, metadata !{i32 %b, i32 %0})
|
call void @llvm.dbg.declare(metadata !{i32 %a}, metadata !{i32 %a, metadata !"foo"})
|
||||||
call void @llvm.dbg.declare({ }* %three, metadata !{i32 %a, metadata !"foo"})
|
|
||||||
; CHECK: metadata !{i32 %a, metadata !"foo"}
|
; CHECK: metadata !{i32 %a, metadata !"foo"}
|
||||||
call void @llvm.dbg.declare({ }* %three, metadata !{metadata !0, i32 %two})
|
call void @llvm.dbg.declare(metadata !{i32 %b}, metadata !{metadata !0, i32 %two})
|
||||||
|
|
||||||
call void @llvm.dbg.value(metadata !{ i32 %a }, i64 0, metadata !1)
|
call void @llvm.dbg.value(metadata !{ i32 %a }, i64 0, metadata !1)
|
||||||
call void @llvm.dbg.value(metadata !{ i32 %0 }, i64 25, metadata !0)
|
call void @llvm.dbg.value(metadata !{ i32 %0 }, i64 25, metadata !0)
|
||||||
call void @llvm.dbg.value(metadata !{ i32* %1 }, i64 16, metadata !"foo")
|
call void @llvm.dbg.value(metadata !{ i32* %1 }, i64 16, metadata !"foo")
|
||||||
; CHECK: call void @llvm.dbg.value(metadata !{i32* %1}, i64 16, metadata !"foo")
|
; CHECK: call void @llvm.dbg.value(metadata !{i32* %1}, i64 16, metadata !"foo")
|
||||||
call void @llvm.dbg.value(metadata !{ { }* %three }, i64 12, metadata !"bar")
|
call void @llvm.dbg.value(metadata !"foo", i64 12, metadata !"bar")
|
||||||
|
|
||||||
ret void, !foo !0, !bar !1
|
ret void, !foo !0, !bar !1
|
||||||
; CHECK: ret void, !foo !0, !bar !1
|
; CHECK: ret void, !foo !0, !bar !1
|
||||||
@ -30,7 +28,7 @@ entry:
|
|||||||
!0 = metadata !{i32 662302, i32 26, metadata !1, null}
|
!0 = metadata !{i32 662302, i32 26, metadata !1, null}
|
||||||
!1 = metadata !{i32 4, metadata !"foo"}
|
!1 = metadata !{i32 4, metadata !"foo"}
|
||||||
|
|
||||||
declare void @llvm.dbg.declare({ }*, metadata) nounwind readnone
|
declare void @llvm.dbg.declare(metadata, metadata) nounwind readnone
|
||||||
declare void @llvm.dbg.value(metadata, i64, metadata) nounwind readnone
|
declare void @llvm.dbg.value(metadata, i64, metadata) nounwind readnone
|
||||||
|
|
||||||
!foo = !{ !0 }
|
!foo = !{ !0 }
|
||||||
|
@ -9,8 +9,7 @@ entry:
|
|||||||
br label %do.body, !dbg !0
|
br label %do.body, !dbg !0
|
||||||
|
|
||||||
do.body: ; preds = %entry
|
do.body: ; preds = %entry
|
||||||
%0 = bitcast i32* %count_ to { }* ; <{ }*> [#uses=1]
|
call void @llvm.dbg.declare(metadata !{i32* %count_}, metadata !4)
|
||||||
call void @llvm.dbg.declare({ }* %0, metadata !4)
|
|
||||||
%conv = ptrtoint i32* %count_ to i32, !dbg !0 ; <i32> [#uses=1]
|
%conv = ptrtoint i32* %count_ to i32, !dbg !0 ; <i32> [#uses=1]
|
||||||
%call = call i32 @foo(i32 %conv) ssp, !dbg !0 ; <i32> [#uses=0]
|
%call = call i32 @foo(i32 %conv) ssp, !dbg !0 ; <i32> [#uses=0]
|
||||||
br label %do.end, !dbg !0
|
br label %do.end, !dbg !0
|
||||||
@ -19,7 +18,7 @@ do.end: ; preds = %do.body
|
|||||||
ret void, !dbg !7
|
ret void, !dbg !7
|
||||||
}
|
}
|
||||||
|
|
||||||
declare void @llvm.dbg.declare({ }*, metadata) nounwind readnone
|
declare void @llvm.dbg.declare(metadata, metadata) nounwind readnone
|
||||||
|
|
||||||
declare i32 @foo(i32) ssp
|
declare i32 @foo(i32) ssp
|
||||||
|
|
||||||
|
@ -19,11 +19,11 @@ entry:
|
|||||||
call void @llvm.dbg.stoppoint(i32 6, i32 3, metadata !1)
|
call void @llvm.dbg.stoppoint(i32 6, i32 3, metadata !1)
|
||||||
call void @llvm.dbg.stoppoint(i32 7, i32 3, metadata !1)
|
call void @llvm.dbg.stoppoint(i32 7, i32 3, metadata !1)
|
||||||
%0 = bitcast %struct.foo* %b to { }* ; <{ }*> [#uses=1]
|
%0 = bitcast %struct.foo* %b to { }* ; <{ }*> [#uses=1]
|
||||||
call void @llvm.dbg.declare({ }* %0, metadata !4)
|
call void @llvm.dbg.declare(metadata !{%struct.foo* %b}, metadata !4)
|
||||||
; CHECK:; %0 is variable b of type foo declared at x.c:7
|
; CHECK:; %0 is variable b of type foo declared at x.c:7
|
||||||
call void @llvm.dbg.stoppoint(i32 8, i32 3, metadata !1)
|
call void @llvm.dbg.stoppoint(i32 8, i32 3, metadata !1)
|
||||||
%1 = bitcast [4 x i32]* %a to { }* ; <{ }*> [#uses=1]
|
%1 = bitcast [4 x i32]* %a to { }* ; <{ }*> [#uses=1]
|
||||||
call void @llvm.dbg.declare({ }* %1, metadata !8)
|
call void @llvm.dbg.declare(metadata !{[4 x i32]* %a}, metadata !8)
|
||||||
; CHECK:; %1 is variable a of type declared at x.c:8
|
; CHECK:; %1 is variable a of type declared at x.c:8
|
||||||
call void @llvm.dbg.stoppoint(i32 9, i32 3, metadata !1)
|
call void @llvm.dbg.stoppoint(i32 9, i32 3, metadata !1)
|
||||||
%tmp = getelementptr inbounds %struct.foo* %b, i32 0, i32 0 ; <i32*> [#uses=1]
|
%tmp = getelementptr inbounds %struct.foo* %b, i32 0, i32 0 ; <i32*> [#uses=1]
|
||||||
@ -46,7 +46,7 @@ declare void @llvm.dbg.func.start(metadata) nounwind readnone
|
|||||||
|
|
||||||
declare void @llvm.dbg.stoppoint(i32, i32, metadata) nounwind readnone
|
declare void @llvm.dbg.stoppoint(i32, i32, metadata) nounwind readnone
|
||||||
|
|
||||||
declare void @llvm.dbg.declare({ }*, metadata) nounwind readnone
|
declare void @llvm.dbg.declare(metadata, metadata) nounwind readnone
|
||||||
|
|
||||||
declare void @llvm.dbg.region.end(metadata) nounwind readnone
|
declare void @llvm.dbg.region.end(metadata) nounwind readnone
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user