41char AVRShiftExpand::ID = 0;
48bool AVRShiftExpand::runOnFunction(
Function &
F) {
50 auto &Ctx =
F.getContext();
59 if (isa<ConstantInt>(
I.getOperand(1)))
63 ShiftInsts.
push_back(cast<BinaryOperator>(&
I));
69 for (
auto *
I : ShiftInsts) {
74 return ShiftInsts.size() > 0;
80 Type *InputTy = cast<Instruction>(BI)->getType();
82 Value *Int8Zero = ConstantInt::get(Int8Ty, 0);
93 Builder.SetInsertPoint(&BB->
back());
98 Value *Cmp1 = Builder.CreateICmpEQ(ShiftAmount, Int8Zero);
99 Builder.CreateCondBr(Cmp1, EndBB, LoopBB);
103 Builder.SetInsertPoint(LoopBB);
104 PHINode *ShiftAmountPHI = Builder.CreatePHI(Int8Ty, 2);
106 PHINode *ValuePHI = Builder.CreatePHI(InputTy, 2);
111 Value *ShiftAmountSub =
112 Builder.CreateSub(ShiftAmountPHI, ConstantInt::get(Int8Ty, 1));
113 ShiftAmountPHI->
addIncoming(ShiftAmountSub, LoopBB);
120 case Instruction::Shl:
121 ValueShifted = Builder.CreateShl(ValuePHI, ConstantInt::get(InputTy, 1));
123 case Instruction::LShr:
124 ValueShifted = Builder.CreateLShr(ValuePHI, ConstantInt::get(InputTy, 1));
126 case Instruction::AShr:
127 ValueShifted = Builder.CreateAShr(ValuePHI, ConstantInt::get(InputTy, 1));
136 Value *Cmp2 = Builder.CreateICmpEQ(ShiftAmountSub, Int8Zero);
137 Builder.CreateCondBr(Cmp2, EndBB, LoopBB);
141 Builder.SetInsertPoint(BI);
144 Result->addIncoming(ValueShifted, LoopBB);
Expand Atomic instructions
static Expected< BitVector > expand(StringRef S, StringRef Original)
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
LLVM Basic Block Representation.
static BasicBlock * Create(LLVMContext &Context, const Twine &Name="", Function *Parent=nullptr, BasicBlock *InsertBefore=nullptr)
Creates a new BasicBlock.
BasicBlock * splitBasicBlock(iterator I, const Twine &BBName="", bool Before=false)
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
BinaryOps getOpcode() const
FunctionPass class - This class is used to implement most global optimizations.
virtual bool runOnFunction(Function &F)=0
runOnFunction - Virtual method overriden by subclasses to do the per-function processing of the pass.
This provides a uniform API for creating instructions and inserting them into a basic block: either a...
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'.
virtual StringRef getPassName() const
getPassName - Return a nice clean name for a pass.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringRef - Represent a constant reference to a string, i.e.
The instances of the Type class are immutable: once they are created, they are never changed.
static IntegerType * getInt16Ty(LLVMContext &C)
static IntegerType * getInt8Ty(LLVMContext &C)
Value * getOperand(unsigned i) const
LLVM Value Representation.
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
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
This is an optimization pass for GlobalISel generic memory operations.
Pass * createAVRShiftExpandPass()