mirror of
				https://github.com/c64scene-ar/llvm-6502.git
				synced 2025-11-04 05:17:07 +00:00 
			
		
		
		
	Reapply r106422, splitting the code for materializing a value out of
SelectionDAGBuilder::getValue into a helper function, with fixes to use DenseMaps safely. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@107371 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
		@@ -805,27 +805,63 @@ void SelectionDAGBuilder::visit(unsigned Opcode, const User &I) {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// getValue - Return an SDValue for the given Value.
 | 
				
			||||||
SDValue SelectionDAGBuilder::getValue(const Value *V) {
 | 
					SDValue SelectionDAGBuilder::getValue(const Value *V) {
 | 
				
			||||||
 | 
					  // If we already have an SDValue for this value, use it. It's important
 | 
				
			||||||
 | 
					  // to do this first, so that we don't create a CopyFromReg if we already
 | 
				
			||||||
 | 
					  // have a regular SDValue.
 | 
				
			||||||
  SDValue &N = NodeMap[V];
 | 
					  SDValue &N = NodeMap[V];
 | 
				
			||||||
  if (N.getNode()) return N;
 | 
					  if (N.getNode()) return N;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // If there's a virtual register allocated and initialized for this
 | 
				
			||||||
 | 
					  // value, use it.
 | 
				
			||||||
 | 
					  DenseMap<const Value *, unsigned>::iterator It = FuncInfo.ValueMap.find(V);
 | 
				
			||||||
 | 
					  if (It != FuncInfo.ValueMap.end()) {
 | 
				
			||||||
 | 
					    unsigned InReg = It->second;
 | 
				
			||||||
 | 
					    RegsForValue RFV(*DAG.getContext(), TLI, InReg, V->getType());
 | 
				
			||||||
 | 
					    SDValue Chain = DAG.getEntryNode();
 | 
				
			||||||
 | 
					    return N = RFV.getCopyFromRegs(DAG, FuncInfo, getCurDebugLoc(), Chain, NULL);
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // Otherwise create a new SDValue and remember it.
 | 
				
			||||||
 | 
					  SDValue Val = getValueImpl(V);
 | 
				
			||||||
 | 
					  NodeMap[V] = Val;
 | 
				
			||||||
 | 
					  return Val;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/// getNonRegisterValue - Return an SDValue for the given Value, but
 | 
				
			||||||
 | 
					/// don't look in FuncInfo.ValueMap for a virtual register.
 | 
				
			||||||
 | 
					SDValue SelectionDAGBuilder::getNonRegisterValue(const Value *V) {
 | 
				
			||||||
 | 
					  // If we already have an SDValue for this value, use it.
 | 
				
			||||||
 | 
					  SDValue &N = NodeMap[V];
 | 
				
			||||||
 | 
					  if (N.getNode()) return N;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  // Otherwise create a new SDValue and remember it.
 | 
				
			||||||
 | 
					  SDValue Val = getValueImpl(V);
 | 
				
			||||||
 | 
					  NodeMap[V] = Val;
 | 
				
			||||||
 | 
					  return Val;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/// getValueImpl - Helper function for getValue and getMaterializedValue.
 | 
				
			||||||
 | 
					/// Create an SDValue for the given value.
 | 
				
			||||||
 | 
					SDValue SelectionDAGBuilder::getValueImpl(const Value *V) {
 | 
				
			||||||
  if (const Constant *C = dyn_cast<Constant>(V)) {
 | 
					  if (const Constant *C = dyn_cast<Constant>(V)) {
 | 
				
			||||||
    EVT VT = TLI.getValueType(V->getType(), true);
 | 
					    EVT VT = TLI.getValueType(V->getType(), true);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (const ConstantInt *CI = dyn_cast<ConstantInt>(C))
 | 
					    if (const ConstantInt *CI = dyn_cast<ConstantInt>(C))
 | 
				
			||||||
      return N = DAG.getConstant(*CI, VT);
 | 
					      return DAG.getConstant(*CI, VT);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (const GlobalValue *GV = dyn_cast<GlobalValue>(C))
 | 
					    if (const GlobalValue *GV = dyn_cast<GlobalValue>(C))
 | 
				
			||||||
      return N = DAG.getGlobalAddress(GV, VT);
 | 
					      return DAG.getGlobalAddress(GV, VT);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (isa<ConstantPointerNull>(C))
 | 
					    if (isa<ConstantPointerNull>(C))
 | 
				
			||||||
      return N = DAG.getConstant(0, TLI.getPointerTy());
 | 
					      return DAG.getConstant(0, TLI.getPointerTy());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (const ConstantFP *CFP = dyn_cast<ConstantFP>(C))
 | 
					    if (const ConstantFP *CFP = dyn_cast<ConstantFP>(C))
 | 
				
			||||||
      return N = DAG.getConstantFP(*CFP, VT);
 | 
					      return DAG.getConstantFP(*CFP, VT);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (isa<UndefValue>(C) && !V->getType()->isAggregateType())
 | 
					    if (isa<UndefValue>(C) && !V->getType()->isAggregateType())
 | 
				
			||||||
      return N = DAG.getUNDEF(VT);
 | 
					      return DAG.getUNDEF(VT);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) {
 | 
					    if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) {
 | 
				
			||||||
      visit(CE->getOpcode(), *CE);
 | 
					      visit(CE->getOpcode(), *CE);
 | 
				
			||||||
@@ -913,12 +949,18 @@ SDValue SelectionDAGBuilder::getValue(const Value *V) {
 | 
				
			|||||||
      return DAG.getFrameIndex(SI->second, TLI.getPointerTy());
 | 
					      return DAG.getFrameIndex(SI->second, TLI.getPointerTy());
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  unsigned InReg = FuncInfo.ValueMap[V];
 | 
					  // If this is an instruction which fast-isel has deferred, select it now.
 | 
				
			||||||
  assert(InReg && "Value not in map!");
 | 
					  if (const Instruction *Inst = dyn_cast<Instruction>(V)) {
 | 
				
			||||||
 | 
					    assert(Inst->isSafeToSpeculativelyExecute() &&
 | 
				
			||||||
 | 
					           "Instruction with side effects deferred!");
 | 
				
			||||||
 | 
					    visit(*Inst);
 | 
				
			||||||
 | 
					    DenseMap<const Value *, SDValue>::iterator NIt = NodeMap.find(Inst);
 | 
				
			||||||
 | 
					    if (NIt != NodeMap.end() && NIt->second.getNode())
 | 
				
			||||||
 | 
					      return NIt->second;
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  RegsForValue RFV(*DAG.getContext(), TLI, InReg, V->getType());
 | 
					  llvm_unreachable("Can't get register for value!");
 | 
				
			||||||
  SDValue Chain = DAG.getEntryNode();
 | 
					  return SDValue();
 | 
				
			||||||
  return RFV.getCopyFromRegs(DAG, FuncInfo, getCurDebugLoc(), Chain, NULL);
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/// Get the EVTs and ArgFlags collections that represent the legalized return 
 | 
					/// Get the EVTs and ArgFlags collections that represent the legalized return 
 | 
				
			||||||
@@ -5881,7 +5923,7 @@ SDValue TargetLowering::LowerOperation(SDValue Op, SelectionDAG &DAG) const {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
void
 | 
					void
 | 
				
			||||||
SelectionDAGBuilder::CopyValueToVirtualRegister(const Value *V, unsigned Reg) {
 | 
					SelectionDAGBuilder::CopyValueToVirtualRegister(const Value *V, unsigned Reg) {
 | 
				
			||||||
  SDValue Op = getValue(V);
 | 
					  SDValue Op = getNonRegisterValue(V);
 | 
				
			||||||
  assert((Op.getOpcode() != ISD::CopyFromReg ||
 | 
					  assert((Op.getOpcode() != ISD::CopyFromReg ||
 | 
				
			||||||
          cast<RegisterSDNode>(Op.getOperand(1))->getReg() != Reg) &&
 | 
					          cast<RegisterSDNode>(Op.getOperand(1))->getReg() != Reg) &&
 | 
				
			||||||
         "Copy from a reg to the same reg!");
 | 
					         "Copy from a reg to the same reg!");
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -346,6 +346,8 @@ public:
 | 
				
			|||||||
  void visit(unsigned Opcode, const User &I);
 | 
					  void visit(unsigned Opcode, const User &I);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  SDValue getValue(const Value *V);
 | 
					  SDValue getValue(const Value *V);
 | 
				
			||||||
 | 
					  SDValue getNonRegisterValue(const Value *V);
 | 
				
			||||||
 | 
					  SDValue getValueImpl(const Value *V);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  void setValue(const Value *V, SDValue NewN) {
 | 
					  void setValue(const Value *V, SDValue NewN) {
 | 
				
			||||||
    SDValue &N = NodeMap[V];
 | 
					    SDValue &N = NodeMap[V];
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user