aboutsummaryrefslogtreecommitdiff
path: root/lib/IR/Instruction.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/IR/Instruction.cpp')
-rw-r--r--lib/IR/Instruction.cpp76
1 files changed, 23 insertions, 53 deletions
diff --git a/lib/IR/Instruction.cpp b/lib/IR/Instruction.cpp
index d861b5288592..ba5629d1662b 100644
--- a/lib/IR/Instruction.cpp
+++ b/lib/IR/Instruction.cpp
@@ -1,9 +1,8 @@
//===-- Instruction.cpp - Implement the Instruction class -----------------===//
//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
@@ -139,8 +138,10 @@ void Instruction::dropPoisonGeneratingFlags() {
cast<GetElementPtrInst>(this)->setIsInBounds(false);
break;
}
+ // TODO: FastMathFlags!
}
+
bool Instruction::isExact() const {
return cast<PossiblyExactOperator>(this)->isExact();
}
@@ -302,6 +303,7 @@ const char *Instruction::getOpcodeName(unsigned OpCode) {
case CatchRet: return "catchret";
case CatchPad: return "catchpad";
case CatchSwitch: return "catchswitch";
+ case CallBr: return "callbr";
// Standard unary operators...
case FNeg: return "fneg";
@@ -406,6 +408,10 @@ static bool haveSameSpecialState(const Instruction *I1, const Instruction *I2,
return CI->getCallingConv() == cast<InvokeInst>(I2)->getCallingConv() &&
CI->getAttributes() == cast<InvokeInst>(I2)->getAttributes() &&
CI->hasIdenticalOperandBundleSchema(*cast<InvokeInst>(I2));
+ if (const CallBrInst *CI = dyn_cast<CallBrInst>(I1))
+ return CI->getCallingConv() == cast<CallBrInst>(I2)->getCallingConv() &&
+ CI->getAttributes() == cast<CallBrInst>(I2)->getAttributes() &&
+ CI->hasIdenticalOperandBundleSchema(*cast<CallBrInst>(I2));
if (const InsertValueInst *IVI = dyn_cast<InsertValueInst>(I1))
return IVI->getIndices() == cast<InsertValueInst>(I2)->getIndices();
if (const ExtractValueInst *EVI = dyn_cast<ExtractValueInst>(I1))
@@ -516,9 +522,9 @@ bool Instruction::mayReadFromMemory() const {
case Instruction::CatchRet:
return true;
case Instruction::Call:
- return !cast<CallInst>(this)->doesNotAccessMemory();
case Instruction::Invoke:
- return !cast<InvokeInst>(this)->doesNotAccessMemory();
+ case Instruction::CallBr:
+ return !cast<CallBase>(this)->doesNotAccessMemory();
case Instruction::Store:
return !cast<StoreInst>(this)->isUnordered();
}
@@ -536,9 +542,9 @@ bool Instruction::mayWriteToMemory() const {
case Instruction::CatchRet:
return true;
case Instruction::Call:
- return !cast<CallInst>(this)->onlyReadsMemory();
case Instruction::Invoke:
- return !cast<InvokeInst>(this)->onlyReadsMemory();
+ case Instruction::CallBr:
+ return !cast<CallBase>(this)->onlyReadsMemory();
case Instruction::Load:
return !cast<LoadInst>(this)->isUnordered();
}
@@ -671,6 +677,13 @@ void Instruction::setSuccessor(unsigned idx, BasicBlock *B) {
llvm_unreachable("not a terminator");
}
+void Instruction::replaceSuccessorWith(BasicBlock *OldBB, BasicBlock *NewBB) {
+ for (unsigned Idx = 0, NumSuccessors = Instruction::getNumSuccessors();
+ Idx != NumSuccessors; ++Idx)
+ if (getSuccessor(Idx) == OldBB)
+ setSuccessor(Idx, NewBB);
+}
+
Instruction *Instruction::cloneImpl() const {
llvm_unreachable("Subclass of Instruction failed to implement cloneImpl");
}
@@ -731,52 +744,9 @@ Instruction *Instruction::clone() const {
return New;
}
-void Instruction::updateProfWeight(uint64_t S, uint64_t T) {
- auto *ProfileData = getMetadata(LLVMContext::MD_prof);
- if (ProfileData == nullptr)
- return;
-
- auto *ProfDataName = dyn_cast<MDString>(ProfileData->getOperand(0));
- if (!ProfDataName || (!ProfDataName->getString().equals("branch_weights") &&
- !ProfDataName->getString().equals("VP")))
- return;
-
- MDBuilder MDB(getContext());
- SmallVector<Metadata *, 3> Vals;
- Vals.push_back(ProfileData->getOperand(0));
- APInt APS(128, S), APT(128, T);
- if (ProfDataName->getString().equals("branch_weights"))
- for (unsigned i = 1; i < ProfileData->getNumOperands(); i++) {
- // Using APInt::div may be expensive, but most cases should fit 64 bits.
- APInt Val(128,
- mdconst::dyn_extract<ConstantInt>(ProfileData->getOperand(i))
- ->getValue()
- .getZExtValue());
- Val *= APS;
- Vals.push_back(MDB.createConstant(
- ConstantInt::get(Type::getInt64Ty(getContext()),
- Val.udiv(APT).getLimitedValue())));
- }
- else if (ProfDataName->getString().equals("VP"))
- for (unsigned i = 1; i < ProfileData->getNumOperands(); i += 2) {
- // The first value is the key of the value profile, which will not change.
- Vals.push_back(ProfileData->getOperand(i));
- // Using APInt::div may be expensive, but most cases should fit 64 bits.
- APInt Val(128,
- mdconst::dyn_extract<ConstantInt>(ProfileData->getOperand(i + 1))
- ->getValue()
- .getZExtValue());
- Val *= APS;
- Vals.push_back(MDB.createConstant(
- ConstantInt::get(Type::getInt64Ty(getContext()),
- Val.udiv(APT).getLimitedValue())));
- }
- setMetadata(LLVMContext::MD_prof, MDNode::get(getContext(), Vals));
-}
-
void Instruction::setProfWeight(uint64_t W) {
- assert((isa<CallInst>(this) || isa<InvokeInst>(this)) &&
- "Can only set weights for call and invoke instrucitons");
+ assert(isa<CallBase>(this) &&
+ "Can only set weights for call like instructions");
SmallVector<uint32_t, 1> Weights;
Weights.push_back(W);
MDBuilder MDB(getContext());