Author: rsmith Date: Mon May 16 17:52:23 2016 New Revision: 269716 URL: http://llvm.org/viewvc/llvm-project?rev=269716&view=rev Log: Avoid O(n^2) string analysis when handling GNU __asm__ statements.
Modified: cfe/trunk/lib/AST/Stmt.cpp Modified: cfe/trunk/lib/AST/Stmt.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Stmt.cpp?rev=269716&r1=269715&r2=269716&view=diff ============================================================================== --- cfe/trunk/lib/AST/Stmt.cpp (original) +++ cfe/trunk/lib/AST/Stmt.cpp Mon May 16 17:52:23 2016 @@ -503,6 +503,9 @@ unsigned GCCAsmStmt::AnalyzeAsmString(Sm bool HasVariants = !C.getTargetInfo().hasNoAsmVariants(); + unsigned LastAsmStringToken = 0; + unsigned LastAsmStringOffset = 0; + while (1) { // Done with the string? if (CurPtr == StrEnd) { @@ -589,10 +592,12 @@ unsigned GCCAsmStmt::AnalyzeAsmString(Sm // (BeginLoc, EndLoc) represents the range of the operand we are currently // processing. Unlike Str, the range includes the leading '%'. - SourceLocation BeginLoc = - getAsmString()->getLocationOfByte(Percent - StrStart, SM, LO, TI); - SourceLocation EndLoc = - getAsmString()->getLocationOfByte(CurPtr - StrStart, SM, LO, TI); + SourceLocation BeginLoc = getAsmString()->getLocationOfByte( + Percent - StrStart, SM, LO, TI, &LastAsmStringToken, + &LastAsmStringOffset); + SourceLocation EndLoc = getAsmString()->getLocationOfByte( + CurPtr - StrStart, SM, LO, TI, &LastAsmStringToken, + &LastAsmStringOffset); Pieces.emplace_back(N, std::move(Str), BeginLoc, EndLoc); continue; @@ -623,10 +628,12 @@ unsigned GCCAsmStmt::AnalyzeAsmString(Sm // (BeginLoc, EndLoc) represents the range of the operand we are currently // processing. Unlike Str, the range includes the leading '%'. - SourceLocation BeginLoc = - getAsmString()->getLocationOfByte(Percent - StrStart, SM, LO, TI); - SourceLocation EndLoc = - getAsmString()->getLocationOfByte(NameEnd + 1 - StrStart, SM, LO, TI); + SourceLocation BeginLoc = getAsmString()->getLocationOfByte( + Percent - StrStart, SM, LO, TI, &LastAsmStringToken, + &LastAsmStringOffset); + SourceLocation EndLoc = getAsmString()->getLocationOfByte( + NameEnd + 1 - StrStart, SM, LO, TI, &LastAsmStringToken, + &LastAsmStringOffset); Pieces.emplace_back(N, std::move(Str), BeginLoc, EndLoc); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits