[llvm-commits] CVS: llvm/lib/Target/Sparc/AddRegNumToValues.cpp
Misha Brukman
brukman at cs.uiuc.edu
Tue May 27 15:06:01 PDT 2003
Changes in directory llvm/lib/Target/Sparc:
AddRegNumToValues.cpp added (r1.1)
---
Log message:
This file provides the `glue' to turn the Value*-based MachineInstrs that
the Sparc instruction selector produces to the unsigned-register-based
MachineInstrs that the target-independent register allocators in the JIT prefer.
---
Diffs of the changes:
Index: llvm/lib/Target/Sparc/AddRegNumToValues.cpp
diff -c /dev/null llvm/lib/Target/Sparc/AddRegNumToValues.cpp:1.1
*** /dev/null Tue May 27 15:05:37 2003
--- llvm/lib/Target/Sparc/AddRegNumToValues.cpp Tue May 27 15:05:27 2003
***************
*** 0 ****
--- 1,64 ----
+ //===-- AddRegNumToValues.cpp - Adds unsigned register indices for Value* -===//
+ //
+ // This is a placeholder pass, just so that it doesn't intrude too much into
+ // the MachineOperand class:
+ // * The Sparc back-end uses Value* in instructions for dataflow
+ // * The RegisterAllocator in the JIT expects unsigned register numbers instead
+ // of Value*
+ //
+ // This pass is an attempt to bridge the gap between the two, without putting an
+ // explicit conversion in the shortest path (i.e., the original LLC codegen).
+ //
+ //===----------------------------------------------------------------------===//
+
+ #include "llvm/CodeGen/Passes.h"
+ #include "llvm/CodeGen/MachineFunctionPass.h"
+ #include "llvm/CodeGen/MachineInstr.h"
+ #include "SparcInternals.h"
+
+ namespace {
+ struct AddRegNumToValues : MachineFunctionPass {
+
+ AddRegNumToValues() {}
+ bool runOnMachineFunction(MachineFunction &F);
+ };
+
+ static RegisterOpt<AddRegNumToValues>
+ X("add-regnum", "Add reg numbers to Values", createAddRegNumToValuesPass);
+ }
+
+ bool AddRegNumToValues::runOnMachineFunction(MachineFunction &F) {
+ unsigned regNum = MRegisterInfo::FirstVirtualRegister;
+ std::map<Value*,unsigned> Value2RegMap;
+
+ for (MachineFunction::iterator i = F.begin(), e = F.end(); i != e; ++i) {
+ MachineBasicBlock &BB = *i;
+ for (MachineBasicBlock::iterator Bi = BB.begin(), Be = BB.end();
+ Bi != Be; ++Bi)
+ {
+ MachineInstr *MI = *Bi;
+
+ // Loop over uses, move from memory into registers
+ for (int i = MI->getNumOperands()-1; i >= 0; --i) {
+ MachineOperand &op = MI->getOperand(i);
+
+ Value *val = op.getVRegValueOrNull();
+ if (Instruction *inst = dyn_cast<Instruction>(val)) {
+ if (Value2RegMap[val] != 0) {
+ MI->SetRegForOperand(i, Value2RegMap[val]);
+ } else {
+ MI->SetRegForOperand(i, regNum);
+ Value2RegMap[val] = regNum++;
+ }
+ }
+ }
+ }
+ }
+
+ Value2RegMap.clear();
+ return false;
+ }
+
+ Pass *createAddRegNumToValuesPass() {
+ return new AddRegNumToValues();
+ }
More information about the llvm-commits
mailing list