[llvm-commits] [llvm] r55748 - in /llvm/trunk: include/llvm/CodeGen/FastISel.h lib/CodeGen/SelectionDAG/FastISel.cpp
Dan Gohman
gohman at apple.com
Wed Sep 3 16:32:19 PDT 2008
Author: djg
Date: Wed Sep 3 18:32:19 2008
New Revision: 55748
URL: http://llvm.org/viewvc/llvm-project?rev=55748&view=rev
Log:
Do trivial local CSE for constants and other non-Instruction values
in FastISel.
Modified:
llvm/trunk/include/llvm/CodeGen/FastISel.h
llvm/trunk/lib/CodeGen/SelectionDAG/FastISel.cpp
Modified: llvm/trunk/include/llvm/CodeGen/FastISel.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/CodeGen/FastISel.h?rev=55748&r1=55747&r2=55748&view=diff
==============================================================================
--- llvm/trunk/include/llvm/CodeGen/FastISel.h (original)
+++ llvm/trunk/include/llvm/CodeGen/FastISel.h Wed Sep 3 18:32:19 2008
@@ -36,6 +36,7 @@
class FastISel {
protected:
MachineBasicBlock *MBB;
+ DenseMap<const Value *, unsigned> LocalValueMap;
DenseMap<const Value *, unsigned> &ValueMap;
DenseMap<const BasicBlock *, MachineBasicBlock *> &MBBMap;
MachineFunction &MF;
Modified: llvm/trunk/lib/CodeGen/SelectionDAG/FastISel.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/FastISel.cpp?rev=55748&r1=55747&r2=55748&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/FastISel.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/FastISel.cpp Wed Sep 3 18:32:19 2008
@@ -21,13 +21,16 @@
#include "llvm/Target/TargetMachine.h"
using namespace llvm;
-// Don't cache constant materializations. To do so would require
-// tracking what uses they dominate. Non-constants, however, already
-// have the SSA def-doms-use requirement enforced, so we can cache their
-// computations.
unsigned FastISel::getRegForValue(Value *V) {
+ // Look up the value to see if we already have a register for it. We
+ // cache values defined by Instructions across blocks, and other values
+ // only locally. This is because Instructions already have the SSA
+ // def-dominatess-use requirement enforced.
if (ValueMap.count(V))
return ValueMap[V];
+ unsigned Reg = LocalValueMap[V];
+ if (Reg != 0)
+ return Reg;
MVT::SimpleValueType VT = TLI.getValueType(V->getType()).getSimpleVT();
if (ConstantInt *CI = dyn_cast<ConstantInt>(V)) {
@@ -35,11 +38,11 @@
return 0;
// Don't cache constant materializations. To do so would require
// tracking what uses they dominate.
- return FastEmit_i(VT, VT, ISD::Constant, CI->getZExtValue());
+ Reg = FastEmit_i(VT, VT, ISD::Constant, CI->getZExtValue());
} else if (isa<ConstantPointerNull>(V)) {
- return FastEmit_i(VT, VT, ISD::Constant, 0);
+ Reg = FastEmit_i(VT, VT, ISD::Constant, 0);
} else if (ConstantFP *CF = dyn_cast<ConstantFP>(V)) {
- unsigned Reg = FastEmit_f(VT, VT, ISD::ConstantFP, CF);
+ Reg = FastEmit_f(VT, VT, ISD::ConstantFP, CF);
if (!Reg) {
const APFloat &Flt = CF->getValueAPF();
@@ -60,15 +63,15 @@
if (Reg == 0)
return 0;
}
-
- return Reg;
} else if (isa<UndefValue>(V)) {
- unsigned Reg = createResultReg(TLI.getRegClassFor(VT));
+ Reg = createResultReg(TLI.getRegClassFor(VT));
BuildMI(MBB, TII.get(TargetInstrInfo::IMPLICIT_DEF), Reg);
- return Reg;
+ } else {
+ return 0;
}
- return 0;
+ LocalValueMap[V] = Reg;
+ return Reg;
}
/// UpdateValueMap - Update the value map to include the new mapping for this
More information about the llvm-commits
mailing list