[llvm] d8ebb80 - [AsmParserContext] Fix regression after #174566 (#180068)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 12 08:29:59 PST 2026
Author: Bertik23
Date: 2026-02-12T17:29:54+01:00
New Revision: d8ebb80e9419645fa647e1f40da1cc828a3047a6
URL: https://github.com/llvm/llvm-project/commit/d8ebb80e9419645fa647e1f40da1cc828a3047a6
DIFF: https://github.com/llvm/llvm-project/commit/d8ebb80e9419645fa647e1f40da1cc828a3047a6.diff
LOG: [AsmParserContext] Fix regression after #174566 (#180068)
This fixes the regressions after merging #174566
The problem was, that the lookup of the location takes logarithmic time
as a function of the number of lines, and a large number of lines causes
the slowdowns. Now all the lookups are guarded with checks if the
AsmParserContext was passed in, to not waste time on information, that
isn't requested.
Added:
Modified:
llvm/include/llvm/AsmParser/LLParser.h
llvm/lib/AsmParser/LLParser.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/AsmParser/LLParser.h b/llvm/include/llvm/AsmParser/LLParser.h
index a7d90a8168960..2db7f3423fce2 100644
--- a/llvm/include/llvm/AsmParser/LLParser.h
+++ b/llvm/include/llvm/AsmParser/LLParser.h
@@ -194,6 +194,18 @@ namespace llvm {
std::string SourceFileName;
+ FileLoc getTokLineColumnPos() {
+ if (ParserContext)
+ return Lex.getTokLineColumnPos();
+ return {0u, 0u};
+ }
+
+ FileLoc getPrevTokEndLineColumnPos() {
+ if (ParserContext)
+ return Lex.getPrevTokEndLineColumnPos();
+ return {0u, 0u};
+ }
+
public:
LLParser(StringRef F, SourceMgr &SM, SMDiagnostic &Err, Module *M,
ModuleSummaryIndex *Index, LLVMContext &Context,
diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp
index 5b916711690ec..2dfd070e068d0 100644
--- a/llvm/lib/AsmParser/LLParser.cpp
+++ b/llvm/lib/AsmParser/LLParser.cpp
@@ -755,7 +755,8 @@ bool LLParser::parseDeclare() {
/// ::= 'define' FunctionHeader (!dbg !56)* '{' ...
bool LLParser::parseDefine() {
assert(Lex.getKind() == lltok::kw_define);
- FileLoc FunctionStart(Lex.getTokLineColumnPos());
+
+ FileLoc FunctionStart = getTokLineColumnPos();
Lex.Lex();
Function *F;
@@ -767,7 +768,7 @@ bool LLParser::parseDefine() {
parseFunctionBody(*F, FunctionNumber, UnnamedArgNums);
if (ParserContext)
ParserContext->addFunctionLocation(
- F, FileLocRange(FunctionStart, Lex.getPrevTokEndLineColumnPos()));
+ F, FileLocRange(FunctionStart, getPrevTokEndLineColumnPos()));
return RetValue;
}
@@ -3536,18 +3537,18 @@ bool LLParser::parseArgumentList(SmallVectorImpl<ArgInfo> &ArgList,
bool Unnamed = false;
if (Lex.getKind() == lltok::LocalVar) {
Name = Lex.getStrVal();
- IdentStart = Lex.getTokLineColumnPos();
+ IdentStart = getTokLineColumnPos();
Lex.Lex();
- IdentEnd = Lex.getPrevTokEndLineColumnPos();
+ IdentEnd = getPrevTokEndLineColumnPos();
} else {
unsigned ArgID;
if (Lex.getKind() == lltok::LocalVarID) {
ArgID = Lex.getUIntVal();
- IdentStart = Lex.getTokLineColumnPos();
+ IdentStart = getTokLineColumnPos();
if (checkValueID(TypeLoc, "argument", "%", CurValID, ArgID))
return true;
Lex.Lex();
- IdentEnd = Lex.getPrevTokEndLineColumnPos();
+ IdentEnd = getPrevTokEndLineColumnPos();
} else {
ArgID = CurValID;
Unnamed = true;
@@ -6830,11 +6831,12 @@ bool LLParser::parseValue(Type *Ty, Value *&V, PerFunctionState *PFS) {
V = nullptr;
ValID ID;
- FileLoc Start = Lex.getTokLineColumnPos();
+ FileLoc Start = getTokLineColumnPos();
bool Ret = parseValID(ID, PFS, Ty) || convertValIDToValue(Ty, ID, V, PFS);
- FileLoc End = Lex.getPrevTokEndLineColumnPos();
- if (!Ret && ParserContext)
+ if (!Ret && ParserContext) {
+ FileLoc End = getPrevTokEndLineColumnPos();
ParserContext->addValueReferenceAtLocation(V, FileLocRange(Start, End));
+ }
return Ret;
}
@@ -7200,7 +7202,7 @@ bool LLParser::parseFunctionBody(Function &Fn, unsigned FunctionNumber,
/// parseBasicBlock
/// ::= (LabelStr|LabelID)? Instruction*
bool LLParser::parseBasicBlock(PerFunctionState &PFS) {
- FileLoc BBStart(Lex.getTokLineColumnPos());
+ FileLoc BBStart = getTokLineColumnPos();
// If this basic block starts out with a name, remember it.
std::string Name;
@@ -7243,7 +7245,7 @@ bool LLParser::parseBasicBlock(PerFunctionState &PFS) {
TrailingDbgRecord.emplace_back(DR, DeleteDbgRecord);
}
- FileLoc InstStart(Lex.getTokLineColumnPos());
+ FileLoc InstStart = getTokLineColumnPos();
// This instruction may have three possibilities for a name: a) none
// specified, b) name specified "%foo =", c) number specified: "%4 =".
LocTy NameLoc = Lex.getLoc();
@@ -7295,13 +7297,13 @@ bool LLParser::parseBasicBlock(PerFunctionState &PFS) {
TrailingDbgRecord.clear();
if (ParserContext) {
ParserContext->addInstructionOrArgumentLocation(
- Inst, FileLocRange(InstStart, Lex.getPrevTokEndLineColumnPos()));
+ Inst, FileLocRange(InstStart, getPrevTokEndLineColumnPos()));
}
} while (!Inst->isTerminator());
if (ParserContext)
ParserContext->addBlockLocation(
- BB, FileLocRange(BBStart, Lex.getPrevTokEndLineColumnPos()));
+ BB, FileLocRange(BBStart, getPrevTokEndLineColumnPos()));
assert(TrailingDbgRecord.empty() &&
"All debug values should have been attached to an instruction.");
More information about the llvm-commits
mailing list