Skip to content

Commit 5665ef3

Browse files
committed
[RISCV] Add inline asm constraints I, J & K for RISC-V
This allows the constraints I, J & K to be used in inline asm for RISC-V, with the following semantics (equivalent to GCC): I: Any 12-bit signed immediate. J: Integer zero only. K: Any 5-bit unsigned immediate. See the GCC definitions here: https://gcc.gnu.org/onlinedocs/gccint/Machine-Constraints.html Differential Revision: https://reviews.llvm.org/D54091 llvm-svn: 363055
1 parent 28a5cad commit 5665ef3

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

clang/lib/Basic/Targets/RISCV.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,26 @@ ArrayRef<TargetInfo::GCCRegAlias> RISCVTargetInfo::getGCCRegAliases() const {
3939
return llvm::makeArrayRef(GCCRegAliases);
4040
}
4141

42+
bool RISCVTargetInfo::validateAsmConstraint(
43+
const char *&Name, TargetInfo::ConstraintInfo &Info) const {
44+
switch (*Name) {
45+
default:
46+
return false;
47+
case 'I':
48+
// A 12-bit signed immediate.
49+
Info.setRequiresImmediate(-2048, 2047);
50+
return true;
51+
case 'J':
52+
// Integer zero.
53+
Info.setRequiresImmediate(0);
54+
return true;
55+
case 'K':
56+
// A 5-bit unsigned immediate for CSR access instructions.
57+
Info.setRequiresImmediate(0, 31);
58+
return true;
59+
}
60+
}
61+
4262
void RISCVTargetInfo::getTargetDefines(const LangOptions &Opts,
4363
MacroBuilder &Builder) const {
4464
Builder.defineMacro("__ELF__");

clang/lib/Basic/Targets/RISCV.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,7 @@ class RISCVTargetInfo : public TargetInfo {
6161
ArrayRef<TargetInfo::GCCRegAlias> getGCCRegAliases() const override;
6262

6363
bool validateAsmConstraint(const char *&Name,
64-
TargetInfo::ConstraintInfo &Info) const override {
65-
return false;
66-
}
64+
TargetInfo::ConstraintInfo &Info) const override;
6765

6866
bool hasFeature(StringRef Feature) const override;
6967

0 commit comments

Comments
 (0)