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

Side by Side Diff: lib/Basic/Targets.cpp

Issue 1022123003: clang: add support for asmjs arch and Emscripten OS (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-clang.git@master
Patch Set: Address comments. Created 5 years, 9 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/AST/ASTContext.cpp ('k') | lib/CodeGen/CodeGenModule.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 //===--- Targets.cpp - Implement -arch option and targets -----------------===// 1 //===--- Targets.cpp - Implement -arch option and targets -----------------===//
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 file implements construction of a TargetInfo object from a 10 // This file implements construction of a TargetInfo object from a
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 switch (Triple.getArch()) { 245 switch (Triple.getArch()) {
246 default: 246 default:
247 case llvm::Triple::x86: 247 case llvm::Triple::x86:
248 case llvm::Triple::x86_64: 248 case llvm::Triple::x86_64:
249 this->MCountName = ".mcount"; 249 this->MCountName = ".mcount";
250 break; 250 break;
251 } 251 }
252 } 252 }
253 }; 253 };
254 254
255 // @LOCALMOD-START Emscripten
256 // Emscripten target
257 template <typename Target>
258 class EmscriptenTargetInfo : public OSTargetInfo<Target> {
259 protected:
260 void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
261 MacroBuilder &Builder) const override {
262 // A macro for the platform.
263 Builder.defineMacro("__EMSCRIPTEN__");
264 // Earlier versions of Emscripten defined this, so we continue to define it
265 // for compatibility, for now. Users should ideally prefer __EMSCRIPTEN__.
266 Builder.defineMacro("EMSCRIPTEN");
267 // A common platform macro.
268 if (Opts.POSIXThreads)
269 Builder.defineMacro("_REENTRANT");
270 // Follow g++ convention and predefine _GNU_SOURCE for C++.
271 if (Opts.CPlusPlus)
272 Builder.defineMacro("_GNU_SOURCE");
273
274 // Emscripten's software environment and the asm.js runtime aren't really
275 // Unix per se, but they're perhaps more Unix-like than what software
276 // expects when "unix" is *not* defined.
277 DefineStd(Builder, "unix", Opts);
278 }
279
280 public:
281 explicit EmscriptenTargetInfo(const llvm::Triple &Triple)
282 : OSTargetInfo<Target>(Triple) {
283 // Emcripten currently does prepend a prefix to user labels, but this is
284 // handled outside of clang. TODO: Handling this within clang may be
285 // beneficial.
286 this->UserLabelPrefix = "";
287 this->MaxAtomicPromoteWidth = this->MaxAtomicInlineWidth = 32;
288
289 // Emscripten uses the Itanium ABI mostly, but it uses ARM-style pointers
290 // to member functions so that it can avoid having to align function
291 // addresses.
292 this->TheCXXABI.set(TargetCXXABI::Emscripten);
293 }
294 };
295 // @LOCALMOD-END Emscripten
296
255 // FreeBSD Target 297 // FreeBSD Target
256 template<typename Target> 298 template<typename Target>
257 class FreeBSDTargetInfo : public OSTargetInfo<Target> { 299 class FreeBSDTargetInfo : public OSTargetInfo<Target> {
258 protected: 300 protected:
259 void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple, 301 void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
260 MacroBuilder &Builder) const override { 302 MacroBuilder &Builder) const override {
261 // FreeBSD defines; list based off of gcc output 303 // FreeBSD defines; list based off of gcc output
262 304
263 unsigned Release = Triple.getOSMajorVersion(); 305 unsigned Release = Triple.getOSMajorVersion();
264 if (Release == 0U) 306 if (Release == 0U)
(...skipping 5716 matching lines...) Expand 10 before | Expand all | Expand 10 after
5981 } 6023 }
5982 void getTargetDefines(const LangOptions &Opts, 6024 void getTargetDefines(const LangOptions &Opts,
5983 MacroBuilder &Builder) const override { 6025 MacroBuilder &Builder) const override {
5984 DefineStd(Builder, "MIPSEL", Opts); 6026 DefineStd(Builder, "MIPSEL", Opts);
5985 Builder.defineMacro("_MIPSEL"); 6027 Builder.defineMacro("_MIPSEL");
5986 Mips64TargetInfoBase::getTargetDefines(Opts, Builder); 6028 Mips64TargetInfoBase::getTargetDefines(Opts, Builder);
5987 } 6029 }
5988 }; 6030 };
5989 } // end anonymous namespace. 6031 } // end anonymous namespace.
5990 6032
6033 // @LOCALMOD-START Emscripten
6034 namespace {
6035 class AsmJSTargetInfo : public TargetInfo {
6036 public:
6037 explicit AsmJSTargetInfo(const llvm::Triple &T) : TargetInfo(T) {
6038 BigEndian = false;
6039 NoAsmVariants = true;
6040 LongAlign = LongWidth = 32;
6041 PointerAlign = PointerWidth = 32;
6042 IntMaxType = Int64Type = TargetInfo::SignedLongLong;
6043 DoubleAlign = 64;
6044 LongDoubleWidth = LongDoubleAlign = 64;
6045 SizeType = TargetInfo::UnsignedInt;
6046 PtrDiffType = TargetInfo::SignedInt;
6047 IntPtrType = TargetInfo::SignedInt;
6048 RegParmMax = 0; // Disallow regparm
6049
6050 // Set the native integer widths set to just i32, since that's currently the
6051 // only integer type we can do arithmetic on without masking or splitting.
6052 //
6053 // Set the required alignment for 128-bit vectors to just 4 bytes, based on
6054 // the direction suggested here:
6055 // https://bugzilla.mozilla.org/show_bug.cgi?id=904913#c21
6056 // We can still set the preferred alignment to 16 bytes though.
6057 //
6058 // Set the natural stack alignment to 16 bytes to accomodate 128-bit aligned
6059 // vectors.
6060 DescriptionString = "e-p:32:32-i64:64-v128:32:128-n32-S128";
6061 }
6062
6063 void getDefaultFeatures(llvm::StringMap<bool> &Features) const override {}
6064 void getTargetDefines(const LangOptions &Opts,
6065 MacroBuilder &Builder) const override {
6066 defineCPUMacros(Builder, "asmjs", /*Tuning=*/false);
6067 }
6068 void getTargetBuiltins(const Builtin::Info *&Records,
6069 unsigned &NumRecords) const override {}
6070 BuiltinVaListKind getBuiltinVaListKind() const override {
6071 // Reuse PNaCl's va_list lowering.
6072 return TargetInfo::PNaClABIBuiltinVaList;
6073 }
6074 void getGCCRegNames(const char *const *&Names,
6075 unsigned &NumNames) const override {
6076 Names = nullptr;
6077 NumNames = 0;
6078 }
6079 void getGCCRegAliases(const GCCRegAlias *&Aliases,
6080 unsigned &NumAliases) const override {
6081 Aliases = nullptr;
6082 NumAliases = 0;
6083 }
6084 bool validateAsmConstraint(const char *&Name,
6085 TargetInfo::ConstraintInfo &Info) const override {
6086 return false;
6087 }
6088 const char *getClobbers() const override { return ""; }
6089 bool isCLZForZeroUndef() const override {
6090 // Today we do clz in software, so we just do the right thing. With ES6,
6091 // we'll get Math.clz32, which is to be defined to do the right thing:
6092 // http://esdiscuss.org/topic/rename-number-prototype-clz-to-math-clz#conten t-36
6093 return false;
6094 }
6095 };
6096 } // end anonymous namespace.
6097 // @LOCALMOD-END Emscripten
6098
5991 namespace { 6099 namespace {
5992 class PNaClTargetInfo : public TargetInfo { 6100 class PNaClTargetInfo : public TargetInfo {
5993 public: 6101 public:
5994 PNaClTargetInfo(const llvm::Triple &Triple) : TargetInfo(Triple) { 6102 PNaClTargetInfo(const llvm::Triple &Triple) : TargetInfo(Triple) {
5995 BigEndian = false; 6103 BigEndian = false;
5996 this->UserLabelPrefix = ""; 6104 this->UserLabelPrefix = "";
5997 this->LongAlign = 32; 6105 this->LongAlign = 32;
5998 this->LongWidth = 32; 6106 this->LongWidth = 32;
5999 this->PointerAlign = 32; 6107 this->PointerAlign = 32;
6000 this->PointerWidth = 32; 6108 this->PointerWidth = 32;
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after
6421 case llvm::Triple::FreeBSD: 6529 case llvm::Triple::FreeBSD:
6422 return new FreeBSDTargetInfo<Mips64ELTargetInfo>(Triple); 6530 return new FreeBSDTargetInfo<Mips64ELTargetInfo>(Triple);
6423 case llvm::Triple::NetBSD: 6531 case llvm::Triple::NetBSD:
6424 return new NetBSDTargetInfo<Mips64ELTargetInfo>(Triple); 6532 return new NetBSDTargetInfo<Mips64ELTargetInfo>(Triple);
6425 case llvm::Triple::OpenBSD: 6533 case llvm::Triple::OpenBSD:
6426 return new OpenBSDTargetInfo<Mips64ELTargetInfo>(Triple); 6534 return new OpenBSDTargetInfo<Mips64ELTargetInfo>(Triple);
6427 default: 6535 default:
6428 return new Mips64ELTargetInfo(Triple); 6536 return new Mips64ELTargetInfo(Triple);
6429 } 6537 }
6430 6538
6539 // @LOCALMOD-START Emscripten
6540 case llvm::Triple::asmjs:
6541 switch (os) {
6542 case llvm::Triple::Emscripten:
6543 return new EmscriptenTargetInfo<AsmJSTargetInfo>(Triple);
6544 default:
6545 return nullptr;
6546 }
6547 // @LOCALMOD-END Emscripten
6548
6431 case llvm::Triple::le32: 6549 case llvm::Triple::le32:
6432 switch (os) { 6550 switch (os) {
6433 case llvm::Triple::NaCl: 6551 case llvm::Triple::NaCl:
6434 return new NaClTargetInfo<PNaClTargetInfo>(Triple); 6552 return new NaClTargetInfo<PNaClTargetInfo>(Triple);
6435 default: 6553 default:
6436 return nullptr; 6554 return nullptr;
6437 } 6555 }
6438 6556
6439 case llvm::Triple::le64: 6557 case llvm::Triple::le64:
6440 return new Le64TargetInfo(Triple); 6558 return new Le64TargetInfo(Triple);
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
6683 // need to pass the minuses. 6801 // need to pass the minuses.
6684 Opts->Features.clear(); 6802 Opts->Features.clear();
6685 for (llvm::StringMap<bool>::const_iterator it = Features.begin(), 6803 for (llvm::StringMap<bool>::const_iterator it = Features.begin(),
6686 ie = Features.end(); it != ie; ++it) 6804 ie = Features.end(); it != ie; ++it)
6687 Opts->Features.push_back((it->second ? "+" : "-") + it->first().str()); 6805 Opts->Features.push_back((it->second ? "+" : "-") + it->first().str());
6688 if (!Target->handleTargetFeatures(Opts->Features, Diags)) 6806 if (!Target->handleTargetFeatures(Opts->Features, Diags))
6689 return nullptr; 6807 return nullptr;
6690 6808
6691 return Target.release(); 6809 return Target.release();
6692 } 6810 }
OLDNEW
« no previous file with comments | « lib/AST/ASTContext.cpp ('k') | lib/CodeGen/CodeGenModule.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698