diff options
author | Alexis Engelke <engelke@in.tum.de> | 2024-08-06 18:33:26 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-06 18:33:26 +0200 |
commit | b7cd564fa3ecc2a9ed0fded98c24f68e2dad63ad (patch) | |
tree | 4ece9ebbe93c83fbdbff1612c8b5de8cbd1b5375 /llvm/lib/IR/AutoUpgrade.cpp | |
parent | 1d2b6d9d4d1074bac4a6ec48dd0ff4253590e34a (diff) | |
download | llvm-b7cd564fa3ecc2a9ed0fded98c24f68e2dad63ad.zip llvm-b7cd564fa3ecc2a9ed0fded98c24f68e2dad63ad.tar.gz llvm-b7cd564fa3ecc2a9ed0fded98c24f68e2dad63ad.tar.bz2 |
[IR] Don't verify module flags on every access (#102153)
8b4306ce050bd5 introduced validity checks for every module flag access,
because the auto-upgrader uses named metadata before verifying the
module.
This causes overhead for all other accesses, and the check is, in fact,
only need at that single place. Change the upgrader to be careful when
accessing module flags before the module is verified and remove the
checks on all other occasions.
There are two tangential optimizations included: first, when querying a
specific flag, don't enumerate all other flags into a vector as well.
Second, don't use a Twine for getNamedMetadata(), which has
materialization overhead -- all call sites use simple strings that can
be implicitly converted to a StringRef.
Diffstat (limited to 'llvm/lib/IR/AutoUpgrade.cpp')
-rw-r--r-- | llvm/lib/IR/AutoUpgrade.cpp | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/llvm/lib/IR/AutoUpgrade.cpp b/llvm/lib/IR/AutoUpgrade.cpp index 53de9ee..ec71975 100644 --- a/llvm/lib/IR/AutoUpgrade.cpp +++ b/llvm/lib/IR/AutoUpgrade.cpp @@ -4886,7 +4886,25 @@ bool llvm::UpgradeDebugInfo(Module &M) { if (DisableAutoUpgradeDebugInfo) return false; - unsigned Version = getDebugMetadataVersionFromModule(M); + // We need to get metadata before the module is verified (i.e., getModuleFlag + // makes assumptions that we haven't verified yet). Carefully extract the flag + // from the metadata. + unsigned Version = 0; + if (NamedMDNode *ModFlags = M.getModuleFlagsMetadata()) { + auto OpIt = find_if(ModFlags->operands(), [](const MDNode *Flag) { + if (Flag->getNumOperands() < 3) + return false; + if (MDString *K = dyn_cast_or_null<MDString>(Flag->getOperand(1))) + return K->getString() == "Debug Info Version"; + return false; + }); + if (OpIt != ModFlags->op_end()) { + const MDOperand &ValOp = (*OpIt)->getOperand(2); + if (auto *CI = mdconst::dyn_extract_or_null<ConstantInt>(ValOp)) + Version = CI->getZExtValue(); + } + } + if (Version == DEBUG_METADATA_VERSION) { bool BrokenDebugInfo = false; if (verifyModule(M, &llvm::errs(), &BrokenDebugInfo)) |