Skip to content
This repository was archived by the owner on Apr 23, 2020. It is now read-only.

Commit 64c8bcf

Browse files
committed
Merging r332444:
------------------------------------------------------------------------ r332444 | psmith | 2018-05-16 02:33:25 -0700 (Wed, 16 May 2018) | 20 lines [AArch64] Support "S" inline assembler constraint This patch re-introduces the "S" inline assembler constraint. This matches an absolute symbolic address or a label reference. The primary use case is asm("adrp %0, %1\n\t" "add %0, %0, :lo12:%1" : "=r"(addr) : "S"(&var)); I say re-introduces as it seems like "S" was implemented in the original AArch64 backend, but it looks like it wasn't carried forward to the merged backend. The original implementation had A and L modifiers that could be used to print ":lo12:" to the string. It looks like gcc doesn't use these and :lo12: is expected to be written in the inline assembly string so I've not implemented A and L. Clang already supports the S modifier. Fixes PR37180 Differential Revision: https://reviews.llvm.org/D46745 ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_60@332644 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 133e52e commit 64c8bcf

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

lib/Target/AArch64/AArch64AsmPrinter.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,11 @@ void AArch64AsmPrinter::printOperand(const MachineInstr *MI, unsigned OpNum,
299299
printOffset(MO.getOffset(), O);
300300
break;
301301
}
302+
case MachineOperand::MO_BlockAddress: {
303+
MCSymbol *Sym = GetBlockAddressSymbol(MO.getBlockAddress());
304+
Sym->print(O, MAI);
305+
break;
306+
}
302307
}
303308
}
304309

lib/Target/AArch64/AArch64ISelLowering.cpp

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5066,7 +5066,7 @@ SDValue AArch64TargetLowering::getRecipEstimate(SDValue Operand,
50665066

50675067
// Table of Constraints
50685068
// TODO: This is the current set of constraints supported by ARM for the
5069-
// compiler, not all of them may make sense, e.g. S may be difficult to support.
5069+
// compiler, not all of them may make sense.
50705070
//
50715071
// r - A general register
50725072
// w - An FP/SIMD register of some size in the range v0-v31
@@ -5126,6 +5126,8 @@ AArch64TargetLowering::getConstraintType(StringRef Constraint) const {
51265126
// currently handle addresses it is the same as 'r'.
51275127
case 'Q':
51285128
return C_Memory;
5129+
case 'S': // A symbolic address
5130+
return C_Other;
51295131
}
51305132
}
51315133
return TargetLowering::getConstraintType(Constraint);
@@ -5250,6 +5252,23 @@ void AArch64TargetLowering::LowerAsmOperandForConstraint(
52505252
Result = DAG.getRegister(AArch64::WZR, MVT::i32);
52515253
break;
52525254
}
5255+
case 'S': {
5256+
// An absolute symbolic address or label reference.
5257+
if (const GlobalAddressSDNode *GA = dyn_cast<GlobalAddressSDNode>(Op)) {
5258+
Result = DAG.getTargetGlobalAddress(GA->getGlobal(), SDLoc(Op),
5259+
GA->getValueType(0));
5260+
} else if (const BlockAddressSDNode *BA =
5261+
dyn_cast<BlockAddressSDNode>(Op)) {
5262+
Result =
5263+
DAG.getTargetBlockAddress(BA->getBlockAddress(), BA->getValueType(0));
5264+
} else if (const ExternalSymbolSDNode *ES =
5265+
dyn_cast<ExternalSymbolSDNode>(Op)) {
5266+
Result =
5267+
DAG.getTargetExternalSymbol(ES->getSymbol(), ES->getValueType(0));
5268+
} else
5269+
return;
5270+
break;
5271+
}
52535272

52545273
case 'I':
52555274
case 'J':
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
;RUN: llc -mtriple=aarch64-none-linux-gnu -mattr=+neon < %s | FileCheck %s
2+
@var = global i32 0
3+
define void @test_inline_constraint_S() {
4+
; CHECK-LABEL: test_inline_constraint_S:
5+
call void asm sideeffect "adrp x0, $0", "S"(i32* @var)
6+
call void asm sideeffect "add x0, x0, :lo12:$0", "S"(i32* @var)
7+
; CHECK: adrp x0, var
8+
; CHECK: add x0, x0, :lo12:var
9+
ret void
10+
}
11+
define i32 @test_inline_constraint_S_label(i1 %in) {
12+
; CHECK-LABEL: test_inline_constraint_S_label:
13+
call void asm sideeffect "adr x0, $0", "S"(i8* blockaddress(@test_inline_constraint_S_label, %loc))
14+
; CHECK: adr x0, .Ltmp{{[0-9]+}}
15+
br i1 %in, label %loc, label %loc2
16+
loc:
17+
ret i32 0
18+
loc2:
19+
ret i32 42
20+
}

0 commit comments

Comments
 (0)