2012-06-02 10:20:22 +00:00
|
|
|
//===- HexagonRemoveExtendArgs.cpp - Remove unnecessary argument sign extends //
|
2011-12-12 21:14:40 +00:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// Pass that removes sign extends for function parameters. These parameters
|
|
|
|
// are already sign extended by the caller per Hexagon's ABI
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2012-12-03 16:50:05 +00:00
|
|
|
#include "Hexagon.h"
|
2012-02-06 10:19:29 +00:00
|
|
|
#include "HexagonTargetMachine.h"
|
2012-12-03 16:50:05 +00:00
|
|
|
#include "llvm/CodeGen/MachineFunctionAnalysis.h"
|
2015-01-28 04:57:56 +00:00
|
|
|
#include "llvm/CodeGen/StackProtector.h"
|
2013-01-02 11:36:10 +00:00
|
|
|
#include "llvm/IR/Function.h"
|
|
|
|
#include "llvm/IR/Instructions.h"
|
2012-02-06 10:19:29 +00:00
|
|
|
#include "llvm/Pass.h"
|
|
|
|
#include "llvm/Transforms/Scalar.h"
|
2011-12-12 21:14:40 +00:00
|
|
|
|
|
|
|
using namespace llvm;
|
2013-05-06 21:58:00 +00:00
|
|
|
|
|
|
|
namespace llvm {
|
2015-06-15 19:05:35 +00:00
|
|
|
FunctionPass *createHexagonRemoveExtendArgs(const HexagonTargetMachine &TM);
|
2013-05-06 21:58:00 +00:00
|
|
|
void initializeHexagonRemoveExtendArgsPass(PassRegistry&);
|
|
|
|
}
|
|
|
|
|
2011-12-12 21:14:40 +00:00
|
|
|
namespace {
|
|
|
|
struct HexagonRemoveExtendArgs : public FunctionPass {
|
|
|
|
public:
|
|
|
|
static char ID;
|
2013-05-06 21:58:00 +00:00
|
|
|
HexagonRemoveExtendArgs() : FunctionPass(ID) {
|
|
|
|
initializeHexagonRemoveExtendArgsPass(*PassRegistry::getPassRegistry());
|
|
|
|
}
|
2014-04-29 07:58:16 +00:00
|
|
|
bool runOnFunction(Function &F) override;
|
2011-12-12 21:14:40 +00:00
|
|
|
|
2014-04-29 07:58:16 +00:00
|
|
|
const char *getPassName() const override {
|
2011-12-12 21:14:40 +00:00
|
|
|
return "Remove sign extends";
|
|
|
|
}
|
|
|
|
|
2014-04-29 07:58:16 +00:00
|
|
|
void getAnalysisUsage(AnalysisUsage &AU) const override {
|
2011-12-12 21:14:40 +00:00
|
|
|
AU.addRequired<MachineFunctionAnalysis>();
|
|
|
|
AU.addPreserved<MachineFunctionAnalysis>();
|
2015-01-28 04:57:56 +00:00
|
|
|
AU.addPreserved<StackProtector>();
|
2011-12-12 21:14:40 +00:00
|
|
|
FunctionPass::getAnalysisUsage(AU);
|
|
|
|
}
|
|
|
|
};
|
2015-06-23 09:49:53 +00:00
|
|
|
}
|
2011-12-12 21:14:40 +00:00
|
|
|
|
|
|
|
char HexagonRemoveExtendArgs::ID = 0;
|
|
|
|
|
2013-05-06 21:58:00 +00:00
|
|
|
INITIALIZE_PASS(HexagonRemoveExtendArgs, "reargs",
|
|
|
|
"Remove Sign and Zero Extends for Args", false, false)
|
2011-12-12 21:14:40 +00:00
|
|
|
|
|
|
|
bool HexagonRemoveExtendArgs::runOnFunction(Function &F) {
|
|
|
|
unsigned Idx = 1;
|
|
|
|
for (Function::arg_iterator AI = F.arg_begin(), AE = F.arg_end(); AI != AE;
|
|
|
|
++AI, ++Idx) {
|
2012-12-30 12:45:13 +00:00
|
|
|
if (F.getAttributes().hasAttribute(Idx, Attribute::SExt)) {
|
2011-12-12 21:14:40 +00:00
|
|
|
Argument* Arg = AI;
|
|
|
|
if (!isa<PointerType>(Arg->getType())) {
|
2014-03-09 03:16:01 +00:00
|
|
|
for (auto UI = Arg->user_begin(); UI != Arg->user_end();) {
|
2011-12-12 21:14:40 +00:00
|
|
|
if (isa<SExtInst>(*UI)) {
|
2014-03-09 03:16:01 +00:00
|
|
|
Instruction* I = cast<Instruction>(*UI);
|
|
|
|
SExtInst* SI = new SExtInst(Arg, I->getType());
|
2011-12-12 21:14:40 +00:00
|
|
|
assert (EVT::getEVT(SI->getType()) ==
|
2014-03-09 03:16:01 +00:00
|
|
|
(EVT::getEVT(I->getType())));
|
2011-12-12 21:14:40 +00:00
|
|
|
++UI;
|
2014-03-09 03:16:01 +00:00
|
|
|
I->replaceAllUsesWith(SI);
|
2011-12-12 21:14:40 +00:00
|
|
|
Instruction* First = F.getEntryBlock().begin();
|
|
|
|
SI->insertBefore(First);
|
2014-03-09 03:16:01 +00:00
|
|
|
I->eraseFromParent();
|
2011-12-12 21:14:40 +00:00
|
|
|
} else {
|
|
|
|
++UI;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-05-06 18:38:37 +00:00
|
|
|
FunctionPass*
|
|
|
|
llvm::createHexagonRemoveExtendArgs(const HexagonTargetMachine &TM) {
|
2011-12-12 21:14:40 +00:00
|
|
|
return new HexagonRemoveExtendArgs();
|
|
|
|
}
|