Index: lib/Basic/Targets.cpp =================================================================== --- lib/Basic/Targets.cpp +++ lib/Basic/Targets.cpp @@ -6353,6 +6353,83 @@ return llvm::makeArrayRef(GCCRegNames); } +class AAPTargetInfo : public TargetInfo { +public: + AAPTargetInfo(const llvm::Triple &Triple) : TargetInfo(Triple) { + BigEndian = false; + TLSSupported = false; + IntWidth = 16; + IntAlign = 16; + LongWidth = 32; + LongLongWidth = 64; + LongAlign = LongLongAlign = 16; + PointerWidth = 16; + PointerAlign = 16; + + // float/double alignment needed when accessing va_args + FloatWidth = 32; + FloatAlign = 16; + DoubleWidth = 64; + DoubleAlign = 16; + + SuitableAlign = 16; + SizeType = UnsignedInt; + IntMaxType = SignedLongLong; + IntPtrType = SignedInt; + PtrDiffType = SignedInt; + SigAtomicType = SignedLong; + DataLayoutString = "e-m:e-p:16:16-i32:16-i64:16-f32:16-f64:16-n16"; + } + void getTargetDefines(const LangOptions &Opts, + MacroBuilder &Builder) const override { + Builder.defineMacro("AAP"); + Builder.defineMacro("__AAP__"); + } + + ArrayRef getTargetBuiltins() const override { + return None; + } + bool hasFeature(StringRef Feature) const override { + return Feature == "AAP"; + } + ArrayRef getGCCRegNames() const override { + const char * const GCCRegNames[] = { + "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", + "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15", + "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23", + "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31", + "r32", "r33", "r34", "r35", "r36", "r37", "r38", "r39", + "r40", "r41", "r42", "r43", "r44", "r45", "r46", "r47", + "r48", "r49", "r50", "r51", "r52", "r53", "r54", "r55", + "r56", "r57", "r58", "r59", "r60", "r61", "r62", "r63", + }; + return llvm::makeArrayRef(GCCRegNames); + } + ArrayRef getGCCRegAliases() const override { + // No aliases + return None; + } + bool + validateAsmConstraint(const char *&Name, + TargetInfo::ConstraintInfo &Info) const override { + switch (*Name) { + default: + return false; + case 'r': // CPU registers. + Info.setAllowsRegister(); + return true; + } + } + const char *getClobbers() const override { + // FIXME: Is this really right? + return ""; + } + BuiltinVaListKind getBuiltinVaListKind() const override { + // FIXME: implement + return TargetInfo::CharPtrBuiltinVaList; + } +}; + // LLVM and Clang cannot be used directly to output native binaries for // target, but is used to compile C code to llvm bitcode with correct // type and alignment information. @@ -7523,6 +7600,9 @@ case llvm::Triple::hexagon: return new HexagonTargetInfo(Triple); + case llvm::Triple::aap: + return new AAPTargetInfo(Triple); + case llvm::Triple::aarch64: if (Triple.isOSDarwin()) return new DarwinAArch64TargetInfo(Triple); Index: lib/Driver/Driver.cpp =================================================================== --- lib/Driver/Driver.cpp +++ lib/Driver/Driver.cpp @@ -2336,6 +2336,9 @@ case llvm::Triple::tce: TC = new toolchains::TCEToolChain(*this, Target, Args); break; + case llvm::Triple::aap: + TC = new toolchains::AAP(*this, Target, Args); + break; case llvm::Triple::hexagon: TC = new toolchains::HexagonToolChain(*this, Target, Args); break; Index: lib/Driver/ToolChains.h =================================================================== --- lib/Driver/ToolChains.h +++ lib/Driver/ToolChains.h @@ -1155,6 +1155,29 @@ Tool *buildLinker() const override; }; +class LLVM_LIBRARY_VISIBILITY AAP : public ToolChain { +public: + AAP(const Driver &D, const llvm::Triple &Triple, + const llvm::opt::ArgList &Args); +protected: + Tool *buildAssembler() const override; + Tool *buildLinker() const override; +public: + bool isPICDefault() const override { return false; } + bool isPIEDefault() const override { return false; } + bool isPICDefaultForced() const override { return true; } + bool HasNativeLLVMSupport() const override; + + bool IsIntegratedAssemblerDefault() const override { return true; } + bool SupportsProfiling() const override { return false; } + bool hasBlocksRuntime() const override { return false; } + + void AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs, + llvm::opt::ArgStringList &CC1Args) const override; + void addClangTargetOptions(const llvm::opt::ArgList &DriverArgs, + llvm::opt::ArgStringList &CC1Args) const override; +}; + } // end namespace toolchains } // end namespace driver } // end namespace clang Index: lib/Driver/ToolChains.cpp =================================================================== --- lib/Driver/ToolChains.cpp +++ lib/Driver/ToolChains.cpp @@ -2374,6 +2374,7 @@ switch (getTriple().getArch()) { case llvm::Triple::x86: case llvm::Triple::x86_64: + case llvm::Triple::aap: case llvm::Triple::aarch64: case llvm::Triple::aarch64_be: case llvm::Triple::arm: @@ -4569,3 +4570,44 @@ Res |= SanitizerKind::Vptr; return Res; } + +/// AAP tool chain +AAP::AAP(const Driver &D, const llvm::Triple &Triple, + const ArgList &Args) : ToolChain(D, Triple, Args) { + // Program paths are assumed to be locatable through the 'PATH' env variable +} + +Tool *AAP::buildAssembler() const { + return new tools::AAP::Assemble(*this); +} + +Tool *AAP::buildLinker() const { + return new tools::AAP::Link(*this); +} + +bool AAP::HasNativeLLVMSupport() const { + return true; +} + +void AAP::AddClangSystemIncludeArgs(const llvm::opt::ArgList &DriverArgs, + llvm::opt::ArgStringList &CC1Args) const { + const Driver &D = getDriver(); + + if (DriverArgs.hasArg(options::OPT_nostdinc) || + DriverArgs.hasArg(options::OPT_nostdlibinc)) { + return; + } + + // standard system includes are disabled, so we add our own + const std::string InstallPrefix = D.InstalledDir; + const std::string IncludeDir = InstallPrefix + "/../aap/include"; + StringRef IncludeDirStr(IncludeDir); + + addSystemIncludes(DriverArgs, CC1Args, IncludeDirStr); +} + +void AAP::addClangTargetOptions(const llvm::opt::ArgList &DriverArgs, + llvm::opt::ArgStringList &CC1Args) const { + CC1Args.push_back("-nostdsysteminc"); + CC1Args.push_back("-dwarf-column-info"); +} \ No newline at end of file Index: lib/Driver/Tools.h =================================================================== --- lib/Driver/Tools.h +++ lib/Driver/Tools.h @@ -60,6 +60,8 @@ const InputInfoList &Inputs, const ToolChain *AuxToolChain) const; + void AddAAPTargetArgs(const llvm::opt::ArgList &Args, + llvm::opt::ArgStringList &CmdArgs) const; void AddAArch64TargetArgs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const; void AddARMTargetArgs(const llvm::Triple &Triple, @@ -938,6 +940,34 @@ } // end namespace NVPTX +namespace AAP { + class LLVM_LIBRARY_VISIBILITY Assemble : public Tool { + public: + Assemble(const ToolChain &TC) : Tool("AAP::Assemble", "aap-as", TC) + {} + + bool hasIntegratedCPP() const override { return false; } + void ConstructJob(Compilation &C, const JobAction &JA, + const InputInfo &Output, + const InputInfoList &Inputs, + const llvm::opt::ArgList &TCArgs, + const char *LinkingOutput) const override; + }; + class LLVM_LIBRARY_VISIBILITY Link : public Tool { + public: + Link(const ToolChain &TC) : Tool("AAP::Link", "aap-ld", TC) + {} + + bool hasIntegratedCPP() const override { return false; } + bool isLinkJob() const override { return true; } + void ConstructJob(Compilation &C, const JobAction &JA, + const InputInfo &Output, + const InputInfoList &Inputs, + const llvm::opt::ArgList &TCArgs, + const char *LinkingOutput) const override; + }; +} // end namespace AAP + } // end namespace tools } // end namespace driver } // end namespace clang Index: lib/Driver/Tools.cpp =================================================================== --- lib/Driver/Tools.cpp +++ lib/Driver/Tools.cpp @@ -2069,6 +2069,11 @@ CmdArgs.push_back("-machine-sink-split=0"); } +void Clang::AddAAPTargetArgs(const ArgList &Args, + ArgStringList &CmdArgs) const { + return; +} + void Clang::AddWebAssemblyTargetArgs(const ArgList &Args, ArgStringList &CmdArgs) const { // Default to "hidden" visibility. @@ -2915,8 +2920,10 @@ case llvm::Triple::xcore: case llvm::Triple::wasm32: case llvm::Triple::wasm64: + case llvm::Triple::aap: // XCore never wants frame pointers, regardless of OS. // WebAssembly never wants frame pointers. + // AAP never wants frame pointers return false; default: break; @@ -4028,6 +4035,10 @@ default: break; + case llvm::Triple::aap: + AddAAPTargetArgs(Args, CmdArgs); + break; + case llvm::Triple::arm: case llvm::Triple::armeb: case llvm::Triple::thumb: @@ -10721,3 +10732,71 @@ const char *Exec = Args.MakeArgString(TC.GetProgramPath("fatbinary")); C.addCommand(llvm::make_unique(JA, *this, Exec, CmdArgs, Inputs)); } + +void AAP::Assemble::ConstructJob(Compilation &C, const JobAction &JA, + const InputInfo &Output, + const InputInfoList &Inputs, + const ArgList &Args, + const char *LinkingOutput) const { + ArgStringList CmdArgs; + + // Add input assembly files to command line + for (InputInfoList::const_iterator it = Inputs.begin(), ie = Inputs.end(); + it != ie; + ++it) { + const InputInfo &II = *it; + CmdArgs.push_back(II.getFilename()); + } + + const char *Exec = + Args.MakeArgString(getToolChain().GetProgramPath("aap-as")); + + C.addCommand(llvm::make_unique(JA, *this, Exec, CmdArgs, Inputs)); +} + +void AAP::Link::ConstructJob(Compilation &C, const JobAction &JA, + const InputInfo &Output, + const InputInfoList &Inputs, + const ArgList &Args, + const char *LinkingOutput) const { + ArgStringList CmdArgs; + + // Add crt0 and libc + const toolchains::AAP& ToolChain = + static_cast(getToolChain()); + const Driver &D = ToolChain.getDriver(); + + const std::string InstallPrefix = D.InstalledDir; + const std::string LibFilesDir = InstallPrefix + "/../aap/lib"; + const std::string crt0 = LibFilesDir + "/crt0.o"; + const std::string libpath = "-L" + LibFilesDir; + + if (!Args.hasArg(options::OPT_nostdlib) && + !Args.hasArg(options::OPT_nostartfiles)) { + CmdArgs.push_back(Args.MakeArgString(crt0)); + } + AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs); + + CmdArgs.push_back(Args.MakeArgString(libpath)); + if (!Args.hasArg(options::OPT_nostdlib)) { + CmdArgs.push_back("-lc"); + CmdArgs.push_back("-laap"); + CmdArgs.push_back("-lcompiler_rt"); + + // This may need to link a second time to resolve interdependencies + } + + Args.AddAllArgs(CmdArgs, options::OPT_L); + + if (Output.isFilename()) { + CmdArgs.push_back("-o"); + CmdArgs.push_back(Output.getFilename()); + } + else { + assert(Output.isNothing() && "Input output"); + } + + const char *Exec = + Args.MakeArgString(getToolChain().GetProgramPath("aap-ld")); + C.addCommand(llvm::make_unique(JA, *this, Exec, CmdArgs, Inputs)); +} Index: lib/Headers/float.h =================================================================== --- lib/Headers/float.h +++ lib/Headers/float.h @@ -74,7 +74,14 @@ /* Characteristics of floating point types, C99 5.2.4.2.2 */ #define FLT_EVAL_METHOD __FLT_EVAL_METHOD__ -#define FLT_ROUNDS (__builtin_flt_rounds()) + +/* __builtin_flt_rounds is not supported by AAP, and the rounding mode cannot + be changed anyway so we just default to 'to nearest' */ +#ifdef __AAP__ + #define FLT_ROUNDS 1 +#else + #define FLT_ROUNDS (__builtin_flt_rounds()) +#endif #define FLT_RADIX __FLT_RADIX__ #define FLT_MANT_DIG __FLT_MANT_DIG__