From dc8499fbc7bea14664cc7a58c79948552d5bc318 Mon Sep 17 00:00:00 2001 From: Tim Northover Date: Wed, 19 Oct 2016 15:55:06 +0000 Subject: [PATCH] GlobalISel: support translating volatile loads and stores. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@284603 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/GlobalISel/IRTranslator.cpp | 31 ++++++++++--------- .../AArch64/GlobalISel/arm64-irtranslator.ll | 16 +++++++--- 2 files changed, 29 insertions(+), 18 deletions(-) diff --git a/lib/CodeGen/GlobalISel/IRTranslator.cpp b/lib/CodeGen/GlobalISel/IRTranslator.cpp index dd64cc7fab6..2a66251190c 100644 --- a/lib/CodeGen/GlobalISel/IRTranslator.cpp +++ b/lib/CodeGen/GlobalISel/IRTranslator.cpp @@ -168,31 +168,36 @@ bool IRTranslator::translateBr(const User &U) { bool IRTranslator::translateLoad(const User &U) { const LoadInst &LI = cast(U); - if (!TPC->isGlobalISelAbortEnabled() && !LI.isSimple()) + if (!TPC->isGlobalISelAbortEnabled() && LI.isAtomic()) return false; - assert(LI.isSimple() && "only simple loads are supported at the moment"); + assert(!LI.isAtomic() && "only non-atomic loads are supported at the moment"); + auto Flags = LI.isVolatile() ? MachineMemOperand::MOVolatile + : MachineMemOperand::MONone; + Flags |= MachineMemOperand::MOLoad; MachineFunction &MF = MIRBuilder.getMF(); unsigned Res = getOrCreateVReg(LI); unsigned Addr = getOrCreateVReg(*LI.getPointerOperand()); LLT VTy{*LI.getType(), *DL}, PTy{*LI.getPointerOperand()->getType(), *DL}; - MIRBuilder.buildLoad( Res, Addr, - *MF.getMachineMemOperand( - MachinePointerInfo(LI.getPointerOperand()), MachineMemOperand::MOLoad, - DL->getTypeStoreSize(LI.getType()), getMemOpAlignment(LI))); + *MF.getMachineMemOperand(MachinePointerInfo(LI.getPointerOperand()), + Flags, DL->getTypeStoreSize(LI.getType()), + getMemOpAlignment(LI))); return true; } bool IRTranslator::translateStore(const User &U) { const StoreInst &SI = cast(U); - if (!TPC->isGlobalISelAbortEnabled() && !SI.isSimple()) + if (!TPC->isGlobalISelAbortEnabled() && SI.isAtomic()) return false; - assert(SI.isSimple() && "only simple loads are supported at the moment"); + assert(!SI.isAtomic() && "only non-atomic stores supported at the moment"); + auto Flags = SI.isVolatile() ? MachineMemOperand::MOVolatile + : MachineMemOperand::MONone; + Flags |= MachineMemOperand::MOStore; MachineFunction &MF = MIRBuilder.getMF(); unsigned Val = getOrCreateVReg(*SI.getValueOperand()); @@ -201,12 +206,10 @@ bool IRTranslator::translateStore(const User &U) { PTy{*SI.getPointerOperand()->getType(), *DL}; MIRBuilder.buildStore( - Val, Addr, - *MF.getMachineMemOperand( - MachinePointerInfo(SI.getPointerOperand()), - MachineMemOperand::MOStore, - DL->getTypeStoreSize(SI.getValueOperand()->getType()), - getMemOpAlignment(SI))); + Val, Addr, *MF.getMachineMemOperand( + MachinePointerInfo(SI.getPointerOperand()), Flags, + DL->getTypeStoreSize(SI.getValueOperand()->getType()), + getMemOpAlignment(SI))); return true; } diff --git a/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll b/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll index be69cfa1c61..02f26ccf29a 100644 --- a/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll +++ b/test/CodeGen/AArch64/GlobalISel/arm64-irtranslator.ll @@ -271,14 +271,20 @@ define void @trunc(i64 %a) { ; CHECK: [[ADDR42:%[0-9]+]](p42) = COPY %x1 ; CHECK: [[VAL1:%[0-9]+]](s64) = G_LOAD [[ADDR]](p0) :: (load 8 from %ir.addr, align 16) ; CHECK: [[VAL2:%[0-9]+]](s64) = G_LOAD [[ADDR42]](p42) :: (load 8 from %ir.addr42) -; CHECK: [[SUM:%.*]](s64) = G_ADD [[VAL1]], [[VAL2]] -; CHECK: %x0 = COPY [[SUM]] +; CHECK: [[SUM2:%.*]](s64) = G_ADD [[VAL1]], [[VAL2]] +; CHECK: [[VAL3:%[0-9]+]](s64) = G_LOAD [[ADDR]](p0) :: (volatile load 8 from %ir.addr) +; CHECK: [[SUM3:%[0-9]+]](s64) = G_ADD [[SUM2]], [[VAL3]] +; CHECK: %x0 = COPY [[SUM3]] ; CHECK: RET_ReallyLR implicit %x0 define i64 @load(i64* %addr, i64 addrspace(42)* %addr42) { %val1 = load i64, i64* %addr, align 16 + %val2 = load i64, i64 addrspace(42)* %addr42 - %sum = add i64 %val1, %val2 - ret i64 %sum + %sum2 = add i64 %val1, %val2 + + %val3 = load volatile i64, i64* %addr + %sum3 = add i64 %sum2, %val3 + ret i64 %sum3 } ; CHECK-LABEL: name: store @@ -288,10 +294,12 @@ define i64 @load(i64* %addr, i64 addrspace(42)* %addr42) { ; CHECK: [[VAL2:%[0-9]+]](s64) = COPY %x3 ; CHECK: G_STORE [[VAL1]](s64), [[ADDR]](p0) :: (store 8 into %ir.addr, align 16) ; CHECK: G_STORE [[VAL2]](s64), [[ADDR42]](p42) :: (store 8 into %ir.addr42) +; CHECK: G_STORE [[VAL1]](s64), [[ADDR]](p0) :: (volatile store 8 into %ir.addr) ; CHECK: RET_ReallyLR define void @store(i64* %addr, i64 addrspace(42)* %addr42, i64 %val1, i64 %val2) { store i64 %val1, i64* %addr, align 16 store i64 %val2, i64 addrspace(42)* %addr42 + store volatile i64 %val1, i64* %addr %sum = add i64 %val1, %val2 ret void }