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

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

Issue 939073008: Rebased PNaCl localmods in LLVM to 223109 (Closed)
Patch Set: undo localmod Created 5 years, 10 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 | « lib/Analysis/NaCl/PNaClABIProps.cpp ('k') | lib/Analysis/NaCl/PNaClABIVerifyFunctions.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 //===- PNaClABITypeChecker.cpp - Verify PNaCl ABI rules -------------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // Common type-checking code for module and function-level passes
11 //
12 //
13 //===----------------------------------------------------------------------===//
14
15 #include "llvm/Analysis/NaCl/PNaClABITypeChecker.h"
16 #include "llvm/IR/Constant.h"
17 #include "llvm/IR/Constants.h"
18 #include "llvm/IR/DerivedTypes.h"
19 #include "llvm/IR/Metadata.h"
20
21 using namespace llvm;
22
23 bool PNaClABITypeChecker::isValidParamType(const Type *Ty) {
24 if (!(isValidScalarType(Ty) || isValidVectorType(Ty)))
25 return false;
26 if (const IntegerType *IntTy = dyn_cast<IntegerType>(Ty)) {
27 // PNaCl requires function arguments and return values to be 32
28 // bits or larger. This avoids exposing architecture
29 // ABI-dependent differences about whether arguments or return
30 // values are zero-extended when calling a function with the wrong
31 // prototype.
32 if (IntTy->getBitWidth() < 32)
33 return false;
34 }
35 return true;
36 }
37
38 bool PNaClABITypeChecker::isValidFunctionType(const FunctionType *FTy) {
39 if (FTy->isVarArg())
40 return false;
41 if (!isValidParamType(FTy->getReturnType()))
42 return false;
43 for (unsigned I = 0, E = FTy->getNumParams(); I < E; ++I) {
44 if (!isValidParamType(FTy->getParamType(I)))
45 return false;
46 }
47 return true;
48 }
49
50 namespace {
51 static inline bool NaClIsValidIntType(const Type *Ty) {
52 unsigned Width = cast<const IntegerType>(Ty)->getBitWidth();
53 return Width == 1 || Width == 8 || Width == 16 ||
54 Width == 32 || Width == 64;
55 }
56 }
57
58 bool PNaClABITypeChecker::isValidScalarType(const Type *Ty) {
59 switch (Ty->getTypeID()) {
60 case Type::IntegerTyID: {
61 return NaClIsValidIntType(Ty);
62 }
63 case Type::VoidTyID:
64 case Type::FloatTyID:
65 case Type::DoubleTyID:
66 return true;
67 default:
68 return false;
69 }
70 }
71
72 // TODO(jfb) Handle 64-bit int and double, and 2xi1.
73 bool PNaClABITypeChecker::isValidVectorType(const Type *Ty) {
74 if (!Ty->isVectorTy())
75 return false;
76 unsigned Elems = Ty->getVectorNumElements();
77 const Type *VTy = Ty->getVectorElementType();
78
79 switch (VTy->getTypeID()) {
80 case Type::IntegerTyID: {
81 unsigned Width = cast<const IntegerType>(VTy)->getBitWidth();
82 switch (Width) {
83 case 1: return Elems == 4 || Elems == 8 || Elems == 16;
84 case 8: return Elems == 16;
85 case 16: return Elems == 8;
86 case 32: return Elems == 4;
87 default: return false;
88 }
89 }
90 case Type::FloatTyID:
91 return Elems == 4;
92 default:
93 return false;
94 }
95 }
96
97 namespace {
98 static inline bool NaClIsValidIntArithmeticType(const Type *Ty) {
99 return Ty->isIntegerTy() && !Ty->isIntegerTy(1)
100 && NaClIsValidIntType(Ty);
101 }
102
103 }
104
105 bool PNaClABITypeChecker::isValidIntArithmeticType(const Type *Ty) {
106 if (isValidVectorType(Ty))
107 return NaClIsValidIntArithmeticType(Ty->getVectorElementType());
108 return NaClIsValidIntArithmeticType(Ty);
109 }
OLDNEW
« no previous file with comments | « lib/Analysis/NaCl/PNaClABIProps.cpp ('k') | lib/Analysis/NaCl/PNaClABIVerifyFunctions.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698