Skip to content

Commit f5ffedf

Browse files
authored
[clang][bytecode] Pass SourceInfo objects by value (#159532)
They are only pointer-sized and copying them is cheaper than taking the const ref.
1 parent 226b0a9 commit f5ffedf

File tree

5 files changed

+17
-17
lines changed

5 files changed

+17
-17
lines changed

clang/lib/AST/ByteCode/ByteCodeEmitter.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,7 @@ void emit(Program &P, llvm::SmallVectorImpl<std::byte> &Code,
207207
}
208208

209209
template <typename... Tys>
210-
bool ByteCodeEmitter::emitOp(Opcode Op, const Tys &...Args,
211-
const SourceInfo &SI) {
210+
bool ByteCodeEmitter::emitOp(Opcode Op, const Tys &...Args, SourceInfo SI) {
212211
bool Success = true;
213212

214213
// The opcode is followed by arguments. The source info is

clang/lib/AST/ByteCode/ByteCodeEmitter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class ByteCodeEmitter {
9999

100100
/// Emits an opcode.
101101
template <typename... Tys>
102-
bool emitOp(Opcode Op, const Tys &...Args, const SourceInfo &L);
102+
bool emitOp(Opcode Op, const Tys &...Args, SourceInfo L);
103103

104104
protected:
105105
#define GET_LINK_PROTO

clang/lib/AST/ByteCode/EvalEmitter.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ bool EvalEmitter::speculate(const CallExpr *E, const LabelTy &EndLabel) {
177177
return this->emitBool(true, E);
178178
}
179179

180-
template <PrimType OpType> bool EvalEmitter::emitRet(const SourceInfo &Info) {
180+
template <PrimType OpType> bool EvalEmitter::emitRet(SourceInfo Info) {
181181
if (!isActive())
182182
return true;
183183

@@ -186,7 +186,7 @@ template <PrimType OpType> bool EvalEmitter::emitRet(const SourceInfo &Info) {
186186
return true;
187187
}
188188

189-
template <> bool EvalEmitter::emitRet<PT_Ptr>(const SourceInfo &Info) {
189+
template <> bool EvalEmitter::emitRet<PT_Ptr>(SourceInfo Info) {
190190
if (!isActive())
191191
return true;
192192

@@ -247,12 +247,12 @@ template <> bool EvalEmitter::emitRet<PT_Ptr>(const SourceInfo &Info) {
247247
return true;
248248
}
249249

250-
bool EvalEmitter::emitRetVoid(const SourceInfo &Info) {
250+
bool EvalEmitter::emitRetVoid(SourceInfo Info) {
251251
EvalResult.setValid();
252252
return true;
253253
}
254254

255-
bool EvalEmitter::emitRetValue(const SourceInfo &Info) {
255+
bool EvalEmitter::emitRetValue(SourceInfo Info) {
256256
const auto &Ptr = S.Stk.pop<Pointer>();
257257

258258
if (!EvalResult.checkReturnValue(S, Ctx, Ptr, Info))
@@ -270,7 +270,7 @@ bool EvalEmitter::emitRetValue(const SourceInfo &Info) {
270270
return false;
271271
}
272272

273-
bool EvalEmitter::emitGetPtrLocal(uint32_t I, const SourceInfo &Info) {
273+
bool EvalEmitter::emitGetPtrLocal(uint32_t I, SourceInfo Info) {
274274
if (!isActive())
275275
return true;
276276

@@ -280,7 +280,7 @@ bool EvalEmitter::emitGetPtrLocal(uint32_t I, const SourceInfo &Info) {
280280
}
281281

282282
template <PrimType OpType>
283-
bool EvalEmitter::emitGetLocal(uint32_t I, const SourceInfo &Info) {
283+
bool EvalEmitter::emitGetLocal(uint32_t I, SourceInfo Info) {
284284
if (!isActive())
285285
return true;
286286

@@ -296,7 +296,7 @@ bool EvalEmitter::emitGetLocal(uint32_t I, const SourceInfo &Info) {
296296
}
297297

298298
template <PrimType OpType>
299-
bool EvalEmitter::emitSetLocal(uint32_t I, const SourceInfo &Info) {
299+
bool EvalEmitter::emitSetLocal(uint32_t I, SourceInfo Info) {
300300
if (!isActive())
301301
return true;
302302

@@ -310,7 +310,7 @@ bool EvalEmitter::emitSetLocal(uint32_t I, const SourceInfo &Info) {
310310
return true;
311311
}
312312

313-
bool EvalEmitter::emitDestroy(uint32_t I, const SourceInfo &Info) {
313+
bool EvalEmitter::emitDestroy(uint32_t I, SourceInfo Info) {
314314
if (!isActive())
315315
return true;
316316

clang/lib/AST/ByteCode/Source.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ class SourceInfo final {
9292
private:
9393
llvm::PointerUnion<const Decl *, const Stmt *> Source;
9494
};
95+
static_assert(sizeof(SourceInfo) == sizeof(void *));
9596

9697
using SourceMap = std::vector<std::pair<unsigned, SourceInfo>>;
9798

clang/utils/TableGen/ClangOpcodesEmitter.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ void ClangOpcodesEmitter::EmitEmitter(raw_ostream &OS, StringRef N,
200200
OS << (AsRef ? "const " : " ") << Name << " " << (AsRef ? "&" : "") << "A"
201201
<< I << ", ";
202202
}
203-
OS << "const SourceInfo &L) {\n";
203+
OS << "SourceInfo L) {\n";
204204

205205
// Emit a call to write the opcodes.
206206
OS << " return emitOp<";
@@ -231,7 +231,7 @@ void ClangOpcodesEmitter::EmitProto(raw_ostream &OS, StringRef N,
231231
OS << (AsRef ? "const " : " ") << Name << " " << (AsRef ? "&" : "")
232232
<< ", ";
233233
}
234-
OS << "const SourceInfo &);\n";
234+
OS << "SourceInfo);\n";
235235
});
236236

237237
// Emit a template method for custom emitters to have less to implement.
@@ -248,7 +248,7 @@ void ClangOpcodesEmitter::EmitProto(raw_ostream &OS, StringRef N,
248248
OS << "bool emit" << N << "(";
249249
for (const auto *Arg : Args)
250250
OS << Arg->getValueAsString("Name") << ", ";
251-
OS << "const SourceInfo &);\n";
251+
OS << "SourceInfo);\n";
252252
OS << "#endif\n";
253253
}
254254

@@ -272,7 +272,7 @@ void ClangOpcodesEmitter::EmitGroup(raw_ostream &OS, StringRef N,
272272
OS << "PrimType, ";
273273
for (auto *Arg : Args)
274274
OS << Arg->getValueAsString("Name") << ", ";
275-
OS << "const SourceInfo &I);\n";
275+
OS << "SourceInfo I);\n";
276276
OS << "#endif\n";
277277

278278
// Emit the dispatch implementation in the source.
@@ -294,7 +294,7 @@ void ClangOpcodesEmitter::EmitGroup(raw_ostream &OS, StringRef N,
294294
OS << (AsRef ? "const " : " ") << Name << " " << (AsRef ? "&" : "") << "A"
295295
<< I << ", ";
296296
}
297-
OS << "const SourceInfo &I) {\n";
297+
OS << "SourceInfo I) {\n";
298298

299299
std::function<void(size_t, const Twine &)> Rec;
300300
SmallVector<const Record *, 2> TS;
@@ -368,7 +368,7 @@ void ClangOpcodesEmitter::EmitEval(raw_ostream &OS, StringRef N,
368368
OS << (AsRef ? "const " : " ") << Name << " "
369369
<< (AsRef ? "&" : "") << "A" << I << ", ";
370370
}
371-
OS << "const SourceInfo &L) {\n";
371+
OS << "SourceInfo L) {\n";
372372
OS << " if (!isActive()) return true;\n";
373373
OS << " CurrentSource = L;\n";
374374

0 commit comments

Comments
 (0)