aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/IR')
-rw-r--r--llvm/lib/IR/DebugInfo.cpp25
-rw-r--r--llvm/lib/IR/DebugInfoMetadata.cpp9
-rw-r--r--llvm/lib/IR/OptBisect.cpp42
-rw-r--r--llvm/lib/IR/Pass.cpp26
-rw-r--r--llvm/lib/IR/RuntimeLibcalls.cpp45
5 files changed, 117 insertions, 30 deletions
diff --git a/llvm/lib/IR/DebugInfo.cpp b/llvm/lib/IR/DebugInfo.cpp
index 84a56058..8fb33c3 100644
--- a/llvm/lib/IR/DebugInfo.cpp
+++ b/llvm/lib/IR/DebugInfo.cpp
@@ -2288,39 +2288,36 @@ bool AssignmentTrackingPass::runOnFunction(Function &F) {
// Collect a map of {backing storage : dbg.declares} (currently "backing
// storage" is limited to Allocas). We'll use this to find dbg.declares to
// delete after running `trackAssignments`.
- DenseMap<const AllocaInst *, SmallPtrSet<DbgDeclareInst *, 2>> DbgDeclares;
DenseMap<const AllocaInst *, SmallPtrSet<DbgVariableRecord *, 2>> DVRDeclares;
// Create another similar map of {storage : variables} that we'll pass to
// trackAssignments.
StorageToVarsMap Vars;
- auto ProcessDeclare = [&](auto *Declare, auto &DeclareList) {
+ auto ProcessDeclare = [&](DbgVariableRecord &Declare) {
// FIXME: trackAssignments doesn't let you specify any modifiers to the
// variable (e.g. fragment) or location (e.g. offset), so we have to
// leave dbg.declares with non-empty expressions in place.
- if (Declare->getExpression()->getNumElements() != 0)
+ if (Declare.getExpression()->getNumElements() != 0)
return;
- if (!Declare->getAddress())
+ if (!Declare.getAddress())
return;
if (AllocaInst *Alloca =
- dyn_cast<AllocaInst>(Declare->getAddress()->stripPointerCasts())) {
+ dyn_cast<AllocaInst>(Declare.getAddress()->stripPointerCasts())) {
// FIXME: Skip VLAs for now (let these variables use dbg.declares).
if (!Alloca->isStaticAlloca())
return;
// Similarly, skip scalable vectors (use dbg.declares instead).
if (auto Sz = Alloca->getAllocationSize(*DL); Sz && Sz->isScalable())
return;
- DeclareList[Alloca].insert(Declare);
- Vars[Alloca].insert(VarRecord(Declare));
+ DVRDeclares[Alloca].insert(&Declare);
+ Vars[Alloca].insert(VarRecord(&Declare));
}
};
for (auto &BB : F) {
for (auto &I : BB) {
for (DbgVariableRecord &DVR : filterDbgVars(I.getDbgRecordRange())) {
if (DVR.isDbgDeclare())
- ProcessDeclare(&DVR, DVRDeclares);
+ ProcessDeclare(DVR);
}
- if (DbgDeclareInst *DDI = dyn_cast<DbgDeclareInst>(&I))
- ProcessDeclare(DDI, DbgDeclares);
}
}
@@ -2336,8 +2333,8 @@ bool AssignmentTrackingPass::runOnFunction(Function &F) {
trackAssignments(F.begin(), F.end(), Vars, *DL);
// Delete dbg.declares for variables now tracked with assignment tracking.
- auto DeleteSubsumedDeclare = [&](const auto &Markers, auto &Declares) {
- (void)Markers;
+ for (auto &[Insts, Declares] : DVRDeclares) {
+ auto Markers = at::getDVRAssignmentMarkers(Insts);
for (auto *Declare : Declares) {
// Assert that the alloca that Declare uses is now linked to a dbg.assign
// describing the same variable (i.e. check that this dbg.declare has
@@ -2356,10 +2353,6 @@ bool AssignmentTrackingPass::runOnFunction(Function &F) {
Changed = true;
}
};
- for (auto &P : DbgDeclares)
- DeleteSubsumedDeclare(at::getAssignmentMarkers(P.first), P.second);
- for (auto &P : DVRDeclares)
- DeleteSubsumedDeclare(at::getDVRAssignmentMarkers(P.first), P.second);
return Changed;
}
diff --git a/llvm/lib/IR/DebugInfoMetadata.cpp b/llvm/lib/IR/DebugInfoMetadata.cpp
index 2270923..f16963d 100644
--- a/llvm/lib/IR/DebugInfoMetadata.cpp
+++ b/llvm/lib/IR/DebugInfoMetadata.cpp
@@ -49,20 +49,11 @@ uint32_t DIType::getAlignInBits() const {
const DIExpression::FragmentInfo DebugVariable::DefaultFragment = {
std::numeric_limits<uint64_t>::max(), std::numeric_limits<uint64_t>::min()};
-DebugVariable::DebugVariable(const DbgVariableIntrinsic *DII)
- : Variable(DII->getVariable()),
- Fragment(DII->getExpression()->getFragmentInfo()),
- InlinedAt(DII->getDebugLoc().getInlinedAt()) {}
-
DebugVariable::DebugVariable(const DbgVariableRecord *DVR)
: Variable(DVR->getVariable()),
Fragment(DVR->getExpression()->getFragmentInfo()),
InlinedAt(DVR->getDebugLoc().getInlinedAt()) {}
-DebugVariableAggregate::DebugVariableAggregate(const DbgVariableIntrinsic *DVI)
- : DebugVariable(DVI->getVariable(), std::nullopt,
- DVI->getDebugLoc()->getInlinedAt()) {}
-
DILocation::DILocation(LLVMContext &C, StorageType Storage, unsigned Line,
unsigned Column, uint64_t AtomGroup, uint8_t AtomRank,
ArrayRef<Metadata *> MDs, bool ImplicitCode)
diff --git a/llvm/lib/IR/OptBisect.cpp b/llvm/lib/IR/OptBisect.cpp
index 427e8b7..29ca268 100644
--- a/llvm/lib/IR/OptBisect.cpp
+++ b/llvm/lib/IR/OptBisect.cpp
@@ -25,6 +25,11 @@ static OptBisect &getOptBisector() {
return OptBisector;
}
+static OptDisable &getOptDisabler() {
+ static OptDisable OptDisabler;
+ return OptDisabler;
+}
+
static cl::opt<int> OptBisectLimit("opt-bisect-limit", cl::Hidden,
cl::init(OptBisect::Disabled), cl::Optional,
cl::cb<void, int>([](int Limit) {
@@ -37,6 +42,18 @@ static cl::opt<bool> OptBisectVerbose(
cl::desc("Show verbose output when opt-bisect-limit is set"), cl::Hidden,
cl::init(true), cl::Optional);
+static cl::list<std::string> OptDisablePasses(
+ "opt-disable", cl::Hidden, cl::CommaSeparated, cl::Optional,
+ cl::cb<void, std::string>([](const std::string &Pass) {
+ getOptDisabler().setDisabled(Pass);
+ }),
+ cl::desc("Optimization pass(es) to disable (comma-separated list)"));
+
+static cl::opt<bool>
+ OptDisableVerbose("opt-disable-enable-verbosity",
+ cl::desc("Show verbose output when opt-disable is set"),
+ cl::Hidden, cl::init(false), cl::Optional);
+
static void printPassMessage(StringRef Name, int PassNum, StringRef TargetDesc,
bool Running) {
StringRef Status = Running ? "" : "NOT ";
@@ -55,4 +72,27 @@ bool OptBisect::shouldRunPass(StringRef PassName,
return ShouldRun;
}
-OptPassGate &llvm::getGlobalPassGate() { return getOptBisector(); }
+static void printDisablePassMessage(const StringRef &Name, StringRef TargetDesc,
+ bool Running) {
+ StringRef Status = Running ? "" : "NOT ";
+ dbgs() << "OptDisable: " << Status << "running pass " << Name << " on "
+ << TargetDesc << "\n";
+}
+
+void OptDisable::setDisabled(StringRef Pass) { DisabledPasses.insert(Pass); }
+
+bool OptDisable::shouldRunPass(StringRef PassName,
+ StringRef IRDescription) const {
+ assert(isEnabled());
+
+ const bool ShouldRun = !DisabledPasses.contains(PassName);
+ if (OptDisableVerbose)
+ printDisablePassMessage(PassName, IRDescription, ShouldRun);
+ return ShouldRun;
+}
+
+OptPassGate &llvm::getGlobalPassGate() {
+ if (getOptDisabler().isEnabled())
+ return getOptDisabler();
+ return getOptBisector();
+}
diff --git a/llvm/lib/IR/Pass.cpp b/llvm/lib/IR/Pass.cpp
index 2c5ef71..dec7c9a 100644
--- a/llvm/lib/IR/Pass.cpp
+++ b/llvm/lib/IR/Pass.cpp
@@ -62,8 +62,12 @@ static std::string getDescription(const Module &M) {
bool ModulePass::skipModule(const Module &M) const {
const OptPassGate &Gate = M.getContext().getOptPassGate();
- return Gate.isEnabled() &&
- !Gate.shouldRunPass(this->getPassName(), getDescription(M));
+
+ StringRef PassName = getPassArgument();
+ if (PassName.empty())
+ PassName = this->getPassName();
+
+ return Gate.isEnabled() && !Gate.shouldRunPass(PassName, getDescription(M));
}
bool Pass::mustPreserveAnalysisID(char &AID) const {
@@ -86,6 +90,16 @@ StringRef Pass::getPassName() const {
return "Unnamed pass: implement Pass::getPassName()";
}
+/// getPassArgument - Return a nice clean name for a pass
+/// corresponding to that used to enable the pass in opt
+StringRef Pass::getPassArgument() const {
+ AnalysisID AID = getPassID();
+ const PassInfo *PI = Pass::lookupPassInfo(AID);
+ if (PI)
+ return PI->getPassArgument();
+ return "";
+}
+
void Pass::preparePassManager(PMStack &) {
// By default, don't do anything.
}
@@ -173,8 +187,12 @@ static std::string getDescription(const Function &F) {
bool FunctionPass::skipFunction(const Function &F) const {
OptPassGate &Gate = F.getContext().getOptPassGate();
- if (Gate.isEnabled() &&
- !Gate.shouldRunPass(this->getPassName(), getDescription(F)))
+
+ StringRef PassName = getPassArgument();
+ if (PassName.empty())
+ PassName = this->getPassName();
+
+ if (Gate.isEnabled() && !Gate.shouldRunPass(PassName, getDescription(F)))
return true;
if (F.hasOptNone()) {
diff --git a/llvm/lib/IR/RuntimeLibcalls.cpp b/llvm/lib/IR/RuntimeLibcalls.cpp
index b1864897..5936ac7 100644
--- a/llvm/lib/IR/RuntimeLibcalls.cpp
+++ b/llvm/lib/IR/RuntimeLibcalls.cpp
@@ -135,6 +135,51 @@ void RuntimeLibcallsInfo::initLibcalls(const Triple &TT,
}
}
+RTLIB::LibcallImpl
+RuntimeLibcallsInfo::getSupportedLibcallImpl(StringRef FuncName) const {
+ const ArrayRef<uint16_t> RuntimeLibcallNameOffsets(
+ RuntimeLibcallNameOffsetTable);
+
+ iterator_range<ArrayRef<uint16_t>::const_iterator> Range =
+ getRecognizedLibcallImpls(FuncName);
+
+ for (auto I = Range.begin(); I != Range.end(); ++I) {
+ RTLIB::LibcallImpl Impl =
+ static_cast<RTLIB::LibcallImpl>(I - RuntimeLibcallNameOffsets.begin());
+
+ // FIXME: This should not depend on looking up ImplToLibcall, only the list
+ // of libcalls for the module.
+ RTLIB::LibcallImpl Recognized = LibcallImpls[ImplToLibcall[Impl]];
+ if (Recognized != RTLIB::Unsupported)
+ return Recognized;
+ }
+
+ return RTLIB::Unsupported;
+}
+
+iterator_range<ArrayRef<uint16_t>::const_iterator>
+RuntimeLibcallsInfo::getRecognizedLibcallImpls(StringRef FuncName) {
+ StringTable::Iterator It = lower_bound(RuntimeLibcallImplNameTable, FuncName);
+ if (It == RuntimeLibcallImplNameTable.end() || *It != FuncName)
+ return iterator_range(ArrayRef<uint16_t>());
+
+ uint16_t IndexVal = It.offset().value();
+ const ArrayRef<uint16_t> TableRef(RuntimeLibcallNameOffsetTable);
+
+ ArrayRef<uint16_t>::const_iterator E = TableRef.end();
+ ArrayRef<uint16_t>::const_iterator EntriesBegin =
+ std::lower_bound(TableRef.begin(), E, IndexVal);
+ ArrayRef<uint16_t>::const_iterator EntriesEnd = EntriesBegin;
+
+ while (EntriesEnd != E && *EntriesEnd == IndexVal)
+ ++EntriesEnd;
+
+ assert(EntriesBegin != E &&
+ "libcall found in name table but not offset table");
+
+ return make_range(EntriesBegin, EntriesEnd);
+}
+
bool RuntimeLibcallsInfo::darwinHasExp10(const Triple &TT) {
switch (TT.getOS()) {
case Triple::MacOSX: