[llvm] r247250 - [ADT] Micro-optimize the Triple constructor by doing a single split and
Chandler Carruth via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 10 00:51:43 PDT 2015
Author: chandlerc
Date: Thu Sep 10 02:51:43 2015
New Revision: 247250
URL: http://llvm.org/viewvc/llvm-project?rev=247250&view=rev
Log:
[ADT] Micro-optimize the Triple constructor by doing a single split and
re-using the resulting components rather than repeatedly splitting and
re-splitting to compute each component as part of the initializer list.
This is more work on PR23676. Sadly, it doesn't help much. It removes
the constructor from my profile, but doesn't make a sufficient dent in
the total time. But it should play together nicely with subsequent
changes.
Modified:
llvm/trunk/lib/Support/Triple.cpp
Modified: llvm/trunk/lib/Support/Triple.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Triple.cpp?rev=247250&r1=247249&r2=247250&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Triple.cpp (original)
+++ llvm/trunk/lib/Support/Triple.cpp Thu Sep 10 02:51:43 2015
@@ -572,14 +572,27 @@ static Triple::ObjectFormatType getDefau
/// This stores the string representation and parses the various pieces into
/// enum members.
Triple::Triple(const Twine &Str)
- : Data(Str.str()),
- Arch(parseArch(getArchName())),
- SubArch(parseSubArch(getArchName())),
- Vendor(parseVendor(getVendorName())),
- OS(parseOS(getOSName())),
- Environment(parseEnvironment(getEnvironmentName())),
- ObjectFormat(parseFormat(getEnvironmentName())) {
- if (ObjectFormat == Triple::UnknownObjectFormat)
+ : Data(Str.str()), Arch(UnknownArch), SubArch(NoSubArch),
+ Vendor(UnknownVendor), OS(UnknownOS), Environment(UnknownEnvironment),
+ ObjectFormat(UnknownObjectFormat) {
+ // Do minimal parsing by hand here.
+ SmallVector<StringRef, 4> Components;
+ StringRef(Data).split(Components, '-', /*MaxSplit*/ 3);
+ if (Components.size() > 0) {
+ Arch = parseArch(Components[0]);
+ SubArch = parseSubArch(Components[0]);
+ if (Components.size() > 1) {
+ Vendor = parseVendor(Components[1]);
+ if (Components.size() > 2) {
+ OS = parseOS(Components[2]);
+ if (Components.size() > 3) {
+ Environment = parseEnvironment(Components[3]);
+ ObjectFormat = parseFormat(Components[3]);
+ }
+ }
+ }
+ }
+ if (ObjectFormat == UnknownObjectFormat)
ObjectFormat = getDefaultFormat(*this);
}
More information about the llvm-commits
mailing list