LLVM API Documentation

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HexagonRemoveSZExtArgs.cpp
Go to the documentation of this file.
1 //===- HexagonRemoveExtendArgs.cpp - Remove unnecessary argument sign extends //
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // Pass that removes sign extends for function parameters. These parameters
11 // are already sign extended by the caller per Hexagon's ABI
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #include "Hexagon.h"
16 #include "HexagonTargetMachine.h"
18 #include "llvm/IR/Function.h"
19 #include "llvm/IR/Instructions.h"
20 #include "llvm/Pass.h"
21 #include "llvm/Transforms/Scalar.h"
22 
23 using namespace llvm;
24 
25 namespace llvm {
27 }
28 
29 namespace {
30  struct HexagonRemoveExtendArgs : public FunctionPass {
31  public:
32  static char ID;
33  HexagonRemoveExtendArgs() : FunctionPass(ID) {
35  }
36  virtual bool runOnFunction(Function &F);
37 
38  const char *getPassName() const {
39  return "Remove sign extends";
40  }
41 
42  virtual void getAnalysisUsage(AnalysisUsage &AU) const {
46  }
47  };
48 }
49 
51 
52 INITIALIZE_PASS(HexagonRemoveExtendArgs, "reargs",
53  "Remove Sign and Zero Extends for Args", false, false)
54 
55 bool HexagonRemoveExtendArgs::runOnFunction(Function &F) {
56  unsigned Idx = 1;
57  for (Function::arg_iterator AI = F.arg_begin(), AE = F.arg_end(); AI != AE;
58  ++AI, ++Idx) {
59  if (F.getAttributes().hasAttribute(Idx, Attribute::SExt)) {
60  Argument* Arg = AI;
61  if (!isa<PointerType>(Arg->getType())) {
62  for (Instruction::use_iterator UI = Arg->use_begin();
63  UI != Arg->use_end();) {
64  if (isa<SExtInst>(*UI)) {
65  Instruction* Use = cast<Instruction>(*UI);
66  SExtInst* SI = new SExtInst(Arg, Use->getType());
67  assert (EVT::getEVT(SI->getType()) ==
68  (EVT::getEVT(Use->getType())));
69  ++UI;
70  Use->replaceAllUsesWith(SI);
71  Instruction* First = F.getEntryBlock().begin();
72  SI->insertBefore(First);
73  Use->eraseFromParent();
74  } else {
75  ++UI;
76  }
77  }
78  }
79  }
80  }
81  return true;
82 }
83 
84 
85 
88  return new HexagonRemoveExtendArgs();
89 }
use_iterator use_end()
Definition: Value.h:152
AnalysisUsage & addPreserved()
static PassRegistry * getPassRegistry()
LLVM Argument representation.
Definition: Argument.h:35
Sign extended before/after call.
Definition: Attributes.h:97
virtual void getAnalysisUsage(AnalysisUsage &) const
Definition: Pass.cpp:75
F(f)
This class represents a sign extension of integer types.
AnalysisUsage & addRequired()
Definition: Use.h:60
ID
LLVM Calling Convention Representation.
Definition: CallingConv.h:26
void replaceAllUsesWith(Value *V)
Definition: Value.cpp:303
INITIALIZE_PASS(HexagonRemoveExtendArgs,"reargs","Remove Sign and Zero Extends for Args", false, false) bool HexagonRemoveExtendArgs
value_use_iterator< User > use_iterator
Definition: Value.h:146
void insertBefore(Instruction *InsertPos)
Definition: Instruction.cpp:78
Type * getType() const
Definition: Value.h:111
FunctionPass * createHexagonRemoveExtendArgs(const HexagonTargetMachine &TM)
void initializeHexagonRemoveExtendArgsPass(PassRegistry &)
use_iterator use_begin()
Definition: Value.h:150
static EVT getEVT(Type *Ty, bool HandleUnknown=false)
Definition: ValueTypes.cpp:275