Go to the documentation of this file.
86 using namespace SymbolRewriter;
88 #define DEBUG_TYPE "symbol-rewriter"
97 const std::string &
Target) {
99 auto &Comdats =
M.getComdatSymbolTable();
102 C->setSelectionKind(CD->getSelectionKind());
105 Comdats.erase(Comdats.find(
Source));
123 bool performOnModule(
Module &M)
override;
134 bool ExplicitRewriteDescriptor<DT, ValueType, Get>::performOnModule(
Module &M) {
135 bool Changed =
false;
141 S->setValueName(
T->getValueName());
159 const std::string Transform;
165 bool performOnModule(
Module &M)
override;
178 bool PatternRewriteDescriptor<DT, ValueType, Get, Iterator>::
179 performOnModule(
Module &M) {
180 bool Changed =
false;
181 for (
auto &
C : (
M.*Iterator)()) {
187 M.getModuleIdentifier() +
": " +
Error);
189 if (
C.getName() == Name)
195 if (
Value *V = (
M.*Get)(Name))
196 C.setValueName(V->getValueName());
210 using ExplicitRewriteFunctionDescriptor =
217 using ExplicitRewriteGlobalVariableDescriptor =
223 using ExplicitRewriteNamedAliasDescriptor =
230 using PatternRewriteFunctionDescriptor =
238 using PatternRewriteGlobalVariableDescriptor =
246 using PatternRewriteNamedAliasDescriptor =
259 "': " + Mapping.
getError().message());
272 for (
auto &Document : YS) {
276 if (isa<yaml::NullNode>(Document.getRoot()))
279 DescriptorList = dyn_cast<yaml::MappingNode>(Document.getRoot());
280 if (!DescriptorList) {
281 YS.printError(Document.getRoot(),
"DescriptorList node must be a map");
285 for (
auto &Descriptor : *DescriptorList)
286 if (!parseEntry(YS, Descriptor,
DL))
300 Key = dyn_cast<yaml::ScalarNode>(Entry.getKey());
302 YS.
printError(Entry.getKey(),
"rewrite type must be a scalar");
306 Value = dyn_cast<yaml::MappingNode>(Entry.getValue());
308 YS.
printError(Entry.getValue(),
"rewrite descriptor must be a map");
312 RewriteType =
Key->getValue(KeyStorage);
313 if (RewriteType.
equals(
"function"))
314 return parseRewriteFunctionDescriptor(YS,
Key,
Value,
DL);
315 else if (RewriteType.
equals(
"global variable"))
316 return parseRewriteGlobalVariableDescriptor(YS,
Key,
Value,
DL);
317 else if (RewriteType.
equals(
"global alias"))
318 return parseRewriteGlobalAliasDescriptor(YS,
Key,
Value,
DL);
320 YS.
printError(Entry.getKey(),
"unknown rewrite type");
324 bool RewriteMapParser::
331 std::string Transform;
333 for (
auto &
Field : *Descriptor) {
340 Key = dyn_cast<yaml::ScalarNode>(
Field.getKey());
346 Value = dyn_cast<yaml::ScalarNode>(
Field.getValue());
352 KeyValue =
Key->getValue(KeyStorage);
353 if (KeyValue.
equals(
"source")) {
356 Source = std::string(
Value->getValue(ValueStorage));
361 }
else if (KeyValue.
equals(
"target")) {
362 Target = std::string(
Value->getValue(ValueStorage));
363 }
else if (KeyValue.
equals(
"transform")) {
364 Transform = std::string(
Value->getValue(ValueStorage));
365 }
else if (KeyValue.
equals(
"naked")) {
366 std::string Undecorated;
368 Undecorated = std::string(
Value->getValue(ValueStorage));
376 if (Transform.empty() ==
Target.empty()) {
378 "exactly one of transform or target must be specified");
385 DL->
push_back(std::make_unique<ExplicitRewriteFunctionDescriptor>(
389 std::make_unique<PatternRewriteFunctionDescriptor>(
Source, Transform));
394 bool RewriteMapParser::
400 std::string Transform;
402 for (
auto &
Field : *Descriptor) {
409 Key = dyn_cast<yaml::ScalarNode>(
Field.getKey());
415 Value = dyn_cast<yaml::ScalarNode>(
Field.getValue());
421 KeyValue =
Key->getValue(KeyStorage);
422 if (KeyValue.
equals(
"source")) {
425 Source = std::string(
Value->getValue(ValueStorage));
430 }
else if (KeyValue.
equals(
"target")) {
431 Target = std::string(
Value->getValue(ValueStorage));
432 }
else if (KeyValue.
equals(
"transform")) {
433 Transform = std::string(
Value->getValue(ValueStorage));
440 if (Transform.empty() ==
Target.empty()) {
442 "exactly one of transform or target must be specified");
447 DL->
push_back(std::make_unique<ExplicitRewriteGlobalVariableDescriptor>(
451 DL->
push_back(std::make_unique<PatternRewriteGlobalVariableDescriptor>(
457 bool RewriteMapParser::
463 std::string Transform;
465 for (
auto &
Field : *Descriptor) {
472 Key = dyn_cast<yaml::ScalarNode>(
Field.getKey());
478 Value = dyn_cast<yaml::ScalarNode>(
Field.getValue());
484 KeyValue =
Key->getValue(KeyStorage);
485 if (KeyValue.
equals(
"source")) {
488 Source = std::string(
Value->getValue(ValueStorage));
493 }
else if (KeyValue.
equals(
"target")) {
494 Target = std::string(
Value->getValue(ValueStorage));
495 }
else if (KeyValue.
equals(
"transform")) {
496 Transform = std::string(
Value->getValue(ValueStorage));
503 if (Transform.empty() ==
Target.empty()) {
505 "exactly one of transform or target must be specified");
510 DL->
push_back(std::make_unique<ExplicitRewriteNamedAliasDescriptor>(
514 DL->
push_back(std::make_unique<PatternRewriteNamedAliasDescriptor>(
522 class RewriteSymbolsLegacyPass :
public ModulePass {
526 RewriteSymbolsLegacyPass();
529 bool runOnModule(
Module &M)
override;
539 RewriteSymbolsLegacyPass::RewriteSymbolsLegacyPass() :
ModulePass(
ID) {
543 RewriteSymbolsLegacyPass::RewriteSymbolsLegacyPass(
547 bool RewriteSymbolsLegacyPass::runOnModule(
Module &M) {
548 return Impl.runImpl(M);
562 for (
auto &Descriptor : Descriptors)
563 Changed |= Descriptor->performOnModule(
M);
568 void RewriteSymbolPass::loadAndParseMapFiles() {
572 for (
const auto &MapFile : MapFiles)
573 Parser.
parse(MapFile, &Descriptors);
580 return new RewriteSymbolsLegacyPass();
585 return new RewriteSymbolsLegacyPass(
DL);
A set of analyses that are preserved following a run of a transformation pass.
void setComdat(Comdat *C)
This is an optimization pass for GlobalISel generic memory operations.
We currently emits eax Perhaps this is what we really should generate is Is imull three or four cycles eax eax The current instruction priority is based on pattern complexity The former is more complex because it folds a load so the latter will not be emitted Perhaps we should use AddedComplexity to give LEA32r a higher priority We should always try to match LEA first since the LEA matching code does some estimate to determine whether the match is profitable if we care more about code then imull is better It s two bytes shorter than movl leal On a Pentium M
static ErrorOr< std::unique_ptr< MemoryBuffer > > getFile(const Twine &Filename, bool IsText=false, bool RequiresNullTerminator=true, bool IsVolatile=false, std::optional< Align > Alignment=std::nullopt)
Open the specified file as a MemoryBuffer, returning a new MemoryBuffer if successful,...
ModulePass class - This class is used to implement unstructured interprocedural optimizations and ana...
This currently compiles esp xmm0 movsd esp eax eax esp ret We should use not the dag combiner This is because dagcombine2 needs to be able to see through the X86ISD::Wrapper which DAGCombine can t really do The code for turning x load into a single vector load is target independent and should be moved to the dag combiner The code for turning x load into a vector load can only handle a direct load from a global or a direct load from the stack It should be generalized to handle any load from P
Target - Wrapper for Target specific information.
std::list< std::unique_ptr< RewriteDescriptor > > RewriteDescriptorList
static cl::list< std::string > RewriteMapFiles("rewrite-map-file", cl::desc("Symbol Rewrite Map"), cl::value_desc("filename"), cl::Hidden)
static PreservedAnalyses none()
Convenience factory function for the empty preserved set.
PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM)
A scalar node is an opaque datum that can be presented as a series of zero or more Unicode scalar val...
Represents a YAML map created from either a block map for a flow map.
Function * getFunction(StringRef Name) const
Look up the specified function in the module symbol table.
ModulePass * createRewriteSymbolsPass()
void push_back(MachineInstr *MI)
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
iterator_range< global_iterator > globals()
(vector float) vec_cmpeq(*A, *B) C
static void rewriteComdat(Module &M, GlobalObject *GO, const std::string &Source, const std::string &Target)
GlobalAlias * getNamedAlias(StringRef Name) const
Return the global alias in the module with the specified name, of arbitrary type.
std::error_code getError() const
const Comdat * getComdat() const
@ GlobalVariable
function - descriptor rewrites a function
void printError(Node *N, const Twine &Msg, SourceMgr::DiagKind Kind=SourceMgr::DK_Error)
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
void initializeRewriteSymbolsLegacyPassPass(PassRegistry &)
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
bool equals(StringRef RHS) const
equals - Check for string equality, this is more efficient than compare() when the relative ordering ...
iterator_range< alias_iterator > aliases()
std::string lower() const
iterator_range< iterator > functions()
std::string sub(StringRef Repl, StringRef String, std::string *Error=nullptr) const
sub - Return the result of replacing the first match of the regex in String with the Repl string.
A Module instance is used to store all the information related to an LLVM module.
INITIALIZE_PASS(RewriteSymbolsLegacyPass, "rewrite-symbols", "Rewrite Symbols", false, false) ModulePass *llvm
StringRef - Represent a constant reference to a string, i.e.
This owns the files read by a parser, handles include stacks, and handles diagnostic wrangling.
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
This class represents a YAML stream potentially containing multiple documents.
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Machine Check Debug Module
PointerUnion< const Value *, const PseudoSourceValue * > ValueType
GlobalVariable * getGlobalVariable(StringRef Name) const
Look up the specified global variable in the module symbol table.
The basic entity representing a rewrite operation.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
@ NamedAlias
global variable - descriptor rewrites a global variable
Lightweight error class with error context and mandatory checking.
static bool runImpl(Function &F, const TargetLowering &TLI)
static bool isValid(const char C)
Returns true if C is a valid mangled character: <0-9a-zA-Z_>.
Represents either an error or a value T.
A range adaptor for a pair of iterators.
A container for analyses that lazily runs them and caches their results.
LLVM Value Representation.
bool parse(const std::string &MapFile, RewriteDescriptorList *Descriptors)