Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6ec3d10

Browse files
authored
Merge branch 'llvm:main' into mt-2-msvc
2 parents e1f55b0 + be1bc28 commit 6ec3d10

58 files changed

Lines changed: 1019 additions & 347 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

bolt/include/bolt/Passes/DataflowAnalysis.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -404,10 +404,12 @@ class DataflowAnalysis {
404404
// Propagate information from first instruction down to the last one
405405
StateTy *PrevState = &St;
406406
const MCInst *LAST = nullptr;
407-
if (!Backward)
408-
LAST = &*BB->rbegin();
409-
else
410-
LAST = &*BB->begin();
407+
if (!BB->empty()) {
408+
if (!Backward)
409+
LAST = &*BB->rbegin();
410+
else
411+
LAST = &*BB->begin();
412+
}
411413

412414
auto doNext = [&](MCInst &Inst, const BinaryBasicBlock &BB) {
413415
StateTy CurState = derived().computeNext(Inst, *PrevState);

bolt/lib/Passes/AllocCombiner.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ static void runForAllWeCare(std::map<uint64_t, BinaryFunction> &BFs,
6464
void AllocCombinerPass::combineAdjustments(BinaryFunction &BF) {
6565
BinaryContext &BC = BF.getBinaryContext();
6666
for (BinaryBasicBlock &BB : BF) {
67+
SmallVector<MCInst *, 2> ToErase;
6768
MCInst *Prev = nullptr;
6869
for (MCInst &Inst : llvm::reverse(BB)) {
6970
if (isIndifferentToSP(Inst, BC))
@@ -94,12 +95,14 @@ void AllocCombinerPass::combineAdjustments(BinaryFunction &BF) {
9495
Inst.dump();
9596
});
9697

97-
BB.eraseInstruction(BB.findInstruction(Prev));
98+
ToErase.push_back(Prev);
9899
++NumCombined;
99100
DynamicCountCombined += BB.getKnownExecutionCount();
100101
FuncsChanged.insert(&BF);
101102
Prev = &Inst;
102103
}
104+
for (MCInst *Inst : ToErase)
105+
BB.eraseInstruction(BB.findInstruction(Inst));
103106
}
104107
}
105108

bolt/lib/Passes/IndirectCallPromotion.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -775,8 +775,7 @@ IndirectCallPromotion::rewriteCall(
775775
InstructionListType TailInsts;
776776
const MCInst *TailInst = &CallInst;
777777
if (IsTailCallOrJT)
778-
while (TailInst + 1 < &(*IndCallBlock.end()) &&
779-
MIB->isPseudo(*(TailInst + 1)))
778+
while (TailInst != &IndCallBlock.back() && MIB->isPseudo(*(TailInst + 1)))
780779
TailInsts.push_back(*++TailInst);
781780

782781
InstructionListType MovedInst = IndCallBlock.splitInstructions(&CallInst);

bolt/lib/Passes/ShrinkWrapping.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1887,13 +1887,16 @@ Expected<bool> ShrinkWrapping::processInsertions() {
18871887
void ShrinkWrapping::processDeletions() {
18881888
LivenessAnalysis &LA = Info.getLivenessAnalysis();
18891889
for (BinaryBasicBlock &BB : BF) {
1890-
for (auto II = BB.begin(); II != BB.end(); ++II) {
1890+
for (auto II = BB.begin(); II != BB.end();) {
18911891
MCInst &Inst = *II;
18921892
auto TodoList = BC.MIB->tryGetAnnotationAs<std::vector<WorklistItem>>(
18931893
Inst, getAnnotationIndex());
1894-
if (!TodoList)
1894+
if (!TodoList) {
1895+
++II;
18951896
continue;
1897+
}
18961898
// Process all deletions
1899+
bool Erased = false;
18971900
for (WorklistItem &Item : *TodoList) {
18981901
if (Item.Action != WorklistItem::Erase &&
18991902
Item.Action != WorklistItem::ChangeToAdjustment)
@@ -1916,9 +1919,12 @@ void ShrinkWrapping::processDeletions() {
19161919
dbgs() << "Erasing: ";
19171920
BC.printInstruction(dbgs(), Inst);
19181921
});
1919-
II = std::prev(BB.eraseInstruction(II));
1922+
II = BB.eraseInstruction(II);
1923+
Erased = true;
19201924
break;
19211925
}
1926+
if (!Erased)
1927+
++II;
19221928
}
19231929
}
19241930
}

bolt/lib/Passes/TailDuplication.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,18 +167,22 @@ void TailDuplication::constantAndCopyPropagate(
167167

168168
BlocksToPropagate.insert(BlocksToPropagate.begin(), &OriginalBB);
169169
// Iterate through the original instructions to find one to propagate
170-
for (auto Itr = OriginalBB.begin(); Itr != OriginalBB.end(); ++Itr) {
170+
for (auto Itr = OriginalBB.begin(); Itr != OriginalBB.end();) {
171171
MCInst &OriginalInst = *Itr;
172172
// It must be a non conditional
173-
if (BC.MIB->isConditionalMove(OriginalInst))
173+
if (BC.MIB->isConditionalMove(OriginalInst)) {
174+
++Itr;
174175
continue;
176+
}
175177

176178
// Move immediate or move register
177179
if ((!BC.MII->get(OriginalInst.getOpcode()).isMoveImmediate() ||
178180
!OriginalInst.getOperand(1).isImm()) &&
179181
(!BC.MII->get(OriginalInst.getOpcode()).isMoveReg() ||
180-
!OriginalInst.getOperand(1).isReg()))
182+
!OriginalInst.getOperand(1).isReg())) {
183+
++Itr;
181184
continue;
185+
}
182186

183187
// True if this is constant propagation and not copy propagation
184188
bool ConstantProp = BC.MII->get(OriginalInst.getOpcode()).isMoveImmediate();
@@ -247,7 +251,9 @@ void TailDuplication::constantAndCopyPropagate(
247251
// to replace is active for constant propagation
248252
StaticInstructionDeletionCount++;
249253
DynamicInstructionDeletionCount += OriginalBB.getExecutionCount();
250-
Itr = std::prev(OriginalBB.eraseInstruction(Itr));
254+
Itr = OriginalBB.eraseInstruction(Itr);
255+
} else {
256+
++Itr;
251257
}
252258
}
253259
}

clang/include/clang/Analysis/Analyses/LifetimeSafety/FactsGenerator.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ class FactsGenerator : public ConstStmtVisitor<FactsGenerator> {
134134
// corresponding to the left-hand side is updated to be a "write", thereby
135135
// exempting it from the check.
136136
llvm::DenseMap<const Expr *, UseFact *> UseFacts;
137+
const CFGBlock *CurrentBlock;
137138
};
138139

139140
} // namespace clang::lifetimes::internal

clang/lib/Analysis/LifetimeSafety/FactsGenerator.cpp

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ void FactsGenerator::run() {
103103
for (const CFGBlock *Block : *AC.getAnalysis<PostOrderCFGView>()) {
104104
CurrentBlockFacts.clear();
105105
EscapesInCurrentBlock.clear();
106+
CurrentBlock = Block;
106107
if (Block == &Cfg.getEntry())
107108
CurrentBlockFacts.append(PlaceholderLoanFacts.begin(),
108109
PlaceholderLoanFacts.end());
@@ -422,12 +423,58 @@ void FactsGenerator::VisitBinaryOperator(const BinaryOperator *BO) {
422423
}
423424

424425
void FactsGenerator::VisitConditionalOperator(const ConditionalOperator *CO) {
425-
if (hasOrigins(CO)) {
426-
// Merge origins from both branches of the conditional operator.
427-
// We kill to clear the initial state and merge both origins into it.
428-
killAndFlowOrigin(*CO, *CO->getTrueExpr());
429-
flowOrigin(*CO, *CO->getFalseExpr());
426+
if (!hasOrigins(CO))
427+
return;
428+
429+
const Expr *TrueExpr = CO->getTrueExpr();
430+
const Expr *FalseExpr = CO->getFalseExpr();
431+
432+
const auto Preds = CurrentBlock->preds();
433+
434+
// Skip origin flow from conditional operator arms that cannot produce the
435+
// result value: throw arms and calls to noreturn functions.
436+
bool TBHasEdge = true;
437+
bool FBHasEdge = true;
438+
439+
switch (CurrentBlock->pred_size()) {
440+
case 0:
441+
return;
442+
case 1: {
443+
TBHasEdge = llvm::any_of(**Preds.begin(),
444+
[ExpectedStmt = TrueExpr->IgnoreParenImpCasts()](
445+
const CFGElement &Elt) {
446+
if (auto CS = Elt.getAs<CFGStmt>())
447+
return CS->getStmt() == ExpectedStmt;
448+
return false;
449+
});
450+
FBHasEdge = !TBHasEdge;
451+
break;
452+
}
453+
case 2: {
454+
const auto *It = Preds.begin();
455+
TBHasEdge = It->isReachable();
456+
FBHasEdge = (++It)->isReachable();
457+
break;
430458
}
459+
default:
460+
llvm_unreachable("expected at most 2 predecessors");
461+
return;
462+
}
463+
464+
bool FirstFlow = true;
465+
auto HandleFlow = [&](const Expr *E) {
466+
if (FirstFlow) {
467+
killAndFlowOrigin(*CO, *E);
468+
FirstFlow = false;
469+
} else {
470+
flowOrigin(*CO, *E);
471+
}
472+
};
473+
474+
if (TBHasEdge)
475+
HandleFlow(TrueExpr);
476+
if (FBHasEdge)
477+
HandleFlow(FalseExpr);
431478
}
432479

433480
void FactsGenerator::VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *OCE) {

clang/lib/Driver/Driver.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7216,6 +7216,10 @@ const ToolChain &Driver::getToolChain(const ArgList &Args,
72167216
case llvm::Triple::csky:
72177217
TC = std::make_unique<toolchains::CSKYToolChain>(*this, Target, Args);
72187218
break;
7219+
case llvm::Triple::amdgcn:
7220+
case llvm::Triple::r600:
7221+
TC = std::make_unique<toolchains::AMDGPUToolChain>(*this, Target, Args);
7222+
break;
72197223
default:
72207224
if (toolchains::BareMetal::handlesTarget(Target))
72217225
TC = std::make_unique<toolchains::BareMetal>(*this, Target, Args);

clang/lib/Driver/ModulesDriver.cpp

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,8 @@ class CGNode : public CGNodeBase {
749749
CGNode(const NodeKind K) : Kind(K) {}
750750
CGNode(const CGNode &) = delete;
751751
CGNode(CGNode &&) = delete;
752+
CGNode &operator=(const CGNode &) = delete;
753+
CGNode &operator=(CGNode &&) = delete;
752754
virtual ~CGNode() = 0;
753755

754756
NodeKind getKind() const { return Kind; }
@@ -893,6 +895,10 @@ class CGEdge : public CGEdgeBase {
893895
};
894896

895897
CGEdge(CGNode &N, EdgeKind K) : CGEdgeBase(N), Kind(K) {}
898+
CGEdge(const CGEdge &) = delete;
899+
CGEdge &operator=(const CGEdge &) = delete;
900+
CGEdge(CGEdge &&) = delete;
901+
CGEdge &operator=(CGEdge &&) = delete;
896902

897903
EdgeKind getKind() const { return Kind; }
898904

@@ -909,7 +915,10 @@ class CompilationGraph : public CGBase {
909915
public:
910916
CompilationGraph() = default;
911917
CompilationGraph(const CompilationGraph &) = delete;
918+
CompilationGraph &operator=(const CompilationGraph &) = delete;
912919
CompilationGraph(CompilationGraph &&G) = default;
920+
CompilationGraph &operator=(CompilationGraph &&) = default;
921+
~CompilationGraph() = default;
913922

914923
CGNode &getRoot() const {
915924
assert(Root && "Root node has not yet been created!");
@@ -1496,6 +1505,19 @@ static void createAndConnectRoot(CompilationGraph &Graph) {
14961505
}
14971506
}
14981507

1508+
/// Moves jobs from \p Graph into \p C in the graph's topological order.
1509+
static void feedJobsBackIntoCompilation(Compilation &C,
1510+
CompilationGraph &&Graph) {
1511+
llvm::ReversePostOrderTraversal<CompilationGraph *> TopologicallySortedNodes(
1512+
&Graph);
1513+
assert(isa<RootNode>(*TopologicallySortedNodes.begin()) &&
1514+
"First node in topological order must be the root!");
1515+
auto TopologicallySortedJobNodes = llvm::map_range(
1516+
llvm::drop_begin(TopologicallySortedNodes), llvm::CastTo<JobNode>);
1517+
for (auto *JN : TopologicallySortedJobNodes)
1518+
C.addCommand(std::move(JN->Job));
1519+
}
1520+
14991521
void driver::modules::runModulesDriver(
15001522
Compilation &C, ArrayRef<StdModuleManifest::Module> ManifestEntries) {
15011523
llvm::PrettyStackTraceString CrashInfo("Running modules driver.");
@@ -1554,12 +1576,5 @@ void driver::modules::runModulesDriver(
15541576

15551577
// TODO: Fix-up command-lines for named module imports.
15561578

1557-
llvm::ReversePostOrderTraversal<CompilationGraph *> TopologicallySortedNodes(
1558-
&Graph);
1559-
assert(isa<RootNode>(*TopologicallySortedNodes.begin()) &&
1560-
"First node in topological order must be the root!");
1561-
auto TopologicallySortedJobNodes = llvm::map_range(
1562-
llvm::drop_begin(TopologicallySortedNodes), llvm::CastTo<JobNode>);
1563-
for (auto *JN : TopologicallySortedJobNodes)
1564-
C.addCommand(std::move(JN->Job));
1579+
feedJobsBackIntoCompilation(C, std::move(Graph));
15651580
}

clang/lib/Sema/AnalysisBasedWarnings.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2922,7 +2922,7 @@ LifetimeSafetyTUAnalysis(Sema &S, TranslationUnitDecl *TU,
29222922
if (!FD)
29232923
continue;
29242924
AnalysisDeclContext AC(nullptr, FD);
2925-
AC.getCFGBuildOptions().PruneTriviallyFalseEdges = false;
2925+
AC.getCFGBuildOptions().PruneTriviallyFalseEdges = true;
29262926
AC.getCFGBuildOptions().AddLifetime = true;
29272927
AC.getCFGBuildOptions().AddParameterLifetimes = true;
29282928
AC.getCFGBuildOptions().setAllAlwaysAdd();

0 commit comments

Comments
 (0)