LLVM  3.7.0
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"
19 #include "llvm/IR/Function.h"
20 #include "llvm/IR/Instructions.h"
21 #include "llvm/Pass.h"
22 #include "llvm/Transforms/Scalar.h"
23 
24 using namespace llvm;
25 
26 namespace llvm {
29 }
30 
31 namespace {
32  struct HexagonRemoveExtendArgs : public FunctionPass {
33  public:
34  static char ID;
35  HexagonRemoveExtendArgs() : FunctionPass(ID) {
37  }
38  bool runOnFunction(Function &F) override;
39 
40  const char *getPassName() const override {
41  return "Remove sign extends";
42  }
43 
44  void getAnalysisUsage(AnalysisUsage &AU) const override {
49  }
50  };
51 }
52 
54 
55 INITIALIZE_PASS(HexagonRemoveExtendArgs, "reargs",
56  "Remove Sign and Zero Extends for Args", false, false)
57 
58 bool HexagonRemoveExtendArgs::runOnFunction(Function &F) {
59  unsigned Idx = 1;
60  for (Function::arg_iterator AI = F.arg_begin(), AE = F.arg_end(); AI != AE;
61  ++AI, ++Idx) {
62  if (F.getAttributes().hasAttribute(Idx, Attribute::SExt)) {
63  Argument* Arg = AI;
64  if (!isa<PointerType>(Arg->getType())) {
65  for (auto UI = Arg->user_begin(); UI != Arg->user_end();) {
66  if (isa<SExtInst>(*UI)) {
67  Instruction* I = cast<Instruction>(*UI);
68  SExtInst* SI = new SExtInst(Arg, I->getType());
69  assert (EVT::getEVT(SI->getType()) ==
70  (EVT::getEVT(I->getType())));
71  ++UI;
72  I->replaceAllUsesWith(SI);
73  Instruction* First = F.getEntryBlock().begin();
74  SI->insertBefore(First);
75  I->eraseFromParent();
76  } else {
77  ++UI;
78  }
79  }
80  }
81  }
82  }
83  return true;
84 }
85 
86 
87 
90  return new HexagonRemoveExtendArgs();
91 }
iplist< Instruction >::iterator eraseFromParent()
eraseFromParent - This method unlinks 'this' from the containing basic block and deletes it...
Definition: Instruction.cpp:70
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
LLVM Argument representation.
Definition: Argument.h:35
Sign extended before/after call.
Definition: Attributes.h:105
virtual void getAnalysisUsage(AnalysisUsage &) const
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
Definition: Pass.cpp:78
F(f)
This class represents a sign extension of integer types.
MachineFunctionAnalysis - This class is a Pass that manages a MachineFunction object.
AnalysisUsage & addRequired()
void replaceAllUsesWith(Value *V)
Change all uses of this to point to a new Value.
Definition: Value.cpp:351
INITIALIZE_PASS(HexagonRemoveExtendArgs,"reargs","Remove Sign and Zero Extends for Args", false, false) bool HexagonRemoveExtendArgs
void insertBefore(Instruction *InsertPos)
Insert an unlinked instruction into a basic block immediately before the specified instruction...
Definition: Instruction.cpp:76
Represent the analysis usage information of a pass.
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:294
Type * getType() const
All values are typed, get the type of this value.
Definition: Value.h:222
FunctionPass * createHexagonRemoveExtendArgs(const HexagonTargetMachine &TM)
void initializeHexagonRemoveExtendArgsPass(PassRegistry &)
#define I(x, y, z)
Definition: MD5.cpp:54
static EVT getEVT(Type *Ty, bool HandleUnknown=false)
getEVT - Return the value type corresponding to the specified type.
Definition: ValueTypes.cpp:277
user_iterator user_begin()
Definition: Value.h:294
PassRegistry - This class manages the registration and intitialization of the pass subsystem as appli...
Definition: PassRegistry.h:41
user_iterator user_end()
Definition: Value.h:296