2017-05-06 06:30:37 +08:00
|
|
|
//===- DebugInfo.cpp - Debug Information Helper Classes -------------------===//
|
2013-11-08 16:13:15 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file implements the helper classes used to build and interpret debug
|
|
|
|
// information in LLVM IR form.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2017-11-02 06:18:52 +08:00
|
|
|
#include "llvm-c/DebugInfo.h"
|
2017-05-06 06:30:37 +08:00
|
|
|
#include "llvm/ADT/DenseMap.h"
|
|
|
|
#include "llvm/ADT/DenseSet.h"
|
|
|
|
#include "llvm/ADT/None.h"
|
2017-11-02 06:18:52 +08:00
|
|
|
#include "llvm/ADT/STLExtras.h"
|
2013-11-08 16:13:15 +08:00
|
|
|
#include "llvm/ADT/SmallPtrSet.h"
|
2017-05-06 06:30:37 +08:00
|
|
|
#include "llvm/ADT/SmallVector.h"
|
|
|
|
#include "llvm/ADT/StringRef.h"
|
|
|
|
#include "llvm/IR/BasicBlock.h"
|
2013-11-08 16:13:15 +08:00
|
|
|
#include "llvm/IR/Constants.h"
|
2017-05-06 06:30:37 +08:00
|
|
|
#include "llvm/IR/DebugInfoMetadata.h"
|
|
|
|
#include "llvm/IR/DebugLoc.h"
|
2017-11-02 06:18:52 +08:00
|
|
|
#include "llvm/IR/DebugInfo.h"
|
|
|
|
#include "llvm/IR/DIBuilder.h"
|
2017-05-06 06:30:37 +08:00
|
|
|
#include "llvm/IR/Function.h"
|
2016-04-18 17:17:29 +08:00
|
|
|
#include "llvm/IR/GVMaterializer.h"
|
2017-05-06 06:30:37 +08:00
|
|
|
#include "llvm/IR/Instruction.h"
|
2013-11-08 16:13:15 +08:00
|
|
|
#include "llvm/IR/IntrinsicInst.h"
|
2017-05-06 06:30:37 +08:00
|
|
|
#include "llvm/IR/LLVMContext.h"
|
|
|
|
#include "llvm/IR/Metadata.h"
|
2013-11-08 16:13:15 +08:00
|
|
|
#include "llvm/IR/Module.h"
|
2017-05-06 06:30:37 +08:00
|
|
|
#include "llvm/Support/Casting.h"
|
|
|
|
#include <algorithm>
|
|
|
|
#include <cassert>
|
|
|
|
#include <utility>
|
|
|
|
|
2013-11-08 16:13:15 +08:00
|
|
|
using namespace llvm;
|
|
|
|
using namespace llvm::dwarf;
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
DISubprogram *llvm::getDISubprogram(const MDNode *Scope) {
|
|
|
|
if (auto *LocalScope = dyn_cast_or_null<DILocalScope>(Scope))
|
2015-03-31 10:06:28 +08:00
|
|
|
return LocalScope->getSubprogram();
|
|
|
|
return nullptr;
|
2013-11-08 16:13:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// DebugInfoFinder implementations.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
void DebugInfoFinder::reset() {
|
|
|
|
CUs.clear();
|
|
|
|
SPs.clear();
|
|
|
|
GVs.clear();
|
|
|
|
TYs.clear();
|
|
|
|
Scopes.clear();
|
|
|
|
NodesSeen.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DebugInfoFinder::processModule(const Module &M) {
|
2018-04-14 05:23:11 +08:00
|
|
|
for (auto *CU : M.debug_compile_units())
|
|
|
|
processCompileUnit(CU);
|
2017-04-11 21:32:11 +08:00
|
|
|
for (auto &F : M.functions()) {
|
2016-04-15 23:57:41 +08:00
|
|
|
if (auto *SP = cast_or_null<DISubprogram>(F.getSubprogram()))
|
|
|
|
processSubprogram(SP);
|
2017-04-11 21:32:11 +08:00
|
|
|
// There could be subprograms from inlined functions referenced from
|
|
|
|
// instructions only. Walk the function to find them.
|
2018-04-14 05:23:11 +08:00
|
|
|
for (const BasicBlock &BB : F)
|
|
|
|
for (const Instruction &I : BB)
|
|
|
|
processInstruction(M, I);
|
2017-04-11 21:32:11 +08:00
|
|
|
}
|
2013-11-08 16:13:15 +08:00
|
|
|
}
|
|
|
|
|
[DebugInfo][OPT] Fixing a couple of DI duplication bugs of CloneModule
As demonstrated by the regression tests added in this patch, the
following cases are valid cases:
1. A Function with no DISubprogram attached, but various debug info
related to its instructions, coming, for instance, from an inlined
function, also defined somewhere else in the same module;
2. ... or coming exclusively from the functions inlined and eliminated
from the module entirely.
The ValueMap shared between CloneFunctionInto calls within CloneModule
needs to contain identity mappings for all of the DISubprogram's to
prevent them from being duplicated by MapMetadata / RemapInstruction
calls, this is achieved via DebugInfoFinder collecting all the
DISubprogram's. However, CloneFunctionInto was missing calls into
DebugInfoFinder for functions w/o DISubprogram's attached, but still
referring DISubprogram's from within (case 1). This patch fixes that.
The fix above, however, exposes another issue: if a module contains a
DISubprogram referenced only indirectly from other debug info
metadata, but not attached to any Function defined within the module
(case 2), cloning such a module causes a DICompileUnit duplication: it
will be moved in indirecty via a DISubprogram by DebugInfoFinder first
(because of the first bug fix described above), without being
self-mapped within the shared ValueMap, and then will be copied during
named metadata cloning. So this patch makes sure DebugInfoFinder
visits DICompileUnit's referenced from DISubprogram's as it goes w/o
re-processing llvm.dbg.cu list over and over again for every function
cloned, and makes sure that CloneFunctionInto self-maps
DICompileUnit's referenced from the entire function, not just its own
DISubprogram attached that may also be missing.
The most convenient way of tesing CloneModule I found is to rely on
CloneModule call from `opt -run-twice`, instead of writing tedious
unit tests. That feature has a couple of properties that makes it hard
to use for this purpose though:
1. CloneModule doesn't copy source filename, making `opt -run-twice`
report it as a difference.
2. `opt -run-twice` does the second run on the original module, not
its clone, making the result of cloning completely invisible in opt's
actual output with and without `-run-twice` both, which directly
contradicts `opt -run-twice`s own error message.
This patch fixes this as well.
Reviewed By: aprantl
Reviewers: loladiro, GorNishanov, espindola, echristo, dexonsmith
Subscribers: vsk, debug-info, JDevlieghere, llvm-commits
Differential Revision: https://reviews.llvm.org/D45593
llvm-svn: 330069
2018-04-14 05:22:24 +08:00
|
|
|
void DebugInfoFinder::processCompileUnit(DICompileUnit *CU) {
|
|
|
|
if (!addCompileUnit(CU))
|
|
|
|
return;
|
|
|
|
for (auto DIG : CU->getGlobalVariables()) {
|
|
|
|
if (!addGlobalVariable(DIG))
|
|
|
|
continue;
|
|
|
|
auto *GV = DIG->getVariable();
|
|
|
|
processScope(GV->getScope());
|
|
|
|
processType(GV->getType().resolve());
|
|
|
|
}
|
|
|
|
for (auto *ET : CU->getEnumTypes())
|
|
|
|
processType(ET);
|
|
|
|
for (auto *RT : CU->getRetainedTypes())
|
|
|
|
if (auto *T = dyn_cast<DIType>(RT))
|
|
|
|
processType(T);
|
|
|
|
else
|
|
|
|
processSubprogram(cast<DISubprogram>(RT));
|
|
|
|
for (auto *Import : CU->getImportedEntities()) {
|
|
|
|
auto *Entity = Import->getEntity().resolve();
|
|
|
|
if (auto *T = dyn_cast<DIType>(Entity))
|
|
|
|
processType(T);
|
|
|
|
else if (auto *SP = dyn_cast<DISubprogram>(Entity))
|
|
|
|
processSubprogram(SP);
|
|
|
|
else if (auto *NS = dyn_cast<DINamespace>(Entity))
|
|
|
|
processScope(NS->getScope());
|
|
|
|
else if (auto *M = dyn_cast<DIModule>(Entity))
|
|
|
|
processScope(M->getScope());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-14 05:23:11 +08:00
|
|
|
void DebugInfoFinder::processInstruction(const Module &M,
|
|
|
|
const Instruction &I) {
|
|
|
|
if (auto *DDI = dyn_cast<DbgDeclareInst>(&I))
|
|
|
|
processDeclare(M, DDI);
|
|
|
|
else if (auto *DVI = dyn_cast<DbgValueInst>(&I))
|
|
|
|
processValue(M, DVI);
|
|
|
|
|
|
|
|
if (auto DbgLoc = I.getDebugLoc())
|
|
|
|
processLocation(M, DbgLoc.get());
|
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
void DebugInfoFinder::processLocation(const Module &M, const DILocation *Loc) {
|
2013-11-08 16:13:15 +08:00
|
|
|
if (!Loc)
|
|
|
|
return;
|
2015-04-14 09:35:55 +08:00
|
|
|
processScope(Loc->getScope());
|
|
|
|
processLocation(M, Loc->getInlinedAt());
|
2013-11-08 16:13:15 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
void DebugInfoFinder::processType(DIType *DT) {
|
2013-11-08 16:13:15 +08:00
|
|
|
if (!addType(DT))
|
|
|
|
return;
|
2016-04-24 05:08:00 +08:00
|
|
|
processScope(DT->getScope().resolve());
|
2015-07-25 04:56:10 +08:00
|
|
|
if (auto *ST = dyn_cast<DISubroutineType>(DT)) {
|
|
|
|
for (DITypeRef Ref : ST->getTypeArray())
|
2016-04-24 05:08:00 +08:00
|
|
|
processType(Ref.resolve());
|
2015-07-25 04:56:10 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (auto *DCT = dyn_cast<DICompositeType>(DT)) {
|
2016-04-24 05:08:00 +08:00
|
|
|
processType(DCT->getBaseType().resolve());
|
2015-04-14 17:18:17 +08:00
|
|
|
for (Metadata *D : DCT->getElements()) {
|
2015-04-30 00:38:44 +08:00
|
|
|
if (auto *T = dyn_cast<DIType>(D))
|
2015-04-07 07:18:49 +08:00
|
|
|
processType(T);
|
2015-04-30 00:38:44 +08:00
|
|
|
else if (auto *SP = dyn_cast<DISubprogram>(D))
|
2015-04-07 07:18:49 +08:00
|
|
|
processSubprogram(SP);
|
2013-11-08 16:13:15 +08:00
|
|
|
}
|
2015-07-25 04:56:10 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (auto *DDT = dyn_cast<DIDerivedType>(DT)) {
|
2016-04-24 05:08:00 +08:00
|
|
|
processType(DDT->getBaseType().resolve());
|
2013-11-08 16:13:15 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
void DebugInfoFinder::processScope(DIScope *Scope) {
|
2015-04-07 07:18:49 +08:00
|
|
|
if (!Scope)
|
|
|
|
return;
|
2015-04-30 00:38:44 +08:00
|
|
|
if (auto *Ty = dyn_cast<DIType>(Scope)) {
|
2013-11-08 16:13:15 +08:00
|
|
|
processType(Ty);
|
|
|
|
return;
|
|
|
|
}
|
2015-04-30 00:38:44 +08:00
|
|
|
if (auto *CU = dyn_cast<DICompileUnit>(Scope)) {
|
2015-04-07 07:18:49 +08:00
|
|
|
addCompileUnit(CU);
|
2013-11-08 16:13:15 +08:00
|
|
|
return;
|
|
|
|
}
|
2015-04-30 00:38:44 +08:00
|
|
|
if (auto *SP = dyn_cast<DISubprogram>(Scope)) {
|
2015-04-07 07:18:49 +08:00
|
|
|
processSubprogram(SP);
|
2013-11-08 16:13:15 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!addScope(Scope))
|
|
|
|
return;
|
2015-04-30 00:38:44 +08:00
|
|
|
if (auto *LB = dyn_cast<DILexicalBlockBase>(Scope)) {
|
2015-04-14 11:40:37 +08:00
|
|
|
processScope(LB->getScope());
|
2015-04-30 00:38:44 +08:00
|
|
|
} else if (auto *NS = dyn_cast<DINamespace>(Scope)) {
|
2015-04-14 11:01:27 +08:00
|
|
|
processScope(NS->getScope());
|
2015-06-30 07:03:47 +08:00
|
|
|
} else if (auto *M = dyn_cast<DIModule>(Scope)) {
|
|
|
|
processScope(M->getScope());
|
2013-11-08 16:13:15 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
void DebugInfoFinder::processSubprogram(DISubprogram *SP) {
|
2013-11-08 16:13:15 +08:00
|
|
|
if (!addSubprogram(SP))
|
|
|
|
return;
|
2016-04-24 05:08:00 +08:00
|
|
|
processScope(SP->getScope().resolve());
|
[DebugInfo][OPT] Fixing a couple of DI duplication bugs of CloneModule
As demonstrated by the regression tests added in this patch, the
following cases are valid cases:
1. A Function with no DISubprogram attached, but various debug info
related to its instructions, coming, for instance, from an inlined
function, also defined somewhere else in the same module;
2. ... or coming exclusively from the functions inlined and eliminated
from the module entirely.
The ValueMap shared between CloneFunctionInto calls within CloneModule
needs to contain identity mappings for all of the DISubprogram's to
prevent them from being duplicated by MapMetadata / RemapInstruction
calls, this is achieved via DebugInfoFinder collecting all the
DISubprogram's. However, CloneFunctionInto was missing calls into
DebugInfoFinder for functions w/o DISubprogram's attached, but still
referring DISubprogram's from within (case 1). This patch fixes that.
The fix above, however, exposes another issue: if a module contains a
DISubprogram referenced only indirectly from other debug info
metadata, but not attached to any Function defined within the module
(case 2), cloning such a module causes a DICompileUnit duplication: it
will be moved in indirecty via a DISubprogram by DebugInfoFinder first
(because of the first bug fix described above), without being
self-mapped within the shared ValueMap, and then will be copied during
named metadata cloning. So this patch makes sure DebugInfoFinder
visits DICompileUnit's referenced from DISubprogram's as it goes w/o
re-processing llvm.dbg.cu list over and over again for every function
cloned, and makes sure that CloneFunctionInto self-maps
DICompileUnit's referenced from the entire function, not just its own
DISubprogram attached that may also be missing.
The most convenient way of tesing CloneModule I found is to rely on
CloneModule call from `opt -run-twice`, instead of writing tedious
unit tests. That feature has a couple of properties that makes it hard
to use for this purpose though:
1. CloneModule doesn't copy source filename, making `opt -run-twice`
report it as a difference.
2. `opt -run-twice` does the second run on the original module, not
its clone, making the result of cloning completely invisible in opt's
actual output with and without `-run-twice` both, which directly
contradicts `opt -run-twice`s own error message.
This patch fixes this as well.
Reviewed By: aprantl
Reviewers: loladiro, GorNishanov, espindola, echristo, dexonsmith
Subscribers: vsk, debug-info, JDevlieghere, llvm-commits
Differential Revision: https://reviews.llvm.org/D45593
llvm-svn: 330069
2018-04-14 05:22:24 +08:00
|
|
|
// Some of the users, e.g. CloneFunctionInto / CloneModule, need to set up a
|
|
|
|
// ValueMap containing identity mappings for all of the DICompileUnit's, not
|
|
|
|
// just DISubprogram's, referenced from anywhere within the Function being
|
|
|
|
// cloned prior to calling MapMetadata / RemapInstruction to avoid their
|
|
|
|
// duplication later as DICompileUnit's are also directly referenced by
|
|
|
|
// llvm.dbg.cu list. Thefore we need to collect DICompileUnit's here as well.
|
|
|
|
// Also, DICompileUnit's may reference DISubprogram's too and therefore need
|
|
|
|
// to be at least looked through.
|
|
|
|
processCompileUnit(SP->getUnit());
|
2015-04-14 11:40:37 +08:00
|
|
|
processType(SP->getType());
|
|
|
|
for (auto *Element : SP->getTemplateParams()) {
|
2015-04-30 00:38:44 +08:00
|
|
|
if (auto *TType = dyn_cast<DITemplateTypeParameter>(Element)) {
|
2016-04-24 05:08:00 +08:00
|
|
|
processType(TType->getType().resolve());
|
2015-04-30 00:38:44 +08:00
|
|
|
} else if (auto *TVal = dyn_cast<DITemplateValueParameter>(Element)) {
|
2016-04-24 05:08:00 +08:00
|
|
|
processType(TVal->getType().resolve());
|
2013-11-08 16:13:15 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-18 02:42:37 +08:00
|
|
|
void DebugInfoFinder::processDeclare(const Module &M,
|
|
|
|
const DbgDeclareInst *DDI) {
|
2015-04-18 07:20:10 +08:00
|
|
|
auto *N = dyn_cast<MDNode>(DDI->getVariable());
|
2013-11-08 16:13:15 +08:00
|
|
|
if (!N)
|
|
|
|
return;
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
auto *DV = dyn_cast<DILocalVariable>(N);
|
2015-04-07 07:18:49 +08:00
|
|
|
if (!DV)
|
2013-11-08 16:13:15 +08:00
|
|
|
return;
|
|
|
|
|
2014-11-19 15:49:26 +08:00
|
|
|
if (!NodesSeen.insert(DV).second)
|
2013-11-08 16:13:15 +08:00
|
|
|
return;
|
2015-04-14 10:22:36 +08:00
|
|
|
processScope(DV->getScope());
|
2016-04-24 05:08:00 +08:00
|
|
|
processType(DV->getType().resolve());
|
2013-11-08 16:13:15 +08:00
|
|
|
}
|
|
|
|
|
2013-11-18 02:42:37 +08:00
|
|
|
void DebugInfoFinder::processValue(const Module &M, const DbgValueInst *DVI) {
|
2015-04-18 07:20:10 +08:00
|
|
|
auto *N = dyn_cast<MDNode>(DVI->getVariable());
|
2013-11-08 16:13:15 +08:00
|
|
|
if (!N)
|
|
|
|
return;
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
auto *DV = dyn_cast<DILocalVariable>(N);
|
2015-04-07 07:18:49 +08:00
|
|
|
if (!DV)
|
2013-11-08 16:13:15 +08:00
|
|
|
return;
|
|
|
|
|
2014-11-19 15:49:26 +08:00
|
|
|
if (!NodesSeen.insert(DV).second)
|
2013-11-08 16:13:15 +08:00
|
|
|
return;
|
2015-04-14 10:22:36 +08:00
|
|
|
processScope(DV->getScope());
|
2016-04-24 05:08:00 +08:00
|
|
|
processType(DV->getType().resolve());
|
2013-11-08 16:13:15 +08:00
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
bool DebugInfoFinder::addType(DIType *DT) {
|
2013-11-08 16:13:15 +08:00
|
|
|
if (!DT)
|
|
|
|
return false;
|
|
|
|
|
2014-11-19 15:49:26 +08:00
|
|
|
if (!NodesSeen.insert(DT).second)
|
2013-11-08 16:13:15 +08:00
|
|
|
return false;
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
TYs.push_back(const_cast<DIType *>(DT));
|
2013-11-08 16:13:15 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
bool DebugInfoFinder::addCompileUnit(DICompileUnit *CU) {
|
2013-11-08 16:13:15 +08:00
|
|
|
if (!CU)
|
|
|
|
return false;
|
2014-11-19 15:49:26 +08:00
|
|
|
if (!NodesSeen.insert(CU).second)
|
2013-11-08 16:13:15 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
CUs.push_back(CU);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-12-20 10:09:43 +08:00
|
|
|
bool DebugInfoFinder::addGlobalVariable(DIGlobalVariableExpression *DIG) {
|
2014-11-19 15:49:26 +08:00
|
|
|
if (!NodesSeen.insert(DIG).second)
|
2013-11-08 16:13:15 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
GVs.push_back(DIG);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
bool DebugInfoFinder::addSubprogram(DISubprogram *SP) {
|
2013-11-08 16:13:15 +08:00
|
|
|
if (!SP)
|
|
|
|
return false;
|
|
|
|
|
2014-11-19 15:49:26 +08:00
|
|
|
if (!NodesSeen.insert(SP).second)
|
2013-11-08 16:13:15 +08:00
|
|
|
return false;
|
|
|
|
|
|
|
|
SPs.push_back(SP);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-04-30 00:38:44 +08:00
|
|
|
bool DebugInfoFinder::addScope(DIScope *Scope) {
|
2013-11-08 16:13:15 +08:00
|
|
|
if (!Scope)
|
|
|
|
return false;
|
|
|
|
// FIXME: Ocaml binding generates a scope with no content, we treat it
|
|
|
|
// as null for now.
|
|
|
|
if (Scope->getNumOperands() == 0)
|
|
|
|
return false;
|
2014-11-19 15:49:26 +08:00
|
|
|
if (!NodesSeen.insert(Scope).second)
|
2013-11-08 16:13:15 +08:00
|
|
|
return false;
|
|
|
|
Scopes.push_back(Scope);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-05-06 06:30:37 +08:00
|
|
|
static MDNode *stripDebugLocFromLoopID(MDNode *N) {
|
2017-01-28 19:22:05 +08:00
|
|
|
assert(N->op_begin() != N->op_end() && "Missing self reference?");
|
|
|
|
|
2017-03-19 21:54:57 +08:00
|
|
|
// if there is no debug location, we do not have to rewrite this MDNode.
|
|
|
|
if (std::none_of(N->op_begin() + 1, N->op_end(), [](const MDOperand &Op) {
|
|
|
|
return isa<DILocation>(Op.get());
|
|
|
|
}))
|
2017-01-28 19:22:05 +08:00
|
|
|
return N;
|
|
|
|
|
2017-03-19 21:54:57 +08:00
|
|
|
// If there is only the debug location without any actual loop metadata, we
|
2017-01-28 19:22:05 +08:00
|
|
|
// can remove the metadata.
|
2017-03-19 21:54:57 +08:00
|
|
|
if (std::none_of(N->op_begin() + 1, N->op_end(), [](const MDOperand &Op) {
|
|
|
|
return !isa<DILocation>(Op.get());
|
|
|
|
}))
|
2017-01-28 19:22:05 +08:00
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
SmallVector<Metadata *, 4> Args;
|
|
|
|
// Reserve operand 0 for loop id self reference.
|
|
|
|
auto TempNode = MDNode::getTemporary(N->getContext(), None);
|
|
|
|
Args.push_back(TempNode.get());
|
2017-03-19 21:54:57 +08:00
|
|
|
// Add all non-debug location operands back.
|
|
|
|
for (auto Op = N->op_begin() + 1; Op != N->op_end(); Op++) {
|
|
|
|
if (!isa<DILocation>(*Op))
|
|
|
|
Args.push_back(*Op);
|
|
|
|
}
|
2017-01-28 19:22:05 +08:00
|
|
|
|
|
|
|
// Set the first operand to itself.
|
|
|
|
MDNode *LoopID = MDNode::get(N->getContext(), Args);
|
|
|
|
LoopID->replaceOperandWith(0, LoopID);
|
|
|
|
return LoopID;
|
|
|
|
}
|
|
|
|
|
2015-03-31 05:36:43 +08:00
|
|
|
bool llvm::stripDebugInfo(Function &F) {
|
|
|
|
bool Changed = false;
|
2018-05-31 21:29:58 +08:00
|
|
|
if (F.hasMetadata(LLVMContext::MD_dbg)) {
|
2015-11-06 06:03:56 +08:00
|
|
|
Changed = true;
|
|
|
|
F.setSubprogram(nullptr);
|
|
|
|
}
|
2016-05-07 12:10:52 +08:00
|
|
|
|
2017-05-06 06:30:37 +08:00
|
|
|
DenseMap<MDNode*, MDNode*> LoopIDsMap;
|
2015-03-31 05:36:43 +08:00
|
|
|
for (BasicBlock &BB : F) {
|
2016-05-07 12:10:52 +08:00
|
|
|
for (auto II = BB.begin(), End = BB.end(); II != End;) {
|
|
|
|
Instruction &I = *II++; // We may delete the instruction, increment now.
|
2016-05-14 12:58:35 +08:00
|
|
|
if (isa<DbgInfoIntrinsic>(&I)) {
|
|
|
|
I.eraseFromParent();
|
2016-05-07 12:10:52 +08:00
|
|
|
Changed = true;
|
2016-05-07 13:07:47 +08:00
|
|
|
continue;
|
2016-05-07 12:10:52 +08:00
|
|
|
}
|
2015-03-31 05:36:43 +08:00
|
|
|
if (I.getDebugLoc()) {
|
|
|
|
Changed = true;
|
|
|
|
I.setDebugLoc(DebugLoc());
|
|
|
|
}
|
|
|
|
}
|
2017-01-28 19:22:05 +08:00
|
|
|
|
|
|
|
auto *TermInst = BB.getTerminator();
|
2017-08-19 05:38:03 +08:00
|
|
|
if (!TermInst)
|
|
|
|
// This is invalid IR, but we may not have run the verifier yet
|
|
|
|
continue;
|
2017-01-28 19:22:05 +08:00
|
|
|
if (auto *LoopID = TermInst->getMetadata(LLVMContext::MD_loop)) {
|
|
|
|
auto *NewLoopID = LoopIDsMap.lookup(LoopID);
|
|
|
|
if (!NewLoopID)
|
|
|
|
NewLoopID = LoopIDsMap[LoopID] = stripDebugLocFromLoopID(LoopID);
|
|
|
|
if (NewLoopID != LoopID)
|
|
|
|
TermInst->setMetadata(LLVMContext::MD_loop, NewLoopID);
|
|
|
|
}
|
2015-03-31 05:36:43 +08:00
|
|
|
}
|
|
|
|
return Changed;
|
|
|
|
}
|
|
|
|
|
2013-11-23 06:06:31 +08:00
|
|
|
bool llvm::StripDebugInfo(Module &M) {
|
|
|
|
bool Changed = false;
|
|
|
|
|
|
|
|
for (Module::named_metadata_iterator NMI = M.named_metadata_begin(),
|
|
|
|
NME = M.named_metadata_end(); NMI != NME;) {
|
2015-10-09 07:49:46 +08:00
|
|
|
NamedMDNode *NMD = &*NMI;
|
2013-11-23 06:06:31 +08:00
|
|
|
++NMI;
|
2016-10-18 04:05:35 +08:00
|
|
|
|
|
|
|
// We're stripping debug info, and without them, coverage information
|
|
|
|
// doesn't quite make sense.
|
|
|
|
if (NMD->getName().startswith("llvm.dbg.") ||
|
|
|
|
NMD->getName() == "llvm.gcov") {
|
2013-11-23 06:06:31 +08:00
|
|
|
NMD->eraseFromParent();
|
|
|
|
Changed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-31 05:36:43 +08:00
|
|
|
for (Function &F : M)
|
|
|
|
Changed |= stripDebugInfo(F);
|
|
|
|
|
2016-10-11 01:53:33 +08:00
|
|
|
for (auto &GV : M.globals()) {
|
2018-05-31 21:29:58 +08:00
|
|
|
Changed |= GV.eraseMetadata(LLVMContext::MD_dbg);
|
2016-10-11 01:53:33 +08:00
|
|
|
}
|
|
|
|
|
2015-04-01 22:44:59 +08:00
|
|
|
if (GVMaterializer *Materializer = M.getMaterializer())
|
2015-03-31 05:36:43 +08:00
|
|
|
Materializer->setStripDebugInfo();
|
2013-11-23 06:06:31 +08:00
|
|
|
|
|
|
|
return Changed;
|
|
|
|
}
|
2013-12-03 05:29:56 +08:00
|
|
|
|
2016-10-26 02:44:13 +08:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
/// Helper class to downgrade -g metadata to -gline-tables-only metadata.
|
|
|
|
class DebugTypeInfoRemoval {
|
|
|
|
DenseMap<Metadata *, Metadata *> Replacements;
|
|
|
|
|
|
|
|
public:
|
|
|
|
/// The (void)() type.
|
|
|
|
MDNode *EmptySubroutineType;
|
|
|
|
|
|
|
|
private:
|
|
|
|
/// Remember what linkage name we originally had before stripping. If we end
|
|
|
|
/// up making two subprograms identical who originally had different linkage
|
|
|
|
/// names, then we need to make one of them distinct, to avoid them getting
|
|
|
|
/// uniqued. Maps the new node to the old linkage name.
|
|
|
|
DenseMap<DISubprogram *, StringRef> NewToLinkageName;
|
|
|
|
|
|
|
|
// TODO: Remember the distinct subprogram we created for a given linkage name,
|
|
|
|
// so that we can continue to unique whenever possible. Map <newly created
|
|
|
|
// node, old linkage name> to the first (possibly distinct) mdsubprogram
|
|
|
|
// created for that combination. This is not strictly needed for correctness,
|
|
|
|
// but can cut down on the number of MDNodes and let us diff cleanly with the
|
|
|
|
// output of -gline-tables-only.
|
|
|
|
|
|
|
|
public:
|
|
|
|
DebugTypeInfoRemoval(LLVMContext &C)
|
|
|
|
: EmptySubroutineType(DISubroutineType::get(C, DINode::FlagZero, 0,
|
|
|
|
MDNode::get(C, {}))) {}
|
|
|
|
|
|
|
|
Metadata *map(Metadata *M) {
|
|
|
|
if (!M)
|
|
|
|
return nullptr;
|
|
|
|
auto Replacement = Replacements.find(M);
|
|
|
|
if (Replacement != Replacements.end())
|
|
|
|
return Replacement->second;
|
|
|
|
|
|
|
|
return M;
|
|
|
|
}
|
|
|
|
MDNode *mapNode(Metadata *N) { return dyn_cast_or_null<MDNode>(map(N)); }
|
|
|
|
|
|
|
|
/// Recursively remap N and all its referenced children. Does a DF post-order
|
|
|
|
/// traversal, so as to remap bottoms up.
|
|
|
|
void traverseAndRemap(MDNode *N) { traverse(N); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Create a new DISubprogram, to replace the one given.
|
|
|
|
DISubprogram *getReplacementSubprogram(DISubprogram *MDS) {
|
|
|
|
auto *FileAndScope = cast_or_null<DIFile>(map(MDS->getFile()));
|
|
|
|
StringRef LinkageName = MDS->getName().empty() ? MDS->getLinkageName() : "";
|
|
|
|
DISubprogram *Declaration = nullptr;
|
|
|
|
auto *Type = cast_or_null<DISubroutineType>(map(MDS->getType()));
|
|
|
|
DITypeRef ContainingType(map(MDS->getContainingType()));
|
|
|
|
auto *Unit = cast_or_null<DICompileUnit>(map(MDS->getUnit()));
|
|
|
|
auto Variables = nullptr;
|
|
|
|
auto TemplateParams = nullptr;
|
|
|
|
|
|
|
|
// Make a distinct DISubprogram, for situations that warrent it.
|
|
|
|
auto distinctMDSubprogram = [&]() {
|
|
|
|
return DISubprogram::getDistinct(
|
|
|
|
MDS->getContext(), FileAndScope, MDS->getName(), LinkageName,
|
|
|
|
FileAndScope, MDS->getLine(), Type, MDS->isLocalToUnit(),
|
|
|
|
MDS->isDefinition(), MDS->getScopeLine(), ContainingType,
|
|
|
|
MDS->getVirtuality(), MDS->getVirtualIndex(),
|
|
|
|
MDS->getThisAdjustment(), MDS->getFlags(), MDS->isOptimized(), Unit,
|
|
|
|
TemplateParams, Declaration, Variables);
|
|
|
|
};
|
|
|
|
|
|
|
|
if (MDS->isDistinct())
|
|
|
|
return distinctMDSubprogram();
|
|
|
|
|
|
|
|
auto *NewMDS = DISubprogram::get(
|
|
|
|
MDS->getContext(), FileAndScope, MDS->getName(), LinkageName,
|
|
|
|
FileAndScope, MDS->getLine(), Type, MDS->isLocalToUnit(),
|
|
|
|
MDS->isDefinition(), MDS->getScopeLine(), ContainingType,
|
|
|
|
MDS->getVirtuality(), MDS->getVirtualIndex(), MDS->getThisAdjustment(),
|
|
|
|
MDS->getFlags(), MDS->isOptimized(), Unit, TemplateParams, Declaration,
|
|
|
|
Variables);
|
|
|
|
|
|
|
|
StringRef OldLinkageName = MDS->getLinkageName();
|
|
|
|
|
|
|
|
// See if we need to make a distinct one.
|
|
|
|
auto OrigLinkage = NewToLinkageName.find(NewMDS);
|
|
|
|
if (OrigLinkage != NewToLinkageName.end()) {
|
|
|
|
if (OrigLinkage->second == OldLinkageName)
|
|
|
|
// We're good.
|
|
|
|
return NewMDS;
|
|
|
|
|
|
|
|
// Otherwise, need to make a distinct one.
|
|
|
|
// TODO: Query the map to see if we already have one.
|
|
|
|
return distinctMDSubprogram();
|
|
|
|
}
|
|
|
|
|
|
|
|
NewToLinkageName.insert({NewMDS, MDS->getLinkageName()});
|
|
|
|
return NewMDS;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Create a new compile unit, to replace the one given
|
|
|
|
DICompileUnit *getReplacementCU(DICompileUnit *CU) {
|
|
|
|
// Drop skeleton CUs.
|
|
|
|
if (CU->getDWOId())
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
auto *File = cast_or_null<DIFile>(map(CU->getFile()));
|
|
|
|
MDTuple *EnumTypes = nullptr;
|
|
|
|
MDTuple *RetainedTypes = nullptr;
|
|
|
|
MDTuple *GlobalVariables = nullptr;
|
|
|
|
MDTuple *ImportedEntities = nullptr;
|
|
|
|
return DICompileUnit::getDistinct(
|
|
|
|
CU->getContext(), CU->getSourceLanguage(), File, CU->getProducer(),
|
|
|
|
CU->isOptimized(), CU->getFlags(), CU->getRuntimeVersion(),
|
|
|
|
CU->getSplitDebugFilename(), DICompileUnit::LineTablesOnly, EnumTypes,
|
|
|
|
RetainedTypes, GlobalVariables, ImportedEntities, CU->getMacros(),
|
Change debug-info-for-profiling from a TargetOption to a function attribute.
Summary: LTO requires the debug-info-for-profiling to be a function attribute.
Reviewers: echristo, mehdi_amini, dblaikie, probinson, aprantl
Reviewed By: mehdi_amini, dblaikie, aprantl
Subscribers: aprantl, probinson, ahatanak, llvm-commits, mehdi_amini
Differential Revision: https://reviews.llvm.org/D29203
llvm-svn: 293833
2017-02-02 06:45:09 +08:00
|
|
|
CU->getDWOId(), CU->getSplitDebugInlining(),
|
2018-08-17 05:29:55 +08:00
|
|
|
CU->getDebugInfoForProfiling(), CU->getNameTableKind());
|
2016-10-26 02:44:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
DILocation *getReplacementMDLocation(DILocation *MLD) {
|
|
|
|
auto *Scope = map(MLD->getScope());
|
|
|
|
auto *InlinedAt = map(MLD->getInlinedAt());
|
|
|
|
if (MLD->isDistinct())
|
|
|
|
return DILocation::getDistinct(MLD->getContext(), MLD->getLine(),
|
|
|
|
MLD->getColumn(), Scope, InlinedAt);
|
|
|
|
return DILocation::get(MLD->getContext(), MLD->getLine(), MLD->getColumn(),
|
|
|
|
Scope, InlinedAt);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Create a new generic MDNode, to replace the one given
|
|
|
|
MDNode *getReplacementMDNode(MDNode *N) {
|
|
|
|
SmallVector<Metadata *, 8> Ops;
|
|
|
|
Ops.reserve(N->getNumOperands());
|
|
|
|
for (auto &I : N->operands())
|
|
|
|
if (I)
|
|
|
|
Ops.push_back(map(I));
|
|
|
|
auto *Ret = MDNode::get(N->getContext(), Ops);
|
|
|
|
return Ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Attempt to re-map N to a newly created node.
|
|
|
|
void remap(MDNode *N) {
|
|
|
|
if (Replacements.count(N))
|
|
|
|
return;
|
|
|
|
|
|
|
|
auto doRemap = [&](MDNode *N) -> MDNode * {
|
|
|
|
if (!N)
|
|
|
|
return nullptr;
|
|
|
|
if (auto *MDSub = dyn_cast<DISubprogram>(N)) {
|
|
|
|
remap(MDSub->getUnit());
|
|
|
|
return getReplacementSubprogram(MDSub);
|
|
|
|
}
|
|
|
|
if (isa<DISubroutineType>(N))
|
|
|
|
return EmptySubroutineType;
|
|
|
|
if (auto *CU = dyn_cast<DICompileUnit>(N))
|
|
|
|
return getReplacementCU(CU);
|
|
|
|
if (isa<DIFile>(N))
|
|
|
|
return N;
|
|
|
|
if (auto *MDLB = dyn_cast<DILexicalBlockBase>(N))
|
|
|
|
// Remap to our referenced scope (recursively).
|
|
|
|
return mapNode(MDLB->getScope());
|
|
|
|
if (auto *MLD = dyn_cast<DILocation>(N))
|
|
|
|
return getReplacementMDLocation(MLD);
|
|
|
|
|
|
|
|
// Otherwise, if we see these, just drop them now. Not strictly necessary,
|
|
|
|
// but this speeds things up a little.
|
|
|
|
if (isa<DINode>(N))
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
return getReplacementMDNode(N);
|
|
|
|
};
|
|
|
|
Replacements[N] = doRemap(N);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Do the remapping traversal.
|
|
|
|
void traverse(MDNode *);
|
|
|
|
};
|
|
|
|
|
2017-05-06 06:30:37 +08:00
|
|
|
} // end anonymous namespace
|
2016-10-26 02:44:13 +08:00
|
|
|
|
|
|
|
void DebugTypeInfoRemoval::traverse(MDNode *N) {
|
|
|
|
if (!N || Replacements.count(N))
|
|
|
|
return;
|
|
|
|
|
|
|
|
// To avoid cycles, as well as for efficiency sake, we will sometimes prune
|
|
|
|
// parts of the graph.
|
|
|
|
auto prune = [](MDNode *Parent, MDNode *Child) {
|
|
|
|
if (auto *MDS = dyn_cast<DISubprogram>(Parent))
|
[DebugInfo] Add DILabel metadata and intrinsic llvm.dbg.label.
In order to set breakpoints on labels and list source code around
labels, we need collect debug information for labels, i.e., label
name, the function label belong, line number in the file, and the
address label located. In order to keep these information in LLVM
IR and to allow backend to generate debug information correctly.
We create a new kind of metadata for labels, DILabel. The format
of DILabel is
!DILabel(scope: !1, name: "foo", file: !2, line: 3)
We hope to keep debug information as much as possible even the
code is optimized. So, we create a new kind of intrinsic for label
metadata to avoid the metadata is eliminated with basic block.
The intrinsic will keep existing if we keep it from optimized out.
The format of the intrinsic is
llvm.dbg.label(metadata !1)
It has only one argument, that is the DILabel metadata. The
intrinsic will follow the label immediately. Backend could get the
label metadata through the intrinsic's parameter.
We also create DIBuilder API for labels to be used by Frontend.
Frontend could use createLabel() to allocate DILabel objects, and use
insertLabel() to insert llvm.dbg.label intrinsic in LLVM IR.
Differential Revision: https://reviews.llvm.org/D45024
Patch by Hsiangkai Wang.
llvm-svn: 331841
2018-05-09 10:40:45 +08:00
|
|
|
return Child == MDS->getRetainedNodes().get();
|
2016-10-26 02:44:13 +08:00
|
|
|
return false;
|
|
|
|
};
|
|
|
|
|
|
|
|
SmallVector<MDNode *, 16> ToVisit;
|
|
|
|
DenseSet<MDNode *> Opened;
|
|
|
|
|
|
|
|
// Visit each node starting at N in post order, and map them.
|
|
|
|
ToVisit.push_back(N);
|
|
|
|
while (!ToVisit.empty()) {
|
|
|
|
auto *N = ToVisit.back();
|
|
|
|
if (!Opened.insert(N).second) {
|
|
|
|
// Close it.
|
|
|
|
remap(N);
|
|
|
|
ToVisit.pop_back();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
for (auto &I : N->operands())
|
|
|
|
if (auto *MDN = dyn_cast_or_null<MDNode>(I))
|
|
|
|
if (!Opened.count(MDN) && !Replacements.count(MDN) && !prune(N, MDN) &&
|
|
|
|
!isa<DICompileUnit>(MDN))
|
|
|
|
ToVisit.push_back(MDN);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool llvm::stripNonLineTableDebugInfo(Module &M) {
|
|
|
|
bool Changed = false;
|
|
|
|
|
|
|
|
// First off, delete the debug intrinsics.
|
|
|
|
auto RemoveUses = [&](StringRef Name) {
|
|
|
|
if (auto *DbgVal = M.getFunction(Name)) {
|
|
|
|
while (!DbgVal->use_empty())
|
|
|
|
cast<Instruction>(DbgVal->user_back())->eraseFromParent();
|
|
|
|
DbgVal->eraseFromParent();
|
|
|
|
Changed = true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
RemoveUses("llvm.dbg.declare");
|
|
|
|
RemoveUses("llvm.dbg.value");
|
|
|
|
|
|
|
|
// Delete non-CU debug info named metadata nodes.
|
|
|
|
for (auto NMI = M.named_metadata_begin(), NME = M.named_metadata_end();
|
|
|
|
NMI != NME;) {
|
|
|
|
NamedMDNode *NMD = &*NMI;
|
|
|
|
++NMI;
|
|
|
|
// Specifically keep dbg.cu around.
|
|
|
|
if (NMD->getName() == "llvm.dbg.cu")
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Drop all dbg attachments from global variables.
|
|
|
|
for (auto &GV : M.globals())
|
|
|
|
GV.eraseMetadata(LLVMContext::MD_dbg);
|
|
|
|
|
|
|
|
DebugTypeInfoRemoval Mapper(M.getContext());
|
2017-05-06 06:30:37 +08:00
|
|
|
auto remap = [&](MDNode *Node) -> MDNode * {
|
2016-10-26 02:44:13 +08:00
|
|
|
if (!Node)
|
|
|
|
return nullptr;
|
|
|
|
Mapper.traverseAndRemap(Node);
|
|
|
|
auto *NewNode = Mapper.mapNode(Node);
|
|
|
|
Changed |= Node != NewNode;
|
|
|
|
Node = NewNode;
|
|
|
|
return NewNode;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Rewrite the DebugLocs to be equivalent to what
|
|
|
|
// -gline-tables-only would have created.
|
|
|
|
for (auto &F : M) {
|
|
|
|
if (auto *SP = F.getSubprogram()) {
|
|
|
|
Mapper.traverseAndRemap(SP);
|
|
|
|
auto *NewSP = cast<DISubprogram>(Mapper.mapNode(SP));
|
|
|
|
Changed |= SP != NewSP;
|
|
|
|
F.setSubprogram(NewSP);
|
|
|
|
}
|
|
|
|
for (auto &BB : F) {
|
|
|
|
for (auto &I : BB) {
|
2017-03-31 04:10:56 +08:00
|
|
|
auto remapDebugLoc = [&](DebugLoc DL) -> DebugLoc {
|
|
|
|
auto *Scope = DL.getScope();
|
|
|
|
MDNode *InlinedAt = DL.getInlinedAt();
|
|
|
|
Scope = remap(Scope);
|
|
|
|
InlinedAt = remap(InlinedAt);
|
|
|
|
return DebugLoc::get(DL.getLine(), DL.getCol(), Scope, InlinedAt);
|
|
|
|
};
|
|
|
|
|
|
|
|
if (I.getDebugLoc() != DebugLoc())
|
|
|
|
I.setDebugLoc(remapDebugLoc(I.getDebugLoc()));
|
|
|
|
|
|
|
|
// Remap DILocations in untyped MDNodes (e.g., llvm.loop).
|
|
|
|
SmallVector<std::pair<unsigned, MDNode *>, 2> MDs;
|
|
|
|
I.getAllMetadata(MDs);
|
|
|
|
for (auto Attachment : MDs)
|
|
|
|
if (auto *T = dyn_cast_or_null<MDTuple>(Attachment.second))
|
|
|
|
for (unsigned N = 0; N < T->getNumOperands(); ++N)
|
|
|
|
if (auto *Loc = dyn_cast_or_null<DILocation>(T->getOperand(N)))
|
|
|
|
if (Loc != DebugLoc())
|
|
|
|
T->replaceOperandWith(N, remapDebugLoc(Loc));
|
2016-10-26 02:44:13 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create a new llvm.dbg.cu, which is equivalent to the one
|
|
|
|
// -gline-tables-only would have created.
|
|
|
|
for (auto &NMD : M.getNamedMDList()) {
|
|
|
|
SmallVector<MDNode *, 8> Ops;
|
|
|
|
for (MDNode *Op : NMD.operands())
|
|
|
|
Ops.push_back(remap(Op));
|
2018-07-03 20:39:52 +08:00
|
|
|
|
2016-10-26 02:44:13 +08:00
|
|
|
if (!Changed)
|
|
|
|
continue;
|
2018-07-03 20:39:52 +08:00
|
|
|
|
2016-10-26 02:44:13 +08:00
|
|
|
NMD.clearOperands();
|
|
|
|
for (auto *Op : Ops)
|
|
|
|
if (Op)
|
|
|
|
NMD.addOperand(Op);
|
|
|
|
}
|
|
|
|
return Changed;
|
|
|
|
}
|
|
|
|
|
2013-12-03 08:12:14 +08:00
|
|
|
unsigned llvm::getDebugMetadataVersionFromModule(const Module &M) {
|
2015-02-16 14:04:53 +08:00
|
|
|
if (auto *Val = mdconst::dyn_extract_or_null<ConstantInt>(
|
IR: Split Metadata from Value
Split `Metadata` away from the `Value` class hierarchy, as part of
PR21532. Assembly and bitcode changes are in the wings, but this is the
bulk of the change for the IR C++ API.
I have a follow-up patch prepared for `clang`. If this breaks other
sub-projects, I apologize in advance :(. Help me compile it on Darwin
I'll try to fix it. FWIW, the errors should be easy to fix, so it may
be simpler to just fix it yourself.
This breaks the build for all metadata-related code that's out-of-tree.
Rest assured the transition is mechanical and the compiler should catch
almost all of the problems.
Here's a quick guide for updating your code:
- `Metadata` is the root of a class hierarchy with three main classes:
`MDNode`, `MDString`, and `ValueAsMetadata`. It is distinct from
the `Value` class hierarchy. It is typeless -- i.e., instances do
*not* have a `Type`.
- `MDNode`'s operands are all `Metadata *` (instead of `Value *`).
- `TrackingVH<MDNode>` and `WeakVH` referring to metadata can be
replaced with `TrackingMDNodeRef` and `TrackingMDRef`, respectively.
If you're referring solely to resolved `MDNode`s -- post graph
construction -- just use `MDNode*`.
- `MDNode` (and the rest of `Metadata`) have only limited support for
`replaceAllUsesWith()`.
As long as an `MDNode` is pointing at a forward declaration -- the
result of `MDNode::getTemporary()` -- it maintains a side map of its
uses and can RAUW itself. Once the forward declarations are fully
resolved RAUW support is dropped on the ground. This means that
uniquing collisions on changing operands cause nodes to become
"distinct". (This already happened fairly commonly, whenever an
operand went to null.)
If you're constructing complex (non self-reference) `MDNode` cycles,
you need to call `MDNode::resolveCycles()` on each node (or on a
top-level node that somehow references all of the nodes). Also,
don't do that. Metadata cycles (and the RAUW machinery needed to
construct them) are expensive.
- An `MDNode` can only refer to a `Constant` through a bridge called
`ConstantAsMetadata` (one of the subclasses of `ValueAsMetadata`).
As a side effect, accessing an operand of an `MDNode` that is known
to be, e.g., `ConstantInt`, takes three steps: first, cast from
`Metadata` to `ConstantAsMetadata`; second, extract the `Constant`;
third, cast down to `ConstantInt`.
The eventual goal is to introduce `MDInt`/`MDFloat`/etc. and have
metadata schema owners transition away from using `Constant`s when
the type isn't important (and they don't care about referring to
`GlobalValue`s).
In the meantime, I've added transitional API to the `mdconst`
namespace that matches semantics with the old code, in order to
avoid adding the error-prone three-step equivalent to every call
site. If your old code was:
MDNode *N = foo();
bar(isa <ConstantInt>(N->getOperand(0)));
baz(cast <ConstantInt>(N->getOperand(1)));
bak(cast_or_null <ConstantInt>(N->getOperand(2)));
bat(dyn_cast <ConstantInt>(N->getOperand(3)));
bay(dyn_cast_or_null<ConstantInt>(N->getOperand(4)));
you can trivially match its semantics with:
MDNode *N = foo();
bar(mdconst::hasa <ConstantInt>(N->getOperand(0)));
baz(mdconst::extract <ConstantInt>(N->getOperand(1)));
bak(mdconst::extract_or_null <ConstantInt>(N->getOperand(2)));
bat(mdconst::dyn_extract <ConstantInt>(N->getOperand(3)));
bay(mdconst::dyn_extract_or_null<ConstantInt>(N->getOperand(4)));
and when you transition your metadata schema to `MDInt`:
MDNode *N = foo();
bar(isa <MDInt>(N->getOperand(0)));
baz(cast <MDInt>(N->getOperand(1)));
bak(cast_or_null <MDInt>(N->getOperand(2)));
bat(dyn_cast <MDInt>(N->getOperand(3)));
bay(dyn_cast_or_null<MDInt>(N->getOperand(4)));
- A `CallInst` -- specifically, intrinsic instructions -- can refer to
metadata through a bridge called `MetadataAsValue`. This is a
subclass of `Value` where `getType()->isMetadataTy()`.
`MetadataAsValue` is the *only* class that can legally refer to a
`LocalAsMetadata`, which is a bridged form of non-`Constant` values
like `Argument` and `Instruction`. It can also refer to any other
`Metadata` subclass.
(I'll break all your testcases in a follow-up commit, when I propagate
this change to assembly.)
llvm-svn: 223802
2014-12-10 02:38:53 +08:00
|
|
|
M.getModuleFlag("Debug Info Version")))
|
|
|
|
return Val->getZExtValue();
|
|
|
|
return 0;
|
2013-12-03 05:29:56 +08:00
|
|
|
}
|
2017-10-03 02:13:14 +08:00
|
|
|
|
|
|
|
void Instruction::applyMergedLocation(const DILocation *LocA,
|
|
|
|
const DILocation *LocB) {
|
2018-04-13 04:58:24 +08:00
|
|
|
setDebugLoc(DILocation::getMergedLocation(LocA, LocB,
|
|
|
|
DILocation::WithGeneratedLocation));
|
2017-10-03 02:13:14 +08:00
|
|
|
}
|
2017-11-02 06:18:52 +08:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// LLVM C API implementations.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
static unsigned map_from_llvmDWARFsourcelanguage(LLVMDWARFSourceLanguage lang) {
|
|
|
|
switch (lang) {
|
|
|
|
#define HANDLE_DW_LANG(ID, NAME, VERSION, VENDOR) \
|
|
|
|
case LLVMDWARFSourceLanguage##NAME: return ID;
|
|
|
|
#include "llvm/BinaryFormat/Dwarf.def"
|
|
|
|
#undef HANDLE_DW_LANG
|
|
|
|
}
|
|
|
|
llvm_unreachable("Unhandled Tag");
|
|
|
|
}
|
|
|
|
|
2018-04-02 08:17:40 +08:00
|
|
|
template <typename DIT> DIT *unwrapDI(LLVMMetadataRef Ref) {
|
|
|
|
return (DIT *)(Ref ? unwrap<MDNode>(Ref) : nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static DINode::DIFlags map_from_llvmDIFlags(LLVMDIFlags Flags) {
|
|
|
|
return static_cast<DINode::DIFlags>(Flags);
|
|
|
|
}
|
|
|
|
|
2018-05-11 02:23:55 +08:00
|
|
|
static LLVMDIFlags map_to_llvmDIFlags(DINode::DIFlags Flags) {
|
|
|
|
return static_cast<LLVMDIFlags>(Flags);
|
|
|
|
}
|
|
|
|
|
2017-11-02 06:18:52 +08:00
|
|
|
unsigned LLVMDebugMetadataVersion() {
|
|
|
|
return DEBUG_METADATA_VERSION;
|
|
|
|
}
|
|
|
|
|
|
|
|
LLVMDIBuilderRef LLVMCreateDIBuilderDisallowUnresolved(LLVMModuleRef M) {
|
|
|
|
return wrap(new DIBuilder(*unwrap(M), false));
|
|
|
|
}
|
|
|
|
|
|
|
|
LLVMDIBuilderRef LLVMCreateDIBuilder(LLVMModuleRef M) {
|
|
|
|
return wrap(new DIBuilder(*unwrap(M)));
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned LLVMGetModuleDebugMetadataVersion(LLVMModuleRef M) {
|
|
|
|
return getDebugMetadataVersionFromModule(*unwrap(M));
|
|
|
|
}
|
|
|
|
|
|
|
|
LLVMBool LLVMStripModuleDebugInfo(LLVMModuleRef M) {
|
|
|
|
return StripDebugInfo(*unwrap(M));
|
|
|
|
}
|
|
|
|
|
|
|
|
void LLVMDisposeDIBuilder(LLVMDIBuilderRef Builder) {
|
|
|
|
delete unwrap(Builder);
|
|
|
|
}
|
|
|
|
|
|
|
|
void LLVMDIBuilderFinalize(LLVMDIBuilderRef Builder) {
|
|
|
|
unwrap(Builder)->finalize();
|
|
|
|
}
|
|
|
|
|
|
|
|
LLVMMetadataRef LLVMDIBuilderCreateCompileUnit(
|
|
|
|
LLVMDIBuilderRef Builder, LLVMDWARFSourceLanguage Lang,
|
|
|
|
LLVMMetadataRef FileRef, const char *Producer, size_t ProducerLen,
|
|
|
|
LLVMBool isOptimized, const char *Flags, size_t FlagsLen,
|
|
|
|
unsigned RuntimeVer, const char *SplitName, size_t SplitNameLen,
|
|
|
|
LLVMDWARFEmissionKind Kind, unsigned DWOId, LLVMBool SplitDebugInlining,
|
|
|
|
LLVMBool DebugInfoForProfiling) {
|
2018-04-02 08:17:40 +08:00
|
|
|
auto File = unwrapDI<DIFile>(FileRef);
|
2017-11-02 06:18:52 +08:00
|
|
|
|
|
|
|
return wrap(unwrap(Builder)->createCompileUnit(
|
|
|
|
map_from_llvmDWARFsourcelanguage(Lang), File,
|
|
|
|
StringRef(Producer, ProducerLen), isOptimized,
|
|
|
|
StringRef(Flags, FlagsLen), RuntimeVer,
|
|
|
|
StringRef(SplitName, SplitNameLen),
|
|
|
|
static_cast<DICompileUnit::DebugEmissionKind>(Kind), DWOId,
|
|
|
|
SplitDebugInlining, DebugInfoForProfiling));
|
|
|
|
}
|
|
|
|
|
|
|
|
LLVMMetadataRef
|
|
|
|
LLVMDIBuilderCreateFile(LLVMDIBuilderRef Builder, const char *Filename,
|
|
|
|
size_t FilenameLen, const char *Directory,
|
|
|
|
size_t DirectoryLen) {
|
|
|
|
return wrap(unwrap(Builder)->createFile(StringRef(Filename, FilenameLen),
|
|
|
|
StringRef(Directory, DirectoryLen)));
|
|
|
|
}
|
|
|
|
|
2018-04-23 21:51:43 +08:00
|
|
|
LLVMMetadataRef
|
|
|
|
LLVMDIBuilderCreateModule(LLVMDIBuilderRef Builder, LLVMMetadataRef ParentScope,
|
|
|
|
const char *Name, size_t NameLen,
|
|
|
|
const char *ConfigMacros, size_t ConfigMacrosLen,
|
|
|
|
const char *IncludePath, size_t IncludePathLen,
|
|
|
|
const char *ISysRoot, size_t ISysRootLen) {
|
|
|
|
return wrap(unwrap(Builder)->createModule(
|
|
|
|
unwrapDI<DIScope>(ParentScope), StringRef(Name, NameLen),
|
|
|
|
StringRef(ConfigMacros, ConfigMacrosLen),
|
|
|
|
StringRef(IncludePath, IncludePathLen),
|
|
|
|
StringRef(ISysRoot, ISysRootLen)));
|
|
|
|
}
|
|
|
|
|
|
|
|
LLVMMetadataRef LLVMDIBuilderCreateNameSpace(LLVMDIBuilderRef Builder,
|
|
|
|
LLVMMetadataRef ParentScope,
|
|
|
|
const char *Name, size_t NameLen,
|
|
|
|
LLVMBool ExportSymbols) {
|
|
|
|
return wrap(unwrap(Builder)->createNameSpace(
|
|
|
|
unwrapDI<DIScope>(ParentScope), StringRef(Name, NameLen), ExportSymbols));
|
|
|
|
}
|
|
|
|
|
2018-04-07 14:07:55 +08:00
|
|
|
LLVMMetadataRef LLVMDIBuilderCreateFunction(
|
|
|
|
LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
|
|
|
|
size_t NameLen, const char *LinkageName, size_t LinkageNameLen,
|
|
|
|
LLVMMetadataRef File, unsigned LineNo, LLVMMetadataRef Ty,
|
|
|
|
LLVMBool IsLocalToUnit, LLVMBool IsDefinition,
|
|
|
|
unsigned ScopeLine, LLVMDIFlags Flags, LLVMBool IsOptimized) {
|
|
|
|
return wrap(unwrap(Builder)->createFunction(
|
|
|
|
unwrapDI<DIScope>(Scope), {Name, NameLen}, {LinkageName, LinkageNameLen},
|
|
|
|
unwrapDI<DIFile>(File), LineNo, unwrapDI<DISubroutineType>(Ty),
|
|
|
|
IsLocalToUnit, IsDefinition, ScopeLine, map_from_llvmDIFlags(Flags),
|
|
|
|
IsOptimized, nullptr, nullptr, nullptr));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LLVMMetadataRef LLVMDIBuilderCreateLexicalBlock(
|
|
|
|
LLVMDIBuilderRef Builder, LLVMMetadataRef Scope,
|
|
|
|
LLVMMetadataRef File, unsigned Line, unsigned Col) {
|
|
|
|
return wrap(unwrap(Builder)->createLexicalBlock(unwrapDI<DIScope>(Scope),
|
|
|
|
unwrapDI<DIFile>(File),
|
|
|
|
Line, Col));
|
|
|
|
}
|
|
|
|
|
|
|
|
LLVMMetadataRef
|
|
|
|
LLVMDIBuilderCreateLexicalBlockFile(LLVMDIBuilderRef Builder,
|
|
|
|
LLVMMetadataRef Scope,
|
|
|
|
LLVMMetadataRef File,
|
|
|
|
unsigned Discriminator) {
|
|
|
|
return wrap(unwrap(Builder)->createLexicalBlockFile(unwrapDI<DIScope>(Scope),
|
|
|
|
unwrapDI<DIFile>(File),
|
|
|
|
Discriminator));
|
|
|
|
}
|
|
|
|
|
2018-04-29 06:32:07 +08:00
|
|
|
LLVMMetadataRef
|
|
|
|
LLVMDIBuilderCreateImportedModuleFromNamespace(LLVMDIBuilderRef Builder,
|
|
|
|
LLVMMetadataRef Scope,
|
|
|
|
LLVMMetadataRef NS,
|
|
|
|
LLVMMetadataRef File,
|
|
|
|
unsigned Line) {
|
|
|
|
return wrap(unwrap(Builder)->createImportedModule(unwrapDI<DIScope>(Scope),
|
|
|
|
unwrapDI<DINamespace>(NS),
|
|
|
|
unwrapDI<DIFile>(File),
|
|
|
|
Line));
|
|
|
|
}
|
|
|
|
|
|
|
|
LLVMMetadataRef
|
|
|
|
LLVMDIBuilderCreateImportedModuleFromAlias(LLVMDIBuilderRef Builder,
|
|
|
|
LLVMMetadataRef Scope,
|
|
|
|
LLVMMetadataRef ImportedEntity,
|
|
|
|
LLVMMetadataRef File,
|
|
|
|
unsigned Line) {
|
|
|
|
return wrap(unwrap(Builder)->createImportedModule(
|
|
|
|
unwrapDI<DIScope>(Scope),
|
|
|
|
unwrapDI<DIImportedEntity>(ImportedEntity),
|
|
|
|
unwrapDI<DIFile>(File), Line));
|
|
|
|
}
|
|
|
|
|
|
|
|
LLVMMetadataRef
|
|
|
|
LLVMDIBuilderCreateImportedModuleFromModule(LLVMDIBuilderRef Builder,
|
|
|
|
LLVMMetadataRef Scope,
|
|
|
|
LLVMMetadataRef M,
|
|
|
|
LLVMMetadataRef File,
|
|
|
|
unsigned Line) {
|
|
|
|
return wrap(unwrap(Builder)->createImportedModule(unwrapDI<DIScope>(Scope),
|
|
|
|
unwrapDI<DIModule>(M),
|
|
|
|
unwrapDI<DIFile>(File),
|
|
|
|
Line));
|
|
|
|
}
|
|
|
|
|
|
|
|
LLVMMetadataRef
|
|
|
|
LLVMDIBuilderCreateImportedDeclaration(LLVMDIBuilderRef Builder,
|
|
|
|
LLVMMetadataRef Scope,
|
|
|
|
LLVMMetadataRef Decl,
|
|
|
|
LLVMMetadataRef File,
|
|
|
|
unsigned Line,
|
|
|
|
const char *Name, size_t NameLen) {
|
|
|
|
return wrap(unwrap(Builder)->createImportedDeclaration(
|
|
|
|
unwrapDI<DIScope>(Scope),
|
|
|
|
unwrapDI<DINode>(Decl),
|
|
|
|
unwrapDI<DIFile>(File), Line, {Name, NameLen}));
|
|
|
|
}
|
|
|
|
|
2017-11-02 06:18:52 +08:00
|
|
|
LLVMMetadataRef
|
|
|
|
LLVMDIBuilderCreateDebugLocation(LLVMContextRef Ctx, unsigned Line,
|
|
|
|
unsigned Column, LLVMMetadataRef Scope,
|
|
|
|
LLVMMetadataRef InlinedAt) {
|
|
|
|
return wrap(DILocation::get(*unwrap(Ctx), Line, Column, unwrap(Scope),
|
|
|
|
unwrap(InlinedAt)));
|
|
|
|
}
|
2018-04-02 08:17:40 +08:00
|
|
|
|
2018-05-11 02:23:55 +08:00
|
|
|
unsigned LLVMDILocationGetLine(LLVMMetadataRef Location) {
|
|
|
|
return unwrapDI<DILocation>(Location)->getLine();
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned LLVMDILocationGetColumn(LLVMMetadataRef Location) {
|
|
|
|
return unwrapDI<DILocation>(Location)->getColumn();
|
|
|
|
}
|
|
|
|
|
|
|
|
LLVMMetadataRef LLVMDILocationGetScope(LLVMMetadataRef Location) {
|
|
|
|
return wrap(unwrapDI<DILocation>(Location)->getScope());
|
|
|
|
}
|
|
|
|
|
2018-04-02 08:17:40 +08:00
|
|
|
LLVMMetadataRef LLVMDIBuilderCreateEnumerationType(
|
|
|
|
LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
|
|
|
|
size_t NameLen, LLVMMetadataRef File, unsigned LineNumber,
|
2018-04-29 02:13:39 +08:00
|
|
|
uint64_t SizeInBits, uint32_t AlignInBits, LLVMMetadataRef *Elements,
|
2018-04-02 08:17:40 +08:00
|
|
|
unsigned NumElements, LLVMMetadataRef ClassTy) {
|
|
|
|
auto Elts = unwrap(Builder)->getOrCreateArray({unwrap(Elements),
|
|
|
|
NumElements});
|
|
|
|
return wrap(unwrap(Builder)->createEnumerationType(
|
|
|
|
unwrapDI<DIScope>(Scope), {Name, NameLen}, unwrapDI<DIFile>(File),
|
|
|
|
LineNumber, SizeInBits, AlignInBits, Elts, unwrapDI<DIType>(ClassTy)));
|
|
|
|
}
|
|
|
|
|
|
|
|
LLVMMetadataRef LLVMDIBuilderCreateUnionType(
|
|
|
|
LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
|
|
|
|
size_t NameLen, LLVMMetadataRef File, unsigned LineNumber,
|
2018-04-29 02:13:39 +08:00
|
|
|
uint64_t SizeInBits, uint32_t AlignInBits, LLVMDIFlags Flags,
|
2018-04-02 08:17:40 +08:00
|
|
|
LLVMMetadataRef *Elements, unsigned NumElements, unsigned RunTimeLang,
|
|
|
|
const char *UniqueId, size_t UniqueIdLen) {
|
|
|
|
auto Elts = unwrap(Builder)->getOrCreateArray({unwrap(Elements),
|
|
|
|
NumElements});
|
|
|
|
return wrap(unwrap(Builder)->createUnionType(
|
|
|
|
unwrapDI<DIScope>(Scope), {Name, NameLen}, unwrapDI<DIFile>(File),
|
|
|
|
LineNumber, SizeInBits, AlignInBits, map_from_llvmDIFlags(Flags),
|
|
|
|
Elts, RunTimeLang, {UniqueId, UniqueIdLen}));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LLVMMetadataRef
|
2018-04-29 02:13:39 +08:00
|
|
|
LLVMDIBuilderCreateArrayType(LLVMDIBuilderRef Builder, uint64_t Size,
|
|
|
|
uint32_t AlignInBits, LLVMMetadataRef Ty,
|
2018-04-02 08:17:40 +08:00
|
|
|
LLVMMetadataRef *Subscripts,
|
|
|
|
unsigned NumSubscripts) {
|
|
|
|
auto Subs = unwrap(Builder)->getOrCreateArray({unwrap(Subscripts),
|
|
|
|
NumSubscripts});
|
|
|
|
return wrap(unwrap(Builder)->createArrayType(Size, AlignInBits,
|
|
|
|
unwrapDI<DIType>(Ty), Subs));
|
|
|
|
}
|
|
|
|
|
|
|
|
LLVMMetadataRef
|
2018-04-29 02:13:39 +08:00
|
|
|
LLVMDIBuilderCreateVectorType(LLVMDIBuilderRef Builder, uint64_t Size,
|
|
|
|
uint32_t AlignInBits, LLVMMetadataRef Ty,
|
2018-04-02 08:17:40 +08:00
|
|
|
LLVMMetadataRef *Subscripts,
|
|
|
|
unsigned NumSubscripts) {
|
|
|
|
auto Subs = unwrap(Builder)->getOrCreateArray({unwrap(Subscripts),
|
|
|
|
NumSubscripts});
|
|
|
|
return wrap(unwrap(Builder)->createVectorType(Size, AlignInBits,
|
|
|
|
unwrapDI<DIType>(Ty), Subs));
|
|
|
|
}
|
|
|
|
|
|
|
|
LLVMMetadataRef
|
|
|
|
LLVMDIBuilderCreateBasicType(LLVMDIBuilderRef Builder, const char *Name,
|
2018-04-29 02:13:39 +08:00
|
|
|
size_t NameLen, uint64_t SizeInBits,
|
2018-08-20 07:39:47 +08:00
|
|
|
LLVMDWARFTypeEncoding Encoding,
|
|
|
|
LLVMDIFlags Flags) {
|
2018-04-02 08:17:40 +08:00
|
|
|
return wrap(unwrap(Builder)->createBasicType({Name, NameLen},
|
2018-08-20 07:39:47 +08:00
|
|
|
SizeInBits, Encoding,
|
|
|
|
map_from_llvmDIFlags(Flags)));
|
2018-04-02 08:17:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
LLVMMetadataRef LLVMDIBuilderCreatePointerType(
|
|
|
|
LLVMDIBuilderRef Builder, LLVMMetadataRef PointeeTy,
|
2018-04-29 02:13:39 +08:00
|
|
|
uint64_t SizeInBits, uint32_t AlignInBits, unsigned AddressSpace,
|
2018-04-02 08:17:40 +08:00
|
|
|
const char *Name, size_t NameLen) {
|
|
|
|
return wrap(unwrap(Builder)->createPointerType(unwrapDI<DIType>(PointeeTy),
|
|
|
|
SizeInBits, AlignInBits,
|
|
|
|
AddressSpace, {Name, NameLen}));
|
|
|
|
}
|
|
|
|
|
|
|
|
LLVMMetadataRef LLVMDIBuilderCreateStructType(
|
|
|
|
LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
|
|
|
|
size_t NameLen, LLVMMetadataRef File, unsigned LineNumber,
|
2018-04-29 02:13:39 +08:00
|
|
|
uint64_t SizeInBits, uint32_t AlignInBits, LLVMDIFlags Flags,
|
2018-04-02 08:17:40 +08:00
|
|
|
LLVMMetadataRef DerivedFrom, LLVMMetadataRef *Elements,
|
|
|
|
unsigned NumElements, unsigned RunTimeLang, LLVMMetadataRef VTableHolder,
|
|
|
|
const char *UniqueId, size_t UniqueIdLen) {
|
|
|
|
auto Elts = unwrap(Builder)->getOrCreateArray({unwrap(Elements),
|
|
|
|
NumElements});
|
|
|
|
return wrap(unwrap(Builder)->createStructType(
|
|
|
|
unwrapDI<DIScope>(Scope), {Name, NameLen}, unwrapDI<DIFile>(File),
|
|
|
|
LineNumber, SizeInBits, AlignInBits, map_from_llvmDIFlags(Flags),
|
|
|
|
unwrapDI<DIType>(DerivedFrom), Elts, RunTimeLang,
|
|
|
|
unwrapDI<DIType>(VTableHolder), {UniqueId, UniqueIdLen}));
|
|
|
|
}
|
|
|
|
|
|
|
|
LLVMMetadataRef LLVMDIBuilderCreateMemberType(
|
|
|
|
LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
|
2018-04-29 02:13:39 +08:00
|
|
|
size_t NameLen, LLVMMetadataRef File, unsigned LineNo, uint64_t SizeInBits,
|
|
|
|
uint32_t AlignInBits, uint64_t OffsetInBits, LLVMDIFlags Flags,
|
2018-04-02 08:17:40 +08:00
|
|
|
LLVMMetadataRef Ty) {
|
|
|
|
return wrap(unwrap(Builder)->createMemberType(unwrapDI<DIScope>(Scope),
|
|
|
|
{Name, NameLen}, unwrapDI<DIFile>(File), LineNo, SizeInBits, AlignInBits,
|
|
|
|
OffsetInBits, map_from_llvmDIFlags(Flags), unwrapDI<DIType>(Ty)));
|
|
|
|
}
|
|
|
|
|
|
|
|
LLVMMetadataRef
|
|
|
|
LLVMDIBuilderCreateUnspecifiedType(LLVMDIBuilderRef Builder, const char *Name,
|
|
|
|
size_t NameLen) {
|
|
|
|
return wrap(unwrap(Builder)->createUnspecifiedType({Name, NameLen}));
|
|
|
|
}
|
|
|
|
|
|
|
|
LLVMMetadataRef
|
|
|
|
LLVMDIBuilderCreateStaticMemberType(
|
|
|
|
LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
|
|
|
|
size_t NameLen, LLVMMetadataRef File, unsigned LineNumber,
|
|
|
|
LLVMMetadataRef Type, LLVMDIFlags Flags, LLVMValueRef ConstantVal,
|
2018-04-29 02:13:39 +08:00
|
|
|
uint32_t AlignInBits) {
|
2018-04-02 08:17:40 +08:00
|
|
|
return wrap(unwrap(Builder)->createStaticMemberType(
|
|
|
|
unwrapDI<DIScope>(Scope), {Name, NameLen},
|
|
|
|
unwrapDI<DIFile>(File), LineNumber, unwrapDI<DIType>(Type),
|
|
|
|
map_from_llvmDIFlags(Flags), unwrap<Constant>(ConstantVal),
|
|
|
|
AlignInBits));
|
|
|
|
}
|
|
|
|
|
2018-05-22 00:27:35 +08:00
|
|
|
LLVMMetadataRef
|
|
|
|
LLVMDIBuilderCreateObjCIVar(LLVMDIBuilderRef Builder,
|
|
|
|
const char *Name, size_t NameLen,
|
|
|
|
LLVMMetadataRef File, unsigned LineNo,
|
|
|
|
uint64_t SizeInBits, uint32_t AlignInBits,
|
|
|
|
uint64_t OffsetInBits, LLVMDIFlags Flags,
|
|
|
|
LLVMMetadataRef Ty, LLVMMetadataRef PropertyNode) {
|
|
|
|
return wrap(unwrap(Builder)->createObjCIVar(
|
|
|
|
{Name, NameLen}, unwrapDI<DIFile>(File), LineNo,
|
|
|
|
SizeInBits, AlignInBits, OffsetInBits,
|
|
|
|
map_from_llvmDIFlags(Flags), unwrapDI<DIType>(Ty),
|
|
|
|
unwrapDI<MDNode>(PropertyNode)));
|
|
|
|
}
|
|
|
|
|
|
|
|
LLVMMetadataRef
|
|
|
|
LLVMDIBuilderCreateObjCProperty(LLVMDIBuilderRef Builder,
|
|
|
|
const char *Name, size_t NameLen,
|
|
|
|
LLVMMetadataRef File, unsigned LineNo,
|
|
|
|
const char *GetterName, size_t GetterNameLen,
|
|
|
|
const char *SetterName, size_t SetterNameLen,
|
|
|
|
unsigned PropertyAttributes,
|
|
|
|
LLVMMetadataRef Ty) {
|
|
|
|
return wrap(unwrap(Builder)->createObjCProperty(
|
|
|
|
{Name, NameLen}, unwrapDI<DIFile>(File), LineNo,
|
|
|
|
{GetterName, GetterNameLen}, {SetterName, SetterNameLen},
|
|
|
|
PropertyAttributes, unwrapDI<DIType>(Ty)));
|
|
|
|
}
|
|
|
|
|
2018-04-02 08:17:40 +08:00
|
|
|
LLVMMetadataRef
|
|
|
|
LLVMDIBuilderCreateObjectPointerType(LLVMDIBuilderRef Builder,
|
|
|
|
LLVMMetadataRef Type) {
|
|
|
|
return wrap(unwrap(Builder)->createObjectPointerType(unwrapDI<DIType>(Type)));
|
|
|
|
}
|
|
|
|
|
2018-05-11 05:10:06 +08:00
|
|
|
LLVMMetadataRef
|
|
|
|
LLVMDIBuilderCreateTypedef(LLVMDIBuilderRef Builder, LLVMMetadataRef Type,
|
|
|
|
const char *Name, size_t NameLen,
|
|
|
|
LLVMMetadataRef File, unsigned LineNo,
|
|
|
|
LLVMMetadataRef Scope) {
|
|
|
|
return wrap(unwrap(Builder)->createTypedef(
|
|
|
|
unwrapDI<DIType>(Type), {Name, NameLen},
|
|
|
|
unwrapDI<DIFile>(File), LineNo,
|
|
|
|
unwrapDI<DIScope>(Scope)));
|
|
|
|
}
|
|
|
|
|
2018-05-22 00:27:35 +08:00
|
|
|
LLVMMetadataRef
|
|
|
|
LLVMDIBuilderCreateInheritance(LLVMDIBuilderRef Builder,
|
|
|
|
LLVMMetadataRef Ty, LLVMMetadataRef BaseTy,
|
|
|
|
uint64_t BaseOffset, uint32_t VBPtrOffset,
|
|
|
|
LLVMDIFlags Flags) {
|
|
|
|
return wrap(unwrap(Builder)->createInheritance(
|
|
|
|
unwrapDI<DIType>(Ty), unwrapDI<DIType>(BaseTy),
|
|
|
|
BaseOffset, VBPtrOffset, map_from_llvmDIFlags(Flags)));
|
|
|
|
}
|
|
|
|
|
2018-04-23 21:51:43 +08:00
|
|
|
LLVMMetadataRef
|
|
|
|
LLVMDIBuilderCreateForwardDecl(
|
|
|
|
LLVMDIBuilderRef Builder, unsigned Tag, const char *Name,
|
|
|
|
size_t NameLen, LLVMMetadataRef Scope, LLVMMetadataRef File, unsigned Line,
|
2018-04-29 02:13:39 +08:00
|
|
|
unsigned RuntimeLang, uint64_t SizeInBits, uint32_t AlignInBits,
|
2018-04-23 21:51:43 +08:00
|
|
|
const char *UniqueIdentifier, size_t UniqueIdentifierLen) {
|
|
|
|
return wrap(unwrap(Builder)->createForwardDecl(
|
|
|
|
Tag, {Name, NameLen}, unwrapDI<DIScope>(Scope),
|
|
|
|
unwrapDI<DIFile>(File), Line, RuntimeLang, SizeInBits,
|
|
|
|
AlignInBits, {UniqueIdentifier, UniqueIdentifierLen}));
|
|
|
|
}
|
|
|
|
|
2018-04-02 08:17:40 +08:00
|
|
|
LLVMMetadataRef
|
|
|
|
LLVMDIBuilderCreateReplaceableCompositeType(
|
2018-04-03 03:11:44 +08:00
|
|
|
LLVMDIBuilderRef Builder, unsigned Tag, const char *Name,
|
|
|
|
size_t NameLen, LLVMMetadataRef Scope, LLVMMetadataRef File, unsigned Line,
|
2018-04-29 02:13:39 +08:00
|
|
|
unsigned RuntimeLang, uint64_t SizeInBits, uint32_t AlignInBits,
|
2018-04-02 08:17:40 +08:00
|
|
|
LLVMDIFlags Flags, const char *UniqueIdentifier,
|
2018-04-03 03:11:44 +08:00
|
|
|
size_t UniqueIdentifierLen) {
|
2018-04-02 08:17:40 +08:00
|
|
|
return wrap(unwrap(Builder)->createReplaceableCompositeType(
|
|
|
|
Tag, {Name, NameLen}, unwrapDI<DIScope>(Scope),
|
|
|
|
unwrapDI<DIFile>(File), Line, RuntimeLang, SizeInBits,
|
|
|
|
AlignInBits, map_from_llvmDIFlags(Flags),
|
|
|
|
{UniqueIdentifier, UniqueIdentifierLen}));
|
|
|
|
}
|
|
|
|
|
|
|
|
LLVMMetadataRef
|
|
|
|
LLVMDIBuilderCreateQualifiedType(LLVMDIBuilderRef Builder, unsigned Tag,
|
|
|
|
LLVMMetadataRef Type) {
|
|
|
|
return wrap(unwrap(Builder)->createQualifiedType(Tag,
|
|
|
|
unwrapDI<DIType>(Type)));
|
|
|
|
}
|
|
|
|
|
|
|
|
LLVMMetadataRef
|
|
|
|
LLVMDIBuilderCreateReferenceType(LLVMDIBuilderRef Builder, unsigned Tag,
|
|
|
|
LLVMMetadataRef Type) {
|
|
|
|
return wrap(unwrap(Builder)->createReferenceType(Tag,
|
|
|
|
unwrapDI<DIType>(Type)));
|
|
|
|
}
|
|
|
|
|
|
|
|
LLVMMetadataRef
|
|
|
|
LLVMDIBuilderCreateNullPtrType(LLVMDIBuilderRef Builder) {
|
|
|
|
return wrap(unwrap(Builder)->createNullPtrType());
|
|
|
|
}
|
|
|
|
|
|
|
|
LLVMMetadataRef
|
|
|
|
LLVMDIBuilderCreateMemberPointerType(LLVMDIBuilderRef Builder,
|
|
|
|
LLVMMetadataRef PointeeType,
|
|
|
|
LLVMMetadataRef ClassType,
|
2018-04-29 02:13:39 +08:00
|
|
|
uint64_t SizeInBits,
|
|
|
|
uint32_t AlignInBits,
|
2018-04-02 08:17:40 +08:00
|
|
|
LLVMDIFlags Flags) {
|
|
|
|
return wrap(unwrap(Builder)->createMemberPointerType(
|
|
|
|
unwrapDI<DIType>(PointeeType),
|
|
|
|
unwrapDI<DIType>(ClassType), AlignInBits, SizeInBits,
|
|
|
|
map_from_llvmDIFlags(Flags)));
|
|
|
|
}
|
|
|
|
|
2018-04-29 02:13:39 +08:00
|
|
|
LLVMMetadataRef
|
|
|
|
LLVMDIBuilderCreateBitFieldMemberType(LLVMDIBuilderRef Builder,
|
|
|
|
LLVMMetadataRef Scope,
|
|
|
|
const char *Name, size_t NameLen,
|
|
|
|
LLVMMetadataRef File, unsigned LineNumber,
|
|
|
|
uint64_t SizeInBits,
|
|
|
|
uint64_t OffsetInBits,
|
|
|
|
uint64_t StorageOffsetInBits,
|
|
|
|
LLVMDIFlags Flags, LLVMMetadataRef Type) {
|
|
|
|
return wrap(unwrap(Builder)->createBitFieldMemberType(
|
|
|
|
unwrapDI<DIScope>(Scope), {Name, NameLen},
|
|
|
|
unwrapDI<DIFile>(File), LineNumber,
|
|
|
|
SizeInBits, OffsetInBits, StorageOffsetInBits,
|
|
|
|
map_from_llvmDIFlags(Flags), unwrapDI<DIType>(Type)));
|
|
|
|
}
|
|
|
|
|
|
|
|
LLVMMetadataRef LLVMDIBuilderCreateClassType(LLVMDIBuilderRef Builder,
|
|
|
|
LLVMMetadataRef Scope, const char *Name, size_t NameLen,
|
|
|
|
LLVMMetadataRef File, unsigned LineNumber, uint64_t SizeInBits,
|
|
|
|
uint32_t AlignInBits, uint64_t OffsetInBits, LLVMDIFlags Flags,
|
|
|
|
LLVMMetadataRef DerivedFrom,
|
|
|
|
LLVMMetadataRef *Elements, unsigned NumElements,
|
|
|
|
LLVMMetadataRef VTableHolder, LLVMMetadataRef TemplateParamsNode,
|
|
|
|
const char *UniqueIdentifier, size_t UniqueIdentifierLen) {
|
|
|
|
auto Elts = unwrap(Builder)->getOrCreateArray({unwrap(Elements),
|
|
|
|
NumElements});
|
|
|
|
return wrap(unwrap(Builder)->createClassType(
|
|
|
|
unwrapDI<DIScope>(Scope), {Name, NameLen},
|
|
|
|
unwrapDI<DIFile>(File), LineNumber,
|
|
|
|
SizeInBits, AlignInBits, OffsetInBits,
|
|
|
|
map_from_llvmDIFlags(Flags), unwrapDI<DIType>(DerivedFrom),
|
|
|
|
Elts, unwrapDI<DIType>(VTableHolder),
|
|
|
|
unwrapDI<MDNode>(TemplateParamsNode),
|
|
|
|
{UniqueIdentifier, UniqueIdentifierLen}));
|
|
|
|
}
|
|
|
|
|
2018-04-02 08:17:40 +08:00
|
|
|
LLVMMetadataRef
|
|
|
|
LLVMDIBuilderCreateArtificialType(LLVMDIBuilderRef Builder,
|
|
|
|
LLVMMetadataRef Type) {
|
|
|
|
return wrap(unwrap(Builder)->createArtificialType(unwrapDI<DIType>(Type)));
|
|
|
|
}
|
|
|
|
|
2018-05-11 02:23:55 +08:00
|
|
|
const char *LLVMDITypeGetName(LLVMMetadataRef DType, size_t *Length) {
|
|
|
|
StringRef Str = unwrap<DIType>(DType)->getName();
|
|
|
|
*Length = Str.size();
|
|
|
|
return Str.data();
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t LLVMDITypeGetSizeInBits(LLVMMetadataRef DType) {
|
|
|
|
return unwrapDI<DIType>(DType)->getSizeInBits();
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t LLVMDITypeGetOffsetInBits(LLVMMetadataRef DType) {
|
|
|
|
return unwrapDI<DIType>(DType)->getOffsetInBits();
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t LLVMDITypeGetAlignInBits(LLVMMetadataRef DType) {
|
|
|
|
return unwrapDI<DIType>(DType)->getAlignInBits();
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned LLVMDITypeGetLine(LLVMMetadataRef DType) {
|
|
|
|
return unwrapDI<DIType>(DType)->getLine();
|
|
|
|
}
|
|
|
|
|
|
|
|
LLVMDIFlags LLVMDITypeGetFlags(LLVMMetadataRef DType) {
|
|
|
|
return map_to_llvmDIFlags(unwrapDI<DIType>(DType)->getFlags());
|
|
|
|
}
|
|
|
|
|
2018-04-23 22:29:33 +08:00
|
|
|
LLVMMetadataRef LLVMDIBuilderGetOrCreateTypeArray(LLVMDIBuilderRef Builder,
|
|
|
|
LLVMMetadataRef *Types,
|
|
|
|
size_t Length) {
|
|
|
|
return wrap(
|
|
|
|
unwrap(Builder)->getOrCreateTypeArray({unwrap(Types), Length}).get());
|
|
|
|
}
|
|
|
|
|
2018-04-02 08:17:40 +08:00
|
|
|
LLVMMetadataRef
|
|
|
|
LLVMDIBuilderCreateSubroutineType(LLVMDIBuilderRef Builder,
|
|
|
|
LLVMMetadataRef File,
|
|
|
|
LLVMMetadataRef *ParameterTypes,
|
|
|
|
unsigned NumParameterTypes,
|
|
|
|
LLVMDIFlags Flags) {
|
|
|
|
auto Elts = unwrap(Builder)->getOrCreateTypeArray({unwrap(ParameterTypes),
|
|
|
|
NumParameterTypes});
|
|
|
|
return wrap(unwrap(Builder)->createSubroutineType(
|
|
|
|
Elts, map_from_llvmDIFlags(Flags)));
|
|
|
|
}
|
2018-04-07 14:07:55 +08:00
|
|
|
|
2018-04-23 03:24:44 +08:00
|
|
|
LLVMMetadataRef LLVMDIBuilderCreateExpression(LLVMDIBuilderRef Builder,
|
|
|
|
int64_t *Addr, size_t Length) {
|
|
|
|
return wrap(unwrap(Builder)->createExpression(ArrayRef<int64_t>(Addr,
|
|
|
|
Length)));
|
|
|
|
}
|
|
|
|
|
2018-04-24 06:31:49 +08:00
|
|
|
LLVMMetadataRef
|
|
|
|
LLVMDIBuilderCreateConstantValueExpression(LLVMDIBuilderRef Builder,
|
|
|
|
int64_t Value) {
|
|
|
|
return wrap(unwrap(Builder)->createConstantValueExpression(Value));
|
|
|
|
}
|
|
|
|
|
|
|
|
LLVMMetadataRef
|
|
|
|
LLVMDIBuilderCreateGlobalVariableExpression(LLVMDIBuilderRef Builder,
|
|
|
|
LLVMMetadataRef Scope,
|
|
|
|
const char *Name, size_t NameLen,
|
|
|
|
const char *Linkage, size_t LinkLen,
|
|
|
|
LLVMMetadataRef File,
|
|
|
|
unsigned LineNo,
|
|
|
|
LLVMMetadataRef Ty,
|
|
|
|
LLVMBool LocalToUnit,
|
|
|
|
LLVMMetadataRef Expr,
|
|
|
|
LLVMMetadataRef Decl,
|
|
|
|
uint32_t AlignInBits) {
|
|
|
|
return wrap(unwrap(Builder)->createGlobalVariableExpression(
|
|
|
|
unwrapDI<DIScope>(Scope), {Name, NameLen}, {Linkage, LinkLen},
|
|
|
|
unwrapDI<DIFile>(File), LineNo, unwrapDI<DIType>(Ty),
|
|
|
|
LocalToUnit, unwrap<DIExpression>(Expr),
|
|
|
|
unwrapDI<MDNode>(Decl), AlignInBits));
|
|
|
|
}
|
|
|
|
|
2018-05-11 02:09:53 +08:00
|
|
|
LLVMMetadataRef LLVMTemporaryMDNode(LLVMContextRef Ctx, LLVMMetadataRef *Data,
|
|
|
|
size_t Count) {
|
|
|
|
return wrap(
|
|
|
|
MDTuple::getTemporary(*unwrap(Ctx), {unwrap(Data), Count}).release());
|
|
|
|
}
|
|
|
|
|
|
|
|
void LLVMDisposeTemporaryMDNode(LLVMMetadataRef TempNode) {
|
|
|
|
MDNode::deleteTemporary(unwrapDI<MDNode>(TempNode));
|
|
|
|
}
|
|
|
|
|
|
|
|
void LLVMMetadataReplaceAllUsesWith(LLVMMetadataRef TargetMetadata,
|
|
|
|
LLVMMetadataRef Replacement) {
|
|
|
|
auto *Node = unwrapDI<MDNode>(TargetMetadata);
|
|
|
|
Node->replaceAllUsesWith(unwrap<Metadata>(Replacement));
|
|
|
|
MDNode::deleteTemporary(Node);
|
|
|
|
}
|
|
|
|
|
2018-04-24 06:31:49 +08:00
|
|
|
LLVMMetadataRef
|
|
|
|
LLVMDIBuilderCreateTempGlobalVariableFwdDecl(LLVMDIBuilderRef Builder,
|
|
|
|
LLVMMetadataRef Scope,
|
|
|
|
const char *Name, size_t NameLen,
|
|
|
|
const char *Linkage, size_t LnkLen,
|
|
|
|
LLVMMetadataRef File,
|
|
|
|
unsigned LineNo,
|
|
|
|
LLVMMetadataRef Ty,
|
|
|
|
LLVMBool LocalToUnit,
|
|
|
|
LLVMMetadataRef Decl,
|
|
|
|
uint32_t AlignInBits) {
|
|
|
|
return wrap(unwrap(Builder)->createTempGlobalVariableFwdDecl(
|
|
|
|
unwrapDI<DIScope>(Scope), {Name, NameLen}, {Linkage, LnkLen},
|
|
|
|
unwrapDI<DIFile>(File), LineNo, unwrapDI<DIType>(Ty),
|
|
|
|
LocalToUnit, unwrapDI<MDNode>(Decl), AlignInBits));
|
|
|
|
}
|
|
|
|
|
2018-04-23 03:24:44 +08:00
|
|
|
LLVMValueRef LLVMDIBuilderInsertDeclareBefore(
|
|
|
|
LLVMDIBuilderRef Builder, LLVMValueRef Storage, LLVMMetadataRef VarInfo,
|
|
|
|
LLVMMetadataRef Expr, LLVMMetadataRef DL, LLVMValueRef Instr) {
|
|
|
|
return wrap(unwrap(Builder)->insertDeclare(
|
|
|
|
unwrap(Storage), unwrap<DILocalVariable>(VarInfo),
|
|
|
|
unwrap<DIExpression>(Expr), unwrap<DILocation>(DL),
|
|
|
|
unwrap<Instruction>(Instr)));
|
|
|
|
}
|
|
|
|
|
|
|
|
LLVMValueRef LLVMDIBuilderInsertDeclareAtEnd(
|
|
|
|
LLVMDIBuilderRef Builder, LLVMValueRef Storage, LLVMMetadataRef VarInfo,
|
|
|
|
LLVMMetadataRef Expr, LLVMMetadataRef DL, LLVMBasicBlockRef Block) {
|
|
|
|
return wrap(unwrap(Builder)->insertDeclare(
|
|
|
|
unwrap(Storage), unwrap<DILocalVariable>(VarInfo),
|
|
|
|
unwrap<DIExpression>(Expr), unwrap<DILocation>(DL),
|
|
|
|
unwrap(Block)));
|
|
|
|
}
|
|
|
|
|
2018-04-24 06:31:49 +08:00
|
|
|
LLVMValueRef LLVMDIBuilderInsertDbgValueBefore(LLVMDIBuilderRef Builder,
|
|
|
|
LLVMValueRef Val,
|
|
|
|
LLVMMetadataRef VarInfo,
|
|
|
|
LLVMMetadataRef Expr,
|
|
|
|
LLVMMetadataRef DebugLoc,
|
|
|
|
LLVMValueRef Instr) {
|
|
|
|
return wrap(unwrap(Builder)->insertDbgValueIntrinsic(
|
|
|
|
unwrap(Val), unwrap<DILocalVariable>(VarInfo),
|
|
|
|
unwrap<DIExpression>(Expr), unwrap<DILocation>(DebugLoc),
|
|
|
|
unwrap<Instruction>(Instr)));
|
|
|
|
}
|
|
|
|
|
|
|
|
LLVMValueRef LLVMDIBuilderInsertDbgValueAtEnd(LLVMDIBuilderRef Builder,
|
|
|
|
LLVMValueRef Val,
|
|
|
|
LLVMMetadataRef VarInfo,
|
|
|
|
LLVMMetadataRef Expr,
|
|
|
|
LLVMMetadataRef DebugLoc,
|
|
|
|
LLVMBasicBlockRef Block) {
|
|
|
|
return wrap(unwrap(Builder)->insertDbgValueIntrinsic(
|
|
|
|
unwrap(Val), unwrap<DILocalVariable>(VarInfo),
|
|
|
|
unwrap<DIExpression>(Expr), unwrap<DILocation>(DebugLoc),
|
|
|
|
unwrap(Block)));
|
|
|
|
}
|
|
|
|
|
2018-04-23 03:24:44 +08:00
|
|
|
LLVMMetadataRef LLVMDIBuilderCreateAutoVariable(
|
|
|
|
LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
|
|
|
|
size_t NameLen, LLVMMetadataRef File, unsigned LineNo, LLVMMetadataRef Ty,
|
|
|
|
LLVMBool AlwaysPreserve, LLVMDIFlags Flags, uint32_t AlignInBits) {
|
|
|
|
return wrap(unwrap(Builder)->createAutoVariable(
|
|
|
|
unwrap<DIScope>(Scope), {Name, NameLen}, unwrap<DIFile>(File),
|
|
|
|
LineNo, unwrap<DIType>(Ty), AlwaysPreserve,
|
|
|
|
map_from_llvmDIFlags(Flags), AlignInBits));
|
|
|
|
}
|
|
|
|
|
|
|
|
LLVMMetadataRef LLVMDIBuilderCreateParameterVariable(
|
|
|
|
LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name,
|
|
|
|
size_t NameLen, unsigned ArgNo, LLVMMetadataRef File, unsigned LineNo,
|
|
|
|
LLVMMetadataRef Ty, LLVMBool AlwaysPreserve, LLVMDIFlags Flags) {
|
|
|
|
return wrap(unwrap(Builder)->createParameterVariable(
|
|
|
|
unwrap<DIScope>(Scope), Name, ArgNo, unwrap<DIFile>(File),
|
|
|
|
LineNo, unwrap<DIType>(Ty), AlwaysPreserve,
|
|
|
|
map_from_llvmDIFlags(Flags)));
|
|
|
|
}
|
|
|
|
|
2018-04-23 22:29:33 +08:00
|
|
|
LLVMMetadataRef LLVMDIBuilderGetOrCreateSubrange(LLVMDIBuilderRef Builder,
|
|
|
|
int64_t Lo, int64_t Count) {
|
|
|
|
return wrap(unwrap(Builder)->getOrCreateSubrange(Lo, Count));
|
|
|
|
}
|
|
|
|
|
|
|
|
LLVMMetadataRef LLVMDIBuilderGetOrCreateArray(LLVMDIBuilderRef Builder,
|
|
|
|
LLVMMetadataRef *Data,
|
|
|
|
size_t Length) {
|
|
|
|
Metadata **DataValue = unwrap(Data);
|
|
|
|
return wrap(unwrap(Builder)->getOrCreateArray({DataValue, Length}).get());
|
|
|
|
}
|
|
|
|
|
2018-04-07 14:07:55 +08:00
|
|
|
LLVMMetadataRef LLVMGetSubprogram(LLVMValueRef Func) {
|
|
|
|
return wrap(unwrap<Function>(Func)->getSubprogram());
|
|
|
|
}
|
|
|
|
|
|
|
|
void LLVMSetSubprogram(LLVMValueRef Func, LLVMMetadataRef SP) {
|
|
|
|
unwrap<Function>(Func)->setSubprogram(unwrap<DISubprogram>(SP));
|
|
|
|
}
|