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 //===----------------------------------------------------------------------===//
15 #include "HexagonTargetMachine.h"
16 #include "llvm/Function.h"
17 #include "llvm/Instructions.h"
18 #include "llvm/Pass.h"
19 #include "llvm/CodeGen/MachineFunctionAnalysis.h"
20 #include "llvm/Transforms/Scalar.h"
24 struct HexagonRemoveExtendArgs : public FunctionPass {
27 HexagonRemoveExtendArgs() : FunctionPass(ID) {}
28 virtual bool runOnFunction(Function &F);
30 const char *getPassName() const {
31 return "Remove sign extends";
34 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
35 AU.addRequired<MachineFunctionAnalysis>();
36 AU.addPreserved<MachineFunctionAnalysis>();
37 FunctionPass::getAnalysisUsage(AU);
42 char HexagonRemoveExtendArgs::ID = 0;
43 RegisterPass<HexagonRemoveExtendArgs> X("reargs",
44 "Remove Sign and Zero Extends for Args"
49 bool HexagonRemoveExtendArgs::runOnFunction(Function &F) {
51 for (Function::arg_iterator AI = F.arg_begin(), AE = F.arg_end(); AI != AE;
53 if (F.paramHasAttr(Idx, Attribute::SExt)) {
55 if (!isa<PointerType>(Arg->getType())) {
56 for (Instruction::use_iterator UI = Arg->use_begin();
57 UI != Arg->use_end();) {
58 if (isa<SExtInst>(*UI)) {
59 Instruction* Use = cast<Instruction>(*UI);
60 SExtInst* SI = new SExtInst(Arg, Use->getType());
61 assert (EVT::getEVT(SI->getType()) ==
62 (EVT::getEVT(Use->getType())));
64 Use->replaceAllUsesWith(SI);
65 Instruction* First = F.getEntryBlock().begin();
66 SI->insertBefore(First);
67 Use->eraseFromParent();
80 FunctionPass *llvm::createHexagonRemoveExtendOps(HexagonTargetMachine &TM) {
81 return new HexagonRemoveExtendArgs();