Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(35)

Side by Side Diff: lib/CodeGen/CGExprComplex.cpp

Issue 18502004: Propagate alignment for _Complex (Closed) Base URL: http://git.chromium.org/native_client/pnacl-clang.git@master
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 //===--- CGExprComplex.cpp - Emit LLVM Code for Complex Exprs -------------===// 1 //===--- CGExprComplex.cpp - Emit LLVM Code for Complex Exprs -------------===//
2 // 2 //
3 // The LLVM Compiler Infrastructure 3 // The LLVM Compiler Infrastructure
4 // 4 //
5 // This file is distributed under the University of Illinois Open Source 5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details. 6 // License. See LICENSE.TXT for details.
7 // 7 //
8 //===----------------------------------------------------------------------===// 8 //===----------------------------------------------------------------------===//
9 // 9 //
10 // This contains code to emit Expr nodes with complex types as LLVM code. 10 // This contains code to emit Expr nodes with complex types as LLVM code.
11 // 11 //
12 //===----------------------------------------------------------------------===// 12 //===----------------------------------------------------------------------===//
13 13
14 #include "CodeGenFunction.h" 14 #include "CodeGenFunction.h"
15 #include "CodeGenModule.h" 15 #include "CodeGenModule.h"
16 #include "clang/AST/ASTContext.h" 16 #include "clang/AST/ASTContext.h"
17 #include "clang/AST/StmtVisitor.h" 17 #include "clang/AST/StmtVisitor.h"
18 #include "llvm/ADT/SmallString.h" 18 #include "llvm/ADT/SmallString.h"
19 #include "llvm/IR/Constants.h" 19 #include "llvm/IR/Constants.h"
20 #include "llvm/IR/Function.h" 20 #include "llvm/IR/Function.h"
21 #include "llvm/IR/GlobalValue.h" // @LOCALMOD not needed after merge
21 using namespace clang; 22 using namespace clang;
22 using namespace CodeGen; 23 using namespace CodeGen;
23 24
24 //===----------------------------------------------------------------------===// 25 //===----------------------------------------------------------------------===//
25 // Complex Expression Emitter 26 // Complex Expression Emitter
26 //===----------------------------------------------------------------------===// 27 //===----------------------------------------------------------------------===//
27 28
28 typedef CodeGenFunction::ComplexPairTy ComplexPairTy; 29 typedef CodeGenFunction::ComplexPairTy ComplexPairTy;
29 30
30 namespace { 31 namespace {
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 285
285 //===----------------------------------------------------------------------===// 286 //===----------------------------------------------------------------------===//
286 // Utilities 287 // Utilities
287 //===----------------------------------------------------------------------===// 288 //===----------------------------------------------------------------------===//
288 289
289 /// EmitLoadOfComplex - Given an RValue reference for a complex, emit code to 290 /// EmitLoadOfComplex - Given an RValue reference for a complex, emit code to
290 /// load the real and imaginary pieces, returning them as Real/Imag. 291 /// load the real and imaginary pieces, returning them as Real/Imag.
291 ComplexPairTy ComplexExprEmitter::EmitLoadOfComplex(llvm::Value *SrcPtr, 292 ComplexPairTy ComplexExprEmitter::EmitLoadOfComplex(llvm::Value *SrcPtr,
292 bool isVolatile) { 293 bool isVolatile) {
293 llvm::Value *Real=0, *Imag=0; 294 llvm::Value *Real=0, *Imag=0;
295 // @LOCALMOD-START I submitted a fix upstream for this issue, but the code
296 // was re-written to use LValue instead of Value, so this
297 // fix will be wrong after the merge.
298 // We should cherry-pick my fix, which is past 3.3.
299 unsigned Align = 0;
300
301 if (llvm::GlobalValue *GV = dyn_cast<llvm::GlobalValue>(SrcPtr))
302 Align = GV->getAlignment();
294 303
295 if (!IgnoreReal || isVolatile) { 304 if (!IgnoreReal || isVolatile) {
296 llvm::Value *RealP = Builder.CreateStructGEP(SrcPtr, 0, 305 llvm::Value *RealP = Builder.CreateStructGEP(SrcPtr, 0,
297 SrcPtr->getName() + ".realp"); 306 SrcPtr->getName() + ".realp");
298 Real = Builder.CreateLoad(RealP, isVolatile, SrcPtr->getName() + ".real"); 307 Real = Builder.CreateAlignedLoad(RealP, Align, isVolatile,
308 SrcPtr->getName() + ".real");
299 } 309 }
300 310
301 if (!IgnoreImag || isVolatile) { 311 if (!IgnoreImag || isVolatile) {
302 llvm::Value *ImagP = Builder.CreateStructGEP(SrcPtr, 1, 312 llvm::Value *ImagP = Builder.CreateStructGEP(SrcPtr, 1,
303 SrcPtr->getName() + ".imagp"); 313 SrcPtr->getName() + ".imagp");
304 Imag = Builder.CreateLoad(ImagP, isVolatile, SrcPtr->getName() + ".imag"); 314 Imag = Builder.CreateAlignedLoad(ImagP, Align, isVolatile,
315 SrcPtr->getName() + ".imag");
305 } 316 }
306 return ComplexPairTy(Real, Imag); 317 return ComplexPairTy(Real, Imag);
307 } 318 }
308 319
309 /// EmitStoreOfComplex - Store the specified real/imag parts into the 320 /// EmitStoreOfComplex - Store the specified real/imag parts into the
310 /// specified value pointer. 321 /// specified value pointer.
311 void ComplexExprEmitter::EmitStoreOfComplex(ComplexPairTy Val, llvm::Value *Ptr, 322 void ComplexExprEmitter::EmitStoreOfComplex(ComplexPairTy Val, llvm::Value *Ptr,
312 bool isVolatile) { 323 bool isVolatile) {
313 llvm::Value *RealPtr = Builder.CreateStructGEP(Ptr, 0, "real"); 324 llvm::Value *RealPtr = Builder.CreateStructGEP(Ptr, 0, "real");
314 llvm::Value *ImagPtr = Builder.CreateStructGEP(Ptr, 1, "imag"); 325 llvm::Value *ImagPtr = Builder.CreateStructGEP(Ptr, 1, "imag");
326 unsigned Align = 0;
315 327
316 Builder.CreateStore(Val.first, RealPtr, isVolatile); 328 if (llvm::GlobalValue *GV = dyn_cast<llvm::GlobalValue>(Ptr))
317 Builder.CreateStore(Val.second, ImagPtr, isVolatile); 329 Align = GV->getAlignment();
330
331 Builder.CreateAlignedStore(Val.first, RealPtr, Align, isVolatile);
332 Builder.CreateAlignedStore(Val.second, ImagPtr, Align, isVolatile);
333 // @LOCALMOD-END
318 } 334 }
319 335
320 336
321 337
322 //===----------------------------------------------------------------------===// 338 //===----------------------------------------------------------------------===//
323 // Visitor Methods 339 // Visitor Methods
324 //===----------------------------------------------------------------------===// 340 //===----------------------------------------------------------------------===//
325 341
326 ComplexPairTy ComplexExprEmitter::VisitExpr(Expr *E) { 342 ComplexPairTy ComplexExprEmitter::VisitExpr(Expr *E) {
327 CGF.ErrorUnsupported(E, "complex expression"); 343 CGF.ErrorUnsupported(E, "complex expression");
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after
832 case BO_SubAssign: Op = &ComplexExprEmitter::EmitBinSub; break; 848 case BO_SubAssign: Op = &ComplexExprEmitter::EmitBinSub; break;
833 case BO_AddAssign: Op = &ComplexExprEmitter::EmitBinAdd; break; 849 case BO_AddAssign: Op = &ComplexExprEmitter::EmitBinAdd; break;
834 850
835 default: 851 default:
836 llvm_unreachable("unexpected complex compound assignment"); 852 llvm_unreachable("unexpected complex compound assignment");
837 } 853 }
838 854
839 ComplexPairTy Val; // ignored 855 ComplexPairTy Val; // ignored
840 return ComplexExprEmitter(*this).EmitCompoundAssignLValue(E, Op, Val); 856 return ComplexExprEmitter(*this).EmitCompoundAssignLValue(E, Op, Val);
841 } 857 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698