[PATCH] [RFC][7/17]TILE-Gx: support pseduo instruction expanding for tilegx
Jiong WANG
wong.kwongyuan.llvm at gmail.com
Mon Mar 11 00:54:40 PDT 2013
add the patch. (do not know why it's not included in previous post, my editing time is too long?)
http://llvm-reviews.chandlerc.com/D517
Files:
lib/Target/Tile/TileExpandPseudo.cpp
Index: lib/Target/Tile/TileExpandPseudo.cpp
===================================================================
--- /dev/null
+++ lib/Target/Tile/TileExpandPseudo.cpp
@@ -0,0 +1,113 @@
+//===-- TileExpandPseudo.cpp - Expand Pseudo Instructions ----------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This pass expands pseudo instructions into target instructions after register
+// allocation but before post-RA scheduling.
+//
+//===----------------------------------------------------------------------===//
+
+#define DEBUG_TYPE "tile-expand-pseudo"
+
+#include "Tile.h"
+#include "TileTargetMachine.h"
+#include "llvm/CodeGen/MachineFunctionPass.h"
+#include "llvm/CodeGen/MachineInstrBuilder.h"
+#include "llvm/Target/TargetInstrInfo.h"
+#include "llvm/ADT/Statistic.h"
+
+using namespace llvm;
+
+namespace {
+ struct TileExpandPseudo : public MachineFunctionPass {
+
+ TargetMachine &TM;
+ const TargetInstrInfo *TII;
+
+ static char ID;
+ TileExpandPseudo(TargetMachine &tm)
+ : MachineFunctionPass(ID), TM(tm), TII(tm.getInstrInfo()) { }
+
+ virtual const char *getPassName() const {
+ return "Tile PseudoInstrs Expansion";
+ }
+
+ bool runOnMachineFunction(MachineFunction &F);
+ bool runOnMachineBasicBlock(MachineBasicBlock &MBB);
+
+ private:
+ void ExpandBuildPairF64(MachineBasicBlock&, MachineBasicBlock::iterator);
+ void ExpandExtractElementF64(MachineBasicBlock&,
+ MachineBasicBlock::iterator);
+ };
+ char TileExpandPseudo::ID = 0;
+} // end of anonymous namespace
+
+bool TileExpandPseudo::runOnMachineFunction(MachineFunction& F) {
+ bool Changed = false;
+
+ for (MachineFunction::iterator I = F.begin(); I != F.end(); ++I)
+ Changed |= runOnMachineBasicBlock(*I);
+
+ return Changed;
+}
+
+bool TileExpandPseudo::runOnMachineBasicBlock(MachineBasicBlock& MBB) {
+
+ bool Changed = false;
+ MachineFunction &MF = *MBB.getParent();
+ MachineFrameInfo *MFI = MF.getFrameInfo();
+ TileFunctionInfo *TFI = MF.getInfo<TileFunctionInfo>();
+ for (MachineBasicBlock::iterator I = MBB.begin(); I != MBB.end();) {
+ const MCInstrDesc& MCid = I->getDesc();
+
+ switch(MCid.getOpcode()) {
+ default:
+ ++I;
+ continue;
+ case Tile::VAARG_SP:
+ BuildMI(MBB, I, I->getDebugLoc(), TII->get(Tile::ADDLI),
+ I->getOperand(0).getReg())
+ .addReg(I->getOperand(1).getReg())
+ .addImm(MFI->getStackSize() + MFI->getOffsetAdjustment());
+ break;
+
+ // The addr alloca returned should by adjusted by the size
+ // of Tile 16bytes zone and arg outgoing zone.
+ case Tile::ALLOCA_ADDR:
+ BuildMI(MBB, I, I->getDebugLoc(), TII->get(Tile::ADDLI)
+ ,I->getOperand(0).getReg())
+ .addReg(I->getOperand(1).getReg())
+ .addImm(TFI->getMaxCallFrameSize() + (MFI->hasCalls() ? 16 : 0));
+ break;
+
+ case Tile::ALLOCA_SP:
+ unsigned src_sp = Tile::SP;
+ if (MFI->hasCalls())
+ src_sp = I->getOperand(2).getReg();
+
+ BuildMI(MBB, I, I->getDebugLoc(), TII->get(Tile::ADD)
+ ,I->getOperand(0).getReg())
+ .addReg(Tile::ZERO)
+ .addReg(src_sp);
+ break;
+
+ }
+
+ // Delete original instr.
+ MBB.erase(I++);
+ Changed = true;
+ }
+
+ return Changed;
+}
+
+/// Returns a pass that expands pseudo instrs into real instrs.
+FunctionPass *llvm::createTileExpandPseudoPass(TileTargetMachine &tm) {
+ return new TileExpandPseudo(tm);
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D517.1.patch
Type: text/x-patch
Size: 3755 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130311/d0419c9f/attachment.bin>
More information about the llvm-commits
mailing list