[llvm-commits] [llvm] r54000 - in /llvm/trunk: include/llvm/CodeGen/LiveIntervalAnalysis.h include/llvm/CodeGen/MachineRegisterInfo.h include/llvm/CodeGen/PseudoSourceValue.h lib/CodeGen/LiveIntervalAnalysis.cpp lib/CodeGen/PseudoSourceValue.cpp test/CodeGen/X86/remat-constant.ll
Evan Cheng
evan.cheng at apple.com
Thu Jul 24 18:02:23 PDT 2008
On Jul 24, 2008, at 5:02 PM, Dan Gohman wrote:
Very nice. But this logic can potentially be shared (e.g. machine
LICM)? Should it be moved elsewhere? For example,
MachineInstr::isSafeToMove() does some of the check.
Evan
>
> + // If the instruction access memory but the memoperands have
> been lost,
> + // we can't analyze it.
> const TargetInstrDesc &TID = MI->getDesc();
> - isLoad = TID.isSimpleLoad();
> + if ((TID.mayLoad() || TID.mayStore()) && MI->memoperands_empty())
> + return false;
>
> - unsigned ImpUse = getReMatImplicitUse(li, MI);
> - if (ImpUse) {
> - const LiveInterval &ImpLi = getInterval(ImpUse);
> - for (MachineRegisterInfo::use_iterator ri = mri_-
> >use_begin(li.reg),
> - re = mri_->use_end(); ri != re; ++ri) {
> - MachineInstr *UseMI = &*ri;
> - unsigned UseIdx = getInstructionIndex(UseMI);
> - if (li.FindLiveRangeContaining(UseIdx)->valno != ValNo)
> + // Avoid instructions obviously unsafe for remat.
> + if (TID.hasUnmodeledSideEffects() || TID.isNotDuplicable())
> + return false;
> +
> + // If the instruction accesses memory and the memory could be
> non-constant,
> + // assume the instruction is not rematerializable.
> + for (alist<MachineMemOperand>::const_iterator I = MI-
> >memoperands_begin(),
> + E = MI->memoperands_end(); I != E; ++I) {
> + const MachineMemOperand &MMO = *I;
> + if (MMO.isVolatile() || MMO.isStore())
> + return false;
> + const Value *V = MMO.getValue();
> + if (!V)
> + return false;
> + if (const PseudoSourceValue *PSV =
> dyn_cast<PseudoSourceValue>(V)) {
> + if (!PSV->isConstant(mf_->getFrameInfo()))
> + return false;
> + } else if (!aa_->pointsToConstantMemory(V))
> + return false;
> + }
> +
> + // If any of the registers accessed are non-constant,
> conservatively assume
> + // the instruction is not rematerializable.
> + unsigned ImpUse = 0;
> + for (unsigned i = 0, e = MI->getNumOperands(); i != e; ++i) {
> + const MachineOperand &MO = MI->getOperand(i);
> + if (MO.isReg()) {
> + unsigned Reg = MO.getReg();
> + if (Reg == 0)
> continue;
> - if (!isValNoAvailableAt(ImpLi, MI, UseIdx))
> + if (TargetRegisterInfo::isPhysicalRegister(Reg))
> + return false;
> +
> + // Only allow one def, and that in the first operand.
> + if (MO.isDef() != (i == 0))
> + return false;
> +
> + // Only allow constant-valued registers.
> + bool IsLiveIn = mri_->isLiveIn(Reg);
> + MachineRegisterInfo::def_iterator I = mri_->def_begin(Reg),
> + E = mri_->def_end();
> +
> + // For the def, it should be the only def.
> + if (MO.isDef() && (next(I) != E || IsLiveIn))
> return false;
> +
> + if (MO.isUse()) {
> + // Only allow one use other register use, as that's all the
> + // remat mechanisms support currently.
> + if (Reg != li.reg) {
> + if (ImpUse == 0)
> + ImpUse = Reg;
> + else if (Reg != ImpUse)
> + return false;
> + }
> + // For uses, there should be only one associate def.
> + if (I != E && (next(I) != E || IsLiveIn))
> + return false;
> + }
> }
> }
> - return true;
> }
>
> - return false;
> + unsigned ImpUse = getReMatImplicitUse(li, MI);
> + if (ImpUse) {
> + const LiveInterval &ImpLi = getInterval(ImpUse);
> + for (MachineRegisterInfo::use_iterator ri = mri_-
> >use_begin(li.reg),
> + re = mri_->use_end(); ri != re; ++ri) {
> + MachineInstr *UseMI = &*ri;
> + unsigned UseIdx = getInstructionIndex(UseMI);
> + if (li.FindLiveRangeContaining(UseIdx)->valno != ValNo)
> + continue;
> + if (!isValNoAvailableAt(ImpLi, MI, UseIdx))
> + return false;
> + }
> + }
> + return true;
> }
>
> /// isReMaterializable - Returns true if every definition of MI of
> every
>
> Modified: llvm/trunk/lib/CodeGen/PseudoSourceValue.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/PseudoSourceValue.cpp?rev=54000&r1=53999&r2=54000&view=diff
>
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> --- llvm/trunk/lib/CodeGen/PseudoSourceValue.cpp (original)
> +++ llvm/trunk/lib/CodeGen/PseudoSourceValue.cpp Thu Jul 24 19:02:30
> 2008
> @@ -11,6 +11,7 @@
> //
> //
> =
> =
> =
> ----------------------------------------------------------------------=
> ==//
>
> +#include "llvm/CodeGen/MachineFrameInfo.h"
> #include "llvm/CodeGen/PseudoSourceValue.h"
> #include "llvm/DerivedTypes.h"
> #include "llvm/Support/Compiler.h"
> @@ -51,6 +52,9 @@
> const int FI;
> public:
> explicit FixedStackPseudoSourceValue(int fi) : FI(fi) {}
> +
> + virtual bool isConstant(const MachineFrameInfo *MFI) const;
> +
> virtual void print(std::ostream &OS) const {
> OS << "FixedStack" << FI;
> }
> @@ -64,4 +68,20 @@
> V = new FixedStackPseudoSourceValue(FI);
> return V;
> }
> +
> + bool PseudoSourceValue::isConstant(const MachineFrameInfo *)
> const {
> + if (this == getStack())
> + return false;
> + if (this == getGOT() ||
> + this == getConstantPool() ||
> + this == getJumpTable())
> + return true;
> + assert(0 && "Unknown PseudoSourceValue!");
> + return false;
> + }
> +
> + bool
> + FixedStackPseudoSourceValue::isConstant(const MachineFrameInfo
> *MFI) const {
> + return MFI && MFI->isImmutableObjectIndex(FI);
> + }
> }
>
> Added: llvm/trunk/test/CodeGen/X86/remat-constant.ll
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/remat-constant.ll?rev=54000&view=auto
>
> =
> =
> =
> =
> =
> =
> =
> =
> ======================================================================
> --- llvm/trunk/test/CodeGen/X86/remat-constant.ll (added)
> +++ llvm/trunk/test/CodeGen/X86/remat-constant.ll Thu Jul 24
> 19:02:30 2008
> @@ -0,0 +1,15 @@
> +; RUN: llvm-as < %s | llc -march=x86-64 -relocation-model=static |
> grep xmm | count 2
> +
> +declare void @bar() nounwind
> +
> + at a = external constant float
> +
> +declare void @qux(float %f) nounwind
> +
> +define void @foo() nounwind {
> + %f = load float* @a
> + call void @bar()
> + call void @qux(float %f)
> + call void @qux(float %f)
> + ret void
> +}
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
More information about the llvm-commits
mailing list