forked from OSchip/llvm-project
[Profile] code refactoring: make getStep a method in base class
llvm-svn: 282002
This commit is contained in:
parent
9b5d89513b
commit
a754c47ac5
|
@ -359,6 +359,7 @@ namespace llvm {
|
||||||
ConstantInt *getIndex() const {
|
ConstantInt *getIndex() const {
|
||||||
return cast<ConstantInt>(const_cast<Value *>(getArgOperand(3)));
|
return cast<ConstantInt>(const_cast<Value *>(getArgOperand(3)));
|
||||||
}
|
}
|
||||||
|
Value *getStep() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
class InstrProfIncrementInstStep : public InstrProfIncrementInst {
|
class InstrProfIncrementInstStep : public InstrProfIncrementInst {
|
||||||
|
@ -369,7 +370,6 @@ namespace llvm {
|
||||||
static inline bool classof(const Value *V) {
|
static inline bool classof(const Value *V) {
|
||||||
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
|
return isa<IntrinsicInst>(V) && classof(cast<IntrinsicInst>(V));
|
||||||
}
|
}
|
||||||
Value *getStep() const { return const_cast<Value *>(getArgOperand(4)); }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/// This represents the llvm.instrprof_value_profile intrinsic.
|
/// This represents the llvm.instrprof_value_profile intrinsic.
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
#include "llvm/IR/Constants.h"
|
#include "llvm/IR/Constants.h"
|
||||||
#include "llvm/IR/GlobalVariable.h"
|
#include "llvm/IR/GlobalVariable.h"
|
||||||
#include "llvm/IR/Metadata.h"
|
#include "llvm/IR/Metadata.h"
|
||||||
|
#include "llvm/IR/Module.h"
|
||||||
#include "llvm/Support/raw_ostream.h"
|
#include "llvm/Support/raw_ostream.h"
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
|
@ -83,3 +84,12 @@ int llvm::Intrinsic::lookupLLVMIntrinsicByName(ArrayRef<const char *> NameTable,
|
||||||
return LastLow - NameTable.begin();
|
return LastLow - NameTable.begin();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Value *InstrProfIncrementInst::getStep() const {
|
||||||
|
if (InstrProfIncrementInstStep::classof(this)) {
|
||||||
|
return const_cast<Value *>(getArgOperand(4));
|
||||||
|
}
|
||||||
|
const Module *M = getModule();
|
||||||
|
LLVMContext &Context = M->getContext();
|
||||||
|
return ConstantInt::get(Type::getInt64Ty(Context), 1);
|
||||||
|
}
|
||||||
|
|
|
@ -222,14 +222,6 @@ void InstrProfiling::lowerValueProfileInst(InstrProfValueProfileInst *Ind) {
|
||||||
Ind->eraseFromParent();
|
Ind->eraseFromParent();
|
||||||
}
|
}
|
||||||
|
|
||||||
static Value *getIncrementStep(InstrProfIncrementInst *Inc,
|
|
||||||
IRBuilder<> &Builder) {
|
|
||||||
auto *IncWithStep = dyn_cast<InstrProfIncrementInstStep>(Inc);
|
|
||||||
if (IncWithStep)
|
|
||||||
return IncWithStep->getStep();
|
|
||||||
return Builder.getInt64(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
void InstrProfiling::lowerIncrement(InstrProfIncrementInst *Inc) {
|
void InstrProfiling::lowerIncrement(InstrProfIncrementInst *Inc) {
|
||||||
GlobalVariable *Counters = getOrCreateRegionCounters(Inc);
|
GlobalVariable *Counters = getOrCreateRegionCounters(Inc);
|
||||||
|
|
||||||
|
@ -237,7 +229,7 @@ void InstrProfiling::lowerIncrement(InstrProfIncrementInst *Inc) {
|
||||||
uint64_t Index = Inc->getIndex()->getZExtValue();
|
uint64_t Index = Inc->getIndex()->getZExtValue();
|
||||||
Value *Addr = Builder.CreateConstInBoundsGEP2_64(Counters, 0, Index);
|
Value *Addr = Builder.CreateConstInBoundsGEP2_64(Counters, 0, Index);
|
||||||
Value *Count = Builder.CreateLoad(Addr, "pgocount");
|
Value *Count = Builder.CreateLoad(Addr, "pgocount");
|
||||||
Count = Builder.CreateAdd(Count, getIncrementStep(Inc, Builder));
|
Count = Builder.CreateAdd(Count, Inc->getStep());
|
||||||
Inc->replaceAllUsesWith(Builder.CreateStore(Count, Addr));
|
Inc->replaceAllUsesWith(Builder.CreateStore(Count, Addr));
|
||||||
Inc->eraseFromParent();
|
Inc->eraseFromParent();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue