Skip to content

Commit 2bb7292

Browse files
authored
[clang] Remove source range from CXXOperatorCallExpr (#147028)
This patch stops storing a source range in `CXXOperatorCallExpr` and keeps only the begin location. This change allows us to retain the optimization #141058 when switching to 64-bit source locations. Performance results: https://llvm-compile-time-tracker.com/compare.php?from=0588e8188c647460b641b09467fe6b13a8d510d5&to=5958f83476a8b8ba97936f262396d3ff98fb1662&stat=instructions:u
1 parent 6855573 commit 2bb7292

File tree

5 files changed

+7
-8
lines changed

5 files changed

+7
-8
lines changed

clang/include/clang/AST/ExprCXX.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class CXXOperatorCallExpr final : public CallExpr {
8484
friend class ASTStmtReader;
8585
friend class ASTStmtWriter;
8686

87-
SourceRange Range;
87+
SourceLocation BeginLoc;
8888

8989
// CXXOperatorCallExpr has some trailing objects belonging
9090
// to CallExpr. See CallExpr for the details.
@@ -158,9 +158,9 @@ class CXXOperatorCallExpr final : public CallExpr {
158158
: getOperatorLoc();
159159
}
160160

161-
SourceLocation getBeginLoc() const { return Range.getBegin(); }
162-
SourceLocation getEndLoc() const { return Range.getEnd(); }
163-
SourceRange getSourceRange() const { return Range; }
161+
SourceLocation getBeginLoc() const { return BeginLoc; }
162+
SourceLocation getEndLoc() const { return getSourceRangeImpl().getEnd(); }
163+
SourceRange getSourceRange() const { return getSourceRangeImpl(); }
164164

165165
static bool classof(const Stmt *T) {
166166
return T->getStmtClass() == CXXOperatorCallExprClass;

clang/lib/AST/ExprCXX.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ CXXOperatorCallExpr::CXXOperatorCallExpr(OverloadedOperatorKind OpKind,
600600
assert(
601601
(CXXOperatorCallExprBits.OperatorKind == static_cast<unsigned>(OpKind)) &&
602602
"OperatorKind overflow!");
603-
Range = getSourceRangeImpl();
603+
BeginLoc = getSourceRangeImpl().getBegin();
604604
}
605605

606606
CXXOperatorCallExpr::CXXOperatorCallExpr(unsigned NumArgs, bool HasFPFeatures,

clang/lib/Serialization/ASTReaderStmt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1733,7 +1733,7 @@ void ASTStmtReader::VisitMSDependentExistsStmt(MSDependentExistsStmt *S) {
17331733
void ASTStmtReader::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
17341734
VisitCallExpr(E);
17351735
E->CXXOperatorCallExprBits.OperatorKind = Record.readInt();
1736-
E->Range = Record.readSourceRange();
1736+
E->BeginLoc = Record.readSourceLocation();
17371737
}
17381738

17391739
void ASTStmtReader::VisitCXXRewrittenBinaryOperator(

clang/lib/Serialization/ASTWriterDecl.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2933,7 +2933,6 @@ void ASTWriter::WriteDeclAbbrevs() {
29332933
// CXXOperatorCallExpr
29342934
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Operator Kind
29352935
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location
2936-
Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Source Location
29372936
CXXOperatorCallExprAbbrev = Stream.EmitAbbrev(std::move(Abv));
29382937

29392938
// Abbreviation for EXPR_CXX_MEMBER_CALL

clang/lib/Serialization/ASTWriterStmt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1702,7 +1702,7 @@ void ASTStmtWriter::VisitMSDependentExistsStmt(MSDependentExistsStmt *S) {
17021702
void ASTStmtWriter::VisitCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
17031703
VisitCallExpr(E);
17041704
Record.push_back(E->getOperator());
1705-
Record.AddSourceRange(E->Range);
1705+
Record.AddSourceLocation(E->BeginLoc);
17061706

17071707
if (!E->hasStoredFPFeatures() && !static_cast<bool>(E->getADLCallKind()))
17081708
AbbrevToUse = Writer.getCXXOperatorCallExprAbbrev();

0 commit comments

Comments
 (0)