-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[clang][bytecode] Pass SourceInfo objects by value
#159532
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Member
|
@llvm/pr-subscribers-clang Author: Timm Baeder (tbaederr) ChangesThey are only pointer-sized and copying them is cheaper than taking the const ref. Full diff: https://github.com/llvm/llvm-project/pull/159532.diff 5 Files Affected:
diff --git a/clang/lib/AST/ByteCode/ByteCodeEmitter.cpp b/clang/lib/AST/ByteCode/ByteCodeEmitter.cpp
index 274efccac79dc..270e48ba830f2 100644
--- a/clang/lib/AST/ByteCode/ByteCodeEmitter.cpp
+++ b/clang/lib/AST/ByteCode/ByteCodeEmitter.cpp
@@ -207,8 +207,7 @@ void emit(Program &P, llvm::SmallVectorImpl<std::byte> &Code,
}
template <typename... Tys>
-bool ByteCodeEmitter::emitOp(Opcode Op, const Tys &...Args,
- const SourceInfo &SI) {
+bool ByteCodeEmitter::emitOp(Opcode Op, const Tys &...Args, SourceInfo SI) {
bool Success = true;
// The opcode is followed by arguments. The source info is
@@ -216,8 +215,9 @@ bool ByteCodeEmitter::emitOp(Opcode Op, const Tys &...Args,
emit(P, Code, Op, Success);
if (LocOverride)
SrcMap.emplace_back(Code.size(), *LocOverride);
- else if (SI)
+ else if (SI) {
SrcMap.emplace_back(Code.size(), SI);
+ }
(..., emit(P, Code, Args, Success));
return Success;
diff --git a/clang/lib/AST/ByteCode/ByteCodeEmitter.h b/clang/lib/AST/ByteCode/ByteCodeEmitter.h
index c050b299d8f61..ca8dc38e65246 100644
--- a/clang/lib/AST/ByteCode/ByteCodeEmitter.h
+++ b/clang/lib/AST/ByteCode/ByteCodeEmitter.h
@@ -99,7 +99,7 @@ class ByteCodeEmitter {
/// Emits an opcode.
template <typename... Tys>
- bool emitOp(Opcode Op, const Tys &...Args, const SourceInfo &L);
+ bool emitOp(Opcode Op, const Tys &...Args, SourceInfo L);
protected:
#define GET_LINK_PROTO
diff --git a/clang/lib/AST/ByteCode/EvalEmitter.cpp b/clang/lib/AST/ByteCode/EvalEmitter.cpp
index c7287999dd9c0..007321791fdd4 100644
--- a/clang/lib/AST/ByteCode/EvalEmitter.cpp
+++ b/clang/lib/AST/ByteCode/EvalEmitter.cpp
@@ -177,7 +177,7 @@ bool EvalEmitter::speculate(const CallExpr *E, const LabelTy &EndLabel) {
return this->emitBool(true, E);
}
-template <PrimType OpType> bool EvalEmitter::emitRet(const SourceInfo &Info) {
+template <PrimType OpType> bool EvalEmitter::emitRet(SourceInfo Info) {
if (!isActive())
return true;
@@ -186,7 +186,7 @@ template <PrimType OpType> bool EvalEmitter::emitRet(const SourceInfo &Info) {
return true;
}
-template <> bool EvalEmitter::emitRet<PT_Ptr>(const SourceInfo &Info) {
+template <> bool EvalEmitter::emitRet<PT_Ptr>(SourceInfo Info) {
if (!isActive())
return true;
@@ -247,12 +247,12 @@ template <> bool EvalEmitter::emitRet<PT_Ptr>(const SourceInfo &Info) {
return true;
}
-bool EvalEmitter::emitRetVoid(const SourceInfo &Info) {
+bool EvalEmitter::emitRetVoid(SourceInfo Info) {
EvalResult.setValid();
return true;
}
-bool EvalEmitter::emitRetValue(const SourceInfo &Info) {
+bool EvalEmitter::emitRetValue(SourceInfo Info) {
const auto &Ptr = S.Stk.pop<Pointer>();
if (!EvalResult.checkReturnValue(S, Ctx, Ptr, Info))
@@ -270,7 +270,7 @@ bool EvalEmitter::emitRetValue(const SourceInfo &Info) {
return false;
}
-bool EvalEmitter::emitGetPtrLocal(uint32_t I, const SourceInfo &Info) {
+bool EvalEmitter::emitGetPtrLocal(uint32_t I, SourceInfo Info) {
if (!isActive())
return true;
@@ -280,7 +280,7 @@ bool EvalEmitter::emitGetPtrLocal(uint32_t I, const SourceInfo &Info) {
}
template <PrimType OpType>
-bool EvalEmitter::emitGetLocal(uint32_t I, const SourceInfo &Info) {
+bool EvalEmitter::emitGetLocal(uint32_t I, SourceInfo Info) {
if (!isActive())
return true;
@@ -296,7 +296,7 @@ bool EvalEmitter::emitGetLocal(uint32_t I, const SourceInfo &Info) {
}
template <PrimType OpType>
-bool EvalEmitter::emitSetLocal(uint32_t I, const SourceInfo &Info) {
+bool EvalEmitter::emitSetLocal(uint32_t I, SourceInfo Info) {
if (!isActive())
return true;
@@ -310,7 +310,7 @@ bool EvalEmitter::emitSetLocal(uint32_t I, const SourceInfo &Info) {
return true;
}
-bool EvalEmitter::emitDestroy(uint32_t I, const SourceInfo &Info) {
+bool EvalEmitter::emitDestroy(uint32_t I, SourceInfo Info) {
if (!isActive())
return true;
diff --git a/clang/lib/AST/ByteCode/Source.h b/clang/lib/AST/ByteCode/Source.h
index d5d294e31d90c..f355d14db5e30 100644
--- a/clang/lib/AST/ByteCode/Source.h
+++ b/clang/lib/AST/ByteCode/Source.h
@@ -92,6 +92,7 @@ class SourceInfo final {
private:
llvm::PointerUnion<const Decl *, const Stmt *> Source;
};
+static_assert(sizeof(SourceInfo) == sizeof(void *));
using SourceMap = std::vector<std::pair<unsigned, SourceInfo>>;
diff --git a/clang/utils/TableGen/ClangOpcodesEmitter.cpp b/clang/utils/TableGen/ClangOpcodesEmitter.cpp
index 9d0773e1aff8f..d26122aca46bd 100644
--- a/clang/utils/TableGen/ClangOpcodesEmitter.cpp
+++ b/clang/utils/TableGen/ClangOpcodesEmitter.cpp
@@ -200,7 +200,7 @@ void ClangOpcodesEmitter::EmitEmitter(raw_ostream &OS, StringRef N,
OS << (AsRef ? "const " : " ") << Name << " " << (AsRef ? "&" : "") << "A"
<< I << ", ";
}
- OS << "const SourceInfo &L) {\n";
+ OS << "SourceInfo L) {\n";
// Emit a call to write the opcodes.
OS << " return emitOp<";
@@ -231,7 +231,7 @@ void ClangOpcodesEmitter::EmitProto(raw_ostream &OS, StringRef N,
OS << (AsRef ? "const " : " ") << Name << " " << (AsRef ? "&" : "")
<< ", ";
}
- OS << "const SourceInfo &);\n";
+ OS << "SourceInfo);\n";
});
// Emit a template method for custom emitters to have less to implement.
@@ -248,7 +248,7 @@ void ClangOpcodesEmitter::EmitProto(raw_ostream &OS, StringRef N,
OS << "bool emit" << N << "(";
for (const auto *Arg : Args)
OS << Arg->getValueAsString("Name") << ", ";
- OS << "const SourceInfo &);\n";
+ OS << "SourceInfo);\n";
OS << "#endif\n";
}
@@ -272,7 +272,7 @@ void ClangOpcodesEmitter::EmitGroup(raw_ostream &OS, StringRef N,
OS << "PrimType, ";
for (auto *Arg : Args)
OS << Arg->getValueAsString("Name") << ", ";
- OS << "const SourceInfo &I);\n";
+ OS << "SourceInfo I);\n";
OS << "#endif\n";
// Emit the dispatch implementation in the source.
@@ -294,7 +294,7 @@ void ClangOpcodesEmitter::EmitGroup(raw_ostream &OS, StringRef N,
OS << (AsRef ? "const " : " ") << Name << " " << (AsRef ? "&" : "") << "A"
<< I << ", ";
}
- OS << "const SourceInfo &I) {\n";
+ OS << "SourceInfo I) {\n";
std::function<void(size_t, const Twine &)> Rec;
SmallVector<const Record *, 2> TS;
@@ -368,7 +368,7 @@ void ClangOpcodesEmitter::EmitEval(raw_ostream &OS, StringRef N,
OS << (AsRef ? "const " : " ") << Name << " "
<< (AsRef ? "&" : "") << "A" << I << ", ";
}
- OS << "const SourceInfo &L) {\n";
+ OS << "SourceInfo L) {\n";
OS << " if (!isActive()) return true;\n";
OS << " CurrentSource = L;\n";
|
SourceInfo object by valueSourceInfo objects by value
8fb387f to
151dfc4
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
clang:bytecode
Issues for the clang bytecode constexpr interpreter
clang:frontend
Language frontend issues, e.g. anything involving "Sema"
clang
Clang issues not falling into any other category
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
They are only pointer-sized and copying them is cheaper than taking the const ref.