31 AVRShiftExpandLegacy() : FunctionPass(ID) {}
35 StringRef getPassName()
const override {
return "AVR Shift Expansion"; }
40char AVRShiftExpandLegacy::ID = 0;
46 return new AVRShiftExpandLegacy();
54 Value *Int8Zero = ConstantInt::get(Int8Ty, 0);
65 Builder.SetInsertPoint(&BB->
back());
70 Value *Cmp1 = Builder.CreateICmpEQ(ShiftAmount, Int8Zero);
71 Builder.CreateCondBr(Cmp1, EndBB, LoopBB);
75 Builder.SetInsertPoint(LoopBB);
76 PHINode *ShiftAmountPHI = Builder.CreatePHI(Int8Ty, 2);
78 PHINode *ValuePHI = Builder.CreatePHI(InputTy, 2);
83 Value *ShiftAmountSub =
84 Builder.CreateSub(ShiftAmountPHI, ConstantInt::get(Int8Ty, 1));
85 ShiftAmountPHI->
addIncoming(ShiftAmountSub, LoopBB);
92 case Instruction::Shl:
93 ValueShifted = Builder.CreateShl(ValuePHI, ConstantInt::get(InputTy, 1));
95 case Instruction::LShr:
96 ValueShifted = Builder.CreateLShr(ValuePHI, ConstantInt::get(InputTy, 1));
98 case Instruction::AShr:
99 ValueShifted = Builder.CreateAShr(ValuePHI, ConstantInt::get(InputTy, 1));
108 Value *Cmp2 = Builder.CreateICmpEQ(ShiftAmountSub, Int8Zero);
109 Builder.CreateCondBr(Cmp2, EndBB, LoopBB);
113 Builder.SetInsertPoint(BI);
114 PHINode *Result = Builder.CreatePHI(InputTy, 2);
116 Result->addIncoming(ValueShifted, LoopBB);
125 auto &Ctx =
F.getContext();
145 for (
auto *
I : ShiftInsts) {
150 return ShiftInsts.
size() > 0;
153bool AVRShiftExpandLegacy::runOnFunction(
Function &
F) {
static bool expandShiftsInFunction(Function &F)
static void expandBinaryOperator(BinaryOperator *BI)
Expand Atomic instructions
static bool runOnFunction(Function &F, bool PostInlining)
This header defines various interfaces for pass management in LLVM.
FunctionAnalysisManager FAM
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM)
LLVM Basic Block Representation.
LLVM_ABI BasicBlock * splitBasicBlock(iterator I, const Twine &BBName="")
Split the basic block into two basic blocks at the specified instruction.
const Function * getParent() const
Return the enclosing method, or null if none.
const Instruction & back() const
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
BinaryOps getOpcode() const
FunctionPass class - This class is used to implement most global optimizations.
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
LLVM_ABI InstListType::iterator eraseFromParent()
This method unlinks 'this' from the containing basic block and deletes it.
void addIncoming(Value *V, BasicBlock *BB)
Add an incoming value to the end of the PHI list.
Pass interface - Implemented by all 'passes'.
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
The instances of the Type class are immutable: once they are created, they are never changed.
static LLVM_ABI IntegerType * getInt8Ty(LLVMContext &C)
static LLVM_ABI IntegerType * getInt16Ty(LLVMContext &C)
Value * getOperand(unsigned i) const
LLVM Value Representation.
LLVM_ABI void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
LLVMContext & getContext() const
All values hold a context through their type.
const ParentTy * getParent() const
Pass manager infrastructure for declaring and invalidating analyses.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This is an optimization pass for GlobalISel generic memory operations.
Pass * createAVRShiftExpandLegacyPass()
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.