diff options
| author | Daniel Sanders <daniel_l_sanders@apple.com> | 2019-09-18 18:14:42 +0000 |
|---|---|---|
| committer | Daniel Sanders <daniel_l_sanders@apple.com> | 2019-09-18 18:14:42 +0000 |
| commit | 1723364a68487c1c070ca58799a0a5c39adca85d (patch) | |
| tree | f0694c4e338256372f001cc4b97bdc85ca0cacd5 /llvm/utils | |
| parent | 85e26f56cbf3e1ae3aed155b817912f02172bbef (diff) | |
| download | bcm5719-llvm-1723364a68487c1c070ca58799a0a5c39adca85d.tar.gz bcm5719-llvm-1723364a68487c1c070ca58799a0a5c39adca85d.zip | |
Fix compile-time regression caused by rL371928
Summary:
Also fixup rL371928 for cases that occur on our out-of-tree backend
There were still quite a few intermediate APInts and this caused the
compile time of MCCodeEmitter for our target to jump from 16s up to
~5m40s. This patch, brings it back down to ~17s by eliminating pretty
much all of them using two new APInt functions (extractBitsAsZExtValue(),
insertBits() but with a uint64_t). The exact conditions for eliminating
them is that the field extracted/inserted must be <=64-bit which is
almost always true.
Note: The two new APInt API's assume that APInt::WordSize is at least
64-bit because that means they touch at most 2 APInt words. They
statically assert that's true. It seems very unlikely that someone
is patching it to be smaller so this should be fine.
Reviewers: jmolloy
Reviewed By: jmolloy
Subscribers: hiraditya, dexonsmith, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D67686
llvm-svn: 372243
Diffstat (limited to 'llvm/utils')
| -rw-r--r-- | llvm/utils/TableGen/CodeEmitterGen.cpp | 70 |
1 files changed, 40 insertions, 30 deletions
diff --git a/llvm/utils/TableGen/CodeEmitterGen.cpp b/llvm/utils/TableGen/CodeEmitterGen.cpp index 907fa1e8463..10c42bbc6ff 100644 --- a/llvm/utils/TableGen/CodeEmitterGen.cpp +++ b/llvm/utils/TableGen/CodeEmitterGen.cpp @@ -212,40 +212,47 @@ AddCodeToMergeInOperand(Record *R, BitsInit *BI, const std::string &VarName, std::string maskStr; int opShift; + unsigned loBit = beginVarBit - N + 1; + unsigned hiBit = loBit + N; + unsigned loInstBit = beginInstBit - N + 1; if (UseAPInt) { - unsigned loBit = beginVarBit - N + 1; - unsigned hiBit = loBit + N; - maskStr = "M" + itostr(bit); - Case += " const APInt " + maskStr + " = APInt::getBitsSet(" + - itostr(BitWidth) + ", " + itostr(loBit) + ", " + itostr(hiBit) + - ");\n"; + std::string extractStr; + if (N >= 64) { + extractStr = "op.extractBits(" + itostr(hiBit - loBit) + ", " + + itostr(loBit) + ")"; + Case += " Value.insertBits(" + extractStr + ", " + + itostr(loInstBit) + ");\n"; + } else { + extractStr = "op.extractBitsAsZExtValue(" + itostr(hiBit - loBit) + + ", " + itostr(loBit) + ")"; + Case += " Value.insertBits(" + extractStr + ", " + + itostr(loInstBit) + ", " + itostr(hiBit - loBit) + ");\n"; + } } else { uint64_t opMask = ~(uint64_t)0 >> (64 - N); opShift = beginVarBit - N + 1; opMask <<= opShift; maskStr = "UINT64_C(" + utostr(opMask) + ")"; - } - opShift = beginInstBit - beginVarBit; - - if (numOperandLits == 1) { - // Because Op may be an APInt, ensure all arithmetic is done in-place - // where possible to elide copies. - Case += " op &= " + maskStr + ";\n"; - if (opShift > 0) { - Case += " op <<= " + itostr(opShift) + ";\n"; - } else if (opShift < 0) { - Case += " op >>= " + itostr(-opShift) + ";\n"; - } - Case += " Value |= op;\n"; - } else { - if (opShift > 0) { - Case += " Value |= (op & " + maskStr + ") << " + itostr(opShift) + - ";\n"; - } else if (opShift < 0) { - Case += " Value |= (op & " + maskStr + ") >> " + itostr(-opShift) + - ";\n"; + opShift = beginInstBit - beginVarBit; + + if (numOperandLits == 1) { + Case += " op &= " + maskStr + ";\n"; + if (opShift > 0) { + Case += " op <<= " + itostr(opShift) + ";\n"; + } else if (opShift < 0) { + Case += " op >>= " + itostr(-opShift) + ";\n"; + } + Case += " Value |= op;\n"; } else { - Case += " Value |= (op & " + maskStr + ");\n"; + if (opShift > 0) { + Case += " Value |= (op & " + maskStr + ") << " + + itostr(opShift) + ";\n"; + } else if (opShift < 0) { + Case += " Value |= (op & " + maskStr + ") >> " + + itostr(-opShift) + ";\n"; + } else { + Case += " Value |= (op & " + maskStr + ");\n"; + } } } } @@ -436,9 +443,12 @@ void CodeEmitterGen::run(raw_ostream &o) { << " raw_string_ostream Msg(msg);\n" << " Msg << \"Not supported instr: \" << MI;\n" << " report_fatal_error(Msg.str());\n" - << " }\n" - << " return Value;\n" - << "}\n\n"; + << " }\n"; + if (UseAPInt) + o << " Inst = Value;\n"; + else + o << " return Value;\n"; + o << "}\n\n"; const auto &All = SubtargetFeatureInfo::getAll(Records); std::map<Record *, SubtargetFeatureInfo, LessRecordByID> SubtargetFeatures; |

