Only reserved registers can be read.
Differential Revision: https://reviews.llvm.org/D137532
}
TargetLowering::LowerAsmOperandForConstraint(Op, Constraint, Ops, DAG);
}
+
+#define GET_REGISTER_MATCHER
+#include "LoongArchGenAsmMatcher.inc"
+
+Register
+LoongArchTargetLowering::getRegisterByName(const char *RegName, LLT VT,
+ const MachineFunction &MF) const {
+ std::pair<StringRef, StringRef> Name = StringRef(RegName).split('$');
+ std::string NewRegName = Name.second.str();
+ Register Reg = MatchRegisterAltName(NewRegName);
+ if (Reg == LoongArch::NoRegister)
+ Reg = MatchRegisterName(NewRegName);
+ if (Reg == LoongArch::NoRegister)
+ report_fatal_error(
+ Twine("Invalid register name \"" + StringRef(RegName) + "\"."));
+ BitVector ReservedRegs = Subtarget.getRegisterInfo()->getReservedRegs(MF);
+ if (!ReservedRegs.test(Reg))
+ report_fatal_error(Twine("Trying to obtain non-reserved register \"" +
+ StringRef(RegName) + "\"."));
+ return Reg;
+}
return ISD::SIGN_EXTEND;
}
+ Register getRegisterByName(const char *RegName, LLT VT,
+ const MachineFunction &MF) const override;
+
private:
/// Target-specific function used to lower LoongArch calling conventions.
typedef bool LoongArchCCAssignFn(const DataLayout &DL, LoongArchABI::ABI ABI,
--- /dev/null
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc < %s --mtriple=loongarch64 | FileCheck %s
+
+define i64 @get_stack() nounwind {
+; CHECK-LABEL: get_stack:
+; CHECK: # %bb.0: # %entry
+; CHECK-NEXT: move $a0, $sp
+; CHECK-NEXT: ret
+entry:
+ %sp = call i64 @llvm.read_register.i64(metadata !0)
+ ret i64 %sp
+}
+
+define void @set_stack(i64 %val) nounwind {
+; CHECK-LABEL: set_stack:
+; CHECK: # %bb.0: # %entry
+; CHECK-NEXT: move $sp, $a0
+; CHECK-NEXT: ret
+entry:
+ call void @llvm.write_register.i64(metadata !0, i64 %val)
+ ret void
+}
+
+declare i64 @llvm.read_register.i64(metadata) nounwind
+declare void @llvm.write_register.i64(metadata, i64) nounwind
+
+!0 = !{!"$sp\00"}