[llvm-commits] [llvm] r46646 - in /llvm/trunk: lib/Target/CBackend/CBackend.cpp test/CodeGen/CBackend/2008-02-01-UnalignedLoadStore.ll
Lauro Ramos Venancio
lauro.venancio at gmail.com
Fri Feb 1 13:26:00 PST 2008
Author: laurov
Date: Fri Feb 1 15:25:59 2008
New Revision: 46646
URL: http://llvm.org/viewvc/llvm-project?rev=46646&view=rev
Log:
CBackend: Implement unaligned load/store.
Added:
llvm/trunk/test/CodeGen/CBackend/2008-02-01-UnalignedLoadStore.ll
Modified:
llvm/trunk/lib/Target/CBackend/CBackend.cpp
Modified: llvm/trunk/lib/Target/CBackend/CBackend.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/CBackend/CBackend.cpp?rev=46646&r1=46645&r2=46646&view=diff
==============================================================================
--- llvm/trunk/lib/Target/CBackend/CBackend.cpp (original)
+++ llvm/trunk/lib/Target/CBackend/CBackend.cpp Fri Feb 1 15:25:59 2008
@@ -147,6 +147,9 @@
void writeOperandWithCast(Value* Operand, const ICmpInst &I);
bool writeInstructionCast(const Instruction &I);
+ void writeMemoryAccess(Value *Operand, const Type *OperandType,
+ bool IsVolatile, unsigned Alignment);
+
private :
std::string InterpretASMConstraint(InlineAsm::ConstraintInfo& c);
@@ -2935,29 +2938,47 @@
}
}
-void CWriter::visitLoadInst(LoadInst &I) {
- Out << '*';
- if (I.isVolatile()) {
+void CWriter::writeMemoryAccess(Value *Operand, const Type *OperandType,
+ bool IsVolatile, unsigned Alignment) {
+
+ bool IsUnaligned = Alignment &&
+ Alignment < TD->getABITypeAlignment(OperandType);
+
+ if (!IsUnaligned)
+ Out << '*';
+ if (IsVolatile || IsUnaligned) {
Out << "((";
- printType(Out, I.getType(), false, "volatile*");
+ if (IsUnaligned)
+ Out << "struct __attribute__ ((packed, aligned(" << Alignment << "))) {";
+ printType(Out, OperandType, false, IsUnaligned ? "data" : "volatile*");
+ if (IsUnaligned) {
+ Out << "; } ";
+ if (IsVolatile) Out << "volatile ";
+ Out << "*";
+ }
Out << ")";
}
- writeOperand(I.getOperand(0));
+ writeOperand(Operand);
- if (I.isVolatile())
+ if (IsVolatile || IsUnaligned) {
Out << ')';
+ if (IsUnaligned)
+ Out << "->data";
+ }
+}
+
+void CWriter::visitLoadInst(LoadInst &I) {
+
+ writeMemoryAccess(I.getOperand(0), I.getType(), I.isVolatile(),
+ I.getAlignment());
+
}
void CWriter::visitStoreInst(StoreInst &I) {
- Out << '*';
- if (I.isVolatile()) {
- Out << "((";
- printType(Out, I.getOperand(0)->getType(), false, " volatile*");
- Out << ")";
- }
- writeOperand(I.getPointerOperand());
- if (I.isVolatile()) Out << ')';
+
+ writeMemoryAccess(I.getPointerOperand(), I.getOperand(0)->getType(),
+ I.isVolatile(), I.getAlignment());
Out << " = ";
Value *Operand = I.getOperand(0);
Constant *BitMask = 0;
Added: llvm/trunk/test/CodeGen/CBackend/2008-02-01-UnalignedLoadStore.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/CBackend/2008-02-01-UnalignedLoadStore.ll?rev=46646&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/CBackend/2008-02-01-UnalignedLoadStore.ll (added)
+++ llvm/trunk/test/CodeGen/CBackend/2008-02-01-UnalignedLoadStore.ll Fri Feb 1 15:25:59 2008
@@ -0,0 +1,15 @@
+; RUN: llvm-as < %s | llc -march=c | \
+; RUN: grep {struct __attribute__ ((packed, aligned(} | count 4
+
+define void @test(i32* %P) {
+ %X = load i32* %P, align 1
+ store i32 %X, i32* %P, align 1
+ ret void
+}
+
+define void @test2(i32* %P) {
+ %X = volatile load i32* %P, align 2
+ volatile store i32 %X, i32* %P, align 2
+ ret void
+}
+
More information about the llvm-commits
mailing list