================
@@ -6314,6 +6314,69 @@ unsigned
TargetLowering::AsmOperandInfo::getMatchedOperand() const {
return atoi(ConstraintCode.c_str());
}
+/// Return true if \p OpInfo, an operand of the inline asm \p Call, is an "rm"
+/// operand that should prefer a register, leaving the register allocator to
+/// fold it to a stack slot if it runs out of registers (see
+/// AsmOperandInfo::MayFoldRegister). This includes "g", which Clang expands to
+/// "imr": immediate codes are still tried first for a constant, so they don't
+/// affect the choice between 'r' and 'm'.
+static bool shouldPreferFoldableRegister(
+ const TargetLowering &TLI, const TargetRegisterInfo *TRI,
+ const TargetLowering::AsmOperandInfo &OpInfo, const CallBase &Call) {
+ // Without a fold to fall back on, 'm' is the only choice that can't run out
+ // of registers.
+ if (!TLI.supportsRegMemInlineAsmFolding())
+ return false;
+
+ // An indirect operand is already in memory: a register would only add a
+ // load or store around the asm, and isn't supported for an indirect input.
+ if (OpInfo.isIndirect)
+ return false;
+
+ // Leave inputs at -O0 in memory, as they were. A direct output can't be in
+ // memory (see SelectionDAGBuilder), so it takes the register regardless.
+ if (OpInfo.Type != InlineAsm::isOutput &&
+ TLI.getTargetMachine().getOptLevel() == CodeGenOptLevel::None)
+ return false;
+
+ // The greedy allocator reloads a folded asm goto output tied to an input
+ // after the asm, where the indirect targets don't see it.
+ if (isa<CallBrInst>(Call) && OpInfo.hasMatchingInput())
+ return false;
+
+ // Codes stays empty for a constraint with alternatives ("r|m") until one is
+ // selected, so this only ever matches a plain "rm" plus immediate codes. Any
+ // other code (e.g. a specific register or another register class) leaves
+ // the choice to the usual preference order.
+ if (!is_contained(OpInfo.Codes, "r") || !is_contained(OpInfo.Codes, "m"))
----------------
isanbard wrote:
@danilaml Do you mean the `X` constraint? If so, that's handled in
`TargetLowering::ComputeConstraintToUse()`. It looks like it tries to lower it
to the `r` constraint if possible (see `TargetLowering::LowerXConstraint()`).
It does beg the question of whether it should be `rm` instead (the `i`
constraint is handled separately).
https://github.com/llvm/llvm-project/pull/229632
_______________________________________________
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits