Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit 0dfe884

Browse files
committed
[Transforms] Revert r316630 changes in Scalar/MergeICmps.cpp to fix broken build bots (NFC).
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@316634 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 46057fe commit 0dfe884

File tree

1 file changed

+31
-62
lines changed

1 file changed

+31
-62
lines changed

lib/Transforms/Scalar/MergeICmps.cpp

Lines changed: 31 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -19,47 +19,33 @@
1919
// - Code size is smaller, both because jumps are removed and because the
2020
// encoding of a 2*n byte compare is smaller than that of two n-byte
2121
// compares.
22-
//
22+
2323
//===----------------------------------------------------------------------===//
2424

25-
#include "llvm/ADT/APInt.h"
26-
#include "llvm/ADT/ArrayRef.h"
25+
#include <algorithm>
26+
#include <numeric>
27+
#include <utility>
28+
#include <vector>
29+
#include "llvm/ADT/APSInt.h"
2730
#include "llvm/Analysis/Loads.h"
2831
#include "llvm/Analysis/TargetLibraryInfo.h"
2932
#include "llvm/Analysis/TargetTransformInfo.h"
30-
#include "llvm/IR/BasicBlock.h"
31-
#include "llvm/IR/Constants.h"
32-
#include "llvm/IR/DataLayout.h"
3333
#include "llvm/IR/Function.h"
3434
#include "llvm/IR/IRBuilder.h"
35-
#include "llvm/IR/Instruction.h"
36-
#include "llvm/IR/Instructions.h"
37-
#include "llvm/IR/Module.h"
38-
#include "llvm/IR/PassManager.h"
39-
#include "llvm/IR/Type.h"
40-
#include "llvm/IR/Value.h"
35+
#include "llvm/IR/IntrinsicInst.h"
4136
#include "llvm/Pass.h"
42-
#include "llvm/Support/Casting.h"
43-
#include "llvm/Support/Debug.h"
44-
#include "llvm/Support/raw_ostream.h"
4537
#include "llvm/Transforms/Scalar.h"
4638
#include "llvm/Transforms/Utils/BuildLibCalls.h"
47-
#include <algorithm>
48-
#include <cassert>
49-
#include <cstddef>
50-
#include <numeric>
51-
#include <utility>
52-
#include <vector>
5339

5440
using namespace llvm;
5541

56-
#define DEBUG_TYPE "mergeicmps"
57-
5842
namespace {
5943

44+
#define DEBUG_TYPE "mergeicmps"
45+
6046
// A BCE atom.
6147
struct BCEAtom {
62-
BCEAtom() = default;
48+
BCEAtom() : GEP(nullptr), LoadI(nullptr), Offset() {}
6349

6450
const Value *Base() const { return GEP ? GEP->getPointerOperand() : nullptr; }
6551

@@ -81,17 +67,15 @@ struct BCEAtom {
8167
return NameCmp < 0;
8268
}
8369

84-
GetElementPtrInst *GEP = nullptr;
85-
LoadInst *LoadI = nullptr;
70+
GetElementPtrInst *GEP;
71+
LoadInst *LoadI;
8672
APInt Offset;
8773
};
8874

89-
} // end anonymous namespace
90-
9175
// If this value is a load from a constant offset w.r.t. a base address, and
9276
// there are no othe rusers of the load or address, returns the base address and
9377
// the offset.
94-
static BCEAtom visitICmpLoadOperand(Value *const Val) {
78+
BCEAtom visitICmpLoadOperand(Value *const Val) {
9579
BCEAtom Result;
9680
if (auto *const LoadI = dyn_cast<LoadInst>(Val)) {
9781
DEBUG(dbgs() << "load\n");
@@ -127,16 +111,14 @@ static BCEAtom visitICmpLoadOperand(Value *const Val) {
127111
return Result;
128112
}
129113

130-
namespace {
131-
132114
// A basic block with a comparison between two BCE atoms.
133115
// Note: the terminology is misleading: the comparison is symmetric, so there
134116
// is no real {l/r}hs. What we want though is to have the same base on the
135117
// left (resp. right), so that we can detect consecutive loads. To ensure this
136118
// we put the smallest atom on the left.
137119
class BCECmpBlock {
138-
public:
139-
BCECmpBlock() = default;
120+
public:
121+
BCECmpBlock() {}
140122

141123
BCECmpBlock(BCEAtom L, BCEAtom R, int SizeBits)
142124
: Lhs_(L), Rhs_(R), SizeBits_(SizeBits) {
@@ -166,21 +148,17 @@ class BCECmpBlock {
166148

167149
// The basic block where this comparison happens.
168150
BasicBlock *BB = nullptr;
169-
170151
// The ICMP for this comparison.
171152
ICmpInst *CmpI = nullptr;
172-
173153
// The terminating branch.
174154
BranchInst *BranchI = nullptr;
175155

176-
private:
156+
private:
177157
BCEAtom Lhs_;
178158
BCEAtom Rhs_;
179159
int SizeBits_ = 0;
180160
};
181161

182-
} // end anonymous namespace
183-
184162
bool BCECmpBlock::doesOtherWork() const {
185163
AssertConsistent();
186164
// TODO(courbet): Can we allow some other things ? This is very conservative.
@@ -205,8 +183,8 @@ bool BCECmpBlock::doesOtherWork() const {
205183

206184
// Visit the given comparison. If this is a comparison between two valid
207185
// BCE atoms, returns the comparison.
208-
static BCECmpBlock visitICmp(const ICmpInst *const CmpI,
209-
const ICmpInst::Predicate ExpectedPredicate) {
186+
BCECmpBlock visitICmp(const ICmpInst *const CmpI,
187+
const ICmpInst::Predicate ExpectedPredicate) {
210188
if (CmpI->getPredicate() == ExpectedPredicate) {
211189
DEBUG(dbgs() << "cmp "
212190
<< (ExpectedPredicate == ICmpInst::ICMP_EQ ? "eq" : "ne")
@@ -223,8 +201,8 @@ static BCECmpBlock visitICmp(const ICmpInst *const CmpI,
223201

224202
// Visit the given comparison block. If this is a comparison between two valid
225203
// BCE atoms, returns the comparison.
226-
static BCECmpBlock visitCmpBlock(Value *const Val, BasicBlock *const Block,
227-
const BasicBlock *const PhiBlock) {
204+
BCECmpBlock visitCmpBlock(Value *const Val, BasicBlock *const Block,
205+
const BasicBlock *const PhiBlock) {
228206
if (Block->empty()) return {};
229207
auto *const BranchI = dyn_cast<BranchInst>(Block->getTerminator());
230208
if (!BranchI) return {};
@@ -262,11 +240,9 @@ static BCECmpBlock visitCmpBlock(Value *const Val, BasicBlock *const Block,
262240
return {};
263241
}
264242

265-
namespace {
266-
267243
// A chain of comparisons.
268244
class BCECmpChain {
269-
public:
245+
public:
270246
BCECmpChain(const std::vector<BasicBlock *> &Blocks, PHINode &Phi);
271247

272248
int size() const { return Comparisons_.size(); }
@@ -277,7 +253,7 @@ class BCECmpChain {
277253

278254
bool simplify(const TargetLibraryInfo *const TLI);
279255

280-
private:
256+
private:
281257
static bool IsContiguous(const BCECmpBlock &First,
282258
const BCECmpBlock &Second) {
283259
return First.Lhs().Base() == Second.Lhs().Base() &&
@@ -295,13 +271,10 @@ class BCECmpChain {
295271

296272
PHINode &Phi_;
297273
std::vector<BCECmpBlock> Comparisons_;
298-
299274
// The original entry block (before sorting);
300275
BasicBlock *EntryBlock_;
301276
};
302277

303-
} // end anonymous namespace
304-
305278
BCECmpChain::BCECmpChain(const std::vector<BasicBlock *> &Blocks, PHINode &Phi)
306279
: Phi_(Phi) {
307280
// Now look inside blocks to check for BCE comparisons.
@@ -474,8 +447,7 @@ void BCECmpChain::mergeComparisons(ArrayRef<BCECmpBlock> Comparisons,
474447
IRBuilder<> Builder(BB);
475448
const auto &DL = Phi.getModule()->getDataLayout();
476449
Value *const MemCmpCall = emitMemCmp(
477-
FirstComparison.Lhs().GEP, FirstComparison.Rhs().GEP,
478-
ConstantInt::get(DL.getIntPtrType(Context), TotalSize),
450+
FirstComparison.Lhs().GEP, FirstComparison.Rhs().GEP, ConstantInt::get(DL.getIntPtrType(Context), TotalSize),
479451
Builder, DL, TLI);
480452
Value *const MemCmpIsZero = Builder.CreateICmpEQ(
481453
MemCmpCall, ConstantInt::get(Type::getInt32Ty(Context), 0));
@@ -532,9 +504,9 @@ void BCECmpChain::mergeComparisons(ArrayRef<BCECmpBlock> Comparisons,
532504
}
533505
}
534506

535-
static std::vector<BasicBlock *> getOrderedBlocks(PHINode &Phi,
536-
BasicBlock *const LastBlock,
537-
int NumBlocks) {
507+
std::vector<BasicBlock *> getOrderedBlocks(PHINode &Phi,
508+
BasicBlock *const LastBlock,
509+
int NumBlocks) {
538510
// Walk up from the last block to find other blocks.
539511
std::vector<BasicBlock *> Blocks(NumBlocks);
540512
BasicBlock *CurBlock = LastBlock;
@@ -566,7 +538,7 @@ static std::vector<BasicBlock *> getOrderedBlocks(PHINode &Phi,
566538
return Blocks;
567539
}
568540

569-
static bool processPhi(PHINode &Phi, const TargetLibraryInfo *const TLI) {
541+
bool processPhi(PHINode &Phi, const TargetLibraryInfo *const TLI) {
570542
DEBUG(dbgs() << "processPhi()\n");
571543
if (Phi.getNumIncomingValues() <= 1) {
572544
DEBUG(dbgs() << "skip: only one incoming value in phi\n");
@@ -621,10 +593,8 @@ static bool processPhi(PHINode &Phi, const TargetLibraryInfo *const TLI) {
621593
return CmpChain.simplify(TLI);
622594
}
623595

624-
namespace {
625-
626596
class MergeICmps : public FunctionPass {
627-
public:
597+
public:
628598
static char ID;
629599

630600
MergeICmps() : FunctionPass(ID) {
@@ -639,18 +609,16 @@ class MergeICmps : public FunctionPass {
639609
return !PA.areAllPreserved();
640610
}
641611

612+
private:
642613
void getAnalysisUsage(AnalysisUsage &AU) const override {
643614
AU.addRequired<TargetLibraryInfoWrapperPass>();
644615
AU.addRequired<TargetTransformInfoWrapperPass>();
645616
}
646617

647-
private:
648618
PreservedAnalyses runImpl(Function &F, const TargetLibraryInfo *TLI,
649619
const TargetTransformInfo *TTI);
650620
};
651621

652-
} // end anonymous namespace
653-
654622
PreservedAnalyses MergeICmps::runImpl(Function &F, const TargetLibraryInfo *TLI,
655623
const TargetTransformInfo *TTI) {
656624
DEBUG(dbgs() << "MergeICmpsPass: " << F.getName() << "\n");
@@ -672,8 +640,9 @@ PreservedAnalyses MergeICmps::runImpl(Function &F, const TargetLibraryInfo *TLI,
672640
return PreservedAnalyses::all();
673641
}
674642

675-
char MergeICmps::ID = 0;
643+
} // namespace
676644

645+
char MergeICmps::ID = 0;
677646
INITIALIZE_PASS_BEGIN(MergeICmps, "mergeicmps",
678647
"Merge contiguous icmps into a memcmp", false, false)
679648
INITIALIZE_PASS_DEPENDENCY(TargetLibraryInfoWrapperPass)

0 commit comments

Comments
 (0)