Skip to content

Commit da100de

Browse files
OCHyamsRalender
authored andcommitted
[NFC][DwarfDebug] Add test for variables with a single location which
don't span their entire scope. The previous commit (6d1c40c) is an older version of the test. Reviewed By: aprantl, vsk Differential Revision: https://reviews.llvm.org/D79573
1 parent 72edb79 commit da100de

15 files changed

+967
-80
lines changed

llvm/include/llvm/Analysis/AssumeBundleQueries.h

+8
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ inline RetainedKnowledge getKnowledgeFromUseInAssume(const Use *U) {
122122
U->getOperandNo());
123123
}
124124

125+
/// Tag in operand bundle indicating that this bundle should be ignored.
126+
constexpr StringRef IgnoreBundleTag = "ignore";
127+
125128
/// Return true iff the operand bundles of the provided llvm.assume doesn't
126129
/// contain any valuable information. This is true when:
127130
/// - The operand bundle is empty
@@ -154,6 +157,11 @@ RetainedKnowledge getKnowledgeValidInContext(
154157
const Instruction *CtxI, const DominatorTree *DT = nullptr,
155158
AssumptionCache *AC = nullptr);
156159

160+
/// This extracts the Knowledge from an element of an operand bundle.
161+
/// This is mostly for use in the assume builder.
162+
RetainedKnowledge getKnowledgeFromBundle(CallInst &Assume,
163+
const CallBase::BundleOpInfo &BOI);
164+
157165
} // namespace llvm
158166

159167
#endif

llvm/include/llvm/IR/LLVMContext.h

+5
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class LLVMContextImpl;
3131
class Module;
3232
class OptPassGate;
3333
template <typename T> class SmallVectorImpl;
34+
template <typename T> class StringMapEntry;
3435
class SMDiagnostic;
3536
class StringRef;
3637
class Twine;
@@ -107,6 +108,10 @@ class LLVMContext {
107108
/// \see LLVMContext::getOperandBundleTagID
108109
void getOperandBundleTags(SmallVectorImpl<StringRef> &Result) const;
109110

111+
/// getOrInsertBundleTag - Returns the Tag to use for an operand bundle of
112+
/// name TagName.
113+
StringMapEntry<uint32_t> *getOrInsertBundleTag(StringRef TagName) const;
114+
110115
/// getOperandBundleTagID - Maps a bundle tag to an integer ID. Every bundle
111116
/// tag registered with an LLVMContext has an unique ID.
112117
uint32_t getOperandBundleTagID(StringRef Tag) const;

llvm/include/llvm/InitializePasses.h

+1
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ void initializeAggressiveInstCombinerLegacyPassPass(PassRegistry&);
7171
void initializeAliasSetPrinterPass(PassRegistry&);
7272
void initializeAlignmentFromAssumptionsPass(PassRegistry&);
7373
void initializeAlwaysInlinerLegacyPassPass(PassRegistry&);
74+
void initializeAssumeSimplifyPassLegacyPassPass(PassRegistry &);
7475
void initializeOpenMPOptLegacyPassPass(PassRegistry &);
7576
void initializeArgPromotionPass(PassRegistry&);
7677
void initializeAssumptionCacheTrackerPass(PassRegistry&);

llvm/include/llvm/Transforms/Utils.h

+8-1
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,13 @@ FunctionPass *createUnifyLoopExitsPass();
147147
// into a natural loop.
148148
//
149149
FunctionPass *createFixIrreduciblePass();
150-
}
150+
151+
//===----------------------------------------------------------------------===//
152+
//
153+
// AssumeSimplify - remove redundant assumes and merge assumes in the same
154+
// BasicBlock when possible.
155+
//
156+
FunctionPass *createAssumeSimplifyPass();
157+
} // namespace llvm
151158

152159
#endif

llvm/include/llvm/Transforms/Utils/AssumeBundleBuilder.h

+8
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ IntrinsicInst *buildAssumeFromInst(Instruction *I);
4141
void salvageKnowledge(Instruction *I, AssumptionCache *AC = nullptr,
4242
DominatorTree *DT = nullptr);
4343

44+
/// This pass attempts to minimize the number of assume without loosing any
45+
/// information.
46+
struct AssumeSimplifyPass : public PassInfoMixin<AssumeSimplifyPass> {
47+
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);
48+
};
49+
50+
FunctionPass *createAssumeSimplifyPass();
51+
4452
/// This pass will try to build an llvm.assume for every instruction in the
4553
/// function. Its main purpose is testing.
4654
struct AssumeBuilderPass : public PassInfoMixin<AssumeBuilderPass> {

llvm/lib/Analysis/AssumeBundleQueries.cpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,13 @@ void llvm::fillMapFromAssume(CallInst &AssumeCI, RetainedKnowledgeMap &Result) {
8989
}
9090
}
9191

92-
static RetainedKnowledge
93-
getKnowledgeFromBundle(CallInst &Assume, const CallBase::BundleOpInfo &BOI) {
92+
RetainedKnowledge
93+
llvm::getKnowledgeFromBundle(CallInst &Assume,
94+
const CallBase::BundleOpInfo &BOI) {
9495
RetainedKnowledge Result;
9596
Result.AttrKind = Attribute::getAttrKindFromName(BOI.Tag->getKey());
96-
Result.WasOn = getValueFromBundleOpInfo(Assume, BOI, ABA_WasOn);
97+
if (bundleHasArgument(BOI, ABA_WasOn))
98+
Result.WasOn = getValueFromBundleOpInfo(Assume, BOI, ABA_WasOn);
9799
if (BOI.End - BOI.Begin > ABA_Argument)
98100
Result.ArgValue =
99101
cast<ConstantInt>(getValueFromBundleOpInfo(Assume, BOI, ABA_Argument))
@@ -116,7 +118,7 @@ bool llvm::isAssumeWithEmptyBundle(CallInst &CI) {
116118
"this function is intended to be used on llvm.assume");
117119
return none_of(Assume.bundle_op_infos(),
118120
[](const CallBase::BundleOpInfo &BOI) {
119-
return BOI.Tag->getKey() != "ignore";
121+
return BOI.Tag->getKey() != IgnoreBundleTag;
120122
});
121123
}
122124

llvm/lib/Analysis/AssumptionCache.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ findAffectedValues(CallInst *CI,
8080

8181
for (unsigned Idx = 0; Idx != CI->getNumOperandBundles(); Idx++) {
8282
if (CI->getOperandBundleAt(Idx).Inputs.size() > ABA_WasOn &&
83-
CI->getOperandBundleAt(Idx).getTagName() != "ignore")
83+
CI->getOperandBundleAt(Idx).getTagName() != IgnoreBundleTag)
8484
AddAffected(CI->getOperandBundleAt(Idx).Inputs[ABA_WasOn], Idx);
8585
}
8686

llvm/lib/IR/LLVMContext.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,11 @@ void LLVMContext::getOperandBundleTags(SmallVectorImpl<StringRef> &Tags) const {
282282
pImpl->getOperandBundleTags(Tags);
283283
}
284284

285+
StringMapEntry<uint32_t> *
286+
LLVMContext::getOrInsertBundleTag(StringRef TagName) const {
287+
return pImpl->getOrInsertBundleTag(TagName);
288+
}
289+
285290
uint32_t LLVMContext::getOperandBundleTagID(StringRef Tag) const {
286291
return pImpl->getOperandBundleTagID(Tag);
287292
}

llvm/lib/Passes/PassBuilder.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ extern cl::opt<bool> EnableOrderFileInstrumentation;
259259
extern cl::opt<bool> FlattenedProfileUsed;
260260

261261
extern cl::opt<AttributorRunOption> AttributorRun;
262+
extern cl::opt<bool> EnableKnowledgeRetention;
262263

263264
const PassBuilder::OptimizationLevel PassBuilder::OptimizationLevel::O0 = {
264265
/*SpeedLevel*/ 0,
@@ -425,6 +426,8 @@ PassBuilder::buildFunctionSimplificationPipeline(OptimizationLevel Level,
425426

426427
// Catch trivial redundancies
427428
FPM.addPass(EarlyCSEPass(true /* Enable mem-ssa. */));
429+
if (EnableKnowledgeRetention)
430+
FPM.addPass(AssumeSimplifyPass());
428431

429432
// Hoisting of scalars and load expressions.
430433
if (Level.getSpeedupLevel() > 1) {

llvm/lib/Passes/PassRegistry.def

+1
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ FUNCTION_PASS("adce", ADCEPass())
167167
FUNCTION_PASS("add-discriminators", AddDiscriminatorsPass())
168168
FUNCTION_PASS("aggressive-instcombine", AggressiveInstCombinePass())
169169
FUNCTION_PASS("assume-builder", AssumeBuilderPass())
170+
FUNCTION_PASS("assume-simplify", AssumeSimplifyPass())
170171
FUNCTION_PASS("alignment-from-assumptions", AlignmentFromAssumptionsPass())
171172
FUNCTION_PASS("bdce", BDCEPass())
172173
FUNCTION_PASS("bounds-checking", BoundsCheckingPass())

llvm/lib/Transforms/IPO/PassManagerBuilder.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@ cl::opt<AttributorRunOption> AttributorRun(
165165
clEnumValN(AttributorRunOption::NONE, "none",
166166
"disable attributor runs")));
167167

168+
extern cl::opt<bool> EnableKnowledgeRetention;
169+
168170
PassManagerBuilder::PassManagerBuilder() {
169171
OptLevel = 2;
170172
SizeLevel = 0;
@@ -359,6 +361,8 @@ void PassManagerBuilder::addFunctionSimplificationPasses(
359361
assert(OptLevel >= 1 && "Calling function optimizer with no optimization level!");
360362
MPM.add(createSROAPass());
361363
MPM.add(createEarlyCSEPass(true /* Enable mem-ssa. */)); // Catch trivial redundancies
364+
if (EnableKnowledgeRetention)
365+
MPM.add(createAssumeSimplifyPass());
362366

363367
if (OptLevel > 1) {
364368
if (EnableGVNHoist)

0 commit comments

Comments
 (0)