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

Side by Side Diff: lib/Analysis/NaCl/PNaClABITypeChecker.cpp

Issue 221693002: PNaCl: Add support for GCC/LLVM vector extensions (Closed) Base URL: http://git.chromium.org/native_client/pnacl-llvm.git@master
Patch Set: Address dschuff's comments. Created 6 years, 8 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
OLDNEW
1 //===- PNaClABITypeChecker.cpp - Verify PNaCl ABI rules -------------------===// 1 //===- PNaClABITypeChecker.cpp - Verify PNaCl ABI rules -------------------===//
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 // Common type-checking code for module and function-level passes 10 // Common type-checking code for module and function-level passes
11 // 11 //
12 // 12 //
13 //===----------------------------------------------------------------------===// 13 //===----------------------------------------------------------------------===//
14 14
15 #include "PNaClABITypeChecker.h" 15 #include "PNaClABITypeChecker.h"
16 #include "llvm/IR/Constant.h" 16 #include "llvm/IR/Constant.h"
17 #include "llvm/IR/Constants.h" 17 #include "llvm/IR/Constants.h"
18 #include "llvm/IR/DerivedTypes.h" 18 #include "llvm/IR/DerivedTypes.h"
19 #include "llvm/IR/Metadata.h" 19 #include "llvm/IR/Metadata.h"
20 20
21 using namespace llvm; 21 using namespace llvm;
22 22
23 bool PNaClABITypeChecker::isValidParamType(const Type *Ty) { 23 bool PNaClABITypeChecker::isValidParamType(const Type *Ty) {
24 if (!isValidScalarType(Ty)) 24 if (!(isValidScalarType(Ty) || isValidVectorType(Ty)))
25 return false; 25 return false;
26 if (const IntegerType *IntTy = dyn_cast<IntegerType>(Ty)) { 26 if (const IntegerType *IntTy = dyn_cast<IntegerType>(Ty)) {
27 // PNaCl requires function arguments and return values to be 32 27 // PNaCl requires function arguments and return values to be 32
28 // bits or larger. This avoids exposing architecture 28 // bits or larger. This avoids exposing architecture
29 // ABI-dependent differences about whether arguments or return 29 // ABI-dependent differences about whether arguments or return
30 // values are zero-extended when calling a function with the wrong 30 // values are zero-extended when calling a function with the wrong
31 // prototype. 31 // prototype.
32 if (IntTy->getBitWidth() < 32) 32 if (IntTy->getBitWidth() < 32)
33 return false; 33 return false;
34 } 34 }
(...skipping 20 matching lines...) Expand all
55 Width == 32 || Width == 64; 55 Width == 32 || Width == 64;
56 } 56 }
57 case Type::VoidTyID: 57 case Type::VoidTyID:
58 case Type::FloatTyID: 58 case Type::FloatTyID:
59 case Type::DoubleTyID: 59 case Type::DoubleTyID:
60 return true; 60 return true;
61 default: 61 default:
62 return false; 62 return false;
63 } 63 }
64 } 64 }
65
66 // TODO(jfb) Handle 64-bit int and double, and 2xi1.
67 bool PNaClABITypeChecker::isValidVectorType(const Type *Ty) {
68 if (!Ty->isVectorTy())
69 return false;
70 unsigned Elems = Ty->getVectorNumElements();
71 const Type *VTy = Ty->getVectorElementType();
72
73 switch (VTy->getTypeID()) {
74 case Type::IntegerTyID: {
75 unsigned Width = cast<const IntegerType>(VTy)->getBitWidth();
76 switch (Width) {
77 case 1: return Elems == 4 || Elems == 8 || Elems == 16;
78 case 8: return Elems == 16;
79 case 16: return Elems == 8;
80 case 32: return Elems == 4;
81 default: return false;
82 }
83 }
84 case Type::FloatTyID:
85 return Elems == 4;
86 default:
87 return false;
88 }
89 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698