1 //=- HexagonRemoveExtendArgs.cpp - Remove unecessary argument sign extends --=//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // Pass that removes sign extends for function parameters. These parameters
11 // are already sign extended by the caller per Hexagon's ABI
13 //===----------------------------------------------------------------------===//
17 #include "llvm/Pass.h"
18 #include "llvm/Function.h"
19 #include "llvm/Instructions.h"
20 #include "llvm/Transforms/Scalar.h"
21 #include "llvm/CodeGen/MachineFunctionAnalysis.h"
22 #include "HexagonTargetMachine.h"
27 struct HexagonRemoveExtendArgs : public FunctionPass {
30 HexagonRemoveExtendArgs() : FunctionPass(ID) {}
31 virtual bool runOnFunction(Function &F);
33 const char *getPassName() const {
34 return "Remove sign extends";
37 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
38 AU.addRequired<MachineFunctionAnalysis>();
39 AU.addPreserved<MachineFunctionAnalysis>();
40 FunctionPass::getAnalysisUsage(AU);
45 char HexagonRemoveExtendArgs::ID = 0;
46 RegisterPass<HexagonRemoveExtendArgs> X("reargs",
47 "Remove Sign and Zero Extends for Args"
52 bool HexagonRemoveExtendArgs::runOnFunction(Function &F) {
54 for (Function::arg_iterator AI = F.arg_begin(), AE = F.arg_end(); AI != AE;
56 if (F.paramHasAttr(Idx, Attribute::SExt)) {
58 if (!isa<PointerType>(Arg->getType())) {
59 for (Instruction::use_iterator UI = Arg->use_begin();
60 UI != Arg->use_end();) {
61 if (isa<SExtInst>(*UI)) {
62 Instruction* Use = cast<Instruction>(*UI);
63 SExtInst* SI = new SExtInst(Arg, Use->getType());
64 assert (EVT::getEVT(SI->getType()) ==
65 (EVT::getEVT(Use->getType())));
67 Use->replaceAllUsesWith(SI);
68 Instruction* First = F.getEntryBlock().begin();
69 SI->insertBefore(First);
70 Use->eraseFromParent();
83 FunctionPass *llvm::createHexagonRemoveExtendOps(HexagonTargetMachine &TM) {
84 return new HexagonRemoveExtendArgs();