Skip to content

Commit b90cba1

Browse files
committed
[NFC][RemoveDIs] Shuffle header inclusions for "new" debug-info
BasicBlock.h and Instruction.h will eventually need to include DebugProgramInstruction.h so that debug-info attached to instructions can be enumerated and cloned. Originally including it made compiling clang much slower, I think I've pinned that down as being the inclusion of DebugInfoMetadata.h causing ~every LLVM translation unit to parse all the debug-info classes. This patch avoids that by shifting some functions into the cpp file rather than the header, and restores the inclusion of DebugProgramInstruction.h in BasicBlock.h so that the rest of the RemoveDIs functionality can land.
1 parent 220abb0 commit b90cba1

File tree

3 files changed

+30
-25
lines changed

3 files changed

+30
-25
lines changed

llvm/include/llvm/IR/BasicBlock.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "llvm/ADT/iterator.h"
2121
#include "llvm/ADT/iterator_range.h"
2222
#include "llvm/IR/Instruction.h"
23+
#include "llvm/IR/DebugProgramInstruction.h"
2324
#include "llvm/IR/SymbolTableListTraits.h"
2425
#include "llvm/IR/Value.h"
2526
#include <cassert>

llvm/include/llvm/IR/DebugProgramInstruction.h

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,8 @@
5050
#include "llvm/ADT/ilist_node.h"
5151
#include "llvm/ADT/ilist.h"
5252
#include "llvm/ADT/iterator.h"
53-
#include "llvm/IR/DebugInfoMetadata.h"
53+
#include "llvm/ADT/SmallPtrSet.h"
5454
#include "llvm/IR/DebugLoc.h"
55-
#include <cstdint>
56-
#include <utility>
5755

5856
namespace llvm {
5957

@@ -186,11 +184,7 @@ class DPValue : public ilist_node<DPValue>, private DebugValueUser {
186184

187185
void setExpression(DIExpression *NewExpr) { Expression = NewExpr; }
188186

189-
unsigned getNumVariableLocationOps() const {
190-
if (hasArgList())
191-
return cast<DIArgList>(getRawLocation())->getArgs().size();
192-
return 1;
193-
}
187+
unsigned getNumVariableLocationOps() const;
194188

195189
bool hasArgList() const { return isa<DIArgList>(getRawLocation()); }
196190
/// Returns true if this DPValue has no empty MDNodes in its location list.
@@ -204,23 +198,8 @@ class DPValue : public ilist_node<DPValue>, private DebugValueUser {
204198
DebugLoc getDebugLoc() const { return DbgLoc; }
205199
void setDebugLoc(DebugLoc Loc) { DbgLoc = std::move(Loc); }
206200

207-
void setKillLocation() {
208-
// TODO: When/if we remove duplicate values from DIArgLists, we don't need
209-
// this set anymore.
210-
SmallPtrSet<Value *, 4> RemovedValues;
211-
for (Value *OldValue : location_ops()) {
212-
if (!RemovedValues.insert(OldValue).second)
213-
continue;
214-
Value *Poison = PoisonValue::get(OldValue->getType());
215-
replaceVariableLocationOp(OldValue, Poison);
216-
}
217-
}
218-
219-
bool isKillLocation() const {
220-
return (getNumVariableLocationOps() == 0 &&
221-
!getExpression()->isComplex()) ||
222-
any_of(location_ops(), [](Value *V) { return isa<UndefValue>(V); });
223-
}
201+
void setKillLocation();
202+
bool isKillLocation() const;
224203

225204
DILocalVariable *getVariable() const { return Variable; }
226205

llvm/lib/IR/DebugProgramInstruction.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9+
#include "llvm/IR/DebugInfoMetadata.h"
910
#include "llvm/IR/DebugProgramInstruction.h"
1011
#include "llvm/IR/DIBuilder.h"
1112
#include "llvm/IR/IntrinsicInst.h"
@@ -64,6 +65,12 @@ iterator_range<DPValue::location_op_iterator> DPValue::location_ops() const {
6465
location_op_iterator(static_cast<ValueAsMetadata *>(nullptr))};
6566
}
6667

68+
unsigned DPValue::getNumVariableLocationOps() const {
69+
if (hasArgList())
70+
return cast<DIArgList>(getRawLocation())->getArgs().size();
71+
return 1;
72+
}
73+
6774
Value *DPValue::getVariableLocationOp(unsigned OpIdx) const {
6875
auto *MD = getRawLocation();
6976
if (!MD)
@@ -150,6 +157,24 @@ void DPValue::addVariableLocationOps(ArrayRef<Value *> NewValues,
150157
setRawLocation(DIArgList::get(getVariableLocationOp(0)->getContext(), MDs));
151158
}
152159

160+
void DPValue::setKillLocation() {
161+
// TODO: When/if we remove duplicate values from DIArgLists, we don't need
162+
// this set anymore.
163+
SmallPtrSet<Value *, 4> RemovedValues;
164+
for (Value *OldValue : location_ops()) {
165+
if (!RemovedValues.insert(OldValue).second)
166+
continue;
167+
Value *Poison = PoisonValue::get(OldValue->getType());
168+
replaceVariableLocationOp(OldValue, Poison);
169+
}
170+
}
171+
172+
bool DPValue::isKillLocation() const {
173+
return (getNumVariableLocationOps() == 0 &&
174+
!getExpression()->isComplex()) ||
175+
any_of(location_ops(), [](Value *V) { return isa<UndefValue>(V); });
176+
}
177+
153178
std::optional<uint64_t> DPValue::getFragmentSizeInBits() const {
154179
if (auto Fragment = getExpression()->getFragmentInfo())
155180
return Fragment->SizeInBits;

0 commit comments

Comments
 (0)