llvm.org GIT mirror llvm / 3d71688
[inline asm] Implement mayLoad and mayStore for inline assembly. In general, the MachineInstr MayLoad/MayLoad flags are based on the tablegen implementation. For inline assembly, however, we need to compute these based on the constraints. Revert r166929 as this is no longer needed, but leave the test case in place. rdar://12033048 and PR13504 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@167040 91177308-0d34-0410-b5e6-96231b3b80d8 Chad Rosier 7 years ago
6 changed file(s) with 36 addition(s) and 11 deletion(s). Raw diff Collapse all Expand all
5757 NoFlags = 0,
5858 FrameSetup = 1 << 0, // Instruction is used as a part of
5959 // function frame setup code.
60 InsideBundle = 1 << 1 // Instruction is inside a bundle (not
60 InsideBundle = 1 << 1, // Instruction is inside a bundle (not
6161 // the first MI in a bundle)
62 MayLoad = 1 << 2, // Instruction could possibly read memory.
63 MayStore = 1 << 3 // Instruction could possibly modify memory.
6264 };
6365 private:
6466 const MCInstrDesc *MCID; // Instruction descriptor.
444446 /// Instructions with this flag set are not necessarily simple load
445447 /// instructions, they may load a value and modify it, for example.
446448 bool mayLoad(QueryType Type = AnyInBundle) const {
447 return hasProperty(MCID::MayLoad, Type);
449 return hasProperty(MCID::MayLoad, Type) || (Flags & MayLoad);
448450 }
449451
450452
453455 /// instructions, they may store a modified value based on their operands, or
454456 /// may not actually modify anything, for example.
455457 bool mayStore(QueryType Type = AnyInBundle) const {
456 return hasProperty(MCID::MayStore, Type);
458 return hasProperty(MCID::MayStore, Type) || (Flags & MayStore);
457459 }
458460
459461 //===--------------------------------------------------------------------===//
213213 Extra_HasSideEffects = 1,
214214 Extra_IsAlignStack = 2,
215215 Extra_AsmDialect = 4,
216 Extra_MayLoad = 8,
217 Extra_MayStore = 16,
216218
217219 // Inline asm operands map to multiple SDNode / MachineInstr operands.
218220 // The first operand is an immediate describing the asm operand, the low
706706 report("Asm string must be an external symbol", MI);
707707 if (!MI->getOperand(1).isImm())
708708 report("Asm flags must be an immediate", MI);
709 // Allowed flags are Extra_HasSideEffects = 1, and Extra_IsAlignStack = 2.
710 if (!isUInt<2>(MI->getOperand(1).getImm()))
709 // Allowed flags are Extra_HasSideEffects = 1, Extra_IsAlignStack = 2,
710 // Extra_AsmDialect = 4, Extra_MayLoad = 8, and Extra_MayStore = 16.
711 if (!isUInt<5>(MI->getOperand(1).getImm()))
711712 report("Unknown asm flags", &MI->getOperand(1), 1);
712713
713714 assert(InlineAsm::MIOp_FirstOperand == 2 && "Asm format changed");
419419 /// Return true if MI is an instruction we are unable to reason about
420420 /// (like a call or something with unmodeled side effects).
421421 static inline bool isGlobalMemoryObject(AliasAnalysis *AA, MachineInstr *MI) {
422 if (MI->isInlineAsm()) {
423 // Until we can tell if an inline assembly instruction accesses
424 // memory, we must assume all such instructions do so.
425 return true;
426 }
427422 if (MI->isCall() || MI->hasUnmodeledSideEffects() ||
428423 (MI->hasOrderedMemoryRef() &&
429424 (!MI->mayLoad() || !MI->isInvariantLoad(AA))))
902902 getZExtValue();
903903 MI->addOperand(MachineOperand::CreateImm(ExtraInfo));
904904
905 // Set the MayLoad and MayStore flags.
906 if (ExtraInfo & InlineAsm::Extra_MayLoad)
907 MI->setFlag(MachineInstr::MayLoad);
908
909 if (ExtraInfo & InlineAsm::Extra_MayStore)
910 MI->setFlag(MachineInstr::MayStore);
911
905912 // Remember to operand index of the group flags.
906913 SmallVector GroupIdx;
907914
61276127 const MDNode *SrcLoc = CS.getInstruction()->getMetadata("srcloc");
61286128 AsmNodeOperands.push_back(DAG.getMDNode(SrcLoc));
61296129
6130 // Remember the HasSideEffect, AlignStack and AsmDialect bits as operand 3.
6130 // Remember the HasSideEffect, AlignStack, AsmDialect, MayLoad and MayStore
6131 // bits as operand 3.
61316132 unsigned ExtraInfo = 0;
61326133 if (IA->hasSideEffects())
61336134 ExtraInfo |= InlineAsm::Extra_HasSideEffects;
61356136 ExtraInfo |= InlineAsm::Extra_IsAlignStack;
61366137 // Set the asm dialect.
61376138 ExtraInfo |= IA->getDialect() * InlineAsm::Extra_AsmDialect;
6139
6140 // Determine if this InlineAsm MayLoad or MayStore based on the constraints.
6141 for (unsigned i = 0, e = TargetConstraints.size(); i != e; ++i) {
6142 TargetLowering::AsmOperandInfo &OpInfo = TargetConstraints[i];
6143
6144 // Compute the constraint code and ConstraintType to use.
6145 TLI.ComputeConstraintToUse(OpInfo, SDValue());
6146
6147 if (OpInfo.ConstraintType == TargetLowering::C_Memory ||
6148 OpInfo.ConstraintType == TargetLowering::C_Other) {
6149 if (OpInfo.Type == InlineAsm::isInput)
6150 ExtraInfo |= InlineAsm::Extra_MayLoad;
6151 else if (OpInfo.Type == InlineAsm::isOutput)
6152 ExtraInfo |= InlineAsm::Extra_MayStore;
6153 }
6154 }
6155
61386156 AsmNodeOperands.push_back(DAG.getTargetConstant(ExtraInfo,
61396157 TLI.getPointerTy()));
61406158