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

Commit 9f60802

Browse files
author
Krzysztof Parzyszek
committed
[RDF] Improve handling of inline-asm
- Keep implicit defs from inline-asm instructions. - Treat register references from inline-asm as fixed. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@267936 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 58c6e4e commit 9f60802

File tree

3 files changed

+78
-4
lines changed

3 files changed

+78
-4
lines changed

lib/Target/Hexagon/RDFGraph.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -686,10 +686,10 @@ bool TargetOperandInfo::isClobbering(const MachineInstr &In, unsigned OpNum)
686686
return false;
687687
}
688688

689-
// Check if the given instruction specifically requires
689+
// Check if the given instruction specifically requires
690690
bool TargetOperandInfo::isFixedReg(const MachineInstr &In, unsigned OpNum)
691691
const {
692-
if (In.isCall() || In.isReturn())
692+
if (In.isCall() || In.isReturn() || In.isInlineAsm())
693693
return true;
694694
const MCInstrDesc &D = In.getDesc();
695695
if (!D.getImplicitDefs() && !D.getImplicitUses())
@@ -1180,6 +1180,7 @@ void DataFlowGraph::buildStmt(NodeAddr<BlockNode*> BA, MachineInstr &In) {
11801180
ImpUses.insert({R, 0});
11811181

11821182
bool IsCall = In.isCall(), IsReturn = In.isReturn();
1183+
bool IsInlineAsm = In.isInlineAsm();
11831184
bool IsPredicated = TII.isPredicated(In);
11841185
unsigned NumOps = In.getNumOperands();
11851186

@@ -1213,7 +1214,7 @@ void DataFlowGraph::buildStmt(NodeAddr<BlockNode*> BA, MachineInstr &In) {
12131214
if (!Op.isReg() || !Op.isDef() || !Op.isImplicit())
12141215
continue;
12151216
RegisterRef RR = { Op.getReg(), Op.getSubReg() };
1216-
if (!IsCall && !ImpDefs.count(RR))
1217+
if (!IsCall && !IsInlineAsm && !ImpDefs.count(RR))
12171218
continue;
12181219
if (DoneDefs.count(RR))
12191220
continue;
@@ -1238,7 +1239,7 @@ void DataFlowGraph::buildStmt(NodeAddr<BlockNode*> BA, MachineInstr &In) {
12381239
// instructions regardless of whether or not they appear in the instruction
12391240
// descriptor's list.
12401241
bool Implicit = Op.isImplicit();
1241-
bool TakeImplicit = IsReturn || IsCall || IsPredicated;
1242+
bool TakeImplicit = IsReturn || IsCall || IsInlineAsm || IsPredicated;
12421243
if (Implicit && !TakeImplicit && !ImpUses.count(RR))
12431244
continue;
12441245
uint16_t Flags = NodeAttrs::None;
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
; RUN: llc -march=hexagon < %s | FileCheck %s
2+
; CHECK: r0 = #24
3+
; CHECK-NEXT: r1 =
4+
; // R2 should be assigned a value from R3+.
5+
; CHECK-NEXT: r2 = r{{[3-9]}}
6+
; CHECK-NEXT: trap0
7+
8+
target datalayout = "e-m:e-p:32:32:32-i64:64:64-i32:32:32-i16:16:16-i1:8:8-f64:64:64-f32:32:32-v64:64:64-v32:32:32-a:0-n16:32"
9+
target triple = "hexagon"
10+
11+
; Function Attrs: nounwind
12+
define i32 @foo(i32 %status) #0 {
13+
entry:
14+
%arg1 = alloca i32, align 4
15+
%0 = bitcast i32* %arg1 to i8*
16+
call void @llvm.lifetime.start(i64 4, i8* %0) #2
17+
store i32 %status, i32* %arg1, align 4, !tbaa !1
18+
%1 = call i32 asm sideeffect "r0 = #$1\0Ar1 = $2\0Ar2 = $4\0Atrap0 (#0)\0A$0 = r0", "=r,i,r,*m,r,~{r0},~{r1},~{r2}"(i32 24, i32* nonnull %arg1, i32* nonnull %arg1, i32 %status) #2, !srcloc !5
19+
call void @llvm.lifetime.end(i64 4, i8* %0) #2
20+
ret i32 %1
21+
}
22+
23+
; Function Attrs: argmemonly nounwind
24+
declare void @llvm.lifetime.start(i64, i8* nocapture) #1
25+
26+
; Function Attrs: argmemonly nounwind
27+
declare void @llvm.lifetime.end(i64, i8* nocapture) #1
28+
29+
attributes #0 = { nounwind "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="hexagonv5" "target-features"="-hvx,-hvx-double" "unsafe-fp-math"="false" "use-soft-float"="false" }
30+
attributes #1 = { argmemonly nounwind }
31+
attributes #2 = { nounwind }
32+
33+
!1 = !{!2, !2, i64 0}
34+
!2 = !{!"int", !3, i64 0}
35+
!3 = !{!"omnipotent char", !4, i64 0}
36+
!4 = !{!"Simple C/C++ TBAA"}
37+
!5 = !{i32 110, i32 129, i32 146, i32 163, i32 183}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
; RUN: llc -march=hexagon < %s
2+
; REQUIRES: asserts
3+
4+
target datalayout = "e-m:e-p:32:32:32-i64:64:64-i32:32:32-i16:16:16-i1:8:8-f64:64:64-f32:32:32-v64:64:64-v32:32:32-a:0-n16:32"
5+
target triple = "hexagon"
6+
7+
@x = common global i32* null, align 4
8+
9+
; Function Attrs: nounwind
10+
define i32 @inotify_init() #0 {
11+
entry:
12+
%0 = tail call i32 asm sideeffect "trap0(#1);\0A", "={r0},{r6},~{memory}"(i32 1043) #1, !srcloc !1
13+
%cmp = icmp sgt i32 %0, -4096
14+
br i1 %cmp, label %if.then, label %if.end
15+
16+
if.then: ; preds = %entry
17+
%sub = sub nsw i32 0, %0
18+
%1 = load i32*, i32** @x, align 4, !tbaa !2
19+
store i32 %sub, i32* %1, align 4, !tbaa !6
20+
br label %if.end
21+
22+
if.end: ; preds = %if.then, %entry
23+
%retval1.0 = phi i32 [ -1, %if.then ], [ %0, %entry ]
24+
ret i32 %retval1.0
25+
}
26+
27+
attributes #0 = { nounwind "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="hexagonv60" "target-features"="+hvx,-hvx-double" "unsafe-fp-math"="false" "use-soft-float"="false" }
28+
attributes #1 = { nounwind }
29+
30+
!1 = !{i32 155}
31+
!2 = !{!3, !3, i64 0}
32+
!3 = !{!"any pointer", !4, i64 0}
33+
!4 = !{!"omnipotent char", !5, i64 0}
34+
!5 = !{!"Simple C/C++ TBAA"}
35+
!6 = !{!7, !7, i64 0}
36+
!7 = !{!"long", !4, i64 0}

0 commit comments

Comments
 (0)