public static RefType getDefaultMemoryRefType(CodeUnit cu, int opIndex, Address toAddr,
			boolean ignoreExistingReferences) {

		boolean speculativeFlowNotAllowed = false;

		if (toAddr != null && toAddr.isMemoryAddress()) {
			MemoryBlock block = cu.getProgram().getMemory().getBlock(toAddr);
			if (block != null && block.isMapped()) {
				ignoreExistingReferences = true;
				speculativeFlowNotAllowed = true;
			}
		}

		RefType refType = null;

		if (toAddr != null && (cu instanceof Instruction)) {

			if (!toAddr.isMemoryAddress() && !toAddr.isExternalAddress()) {
				throw new IllegalArgumentException("Unsupported toAddr address space type");
			}

			Instruction instr = (Instruction) cu;
			Address[] flowAddrs = instr.getDefaultFlows();
			for (Address flowAddr : flowAddrs) {
				if (toAddr.equals(flowAddr)) {
					refType = getDefaultFlowType(instr, toAddr, false);
					if (refType == null) {
						// we should always find default flows and this should not happen
						refType = RefType.INVALID;
					}
					return refType;
				}
			}

			for (Object resultObj : instr.getResultObjects()) {
				if (resultObj.equals(toAddr)) {
					refType = RefType.WRITE;
					break;
				}
			}

			for (Object inputObj : instr.getInputObjects()) {
				if (inputObj.equals(toAddr)) {
					if (refType == RefType.WRITE) {
						return RefType.READ_WRITE;
					}
					refType = instr.getOperandRefType(opIndex);
					if (refType != RefType.INDIRECTION) {
						return RefType.READ;
					}
				}
			}
			if (refType != null) {
				return refType;
			}
		}

		if (!ignoreExistingReferences) {
			Reference[] refs = cu.getProgram()
					.getReferenceManager()
					.getReferencesFrom(
						cu.getMinAddress(), opIndex);
			for (Reference ref : refs) {
				if (ref.getToAddress().equals(toAddr)) {
					return ref.getReferenceType();
				}
				if (ref.isPrimary()) {
					refType = ref.getReferenceType();
				}
			}
			if (refType != null) {
				return refType;
			}
		}

		if (cu instanceof Instruction) {
			Instruction inst = (Instruction) cu;
			if (toAddr != null) {
				refType = getMemRefType(inst, toAddr);
			}
			if (refType == null && !speculativeFlowNotAllowed) {
				refType = getDefaultComputedFlowType(inst);
			}
			if (refType != null) {
				return refType;
			}
		}

		return RefType.DATA;
	}
Get the default memory flow/data RefType for the specified code unit and opIndex.
@param cu the code unit
@param opIndex the op index
@param toAddr reference destination
@param ignoreExistingReferences if true existing references will not influence default
reference type returned.
@return default RefType
Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/symbol/RefTypeFactory.java