Skip to content

Commit c9b47cd

Browse files
SLTozerchencha3
authored andcommitted
Revert "[NFC][RemoveDIs] Switch ConstantExpr::getAsInstruction to not insert (llvm#84737)"
Reverted due to buildbot failures: https://lab.llvm.org/buildbot/#/builders/139/builds/61717/ This reverts commit 7ef433f.
1 parent 643dd1e commit c9b47cd

File tree

5 files changed

+27
-34
lines changed

5 files changed

+27
-34
lines changed

llvm/include/llvm/IR/Constants.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1289,13 +1289,14 @@ class ConstantExpr : public Constant {
12891289
Type *SrcTy = nullptr) const;
12901290

12911291
/// Returns an Instruction which implements the same operation as this
1292-
/// ConstantExpr. It is not inserted into any basic block.
1292+
/// ConstantExpr. If \p InsertBefore is not null, the new instruction is
1293+
/// inserted before it, otherwise it is not inserted into any basic block.
12931294
///
12941295
/// A better approach to this could be to have a constructor for Instruction
12951296
/// which would take a ConstantExpr parameter, but that would have spread
12961297
/// implementation details of ConstantExpr outside of Constants.cpp, which
12971298
/// would make it harder to remove ConstantExprs altogether.
1298-
Instruction *getAsInstruction() const;
1299+
Instruction *getAsInstruction(Instruction *InsertBefore = nullptr) const;
12991300

13001301
/// Whether creating a constant expression for this binary operator is
13011302
/// desirable.

llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5073,15 +5073,10 @@ FunctionCallee OpenMPIRBuilder::createDispatchFiniFunction(unsigned IVSize,
50735073

50745074
static void replaceConstatExprUsesInFuncWithInstr(ConstantExpr *ConstExpr,
50755075
Function *Func) {
5076-
for (User *User : make_early_inc_range(ConstExpr->users())) {
5077-
if (auto *Instr = dyn_cast<Instruction>(User)) {
5078-
if (Instr->getFunction() == Func) {
5079-
Instruction *ConstInst = ConstExpr->getAsInstruction();
5080-
ConstInst->insertBefore(*Instr->getParent(), Instr->getIterator());
5081-
Instr->replaceUsesOfWith(ConstExpr, ConstInst);
5082-
}
5083-
}
5084-
}
5076+
for (User *User : make_early_inc_range(ConstExpr->users()))
5077+
if (auto *Instr = dyn_cast<Instruction>(User))
5078+
if (Instr->getFunction() == Func)
5079+
Instr->replaceUsesOfWith(ConstExpr, ConstExpr->getAsInstruction(Instr));
50855080
}
50865081

50875082
static void replaceConstantValueUsesInFuncWithInstr(llvm::Value *Input,

llvm/lib/IR/Constants.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3303,7 +3303,7 @@ Value *ConstantExpr::handleOperandChangeImpl(Value *From, Value *ToV) {
33033303
NewOps, this, From, To, NumUpdated, OperandNo);
33043304
}
33053305

3306-
Instruction *ConstantExpr::getAsInstruction() const {
3306+
Instruction *ConstantExpr::getAsInstruction(Instruction *InsertBefore) const {
33073307
SmallVector<Value *, 4> ValueOperands(operands());
33083308
ArrayRef<Value*> Ops(ValueOperands);
33093309

@@ -3322,31 +3322,32 @@ Instruction *ConstantExpr::getAsInstruction() const {
33223322
case Instruction::BitCast:
33233323
case Instruction::AddrSpaceCast:
33243324
return CastInst::Create((Instruction::CastOps)getOpcode(), Ops[0],
3325-
getType(), "");
3325+
getType(), "", InsertBefore);
33263326
case Instruction::InsertElement:
3327-
return InsertElementInst::Create(Ops[0], Ops[1], Ops[2], "");
3327+
return InsertElementInst::Create(Ops[0], Ops[1], Ops[2], "", InsertBefore);
33283328
case Instruction::ExtractElement:
3329-
return ExtractElementInst::Create(Ops[0], Ops[1], "");
3329+
return ExtractElementInst::Create(Ops[0], Ops[1], "", InsertBefore);
33303330
case Instruction::ShuffleVector:
3331-
return new ShuffleVectorInst(Ops[0], Ops[1], getShuffleMask(), "");
3331+
return new ShuffleVectorInst(Ops[0], Ops[1], getShuffleMask(), "",
3332+
InsertBefore);
33323333

33333334
case Instruction::GetElementPtr: {
33343335
const auto *GO = cast<GEPOperator>(this);
33353336
if (GO->isInBounds())
3336-
return GetElementPtrInst::CreateInBounds(GO->getSourceElementType(),
3337-
Ops[0], Ops.slice(1), "");
3337+
return GetElementPtrInst::CreateInBounds(
3338+
GO->getSourceElementType(), Ops[0], Ops.slice(1), "", InsertBefore);
33383339
return GetElementPtrInst::Create(GO->getSourceElementType(), Ops[0],
3339-
Ops.slice(1), "");
3340+
Ops.slice(1), "", InsertBefore);
33403341
}
33413342
case Instruction::ICmp:
33423343
case Instruction::FCmp:
33433344
return CmpInst::Create((Instruction::OtherOps)getOpcode(),
33443345
(CmpInst::Predicate)getPredicate(), Ops[0], Ops[1],
3345-
"");
3346+
"", InsertBefore);
33463347
default:
33473348
assert(getNumOperands() == 2 && "Must be binary operator?");
33483349
BinaryOperator *BO = BinaryOperator::Create(
3349-
(Instruction::BinaryOps)getOpcode(), Ops[0], Ops[1], "");
3350+
(Instruction::BinaryOps)getOpcode(), Ops[0], Ops[1], "", InsertBefore);
33503351
if (isa<OverflowingBinaryOperator>(BO)) {
33513352
BO->setHasNoUnsignedWrap(SubclassOptionalData &
33523353
OverflowingBinaryOperator::NoUnsignedWrap);

llvm/lib/IR/ReplaceConstant.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,11 @@ static bool isExpandableUser(User *U) {
2222
return isa<ConstantExpr>(U) || isa<ConstantAggregate>(U);
2323
}
2424

25-
static SmallVector<Instruction *, 4> expandUser(BasicBlock::iterator InsertPt,
25+
static SmallVector<Instruction *, 4> expandUser(Instruction *InsertPt,
2626
Constant *C) {
2727
SmallVector<Instruction *, 4> NewInsts;
2828
if (auto *CE = dyn_cast<ConstantExpr>(C)) {
29-
Instruction *ConstInst = CE->getAsInstruction();
30-
ConstInst->insertBefore(*InsertPt->getParent(), InsertPt);
31-
NewInsts.push_back(ConstInst);
29+
NewInsts.push_back(CE->getAsInstruction(InsertPt));
3230
} else if (isa<ConstantStruct>(C) || isa<ConstantArray>(C)) {
3331
Value *V = PoisonValue::get(C->getType());
3432
for (auto [Idx, Op] : enumerate(C->operands())) {
@@ -82,11 +80,12 @@ bool convertUsersOfConstantsToInstructions(ArrayRef<Constant *> Consts) {
8280
Instruction *I = InstructionWorklist.pop_back_val();
8381
DebugLoc Loc = I->getDebugLoc();
8482
for (Use &U : I->operands()) {
85-
BasicBlock::iterator BI = I->getIterator();
83+
auto *BI = I;
8684
if (auto *Phi = dyn_cast<PHINode>(I)) {
8785
BasicBlock *BB = Phi->getIncomingBlock(U);
88-
BI = BB->getFirstInsertionPt();
89-
assert(BI != BB->end() && "Unexpected empty basic block");
86+
BasicBlock::iterator It = BB->getFirstInsertionPt();
87+
assert(It != BB->end() && "Unexpected empty basic block");
88+
BI = &*It;
9089
}
9190

9291
if (auto *C = dyn_cast<Constant>(U.get())) {

llvm/lib/Target/XCore/XCoreLowerThreadLocal.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,12 @@ static bool replaceConstantExprOp(ConstantExpr *CE, Pass *P) {
8888
BasicBlock *PredBB = PN->getIncomingBlock(I);
8989
if (PredBB->getTerminator()->getNumSuccessors() > 1)
9090
PredBB = SplitEdge(PredBB, PN->getParent());
91-
BasicBlock::iterator InsertPos =
92-
PredBB->getTerminator()->getIterator();
93-
Instruction *NewInst = CE->getAsInstruction();
94-
NewInst->insertBefore(*PredBB, InsertPos);
91+
Instruction *InsertPos = PredBB->getTerminator();
92+
Instruction *NewInst = CE->getAsInstruction(InsertPos);
9593
PN->setOperand(I, NewInst);
9694
}
9795
} else if (Instruction *Instr = dyn_cast<Instruction>(WU)) {
98-
Instruction *NewInst = CE->getAsInstruction();
99-
NewInst->insertBefore(*Instr->getParent(), Instr->getIterator());
96+
Instruction *NewInst = CE->getAsInstruction(Instr);
10097
Instr->replaceUsesOfWith(CE, NewInst);
10198
} else {
10299
ConstantExpr *CExpr = dyn_cast<ConstantExpr>(WU);

0 commit comments

Comments
 (0)