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

Side by Side Diff: lib/Analysis/NaCl/PNaClABIProps.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/Makefile ('k') | lib/Analysis/NaCl/PNaClABITypeChecker.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 //===- PNaClABIProps.cpp - Verify PNaCl ABI Function 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 // Verify function-level PNaCl ABI properties, at the construct level.
11 //
12 //
13 //===----------------------------------------------------------------------===//
14
15 #include "llvm/Analysis/NaCl.h"
16 #include "llvm/Analysis/NaCl/PNaClABIProps.h"
17 #include "llvm/IR/DataLayout.h"
18 #include "llvm/IR/DerivedTypes.h"
19 #include "llvm/IR/LLVMContext.h"
20 #include "llvm/IR/Metadata.h"
21
22 using namespace llvm;
23
24 bool PNaClABIProps::isWhitelistedMetadata(unsigned MDKind) {
25 return MDKind == LLVMContext::MD_dbg && PNaClABIAllowDebugMetadata;
26 }
27
28 bool PNaClABIProps::isWhitelistedMetadata(const NamedMDNode *MD) {
29 return PNaClABIAllowDebugMetadata &&
30 (MD->getName().startswith("llvm.dbg.") ||
31 // "Debug Info Version" is in llvm.module.flags.
32 MD->getName().equals("llvm.module.flags"));
33 }
34
35 bool PNaClABIProps::
36 isAllowedAlignment(const DataLayout *DL, uint64_t Alignment,
37 const Type *Ty) {
38 // Non-atomic integer operations must always use "align 1", since we do not
39 // want the backend to generate code with non-portable undefined behaviour
40 // (such as misaligned access faults) if user code specifies "align 4" but
41 // uses a misaligned pointer. As a concession to performance, we allow larger
42 // alignment values for floating point types, and we only allow vectors to be
43 // aligned by their element's size.
44 //
45 // TODO(jfb) Allow vectors to be marked as align == 1. This requires proper
46 // testing on each supported ISA, and is probably not as common as
47 // align == elemsize.
48 //
49 // To reduce the set of alignment values that need to be encoded in pexes, we
50 // disallow other alignment values. We require alignments to be explicit by
51 // disallowing Alignment == 0.
52 if (Alignment > std::numeric_limits<uint64_t>::max() / CHAR_BIT)
53 return false; // No overflow assumed below.
54 else if (const VectorType *VTy = dyn_cast<VectorType>(Ty))
55 return !VTy->getElementType()->isIntegerTy(1) &&
56 (Alignment * CHAR_BIT ==
57 DL->getTypeSizeInBits(VTy->getElementType()));
58 else
59 return Alignment == 1 ||
60 (Ty->isDoubleTy() && Alignment == 8) ||
61 (Ty->isFloatTy() && Alignment == 4);
62 }
63
64 const char *PNaClABIProps::CallingConvName(CallingConv::ID CallingConv) {
65 // TODO(kschimpf): Add more calling conventions.
66 switch (CallingConv) {
67 case CallingConv::C: return "ccc";
68 case CallingConv::Fast: return "fastcc";
69 case CallingConv::Cold: return "cold";
70 default:
71 return "unknown";
72 }
73 }
74
75 const char *PNaClABIProps::LinkageName(GlobalValue::LinkageTypes LT) {
76 // This logic is taken from PrintLinkage in lib/IR/AsmWriter.cpp
77 switch (LT) {
78 case GlobalValue::ExternalLinkage: return "external";
79 case GlobalValue::PrivateLinkage: return "private";
80 case GlobalValue::InternalLinkage: return "internal";
81 case GlobalValue::LinkOnceAnyLinkage: return "linkonce";
82 case GlobalValue::LinkOnceODRLinkage: return "linkonce_odr";
83 case GlobalValue::WeakAnyLinkage: return "weak";
84 case GlobalValue::WeakODRLinkage: return "weak_odr";
85 case GlobalValue::CommonLinkage: return "common";
86 case GlobalValue::AppendingLinkage: return "appending";
87 case GlobalValue::ExternalWeakLinkage: return "extern_weak";
88 case GlobalValue::AvailableExternallyLinkage:
89 return "available_externally";
90 }
91 llvm_unreachable("unhandled GlobalValue::LinkageTypes");
92 }
93
94 bool PNaClABIProps::isValidGlobalLinkage(GlobalValue::LinkageTypes Linkage) {
95 switch (Linkage) {
96 case GlobalValue::ExternalLinkage:
97 return true;
98 case GlobalValue::InternalLinkage:
99 return true;
100 default:
101 return false;
102 }
103 }
OLDNEW
« no previous file with comments | « lib/Analysis/NaCl/Makefile ('k') | lib/Analysis/NaCl/PNaClABITypeChecker.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698