diff options
author | Alon Zakai <alonzakai@gmail.com> | 2014-02-25 12:25:39 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2014-02-25 12:25:39 -0800 |
commit | 2a5c6e40d0a9d279750f84a3678c3e4d23061301 (patch) | |
tree | 7714a0b54ab9b3fb492b0c79505671b1310ff8d8 /lib/CodeGen/TargetInfo.cpp | |
parent | ec1178a11d6dbeb371f45dd94a1d1c0849bbf1cb (diff) | |
parent | 632c823b8bfd3fd5a4b77628eddd6161c5d8367e (diff) |
Merge branch 'master' of github.com:sunfishcode/emscripten-fastcomp-clang into incoming
Diffstat (limited to 'lib/CodeGen/TargetInfo.cpp')
-rw-r--r-- | lib/CodeGen/TargetInfo.cpp | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/lib/CodeGen/TargetInfo.cpp b/lib/CodeGen/TargetInfo.cpp index 4fb888a767..5aa982e255 100644 --- a/lib/CodeGen/TargetInfo.cpp +++ b/lib/CodeGen/TargetInfo.cpp @@ -411,6 +411,62 @@ ABIArgInfo DefaultABIInfo::classifyReturnType(QualType RetTy) const { } //===----------------------------------------------------------------------===// +// Emscripten ABI Implementation +// +// This is a very simple ABI that relies a lot on DefaultABIInfo. +//===----------------------------------------------------------------------===// + +class EmscriptenABIInfo : public DefaultABIInfo { + public: + explicit EmscriptenABIInfo(CodeGen::CodeGenTypes &CGT) : DefaultABIInfo(CGT) {} + + ABIArgInfo classifyReturnType(QualType RetTy) const; + ABIArgInfo classifyArgumentType(QualType RetTy) const; +}; + +class EmscriptenTargetCodeGenInfo : public TargetCodeGenInfo { + public: + explicit EmscriptenTargetCodeGenInfo(CodeGen::CodeGenTypes &CGT) + : TargetCodeGenInfo(new EmscriptenABIInfo(CGT)) {} + + // TODO: Re-evaluate whether these hacks, borrowed from PNaCl, are necessary. + bool addAsmMemoryAroundSyncSynchronize() const { return true; } + bool asmMemoryIsFence() const { return true; } +}; + +/// \brief Classify argument of given type \p Ty. +ABIArgInfo EmscriptenABIInfo::classifyArgumentType(QualType Ty) const { + if (isAggregateTypeForABI(Ty)) { + if (CGCXXABI::RecordArgABI RAA = getRecordArgABI(Ty, CGT)) + return ABIArgInfo::getIndirect(0, RAA == CGCXXABI::RAA_DirectInMemory); + return ABIArgInfo::getIndirect(0); + } + + // We can handle floating-point values directly. + if (Ty->isFloatingType()) + return ABIArgInfo::getDirect(); + + // Otherwise just do the default thing. + return DefaultABIInfo::classifyArgumentType(Ty); +} + +ABIArgInfo EmscriptenABIInfo::classifyReturnType(QualType RetTy) const { + if (isAggregateTypeForABI(RetTy)) { + // As an optimization, lower single-element structs to just return a + // regular value. + if (const Type *SeltTy = isSingleElementStruct(RetTy, getContext())) + return ABIArgInfo::getDirect(CGT.ConvertType(QualType(SeltTy, 0))); + } + + // We can handle floating-point values directly. + if (RetTy->isFloatingType()) + return ABIArgInfo::getDirect(); + + // Otherwise just do the default thing. + return DefaultABIInfo::classifyReturnType(RetTy); +} + +//===----------------------------------------------------------------------===// // le32/PNaCl bitcode ABI Implementation // // This is a simplified version of the x86_32 ABI. Arguments and return values @@ -5101,6 +5157,9 @@ const TargetCodeGenInfo &CodeGenModule::getTargetCodeGenInfo() { default: return *(TheTargetCodeGenInfo = new DefaultTargetCodeGenInfo(Types)); + case llvm::Triple::asmjs: + return *(TheTargetCodeGenInfo = new EmscriptenTargetCodeGenInfo(Types)); + case llvm::Triple::le32: return *(TheTargetCodeGenInfo = new PNaClTargetCodeGenInfo(Types)); case llvm::Triple::mips: |