1 //===- HexagonRemoveExtendArgs.cpp - Remove unnecessary 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 //===----------------------------------------------------------------------===//
16 #include "HexagonTargetMachine.h"
17 #include "llvm/CodeGen/MachineFunctionAnalysis.h"
18 #include "llvm/IR/Function.h"
19 #include "llvm/IR/Instructions.h"
20 #include "llvm/Pass.h"
21 #include "llvm/Transforms/Scalar.h"
25 struct HexagonRemoveExtendArgs : public FunctionPass {
28 HexagonRemoveExtendArgs() : FunctionPass(ID) {}
29 virtual bool runOnFunction(Function &F);
31 const char *getPassName() const {
32 return "Remove sign extends";
35 virtual void getAnalysisUsage(AnalysisUsage &AU) const {
36 AU.addRequired<MachineFunctionAnalysis>();
37 AU.addPreserved<MachineFunctionAnalysis>();
38 FunctionPass::getAnalysisUsage(AU);
43 char HexagonRemoveExtendArgs::ID = 0;
44 RegisterPass<HexagonRemoveExtendArgs> X("reargs",
45 "Remove Sign and Zero Extends for Args"
50 bool HexagonRemoveExtendArgs::runOnFunction(Function &F) {
52 for (Function::arg_iterator AI = F.arg_begin(), AE = F.arg_end(); AI != AE;
54 if (F.getAttributes().hasAttribute(Idx, Attribute::SExt)) {
56 if (!isa<PointerType>(Arg->getType())) {
57 for (Instruction::use_iterator UI = Arg->use_begin();
58 UI != Arg->use_end();) {
59 if (isa<SExtInst>(*UI)) {
60 Instruction* Use = cast<Instruction>(*UI);
61 SExtInst* SI = new SExtInst(Arg, Use->getType());
62 assert (EVT::getEVT(SI->getType()) ==
63 (EVT::getEVT(Use->getType())));
65 Use->replaceAllUsesWith(SI);
66 Instruction* First = F.getEntryBlock().begin();
67 SI->insertBefore(First);
68 Use->eraseFromParent();
81 FunctionPass *llvm::createHexagonRemoveExtendOps(HexagonTargetMachine &TM) {
82 return new HexagonRemoveExtendArgs();